43212

Can I use emacs f90-mode with fixed format?

Question:

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?

Answer1:

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 <a href="https://emacs.stackexchange.com/questions/5288/editing-fortran90-in-a-fixed-format-mode?newreg=e243834485dc442baa012a2b14f59706" rel="nofollow">emacs.stackexchange.com</a>, so thanks should flow to user <a href="https://stackoverflow.com/users/353062/deprecated" rel="nofollow">deprecated</a>!

Answer2:

You can achieve some <a href="/questions/tagged/fortran90" class="post-tag" title="show questions tagged 'fortran90'" rel="nofollow">fortran90</a> 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

Recommend

  • Implementing search&highlight - how can I avoid delays when highlight is slow?
  • Starting a syn region with a keyword
  • CVS command to get the current revision number of file
  • How to validate a url with lots of querystrings
  • iOS two views cover exactly half of parent view
  • Android Ripple: How do other apps make their ripple so transparent without affecting the original co
  • Eclipse dark color theme fixes
  • Mongoose TypeError: Cannot use 'in' operator to search for '_id' in
  • UIPickerView without IB?
  • Mercurial: Identify file name after rename
  • MultiLevel ExpandableListView not highlighting properly
  • How to create two column output from a single column
  • ZipList with Scalaz
  • Create a link to a web page that runs a Javascript function on the page
  • Alamofire and Reachability.swift not working on xCode8-beta5
  • Google Maps api v3 get start and end coordinates of a street
  • C# - Most efficient way to iterate through multiple arrays/list
  • netsh acl setting (need alternative method - registry settings?)
  • Getting media player state in windows phone 7
  • Image map in Flex
  • Question about instantiating object
  • Remove final comma from string in vb.net
  • How do I exclude a dependency in provided scope when running in Maven test scope?
  • Is there a perl module to validate passwords stored in “{crypt}hashedpassword” “{ssha}hashedpassword
  • How do I get HTML corresponding to current DOM tree?
  • Installing Apache MyFaces 2 on WildFly 8.2.0
  • Email verification using google app script and google forms
  • Meteor helpers not available in Angular template
  • Using jQuery closest() method with class selector
  • Insert into database using onclick function
  • Array.prototype.includes - not transformed with babel
  • How to show dropdown in excel using jrxml (jasper api)?
  • python regex in pyparsing
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • using HTMLImports.whenReady not working in chrome
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How can I remove ASP.NET Designer.cs files?
  • python draw pie shapes with colour filled
  • Is there any way to bind data to data.frame by some index?
  • How can i traverse a binary tree from right to left in java?