[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: f90 comments indentation
From: |
Glenn Morris |
Subject: |
Re: f90 comments indentation |
Date: |
Fri, 17 Oct 2003 18:31:20 +0100 |
User-agent: |
Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/) |
Stefan Monnier wrote:
>> I am writing f90 programs and I have turned auto-fill mode on. I
>> want my comments to be indented to where my earlier comment line
>> starts. So, for example, what I want is this (irrespective of the
>> comment column)
>
>> real, (kind=long), dimension(3,3) :: abcd ! This is a test
>> ! comment
>
>> But, what I get is
>
>> real, (kind=long), dimension(3,3) :: abcd ! This is a test
>> ! comment
>
> If this is what you get after hitting SPC (which triggered auto-fill),
> then it's a bug that you should report with M-x report-emacs-bug
That would not be a bug, because by default (controllable through
f90-indented-comment-re) f90-mode indents "!" comments as code, not to
comment-column.
> If that's what you get after hitting TAB on the second line, then
> it's a problem with indentation of comments (which is sadly partly
> separate from the indentation that takes place during auto-fill) and
> there might be some convention that you need to follow (such as
> using some other comment marker, or using two or three ! or ...).
(setq f90-indented-comment-re "!!")
would get "!" comments indented to comment-column, but would not
necessarily align them as the OP wants (if the non-comment portion of
the first line extended beyond comment-column). There's no option in
f90 for that style, but there probably could (and maybe should) be. In
the meantime, combining the above setting with something like the
following seems to work:
(defadvice f90-indent-line (around set-comment-column activate)
"Set comment-column so as to align consecutive trailing comments."
(let ((comment-column comment-column)
col f90-cache-position)
(save-excursion
(beginning-of-line)
(skip-chars-forward " \t")
(when (and (looking-at "!") (zerop (forward-line -1)))
(setq f90-cache-position (point))
(end-of-line)
(while (and (f90-in-comment)
(search-backward "!" f90-cache-position t))
(setq col (current-column)))
(or (looking-at f90-indented-comment-re)
(and col (setq comment-column col)))))
ad-do-it))