2013-10-10 12 views
3

在Emacs 21.x我不知道是否通過特定的拆分窗口定製或由於Emacs的不同默認行爲,除了拆分窗口調用拆分窗口下面,它切換非緩衝區專注窗口到下一個緩衝區。如何使用顯示下一個緩衝區的新窗口定製Emacs split-window-X?

當前(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) 
    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指示的修正,現已可在上述建議已經工作,我得到預期的行爲,但它不是定製的有舊的行爲。

+0

使用Emacs幹線的最新版本內置了前幾天,'分裂窗口below'垂直分割窗口,並在同一緩衝出現在兩個窗口 - '拆分選擇窗口分爲兩個窗口,一個高於另一個。所選窗口在上方。新分割的窗口在下面,並顯示相同的緩衝區。返回新窗口.'。順便說一句 - 你幾次拼寫錯誤。 – lawlist

+0

@lawlist,感謝您的回答並指出錯誤。我已經更新了這個問題,現在我的簡單的基於建議的解決方案已經可行 – euluis

回答

3

爲了迴應這個問題,原始海報可能想要在發佈的代碼中嘗試更改單詞below的拼寫。


該函數添加的代碼三行(末尾)Emacs的中繼線split-window-below的當前版本和重命名與一個defalias的功能lawlist-split-window-below。將一個右括號移到該函數的末尾,以允許使用定義在函數更遠處的兩個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) 
相關問題