April 24th, 2007 by Rob Christie · 14 Comments
This is the start of a series on our favorite emacs packages. Some of these packages are part of emacs core, some aren’t (but we could argue should be). I use iswitchb-mode at least a hundred times a day. iswitchb is one of the features of emacs that I rave about whenever I try to explain why I am still using a 30-year old editor. From the package commentary:
As you type in a substring, the list of buffers currently matching the substring is displayed as you type. The list is ordered so that the most recent buffers visited come at the start of the list. The buffer at the start of the list will be the one visited when you press return. By typing more of the substring, the list is narrowed down so that gradually the buffer you want will be at the top of the list. Alternatively, you can use C-s and C-r to rotate buffer names in the list until the one you want is at the top of the list. Completion is also available so that you can see what is common to all of the matching buffers as you type.
The key stroke C-x b brings up the iswitchb mini-buffer, and with a few key strokes the file you want is open. My normal mode of operation is to load the project I am working on into the emacs file name cache, and then use iswitchb to switch between the files. In order to use iswitchb in this manner you will need iswitchb-fc, and a means for populating the file name cache.

Some of the nice features of iswitchb include filtering out buffers that you don’t want to see, and limiting how many files are shown in the minibuffer by customizing the iswitchb-max-to-show variable. Additionally, you can kill a buffer from within iswitchb by typing C-k. The following is a snippet from my .emacs:
;;============================================================
;; iswitchb
;;============================================================
(require 'iswitchb)
(iswitchb-mode 1)
;;============================================================
;; iswitchb ignores
;;============================================================
(add-to-list 'iswitchb-buffer-ignore "^ ")
(add-to-list 'iswitchb-buffer-ignore "*Messages*")
(add-to-list 'iswitchb-buffer-ignore "*ECB")
(add-to-list 'iswitchb-buffer-ignore "*Buffer")
(add-to-list 'iswitchb-buffer-ignore "*Completions")
(add-to-list 'iswitchb-buffer-ignore "*ftp ")
(add-to-list 'iswitchb-buffer-ignore "*bsh")
(add-to-list 'iswitchb-buffer-ignore "*jde-log")
(add-to-list 'iswitchb-buffer-ignore "^[tT][aA][gG][sS]$")
;;============================================================
;; iswitchb-fc
;;============================================================
(require 'filecache)
(load "iswitchb-fc")
There are other packages out there that do the same thing and even more. Even though I love iswitchb, I have been meaning to try icicles and/or the ido package since they seem to provide the same functionality on steroids. If you are an advocate of one of these other packages, I hope to hear from you. If you are not using any of these packages on an hourly basis then start today. The package is indispensable.
Tags:faves · misc · reviews
April 17th, 2007 by Rob Christie · 7 Comments
I ran across this package on gnu.emacs.sources recently. If you enable light-symbol-mode in a buffer and pause on a symbol, then Emacs will highlight all other occurrences of the symbol in the buffer. When you move point the highlighting goes away.
Tags:misc · quick
April 9th, 2007 by Ryan McGeary · 12 Comments
There are several ways to customize the display of the cursor. I happen to prefer highlighting the current line as a visual cue to keep my eye focused on where I’m working.

Before a few days ago, I had not realized there were so many packages to accomplish this, but let’s review a few. [Read more →]
Tags:misc · reviews
April 5th, 2007 by Rob Christie · 19 Comments
When you first start using emacs, there is normally someone who says something like keyboard macros in emacs rock. At that moment in time, they show you some quick little example, it looks neat but it probably doesn’t register with the true magnitude that it should. This series shows examples of macros “in the wild”. I hope it helps reinforce the value of the keyboard macro. [Read more →]
Tags:kb-macros · tips
April 2nd, 2007 by Ryan McGeary · 1 Comment
Michael Stutz recently wrote Part I of a new new series at IBM called Emacs editing environment. The first is Learn the basics of Emacs.
This first tutorial is definitely geared toward the emacs newcomer. There is a lot of overlap with the built-in emacs tutorial (C-h t), but different mediums are good for teaching different kinds of people. Also, reinforcement of the basics is good for a budding emacs hacker.
Note: IBM requires free registration to read the tutorial.
Tags:newbie · news
March 29th, 2007 by Rob Christie · 3 Comments
I frequent the gnu.emacs.sources news group as one route to finding out about new packages. linenum.el came across the list recently. The package displays line numbers on the left side of your buffer. The author indicates that it is an alternative to setnu.el with the benefit that it works incrementally and can handle large files. It seems like one of those packages that is nice to have in your bag of tricks. Of course, you may just want the current line number in your modeline by using the M-x line-number-mode command. You can set it by default with the following line in your .emacs file.
And in case you forgot (or didn’t know), M-g M-g (or M-g g) is the key binding for M-x goto-line in Emacs 22.
Tags:quick · tips
March 26th, 2007 by Ryan McGeary · 3 Comments
Our newbie tips are our way of expressing emacs features we might otherwise take for granted. We hope they help beginners climb the learning curve faster. This particular tip is one that I wish I knew far sooner when I first started using emacs.
Incremental searching with isearch-forward and isearch-backward (C-s and C-r) is crucial in day-to-day and even minute-by-minute emacs usage. Maybe you want to find all uses of a particular variable name, or maybe you want to make sure you’re not repeating the same word in a piece of literature. Let’s dive in with an example:
Suppose we want to search for the word “lorem” in the folowing paragraph:

We could type C-s l o r e m, but seeing as our point is already at one particular instance of “lorem,” we can instead enter C-s C-w. The result is the same. When in isearch-mode, C-w yanks the next word in the buffer and appends it to the end of the current search string:

Now suppose we want to search for instances of “lorem ipsum.” Just hit C-w again:

Awesome, we just saved 9 key presses — a productivity boost.
C-w is part of the isearch-mode-map. There are many isearch modifiers. Here are some that I use most frequently:
C-s – to search again forward
C-r – to search again, but backward
C-w – to yank next word or character in buffer onto the end of the search string, and search for it
M-y – to yank last killed text onto end of search string and search for it
M-r – to toggle regular-expression mode
M-e – to edit the search string in the minibuffer
For a full listing of available isearch modifier keys, review the help for isearch (C-h f isearch-forward). It is also possible to add your own functions to the isearch-mode-map. Last month, we referenced a way to add occur to isearch.
Tags:isearch · newbie · quick · tips
March 22nd, 2007 by Rob Christie · 11 Comments
Bookmarks are one of those features that I have used, but have been on my list to learn more about. This week I decided to bump it off my list and pass along my notes. There are a number of different packages that can be used for bookmarking. I will discuss three. [Read more →]
Tags:reviews
March 17th, 2007 by Ryan McGeary · 7 Comments
On the surface, it might not sound like editing columns of text is something that happens a lot, but I find myself doing it fairly often. A quick way to enter different values on each line down a column is to use set-goal-column (bound to C-x C-n).
Let’s say we have a block of text like the following comma-separated list. We’d like to enter a different value in the second field of each line. First we position the point on the first line between the two commas. This is at column position 6 (emacs starts counting columns at zero).

Now let’s input our first text field and hit C-n to go to the next line.

It does what you might expect. Because our first field pushed us out to column position 23, when we went to the next line our point was placed at the end of the second line. To enter a new field on line 2, we’ll have to first jump back to column 6 manually. That’s no fun. Let’s start over and use set-goal-column instead.

Now, before we enter our first field, we’ll first hit C-x C-n. Setting a goal column sets the current horizontal position as a goal for C-n and C-p. Let’s see what happens when we re-input our first field and hit C-n.

Perfect. We’re right were we need to be. Quickly, we finish our text entry down the column:

To turn off the goal column, pass a non-nil argument to set-goal-column (i.e. C-u C-x C-n).
Note: When you run set-goal-column for the first time, you’ll receive a warning that the function is disabled. You can either follow the built-in instructions and customizations to enable the function, or you can add the following to your emacs initialization.
(put 'set-goal-column 'disabled nil)
This exercise provided a nice way to manage a column of text with different values on each line. When the task is more repetitive, emacs rectangles come in handy. We’ll make rectangles a future topic of discussion.
Tags:quick · tips
March 15th, 2007 by Rob Christie · 5 Comments
Have you ever wanted to test out regular expressions in emacs? Until I found out about re-builder I used to run M-x isearch-forward-regexp (also bound to C-M-s) in a buffer until I figured out the expression I needed. This works but just having M-x re-builder in your bag of tricks helps. In the words of the author, Detlev Zundel
When I have to come up with regular expressions that are more complex than simple string matchers, especially if they contain sub expressions, I find myself spending quite some time in the `development cycle’. `re-builder’ aims to shorten this time span so I can get on with the more interesting bits. With it you can have immediate visual feedback about how well the regexp behaves to your expectations on the intended data.
re-builder supports a number of different input forms for the regular expression. The input type can be changed by C-c TAB when you are in this mode.
Read Regexp Syntax in re-builder

Another nice feature is the highlighting of the different subexpression matches. Xemacs has added perl regular expression support to re-builder as noted on the emacs wiki. I hope this gets added back into GNU emacs.
Tags:quick · tips