Skip to content

Commit

Permalink
fix: in some cases the syntax file can be evaluated before ftplugin
Browse files Browse the repository at this point in the history
Two users, @shadowwa and @dmaes reported errors where vim 9.1 was not
happy about the variable g:puppet_display_errors not being defined when
evaluating `syntax/puppet.vim`. They found out that the order the plugin
scripts were loaded did not reflect my current understanding of how vim
loads plugin files: the syntax file was loaded before the ftplugin
script, so the variable was indeed not yet defined.

Since the variable is only used in the syntax script, we can declare its
default value there if the variable doesn't exist (instead of in the
ftplugin file)

I've also changed to using the more common values 0/1 for
binary flags in order to use vimscript's "truthy/falsy" nature of a
variable.

(Closes: #151)
  • Loading branch information
lelutin committed Sep 12, 2024
1 parent 8f6abca commit be2a608
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Provides
* Formatting based on the latest Puppetlabs Style Guide
* Syntax highlighting compatible with puppet 4.x
* by default, highlights errors: mixing spaces and tabs and bad names. If you
don't want this highlighting, add `let g:puppet_display_errors = v:false`
(or really any value that's not `v:true`) to your vimrc.
don't want this highlighting, add `let g:puppet_display_errors = 0` to your
vimrc.
* Automatic => alignment
* If you don't like that, add `let g:puppet_align_hashes = 0` to your vimrc.
* Ctags support
Expand Down
4 changes: 0 additions & 4 deletions ftplugin/puppet.vim
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ setlocal commentstring=#\ %s

setlocal formatexpr=puppet#format#Format()

if !exists('g:puppet_display_errors')
let g:puppet_display_errors = v:true
endif

let b:undo_ftplugin = '
\ setlocal tabstop< tabstop< softtabstop< shiftwidth< expandtab<
\| setlocal keywordprg< iskeyword< comments< commentstring<
Expand Down
6 changes: 5 additions & 1 deletion syntax/puppet.vim
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ endif
let s:cpo_sav = &cpo
set cpo&vim

if !exists('g:puppet_display_errors')
let g:puppet_display_errors = 1
endif

syn cluster puppetNotTop contains=@puppetExtendedStringSpecial,@puppetRegexpSpecial,puppetTodo

syn match puppetSpaceError display excludenl "\s\+$"
Expand Down Expand Up @@ -282,7 +286,7 @@ hi def link puppetFunction Function
hi def link puppetDeprecated Ignore
hi def link puppetDebug Debug

if g:puppet_display_errors ==# v:true
if g:puppet_display_errors
hi def link puppetInvalidNumber Error
hi def link puppetNameBad Error
hi def link puppetSpaceError Error
Expand Down

0 comments on commit be2a608

Please sign in to comment.