dired-sidebar icon indicating copy to clipboard operation
dired-sidebar copied to clipboard

shortening dired-sidebar buffer names

Open retroj opened this issue 11 months ago • 3 comments

Hello,

I want to make the buffer names of dired-sidebar buffers shorter, so that they would only contain the final path component of the directory being visited. As indicated in the docstring of dired-sidebar-update-buffer-name, it is important to avoid naming conflicts with regular dired buffers. To that end, I am doing this in my config:

(eval-after-load "dired-sidebar"
  '(defun dired-sidebar-buffer-name (dir)
     "Shorter buffer name than dired-sidebar's default, while
still ensuring it is different than normal dired buffer names."
     (concat ":"
             (file-name-nondirectory (directory-file-name dir))
             "/")))

There is another issue that I can foresee by doing this, which is that if I have two different directories with the same name, there would be a name conflict. I believe the solution to that would be to modify `dired-sidebar-update-buffer-name' as follows:

(defun dired-sidebar-update-buffer-name ()
  "Change buffer name to avoid collision with regular `dired' buffers."
  (rename-buffer
   (dired-sidebar-buffer-name (dired-current-directory))
   t)) ;; pass t here to uniquify buffer name in case of conflict

Is that a change that could be made to dired-sidebar?

Then concerning how I achieved shorter buffer names in general, I recognize that my solution is a bit hacky because it overrides a function in dired-sidebar, and I wondered if there might be some cleaner way that dired-sidebar could support shortening of buffer names?

I wonder if there might even be a way to use uniquify.el to make nicer unique short buffer names in the case of a conflict.

I greatly appreciate any thoughts you have on these questions. Thank you!

retroj avatar Jan 29 '25 16:01 retroj

Quick update - I found that dired-sidebar-get-or-create-buffer is looking for existing dired-sidebar buffers by name, which precludes shortening. I think this could be solved by instead looking in the dired-buffers list for a buffer with a matching directory.

retroj avatar Jan 29 '25 16:01 retroj

precludes shortening.

Reworded, I guess you mean dired-sidebar-get-or-create-buffer needs to be changed to support name shortening?

jojojames avatar Feb 11 '25 04:02 jojojames

precludes shortening.

Reworded, I guess you mean dired-sidebar-get-or-create-buffer needs to be changed to support name shortening?

yes

retroj avatar Feb 12 '25 12:02 retroj