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

[wish] visiting directory without creating new buffers

Open BooAA opened this issue 5 years ago • 10 comments

On emacs27 (commit : fbe87d0f8f8878b30b1dfe74f7eb369b569bab6b), pressing "a" (dired-find-alternate-file) will not work and message with "cannot make side window the only window"

On emacs27 (commit : 020e69d992c98fd852e835c9bd707a8d137090f2), dired will create new buffer below instead of showing new directory in side window, like GIF below:

Peek 2019-03-14 14-25

Hope we can have a command to use the same buffer to visit new directory or file rather than creating lots of buffers.

BooAA avatar Mar 14 '19 06:03 BooAA

@fasheng

I duplicated your comment here:

I don't use emacs 27, but "cannot make side window the only window" should be caused by display-buffer-in-side-window which is not very friendly in some cases, for example you want toturn off dired-hide-details-mode and delete-other-windows in dired-sidebar to make it looks like a normal dired buffer, this error will occurs.

Maybe we could use split-window/window--display-buffer instead just like imenu-list did.

Deleted the other comment to keep the other topic focused.

jojojames avatar Mar 20 '19 01:03 jojojames

imenu-list looks very cool and something I was thinking about doing myself at some point. I'll have to try it out first before I come to any conclusions. I like the display-buffer-in-side-window 'api' though since it seems to be a supported built-in. I'm not sure how much extra code imenu-list had to do to avoid using display-buffer-in-side-window (I haven't looked at the code yet.)

I don't use emacs 27, but "cannot make side window the only window" should be caused by display-buffer-in-side-window which is not very friendly in some cases, for example you want toturn off dired-hide-details-mode and delete-other-windows in dired-sidebar to make it looks like a normal dired buffer,

I think it's a tradeoff. I find it a feature that the sidebar can't be the only window left, FWIW and instead of transforming the sidebar, would just open a dired buffer from the current sidebar directory instead.

jojojames avatar Mar 20 '19 01:03 jojojames

I see, both will be fine for me now. In my previous example, add a keybinding to open new dired buffer is also easy.

And Because display-buffer-in-side-window always (set-window-parameter window 'window-slot slot) which will cause "Cannot make side window the only window" error when delete-other-windows called. So I think there may be something related.

The code to use window--display-buffer is similar. Like this:

  (let* ((width 40)
         (window (ignore-errors (split-window (frame-root-window) (- width) 'left)))
         (buffer (or (dired-sidebar-get-or-create-buffer
                      (dired-sidebar-get-dir-to-show)))))
    (when window
      (window--display-buffer buffer window 'window)
      window))

You could decide it~

BTW: @BooAA I wrote a similar extension called dired-toggle , it's not powerful like dired-sidebar but more lightweight, maybe helps for your emacs 27 :)

fasheng avatar Mar 20 '19 05:03 fasheng

On emacs27 (commit : fbe87d0f8f8878b30b1dfe74f7eb369b569bab6b), pressing "a" (dired-find-alternate-file) will not work and message with "cannot make side window the only window"

On emacs27 (commit : 020e69d992c98fd852e835c9bd707a8d137090f2), dired will create new buffer below instead of showing new directory in side window, like GIF below:

Which of these commits is newer? I can't reproduce the first issue in either emacs 26 or emacs 27 head so without an emacs -Q, I'll consider it unreproduceable.

jojojames avatar Mar 20 '19 06:03 jojojames

BTW: @BooAA I wrote a similar extension called dired-toggle , it's not powerful like dired-sidebar but more lightweight, maybe helps for your emacs 27 :)

Way cool project. Seems like it's from 2013! If I knew I would've looked to contribute to that one instead. Anyways, hope you'll stay and contribute to dired-sidebar :).

The code to use window--display-buffer is similar. Like this:

I'd wanna see the tradeoffs between the two before committing one way or the other. But maybe we can abstract out the windowing code and then creating a user option for the user to pick which approach they want to take to display the sidebar. I'd have to dig into the code a little more. Been busy with work lately!

jojojames avatar Mar 20 '19 06:03 jojojames

Yes, very old and simple project. I have given it a random name dired-toggle instead of dired-sidebar because I know someone will create a better one. Now, I find it and can't wait to see dired-sidebar became more versatile then I can deprecate my old project. :D

fasheng avatar Mar 20 '19 07:03 fasheng

Just tried out imenu-list, definitely a cool package I'll probably end up using but it functions as just a regular buffer window. Any action that messes with the windowing layout destroys the 'sidebar-ness' of the buffer. I think that'd be very annoying for dired-sidebar.

I started playing around with a custom function (not custom yet, just hardcoded) and it seems to be like it'd need some extra polish before it can be used.

;;;###autoload
(defun dired-sidebar-show-sidebar (&optional b)
  "Show sidebar displaying buffer B."
  (interactive)
  (let ((buffer (or b
                    ;; Only expect this to be hit when called interactively.
                    (dired-sidebar-get-or-create-buffer
                     (dired-sidebar-get-dir-to-show)))))
    ;; (display-buffer-in-side-window buffer dired-sidebar-display-alist)
    ;; (dired-sidebar-display-in-side-window buffer)
    (dired-sidebar-display-in-new-window buffer)
    (let ((window (get-buffer-window buffer)))
      (when dired-sidebar-no-delete-other-windows
        (set-window-parameter window 'no-delete-other-windows t))
      (set-window-dedicated-p window t)
      (with-selected-window window
        (let ((window-size-fixed))
          (dired-sidebar-set-width dired-sidebar-width))))
    (with-current-buffer buffer
      (if (eq major-mode 'dired-sidebar-mode)
          (dired-build-subdir-alist)
        (dired-sidebar-mode)))
    (dired-sidebar-update-state buffer)))

(defun dired-sidebar-display-in-side-window (buffer)
  (display-buffer-in-side-window buffer dired-sidebar-display-alist))

(defun dired-sidebar-display-in-new-window (buffer)
  (let* ((width 40)
         (window (ignore-errors (split-window
                                 (frame-root-window) (- width) 'left))))
    (when window
      (window--display-buffer buffer window 'window)
      window)))

I don't think I have the motivation to work on the window--display-buffer code/polish but I can definitely make it possible if someone wants to support it. What do you think @fasheng ?

jojojames avatar Mar 21 '19 04:03 jojojames

The topic issue is "without creating new bufers" and PR #39 will fix it.

Although we are not sure if "cannot make side window the only window" error will occurs after emacs 27 stable version released, but we discussed it now, I believe you could give a patch quickly if necessary in the future. So just feel free for window--display-buffer.

BTW: Fix a typo yesterday, 'window-side window parameter may cause the error instead of 'window-slot.

fasheng avatar Mar 21 '19 07:03 fasheng

The topic issue is "without creating new bufers" and PR #39 will fix it.

I think this PR fixes does something else. The issue described here is "don't open new buffer when using find-alternate-file" whereas I think the PR is more about "don't create extra dired buffers".

jojojames avatar May 12 '19 21:05 jojojames

I've gotten this behavior to mostly work. My testing shows normal browsing in the file tree (that is, up and down in the directory structure) generating only two Dired Sidebar buffers. Here is my Doom style configuration:

(setq dired-sidebar-one-instance-p 1)
(map! :map dired-sidebar-mode-map
      :n "DEL" #'dired-sidebar-up-directory
      :n "RET" #'dired-find-alternate-file)

From what I understand, one would use the following style in vanilla Emacs:

(setq dired-sidebar-one-instance-p 1)
(define-key dired-sidebar-mode-map (kbd "RET") 'dired-find-alternate-file)
(define-key dired-sidebar-mode-map (kbd "^") 'dired-sidebar-up-directory)

Source: http://ergoemacs.org/emacs/emacs_dired_tips.html

skyler544 avatar Aug 10 '20 19:08 skyler544