Can I use emacs f90-mode with fixed format?

前提是你 提交于 2019-12-23 20:15:38

问题


I'm updating some fortran 77 code to use fortran 90 constructs and emacs is my editor of choice. Currently, the source is in fixed format and that isn't going to change any time soon (due to external constraints). The two emacs major modes that I can choose from are fortran-mode which only highlights the syntax for fortran 77 constructs (It doesn't understand module or contains, etc. as keywords which I find pretty annoying, but it does understand fixed format -- correctly indenting the code where necessary). The other major mode I could use is f90-mode, however, that gets the indentation all wrong which is also slightly annoying. Is there any way to get the syntax highlighting from f90-mode, but the indentation structure used in fortran-mode?


回答1:


It looks like this is indeed possible. Try adding the following to your config file:

(require 'f90)
(add-hook 'fortran-mode-hook 'f90-font-lock-2)

This is just following the solution provided on emacs.stackexchange.com, so thanks should flow to user deprecated!




回答2:


You can achieve some fortran90 like highlighting in fortran-mode by adding

(add-hook 'after-change-major-mode-hook
 (lambda () (font-lock-add-keywords 'fortran-mode
 '(
      ("\\(CONTAINS\\)" 1 font-lock-keyword-face t )
      ("\\(USE\\)"      1 font-lock-keyword-face t )
 ))))

to your ~/.emacs (or ~/.emacs.d/init.el) file.

For a comprehensive solution some additional work with regular expressions would be needed. But with a few lines, you should be able to feel comfortable with your code. Different colors can be gained by using different faces:

font-lock-comment-face
font-lock-constant-face
font-lock-function-name-face 
font-lock-keyword-face
font-lock-type-face
font-lock-warning-face


来源:https://stackoverflow.com/questions/14319854/can-i-use-emacs-f90-mode-with-fixed-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!