I'm new to Emacs.
When using Emacs to write text, I often have one window open in a frame.
When I want to open a second file in a new window within the frame, I want to vertically split the frame and open a new window at right (not split horizontally and open at bottom, etc.) How do I do that?
I know that C-x 3 opens a new vertically split buffer window at right, and C-x 4 f opens a file at bottom (a horizontal split). That's not what I'm looking for.
There are a number of different ways to do this, but this works:
(defun find-file-other-window-vertically nil
"Edit a file in another window, split vertically."
(interactive)
(let ((split-width-threshold 0)
(split-height-threshold nil))
(call-interactively 'find-file-other-window))
Related
I am edting latex files with Emacs+AucTeX. When working I have two windows in the frame: the latex file window and the reftex-toc window. I set the reftex-toc window dedicated to its buffer by
(defadvice reftex-toc (after reftex-toc-window-dedicated activate)
(set-window-dedicated-p (selected-window) t))
to keep it from being replaced.
But problems arise when I call (TeX-recenter-output-buffer) by C-c C-l. The output buffer can't be displayed. I have to manually switch to the output buffer by C-x b. And if I call help commands, e.g. C-h f, the help buffer is not displayed in a new window as it should be. Instead, it replaces the latex file window. How can I fix this problem?
EDIT
I found that the problem is due to function (display-buffer BUFFER), which is internally called by (TeX-recenter-output-buffer). Under normal circumstances where there is no dedicated window in the frame, (display-buffer BUFFER) creates a new window for BUFFER. But if there are a dedicated window and some normal windows, (display-buffer BUFFER) just displays BUFFER in one of the normal windows w/o creating a new one.
As a workaround, I open another (the 3rd) window, so that if I call C-c C-l, the compilation output is displayed there and the latex file window is kept. However, I am still looking forward to a real solution. Could any one help? Thank you.
When I use C-x 2/3 to open a new window in Emacs, I usually want to do something in the other window, such as shell, open a buffer or visit a new file, but I always change into the other window manually. Is there a way(maybe defun a new function in .emacs, but I'm new to Emacs) that I can switch my point into the other window immediately after C-x 2/3 just like when you open a new tab and switch to it immediately in a browser???
How about just wrapping the function using something like this:
(defun my-split-window-below ()
(interactive)
(let ((win (split-window-below)))
(set-frame-selected-window (selected-frame) win)))
You could also do defadvice on split-window-below using after, and have it select the window, but I'm not sure that it's a better solution.
How can I redirect some buffers to popup in a particular window? For example, when you are using the shell, and you press <TAB>, a *completions* buffer will popup (usually) on a right window... but how can I make this buffer to always popup on another window?
I'd prefer solutions that doesn't involve installing new libraries (even though, programming my own elisp function would be neat).
I'm asking this, because when I use emacs, O like to split it into 3 windows:
The left window is where I code, let's call this the plotting window. The right top window, is where compilation messages will pop-up, let's call it the information window. The right bottom window is where I use the shell, let's call it the shell window. When I use the shell window, and press <TAB> for completions proposals, the *completions* buffer will popup on my plotting window, instead of on my information window.
Until now, I have tried just pressing q when I go to my plotting window, but this is becoming annoying, because it wont always return to the code I was working in, so I have to C-right until I find my code, or C-x b (if I can remember the name of the file I was editing).
The easiest way I can think of is to dedicate the plotting window and the shell window to their buffers. If you have already installed emacs-goodies then you can use M-x dedicated-mode for that purpose.
In the case that the plotting window and the shell window are dedicated emacs only uses the information window to pop-up new buffers.
I for myself use a menu-item that I added to the Buffers menu:
(defun window-dedicated-toggle ()
"Toggle wether window is dedicated to buffer or not."
(interactive)
(message
(if (window-dedicated-p)
(progn
(set-window-dedicated-p nil nil)
"Window not dedicated.")
(progn
(set-window-dedicated-p nil t)
"Window dedicated."))))
(easy-menu-add-item nil '("Buffers") ["Toggle Dedicate Window To Buffer" window-dedicated-toggle t])
I have configured Emacs to save my desktop when I close it, so that when I open it next all my buffers are reopened.
However my init.el splits the frame into three windows at startup, so I can view three buffers on the screen at the same time. The first window already shows the buffer I was last editing, but I would like the other two windows to show the second and third last files I was editing too.
I thought this would be possible using something like this:
;; Split into three equally sized windows
(split-window-horizontally)
(split-window-horizontally)
(balance-windows)
;; Load some buffers into the new windows
(other-window 1)
(next-buffer) ; Shows *Messages* in both windows
;(previous-buffer) ; same
;(switch-to-buffer 'nil t) ; Shows same buffer in both windows
(other-window 1)
(next-buffer)
(previous-multiframe-window)
(previous-multiframe-window)
Unfortunately I can't find a command to select the buffer I want in each window. If I manually type C-x b RET in each window then it selects exactly the buffers I want (and they are different in each window), but I can't figure out how to replicate that behaviour as a command in init.el.
What am I doing wrong?
If the window is selected then you can use
(set-window-buffer (selected-window) "name of buffer")
emacs 23.2
I have just installed emacs on a 10.1" screen netbook.
However, when I compile my source code the compilation window always opens in a horizontal buffer below my source code buffer.
At work I use a 15" screen and the compilation opens up in a vertical window, which is what I like.
However, on my 10.1", is there any way to force it to open in a vertical window. Its just easier to scroll down and find errors when you have the source code buffer vertical to the compilation buffer.
Many thanks for any advice,
Related question here.
(defadvice compile (around split-horizontally activate)
(let ((split-width-threshold 0)
(split-height-threshold nil))
ad-do-it))
If you always want to split horizontally when a new buffer is displayed, you can just set the two variables above and dispense with the advice.
Try these settings:
(setq split-height-threshold nil)
(setq split-width-threshold 0)
With respect to needing to scroll down the source code, you should check out C-x ` or M-x next-error and let Emacs do the scrolling for you.
Take a look at the section "Choosing a window to display" in the Emacs manual. In particular,
Option split-width-threshold
This variable specifies whether split-window-sensibly may split windows horizontally. If it is an integer, split-window-sensibly tries to horizontally split a window only if it has at least this many columns. If it is nil, split-window-sensibly will not split the window horizontally. (It still might split the window vertically, though, see above.)