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 →]
Bookmark Mania
March 22nd, 2007 by Rob Christie · 11 Comments
→ 11 CommentsTags:reviews
Quick Tip: set-goal-column
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.
→ 7 CommentsTags:quick · tips
Quick Tip: re-builder
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.
→ 5 CommentsTags:quick · tips
Tab Completion Everywhere
March 12th, 2007 by Ryan McGeary · 8 Comments
I am addicted to tab completion in the minibuffer and in shells like bash — so much so that I want it everywhere. By default, emacs comes with dabbrev-expand (bound to M-/). When invoked after typing the first few letters of a word, dabbrev-expand first searches the current buffer and then other open buffers for possible completions. Completions are expanded inline on each subsequent call. This is pretty close to what we want, but it’s not the TAB key. We could rebind dabbrev-expand to TAB, but then how would we indent a line? Let’s apply a little bit of elisp smarts.
1 2 3 4 5 6 7 8 9 | (defun indent-or-expand (arg) "Either indent according to mode, or expand the word preceding point." (interactive "*P") (if (and (or (bobp) (= ?w (char-syntax (char-before)))) (or (eobp) (not (= ?w (char-syntax (char-after)))))) (dabbrev-expand arg) (indent-according-to-mode))) |
If we’re at the end of a word boundary, this function invokes dabrev-expand; otherwise, indent-according-to-mode. To avoid errors, the bobp and eobp calls are there to make sure we’re not looking for characters before or after the buffer’s boundary. An interactive prefix argument is optional and is passed directly to dabbrev (C-h f dabbrev-expand for more info).
A positive prefix argument, N, says to take the Nth backward distinct possibility. A negative argument says search forward.
I find that this makes for some wicked-cool behavior. For me, it seems intuitive and natural. But wait, we haven’t bound this to TAB yet. Let’s do that now.
1 2 3 4 5 6 7 | (defun my-tab-fix () (local-set-key [tab] 'indent-or-expand)) (add-hook 'c-mode-hook 'my-tab-fix) (add-hook 'sh-mode-hook 'my-tab-fix) (add-hook 'emacs-lisp-mode-hook 'my-tab-fix) ;; more mode hooks, yada yada, etc ... |
To avoid strange behavior in the minibuffer and other special buffers, it is necessary to rebind TAB only in local modes. I’m sure there is a smarter/cleaner way to do this by instead excluding only the problematic buffers or modes, but I’ll leave that as an exercise for the reader (please post a comment if you have a solution though).
Credits: While I’ve had this nugget in my .emacs for a very long time, I cannot take credit for it. I’ve seen similar solutions in several places, and while I tweaked it a bit myself, I originally stole it from someone else. Emacs-Rails takes this approach one step further by also including snippet support.
Hippie Expand Alternative
We used dabbrev-expand above, but I am considering changing that to hippie-expand instead. Hippie Expand is more powerful, but might require some customization to suit to your liking. I’m not ready for groovy vans or tie-dye, so we’ll have to talk about the details of Hippie Expand sometime later.
→ 8 CommentsTags:elisp · tips
Quick Tip: scroll-all-mode
March 8th, 2007 by Ryan McGeary · No Comments
I don’t use this minor mode very often, but in rare cases, I find it valuable. When you have your frame split with multiple windows, sometimes it’s nice to scroll all the windows in unison. Try running M-x scroll-all-mode. Afterwards, scrolling commands entered in one window apply to all visibile windows. This works especially well when you have two windows split horizontally (C-x 3, side by side). To turn the behavior off, just run M-x scroll-all-mode again.
P.S. If it weren’t for Ediff, I’d probably scroll-all more often.
→ No CommentsTags:quick · tips
Recent Features in Carbon Emacs
March 5th, 2007 by Rob Christie · No Comments
It’s always nice to delete code or configuration files while maintaining or increasing functionality. The 2007-01-06 Carbon Emacs build now imports paths from the user’s shell (bash, tcsh, zsh). Note: The latest available build is from 2007-01-21, and includes a few more goodies. This added functionality allowed me to delete a few setq exec-path and setenv "PATH" statements from my .emacs.
Carbon Emacs includes a number of bundled lisp packages. Since my switch to Mac OS X and Carbon Emacs last year, I started removing duplicate lisp packages from my load path. The decision of whether to keep a package in my site lisp or utilize the bundled package was initially hard. I am a pack rat by nature, and initially I didn’t want to give up control. Eventually, I decided to use the bundled packages for all but the modes that I already update directly from version control repositories. My rationale is that if I am not actively updating a package, then it’s better to just clean up my site-lisp folder and reduce the clutter.
→ No CommentsTags:misc · news · osx
G-client: Google Services in Emacs
March 3rd, 2007 by Ryan McGeary · No Comments
If you are the type who likes to do everything within emacs, check out g-client. For a full writeup, read An Emacs Client For Google Services to learn how to integrate Google’s Blogger, Reader, and Calender with emacs.
→ No CommentsTags:misc · news
Quick Tip: Highlighting Java .properties Files
March 1st, 2007 by Rob Christie · 1 Comment
Java .properties files are normally formatted using conf-javaprop-mode. Recently, I was frustrated because a single quote in a property was highlighted such that multiple lines were colored like a string until there was another quote on another line. I decided I was going to fix it… It turns out that I didn’t have to look far. C-h f conf-javaprop-mode led me to read about conf-mode which led to finding the command conf-quote-normal. This command sets the syntax of ‘ and “ to punctuation. This is the joy of using emacs. It’s the little things. My new .emacs snippet follows:
(add-hook 'conf-javaprop-mode-hook '(lambda () (conf-quote-normal nil)))
Before

After

→ 1 CommentTags:java · quick · tips
Quick Tip: Add occur to isearch
February 27th, 2007 by Ryan McGeary · 9 Comments
Zenspider gives us an excellent tip for extending incremental search. Add this to your emacs initialization:
1 2 3 4 5 6 | (define-key isearch-mode-map (kbd "C-o") (lambda () (interactive) (let ((case-fold-search isearch-case-fold-search)) (occur (if isearch-regexp isearch-string (regexp-quote isearch-string)))))) |
This adds an extra keybinding to interactive search (
C-s) that runsoccuron the current search string/regexp, immediately showing all hits in the entire buffer. I use it all the time now.
Seeing as how I run incremental searches subconsciously before even thinking about running occur, I can see myself using this shortcut constantly. I tried it on the emacs tutorial (C-h t):
C-s foo C-o

→ 9 CommentsTags:elisp · isearch · quick · tips
Quick Tip: Reuse Dired Buffers
February 25th, 2007 by Ryan McGeary · 1 Comment
By default, dired creates new buffers when visiting new directories. Sometimes this is desired, especially when you need to visualize the contents of two separate directories; however, when you’re just navigating around, all the extra buffers tend to clutter your buffer list.
Typical navigation is done with dired-find-file (bound to f, RET, or e) or dired-find-file-other-window (bound to o). When performed on a directory, this visits the directory in a new dired buffer. In Emacs 22, instead try running dired-find-alternate-file (bound to a). This replaces the current buffer keeping the clutter of dired buffers to a minimum.
When you run dired-find-alternate-file 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.
(put 'dired-find-alternate-file 'disabled nil)
Bibliography
GNU Emacs Manual, Visiting Files in Dired
EmacsWiki, DiredReuseDirectoryBuffer — includes other ways to enable similar behavior in Emacs 21.
→ 1 CommentTags:dired · quick · tips