Preserve window layout in Emacs - emacs

I have setup my windows in a certain way. How do I save this setting to be invoked later?

I sometimes still use C-x r w <register> to store a window configuration in a register, and C-x r j <register> (where <register> is a single character) to jump back to it.
While this is a nice way for storing a few window configurations which you want to go back to after some time, I find winner-mode to be more convenient in a few regards. (For example, you won't have to bother naming the configurations).
Just put (winner-mode 1) in your .emacs, bind winner-undo and winner-redo to convenient shortcuts (or use the IMHO awkward C-c <left> and C-c <right> predefined ones), and you'll be able to switch back to previous window configurations.
See also: M-: (info "(emacs) Window Convenience") and M-: (info "(emacs) RegConfig")

I know you allready accepted an answer, however because I understand your question in another way (concerning layout) and this question showed up for me when I was in search for something to persist my emacs window layout, I would like to mention:
workgroups.el
which purpose is to save and restore the way, emacs windows are layed out and many more.

Check out emacs desktop. I have no emacs available but I believe it's part of the standard lisp packages you get when you install emacs.
Use the desktop library to save the
state of Emacs from one session to
another. Once you save the Emacs
desktop—the buffers, their file names,
major modes, buffer positions, and so
on—then subsequent Emacs sessions
reload the saved desktop.

Give Layout Restore a try if you just want to restore the window layout later.

If you want to persist a layout in your hard-drive, desktop-save is the option.
If you need to store multiple layouts during emacs' process lifetime (e.g. you connect to a long-running emacs daemon using emacsclient), you can use C-x r f <register> to store the frame layout in some register and C-x r j <register> for restore.
Since I now and then remotely connect to the work station to do sth, disconnect for a while and later reconnect, restoring layout helps me continue stuff seamlessly (note in this case window layouts stored by C-x r w would be gone).

Related

Emacs Comint History: Search Rather Than Navigate One By One

I would like to, after switching to the buffer where I usually run commands, navigate the history by searching it, rather than navigate one-command-at-a-time at the end of the buffer (e.g. C-p).
Basically I would like to "Reverse I-search" the command history at the end of the buffer, rather than search the buffer.
Did anyone code a working solution? Note that I noticed there is a Command History buffer available, but here it is just a bunch of text and it is not grouped well enough I think to use.
As in a terminal, you can use M-r to search backward. It works in comint-mode, but it also work elsewhere, like in M-x (M-xM-rpatternRET).
Yes, with Icicles.
In Icicle mode, command icicle-comint-search is bound to C-c ` in shell buffers. It gives you the behavior you are looking for. It is described here.
It uses only stuff that is in the currently visible history as candidates, however. If you want to access stuff from your history from previous sessions then use command comint-input-ring, bound to C-c TAB, instead. (This is explained in the same doc.)

emacs follow-mode use/alternatives

I have recently started using Emacs follow-mode to see more of documents I am working on. Unfortunately, it seems to have some limitations, at least as I am using it. I very often use C-x b RET to toggle between two buffers, but this doesn't work as I would expect with follow-mode. I would expect that if both buffers are set up to use follow-mode, it should switch both windows, but it does not. Also, even if only one buffer is set to use follow-mode, hitting C-x b RET after switching to that buffer should get me back to my original configuration, but instead it switches the active window to some third buffer. Can anyone explain some better follow-mode idioms or else an alternative to follow-mode?

call emacs commande automatically

I would find a way to execute the commands in the file emacs. Emacs and therefore automatically.
For example I often use: highlight-80
So I'm forced to type every time: Meta key + highlight-80 +-fashion
it's the same with linum-mode and plenty of other.
I have been trying to put in the file emacs.:
(highlight-80 +-mode)
But the option is not enabled.
Thank you in advance for your help. I am looking desperately for a moment, emacs is my working tool quotidient.
Regards
Use C-h f or C-h v, and read the Emacs manual about such choices.
Some of them are user options (variables), whose values you can customize, using M-x customize-option, so the default setting becomes what you want.
Others are modes, which you can call/set in your init file (~/.emacs) --- see the Emacs manual for how to do that. Typically, you use a positive number to turn a mode on and a negative number to turn it off. E.g.: (menu-bar-mode -1) in your init file turns off the use of a menu bar.
In sum, the Emacs manual (C-x r) is your friend. Sit down and have a first chat with it.
You seem generally a bit unsure about how customising Emacs works, so reading the manual on this topic should probably be your next step:
http://www.gnu.org/software/emacs/manual/html_node/emacs/Customization.html
If you are not using the current stable release (Emacs 24.3 at the moment), there's a chance that some of that information will not apply. The in-built manual is, of course, always correct for the version you are running:
C-hig (emacs) Customization RET

How do I stop Emacs from changing my split buffers?

I have a number of splits open, looking at various buffers. But when I for example check the help on a function it will replace one of the splits with the help buffer. Once I'm done reading the help I have to go back to the correct buffer manually which is a pain. How do I get Emacs to be nicer to my buffers?
Update: Help will let you press q to go back to the previous buffer. But causing the Emacs backtrace to pop up also steals one of my buffer windows and it doesn't have a q.
Update: Backtrace DOES have q to go back. My original question still remains: how do I ask Emacs not to steal one of my splits?
Adding the line(push "*Help*" special-display-buffer-names) to the init file should make subsequent invocations of the help buffer to appear in its own frame(what the desktop usually calls "window"), and leave the original frame with its configuration alone.
See Special Buffer Frames.
You could also use winner-mode. It came up on planet.emacsen.org a while back.
Winner Mode is a global minor mode. When activated, it allows to “undo” (and “redo”) changes in the window configuration with the key commands ‘C-c left’ and ‘C-c right’.
That way you can undo any changes to your splits immediately after they happen.
I hope this will help you :
C-x 0 to remove the current window
C-x 1 to keep only the current window
you can use windmove by adding the following line in your .emacs :
(windmove-default-keybindings)
Then, you can move the point between windows using S-right S-left S-up and S-down
There are lots of ways to store and restore emacs windows, see emacswiki.org on the subject.
What I do is just go to that changed buffer, C-x k it, and the current buffer in that window will be the previous buffer.
It may be possible to define advice for the help that saves the current window and buffer state and restores it with a simple keybind. But this is outside my basic elisp knowledge.

Emacs: help me understand file/buffer management

I've been using emacs for all of my text editing needs for the past three years now. When I'm in a single file, working on code or whatnot, I'm fairly efficient. With two files, I can "C-x b RET" between them and I do fine. However, whenever I need to be working on more than two files at a time, I tend to get lost.
Here are some of the problems that I'd like to work on:
I forget what some of my buffers are called, but I don't understand why C-x C-b splits my window into two buffers and exits the mini buffer. Sure I can switch buffers and choose a buffer to visit, but this feels unintuitive, and leaves me with two buffers open.
When I visit a directory rather than a file, I have a convenient list of all of the files and directories. I usually want to do one of two things with this: 1) Open a single file and never see this buffer again OR 2) Open a bunch of files and never see this buffer again. I don't really know how to do this, as moving the point to a file and hitting return doesn't do either of these things.
I know that my buffers aren't like tabs, but I have an inclination to want to scroll through them to find what I want. I don't know of any key-bindings for this, but I'd like it to be M-n / M-p or the like. Then again, this may be a horribly inefficient way to switch buffers.
When I open interactive help of any kind (for example in ESS), I have a habit of switching back to the buffer I was working in and using C-x 1 to get back to a single buffer. When I do this, however, the help buffer hangs around in my buffer list, further confusing me. I know I can switch to that buffer, kill it, switch back, and then go back to a single buffer, but this seems wrong.
The way I've dealt with this so far involves using a tiling window manager and a few emacs windows in different work-spaces, rather than actually learn the best way to manage a number of files in emacs. I don't necessarily want to change emacs to better fit my needs (although I am open to that if it fits in with what I'm about to say), instead, I'd like to grok the thought process behind handling files/buffers the way that emacs does, and how I can be more efficient with it.
Any answer that would help me understand the correct way, or a more efficient way to manage my buffers or files would be greatly appreciated.
Bind C-x C-b to ibuffer. This is a better buffer listing facility with many advanced features, and its default behaviour is to replace the current buffer with the buffer listing, and then bury the listing when you select a buffer (leaving you with the newly-selected buffer in place of the original one).
You can simply use C-x b to enter your selection in the mini-buffer, of course; however the tab-completion (which is needed to make this a viable option, IMO) does open a new window temporarily, at which point I think you might as well familiarise yourself with something with more features.
Use a instead of RET when selecting from dired. This kills the dired buffer instead of leaving it behind. C-h m in any buffer will show you the help for its major mode (followed by help for the minor modes), and you can read about all the available dired key bindings there.
http://www.emacswiki.org/cgi-bin/wiki/TabBarMode ? (edit: I prefer Rémi's answer for this one, but TabBarMode would give you the visual tab element if you were particularly keen on that.)
q is bound to a 'quit' function in a great many major modes. Generally it buries the buffer rather than killing it, but I certainly find that fine.
To elaborate a little on #1, ibuffer has lots of nice features, and M-x customize-group ibuffer RET will give you some idea of how you can customise it to your liking.
Furthermore, you can filter the buffer list by many criteria (again, use C-h m to see its help page), and then generate a 'group' definition from the current filters, and save your custom filters and groups for future usage.
For example:
/ f ^/var/www/ RET: filter buffer list to show only filenames starting with /var/www/.
/ s Web filters RET: name and save active filter set to your init file.
/ g Web development RET: create a named group from the active filters.
/ S My groups RET: name and save group definitions to your init file.
/ r Web filters RET: invoke the "Web filters" filters.
/ R My groups RET: invoke the "My groups" groups.
RET on a group name to collapse or expand it.
C-k and C-y to kill and yank groups, to re-arrange them.
C-h m for more information...
This way you can have a single Emacs instance running, and create filters and groups for different types of task, and easily switch between them.
I think you will really enjoy Ido for dealing with multiple buffers who's names you can't exactly remember. When you type C-x b it shows a list of open buffers in most used order. As you type some of the characters in a buffer name the list is filtered. The characters you type don't have to be at the begging of the name or contiguous. Using C-f, C-b or left/right arrow keys cycles through the buffer choices.
Also see Smex for Ido like functionality for M-x
Closing windows is done with C-x 0. Intentionally splitting the window is done with C-x 2 for horizontal, C-x 3 for vertical. I love this feature, since it allows me to have test and production code visible at the same time. C-x o takes me to the other window.
I use C-x right (or C-x C-right) and C-x left (or C-x C-right) to go to the next and previous buffer. I don't mind anymore off the few buffer that lay around in Emacs but you could use k in the buffer list to kill the buffer you don't use anymore.
You can also try Iswitchb mode which provides auto-completion for buffer names when you switch buffers via C-x b.
To activate:
M-x iswitchb-mode
Or add to your .emacs file:
(iswitchb-mode)
It is similar to Ido mode for buffer switching but a bit more lightweight.
Also, if you want a more customizable listing of your buffers then use M-x bs-show as an alternative to C-x C-b. In that buffer type ? to get a list of actions you can perform.
I think the number one most useful extension for flipping through buffers is Anything. It lets you start typing part of a buffer (or file!) name and it will figure out what you want. I've rebound C-x b to anything-for-buffers. It makes life so much better.
As always, there are many ways to help you with this; it depends a bit on personal preference what works best, here are some links with explanations:
ibuffer; which is an updated buffer menu (C-x C-b)
ido, which let's you have more powerful autocompletion to switch through buffers. It's a kind-of 'better iswitchb'.
These two are enough for me; but you may also be interested in the tabbar-mode, which gives you rudimentary tabs (like firefox has them).