On 07/10/08 19:49, Gary Johnson wrote:
> On 2008-10-07, Tony Mechelynck<[EMAIL PROTECTED]>  wrote:
>> On 07/10/08 16:08, Bob Hiestand wrote:
>>> On Tue, Oct 7, 2008 at 8:57 AM, A. S. Budden<[EMAIL PROTECTED]>   wrote:
>>>> 2008/10/7 Bob Hiestand<[EMAIL PROTECTED]>:
>>>>> You could do something like the following (untested):
>>>>>
>>>>> :auto BufRead * if expand('%') =~ '^/some/directory'|set 
>>>>> ft=somefiletype|endif
>>>> Wouldn't expand('%:p') be better?
>>>>
>>>> :help expand()
>>> I don't think it matters, as the matching is just testing to see if
>>> the file name starts with that path.
>> I think it does, as the problem was that the match was not found when
>> typing the filename without a path because the file's directory was
>> already current.
>>
>> Example:
>>      :lcd /some/dir
>>      :e filename.ext
>>
>> then expand('%') is "filename.ext", not "/some/dir/filename.ext". If you
>> test (expand('%') =~ '^/some/dir') it'll return 0 i.e. FALSE.
>>
>> OTOH under the same circumstances expand('%:p') is
>> "/some/dir/filename.ext" and it should work.
>>
>> However, I believe you should test for =~ '^some/dir/' with an ending
>> slash, otherwise you'll also find a match for /some/direction/file.txt
>
> For an autocommand pattern there is no need to expand the filename.
> See
>
>     :help autocmd-patterns
>
> where it says:
>
>     2. When there is a '/' in the pattern, Vim checks for a match
>        against both the short file name (as you typed it) and the
>        full file name (after expanding it to a full path and
>        resolving symbolic links).
>
> So the autocommand
>
>     auto BufRead /some/directory/* set ft=foo
>
> will be triggered by any of the following:
>
>     $ vim /some/directory/myfile
>
>     $ cd /some/directory
>     $ vim myfile
>
>     $ cd /some
>     $ vim directory/myfile
>
> Regards,
> Gary

We are not matching against an autocommand pattern here (the autocommand 
pattern has been set to * in the autocommand

au BufRead * if expand('%') =~ '^/some/path' | set ft=somefiletype | endif

) so you are beside the point.

We are using a plain ":if" statement in the autocommand to match 
expand('%') against a pattern, and there Vim will interpret expand('%') 
as the filename as it appears on the status line. If the file's 
directory is current, it will not be part of the return value of 
expand('%').

If you don't believe me, do the following:

        :cd $VIMRUNTIME
        :view vimrc_example.vim
        :echo expand('%')

Pence gets you pounds it's just plain vimrc_example.vim with no path 
shown. So I persist in saying that that autocommand sould be changed to 
either

au BufRead * if expand('%:p') =~ '^/some/path/' | set ft=somefiletype | 
endif

or, according to what you said above,

au BufRead /some/path/* set ft=somefiletype


Best regards,
Tony.
-- 
hundred-and-one symptoms of being an internet addict:
202. You're amazed to find out Spam is a food.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to