Search code examples
emacsbufferdired

Customising the buffer name of a dired buffer


I'd like to have one single dired buffer alive at any time, and I want to be able to bring it to the front with a particular hot key. However, in order to do that, I would need the dired buffer to always have the same name. But the buffer name changes every time a new directory is loaded. Is there a way to tell dired to not change the name? I tried tweaking the reading and loading hooks but it didn't work.

Alternatively, is there a command to bring forward an existing dired buffer?

Thanks!


Solution

  • You probably don't want to do that. Some Dired features depend on the buffer name being associated with the directory.

    A better approach might be to have a command that switches to the only Dired buffer, since you will be having only one at a time.

    (defun switch-to-dired-buffer ()
      "..."
      (interactive)
      (let ((dbufs  (cl-remove-if-not
                     (lambda (bf)
                       (with-current-buffer bf
                         (derived-mode-p 'dired-mode)))
                     (buffer-list))))
        (switch-to-buffer (car dbufs))))
    

    You can also get fancier and prompt for which Dired buffer if there is more than one etc.