| home | dot | up |
See also how to doxygenate your code.
When I got to the section in the MINOS coding convention document regarding the formatting of source code it reminded me of some simple, kludgy emacs lisp code I had used in the past to save me typing time when starting a new file. I figured I might be able to extend them for MINOS. Luckily before I got very far on this I stumbled onto tempo.el which I had unwittingly used before as the underlining engine of the very nice html-helper-mode.el.
I started looking at the tempo.info file and realized it is a really easy package to use so I started fooling around with trying to codify the conventions which relate to formatting. A few hours later I had something which actually worked. The major time was spent in learning elisp. After this initial coding it should be very trivial for me and others how have a passing understanding of lisp to add in other and modify existing rules.
This code mainly exists for my own benefit, but I would be very happy if others found it useful and ecstatic if people actually wanted to improve on them.
Finally, this documentation is almost longer than the actual code.
This set of macros will allow you to greatly reduce the number of keystrokes you must use when starting a new header (.h) or implementation (.cxx) file. It will also help you adhere to MINOS coding conventions.
The macros work by prompting you for the salient information about the Class, Method or other language constructs you are working on. From this a skeleton or template of code is constructed and inserted into your buffer following the coding conventions. You can then traverse the skeleton to various ``hot points'' and fill in the details.
mkdir ~/.elisp
And add the line:
(setq load-path (cons (expand-file-name "~/.elisp") load-path))
to your .emacs file. Now place the required files in
this directory.
(load "minos.el")
to your .emacs file.
Usage is very simple. By default anything you do is initiated by the keystrokes:
C-cmc
that is, typing a `Control-c' followed by an `m'
and a `c' (short for Minos Conventions). These keys are
only bound locally (ie. only in c++-mode). You will then be
prompted for the name of the
block of code which should be inserted into the current buffer.
If you don't know what the name is, just hit the TAB key
and you will be given a list of possibilities which look something
like:
C-cmc
Block name: TAB
Possible completions are:
header-file implementation-file
See below for how to turn on more functionality
File name completion works, so typing ``imp-TAB'' will complete to ``implementation-file''. After a block type is chosen you will be prompted for various pieces of info such as name of Class (which defaults to be the same as the file's name).
If a prompted input is caught as not fitting the convention you will warned and given a chance to quit the current macro or just accept the unconventional format.
Once a template has been inserted into your buffer you can traverse key points which need further filling in by using the the ``M-]'' and ``M-['' keys. (Unfortunately, these hot points are not saved after closing the file.) These will jump the cursor forward and backward, respectively, among the points which may need further editing.
By default, minos-convention.el will be in a novice and verbose mode. This means not all functionality will be present and that verbose comments will be inserted into your buffer. In general, these comments should be deleted. They give examples or other helpful comments.
Increased functionality will make more templates available and is turned on by putting the following in your .emacs file:
(setq minos-convention-expert t)
To turn off the ``helpful'' comments you can use:
(setq minos-convention-verbose nil)
Other customizations can be made by directly editing the
minos.el file. If you wish, take a look at this file,
however, it is not necessary in order to use these macros.
If there is some manner of customization which is required and is not readily obvious how to implement, contact me.
There is not a whole lot to this package. There are two files:
The minos-conventions.el is split into 4 parts:
Since the template syntax is so simple and fairly well described in the tempo.info it won't be described here.
For each minos-convention- function, one must put a entry in the read statement in the minos-convention function so as to allow completion. The entry must match the name of the function as the function call is actually built from this name.