JoshCheek / seeing_is_believing

Displays the results of every line of code in your file
1.31k stars 54 forks source link

Running `seeing_is_believing` for the selected line #137

Closed sameera207 closed 6 years ago

sameera207 commented 6 years ago

Hey @JoshCheek ,

First off, thanks the this awesome plugin,

Quick question.. ( I'm sure I must be doing something wrong here), but I cannot get this work only for selected lines in vim.

Currently I got it working for the entire file. But what I want is for it to run on the line where my cursor is on.

So, following is a screen record of what's happening. I'm doing..

- <leader>z  # to select the line
- <leader>b # to run seeing_is_believing on the current line

2018-08-17 12 38 50

as you can see, instead of running the line with current cursor on, it runs the full file.

Following is my .vimrc mappings

" ===== Seeing Is Believing =====                                                                                                                                                                 
" Assumes you have a Ruby with SiB available in the PATH                                                                                                                                          
" If it doesn't work, you may need to `gem install seeing_is_believing`                                                                                                                           

" Annotate every line                                                                                                                                                                             
nmap <leader>b :%!seeing_is_believing --timeout 12 --line-length 500 --number-of-captures 300 --alignment-strategy chunk<CR>;                                                                     
" Annotate marked lines                                                                                                                                                                           
nmap <leader>n :%.!seeing_is_believing --timeout 12 --line-length 500 --number-of-captures 300 --alignment-strategy chunk --xmpfilter-style<CR>;                                                  
" Remove annotations                                                                                                                                                                              
nmap <leader>c :%.!seeing_is_believing --clean<CR>;                                                                                                                                               
" Mark the current line for annotation                                                                                                                                                            
nmap <leader>z A # => <Esc> 

Any help would be much appreciated

cheers

JoshCheek commented 6 years ago

Hi, sorry for the delay, I haven't found an effective strategy for dealing with notifications.

SiB itself doesn't have an option for this. I could add one, but it feels like this belongs in the editor itself. Eg, in this case, vim would only send the selected lines to SiB and then update them. That feels like the most flexible way to do it.

I've updated my vim bindings to set the scope to just the selected portion when in visual line mode, give this a try: https://github.com/JoshCheek/dotfiles/blob/ce7c47d14e4ae4ff2d736607efb515c75c3e00e4/vimrc#L131-L190

(note I've been told you need at least vim 8 for this to work, IIRC, it's because of the function thing, but if you're on an older one, you can just duplicate the WithoutChangingCursor in each of the three functions)

sameera207 commented 6 years ago

@JoshCheek , Thanks for the reply and I agree with you on not adding this this to SiB . Also, thanks a lot for the explanation and link to your .vimrc file.

I've updated mine and now it works perfectly

I've upgraded my vim to be 8.1.3

2018-09-04 22 24 19

sameera207 commented 6 years ago

closing the issue as the suggested solution works :)

JoshCheek commented 6 years ago

A suggestion, given your example: I wouldn't use the p function. p prints the inspection stdout, which you don't need to do since SiB will display the inspection inline.

JoshCheek commented 6 years ago

Also, given 👆 a thought that entered my brain which feels worth saying aloud, even though I don't have an intent to act on it:

If people are using SiB to make examples for others (eg in a book or whatever) they may have the preference of putting the p in the code so that people without SiB can run it and see the output, but still want the example updated as if it was not called. Perhaps SiB should offer a way to configure how p works?

And now that I've thought that out loud, as I was writing it, I realized the best solution is probably for the user to configure SiB to require their custom file of modifications using the -r flag (maybe the -I flag, too). That's more flexible and doesn't require complicating SiB.