3

在 Emacs 21.x 中,我不知道是通过对拆分窗口的特定自定义还是由于 Emacs 的不同默认行为,除了拆分窗口之外还调用了以下拆分窗口,它在非聚焦中切换了缓冲区窗口到下一个缓冲区。

目前(Emacs 24.x),split-window 和兄弟姐妹 split-window-below 和 split-window-right 似乎不允许这样的自定义。这是真的?

如果是这样,如何调整 Emacs 以具有这种行为?重新定义 split-window 或 split-window-below 和 split-window-right 以在非聚焦窗口上切换到下一个的额外步骤。这可以通过以下建议来完成:

(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))

使用 lawlist 指示的更正,这些更正已经在建议上方可用,并且我得到了预期的行为,但不能自定义旧行为。

4

1 回答 1

3

为了回答这个问题,原始发布者可能想尝试更改below发布代码中单词的拼写。


该函数在当前版本的 Emacs Trunk 中添加了三行代码(在末尾),split-window-below并将函数重命名lawlist-split-window-belowdefalias. 一个右括号被移到函数的末尾,以允许使用在let函数中更远处定义的两个绑定。如果用户希望将注意力集中在new-window(退出函数后),那么只需删除最后一行代码(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)
于 2013-10-10T15:44:03.403 回答