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

Auto generated range #111

Open
kurkale6ka opened this issue Aug 2, 2017 · 0 comments
Open

Auto generated range #111

kurkale6ka opened this issue Aug 2, 2017 · 0 comments

Comments

@kurkale6ka
Copy link

kurkale6ka commented Aug 2, 2017

Hi,

One feature I miss coming from Tabular is the auto generated range.
The idea is to call EasyAlign on a line containing our pattern and from there find all adjacent lines also containing the pattern: that is our range.
For adjacent lines with our pattern there is no point running an extra vip, or gaap etc... the range can easily be calculated.

Ex: :EasyAlign/\\/ -> no range given => run it on all adjacent lines containing \

Pseudo function:

" Generate a range of lines matching a pattern
function! easy#PipeRange(includepat) range

   let top = a:firstline
   let bot = a:lastline

   " No range has been given (top == bot), thus apply range extension logic
   if a:includepat != '' && top == bot
      if top < 0 || top > line('$') || getline(top) !~ a:includepat
         return
      endif
      " Extend range upwards while we match the pattern
      while top > 1 && getline(top-1) =~ a:includepat
         let top -= 1
      endwhile
      " Extend range downwards while we match the pattern
      while bot < line('$') && getline(bot+1) =~ a:includepat
         let bot += 1
      endwhile
   endif

   let lines = map(range(top, bot), 'getline(v:val)')

endfunction

Reference: https://github.com/godlygeek/tabular/blob/master/autoload/tabular.vim#L312-L353

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

1 participant