How to put cscope output in Vim quickfix window?
Asked Answered
F

1

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?

Frantic answered 13/7, 2011 at 10:52 Comment(1)
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("<cword>"))<CR>. Personally, I use this with cppcheck and vera++ for static analysis of C++ code.Frantic
V
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
Vigilant answered 13/7, 2011 at 15:11 Comment(3)
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.Frantic
@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 stringVigilant
to use cscopequifix you need to have quickfix module disable. Saving time from other adding it to your answer plz.Dodi

© 2022 - 2024 — McMap. All rights reserved.