Skip to content

Commit

Permalink
Fix cosmetic/usability bug with marking paths.
Browse files Browse the repository at this point in the history
This commit addresses justinmk#76
and more specifically, this comment: justinmk#76 (comment).
It likely needs some cleanup, but it basically works.

A few notes:

- Syntax rules for DirvishFullPath and DirvishArg must follow the other
  rules, otherwise they may be overriden (see :h syn-priority).
- I am not sure whether \v has any effect in syntax rule, as the manual
  says that syntax patterns are always magic (:h syn-pattern).
- map() has been replaced by a for loop: this way the code is cleaner
  (IMO) and the resulting syntax rules shorter.
- I am not sure what the place for the condition testing for
  b:current_syntax is. That might need to be changed.
  • Loading branch information
lifepillar committed Jun 12, 2018
1 parent f637328 commit 8189293
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions syntax/dirvish.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ endif
let s:sep = exists('+shellslash') && !&shellslash ? '\' : '/'
let s:escape = 'substitute(escape(v:val, ".$~"), "*", ".*", "g")'

" Define (again). Other windows may need the old definitions ...
let s:pat = join(map(argv(), 'escape(fnamemodify(v:val[-1:]==#s:sep?v:val[:-2]:v:val, ":t"), "*.^$~\\")'), '\|')
exe 'syntax match DirvishArg /\'.s:sep.'\@<=\%\('.s:pat.'\)\'.s:sep.'\?$/'
exe 'syntax match DirvishPathHead =\v.*\'.s:sep.'\ze[^\'.s:sep.']+\'.s:sep.'?$= conceal'
exe 'syntax match DirvishPathTail =\v[^\'.s:sep.']+\'.s:sep.'$='
exe 'syntax match DirvishSuffix =[^\'.s:sep.']*\%('.join(map(split(&suffixes, ','), s:escape), '\|') . '\)$='

for p in argv()
let s:base = escape(fnamemodify(p[-1:] ==# s:sep ? p[:-2] : p, ":t"), "@*.^$~\\")
exe 'syntax match DirvishFullPath @^'.escape(p, "@*.^$~\\").'$@ contains=DirvishPathHead,DirvishArg'
exe 'syntax match DirvishArg @'.s:base.s:sep.'\?$@ contained'
endfor

if exists('b:current_syntax')
finish
endif

exe 'syntax match DirvishPathHead =\v.*\'.s:sep.'\ze[^\'.s:sep.']+\'.s:sep.'?$= conceal'
exe 'syntax match DirvishPathTail =\v[^\'.s:sep.']+\'.s:sep.'$='
exe 'syntax match DirvishSuffix =[^\'.s:sep.']*\%('.join(map(split(&suffixes, ','), s:escape), '\|') . '\)$='

let b:current_syntax = "dirvish"

0 comments on commit 8189293

Please sign in to comment.