Friday, March 17, 2006

Effective Emacs

I've always been an Emacs diehard, although I use vi from time-to-time when I have no choice (usually a fresh server install). So I've read the Seven habits of effective text editing, but just can't bear to use vi/vim for anything serious. Anyway, not to be outdone by a mere seven tips, Steve Yegge brings us 10 Specific Ways to Improve Your Productivity With Emacs. There are some particularly good tips in this - I can relate to #7 'Lose the UI', since I don't use the tool- or menubar anyway. Why display it if you don't use it?
You don't need a menu bar. It's just a crutch placed there for disoriented newbies. You also don't need a toolbar with big happy icons, nor do you need a scrollbar. All of these things are for losers, and they are just taking up precious screen real-estate.
One tip I didn't see that I use frequently is the 'mark-whole-buffer' command, bound to 'C-x h' by default. It's great for quickly copying entire buffers - just do 'C-x h M-w' to yank (copy) an entire buffer. In X, you can do this and then paste into another application (like Blogger edit windows in Firefox) with the middle-mouse button. Another good tip from the list at the bottom of host post is the 'align-regexp' function. That one was new to me, but after trying it out, I can see how useful it would be. One of the great things about Emacs is the embedded help - I typed 'C-h f align-regexp<RET>' and got a description of the function with an example:
align-regexp is an interactive compiled Lisp function in 'align.el'. (align-regexp beg end regexp &optional group spacing repeat) Align the current region using an ad-hoc rule read from the minibuffer. beg and end mark the limits of the region. This function will prompt for the regexp to align with. If no prefix arg was specified, you only need to supply the characters to be lined up and any preceding whitespace is replaced. If a prefix arg was specified, the full regexp with parenthesized whitespace should be supplied; it will also prompt for which parenthesis group within regexp to modify, the amount of spacing to use, and whether or not to repeat the rule throughout the line. See 'align-rules-list' for more information about these options. For example, let's say you had a list of phone numbers, and wanted to align them so that the opening parentheses would line up: Fred (123) 456-7890 Alice (123) 456-7890 Mary-Anne (123) 456-7890 Joe (123) 456-7890 There is no predefined rule to handle this, but you could easily do it using a regexp like "(". All you would have to do is to mark the region, call 'align-regexp' and type in that regular expression.
Technorati Tags: , ,

6 comments:

jason said...

I didn't think Steve Yegge's tips were very good. Most of them were rebinding keys, which is just a personal preference.

Even so, I'm against rebinding so many keys. I don't like trying to predict what the rebinding might potentially clash with in the future. I've been wrong before, and had to set the keys back to their default keybindings.

Doug said...

I tend not to re-bind too many keys, also. When I wrote the HTML-mode customizations, I was careful to pick new bindings that were not already in use - best not to surprise someone by wiping out their favorite binding.

Doug

Marc said...

Yeah, I didn't find Steve's tips very useful either. I'm hoping to compile my own list at some point. Currently I only have a few guidelines for beginners, but I'd like to add some of the cooler, more advanced stuff.

http://marc.abramowitz.info/emacs/

Anjan Bacchu said...

hi there,

the link to steve's emacs post doesn't work any longer. he has moved them to
http://steve.yegge.googlepages.com/effective-emacs

BR,
~A

Doug said...

Thank you, I updated it.

Doug

naveeng said...

Hi, can u help me solve the following...

i have a file containing continuous text with commas (',') in between. How to break the line at every comma using emacs???