Can I disable window-splitting in a particular frame? - emacs

I'm a developer who uses emacs. In emacs I use multiple frames (what most people would call X windows), and the compile function for my builds. I like to have one frame for my compilation buffer, and the others for source. That allows me to navigate to build errors easily and get a nice big view of the source I'm investigating along side a nice big view of my build output. This works fine when I use the 'next-error' function from a source frame.
But when I move my pointer into the compilation frame, and click on an error, it vertically splits that frame to show the relevant source. I want it to show the relevant source in one of my other frames.
Is there a way to "lock" a frame so that it won't be split into windows, and so other frames will be used instead? I'm OK if it splits one of my other frames to display the new source files - just not the compilation frame (because that means I have to unsplit that frame and then switch the buffer of a different frame to display the buffer in question - that's cumbersome).
Alternatively it would be fine if I could use a different mouse button on an error in the compilation buffer to say "visit this file and line in a different frame".

I believe you can achieve your goals by making the window in your "compile frame" dedicated:
Functions for displaying a buffer can be told to not use specific windows by marking these windows as dedicated to their buffers.
Interactively, M-x set-window-dedicated-p should make your window dedicated.
From elisp, something like
(set-window-dedicated-p (selected-window) 1)
should do the same. Replacing 1 with t will make the window strongly dedicated:
As a special case, if flag is t, window becomes strongly dedicated to its buffer. set-window-buffer signals an error when the window it acts upon is strongly dedicated to its buffer and does not already display the buffer it is asked to display. Other functions do not treat t differently from any non-nil value.

Related

Emacs switch-to-buffer (C-x b) will change window if the buffer is opened in some other window

I would like to change the behavior of switch-to-buffer to always open the desired buffer in the current window instead of switching to another window if already opened.
My rationale for doing this :
I have 2 screens, one Emacs on each. One is for reading, the other one for writing. Some buffers will be in the reading side for a while, but now I want to edit them. I'd like to have them in front of me instead of automatically switch to this other window on the side.
Thank you.
That is what switch-to-buffer does - exactly what you say you want. Do you see something different when you start Emacs without an init file (emacs -Q)?
The only exception is when the window cannot be used for that buffer. As the doc string says:
If the selected window cannot display the specified
buffer (e.g. if it is a minibuffer window or strongly dedicated
to another buffer), call `pop-to-buffer' to select the buffer in
another window.

emacs zoom in/out globally

I know that I can zoom in/out using C-x C-+, but this applies only to the current file. Once I open another one, the text goes back to the default value and it's really tiresome to do it over and over. How can I keep the zoom level global for the current emacs session?
I know it's possible to set this in the init file if you know the exact font size, which I don't. Plus, I don't want to keep it that permanent - I usually need this when I'm without an external screen for a couple of hours or connected to a beamer while giving a presentation.
This piece of code modify the zoom in/out functionality to apply the commands to every buffer. That should achieve what you are trying to do.
(defadvice text-scale-increase (around all-buffers (arg) activate)
(dolist (buffer (buffer-list))
(with-current-buffer buffer
ad-do-it)))
All of the answers given here, and more, are available on the
EmacsWiki page dedicated to the question of setting and changing font
size, including changing it incrementally.
The answer from #abo-abo is on the right track, regardless of whether
you think the size he used in the example code was too big, and
regardless of whether the solution does not address incremental
adjustment.
The answer from #juanleon essentially makes text scaling simulate
changing the default character size (#abo-abo's answer).
The point of text scaling is to scale the buffer text (one buffer, no
matter where it is shown), not the frame text (all buffers shown in
the frame). But if you want all buffers to have their text size
changed in a given frame then there is no reason to bother with text
scaling in that case: just change the font size.
You can do either or both (scale the buffer text everywhere or zoom a
frame), and do so incrementally, using the same command, if you use
command zoom-in/out from library
zoom-frm.el.
On the other hand, if you really do want to incrementally change the
text size of all buffers in all frames, then the best approaches are
either (1) #juanleon's suggestion or (2) incrementally zoom the standard face
default.
To do the latter, you can use commands zoom-all-frames-in and
zoom-all-frames-out in library
zoom-frm.el
Just paste this in *scratch* and evaluate (with C-j or C-x C-e):
(set-face-attribute 'default nil :height 150)
There's nothing wrong in putting this in the init file
and commenting it out later, when you don't need it.
Its possible to scale all text (including status-line & line-numbers) using a little mode that handles this exact problem: purcell/default-text-scale. It's available in Melpa.
This scales all text to avoid text scale mismatch such as line-numbers of fill-column indicator being offset incorrectly.
The other answers here either don't work for new buffers or require too much manual intervention.
connected to a beamer while giving a presentation.
There is another package for that!
emacs-presentation-mode
Quoting from the site
Execute M-x presentation-mode to start the presentation.
Adjust scale size by C-x C-+ or C-x C--
See https://www.gnu.org/software/emacs/manual/html_node/emacs/Text-Scale.html
After the presentation, execute M-x presentation-mode again.
And then execute M-x presentation-mode again, the last scale will be reproduced.
If you want to persistize its size as the default size of presentation-mode
after restarting Emacs, set presentation-default-text-scale.
It's also have description of differences from other similar modes/package.

Emacs Lisp - opening new window

I'd like to write an emacs lisp function that will write output to a window other than the current window. It should create a new window if only the current one exists, and it should use an existing one otherwise. This is similar to what happens when you run C-h-f (Describe Function), and the description pops up in another window. What is the best way to do this?
See 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 not-this-window frame)
Make buffer buffer-or-name appear in
some window but don't select it.
buffer-or-name must be a buffer or the
name of an existing buffer. Return
the window chosen to display
buffer-or-name or nil if no such
window is found.
Optional argument not-this-window
non-nil means display the buffer in a
window other than the selected one,
even if it is already displayed in the
selected window.
Optional argument frame specifies
which frames to investigate when the
specified buffer is already displayed.
If the buffer is already displayed in
some window on one of these frames
simply return that window. Possible
values of frame are:
`visible' - consider windows on all
visible frames.
0 - consider windows on all visible or
iconified frames.
t - consider windows on all frames.
A specific frame - consider windows on
that frame only.
nil - consider windows on the selected
frame (actually the last
non-minibuffer frame) only. If,
however, either
display-buffer-reuse-frames' or
pop-up-frames' is non-nil (non-nil
and not graphic-only on a text-only
terminal), consider all visible or
iconified frames.
Or you can use pop-to-buffer if you want that buffer to be selected (which it sounds like you don't), or with-output-to-temp-buffer which binds the standard-output to be sent to the temporary buffer - read the documentation for more details (hat tip to Michael for that).

Emacs 23.2 opens a new window for each compile error/warning navigated to

I've recently upgraded from Carbon Emacs (v22.3) to vanilla Emacs 23.2 (from http://www.emacsformacosx.com). On Carbon Emacs when compiling a project, The frame is split in two with the current source file/SConscript in the top window, and the compile output in the bottom window. I'd hit C-x ` to navigate to the first warning or error in the compile output and it would replace whatever was in the top window with the source file the error or warning is in.
In Emacs 23.2, however, a 3rd window is opened causing two windows open in the top half of the frame (split vertically) and the compile output in the window of the bottom half of the frame. How do I tell Emacs to not open a new window and instead open the code in the the existing non-compiler output window in the frame?
A little further clarification on the behavior that I just noticed. If I hit C-x ` while the buffer containing the source file or SConscript file is active, no new window is opened. It's only if I'm manually navigating through the *compilation* buffer and hitting enter on an error or warning, or mouse clicking on a warning when a third buffer window appears.
The function which is used in next-error functionality is pop-to-buffer which in turn uses split-window-sensibly. You can control the behavior of split-window-sensibly by adjusting the variables split-width-threshold and split-height-threshold.
In your case it is split-width-threshold which is too small. In my emacs 23.1 it is set to 160. Just set it to a larger number and the problem should be solved:
(setq split-width-threshold 200)
I can't reproduce this problem myself, but you might try the following:
(setq split-width-threshold nil)
This tells display-buffer never to split windows horizontally, even if they are quite wide. There is also a split-height-threshold variable which is handled similarly. Checking these variables' current values might suggest whether they could be relevant to the behavior you're seeing.
One last thing to check: if you have defined your own display-buffer-function, that could be making these decisions for you.

Emacs - Multiple columns one buffer

I'm trying to edit some assembly code which tends to be formatted in long but thin listings. I'd like to be able to use some of the acres of horizontal space I have and see more code on-screen at one time. Is there a method for getting Emacs (or indeed another editor) to show me multiple columns all pointing to the same buffer?
C-x 3 (emacs) and :vsplit (vim) are great for multiple separate views into the code, but I'd like it to flow from one column to the other (like text in a newspaper).
See follow-mode.
Excerpt:
Follow mode is a minor mode that makes two windows, both showing the same buffer, scroll as a single tall “virtual window.” To use Follow mode, go to a frame with just one window, split it into two side-by-side windows using C-x 3, and then type M-x follow-mode. From then on, you can edit the buffer in either of the two windows, or scroll either one; the other window follows it.
In Follow mode, if you move point outside the portion visible in one window and into the portion visible in the other window, that selects the other window—again, treating the two as if they were parts of one large window.
I use this function to invoke follow-mode, although it would need customization for a different screen size:
;;; I want a key to open the current buffer all over the screen.
(defun all-over-the-screen ()
(interactive)
(delete-other-windows)
(split-window-horizontally)
(split-window-horizontally)
(balance-windows)
(follow-mode t))
The "Multipager" plugin for Vim can do this with VIM splits for people who want to get this behavior in Vim.
Get it from Dr. Chip's page: http://mysite.verizon.net/astronaut/vim/index.html#MPAGE
Docs: http://mysite.verizon.net/astronaut/vim/doc/mpage.txt.html
Vim can do this using :vsplit - and you can have the same buffer open in multiple "windows" (which are actually sections within a single "window").
Documentation here
A quick look at the emacs wiki doesn't show a mode like you describe. However, it shouldn't be too hard to write one... You just need to split the window with C-x 3 and move the text in the other window down, and whenever you move the text, do the same to the other window...
Problems may occur when you get to the bottom of the buffer, do you want the cursor to immediately go to the other window at the top?
Hmm, maybe its not that easy. But it should still be doable...
this is the default behaviour of emacs when splitting the window (C-x 3 for vertical split)
you get two columns which both have the current buffer open
Use vertical-split with C-x 3. This will split the current buffer into two columns that you can switch between with C-x o.