Dedicated window for dired mode in Emacs?
Asked Answered
C

3

5

I have emacs behaving more or less how I want it to by using this common bit of elisp:

(defun toggle-current-window-dedication ()
 (interactive)
 (let* ((window    (selected-window))
        (dedicated (window-dedicated-p window)))
   (set-window-dedicated-p window (not dedicated))
   (message "Window %sdedicated to %s"
            (if dedicated "no longer " "")
            (buffer-name))))

(global-set-key [pause] 'toggle-current-window-dedication)

Unfortunately, dired uses the directory for the buffer name, so dedicating a dired window only dedicates it to that directory. Once you navigate up or down, it opens a new buffer in a separate window. What I would like to do is dedicate a window to a major mode (dired in this case), and have all new buffers that default to that mode prefer that window. Is this possible?

Coleoptile answered 22/11, 2010 at 10:52 Comment(0)
H
4

Try using your code in combination with dired-single, which will cause all dired navigation to happen within a single buffer named *dired*. In the interests of full disclosure, I wrote dired-single.

Hooked answered 25/11, 2010 at 14:30 Comment(3)
Unfortunately, dired-single opens the files in the same window as the *dired* buffer. While this is perfect for directories, it would be nice if files could be treated like with dired-find-file-other-window...Gayl
Joe, did this project move to github.com/crocket/dired-single? Your link is now dead.Icj
I did not move it there, but it looks like someone else did, which is OK by me. Unfortunately, I do not use Emacs any longer, so I don't have a means to support this project.Hooked
B
3

set-window-dedicated-p forces Emacs to only show that window for that buffer, the other dired buffers cannot use the same window. See the *info* page for set-window-dedicated-p:

`display-buffer' (*note Choosing Window::) never uses a dedicated window for displaying another buffer in it.

Perhaps one of the packages on the wiki page for DiredReuseDirectoryBuffer provides the functionality you're looking for...

Bordelaise answered 22/11, 2010 at 13:25 Comment(1)
Thanks, Trey. I am using dired-find-alternate-file to prevent new buffers from being opened, and I set up a same-window-regexps for dired buffers. This gets me 90% of where I want to be, but other buffers can still open in my dired window (help, completions, etc). If I had a better grasp of elisp I would just hook a regexp match for dired in a window before opening a new buffer in it. :)Coleoptile
R
0

Set the dired-kill-when-opening-new-dired-buffer emacs variable to t. For example add the following to your init.el:

(setq dired-kill-when-opening-new-dired-buffer t)

From the documentation:

If non-nil, kill the current buffer when selecting a new directory.

This variable was added, or its default value changed, in Emacs 28.1.
Rabbinate answered 8/10 at 14:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.