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

Re: Checking return codes?

Expand Messages
  • Chris Sutcliffe
    ... The getqflist() is the approach I took: function! Grep(pattern, location) exe noautocmd vimgrep / . a:pattern . /gj . a:location if
    Message 1 of 3 , Mar 31 8:28 AM
      >> Is it possible to check the return code of an Ex command?  I currently
      >> have:
      >>
      >> function! Grep(pattern, location)
      >>     exe "noautocmd vimgrep /" . a:pattern . "/gj " . a:location " | copen"
      >> endfunction
      >>
      >> which causes an error with copen if vimgrep doesn't return anything.
      >> I'd like to handle the error a little more gracefully if possible.
      >
      > You can use a :try :catch block and catch pattern E480.
      > (Seems like the help tag E480 is wrong).
      > And you can also check, whether the result returned by getqflist() is
      > empty.

      The getqflist() is the approach I took:

      function! Grep(pattern, location)
      exe "noautocmd vimgrep /" . a:pattern . "/gj " . a:location
      if (!empty(getqflist()))
      silent exe 'copen'
      endif
      endfunction

      which works nicely for me.

      Cheers!

      Chris

      --
      Chris Sutcliffe
      http://emergedesktop.org
      http://www.google.com/profiles/ir0nh34d

      --
      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

      To unsubscribe, reply using "remove me" as the subject.
    Your message has been successfully submitted and would be delivered to recipients shortly.