Xah Lee wrote:
«Effective Emacs
perm url:
http://xahlee.org/emacs/effective_emacs.html
Another item i should add, is about using list-buffers or the buffers
mode. Actually, ibuffers, which i've been using in place of the
default since emacs 22.»
I have just now wrote the master buffer section.
Here's a text version of the added section:
-----------------------------
Master Buffer Switching
In emacs, every file is represented in a âbufferâ. The term âbufferâ
means a temp area of storage in computer science. From a application
user's perspective, it might be better to think of it as tabs, as the
tabs in browsers, or IDEs, which basically means a single window is
used to represent several different files or work area, but only one
is shown.
A typical emacs user will have tens of buffers in a session. Master
how to manipulate buffers will benefit you greatly.
Here's the classic commands related to buffers:
Command Shortcut Purpose
next-buffer Ctrl+x Ctrl+â switch to next buffer
previous-buffer Ctrl+x Ctrl+â switch to previous buffer
list-buffers Ctrl+x Ctrl+b show all buffers
switch-to-buffer Ctrl+x b switch to a specific buffer
In emacs 22 (released in 2007), there's a new mode called ibuffer.
(start it by âAlt+x ibufferâ) âibuffersâ is a major improvement of the
classic âBuffer menuâ mode. It includes color-differentiated buffer
listing, and few more powerful regex commands that manipulate buffers
in batch. I've been using ibuffers since about 2006 with emacs beta,
and found it completely replace the âBuffer Menuâ mode used by list-
buffers.
emacs ibuffer
above: A screenshot of ibuffer mode.
In ibuffer mode, those purple are emacs's buffers, those blue are
dired, those red with a â>â in front are marked buffers. You can do
operation in batch to the marked ones, such as save all unsaved files,
close all files of a given dir, close all Java files, etc. The concept
and shortcuts are pretty much the same as in dired. Move your cursor
to a file name and press âRETâ to switch to it. To mark a buffer,
press âmâ. To close a buffer, press âDâ. There are over ten commands
for marking; you can have a look at the graphical menu âViewâ and
âMarkâ, once you are in ibuffer mode.
emacs ibuffer mark
above: Emacs's ibuffer mode's âMarkâ menu.
Here's the ibuffer commands i use frequently:
Shortcut | Purpose
*u | Mark unsaved buffer.
S | Save marked buffer.
D | Close marked buffers.
** | Unmark all.
%%m | Mark by mode name (e.g. all html files, all java files)
%%f | Mark by file path (e.g. all files in a dir)
You might want to give ibuffer a easy-to-type shortcut. Since it
completely replaces the functionality of list-buffers command, you
might alias it to ibuffers.
(defalias 'list-buffers 'ibuffer)
Emacs often generates a lot internal buffers that users are not
interested in cycling thru. For example: *scratch*, *Messages*,
*shell*, *Shell Command Output*, *Occur*, *Completions*, *Apropos*,
*info*, etc. You might define your own next-user-buffer and previous-
user-buffer that skips emacs's buffers, and you might define next-
emacs-buffer, previous-emacs-buffer that cycles thru just the emacs's
buffers. Here's the code: modern_operations.el.
Also, the default shortcut for next-buffer (Ctrl+x Ctrl+â) involves
multiple keystrokes, you might define a single-key shortcut for it.
Here's some example code:
;; sample easy shortcuts
(global-set-key (kbd "
") 'find-file) ; Open file
(global-set-key (kbd "") 'ibuffer) ; list buffers
(global-set-key (kbd "") 'previous-user-buffer)
(global-set-key (kbd "") 'next-user-buffer)
(global-set-key (kbd "S-") 'previous-emacs-buffer) ; Shift+f7
(global-set-key (kbd "S-") 'next-emacs-buffer) ; Shift+f8
(global-set-key (kbd "") 'kill-this-buffer) ; Close file
------------------
Xah
xah@xahlee.org
â http://xahlee.org/
â