erietz / vim-terminator

:dagger: Run your code in an output buffer or a vim terminal conveniently
GNU General Public License v3.0
116 stars 2 forks source link

Issue with delimiters #4

Closed joalof closed 3 years ago

joalof commented 3 years ago

Thanks for writing this great plugin, combines a bunch of features I've been looking for into one neat package.

I'm currently having an issue with sending delimited code cells to a terminal/repl: only code between two explicit delimiters is successfully sent. For instance, sending code from the following Python script (to IPython)

import math

# In[1]:
a = 1

# In[2]:
print(a)

works for the code between the two delimiters but fails for the import and the print statements with a "delimiter not found" message. (tested on Ubuntu 18.04 with vanilla vim 8.2). Any idea what's going on?

As a feature suggestion, it would be neat to have an operator that allows you to send text via motions, I saw this implemented in, .e.g., Zepl.vim.

erietz commented 3 years ago

Thanks for testing out the plugin and filing an issue. Yes, I think I did this for a safety feature of some sort, but I agree that you should be able to leave out the last and first delimiters and still be able to send the text to the terminal.

I believe the two commented lines in this snippet fix the problem, but I would like to do a bit more testing before making this the default behavior.

    "let last_delim = search('\(' . delimiter . '\|\%^\)', 'bW')
    let last_delim = search(delimiter, 'b', line("w0"))
    call setpos('.', save_pos)
    "let next_delim = search('\(' . delimiter . '\|\%$\)', 'W')
    let next_delim = search(delimiter, '', line("w$"))
erietz commented 3 years ago

I will also try out Zepl.vim myself in the next few days, it looks like a good plugin. I have been considering removing all of the REPL features of vim-terminator for the sake of simplicity given that there is a good alternative plugin. What do you think?

joalof commented 3 years ago

Thanks for your reply. With the commented lines in your snippet I still can't run the first cell & the last cell only works if the file ends with an empty line. Both delimiter search alternatives seem to have some consistency issues as well when you try to execute a cell with the cursor positioned on the delimiter line. I would expect this to run the cell underneath but sometimes it also runs code above or throws a delimiter not found (this is probably also related to BOF/EOF).

Regarding whether to keep the REPL features or not, I'm not sure. Zepl has been working great for me but lacks your delimiter functionality which I'm very keen on. However, if you think the REPL implementation in Zepl looks good (I can't really judge with my abysmal VimL skills =p) then perhaps one could make a contribution or convince the author to add delimiter support.

erietz commented 3 years ago

The last commit should fix sending text between BOF/EOF and a delimiter. From the testing that I have done, it appears to now be working if the cursor is on the delimiter or if the last line of the file is not empty. I will leave this issue open indefinitely since I have not written tests for this plugin. After some consideration, I think it makes sense to keep adding nice features to this plugin.

joalof commented 3 years ago

Yeah, I kinda like that I get all the script running + repl functionality that I want from this plugin. Thanks for providing a fix for the BOF/EOF cells. After some more testing I found two remaning issues: 1) Running a cell with the cursor positioned on the first character of a delimiter line also triggers the above cell. 2) If the entire cell doesn't fit within the current visible window the delimiters are not found (but maybe this was intentional?)

In an effort to learn some vimL I took a stab at fixing this myself, the only real difference from your implementation is that I start each delimiter search at the end of the current line and limit searches to the first/last actual line rather than first/last visible line. I'm posting the snippet here in case it helps:

https://github.com/joalof/vim-terminator/blob/f222bc9a0ca59d4281b1ad2d0f45028511fc90eb/autoload/terminator.vim#L156-L192

erietz commented 3 years ago

Nice!

  1. How did you send that link to your modifications?

  2. Can you file a pull request so I can test/merge this?

joalof commented 3 years ago
  1. Just found this feature myself actually, very handy: https://docs.github.com/en/github/managing-your-work-on-github/creating-a-permanent-link-to-a-code-snippet
  2. Done