我正在研究一个fortran代码。源代码是用旧时尚f77风格写的,但f90评论风格,带'!'被授权。我想在点击带有注释的行上的标签时编辑emacs行为。我可以区分3种类型的评论:
program helloworld
integer:: i,j
do i=1,1
do j=1,1
* This is a first type of comment
* another first type comment
! second type of comment
print *,"helloworld" ! third type of comment
enddo
enddo ! another third type comment
end program helloworld
当用评论类型点击每一行的标签时,我得到了
program helloworld
integer:: i,j
do i=1,1
do j=1,1
* This is a first type of comment
* another first type comment
! second type of comment
print *,"helloworld" ! third type of comment
enddo
enddo ! another third type comment
end program helloworld
我想要的行为是,在一行上点击标签:
我试图在我的init.el中覆盖fortran.el中的一些函数,但是对于lisp发疯了。如果一些lisp / emacs战士可以帮助我,我会很高兴。
由于
答案 0 :(得分:4)
您可以通过以下方式实现第2和第3类评论的目标:
(setq fortran-comment-indent-style 'relative)
(add-hook 'fortran-mode-hook (lambda () (setq comment-column 0)))
对于您的第一类评论,您需要 hack ,如下所示:
(defadvice fortran-indent-line (after custom-indentation activate)
(save-excursion
(forward-line 0)
(when (looking-at "*")
(forward-char 1)
(just-one-space))))
修改强>
尊重您的上一次评论需要更复杂,更丑陋的黑客攻击。 替换之前的defadvice
:
(defadvice fortran-indent-line (around custom-indentation activate)
(let ((type-* (save-excursion
(forward-line 0)
(looking-at "\s*\\*")))
(type-! (save-excursion
(forward-line 0)
(looking-at "\s*!"))))
(if type-!
(progn
(save-excursion
(forward-line 0)
(re-search-forward "!")
(replace-match "__"))
ad-do-it
(save-excursion
(forward-line 0)
(re-search-forward "__")
(replace-match "!"))
)
(if (not type-*)
ad-do-it))))