'cfile' Behavior

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

'cfile' Behavior

jason heddings-2
It seems that using cfile has different behavior than expected...

Internally, I run :grep (using findstr) and the results are formatted nicely
(in :copen) and easy to navigate (:cnext and :cprev)

If I run `findstr /n` and redirect the results to a file, then use :cfile to
read the file, :cnext and :cprev display the line at the bottom, but do not
move to the line, also, :copen does not seem to recognize the formatting of
the errorfile.

Any ideas?

--jah

Reply | Threaded
Open this post in threaded view
|

RE: 'cfile' Behavior

jason heddings-2
Well, I think I may have found the issue.

It looks like :grep makes use of the 'grepformat' string, but :cfile will
only use the 'errorformat' string.  So, I had to do a little manipulating to
get it to parse the grep file.  Now, the only problem is that I lose my
errorformat.  Any ideas?

Here is the code:
  let g:bg_grep_efm = &errorformat
  set errorformat=%f:%l:%m
  execute "cfile " . g:bg_grep_file
  execute "set errorformat=" . g:bg_grep_efm
  echo &errorformat

Echoes:
errorformat=

--jah

-----Original Message-----
From: jason heddings [mailto:[hidden email]]
Sent: Tuesday, 06 September, 2005 11:07
To: [hidden email]
Subject: 'cfile' Behavior

It seems that using cfile has different behavior than expected...

Internally, I run :grep (using findstr) and the results are formatted nicely
(in :copen) and easy to navigate (:cnext and :cprev)

If I run `findstr /n` and redirect the results to a file, then use :cfile to
read the file, :cnext and :cprev display the line at the bottom, but do not
move to the line, also, :copen does not seem to recognize the formatting of
the errorfile.

Any ideas?

--jah



Reply | Threaded
Open this post in threaded view
|

Re: 'cfile' Behavior

Jürgen Krämer

Hi,

jason heddings wrote:

>
> Well, I think I may have found the issue.
>
> It looks like :grep makes use of the 'grepformat' string, but :cfile will
> only use the 'errorformat' string.  So, I had to do a little manipulating to
> get it to parse the grep file.  Now, the only problem is that I lose my
> errorformat.  Any ideas?
>
> Here is the code:
>   let g:bg_grep_efm = &errorformat
>   set errorformat=%f:%l:%m
>   execute "cfile " . g:bg_grep_file
>   execute "set errorformat=" . g:bg_grep_efm

the content of g:bg_grep_efm is probably not suited for using in a
"set"-command because it may contain unescaped spaces and other
special characters. Instead of executing a "set"-command you might use

  let &errorformat = g:bg_grep_efm

>   echo &errorformat
>
> Echoes:
> errorformat=

Regards,
J?rgen

--
J?rgen Kr?mer                              Softwareentwicklung
HABEL GmbH & Co. KG                        mailto:[hidden email]
Hinteres ?schle 2                          Tel: +49 / 74 61 / 93 53 - 15
78604 Rietheim-Weilheim                    Fax: +49 / 74 61 / 93 53 - 99
Reply | Threaded
Open this post in threaded view
|

RE: 'cfile' Behavior

jason heddings-2
Thanks for the pointer...

In order to reset the 'efm' option, I needed to get this back into the real
error string.  I was able to do it using the following:

  let l:efm = escape(&errorformat, "\" ")
  set errorformat=%f:%l:%m
  execute "cfile " . g:grep_file
  execute "set errorformat=" . l:efm

Now I just need to find a way to read the existing grepformat if one has not
been specified...

--jah


-----Original Message-----
From: Jürgen Krämer [mailto:[hidden email]]
Sent: Tuesday, 06 September, 2005 23:45
To: vim mailing list
Subject: Re: 'cfile' Behavior


Hi,

jason heddings wrote:

>
> Well, I think I may have found the issue.
>
> It looks like :grep makes use of the 'grepformat' string, but :cfile
> will only use the 'errorformat' string.  So, I had to do a little
> manipulating to get it to parse the grep file.  Now, the only problem
> is that I lose my errorformat.  Any ideas?
>
> Here is the code:
>   let g:bg_grep_efm = &errorformat
>   set errorformat=%f:%l:%m
>   execute "cfile " . g:bg_grep_file
>   execute "set errorformat=" . g:bg_grep_efm

the content of g:bg_grep_efm is probably not suited for using in a
"set"-command because it may contain unescaped spaces and other special
characters. Instead of executing a "set"-command you might use

  let &errorformat = g:bg_grep_efm

>   echo &errorformat
>
> Echoes:
> errorformat=

Regards,
Jürgen

--
Jürgen Krämer                              Softwareentwicklung
HABEL GmbH & Co. KG                        mailto:[hidden email]
Hinteres Öschle 2                          Tel: +49 / 74 61 / 93 53 - 15
78604 Rietheim-Weilheim                    Fax: +49 / 74 61 / 93 53 - 99

Reply | Threaded
Open this post in threaded view
|

Re: 'cfile' Behavior

Gary Johnson
On 2005-09-07, jason heddings <[hidden email]> wrote:

> Thanks for the pointer...
>
> In order to reset the 'efm' option, I needed to get this back into the real
> error string.  I was able to do it using the following:
>
>   let l:efm = escape(&errorformat, "\" ")
>   set errorformat=%f:%l:%m
>   execute "cfile " . g:grep_file
>   execute "set errorformat=" . l:efm
>
> Now I just need to find a way to read the existing grepformat if one has not
> been specified...

I'm not sure I understand the problem, but here's what I do to save
and restore the 'grepformat' in one of my functions.

        let gf = &grepformat
        set grepformat=%f\ %[%^\ ]%#\ %l\ %m
        execute "grep -" . num . a:name
        let &grepformat = gf

Note that I have elsewhere temporarily set 'grepprg' to something
other than grep, so the specifics of the 'grepformat' and the
arguments to the grep command won't be useful to you, but this
should give you a structure and syntax that work.

HTH,
Gary

--
Gary Johnson                 | Agilent Technologies
[hidden email]     | Wireless Division
                             | Spokane, Washington, USA