Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dedicated window for dired mode in Emacs?

Tags:

emacs

elisp

dired

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?

like image 603
Parker Ault Avatar asked Nov 22 '10 10:11

Parker Ault


2 Answers

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.

like image 142
Joe Casadonte Avatar answered Oct 06 '22 00:10

Joe Casadonte


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...

like image 40
Trey Jackson Avatar answered Oct 05 '22 22:10

Trey Jackson