Column guide in Emacs

Many professional editors have a column guide. For example, below you see in the Powershell editor a veritcal line at column 80.

image

This marker comes in handy, if you want to print your files. In Emacs I usually check for the column 80 in the status line.

image

However, I usually forget to check, and when I print out stuff or publish, I got line breaks where I don’t want them. Passing the 80th column for comments is not a problem, as a simple Ctrl-q forces Emacs to break the lines nicely and add comment symbols at the beginning.

image

But after hitting Ctrl-q, Emacs produces this:

image

There is, however, a package, that mimics column guide seen in other editors. The package is called “fill-column-indicator”. Installing this package will do the trick. After installing, you only have to add the following lines to your .emacs file:

image

I added two hooks, so the column rule appears automatically in Gams and ess.

More information can be found here: http://www.emacswiki.org/emacs/FillColumnIndicator

Using file templates in Emacs

A good practice in modeling is to place information related to the project your are working on, the subject, the data and your personal information like E-mail address at the top of your file. In Emacs you can define skeleton functions that will prompt for the information and put it in the file. Below is an example for a file with as comment symbol “**: (the $Id: $ is for my version control system, that automatically will add the information on the last commit in this line).

image

Below you see how to make a function using skeleton. As I don’t want to repeat myself, the function asks as an input the comment symbol(s) that should be used. I now can use the function for different programming languages (R uses “#” , C++ uses two forward slashes, GAMS “*”, etc.). You can add the time and date by using the command “current-time-string”. All other inputs that have skeleton-read in front of it, are also prompted for. If you need the template for your whole project team, you could just make the author and contact field also input-dependent.

image 

More information can be found at: SkeletonMode. (note that this is part of Emacs since version 22).

PS. The function puts an extra comment symbol at the end (not shown). This is a bug in my function. Any ideas how to get rid of this are welcome.