Emacs Paragraph Comments

Posted on by on June 5th, 2013 | 0 Comments »


I often want to write high level paragraph descriptions of functions as internal documentation to my code.  I added a regular expression that determines the start of comments and can correctly indent them.  Even if you add a word (making the line overflow the fill-column) you simply invoke fill-paragraph again and it will fix the line, without having to manually go through every line.


For a long paragraph with a comment in front, invoke "fill-paragraph"Fix into paragraphs in lisp.

Fix paragraphs in Lisp

Lets say you have a GPL clase and you want to properly align all the words.  I have paragraphs seperated by ;; on the next line:


By invoking fill paragraph with M-q it fixes the paragraphs nicely:


If I modify the fill-column by typing: M-x set-fill column 50, and then re-invoking set-fill-column, I can easily make the paragarph line lengths very short if I want.



Fix C Comment Block

You can do the same for C comment blocks: Long comment block:


Fixed comment block:




Add the following code to your .emacs file
;; -----------------------------------------------------------------------------
;; -- C C++ C# Mode
;; -----------------------------------------------------------------------------
(add-hook 'c-mode-common-hook
	  '(lambda () 
	     (set-fill-column 80)
	     ;;M-q to fill /** */ Paragraph Segments
	     (setq paragraph-start "^[ ]*\\(///\\|\\**\\)[ ]*\\([ ]*$\\|@\\)\\|^\f")
Emacs Tempo Tags (Template Expansion)
Linux Mint Debian MATE Easily Splitting Windows

Categorized Under


About Nick Guthrie

» has written 38 posts