管理 Emacs *Man* 缓冲区位置?
Managing Emacs *Man* buffer location?
最近[*] 开始激怒我的 Emacs 行为:
- 我正在编辑文件,需要一些帮助
- M-x man something
- emacs 礼貌地将框架分成两个 windows 并在那里打开联机帮助页,我看到了 source 和 man,太棒了
- 在阅读 man 时,我发现我需要进一步跟进,所以我 M-x man anothertopic
- emacs 在 window 中打开了新的联机帮助页,之前被我的源占用,我在屏幕上看到两个联机帮助页并且无法再编辑(直到我切换缓冲区)
是否可以让 Man 更喜欢重用现有的 man window?
适配display-buffer-reuse-window
创建display-buffer-reuse-major-mode-window
,然后我们可以使用display-buffer-alist
指定这用于显示Man-mode
中的缓冲区。
显然,第一种形式也可以简单地修改以应用于除 Man-mode
之外的任何数量的模式。
(add-to-list 'display-buffer-alist
(cons (lambda (buffer alist)
(with-current-buffer buffer
(eq major-mode 'Man-mode)))
(cons 'display-buffer-reuse-major-mode-window
'((inhibit-same-window . nil)
(reusable-frames . visible)
(inhibit-switch-frame . nil)))))
(defun display-buffer-reuse-major-mode-window (buffer alist)
"Return a window displaying a buffer in BUFFER's major mode.
Return nil if no usable window is found.
If ALIST has a non-nil `inhibit-same-window' entry, the selected
window is not eligible for reuse.
If ALIST contains a `reusable-frames' entry, its value determines
which frames to search for a reusable window:
nil -- the selected frame (actually the last non-minibuffer frame)
A frame -- just that frame
`visible' -- all visible frames
0 -- all frames on the current terminal
t -- all frames.
If ALIST contains no `reusable-frames' entry, search just the
selected frame if `display-buffer-reuse-frames' and
`pop-up-frames' are both nil; search all frames on the current
terminal if either of those variables is non-nil.
If ALIST has a non-nil `inhibit-switch-frame' entry, then in the
event that a window on another frame is chosen, avoid raising
that frame."
(let* ((alist-entry (assq 'reusable-frames alist))
(frames (cond (alist-entry (cdr alist-entry))
((if (eq pop-up-frames 'graphic-only)
(display-graphic-p)
pop-up-frames)
0)
(display-buffer-reuse-frames 0)
(t (last-nonminibuffer-frame))))
(window (let ((mode (with-current-buffer buffer major-mode)))
(if (and (eq mode (with-current-buffer (window-buffer)
major-mode))
(not (cdr (assq 'inhibit-same-window alist))))
(selected-window)
(catch 'window
(walk-windows
(lambda (w)
(and (window-live-p w)
(eq mode (with-current-buffer (window-buffer w)
major-mode))
(not (eq w (selected-window)))
(throw 'window w)))
'nomini frames))))))
(when (window-live-p window)
(prog1 (window--display-buffer buffer window 'reuse alist)
(unless (cdr (assq 'inhibit-switch-frame alist))
(window--maybe-raise-frame (window-frame window)))))))
最近[*] 开始激怒我的 Emacs 行为:
- 我正在编辑文件,需要一些帮助
- M-x man something
- emacs 礼貌地将框架分成两个 windows 并在那里打开联机帮助页,我看到了 source 和 man,太棒了
- 在阅读 man 时,我发现我需要进一步跟进,所以我 M-x man anothertopic
- emacs 在 window 中打开了新的联机帮助页,之前被我的源占用,我在屏幕上看到两个联机帮助页并且无法再编辑(直到我切换缓冲区)
是否可以让 Man 更喜欢重用现有的 man window?
适配display-buffer-reuse-window
创建display-buffer-reuse-major-mode-window
,然后我们可以使用display-buffer-alist
指定这用于显示Man-mode
中的缓冲区。
显然,第一种形式也可以简单地修改以应用于除 Man-mode
之外的任何数量的模式。
(add-to-list 'display-buffer-alist
(cons (lambda (buffer alist)
(with-current-buffer buffer
(eq major-mode 'Man-mode)))
(cons 'display-buffer-reuse-major-mode-window
'((inhibit-same-window . nil)
(reusable-frames . visible)
(inhibit-switch-frame . nil)))))
(defun display-buffer-reuse-major-mode-window (buffer alist)
"Return a window displaying a buffer in BUFFER's major mode.
Return nil if no usable window is found.
If ALIST has a non-nil `inhibit-same-window' entry, the selected
window is not eligible for reuse.
If ALIST contains a `reusable-frames' entry, its value determines
which frames to search for a reusable window:
nil -- the selected frame (actually the last non-minibuffer frame)
A frame -- just that frame
`visible' -- all visible frames
0 -- all frames on the current terminal
t -- all frames.
If ALIST contains no `reusable-frames' entry, search just the
selected frame if `display-buffer-reuse-frames' and
`pop-up-frames' are both nil; search all frames on the current
terminal if either of those variables is non-nil.
If ALIST has a non-nil `inhibit-switch-frame' entry, then in the
event that a window on another frame is chosen, avoid raising
that frame."
(let* ((alist-entry (assq 'reusable-frames alist))
(frames (cond (alist-entry (cdr alist-entry))
((if (eq pop-up-frames 'graphic-only)
(display-graphic-p)
pop-up-frames)
0)
(display-buffer-reuse-frames 0)
(t (last-nonminibuffer-frame))))
(window (let ((mode (with-current-buffer buffer major-mode)))
(if (and (eq mode (with-current-buffer (window-buffer)
major-mode))
(not (cdr (assq 'inhibit-same-window alist))))
(selected-window)
(catch 'window
(walk-windows
(lambda (w)
(and (window-live-p w)
(eq mode (with-current-buffer (window-buffer w)
major-mode))
(not (eq w (selected-window)))
(throw 'window w)))
'nomini frames))))))
(when (window-live-p window)
(prog1 (window--display-buffer buffer window 'reuse alist)
(unless (cdr (assq 'inhibit-switch-frame alist))
(window--maybe-raise-frame (window-frame window)))))))