Loading ...
Sorry, an error occurred while loading the content.

RE: Bug in 7.0.178? autocmd BufReadCmd * DoSomething expand(" ") fails if the filename contains %

Expand Messages
  • Suresh Govindachar
    Thomas sent to vim-dev@vim.org ... Shouldn t be wrapped in escape before the expand, so that -- omitting other arguments -- the sequence would be:
    Message 1 of 2 , Jan 2, 2007
    • 0 Attachment
      Thomas sent to vim-dev@...

      > I have the following line in my source:
      >
      > exec 'autocmd BufReadCmd '. pattern .' call '. rcmd .'(1,
      > expand("<afile>"), "", "%")'
      >
      > This fails if the filename contains % which is replaced with
      > expand('%'). I can't seem to escape the % at any point, can I?
      > Wrapping the exand("<afile>") in a escape(<>, "%") doesn't help.

      Shouldn't <afile> be wrapped in escape before the expand,
      so that -- omitting other arguments -- the sequence would be:

      expand( escape( <afile> ) )

      --Suresh
    • Suresh Govindachar
      ... OK -- I put the cursor on common%h and executed the command ... The result was: common %h Also, escaping a second time with ... resulted in common %h
      Message 2 of 2 , Jan 2, 2007
      • 0 Attachment
        >> Shouldn't <afile> be wrapped in escape before the expand,
        >> so that -- omitting other arguments -- the sequence would be:
        >>
        >> expand( escape( <afile> ) )
        >>
        > I'd assumed that "<afile>" is an argument to expand (:h
        > expand()) and only valid in this context.

        OK -- I put the cursor on common%h and executed the command

        :echo escape(expand("<cWORD>"), "%")

        The result was:

        common\%h

        Also, escaping a second time with
        :echo escape(escape(expand("<cWORD>"), "%"), "%")
        resulted in
        common\\%h

        --Suresh
      Your message has been successfully submitted and would be delivered to recipients shortly.