markonm / traces.vim

Range, pattern and substitute preview for Vim
MIT License
742 stars 13 forks source link

Make autocmds nested #16

Closed olmokramer closed 6 years ago

olmokramer commented 6 years ago

Some plugins, e.g. vim-cool, use the OptionSet autocmd to detect when hlsearch is set, but because traces sets it in an autocmd that is not nested (:help autocmd-nested), vim-cool can not detect that it is set, gives an error and ceases to work for the remainder of the session.

markonm commented 6 years ago

vim-cool should not detect hlsearch change made from traces.vim as it is only temporary.

The following change seems to fix E31 thrown from vim-cool.

diff --git a/autoload/traces.vim b/autoload/traces.vim
index b03c054..63c9f6a 100644
--- a/autoload/traces.vim
+++ b/autoload/traces.vim
@@ -567,7 +567,7 @@ function! s:highlight(group, pattern, priority) abort
   endif

   if &hlsearch && !empty(a:pattern) && a:group ==# 'TracesSearch'
-    let &hlsearch = 0
+    noautocmd let &hlsearch = 0
   endif
   if &scrolloff !=# 0
     let scrolloff = &scrolloff
@@ -784,7 +784,7 @@ function! traces#cmdl_leave() abort
   endif

   if &hlsearch !=# s:buf[s:nr].hlsearch
-    let &hlsearch = s:buf[s:nr].hlsearch
+    noautocmd let &hlsearch = s:buf[s:nr].hlsearch
   endif
   if &cmdheight !=# s:buf[s:nr].cmdheight
     let &cmdheight = s:buf[s:nr].cmdheight

Can you confirm it? Is there any other incompatibility?

All options changed from traces.vim should use noautocmd. I'll fix it.

olmokramer commented 6 years ago

Ah yes that makes sense, and it also seems to fix the issue. Thanks!