管理Emacs * Man *缓冲区位置? [英] Managing Emacs *Man* buffer location?

查看:185
本文介绍了管理Emacs * Man *缓冲区位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




  • 我编辑文件,需要一些帮助

  • Mx man something

  • emacs礼貌地将框架分成两个窗口,并在其中打开联机帮助页面,我看到来源和人都很好,

  • 在阅读的时候,我发现我需要进一步跟进,所以我Mx的男人另外一个。

  • emacs在以前被我的来源占用的窗口中打开新的联机帮助页面,我在屏幕上看到两个manpages不能编辑(直到我切换缓冲区)



是否可以让男人的窗口?

解决方案

适应 display-buffer-reuse-window 创建 display-buffer-reuse-major-mode-window ,我们可以使用 display-buffer-alist 来指定用于在 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
'((prohib-same-window)
(可重用框架可见)
(inhibit-switch-frame。nil)))))

(defun display-buffer-reuse-major-mode-窗口(缓冲区alist)
返回一个显示BUFFER主要模式缓冲区的窗口
如果没有找到可用的窗口,返回零

如果ALIST有一个非零的

如果ALIST包含一个`reusable-frames'条目,它的值决定
哪些帧到搜索可重复使用的窗口:
nil - 所选框架(实际上是最后一个非minibuffer框架)
一个框架 - 只是该框架
`visible' - 所有可见框架
0 - 当前终端上的所有帧
t - 所有帧

如果ALIST不包含`reusable-frames'条目,则只搜索
所选帧,如果` display-buffer-reuse-frames'和
`pop-up-frames'都为零;搜索当前
上的所有帧终端,如果这些变量中的任一个是非零。

如果ALIST具有非零的禁止切换帧条目,则在
事件中,选择另一个帧的窗口,避免提高
该帧。
(let *((alist-entry(assq'reusable-frames alist))
(frames(cond(alist-entry(cdr alist-entry))
((if(eq弹出框架的图形)
(display-graphic-p)
弹出框架)
0)
(display-buffer-reuse-frames 0 )
(t(last-nonminibuffer-frame))))
(window(let((current-buffer buffer major-mode)))
(if(and方程式(with-current-buffer(window-buffer)
major-mode))
(not(cdr(assq'inhibit-same-window alist))))
(selected-窗口)
(catch'window
(walk-windows
(lambda(w)
(和(window-live-p w))
(eq模式(with-current-buffer(window-buffer w))
主要模式))
(不(eq w(selected-window)))
(throw'window w)))
'nomini frames))))))
(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 behaviour which recently[*] started to irritate me:

  • I edit the file, and need some help
  • M-x man something
  • emacs politely splits frame into two windows and opens manpage there, I see both source and man, great
  • while reading man I find that I need to followup further, so I M-x man anothertopic
  • emacs opens new manpage in window previously occupied by my source, I see two manpages on the screen and can't edit anymore (until I switch buffer)

Is it possible to make Man prefer reuse existing man window?

解决方案

Adapting display-buffer-reuse-window to create display-buffer-reuse-major-mode-window, we can then use display-buffer-alist to specify that this be used to display buffers in Man-mode.

Obviously the first form can also be trivially modified to apply to any number of modes besides 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 * Man *缓冲区位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆