I'm new to persp-mode and don't fully understand its API, noticed that the Magit buffers are restored and set to fundamental-mode when restarting Emacs, and the list of these buffers grows as I work on different projects, I would like to have these buffers added automatically by persp-mode to the nil perspective.

screenshot of ivy-switch showing magit buffers

Here is my current configuration for persp-mode:

;; parte de esta configuracion fue extraida de
;; https://pastebin.com/raw/Q1hK8cwi
;; fuente: https://www.reddit.com/r/emacs/comments/d66s8r/how_to_get_the_most_from_perspectiveel/f0r42ch/
(use-package persp-mode
  :after (ivy)
   (append ivy-sort-functions-alist
           '((persp-kill-buffer . nil)
             (persp-remove-buffer . nil)
             (persp-add-buffer . nil)
             (persp-switch . nil)
             (persp-window-switch . nil)
             (persp-frame-switch . nil))))
  (wg-morph-on nil)
  (persp-autokill-buffer-on-remove 'kill-weak)
  (persp-keymap-prefix nil)
  :bind (:map global-map ("C-x x" . hydra-persp/body))
  (after-init . (lambda () (persp-mode 1)))
  (add-hook 'ivy-ignore-buffers  #'(lambda (b)
                                     (when persp-mode
                                       (let ((persp (get-current-persp)))
                                         (if persp
                                             (not (persp-contain-buffer-p b persp))
  (defmacro hfj-make-tab (name &rest body)
    "Select an existing tab, or create one and configure it."
      ((persp-with-name-exists-p ,name)
       (persp-switch ,name))
       (persp-switch ,name)

  (defun hfj-make-tab-f (name setup-actions)
    "Select an existing tab, or create one and configure it."
     ((persp-with-name-exists-p name)
      (persp-switch name))
      (persp-switch name)
      (funcall setup-actions))))

  (defun define-layout-inner (name f)
    "Add layout config to hfj-predefined-layouts"
    (setq hfj-predefined-layouts
          (delete-if (lambda (a) (string-equal (car a) name))
    (push (list* name (cons name f)) hfj-predefined-layouts)
    (setq hfj-predefined-layouts
          (sort hfj-predefined-layouts
                (lambda (a b) (string< (car a) (car b))))))

  (defmacro hfj-define-layout (name &rest body)
    "Add layout config to hfj-predefined-layouts"
    `(define-layout-inner ,name (lambda () ,@body)))

  (defun hfj-pick-layout ()
    "Switch to a new or existing layout."
    (let* ((names (persp-names))
           (name (completing-read "Cambiar a maqueta: " names))
           (exists (persp-with-name-exists-p name)))
      (persp-switch name)
      (unless exists
        (switch-to-buffer "*scratch*"))))

  (defvar hfj-predefined-layouts '())

  (defun hfj-pick-predefined-layout ()
    "Create a predefined layout to be selectable from list."
    (when (null hfj-predefined-layouts)
      (error "No hay maquetas configuradas."))

    (let ((layout-name-and-actions (ivy-read :prompt "Seleccionar maqueta predefinida: " :collection hfj-predefined-layouts :require-match t)))

      (when layout-name-and-actions
        (hfj-make-tab-f (car layout-name-and-actions) (cdr layout-name-and-actions)))))

  (defun hfj-persp-kill-current ()
    (let ((persp (get-current-persp)))
      (cond ((null persp) (error "No se puede matar la maqueta por defecto"))
            (t (persp-kill (persp-name persp))))))

  (defun hfj-persp-switch-to-n (n)
    (let ((names (persp-names-current-frame-fast-ordered))
          (count 1))
      (dolist (name names)
        (when (= count n)
          (persp-switch name))
        (cl-incf count))))
  (defun hfj-persp-switch-to-1 () (interactive) (hfj-persp-switch-to-n 1))
  (defun hfj-persp-switch-to-2 () (interactive) (hfj-persp-switch-to-n 2))
  (defun hfj-persp-switch-to-3 () (interactive) (hfj-persp-switch-to-n 3))
  (defun hfj-persp-switch-to-4 () (interactive) (hfj-persp-switch-to-n 4))
  (defun hfj-persp-switch-to-5 () (interactive) (hfj-persp-switch-to-n 5))
  (defun hfj-persp-switch-to-6 () (interactive) (hfj-persp-switch-to-n 6))
  (defun hfj-persp-switch-to-7 () (interactive) (hfj-persp-switch-to-n 7))
  (defun hfj-persp-switch-to-8 () (interactive) (hfj-persp-switch-to-n 8))
  (defun hfj-persp-switch-to-9 () (interactive) (hfj-persp-switch-to-n 9))
  (defun hfj-persp-switch-to-10 () (interactive) (hfj-persp-switch-to-n 10))

  (defun hydra-perse-names ()
    (let ((names (persp-names-current-frame-fast-ordered))
          (current-name (safe-persp-name (get-current-persp)))
          (parts '())
          (count 1))
      (dolist (name names (s-join " | " (nreverse parts)))
        (cond ((eq name current-name)
               (push (format "[%d:%s]" count name) parts))
               (push (format "%d:%s" count name) parts)))
        (cl-incf count))))
  :hydra (hydra-persp (:hint nil)
Maquetas %s(hydra-perse-names)

^Navegación^      ^Selección^       ^Acciones^       ^Buffers^
_n_: sig.         _l_: escoger       _d_: borrar     _a_: agregar buffer
_p_: prev.        _L_: predefinido   _r_: renombrar
                      ("q" nil)
                      ("a" persp-add-buffer :exit t)
                      ("d" hfj-persp-kill-current)
                      ("l" hfj-pick-layout :exit t)
                      ("L" hfj-pick-predefined-layout :exit t)
                      ("r" persp-rename :exit t)
                      ("n" persp-next)
                      ("p" persp-prev)
                      ("1" hfj-persp-switch-to-1 :exit t)
                      ("2" hfj-persp-switch-to-2 :exit t)
                      ("3" hfj-persp-switch-to-3 :exit t)
                      ("4" hfj-persp-switch-to-4 :exit t)
                      ("5" hfj-persp-switch-to-5 :exit t)
                      ("6" hfj-persp-switch-to-6 :exit t)
                      ("7" hfj-persp-switch-to-7 :exit t)
                      ("8" hfj-persp-switch-to-8 :exit t)
                      ("9" hfj-persp-switch-to-9 :exit t)
                      ("0" hfj-persp-switch-to-10 :exit t)))

(use-package persp-mode-projectile-bridge
  :straight (persp-mode-projectile-bridge :type git :host github :repo "Bad-ptr/persp-mode-projectile-bridge.el")
  :hook ((persp-mode-projectile-bridge-mode . (lambda () (if persp-mode-projectile-bridge-mode
         (after-init . (lambda () (persp-mode-projectile-bridge-mode 1)))))

1 Answer 1


Check out this commimt from the repo seagle0128/.emacs.d.

It adds a filter function into the list persp-filter-save-buffers-functions to do filtering magit buffers. So, we can use the below example to config the persp-mode.

(add-to-list 'persp-filter-save-buffers-functions
             (lambda (b)
               "Ignore temporary buffers."
               (let ((bname (file-name-nondirectory (buffer-name b))))
                 (or (string-prefix-p "magit" bname)
                     (string-equal "*ansi-term*" bname)
                     (string-prefix-p "*" bname)
                     ;; and more
  • 2
    This is a link-only answer, please make sure the answer is useful even if your links go dead
    – Stefan
    Oct 29, 2020 at 12:44
  • What @stefan said. Please summarize here the content linked to that actually provides the answer.
    – Drew
    Oct 29, 2020 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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