[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: M-q on comments in source code
From: |
lee |
Subject: |
Re: M-q on comments in source code |
Date: |
Sat, 24 May 2014 20:00:45 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux) |
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> This formatting is a bit silly ... What can I do to get the comments
>> formatted as in the first example, i. e. the comment indented with the
>> source but with each line trimmed to a length of about max 75
>> characters, not counting the indentation?
>
> I find this to be a waste of space (you'll need windows
> larger than 80 columns to comfortably edit/browse such files),
The lines in the source can easily get longer than 80 cpl, and my screen
is wider than it is high, so it`s the opposite for me: Source with long
lines is easier to review than source with short, broken lines. And
there`s astyle ...
;;
;; astyle buffer ...
;;
(defun astyle-buffer (mcl)
"Ask for code length and pipe all buffer contents through
astyle and replace with the output from astyle, then do
whitespace-cleanup."
(interactive "nMax code length: ")
(shell-command-on-region (point-min) (point-max) (format "astyle
--max-code-length=%d" mcl) nil t 'shell-command-default-error-buffer t)
(whitespace-cleanup))
... which does break long lines but doesn`t put broken lines back
together. (I have an .astylerc with some settings I like.)
> but if you really want that you can probably get it with something
> like:
>
> (advice-add 'current-file-column :around
> (lambda (orig)
> (if (derived-mode-p 'c-mode)
> (+ fill-column (current-indentation))
> (funcall orig))))
Hmm, yes, this is like Eli suggested, thank you :)
I think I can come up with a function that is called instead of
c-fill-paragraph, adjusts fill-column when comments are formatted, calls
c-fill-paragraph and resets fill-column. That should work ...
I`ll post it once I wrote it.
--
Knowledge is volatile and fluid. Software is power.