我正在编写一个fortran代码。消息来源是用老式的f77风格写的,但f90的评论风格是用"!"获得授权。我想编辑emacs在带有注释的行上点击tab时的行为。我可以区分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搞疯了。如果一些口齿不清的勇士能帮助我,我会很高兴。
感谢
您可以通过以下方式获得您想要的第二类和第三类评论:
(setq fortran-comment-indent-style 'relative)
(add-hook 'fortran-mode-hook (lambda () (setq comment-column 0)))
对于您的第一类评论,您需要破解,如下所示:
(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))))