2016-04-08 80 views
3

每當我在emacs中執行apropos,describe-key或其他一些幫助功能時,它會在我的其他窗口中顯示幫助。爲了擺脫它,我必須更改窗口/緩衝區去那裏,鍵入「q」,然後回到我的原始工作緩衝區。emacs從原始緩衝區調度幫助窗口

有沒有一種方法可以以某種方式在代碼中執行此操作?我知道如何保存偏移,切換緩衝區等,但我不知道如何在另一個緩衝區中結束時將「q」發送到minibuffer/emacs。謝謝

+0

幫助緩衝區具有'help-window-select',如下所述。一般來說,你可能對枷鎖包(https://github.com/wasamasa/shackle)感興趣。 – jpkotta

回答

1

這是我對這個問題的解決方案。我將此命令綁定到C-c q

(defvar my/help-window-names 
    '(
    ;; Ubiquitous help buffers 
    "*Help*" 
    "*Apropos*" 
    "*Messages*" 
    "*Completions*" 
    ;; Other general buffers 
    "*Command History*" 
    "*Compile-Log*" 
    "*disabled command*") 
    "Names of buffers that `my/quit-help-windows' should quit.") 

(defun my/quit-help-windows (&optional kill frame) 
    "Quit all windows with help-like buffers. 

Call `quit-windows-on' for every buffer named in 
`my/help-windows-name'. The optional parameters KILL and FRAME 
are just as in `quit-windows-on', except FRAME defaults to t (so 
that only windows on the selected frame are considered). 

Note that a nil value for FRAME cannot be distinguished from an 
omitted parameter and will be ignored; use some other value if 
you want to quit windows on all frames." 
    (interactive) 
    (let ((frame (or frame t))) 
    (dolist (name my/help-window-names) 
     (ignore-errors 
     (quit-windows-on name kill frame))))) 
+0

有趣的解決方案 - 不要用「q」與緩衝區交談,與Emacs交談並說「殺死所有這些人」。並且可擴展,這很好。感謝您貢獻您的代碼。 – Kevin

3

help-window-select變量可能正是你想要的。 如果您將其值設置爲true (setq help-window-select t),那麼當您通過其中一個幫助命令打開幫助窗口時,將自動選擇幫助窗口。然後您可以按q退出並返回原始緩衝區。還有很多其他的選擇,所以你應該檢查這些。

對於apropos窗口或任何使用display-buffer的窗口,您可以使用。

(add-to-list 'display-buffer-alist 
     '("*Apropos*" display-buffer-same-window)) 

display-buffer-same-window是許多選項之一;它會在當前窗口中打開緩衝區。查看display-buffer函數的文檔可以看到其他可能的選項。

+0

謝謝你的快速,準確的目標回覆!我們在那裏。設置變量確實可以解決describe-key的問題,但不能解決Apropos顯示問題。我檢查了等效的apropos變量(describe-variable apropos),但沒有一個看起來像幫助窗口選擇。想法? – Kevin

+0

對不起,延遲重播,我編輯我的答案與apropos緩衝區的一些信息。我使用一個類似的命令在當前窗口中打開一個shell,而不是在另一個窗口中打開。希望能幫助到你。 – Jules

+0

謝謝Jules。我想最好讓它覆蓋我目前的緩衝區,因爲很容易以這種方式進行調度。比不得不去那邊並輸入q ...再次感謝你。 – Kevin

0

我建議把(winner-mode 1)在你的init文件,然後使用C-C<左>調用winner-undo(反覆,如果需要的話)返回到上一個窗口的配置。

+0

是的,謝謝你的提示。我已經有了贏家模式(但奇怪的是,很少使用它,因爲ctrl-x o的舊習慣很難實現......)在Emacs的底層有很多緩衝/窗口魔法。我不知道爲什麼Apropos不算作幫助窗口 - 它以相同的方式發送(用q)。好吧。我現在有一些工作,所以對其他事情。 – Kevin

+0

'apropos-mode'和'help-mode'是不同的主要模式。然而,它們都是從'special-mode'(它提供了鍵綁定)派生而來的。 – phils

+0

YMMV,但我只能建議習慣於使用'winner-undo'(也許將它綁定到稍微簡單的按鍵序列,如果有幫助的話)。我發現它對於類似於這個問題的所有問題的一般化解決方案來說是非常寶貴的,同時也便於恢復我故意製作的窗口更改。 – phils