Skip to content

Commit

Permalink
ENH: Add g:mwExclusionPredicates to be able to suppress mark highligh…
Browse files Browse the repository at this point in the history
…ting in window(s)

Now that the mark highlighting update goes through the single mark#UpdateMark() function, we can add an evaluation of user-configured Predicates (as expressions or Funcrefs). If the current window should be skipped for highlighting (for the plugin, the marks are still "there" and can be added / removed, and jumped to, even though there're invisible), existing match highlighting is removed instead of updated.
By default, consider boolean "nomarks" flag variables for various scopes, as these (especially the buffer-local b:nomarks) can be easily set in filetype plugins.
To make this work with changing buffers, we have to run an additional unconditional mark update on BufWinEnter.

Resolves inkarkat#2.
  • Loading branch information
inkarkat committed Oct 30, 2018
1 parent a82798a commit 1916591
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,30 @@ override the default behavior of using 'ignorecase' by setting:

let g:mwIgnoreCase = 0

To exclude some tab pages, windows, or buffers / filetypes from showing mark
highlightings (you can still "blindly" navigate to marks in there with the
corresponding mappings), you can define a List of expressions or Funcrefs that
are evaluated in every window; if one returns 1, the window will not show
marks.

" Don't mark temp files, Python filetype, and scratch files as defined by
" a custom function.
let g:mwExclusionPredicates =
\ ['expand("%:p") =~# "/tmp"', '&filetype == "python", function('ExcludeScratchFiles')]

By default, tab pages / windows / buffers that have t:nomarks / w:nomarks /
b:nomarks with a true value are excluded. Therefore, to suppress mark
highlighting in a buffer, you can simply

:let b:nomarks = 1

If the predicate changes after a window has already been visible, you can
update the mark highlighting by either:
- switching tab pages back and forth
- toggling marks on / off (via <Plug>MarkToggle)
- :call mark#UpdateMark() (for current buffer)
- :call mark#UpdateScope() (for all windows in the current tab page)

You can use different mappings by mapping to the <Plug>Mark... mappings (use
":map <Plug>Mark" to list them all) before this plugin is sourced.

Expand Down Expand Up @@ -519,6 +543,9 @@ HISTORY
pattern.
- BUG: Regression: <Leader>n without {N} and not on an existing mark prints
error "Do not pass empty pattern to disable all marks".
- ENH: Allow to exclude certain tab pages, windows, or buffers / filetypes
from showing mark highlightings via g:mwExclusionPredicates or (with the
default predicate) t:nomarks / w:nomarks / b:nomarks flags.
__You need to update to ingo-library ([vimscript #4433](http://www.vim.org/scripts/script.php?script_id=4433)) version 1.035!__

##### 3.0.0 18-Sep-2017
Expand Down
15 changes: 15 additions & 0 deletions autoload/mark.vim
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ function! mark#NextUsedGroupIndex( isBackward, isWrapAround, startIndex, count )
return -1
endfunction

function! mark#DefaultExclusionPredicate()
return (exists('b:nomarks') && b:nomarks) || (exists('w:nomarks') && w:nomarks) || (exists('t:nomarks') && t:nomarks)
endfunction

" Set match / clear matches in the current window.
function! s:MarkMatch( indices, expr )
if ! exists('w:mwMatch')
Expand Down Expand Up @@ -197,6 +201,16 @@ function! s:MarkMatch( indices, expr )
endfunction
" Initialize mark colors in a (new) window.
function! mark#UpdateMark( ... )
for l:Predicate in g:mwExclusionPredicates
if ingo#actions#EvaluateOrFunc(l:Predicate)
" The window may have had marks applied previously. Clear any
" existing matches.
call s:MarkMatch(range(s:markNum), '')

return
endif
endfor

if a:0
call call('s:MarkMatch', a:000)
else
Expand Down Expand Up @@ -1117,6 +1131,7 @@ endfunction

augroup Mark
autocmd!
autocmd BufWinEnter * call mark#UpdateMark()
autocmd WinEnter * if ! exists('w:mwMatch') | call mark#UpdateMark() | endif
autocmd TabEnter * call mark#UpdateScope()
augroup END
Expand Down
25 changes: 25 additions & 0 deletions doc/mark.txt
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,28 @@ If you have set 'ignorecase', but want marks to be case-insensitive, you can
override the default behavior of using 'ignorecase' by setting: >
let g:mwIgnoreCase = 0
<
*g:mwExclusionPredicates*
To exclude some tab pages, windows, or buffers / filetypes from showing mark
highlightings (you can still "blindly" navigate to marks in there with the
corresponding mappings), you can define a List of expressions or Funcrefs that
are evaluated in every window; if one returns 1, the window will not show
marks. >
" Don't mark temp files, Python filetype, and scratch files as defined by
" a custom function.
let g:mwExclusionPredicates =
\ ['expand("%:p") =~# "/tmp"', '&filetype == "python", function('ExcludeScratchFiles')]
< *t:nomarks* *w:nomarks* *b:nomarks*
By default, tab pages / windows / buffers that have t:nomarks / w:nomarks /
b:nomarks with a true value are excluded. Therefore, to suppress mark
highlighting in a buffer, you can simply >
:let b:nomarks = 1
If the predicate changes after a window has already been visible, you can
update the mark highlighting by either:
- switching tab pages back and forth
- toggling marks on / off (via <Plug>MarkToggle)
- :call mark#UpdateMark() (for current buffer)
- :call mark#UpdateScope() (for all windows in the current tab page)


*mark-mappings*
You can use different mappings by mapping to the <Plug>Mark... mappings (use
Expand Down Expand Up @@ -518,6 +540,9 @@ HISTORY *mark-history*
pattern.
- BUG: Regression: <Leader>n without {N} and not on an existing mark prints
error "Do not pass empty pattern to disable all marks".
- ENH: Allow to exclude certain tab pages, windows, or buffers / filetypes
from showing mark highlightings via g:mwExclusionPredicates or (with the
default predicate) t:nomarks / w:nomarks / b:nomarks flags.
*** You need to update to ingo-library (vimscript #4433) version 1.035! ***

3.0.0 18-Sep-2017
Expand Down
4 changes: 4 additions & 0 deletions plugin/mark.vim
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ if ! exists('g:mwDirectGroupJumpMappingNum')
let g:mwDirectGroupJumpMappingNum = 9
endif

if ! exists('g:mwExclusionPredicates')
let g:mwExclusionPredicates = [function('mark#DefaultExclusionPredicate')]
endif


"- default highlightings ------------------------------------------------------

Expand Down

0 comments on commit 1916591

Please sign in to comment.