Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Improved highlighting #488

Open
wants to merge 3 commits into from

9 participants

@aaronjensen

Two options here for highlighting, see the two different commits. The second is better than the first, but more complicated.

@kien
Owner

Thank you! I'll check it out as soon as I can. It may be in a while, though, since I've been incredibly busy lately.

@aaronjensen aaronjensen referenced this pull request
Open

search highlight #452

aaronjensen added some commits
@aaronjensen aaronjensen Highlight only individual characters b5f8261
@aaronjensen aaronjensen More complicated, but even better highlighting
Prefers grouping words together, examples:

app/assets/javascripts/common
---                    ------
> app/common

app/models/group_user.rb
--- ------       ----
> appmodelsuser
3559e2b
@aaronjensen

First method aaronjensen@b5f8261:
wemux 4 vim - vim 2013-10-10 23-53-26

Second method aaronjensen@3559e2b:
wemux 4 vim - vim 2013-10-10 23-52-14

@kdurant

@kien why not accept this pull request?

@kien
Owner

@kdurant I haven't been able to check it out yet. Plus it's still a work-in-progress.

@aaronjensen

I wouldn't call it a work in progress anymore unless there is anything you'd like me to change. It seems to work. I'm using a similar thing w/ https://github.com/JazzCore/ctrlp-cmatcher and it's working great.

@tommcdo

+1

Would love to see this merged.

@drn

+1 Would love to see this merged as well

@d11wtq d11wtq referenced this pull request in ctrlpvim/ctrlp.vim
Merged

Improve highlighting #4

@d11wtq

Moved to: ctrlpvim#4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 11, 2013
  1. @aaronjensen
  2. @aaronjensen

    More complicated, but even better highlighting

    aaronjensen authored
    Prefers grouping words together, examples:
    
    app/assets/javascripts/common
    ---                    ------
    > app/common
    
    app/models/group_user.rb
    --- ------       ----
    > appmodelsuser
Commits on Aug 9, 2014
  1. @aaronjensen
This page is out of date. Refresh to see the latest.
Showing with 48 additions and 5 deletions.
  1. +48 −5 autoload/ctrlp.vim
View
53 autoload/ctrlp.vim
@@ -1622,12 +1622,55 @@ fu! s:highlight(pat, grp)
if s:matcher != {} | retu | en
cal clearmatches()
if !empty(a:pat) && s:ispath
- let pat = s:regexp ? substitute(a:pat, '\\\@<!\^', '^> \\zs', 'g') : a:pat
- if s:byfname
- let pat = substitute(pat, '\[\^\(.\{-}\)\]\\{-}', '[^\\/\1]\\{-}', 'g')
- let pat = substitute(pat, '\$\@<!$', '\\ze[^\\/]*$', 'g')
+ if s:regexp
+ let pat = substitute(a:pat, '\\\@<!\^', '^> \\zs', 'g')
+ cal matchadd(a:grp, ( s:martcs == '' ? '\c' : '\C' ).pat)
+ el
+ let pat = a:pat
+
+ " get original characters so we can rebuild pat
+ let chars = split(pat, '\[\^\\\?.\]\\{-}')
+
+ " Build a pattern like /a.*b.*c/ from abc (but with .\{-} non-greedy
+ " matchers instead)
+ let pat = join(chars, '.\{-}')
+ " Ensure we match the last version of our pattern
+ let ending = '\(.*'.pat.'\)\@!'
+ " Case sensitive?
+ let beginning = ( s:martcs == '' ? '\c' : '\C' ).'^.*'
+ if s:byfname
+ " Make sure there are no slashes in our match
+ let beginning = beginning.'\([^\/]*$\)\@='
+ end
+
+ for i in range(len(chars))
+ " Surround our current target letter with \zs and \ze so it only
+ " actually matches that one letter, but has all preceding and trailing
+ " letters as well.
+ " \zsa.*b.*c
+ " a\(\zsb\|.*\zsb)\ze.*c
+ let charcopy = copy(chars)
+ if i == 0
+ let charcopy[i] = '\zs'.charcopy[i].'\ze'
+ let middle = join(charcopy, '.\{-}')
+ else
+ let before = join(charcopy[0:i-1], '.\{-}')
+ let after = join(charcopy[i+1:-1], '.\{-}')
+ let c = charcopy[i]
+ " for abc, match either ab.\{-}c or a.*b.\{-}c in that order
+ let cpat = '\(\zs'.c.'\|'.'.*\zs'.c.'\)\ze.*'
+ let middle = before.cpat.after
+ endif
+
+ " Now we matchadd for each letter, the basic form being:
+ " ^.*\zsx\ze.*$, but with our pattern we built above for the letter,
+ " and a negative lookahead ensuring that we only highlight the last
+ " occurrence of our letters. We also ensure that our matcher is case
+ " insensitive or sensitive depending.
+ cal matchadd(a:grp, beginning.middle.ending)
+ endfor
en
- cal matchadd(a:grp, ( s:martcs == '' ? '\c' : '\C' ).pat)
+
cal matchadd('CtrlPLinePre', '^>')
en
endf
Something went wrong with that request. Please try again.