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

比如 SPC a p 打开进程管理界面,焦点仍然在当前 buffer,我要退出还得先切换窗口,然后按 q,有没有不用切换窗口就可以退出 buffer 的方法(注意不是关闭窗口,只是退出 buffer 然后恢复那个窗口原来的 buffer)

我知道一种方法是 winner-undo,绑定在 SPC w u,但是感觉有点不够直观,而且并没有退出 buffer 只是隐藏了起来。

EDIT:好吧 q 也不算退出,也是把 buffer 隐藏了起来。

可以尝试 shackle

1 个赞

看着挺复杂的,不会和 window-purpose 一样耗资源吧?

目前我用起来没什么问题

换电脑了,虚拟机上总要考虑性能,现在不用管它了。想尝试一下 shackle,等试过了贴心得,欢迎大家交流补充。

试了一下,没什么用

  (require 'shackle)
  (setq shackle-rules '((process-menu-mode :select t)))
  (shackle-mode 1)

还是说我用错了?

上面代码目的是选中弹出的查看进程窗口

目前最可靠的方法还是 SPC w u

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 个赞

我刚才试了没有用,难道是 spacemacs 的原因,等下我再用 Vanilla emacs 试试

我给的代码是 如果新建window, C-g 之后就关掉的, 如果要改成恢复之前的buffer的话需要改动下