Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make this Emacs frame keep its buffer and not get resized?

Tags:

emacs

My Emacs frame looks like this:

+---------------------------+
|             |             |
|             |             |
|             |      B      |
|      A      |             |
|             |             |
|             |             |
|             |-------------|
|             |      C      |
+---------------------------+

C is usually a terminal with some kind of long-running process, like a web server or daemon. Unfortunately, all sorts of things like to switch the buffer in that window and occasionally it gets resized. How can I lock the buffer and height of window C?

like image 282
a paid nerd Avatar asked Mar 01 '11 07:03

a paid nerd


People also ask

Can you only have one buffer open in Emacs at a time?

Each Emacs window displays one Emacs buffer at any time. A single buffer may appear in more than one window; if it does, any changes in its text are displayed in all the windows where it appears.

What are Emacs buffers?

Buffers in Emacs editing are objects that have distinct names and hold text that can be edited. Buffers appear to Lisp programs as a special data type. You can think of the contents of a buffer as a string that you can extend; insertions and deletions may occur in any part of the buffer.

How do I change the buffer in Emacs?

To move between the buffers, type C-x b. Emacs shows you a default buffer name. Press Enter if that's the buffer you want, or type the first few characters of the correct buffer name and press Tab. Emacs fills in the rest of the name.

How do I use buffers in Emacs?

Most buffers are created by visiting files, or by Emacs commands that want to display some text, but you can also create a buffer explicitly by typing C-x b bufname <RET> . This makes a new, empty buffer that is not visiting any file, and selects it for editing. Such buffers are used for making notes to yourself.


2 Answers

If you don't want to be annoyed by window stealing and resizing, put the following lines in your .emacs for a definitive solution that works even with libraries like gud that tries to open a new frame when they can't steal your windows :

(see this answer for info on the following advice)

(defadvice pop-to-buffer (before cancel-other-window first)   (ad-set-arg 1 nil))  (ad-activate 'pop-to-buffer)  ;; Toggle window dedication (defun toggle-window-dedicated ()   "Toggle whether the current active window is dedicated or not"   (interactive)   (message    (if (let (window (get-buffer-window (current-buffer)))          (set-window-dedicated-p window                                   (not (window-dedicated-p window))))        "Window '%s' is dedicated"      "Window '%s' is normal")    (current-buffer)))  ;; Press [pause] key in each window you want to "freeze" (global-set-key [pause] 'toggle-window-dedicated) 

and customize pop-up-windows variable to nil.

you could also use StickyWindows instead of window-dedicated feature.

like image 107
Jérôme Radix Avatar answered Oct 14 '22 09:10

Jérôme Radix


One possibility is to dedicate the window to its buffer, using set-window-dedicated-p. This will not prevent the window from being resized manually, only protect it from being clobbered by display-buffer. For example,

(add-hook 'shell-mode-hook
      (lambda ()
        (interactive)
        (set-window-dedicated-p (selected-window) 1)))

Replace shell-mode-hook as necessary.

like image 21
huaiyuan Avatar answered Oct 14 '22 11:10

huaiyuan