Sunday, June 26, 2011

Re: "Extending" syntax files / overriding keyword with match

On Mon, 27 Jun 2011, Ben Schmidt wrote:

> On 27/06/11 6:56 AM, Benjamin R. Haskell wrote:
>> On Sat, 25 Jun 2011, bendavis78 wrote:
>>
>>> Hi, I'm extending the css.vim syntax file for use with a CSS
>>> framework using "runtime! syntax/css.vim".
>>
>> You probably don't want the '!' there. That will run all
>> syntax/css.vim files found in 'runtimepath'. The only reason another
>> syntax/css.vim should be present in &rtp would be to override a
>> system syntax/css.vim.
>
> No, you do want the '!'. Without it, you may simply pull in a file
> from ~/.vim/syntax/css.vim that sets a handful of variables or
> something like that to be used by $VIMRUNTIME/syntax/css.vim, and not
> actually get the CSS highlighting itself pulled in at all. Needless to
> say, that could be tremendously unhelpful and annoying.

Blech. I thought setting up user settings for syntax files was for
~/.vimrc, ~/.vim/ftplugin/{name}.vim, and ':help after-directory'. That
is: ~/.vimrc or ~/.vim/ftplugin/css.vim would contain settings used by
the first syntax/css.vim found in 'runtimepath', but
~/.vim/syntax/css.vim could be used to override a system
/syntax/css.vim. (So says :help mysyntaxfile-replace )

But, ':help syntax-loading' shows that it'll do :runtime!
syntax/{name}.vim, which loads all syntax/{name}.vim files found. So,
putting custom settings into ~/.vim/syntax/{name}.vim seems fine.

It's also the reason most syntax files are protected by guards of the
form:

==> syntax/{name}.vim <==
if exists('b:current_syntax')
finish
endif
let b:current_syntax = 'name'
" do stuff for 'name'
==============================

So, :runtime! should be fine. Sorry for any confusion.


Back to the original goal, though, two things:

1. If it's reaaally similar to CSS (just adds a few custom rules), you
might want to put your modifications into ~/.vim/after/syntax/css.vim
(See: :help mysyntaxfile-add )

2. If the modifications are more extensive, you might want to create a
whole filetype for the CSS framework files (especially if the files
already have a custom extension -- so are trivially easy to detect). (or
use an existing syntax¹, if it's SASS or SCSS)

--
Best,
Ben H

¹: http://increaseyourgeek.wordpress.com/2011/02/26/syntax-highlighting-for-scss-in-vim/

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: