@@ -21,7 +21,12 @@ if !exists("g:tome_skip_prefix")
2121 let g: tome_skip_prefix = ' ^\$\s\+'
2222endif
2323
24+ if ! exists (" g:tome_highlight_ms" )
25+ let g: tome_highlight_ms = 0
26+ endif
27+
2428let s: vars = {}
29+ let s: highlight_ids = []
2530
2631function ! TomeSetVar (name, value)
2732 if g: tome_vars
@@ -47,6 +52,46 @@ function! s:notify(text)
4752 endif
4853endfunction
4954
55+ function ! s: setExecutedHighlight (start_line, end_line)
56+ if g: tome_highlight_ms <= 0
57+ return
58+ endif
59+
60+ if ! hlexists (' TomeExecuted' )
61+ highlight default link TomeExecuted IncSearch
62+ endif
63+
64+ call s: clearExecutedHighlight ()
65+
66+ for line_num in range (a: start_line , a: end_line )
67+ let pattern = ' \%' .line_num.' l.*'
68+ let id = matchadd (' TomeExecuted' , pattern)
69+ call add (s: highlight_ids , id)
70+ endfor
71+
72+ if len (s: highlight_ids ) > 0
73+ let s: tome_highlight_timer = timer_start (g: tome_highlight_ms , function (' s:tomeClearHighlightTimer' ))
74+ endif
75+ endfunction
76+
77+ function ! s: clearExecutedHighlight ()
78+ if len (s: highlight_ids ) > 0
79+ call timer_stop (s: tome_highlight_timer )
80+ for id in s: highlight_ids
81+ try
82+ call matchdelete (id)
83+ catch
84+ " Ignore errors if highlight doesn't exist
85+ endtry
86+ endfor
87+ endif
88+ let s: highlight_ids = []
89+ endfunction
90+
91+ function ! s: tomeClearHighlightTimer (timer)
92+ call s: clearExecutedHighlight ()
93+ endfunction
94+
5095function ! s: tomeSubstituteVars (text)
5196 if ! g: tome_vars | return [a: text , [], []] | endif
5297 let result = a: text
@@ -93,8 +138,14 @@ function! s:tomeSubstituteVars(text)
93138 endif
94139endfunction
95140
96- function ! s: getVisualSelection ()
141+ function ! s: getAndHighlightCurrentLine ()
142+ call s: setExecutedHighlight (line (" ." ), line (" ." ))
143+ return getline (" ." )." \n "
144+ endfunction
145+
146+ function ! s: getAndHighlightVisualSelection ()
97147 try
148+ call s: setExecutedHighlight (line (" '<" ), line (" '>" ))
98149 let oldA = @a
99150 silent normal ! gv" ay
100151 return getreg (' a' , 1 , 0 )
@@ -103,14 +154,15 @@ function! s:getVisualSelection()
103154 endtry
104155endfunction
105156
106- function ! s: getParagraph ()
157+ function ! s: getAndHighlightParagraph ()
107158 let start = search (' ^$' , ' bnW' )
108159 let end = search (' ^$' , ' nW' )
109160 if end > 0
110161 let end = end - 1
111162 else
112163 let end = ' $'
113164 endif
165+ call s: setExecutedHighlight (start + 1 , end )
114166 let res = getbufline (" %" , start + 1 , end )
115167 return join (res , " \n " )
116168endfunction
@@ -214,15 +266,15 @@ function! s:prepAndSendCommand(targetOffset, text)
214266endfunction
215267
216268function ! s: playLine ()
217- call s: prepAndSendCommand (v: count , getline ( " . " ). " \n " )
269+ call s: prepAndSendCommand (v: count , s: getAndHighlightCurrentLine () )
218270endfunction
219271
220272function ! s: playSel ()
221- call s: prepAndSendCommand (v: count , s: getVisualSelection ())
273+ call s: prepAndSendCommand (v: count , s: getAndHighlightVisualSelection ())
222274endfunction
223275
224276function ! s: playParagraph ()
225- call s: prepAndSendCommand (v: count , s: getParagraph () . " \n " )
277+ call s: prepAndSendCommand (v: count , s: getAndHighlightParagraph () . " \n " )
226278endfunction
227279
228280function ! s: mapBufferCRToPlay ()
@@ -252,7 +304,6 @@ command! TomePlayBook call s:mapBufferCRToPlay()
252304command ! -nargs =? TomeScratchPad call s: markScratch (<q-args> )|call s: mapBufferCRToPlay ()
253305command ! -nargs =? TomeScratchPadOnly call s: markScratch (<q-args> )
254306
255-
256307if ! exists (" g:tome_no_mappings" )
257308
258309 nmap <Leader> p <Plug> (TomePlayLine)
0 commit comments