1
1
" NOTES:
2
2
" problem: cchar cannot be more than 1 character.
3
3
" strategy: make fg/bg the same color, then conceal the other char.
4
- "
5
- " problem: [before 7.4.792] keyword highlight takes priority over conceal.
6
- " strategy: syntax clear | [do the conceal] | let &syntax=s:o_syntax
7
4
8
5
let g: sneak #target_labels = get (g: , ' sneak#target_labels' , " ;sftunq/SFGHLTUNRMQZ?0" )
9
6
10
- let s: clear_syntax = ! has (' patch-7.4.792' )
11
7
let s: matchmap = {}
12
- let s: match_ids = []
13
8
let s: orig_conceal_matches = []
14
9
10
+ let s: use_virt_text = has (' nvim-0.5' )
11
+ if s: use_virt_text
12
+ call luaeval (' require("sneak").init()' )
13
+ else
14
+ let s: match_ids = []
15
+ endif
16
+
15
17
if exists (' *strcharpart' )
16
18
func ! s: strchar (s , i ) abort
17
19
return strcharpart (a: s , a: i , 1 )
@@ -24,10 +26,10 @@ endif
24
26
25
27
func ! s: placematch (c , pos) abort
26
28
let s: matchmap [a: c ] = a: pos
27
- let pat = ' \%' .a: pos [0 ].' l\%' .a: pos [1 ].' c.'
28
- if s: clear_syntax
29
- exec " syntax match SneakLabel '" .pat." ' conceal cchar=" .a: c
29
+ if s: use_virt_text
30
+ call luaeval (' require("sneak").placematch(_A[1], _A[2], _A[3])' , [a: c , a: pos [0 ] - 1 , a: pos [1 ] - 1 ])
30
31
else
32
+ let pat = ' \%' .a: pos [0 ].' l\%' .a: pos [1 ].' c.'
31
33
let id = matchadd (' Conceal' , pat, 999 , -1 , { ' conceal' : a: c })
32
34
call add (s: match_ids , id)
33
35
endif
@@ -127,25 +129,17 @@ endf "}}}
127
129
func ! s: after () abort
128
130
autocmd ! sneak_label_cleanup
129
131
try | call matchdelete (s: sneak_cursor_hl ) | catch | endtry
130
- call map (s: match_ids , ' matchdelete(v:val)' )
131
- let s: match_ids = []
132
- " Remove temporary highlight links.
133
- exec ' hi! link Conceal ' .s: orig_hl_conceal
134
- call s: restore_conceal_matches ()
135
- exec ' hi! link Sneak ' .s: orig_hl_sneak
136
-
137
- if s: clear_syntax
138
- let &l: synmaxcol= s: o_synmaxcol
139
- " Always clear before restore, in case user has `:syntax off`. #200
140
- syntax clear
141
- silent ! let &l: foldmethod= s: o_fdm
142
- silent ! let &l: syntax= s: o_syntax
143
- " Force Vim to reapply 'spell' (must set 'spelllang'). #110
144
- let [&l: spell ,&l: spelllang ]= [s: o_spell ,s: o_spelllang ]
145
- call s: restore_conceal_in_other_windows ()
132
+ if s: use_virt_text
133
+ call luaeval (' require("sneak").after()' )
134
+ else
135
+ call map (s: match_ids , ' matchdelete(v:val)' )
136
+ let s: match_ids = []
137
+ " Remove temporary highlight links.
138
+ exec ' hi! link Conceal ' .s: orig_hl_conceal
139
+ call s: restore_conceal_matches ()
140
+ let [&l: concealcursor ,&l: conceallevel ]= [s: o_cocu ,s: o_cole ]
146
141
endif
147
-
148
- let [&l: concealcursor ,&l: conceallevel ]= [s: o_cocu ,s: o_cole ]
142
+ exec ' hi! link Sneak ' .s: orig_hl_sneak
149
143
endf
150
144
151
145
func ! s: disable_conceal_in_other_windows () abort
@@ -168,34 +162,25 @@ endf
168
162
169
163
func ! s: before () abort
170
164
let s: matchmap = {}
171
- for o in [' spell' , ' spelllang' , ' cocu' , ' cole' , ' fdm' , ' synmaxcol' , ' syntax' ]
172
- exe ' let s:o_' .o .' =&l:' .o
173
- endfor
174
-
175
- setlocal concealcursor= ncv conceallevel= 2
176
165
177
166
" Highlight the cursor location (because cursor is hidden during getchar()).
178
167
let s: sneak_cursor_hl = matchadd (" SneakScope" , ' \%#' , 11 , -1 )
179
168
180
- if s: clear_syntax
181
- setlocal nospell
182
- " Prevent highlighting in other windows showing the same buffer.
183
- ownsyntax sneak_label
184
- " Avoid broken folds when we clear syntax below.
185
- if & l: foldmethod == # ' syntax '
186
- setlocal foldmethod = manual
187
- endif
188
- syntax clear
189
- " This is fast because we cleared syntax. Allows Sneak to work on very long wrapped lines.
190
- setlocal synmaxcol = 0
191
- call s: disable_conceal_in_other_windows ()
169
+ if s: use_virt_text
170
+ call luaeval ( ' require("sneak").before() ' )
171
+ else
172
+ for o in [ ' cocu ' , ' cole ' ]
173
+ exe ' let s:o_ ' . o . ' =&l: ' . o
174
+ endfor
175
+ setlocal concealcursor = ncv conceallevel = 2
176
+
177
+ let s: orig_hl_conceal = sneak#util#links_to ( ' Conceal ' )
178
+ call s: save_conceal_matches ()
179
+ " Set temporary link to our custom 'conceal' highlight.
180
+ hi ! link Conceal SneakLabel
192
181
endif
193
182
194
- let s: orig_hl_conceal = sneak#util#links_to (' Conceal' )
195
- call s: save_conceal_matches ()
196
183
let s: orig_hl_sneak = sneak#util#links_to (' Sneak' )
197
- " Set temporary link to our custom 'conceal' highlight.
198
- hi ! link Conceal SneakLabel
199
184
" Set temporary link to hide the sneak search targets.
200
185
hi ! link Sneak SneakLabelMask
201
186
0 commit comments