2014-02-22 29 views
4

我想在特定的emacs緩衝區中顯示某些內容。如果緩衝區尚未顯示在某個窗口中,我想將其顯示在當前幀的新窗口中。如果它已經顯示在某個地方,我不想把這個窗口或框架或聚焦。我嘗試過的東西: (pop-to-buffer buf nil 'norecord) 這不起作用,因爲當我處於與顯示「buf」的框架不同的框架中時,它將打開一個新窗口。 (display-buffer buf nil t) 這幾乎可以工作,但會引發顯示緩衝區的幀。我希望框架保持在後臺。emacs:如何在不切換窗口的情況下顯示緩衝區而不需要提升幀?

如何繼續?也許有一個函數來檢查一個緩衝區是否已經顯示在的某些幀中某些窗口中?

回答

2

如果我理解你的問題正確下面的函數會做你想要

(defun my-switch-to-buffer (buffer) 
    (interactive 
    (list (ido-read-buffer "Switch to buffer: "))) 
    ;; get-buffer-window (with second argument t) will return 
    ;; nil if the buffer is not open in any window across any 
    ;; frame 
    (unless (get-buffer-window buffer 0) 
    (pop-to-buffer buffer nil t))) 
+0

工程就像一個魅力,這就是我一直在尋找。 –

+0

將參數'0'而不是't'傳遞給'get-buffer-window'通常是可取的,因爲它告訴Emacs忽略其他顯示器上的幀(例如,如果您使用來自各種顯示器的單個Emacs會話和/或ttys中)。 – Stefan

+0

@Stefan,謝謝你的建議,我已經更新了答案。 – 2014-02-25 13:54:41

0

您可以嘗試(來源:http://www.chemie.fu-berlin.de/chemnet/use/info/emacs/emacs_19.html):

C-x b buffer RET 

選擇或創建一個名爲緩衝緩衝(切換到緩衝區)。

C-x 4 b buffer RET 

類似的,但在另一個窗口(切換到緩衝區其他窗口)中選擇緩衝區。

C-x 5 b buffer RET 

類似的,但在單獨的幀(切換到緩衝區其他幀)中選擇緩衝區。

而且有趣的多窗口/幀:http://www.chemie.fu-berlin.de/chemnet/use/info/emacs/emacs_20.html#SEC157

1

您正在使用什麼版本的Emacs是什麼?在Emacs 24中,display-buffer發生了很大變化,提供了幾乎無限的顯示可能性。但結果是行爲總體而言並不平凡,文件也是如此。

(和​​總是選擇緩衝區,你說你不想要的。)

這是從最近的Emacs建立display-buffer的文檔。有關更多信息,請參閱Elisp手冊。不管是否有人在這裏給你一個簡短的答案,這是足夠的,你可能想學習如何馴服display-buffer野獸。 (祝你好運。)

,---- 
| display-buffer is an interactive compiled Lisp function in 
| `window.el'. 
| 
| It is bound to C-x 4 C-o. 
| 
| (display-buffer BUFFER-OR-NAME &optional ACTION FRAME) 
| 
| Display BUFFER-OR-NAME in some window, without selecting it. 
| BUFFER-OR-NAME must be a buffer or the name of an existing 
| buffer. Return the window chosen for displaying BUFFER-OR-NAME, 
| or nil if no such window is found. 
| 
| Optional argument ACTION, if non-nil, should specify a display 
| action. Its form is described below. 
| 
| Optional argument FRAME, if non-nil, acts like an additional 
| ALIST entry (reusable-frames . FRAME) to the action list of ACTION, 
| specifying the frame(s) to search for a window that is already 
| displaying the buffer. See `display-buffer-reuse-window' 
| 
| If ACTION is non-nil, it should have the form (FUNCTION . ALIST), 
| where FUNCTION is either a function or a list of functions, and 
| ALIST is an arbitrary association list (alist). 
| 
| Each such FUNCTION should accept two arguments: the buffer to 
| display and an alist. Based on those arguments, it should 
| display the buffer and return the window. If the caller is 
| prepared to handle the case of not displaying the buffer 
| and returning nil from `display-buffer' it should pass 
| (allow-no-window . t) as an element of the ALIST. 
| 
| The `display-buffer' function builds a function list and an alist 
| by combining the functions and alists specified in 
| `display-buffer-overriding-action', `display-buffer-alist', the 
| ACTION argument, `display-buffer-base-action', and 
| `display-buffer-fallback-action' (in order). Then it calls each 
| function in the combined function list in turn, passing the 
| buffer as the first argument and the combined alist as the second 
| argument, until one of the functions returns non-nil. 
| 
| If ACTION is nil, the function list and the alist are built using 
| only the other variables mentioned above. 
| 
| Available action functions include: 
| `display-buffer-same-window' 
| `display-buffer-reuse-window' 
| `display-buffer-pop-up-frame' 
| `display-buffer-pop-up-window' 
| `display-buffer-in-previous-window' 
| `display-buffer-use-some-window' 
| 
| Recognized alist entries include: 
| 
| `inhibit-same-window' -- A non-nil value prevents the same 
|       window from being used for display. 
| 
| `inhibit-switch-frame' -- A non-nil value prevents any other 
|       frame from being raised or selected, 
|       even if the window is displayed there. 
| 
| `reusable-frames' -- Value specifies frame(s) to search for a 
|      window that already displays the buffer. 
|      See `display-buffer-reuse-window'. 
| 
| `pop-up-frame-parameters' -- Value specifies an alist of frame 
|        parameters to give a new frame, if 
|        one is created. 
| 
| `window-height' -- Value specifies either an integer (the number 
|  of lines of a new window), a floating point number (the 
|  fraction of a new window with respect to the height of the 
|  frame's root window) or a function to be called with one 
|  argument - a new window. The function is supposed to adjust 
|  the height of the window; its return value is ignored. 
|  Suitable functions are `shrink-window-if-larger-than-buffer' 
|  and `fit-window-to-buffer'. 
| 
| `window-width' -- Value specifies either an integer (the number 
|  of columns of a new window), a floating point number (the 
|  fraction of a new window with respect to the width of the 
|  frame's root window) or a function to be called with one 
|  argument - a new window. The function is supposed to adjust 
|  the width of the window; its return value is ignored. 
| 
| `allow-no-window' -- A non-nil value indicates readiness for the case 
|  of not displaying the buffer and FUNCTION can safely return 
|  a non-window value to suppress displaying. 
| 
| The ACTION argument to `display-buffer' can also have a non-nil 
| and non-list value. This means to display the buffer in a window 
| other than the selected one, even if it is already displayed in 
| the selected window. If called interactively with a prefix 
| argument, ACTION is t. 
`---- 
相關問題