One problem that I have with emacs is that it doesn't seem to handle like-named files in different directories very well. For example, if I'm not careful, I'll end up with 20 __init__.py
buffers open. What I've been doing is using M-x rename-buffer
and renaming it to indicate what package it's within. However, doing this manually is somewhat tedious.
Does anyone have any strategies for attacking this problem?
I like uniquify, which comes with Emacs:
(require 'uniquify)
(setq uniquify-buffer-name-style 'reverse)
(setq uniquify-separator "/")
(setq uniquify-after-kill-buffer-p t) ; rename after killing uniquified
(setq uniquify-ignore-buffers-re "^\\*") ; don't muck with special buffers (or Gnus mail buffers)
With those settings, the directory gets added to the buffer name, giving you an indication of where the file is. For example, loading the files /some/path/to/Makefile
and /some/path/to/different/Makefile
would result in the following buffer names:
Makefile/to (which is /some/path/to/Makefile)
and
Makefile/different (which is /some/path/to/different/Makefile)
uniquify
also handles updating the buffer names when buffers are deleted, so when one of the two Makefile
buffers is deleted, the other gets renamed to simply Makefile
.
If you want full control you can redefine create-file-buffer
.
If you want the full filename it could be as simple as
(defun create-file-buffer (filename)
"Create a suitably named buffer for visiting FILENAME, and return it."
(generate-new-buffer filename))
See files.el
for reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With