Emacs Paragraph Comments

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

Overview

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.

Usage

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:

fill-paragarph_gpl_bad

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

fill-paragraph_gpl_fixed

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.

fill-paragarph_gpl_short

 

Fix C Comment Block

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

fill_paragraph_c_intro_bad

Fixed comment block:

fill-paragarph_c_intro_fixed

 

 Installation

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

eLispEmacsProgramming

About Nick Guthrie

» has written 38 posts

History