Comment Boxes In Emacs

Here’s a neat little hack that can save a bit of time. Emacs has the comment-box command that will put a mode-specific comment box around a region. For example, suppose you have the Elisp

A function to do something very profound.
It is called from the top level.
(defun be-profound ()
...)

and that you select the first two lines and call comment-box. You get

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; A function to do something very profound. ;
; It is called from the top level.          ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun be-profound ()
...)

Similarly if you have some C code like

Here is the the main function
that does something or another

int main ( int argc, char **argv)

and select the first two lines and call comment-box you get

/**********************************/
/* Here is the the main function  */
/* that does something or another */
/**********************************/

int main ( int argc, char **argv)

Back when I was writing a lot of C code I used to put a comment box like that in front of every function. I did it by hand so it was sort of pain. I wish I’d had, or known about, something like comment-box to help me out (that was when I was using Vim).

This entry was posted in Programming and tagged . Bookmark the permalink.