Skip to content

Commit 4c4b31e

Browse files
committed
Merge branch 'VladimirPal-feature/highlight-execution'
2 parents ef12fec + 60150e5 commit 4c4b31e

File tree

3 files changed

+78
-7
lines changed

3 files changed

+78
-7
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,12 @@ nmap <Leader>P <Plug>(TomePlayParagraph)
194194
xmap <Leader>p <Plug>(TomePlaySelection)
195195
```
196196

197-
[See `help TomeConfig`](doc/tome.txt) in Vim to change them, and for more options.
197+
[See `help TomeConfig`](doc/tome.txt) in Vim to change them, and for more options:
198+
199+
- execution highlighting
200+
- "no send" to prevent sending commands vim and other TUIs.
201+
- target to send to vim terminal instead of tmux
202+
198203

199204
### tmux options
200205

doc/tome.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,19 @@ let g:tome_vars = 0
114114
```
115115

116116

117+
HIGHLIGHT EXECUTED TEXT *TomeHighlight*
118+
119+
Tome can briefly highlight the lines you executed. This is disabled by default.
120+
Note that TomePlaySelection will highlight the full lines.
121+
122+
```
123+
" enable highlighting with > 0
124+
let g:tome_highlight_ms = 500
125+
```
126+
127+
By default the highlight links to |IncSearch| through the `TomeExecuted`
128+
highlight group. You can customize it by setting your own highlight group
129+
definition for `TomeExecuted`.
130+
131+
117132
vim:tw=78:ts=8:ft=help:norl:

plugin/tome.vim

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ if !exists("g:tome_skip_prefix")
2121
let g:tome_skip_prefix = '^\$\s\+'
2222
endif
2323

24+
if !exists("g:tome_highlight_ms")
25+
let g:tome_highlight_ms = 0
26+
endif
27+
2428
let s:vars = {}
29+
let s:highlight_ids = []
2530

2631
function! TomeSetVar(name, value)
2732
if g:tome_vars
@@ -47,6 +52,46 @@ function! s:notify(text)
4752
endif
4853
endfunction
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+
5095
function! 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
94139
endfunction
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
104155
endfunction
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")
116168
endfunction
@@ -214,15 +266,15 @@ function! s:prepAndSendCommand(targetOffset, text)
214266
endfunction
215267

216268
function! s:playLine()
217-
call s:prepAndSendCommand(v:count, getline(".")."\n")
269+
call s:prepAndSendCommand(v:count, s:getAndHighlightCurrentLine())
218270
endfunction
219271

220272
function! s:playSel()
221-
call s:prepAndSendCommand(v:count, s:getVisualSelection())
273+
call s:prepAndSendCommand(v:count, s:getAndHighlightVisualSelection())
222274
endfunction
223275

224276
function! s:playParagraph()
225-
call s:prepAndSendCommand(v:count, s:getParagraph() . "\n")
277+
call s:prepAndSendCommand(v:count, s:getAndHighlightParagraph() . "\n")
226278
endfunction
227279

228280
function! s:mapBufferCRToPlay()
@@ -252,7 +304,6 @@ command! TomePlayBook call s:mapBufferCRToPlay()
252304
command! -nargs=? TomeScratchPad call s:markScratch(<q-args>)|call s:mapBufferCRToPlay()
253305
command! -nargs=? TomeScratchPadOnly call s:markScratch(<q-args>)
254306

255-
256307
if !exists("g:tome_no_mappings")
257308

258309
nmap <Leader>p <Plug>(TomePlayLine)

0 commit comments

Comments
 (0)