开发者

Significance of the value of the `current_compiler` variable

Vim's compiler plugins are supposed to set the value of the variable current_compiler to something. They should also, unless they are intended to augment an existing compiler plugin, exit early if that variable is already defined. Is the value of the variable intended to be used? Should it be set to the basename of the compiler plugin file? (e.g. $VIMRUNTIME/compiler/foo.vim -> foo)

The documentation has this to say:

To support older Vim versions, the plugins always use "current_compiler" and
not "b:current_compiler".  What the command actually does is the following:

- Delete the "current_compiler" and "b:current_compiler" variables.
- Define the "CompilerSet" user command.  With "!" it does ":set", without "!"
  it does ":setlocal"开发者_如何学编程.
- Execute ":runtime! compiler/{name}.vim".  The plugins are expected to set
  options with "CompilerSet" and set the "current_compiler" variable to the
  name of the compiler.
- Delete the "CompilerSet" user command.
- Set "b:current_compiler" to the value of "current_compiler".
- Without "!" the old value of "current_compiler" is restored.

The command referred to is :compiler. Its argument becomes the {name} used above.

The entry on writing compiler plugins doesn't provide additional information, and the above-mentioned entries cover all the instances of the string current_compiler in the vim help database (as per :lhelpgrep current_compiler).


You can pre-select a particular compiler for a filetype in ~.vim/after/ftplugin/<filetype>.vim. Because this is re-sourced whenever the buffer is loaded (e.g. when moving through :args), it is recommended to only set the compiler if it hasn't yet been set (i.e. only on the first load). Otherwise, switching buffers may override any changed compiler, and messages from when the compiler was set may be printed (and need to be acknowledged) all the time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜