如何自定义Emacs split-window-X,新窗口显示下一个缓冲区? [英] How to customize Emacs split-window-X with the new window showing the next buffer?

查看:185
本文介绍了如何自定义Emacs split-window-X,新窗口显示下一个缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Emacs 21.x中我不知道是否通过分割窗口的特定定制,或者由于Emacs的不同默认行为,除了分割窗口之外还调用了分割窗口,它将缓冲区切换到非焦点窗口到下一个缓冲区。



目前(Emacs 24.x),拆分窗口和兄弟姐妹拆分窗口下面和拆分窗口右边似乎允许这样的定制。这是真的吗?



如果是这样,如何调整Emacs有这个行为?重新定义分割窗口或拆分窗口右下角,并在非关注窗口上再次切换到下一个窗口。这可以通过建议来完成:

 (defun split-window-and-next-buffer(new-window)
(let((old-window(selected-window)))
(select-window new-window)
(next-buffer)
(select-window old-window)

(defadvice split-window-right(在split-window-right-and-next-buffer
激活保护编译之后)
(split- window-and-next-buffer ad-return-value))

(defadvice split-window-below(after split-window-bellow-and-next-buffer
activate protect compile)
(split-window-and-next-buffer ad-return-value))

使用已经在上面已经提供的法律清单指示的修正已经有效,并且我得到了预期的行为,但是不能自定义旧的行为。

解决方案

为了回答这个问题,原来的海报可能会想尝试改变g代码中拼写单词






此函数将三行代码(最后)添加到当前版本的Emacs Trunk split-window-below ,并将该函数重命名为法律列表 defalias 之间的-split-window-below。一个关闭括号被移动到函数的末尾,以允许在函数中使用两个 let 绑定。如果用户想要在新窗口(退出函数后)中的焦点,那么只需删除最后一行代码(select-window old -window)

 (defun lawlist-split-window-below(& optional size) 
将所选窗口分割成两个窗口,一个在另一个窗口之上
所选窗口位于上方,新分隔窗口为
,显示next-buffer。返回新窗口

如果可选参数SIZE被省略或无效,则两个窗口都将获得
相同的高度,或者接近它,如果SIZE为正,则
\\ \\(选择)窗口获取SIZE行,如果SIZE为负,则
lower(new)窗口将获得-SIZE行

如果变量split-window-keep-point非零,两个
窗口获得与所选窗口相同的点值
否则,选择窗口启动以最小化重新显示的
数量;这在缓慢的时候很方便终端
(交互式P)
(let((old-window(selected-window))
(old-point(window-point))
(size(and size(prefix-numeric-值大小)))
move-by-window-height move new window bottom)
(when(and size(<大小0)(<( - size)window-min-height))
;; `split-window'不会在这里发出错误信号。
(错误新窗口的大小太小))
(setq new-window(分割窗口大小))
(除非split-window-keep-point
(with-current-buffer(window-buffer)
;;在
;;(Bug#10971)之下的垂直移动周围使用`save-excursion'注意:当所选窗口的缓冲区有
;;标题行,最多两行缓冲区可能不会在结果配置中显示
;;
(save-excursion
(goto-char(window-start) )
(setq moved(vertical-motion(window-height)))
(set-window-start new-window(point))
(when(>(point) - 新窗口))
(set-window-point new-window(point)))
(when(= moved(window-height))
(setq moved-by-窗口高度t)
(垂直运动-1))
(setq bottom(point)))
(和move-by-window-height
(< = bottom(point))
(set-window-point old-window (1- bottom)))
(和move-by-window-height
(< =(window-start new-window)old-point)
(set-window-point new-window old-point)
(select-window new-window)))
;;始终在交互式使用中复制quit-restore参数。
(let((quit-restore(window-parameter old-window'quit-restore)))
(当quit-restore
(set-window-parameter new-window'
(select-window new-window)
(下一个缓冲区)
(select-window old-window)))

(defalias'split-window-below'lawlist-split-window-below)


In Emacs 21.x I don't know if via a specific customization of split-window or due to a different default behaviour by Emacs, invoking the split-window-below besides splitting the window, it switched the buffer in the non-focused window to the next buffer.

Currently (Emacs 24.x), the split-window and siblings split-window-below and split-window-right don't seem to allow such a customization. Is this true?

If so, how to tweak Emacs to have this behaviour? Redefining split-window or split-window-below and split-window-right to have an extra step of switching to the next on the non-focused window. This could be done with advices:

(defun split-window-and-next-buffer (new-window)
  (let ((old-window (selected-window)))
    (select-window new-window)
    (next-buffer)
    (select-window old-window)
    new-window))

(defadvice split-window-right (after split-window-right-and-next-buffer
                     activate protect compile)
  (split-window-and-next-buffer ad-return-value))

(defadvice split-window-below (after split-window-bellow-and-next-buffer
                      activate protect compile)
  (split-window-and-next-buffer ad-return-value))

With the corrections indicated by lawlist which are already available above the advices already work and I get the intended behaviour, but it isn't customizable to have the old behaviour.

解决方案

In response to the question, the original poster might want try changing the spelling of the word below within the code posted.


This function adds three lines of code (at the end) to the current version of Emacs Trunk split-window-below and renames the function to lawlist-split-window-below with a defalias. One closing parentheses was moved to the end of the function to permit using two of the let bindings defined farther up in the function. If the user wants focus in the new-window (after exiting the function) instead, then just remove the last line of code (select-window old-window).

(defun lawlist-split-window-below (&optional size)
  "Split the selected window into two windows, one above the other.
The selected window is above.  The newly split-off window is
below, and displays the 'next-buffer'.  Return the new window.

If optional argument SIZE is omitted or nil, both windows get the
same height, or close to it.  If SIZE is positive, the upper
\(selected) window gets SIZE lines.  If SIZE is negative, the
lower (new) window gets -SIZE lines.

If the variable `split-window-keep-point' is non-nil, both
windows get the same value of point as the selected window.
Otherwise, the window starts are chosen so as to minimize the
amount of redisplay; this is convenient on slow terminals."
  (interactive "P")
  (let ((old-window (selected-window))
    (old-point (window-point))
    (size (and size (prefix-numeric-value size)))
        moved-by-window-height moved new-window bottom)
    (when (and size (< size 0) (< (- size) window-min-height))
      ;; `split-window' would not signal an error here.
      (error "Size of new window too small"))
    (setq new-window (split-window nil size))
    (unless split-window-keep-point
      (with-current-buffer (window-buffer)
    ;; Use `save-excursion' around vertical movements below
    ;; (Bug#10971).  Note: When the selected window's buffer has a
    ;; header line, up to two lines of the buffer may not show up
    ;; in the resulting configuration.
    (save-excursion
      (goto-char (window-start))
      (setq moved (vertical-motion (window-height)))
      (set-window-start new-window (point))
      (when (> (point) (window-point new-window))
        (set-window-point new-window (point)))
      (when (= moved (window-height))
        (setq moved-by-window-height t)
        (vertical-motion -1))
      (setq bottom (point)))
    (and moved-by-window-height
         (<= bottom (point))
         (set-window-point old-window (1- bottom)))
    (and moved-by-window-height
         (<= (window-start new-window) old-point)
         (set-window-point new-window old-point)
         (select-window new-window)))
    ;; Always copy quit-restore parameter in interactive use.
    (let ((quit-restore (window-parameter old-window 'quit-restore)))
      (when quit-restore
    (set-window-parameter new-window 'quit-restore quit-restore)))
    new-window)
  (select-window new-window)
  (next-buffer)
  (select-window old-window)))

(defalias 'split-window-below 'lawlist-split-window-below)

这篇关于如何自定义Emacs split-window-X,新窗口显示下一个缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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