On 2007-05-16, [EMAIL PROTECTED] wrote:
> Gary Johnson <[EMAIL PROTECTED]> ???? 2007-05-16 16:41:22:
> > On 2007-05-16, [EMAIL PROTECTED] wrote:
> > > Hi, vimmers:
> > >
> > > The line 1230 of editing.txt said:
> > >
> > > To change to the directory of the current file:
> > >         :cd %:h
> > >
> > > This works for Vim 7.0 and before, but not for Vim 7.1. In Vim 7.1 when
> the
> > > pwd is the same as the directory of current file, the command will fail
> > > with E500. The failure will break the execution of a mapping, if one
> have a
> > > mapping to do :cd %:h and then continue to do something else.
> > >
> > > To reproduce the error, just at anytime, run :cd %:h twice. (I've got
> > > Windows gvim7.1.1, cygwin console vim 7.1.1)
> >
> > I would expect ":cd %:h" to give an error the second time it is
> > executed.  Just to be sure, I repeated your experiment on 7.1, 7.0
> > and 6.4 on Unix and 7.0 on Windows.  I always got E500.  Are you
> > sure that it "works" for you for Vim 7.0?
> 
> Positive, I've got a mapping which do :cd %:h then :grep, this mapping
> works since Vim 6.3, 6.4 and 7.0, this is the mapping I used "Everyday" and
> I cannot use Vim without it, then suddenly it breaks after I installed Vim
> 7.1. ---- Now I changed :cd %:h to :cd %:p:h and everything works.

That's very strange.  Your observations certainly don't match mine.  
I wonder what's going on.

> Anyway, I think there should be an option to disable E500, or "catch and
> throw". This is the Unix trend: if the caller feel necessary, a program
> should fail silently in order not to break a script.

I don't think disabling E500 would help.  The text of E500 is, 
"E500: Evaluates to an empty string".  That's warning you that there 
is no head component of the file name.  If you disabled the error, 
and presumably allowed %:h to return an empty string, then your ":cd 
%:h" command would be executing just ":cd", which on a Unix system 
changes to the home directory--not what you want.

Another way to fix your mapping would be to use

   :silent! cd %:h

which allows the cd to fail silently.

Regards,
Gary

-- 
Gary Johnson                 | Agilent Technologies
[EMAIL PROTECTED]     | Mobile Broadband Division
                             | Spokane, Washington, USA

Reply via email to