8

I want to redirect output from cscope to Vim quickfix window. The glue part is easy enough, but I currently stuck at errorformat. Here's an example from cscope output (cscope -L -1 bar):

Format: "filename scope linenumber sourceline"
Example: "abc.cpp foo 25 bar()"

This means inside foo(), at line 25 in abc.cpp there is a call to bar().

efm = %f\ %*[^\ ]\ %l\ %m works but the scope information is lost. For example:

Input: "abc.cpp foo 25 bar()" becomes
Output: "abc.cpp |25| bar()"

What I want is to include the scope in quickfix window, like this:

Input: "abc.cpp foo 25 bar()" becomes
Output: "abc.cpp |25| bar() inside foo()"

Is it possible to do this with errorformat only, or do I need to write a script to manipulate the output before feeding it to Vim?

DumbCoder
  • 5,696
  • 3
  • 29
  • 40
Thanh DK
  • 4,257
  • 3
  • 23
  • 18
  • This maybe helpful so I just put here: One can connect the output of a program to Vim quickfix with `:cex`. For example: `:cex system("cscope -L -1 " . expand(""))`. Personally, I use this with cppcheck and vera++ for static analysis of C++ code. – Thanh DK Jul 14 '11 at 01:51

1 Answers1

10

Instead of messing about with errorformat, just set cscopequickfix and use the normal :cscope commands. eg. (from vim help)

:set cscopequickfix=s-,c-,d-,i-,t-,e-

Edit

You could also use a filter like the following to reorder the fields

sed -e 's/^\([^ ]\+\) \([^ ]\+\) \([^ ]\+\) \(.*\)$/\1 \3 \4 inside \2/'

set it to filter your message, then use the efm

errorformat=%f\ %l\ %m
Hasturkun
  • 35,395
  • 6
  • 71
  • 104
  • Thanks, I didn't know about cscopequickfix before. This seems to work fine btw, so upvote for you. However, this still does not answer my question about matching output with errorformat. It can help to connect output of other programs where there are no built-in. – Thanh DK Jul 14 '11 at 01:38
  • @ThanhDK: I've added a small filter script to do what you want, which is what the vim help suggests you do if the messages don't fit the format string – Hasturkun Jul 14 '11 at 12:13
  • 2
    to use cscopequifix you need to have quickfix module disable. Saving time from other adding it to your answer plz. – MaikoID Nov 07 '14 at 01:16