3

Emacs 21.x では、split-window の特定のカスタマイズによるものなのか、それとも 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))

アドバイスの上で既に利用可能な法リストによって示されている修正により、すでに機能しており、意図した動作が得られますが、古い動作を持つようにカスタマイズすることはできません。

4

1 に答える 1

3

below質問に答えて、元の投稿者は、投稿されたコード内の単語のスペルを変更してみてください。


この関数は、現在のバージョンの Emacs トランクに (最後に) 3 行のコードを追加split-window-belowし、関数の名前lawlist-split-window-belowdefalias. 閉じ括弧の 1 つが関数の最後に移動letされ、関数内で定義されている 2 つのバインドを使用できるようになりました。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 に答える