Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

comment mode in emacs

I commonly program in languages that don't have any sort of block/multiline comment (e.g. python [#] and fortran [c or !].). Is there any way to define a minor mode in emacs that would allow me to enter multiline comments? By that I mean, it would cause emacs to wrap text automatically after X lines (say 72) and automatically prepend a comment character (taken from the current major mode) to the beginning of each line?

Sorry if this is a pretty basic question -- my elisp skills are rudimentary at best.

like image 711
mgilson Avatar asked Aug 15 '12 12:08

mgilson


1 Answers

You can use the following code:

(setq fill-column 72)
(setq comment-auto-fill-only-comments t)
(auto-fill-mode t)

This will wrap the text automatically, only for the comments, and will insert the comment character everytime it does a line break.

I have this set up only for programming modes as follows:

(defun my-prog-mode-hook
  (setq fill-column 72)
  (set (make-local-variable 'comment-auto-fill-only-comments) t)
  (auto-fill-mode t))
(add-hook 'prog-mode-hook 'my-prog-mode-hook)

This makes sure that if I turn auto-fill mode in a non programming mode such as AUCTeX all the text gets wrapped and not only the comments.

like image 72
Nicolas Dudebout Avatar answered Sep 30 '22 04:09

Nicolas Dudebout