想问一下大家都是怎样退出弹出的 buffer 的?

shackle 只对 display-buffer-alist 定制了一下, 不能直接关 buffer. :select t 会在打开buffer后自动选中, 原来是不自动选中那个 buffer 的.

我目前的配置:

;; 记录所有的 popup windows
(defvar shackle--popup-window-list nil)
;; 当前的 popup window
(defvar-local shackle--current-popup-window nil)
(put 'shackle--current-popup-window 'permanent-local t)

(defun shackle-display-buffer-hack (fn buffer alist plist)
  (let ((window (funcall fn buffer alist plist)))
    (setq shackle--current-popup-window window)

    ;; 定制更多规则 ...

    (when (plist-get plist :autoclose)
      (push (cons window buffer) shackle--popup-window-list))
    window))

(defun shackle-close-popup-window-hack (&rest _)
  "按 C-g 之后 关闭当前的 popup window"
  (setq shackle--popup-window-list
        (loop for (window . buffer) in shackle--popup-window-list
              if (and (window-live-p window)
                      (equal (window-buffer window) buffer))
              collect (cons window buffer)))
  ;; `C-g' can deactivate region
  (when (and (called-interactively-p 'interactive)
             (not (region-active-p)))
    (let (window buffer)
      (if (one-window-p)
          (progn
            (setq window (selected-window))
            (when (equal (buffer-local-value 'shackle--current-popup-window
                                             (window-buffer window))
                         window)
              (winner-undo)))
        (setq window (caar shackle--popup-window-list))
        (setq buffer (cdar shackle--popup-window-list))
        (when (and (window-live-p window)
                   (equal (window-buffer window) buffer))
          (delete-window window)

          (pop shackle--popup-window-list))))))

(advice-add 'keyboard-quit :before #'shackle-close-popup-window-hack)
(advice-add 'shackle-display-buffer :around #'shackle-display-buffer-hack)

(setq shackle-default-alignment 'below
      shackle-default-size 0.5
      shackle-default-rule nil
      shackle-rules
      '((process-menu-mode :select t :autoclose t)))

模仿 doom-emacs 之前的 popup 系统

1 个赞