When using xref with Fortran I noticed that indexing by etags is highly incomplete; Almost exclusively subroutines (and maybe functions) are index, but modules, types, constants and global variables are all ignored.

This situation is even confirmed by the executable:

$ etags --help --lang=fortran
In Fortran code, functions, subroutines and block data are tags.

I am trying to fix the situation by adding regular expressions manually, e.g.

find -name "*.f90" | \
    xargs -d $'\n' etags --append \
          --regex='{fortran}/[[:blank:]]*module[[:blank:]]+\([[:alnum:]_]+\)/\1/i' \
          --regex='{fortran}/\(?:[^(]*\|.*::.*\)\(?1:\_<.*?\_>\)[[:blank:]]*=/\1/i' \

While it works, this makes me wonder if any better method is available -- maybe a specialized tools giving better etags for fortran, or at least a centralized place to store my custom regex list.

  • And you can also file a bug report asking for improvement – Dmitry Oct 16 '19 at 15:57

The simple solution: Use ctags -e instead of etags (assuming "Exuberant Ctags"[1])

While man ctags explicitly says that etags is preferred for use with emacs, ctags seems to have much better fortran support. I now use:

ctags -e --recurse
#      :      :
#      :      `- Recursive processing of subdirectories.
#      :         Apparently also filters by extension, 
#      :         avoiding the need for manual filtering of `find`.
#      :
#      `- Output in emacs mode. 
#         Also changes filename from "tags" to "TAGS"

[1] There are multiple flavors of "Ctags". On my system, "Exuberant Ctags" was installed; Language support, Emacs-compatbility and supported flags may deviate. In the comments, "Universal CTags", a fork[2] of "Exuberant CTags", was recommended.

[2] https://en.wikipedia.org/wiki/Ctags#Universal_Ctags

  • 1
    Is that Exuberant Ctags or “plain old” ctags? – nega Oct 16 '19 at 21:49
  • 1
    @nega, exuberant ctags or universal ctags (recommended). – chen bin Oct 17 '19 at 4:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.