【求助】名字如*name*的buffer使用minibuffer替代

名字如*name*的buffer自动弹出来占我窗口, 改变布局, 很烦, 能不能将此类buffer改由minibuffer或者childframe接管。 诸如:*compilation* *Completions* *eldoc* 等等

(setq vmacs-ignore-buffers
      (list
       "\\` " "\*Helm" "\*helm"
       "*Launch" "\*Warnings\*"
       "\*RE-Builder\*"
       "\*dape-repl\*" "\*dape-info"
       "\*vc-diff\*" "\*magit-" "\*vc-" "\*vc*"
       "*Backtrace*" "*Package-Lint*" "\*Completions\*" "\*Compile-Log\*"
       "\*vc-change-log\*" "\*VC-log\*"
       "\*Async Shell Command\*" "\*Shell Command Output\*"
       "\*lsp" "\*ccls" "\*gopls" "\*bingo" "\*mspyls" "\*EGLOT"
       "\*sdcv\*" "\*tramp"  "\*Gofmt Errors\*"
       "\*Ido Completions\*" "\*Flycheck " "\*Flymake"
       "magit-process" "magit-diff" "magit-stash"))

(defvar boring-window-modes
  '(help-mode compilation-mode log-view-mode log-edit-mode
              gnus-article-mode
              org-agenda-mode magit-revision-mode ibuffer-mode))


(defun vmacs-filter(buf &optional ignore-buffers)
  (cl-find-if
   (lambda (f-or-r)
     (string-match-p f-or-r buf))
   (or ignore-buffers vmacs-ignore-buffers)))



(defun bury-boring-windows(&optional bury-cur-win-if-boring)
  "close boring *Help* windows with `C-g'"
  (let ((opened-windows (window-list))
        (cur-buf-win (get-buffer-window)))
    (dolist (win opened-windows)
      (with-current-buffer (window-buffer win)
        (when (or (memq  major-mode boring-window-modes)
                  (vmacs-filter (buffer-name)))
          (when (and (>  (length (window-list)) 1)
                     (not (minibufferp))
                     (or bury-cur-win-if-boring
                         (not (equal cur-buf-win win)))
                     (delete-window win))))))))

(defun vmacs-bury-boring-windows ()
  (when (active-minibuffer-window)
    (select-window (active-minibuffer-window))
    (minibuffer-keyboard-quit))
  (when (equal last-command 'keyboard-quit)
    (bury-boring-windows)))

(advice-add 'keyboard-quit :before #'vmacs-bury-boring-windows)

我的解决办法 两次C-g

我抄了 @seagle0128 大佬的配置,用 popper 管理

可以控制跳出的 buffer 是否被 select,并且可以用 C-g 关闭这些 buffer

(use-package popper
  :straight t
  :bind (:map popper-mode-map
              ("C-M-<tab>"   . popper-cycle)
              ("M-`" . popper-toggle-type))
  :hook (emacs-startup . popper-mode)
  :init
  (setq +popper-reference-buffers-select
        '("\\*Messages\\*"
          "Output\\*$" "\\*Pp Eval Output\\*$"
          "\\*Compile-Log\\*"
          "\\*Completions\\*"
          "\\*Async Shell Command\\*"
          "\\*Apropos\\*"
          "\\*Backtrace\\*"
          "\\*Calendar\\*"
          "\\*Embark Actions\\*"
          "\\*Finder\\*"
          "\\*Kill Ring\\*"
          "\\*Go-Translate\\*"

          bookmark-bmenu-mode
          comint-mode
          compilation-mode
          ibuffer-mode
          help-mode
          tabulated-list-mode
          Buffer-menu-mode
          flymake-diagnostics-buffer-mode

          grep-mode occur-mode rg-mode
          osx-dictionary-mode

          "^\\*Process List\\*" process-menu-mode
          list-environment-mode cargo-process-mode

          "^\\*eshell.*\\*.*$" eshell-mode
          "^\\*shell.*\\*.*$"  shell-mode
          "^\\*terminal.*\\*.*$" term-mode
          "^\\*vterm.*\\*.*$"  vterm-mode
          "^\\*eldoc.*\\*.*$" eldoc-mode

          "\\*package update results\\*$" "\\*Package-Lint\\*$"
          "\\*[Wo]*Man.*\\*$"
          "\\*ert\\*$" overseer-buffer-mode
          "\\*gud-debug\\*$"
          "\\*quickrun\\*$"
          "\\*vc-.*\\*$"
          "^\\*macro expansion\\**"
          reb-mode

          "\\*Agenda Commands\\*" "\\*Org Select\\*" "\\*Capture\\*" "^CAPTURE-.*\\.org*"
          "\\*Graphviz Preview: .*\\*"

          "^GPTel-popup: .*"

          (lambda (buffer) (with-current-buffer buffer (derived-mode-p 'compilation-mode)))
          ))
  (setq +popper-reference-buffer-no-select
        '("\\*Warnings\\*"))
  (setq popper-reference-buffers (append +popper-reference-buffers-select
                                         +popper-reference-buffer-no-select))
  :config
  ;; mode-line indicator
  (with-eval-after-load 'popper
    (setq popper-mode-line
          '(:eval `(:propertize " POP |"
                                face (:inherit ,(+mode-line-get-window-name-face)
                                               :inverse-video ,(mode-line-window-selected-p))))))

  ;; Enable indicator in minibuffer
  (popper-echo-mode 1)

  ;; HACK: close popper with `C-g'
  (defadvice! +popper-close-window-hack (&rest _)
    :before #'keyboard-quit
    (when (and (called-interactively-p 'interactive)
               (not (region-active-p))
               popper-open-popup-alist)
      (let ((window (caar popper-open-popup-alist)))
        (when (window-live-p window)
          (delete-window window)))))

  ;; HACK: do not select window in `+popper-reference-buffer-no-select'
  (defvar +popper-unpacked-vars '(popper--reference-names
                                  popper--reference-modes
                                  popper--reference-predicates
                                  popper--suppressed-names
                                  popper--suppressed-modes
                                  popper--suppressed-predicates))
  (defvar +popper-unpacked-vars-no-select '())

  (dolist (var +popper-unpacked-vars)
    (let ((var-name (intern (concat "+" (symbol-name var) "-no-select"))))
      (eval
       `(progn
          (defvar ,var-name nil)
          (push ',var-name +popper-unpacked-vars-no-select)))))
  (setq +popper-unpacked-vars-no-select (reverse +popper-unpacked-vars-no-select))

  (cl-progv `(popper-reference-buffers ,@+popper-unpacked-vars)
      (list +popper-reference-buffer-no-select)
    (popper--set-reference-vars)
    (cl-loop for var in +popper-unpacked-vars
             for var-no-select in +popper-unpacked-vars-no-select
             do (eval `(setq ,var-no-select ',(symbol-value var))))
    )

  (defun +popper-smart-popup-at-bottom (buffer &optional alist)
    (let ((window (popper-display-popup-at-bottom buffer alist)))
      (unless (cl-progv +popper-unpacked-vars
                  (mapcar #'symbol-value +popper-unpacked-vars-no-select)
                (popper-popup-p buffer))
        (select-window window))))
  (setq popper-display-function #'+popper-smart-popup-at-bottom)
  )
3 个赞