On 3/12/12, Ben Fritz <[email protected]> wrote:
> On Monday, March 12, 2012 12:43:30 AM UTC-5, char101 wrote:
>> Hi,
>>
>> I found these two explanations to be incompatible:
>>
>> :help syntax-loading
>>
>> The step before the last step is:
>>
>>      When the 'syntax' option was set above, this triggers an autocommand
>>     |        from |synload-1| (and |synload-2|).  This find the main syntax 
>> file
>> in
>>     |        'runtimepath', with this command:
>>     |                runtime! syntax/<name>.vim
>>
>> :help mysyntax-replace
>>
>> REPLACING AN EXISTING SYNTAX FILE                    *mysyntaxfile-replace*
>>
>> If you don't like a distributed syntax file, or you have downloaded a new
>> version, follow the same steps as for |mysyntaxfile| above.  Just make
>> sure
>> that you write the syntax file in a directory that is early in
>> 'runtimepath'.
>> Vim will only load the first syntax file found.
>>
>> Running runtime! will include *all* syntax files, while the second
>> explanation says
>> "Vim will only load the first syntax file found".
>>
>> I think the right command should be runtime (not runtime!) because
>> using runtime!
>> is problematic with syntax files loaded using syn include (both custom
>> syntax and
>> default syntax will be loaded and both will run resulting in the default
>> syntax
>> overriding the custom syntax).
>
> You are correct that runtime! will run all the matched files, but what
> you're missing is that most (all?) syntax files distributed with Vim have
> something like the following at the top:

Hi,

Yes, that's right, but before that there is also this check

if ! exists('main_syntax')
  " check if current_syntax has been defined
endif

Now, when a syntax file is include using syn include, the main syntax
is already defined, so that check will not be performed. One of the
most common case is when editing a html file. I have a custom
javascript syntax in my .vim. And I have checked that my custom syntax
is being overriden by the default syntax (both are using the same
syntax group name).

I realize that vim is using runtime! to be able to handle /after/
directories, because they are put in runtimepath. Without using
runtime!, the /after/ directories will not be sourced.

I have changed source_runtime is ex_misc2.c so that it will always
source the files in /after/ directories regardless of the "all"
parameter. And I have changed the usage of runtime! in
syntax/synload.vim and indon.vim to runtime only. So far vim runs fine
and I think it's a more correct way of sourcing syntax and indent
files (now only my custom syntax and indent files that show up in
:scriptnames, but all /after/ syntax are still being sourced, e.g. the
css3-syntax files).

>
> " Quit when a (custom) syntax file was already loaded
> if exists("b:current_syntax")
>   finish
> endif
>
> and later:
>
> let b:current_syntax = "c"
>
> So, only the first matching syntax file actually does anything, any other
> files which run will abort early if written properly.

Still, it's a waste of resource. Syntax files are not meant to be
cascading. Addition to the syntax highlight should be put in the
/after/syntax directory. If I have a custom syntax, vim should not
have to load the default syntax file. And so does with indent files.

-- 
You received this message from the "vim_dev" 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

Raspunde prin e-mail lui