Emacs: switch between buffers with the same name but in different directories

I have two files with the same name but in different directories:

apples/main.cpp oranges/main.cpp 

I open them in one emacs window via emacs apples/main.cpp oranges/main.cpp

When I use Cx b to switch between these two buffers, the buffer names are "main.cpp" and "main.cpp <2>". I would love to see the full path of these two files when switching buffers so that I can eliminate the ambiguity between apples and the version of oranges. Is there any way to do this?

One way could be to modify any code that generates <2> after the second main.cpp, when Emacs detects that a buffer with this name is already open. However, I could not find how to do this.

+6
source share
3 answers

Use uniquify . I use it like this:

 (require 'uniquify) (setq uniquify-buffer-name-style 'forward) 
+13
source

Extension answer Tomas.

There are other uniquify-buffer-name-style options besides forward that you might consider:

The files / foo / bar / mumble / name and / baz / quux / mumble / name will have the following buffer names in different styles:

 forward bar/mumble/name quux/mumble/name reverse name\mumble\bar name\mumble\quux post-forward name|bar/mumble name|quux/mumble post-forward-angle-brackets name<bar/mumble> name<quux/mumble> 

If you want to remove the general suffixes of the conflicting file directory, add the line below to the init emacs file.

(setq uniquify-strip-common-suffix t)

Now, if you open / a 1 / b / c / d and / a2 / b / c / d, the buffer names will say "d | a1" and "d | a2" instead of "d | a1 / b / c" and " d | a2 / b / c ".

+5
source

Use lusty explorer . Configure it with:

 (require 'lusty-explorer) ;; Override the normal file-opening and buffer switching. (global-set-key (kbd "Cx Cf") 'lusty-file-explorer) (global-set-key (kbd "Cx b") 'lusty-buffer-explorer)) 
+1
source

Source: https://habr.com/ru/post/885575/


All Articles