How to shorten path names in grep buffer?
Is it possible to shorten paths in grep results buffer? By default each line of grep results in Emacs looks like this:
/home/pawel/tmp/avro-src-1.5.4-fixed/lang/c/src/datum.c:107:int avro_string_set(avro_datum_t datum, const char *p)
which takes a lot of space and looks messy and not very readable, especially if there is another window beside.
I'd like to see just filenames or partial paths - as long as they are unique in grep buffer, e.g开发者_开发知识库:
datum.c:107:int avro_string_set(avro_datum_t datum, const char *p)
or
/home/(...)/src/datum.c:107:int avro_string_set(avro_datum_t datum, const char *p)
I guess emacs needs to know full paths internally, so it's about displaying grep results only rather than playing with 'grep' parameters. How to do this? Would hide-show mode definitions for grep buffer do the trick, or is there an easier way of doing this?
Thanks.
I made one for you: scf-mode. It works as a minor-mode, so the original file-name can be restored when you turn it off.
For installation instructions see the file header.
If you know Emacs lisp then it may be not hard to implement. You just have to find the common part of the path names, remove it, store the common part in a local variable and then when a grep result is opened assemble the full pathname from the stored parts.
It is a good idea and it would improve the readability of grep-find output, so if you don't get an answer here then I suggest posting the question to emacs help. There are expert users there who can put together a solution quickly if they find the idea worthwile.
what version of emacs are you using? when i run grep on my emacs (23.3.1), i get no path, e.g.:
file1:25:some result
file2:26:some other result
also, what happens on your box when you run the same grep command outside of emacs?
Just M-x cd /home/pawel/tmp/avro-src-1.5.4-fixed/lang/c/src/
before you run M-x grep
.
You only get the directory parts for grep
hits if the files hit are not in the current directory (default-directory
).
精彩评论