问题
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