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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With