Using tabs in GNU Emacs 23 - emacs

I have been looking into packages that would enable me to have tabs in my emacs editor. Would like to open multiple files in a single emacs window. Any help/link would be appreciated

Emacs has this functionality built in. They are called buffers C-x C-f opens a new file of a name you provide. C-x b lets you change between buffers. C-x C-b lists all open buffers. C-x k closes the current buffer.
If you want multiple buffers in one window then C-x 2 splits the windows horizontally. C-x 3 will split it vertically. C-x 1 will close all the windows that are not the current one. C-x o cycles between open panes. &c.
GNU the organization that manages the code base for GNU Emacs has a wonderful tutorial
Note: the the above segment C- means while holding the <CTRL> key
post script: the ido library makes working with emacs in generally much easier.

You can already open multiple files in buffers. However, if you want a visual guide, then this is what you might want: http://emacswiki.org/emacs/TabBarMode
Caveat emptor: You might have to configure it a bit.

or you can use elscreen
and use Gnu/Linux too, so i remap the Winkey to manage my tabs.

emacs doesn't contain "tabs" like an internet browser its best to understand the concept of buffers like the others have said but if you want to have a tab bar at the top anyway just to give a quick reminder of what buffers are open I suggest looking at the TabBarMode in the emacs wiki.
When using buffers i like to use m-x ibuffer since you can filter out which buffers your interested in. say you only want to see the buffers which are associated with files in a /home/flood/coding/epicgame/ directory, i simple go to ibuffer, type / f then type epicgame and a filter will be applied, then to remove the filter simply press / twice and remember that C-h m is your friend.
This technique has helped me alot, you can even OR filters together and merge them into groups. I love emacs XD

Related

Emacs keep opening lots of buffers (Clojure)

I'm a beginner in Clojure and for some reasons I decided that Emacs would be a good choice, because of its usage among the clojurists.
But something that's really anoying me is that Emacs (for working with Clojure projects) opens a bunch of buffers. i.e, when I click "Read a directory to operate in its files" and select the lein's project root, I need to select myproject.core.clj and Emacs keep all the super dirs openned in other buffers. When compiling with cider and working with many clj files, it's painful to keep on alternating through all those buffers.
How can I limitate the numbers of buffers that Emacs leave openned?
(I know C-x k)
(Sorry for any English mistakes)
I had a lot of trouble with this same problem when I first started using Emacs. The solution is to use something other than C-x b or C-x C-b to switch between buffers. In particular:
I use Projectile's C-c p f to switch to arbitrary files in my project. It works very nicely because it takes your .gitignore into account. This can be annoying in some cases, but for the most part it works very well.
I use project-explorer to browse through a tree view of all the files in my project. The ignore features of project-explorer aren't quite as nice as those of Projectile, but you can toggle them using M-o when you need to, which is a feature Projectile doesn't have. project-explorer-open doesn't have a default binding, so I bind it to C-x p.
I use Ido and ido-ubiquitous to make all selection commands (including C-c p f) much easier to use.
If you lose your REPL buffer in CIDER, you can get it back instantly using C-c C-z.
If you already have multiple windows in front of you, windmove provides an extremely fast way to switch between them.
You'll generally end up with a lot of open buffers anyway, but since you now have an easy way to switch between them, that's no longer a problem. You can find a full example of this sort of setup in my personal Emacs config.
Personally, I use C-x C-f to open files, and don't bother with opening buffers for directories.

How can I more easily switch between buffers in Emacs?

I've recently started using emacs and I'm enjoying using it for the most part. The only thing I'm not enjoying, is switching between buffers. I often have a few buffers open and I've grown tired of using C-x b and C-x C-b, are there any packages that make switching between buffers easier? I've looked into emacs wiki on switching buffers and I'd appreciate insight/feedback on what are are using/enjoying. Thanks.
UPDATE: iswitchb-mode is obsolete in Emacs >= 24.4, replaced by ido.
All of the features of iswitchdb are now provided by ido. Ross provided a link to the documentation in his answer. You can activate with the following in your .emacs (or use the customization interface as Ross suggests):
(require 'ido)
(ido-mode 'buffers) ;; only use this line to turn off ido for file names!
(setq ido-ignore-buffers '("^ " "*Completions*" "*Shell Command Output*"
"*Messages*" "Async Shell Command"))
By default, ido provides completions for buffer names and file names. If you only want to replace the features of iswitchb, the second line turns off this feature for file names. ido will ignore any buffers that match the regexps listed in ido-ignore-buffers.
The behaviour described below for iswitchb-mode applies equally to ido for switching buffers.
iswitchb-mode (Emacs < 24.4)
iswitchb-mode replaces the default C-x b behaviour with a very intuitive buffer-switching-with-completion system. There are more sophisticated options, but I've never needed more than this.
After you hit C-x b, you are presented with a list of all buffers. Start typing the name of the buffer you want (or part of its name), and the list is narrowed until only one buffer matches. You don't need to complete the name, though, as soon as the buffer you want is highlighted hitting enter will move you to it. You can also use C-s and C-r to move through the list in order.
You can turn it on by default with this in your .emacs:
(iswitchb-mode 1)
You can also tell it to ignore certain buffers that you never (or very rarely) need to switch to:
(setq iswitchb-buffer-ignore '("^ " "*Completions*" "*Shell Command Output*"
"*Messages*" "Async Shell Command"))
You can use C-x <right> (next-buffer) and C-x <left> (previous-buffer) to cycle around in the buffer ring. You could bind S-<right> and S-<left> to these functions. (S is the "super-key" or windows-key). This way you can save some keystrokes.
Moreover, note that C-x b has a default entry, i.e. it displays a standard value (most of the time this is the previously viewed buffer), so that you don't always need to enter the buffer name explicitly.
Another nice trick is to open separate windows using C-x 2 and C-x 3. This displays several buffers simultaneously. Then you can bind C-<tab> to other-window and get something similar to tabbed browsing.
M-x customize-group ido then set Ido Mode to Turn on both buffer and file and set Ido Everywhere to on. Then click the Save for future sessions button at the top and enjoy ido magic for both files and buffers. Read the docs to get a sense of how to use ido.
Also, take a look at smex.
ido-mode provides an efficient way to switch buffers.
ibuffer is best for managing all opened buffers.
anything is good for selecting an interested thing from different
sources. (for eg: a single key can be used to switch to another
buffer or to open recently closed file or to open a file residing
in the same directory or ... anything you want ... )
If you've looked at the Emacs Wiki, you probably have all this information already, but here are a few other relevant Q&As:
Emacs: help me understand file/buffer management
Buffer switching in Emacs
How to invoke the buffer list in Emacs
My toolkit consists of ibuffer, windmove+framemove, winner-mode, and a custom binding to make C-xleft/right and C-cleft/right less of a hassle to use.
I have mapped the "ยง"-key to 'buffer-list and I find it to be very efficient.
I've started using anything for a couple of days and I'm really liking it: http://www.emacswiki.org/emacs/Anything .
Emacs-fu has an good intro to anything: http://emacs-fu.blogspot.com/2011/09/finding-just-about-anything.html
My favourite function for this is helm-mini which is part of helm.
As other helm functions, it allows incremental narrowing of the selection. It also searches your recently visited buffers, which is a really nice way to re-open a buffer. Helm can be a little surprising at first and as a new Emacs user, I found it visually overwhelming and I preferred ido or ibuffer which have been suggested in other replies. But now I absolutely love it and use it all the time for countless things.
Something that I realized by accident and that can be useful:
mouse-buffer-menu is by default bound to <C-mouse-1> (Control key + mouse left click) and opens a popup with a list of the current buffers.

I have multiple windows in Emacs, (C-x o) will take me to the "other" window, what does other mean?

I'm new to Emacs. I'm confused about the C-x o command. This command will move the focus to the other window. If I have many windows, which window will be selected as the target? What's the quickest way to do this?
Thanks
"When there are more than two windows, this command moves through all the windows in a cyclic order, generally top to bottom and left to right." - Emacs Manual
http://www.gnu.org/software/libtool/manual/emacs/Other-Window.html
C-x o is as quick as any other if you just have two windows. When you have more than 2 windows though, it can be a pain getting to the one you want using C-x o.
The quickest way to move to a particular window to the left/right/top/bottom of the current window is Wind Move. It comes with Emacs 21 and above. You can use Shift + arrow key to move to a window.
http://www.emacswiki.org/emacs/WindMove
First you've got to notice that "window" in Emacs slang means not what you may think it means. What is normally called a window is called "frame" in Emacs. What Emacs calls "window" is a split window inside a frame.
The easiest way to understand what C-x o does is by trying it out yourself.
In a running Emacs instance, first type C-x 2. Now the frame is split vertically into two windows. The cursor ("point") is in the upper of the two windows. Now type C-x 3 and you will have split the upper window horizontally again. All in all you've got three windows now.
Now type C-x o repeatedly to cycle through the different windows. That's it.
Once you've gotten used to the order in which the windows are cycled through, you can do multiple hops at once, thereby skipping some windows, by using the key combination together with a prefix argument. So say, you want to skip one window and thus jump two at once, type C-2 C-x o. This way you can quickly jump to the window you want.
(To return to a single window, type C-x 1.)
C-x o cycles though your opend windows in current frame. If you often have many opend windows, have a try of dim switch window. It displays window index visually and you can switch to a window using its index.
In case such people like me brows the web with research engines to simplify the switching between more than one window I suggest this bindings key configuration (to put in your init file):
(global-set-key [s-left] 'windmove-left)
(global-set-key [s-right] 'windmove-right)
(global-set-key [s-up] 'windmove-up)
(global-set-key [s-down] 'windmove-down)
It bind windows direction switching to super (windows key) + arrows key direction. These case should come unbound.
EDIT
(windmove-default-keybindings 'super) is simpler code thanks to #phils comment below.
BTW if you work with gnome these keys might be bound to some windows moves so you'll have to change it.

Emacs buffer shown after closing a buffer

How can I modify the way emacs picks which buffer to show after closing a buffer?
When I have multiple columns showing the same buffer, and then open another file in one of the buffers and then close the newly opened buffer, it doesn't switch back to the previous buffer, but to another buffer.
I'll try to explain with an example:
Start with a new emacs at *scratch*
C-x 2 (split into two columns)
C-x C-f 1 (find file 1)
C-x o (switch to other frame)
C-x b 1 (find file 1)
C-x C-f 2 (find file 2)
C-x k (kill buffer)
Now it switches to scratch but I would like it to show 1 in both windows again, is it possible to make emacs behave this way?
This may not be a direct answer to your question, but it might help.
Emacs manages its buffer list, including deciding which buffer gets displayed when you kill one (via kill-buffer). I haven't looked into how it's done, but the documentation is "out there". Lots of people have created custom buffer-stack management magic to change the way emacs does things, maybe some of them are based on bayesian analysis, or whatever. You can imagine the possibilities.
I've never looked into changing the way emacs manages its buffers. Instead I just bind other-window and switch-to-buffer to easy keystrokes (C-x o, C-x b) and I get really good at using them.
you could create a simple function for what you want: it should destroys all other windows, then split the window so that the current buffer is displayed in both. Luckily, emacs has functions that do exactly those things.
(defun cheeso-show-buffer-two-windows ()
"Close all other windows; then split, and show the current
buffer in both windows."
(interactive)
(delete-other-windows)
(split-window-vertically))
Bind that to a keystroke, and badda-bing, you're there. This is a vertical split - the windows are displayed in a vertical stack. If you want it horizontally split (the windows are side-by-side), then replace ... well, you know.
This also doesn't quite help directly, but Winner mode might help you get where you want to get.
Are you using tabbar-mode? I had the same problem and for me tabbar was the cause. Tabbar adds the function tabbar-buffer-kill-buffer-hook to kill-buffer-hook. You can remove it with (remove-hook 'kill-buffer-hook 'tabbar-buffer-kill-buffer-hook).
If you don't use tabbar try M-x describe-variable kill-buffer-hook. One of the functions in this list should be responsible for messing with your buffers.

What are the "Programmer shortcuts" in emacs?

I would like to know what are all the programmer-useful shortcuts that exists in emacs.
I come from a netbeans background and I am trying to make myself comfortable with emacs -text only environment. So I am looking at shortcuts for "refactoring" the code, "auto-completion", "go to definition" etc.
How can all these be achieved in emacs ? What are other programmer-useful shortcuts ?
I'll be using emacs basically for LAMP, javascript, C, C++.
ps - you can safely assume that I know how to open a file, save a file, navigate and whatever is in the tutorial in emacs.
For auto-completion, use etags with M-xtags-search or M-xetags-select-find-tag. I use macros often to do repetitive tasks. C-x(<string of useful tasks>C-x). Also, M-xalign-regexp to beautify the code and make it more readable.
You should find most of the most used features by Emacs users in this question's answers here at Stackoverflow.
Check this site
Some the important keybindings that are not there in the tutorial are:
Previous matching bracket: C-M-b (if it doesn't work, try ESC followed by C-b)
Next matching bracket: C-M-f (or ESC C-f)
Go to start of block: C-M-u
Go to end of block: C-M-d
Start of function: C-M-a
End of function: C-M-e
Outline mode: C-u 1 C-x $ (C-x $ to revert)
Newspaper mode: C-x 3 M-x follow-mode (especially useful with today's wide-screen monitors!)
Vertical Copy
Sometimes you will need to copy a vertical patch of data, e.g. one column in a table. First press C- where you want to start copying. Then go to the end of the column and press C-x r k. To paste the column press C-x r y. (If you don't want to delete original column, just press C-_ there once to restore it and then press C-x r y at target.)
To start, here is one :
Meta - / -> does code completion
M-x diff-buffer-with-file
M-x revert-buffer
When working with versioning (I use git), M-x diff-buffer-with-file is really useful. When you have a file open in a buffer in emacs, then you do a git checkout or some other action that touches that file, emacs will complain at you when you try to edit the buffer. M-x diff-buffer-with-file is helpful to see if you will break anything by keeping what's in the buffer. If something has changed and you want to grab the file from disc and put it in the buffer, do M-x revert-buffer.