Emacs Resources

Tips and Tricks

I am collecting some nifty tips and tricks here for you to use… soon come…

C Indentation Style

There are several built in styles in Emacs for indentation of C code. To select between them you can use the key sequence C-c . and if you double-tab there you will get a list of such styles.

It is pretty easy to write a new style if you disagree with these coding styles. Personally I like the Linux coding style myself, although it took a bit to get used to it is actually very nice. I agree with Linus Torvalds when he says that an 8 char or tab indentation is not too much. When you are in hack mode at 4AM it is pretty nice.

In a later article I will write about this more in depth.

Start files updated

Start file for the Gnus news and mail reader for Emacs

Gnus is an excellent system of reading mail and news in. I especially love it since now I can share my mail and news database and newsrc across different operating systems, in principle there is no difference between Gnus under Linux and Gnus under Windows (with a few exceptions, like pathnames and such).

I just love it. But it wasn’t too easy to set up so I hope other people will benefit from having access to my configuration files. You will need both my .emacs and my .gnus file and then you will have to locate the places in the files where you should enter information apropriate to you, such as server names, email addresses and so on.

Good luck.

My ”.emacs” (start file) for Windows NT

This is the startfile for emacs that I use under Windows NT myself. It works quite well for me. I am using an Microsoft Intellimouse Explorer with the ordinary intellimouse drivers that MS supplies with it and scrolling works fine. I have recently heard of people that uses Logitec mice that they run into certain problems sometimes. I suggest comp.emacs if you have problems with this.

Folding

A nice thing is the folding capabilities of Emacs. If you are editing a large file but wants to concentrate on one part, say a soubroutine in your code you can use folding as a way of temporarily hiding what you do not want to se.

Go to the first line you want displayed, press C-SPC to mark it, go to the last and run the command

M-x narrow-to-region

now only the region you have selected will now show. The first time you do this Emacs may ask you if you want to enable this command since it is by default disabled in some installations of Emacs. Enable it and leave it enabled by answering y to the questions.

The short-hand key for this is C-x n n.

To unfold everything use C-x n w.

Stopping Emacs from moving past last line

One of the things that seems to irritate a lot of people is that emacs employs a free roaming buffer. It means that it is possible to move past the end of the file you are editing without inserting any characters like pressing RET and similar. This behaviour is not appreciated by all people so there is now a setting you can change to affect this behaviour.

(setq next-line-add-newlines nil)

Making Emacs show a clock in the status bar

Try this, if you don’t like 24 hour formats, you can just change or omit that line.

(setq display-time-24hr-format t)
(display-time)

A note on emacs key sequences.

The sequence to save a file in Emacs is C-x s this means that you should hold down the CTRL key, press ”x” while doing so, release all keys and then hit ”s”. The M-q sequence is often used to align text in various input modes, to execute that sequence means to hold down the META or ALT (on a PC keyboard) key and pressing q at the same time. This can be a bit confusing if you are not used to Emacs, but you will soon learn. If you have not allready, take the Emacs tutorial now, C-h t will take you to it.