1

I'm trying to open Deft in the left sidebar using this code:

(setq display-buffer-alist
       '(("*Deft*"
          (display-buffer-in-side-window)
          (window-width . 0.25)
          (side . left)
          (slot . 0))))

This is not working and every time I call M-x deft, it shows in the main window.

What's wrong with my code? Has anyone had success in running Deft in the sidebar?

2
  • Your regexp doesn't match, try escaping the * it should be like this "\\*Deft\\*"
    – C11g
    May 30 at 10:03
  • I tried this before, doesn't change anything. Deft shows in the main window. May 30 at 10:37
2

Here's the definition of deft (version 20210101.1519 on MELPA)

(defun deft ()
  "Switch to *Deft* buffer and load files."
  (interactive)
  (switch-to-buffer deft-buffer)
  (if (not (eq major-mode 'deft-mode))
      (deft-mode)))

So it uses your current window, then switch to a buffer with a name of the value of deft-buffer variable, "\*Deft\*" by default, then call deft-mode. This means that it doesn't create a new window, so setting display-buffer-alist does nothing. (Hope this is clear enough.)

You can probably write this in function advice, I prefer to not do this because of reasons. So here is a new function

(defun deft-side-window ()
  (interactive)
  (let ((dummy-buf (generate-new-buffer deft-buffer)))
    (with-current-buffer dummy-buf
      (deft-mode))
    (display-buffer dummy-buf)))

Firstly, it creates a new buffer named after the variable deft-buffer, call deft-mode then having Emacs try to display it, with this, it respects your display-buffer-alist.

Here's another version with your window rules if you want to do it manually.

(defun deft-side-window ()
  (interactive)
  (let ((dummy-buf (generate-new-buffer deft-buffer)))
    (with-current-buffer dummy-buf
      (deft-mode))
    (display-buffer-in-side-window dummy-buf
                   '((side . left)
                 (slot . 0)
                 (window-width . 0.25))))))
  

I messed up the formatting but it works! Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.