iron.nvim icon indicating copy to clipboard operation
iron.nvim copied to clipboard

Python send execution command for file instead of all lines

Open Ikariux opened this issue 3 years ago • 4 comments

Hi Hkupty,

thanks for your plugin!

I wanted to figure out how to send the current file to the REPL. By adding the following lines into my init.vim , I came up with this solution:

function! s:send_file()
    let s:a = substitute(expand("%:p"), '\\', '\\\\\\\\', "g" )
    let s:b = join(['exec(open(\"', s:a, '\").read())'], "")
    let s:c = join(['lua require("iron").core.send(nil,"',s:b,'")'],"")
    exec s:c
endfunction
command! IronSendFile call <SID>send_file()

which executes following command in my python REPL: exec(open(<path_to_file>).read())

Since I have very, very limited knowledge of Vim script and Lua, I suppose there are better ways to implement this? If you think, it might be worth to implement, I highly appreciate it :)

Regards, Ikariux

P.s.: Today I updated to the newest version and struggled with setting everything up. Did you forget to add hinting the creation of a lua file and including this to your init.vim is mandatory for proper working of the plugin?

Ikariux avatar Jul 12 '22 22:07 Ikariux

Hi @Ikariux,

Thanks for the issue and the suggestion. I've recently added a function in iron for doing that. Have a look at iron.core.send_file.

You can bind it using the setup function:

local iron = require("iron.core")

iron.setup {
  keymaps = {
    send_file = "<space>sf",
  }
}

Today I updated to the newest version and struggled with setting everything up. Did you forget to add hinting the creation of a lua file and including this to your init.vim is mandatory for proper working of the plugin?

Sorry if this was poorly communicated. I felt like it was clear in the README.md file. I'll revisit to make sure it is easy and accessible for new users and those who are upgrading from previous version.

Best regards, Henry

hkupty avatar Jul 15 '22 20:07 hkupty

Hi Henry,

yes I saw this function in the README.md file and tried it out. It works, but will send the whole code in chunks to the REPL window, thus the REPL will be filled completely with the code instead just showing the output. Therefore my intention to send only the "execute this file" command and show the results without pasting the whole code into the REPL.

Regards, Nicki

Ikariux avatar Jul 18 '22 16:07 Ikariux

Ok, I'm not 100% sure I'm following, from your snippet I was under the impression that you wanted to send the contents of the file to the REPL.

but will send the whole code in chunks to the REPL window

This leads me to think the issue is with bracketed paste so we paste the file as a whole.

to send only the "execute this file" command and show the results without pasting the whole code into the REPL

Then I get a completely different picture here, which is to do send something like require("your.code.namespace")/import your.code.namespace, depending on the language, so it will not paste the contents of the file but it will still execute it?

Long ago I created trex.nvim, because I didn't want to include language-specific code to iron.nvim. Unfortunately, I barely had time to work on it and it has only a small subset of features commands useful for clojure, plus a few generic and not necessarily working extensions to iron. Would it be the case to add something as I described to trex then?

hkupty avatar Jul 19 '22 06:07 hkupty

Hey, @hkupty but what if I want to send all the lines of the current buffer and run it (i.e. send char 13 at the end) so I can see the output of my code with one single mapped command? Is that possible? Just a little annoying that I need to send the code with one keys and execute the code with another ones. Thanks a lot for your REPL, it really nice!!!

Onefabis avatar Jan 05 '23 00:01 Onefabis