Monday, April 28, 2008

Emacs Tip #19: Startup Options (-q)

The most useful two options I've found for starting up emacs are:

    -q
and
    -debug-init
The first disables the loading of your .emacs and default.el files, which is handy when you want to differentiate between problems in your .emacs file and problems outside (.Xdefaults, site specific .emacs, etc.).

The second gives you a backtrace when any error happens during loading of your .emacs file. While it doesn't often pinpoint the exact line where things went wrong, it usually gives you a clue as to where to start looking for problems.

For all options, read the manual here: Initial Options - GNU Emacs Manual

Monday, April 21, 2008

Emacs Tip #18: Keyboard Macros

If you find yourself doing a repetitive set of keystrokes, but don't want to bother with learning how to actually write a script for that, then record a keyboard macro.


C-x ( begins recording
C-x ) ends recording
C-x e executes the last keyboard macro
C-x C-k lets you edit the keyboard macro you just wrote

If find yourself using lots of macros, you can even save them to your
.emacs and name them (for later use).

For more documentation, see the info page:

C-h K C-x (

Or check out the Keyboard Macros section in the Emacs wiki.

Monday, April 7, 2008

Emacs Tip #17: flyspell and flyspell-prog-mode

Being in front of the computer hasn't helped my spelling because it's so easy to let the computer catch and fix the spelling errors for me. Of course Emacs has spell checking (M-x spell-{buffer,region,string,word}), but what is really handy is spell-checking as you type.

Enter flyspell.

flyspell is a minor-mode, so enabling it only causes spell-checking in that buffer, so it's handy to add the hooks to turn it on for the modes you deem appropriate (mail messages, text files, etc.). But wait, you do most of your work programming, right? Just turn on flyspell-prog-mode, and only your comments and strings will be checked for spelling errors.

It has the standard installation - only the major entry point is the routine 'flyspell-mode where the filename is "flyspell.el", so you need to tell Emacs to look for that appropriately. Here's what I use to enable flyspell and turn it on for a couple of different modes.


(autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t)
(add-hook 'message-mode-hook 'turn-on-flyspell)
(add-hook 'text-mode-hook 'turn-on-flyspell)
(add-hook 'c-mode-common-hook 'flyspell-prog-mode)
(add-hook 'tcl-mode-hook 'flyspell-prog-mode)
(defun turn-on-flyspell ()
"Force flyspell-mode on using a positive arg. For use in hooks."
(interactive)
(flyspell-mode 1))

Tuesday, April 1, 2008

Emacs Tip #16: check-parens

Ever had trouble finding a mismatched parentheses in a file? Of course not, you don't make mistakes.

But, if you do, you can use the built in functionality of M-x check-parens

The documentation is here Parentheses - GNU Emacs Manual

It doesn't pinpoint the problem as closely as I would have hoped in some modes, but it's better than nothing.