Fill comments in emacs python-mode
cut_me_out at hotmail.com
Tue Sep 5 18:08:00 CEST 2000
> Here's an elisp function that will fill only a multiline comment, if
> it's called while the cursor is inside one.
There were a couple of boundary conditions I neglected. Here's a
(defun py-fill-paragraph (justify_p)
"Restrict the fill to the surrounding comment, if there is one."
(if (looking-at "\\s-*#")
;; This is inside a comment; restrict the fill to it.
;; ...find the boundaries of the comment
(let ((comment-start (progn
(re-search-forward "\\(^\\s-*[^ #]\\|\\'\\)")
;; That search could have taken us to either the first
;; non-comment line, or the end of a comment line at the
;; end of the buffer. In the first case, need to avoid
;; filling the line that we hit.
(if (not (looking-at "\\'"))
;; Fill the comment.
(fill-region comment-start (point)))))
;; Just do a normal fill, then.
The chain of destiny can only be grasped one link at a time.
-- Sir Winston Churchill
More information about the Python-list