Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run statically-typed language by scratch terminal (Such as c/cpp/java) #82

Open
justrico opened this issue Feb 2, 2023 · 1 comment

Comments

@justrico
Copy link

justrico commented Feb 2, 2023

Hi, thx for this great project!
I don't know how to set compile and execute commands in scratch terminal cmd config. Firstly, I've tried this by follow readme :

local runners = { c = 'gcc', cpp = 'g++' }

vim.keymap.set('n', '<leader><Enter>', function()
    local buf = vim.api.nvim_buf_get_name(0)
    local ftype = vim.filetype.match({ filename = buf })
    local fname = string.gsub(buf, ftype, '')
    local exec = runners[ftype]
    if exec ~= nil then
    	if exec == 'c' then
    		local cbin_fname = fname..'out'
        	require('FTerm').scratch({
        		cmd = { exec, buf, '-o', '&&', './'..cbin_fname }
        	})
        end
    end
end)

But this didn't work what I expect. The result is same as cmd = { exec, buf }, just compile to a default a.out file, and didn't executed.

image

Then I tried this to only execute a.out :

local runners = { c = 'gcc', cpp = 'g++' }

vim.keymap.set('n', '<leader><Enter>', function()
    local buf = vim.api.nvim_buf_get_name(0)
    local ftype = vim.filetype.match({ filename = buf })
    local exec = runners[ftype]
    if exec ~= nil then
    	if exec == 'c' then
        	require('FTerm').scratch({
        		cmd = { exec, buf, '&&', './a.out' }
        	})
        end
    end
end)

This had same result as I firstly tried. So I wonder to know how to set commands to auto compile and run statically-typed language.

@muhhae
Copy link

muhhae commented Mar 1, 2024

Hi, have you tried

require('FTerm').scratch {
    cmd = 'gcc -o tmp ' .. buf .. ' && ./tmp && rm ./tmp'
}

I do this for all language. And its work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants