Fully-featured Fortran setup for Linux/Mac in Emacs (Intel Fortran support included!)

The doctor will see you now…

Checking your Emacs version…
Checking for Doom’s prerequisites…
Checking for Emacs config conflicts…
Checking for great Emacs features…
Checking for private config conflicts…
Checking for stale elc files…
Checking for problematic git global settings…
Checking Doom Emacs…
✓ Initialized Doom Emacs 3.0.0-pre
✓ Detected 36 modules
✓ Detected 136 packages
Checking Doom core for irregularities…
Found font material-design-icons.ttf
Found font weathericons.ttf
Found font octicons.ttf
Found font fontawesome.ttf
Found font file-icons.ttf
Found font all-the-icons.ttf
Checking for stale elc files in your DOOMDIR…
Checking your enabled modules…
:lang markdown
! Couldn’t find a markdown compiler, `markdown-preview’ won’t work
:lang python
! Couldn’t find isort. Import sorting will not work.
! Couldn’t find pipenv. pipenv support will not work.
! Couldn’t find nosetests. Running tests through nose will not work.
! Couldn’t find pytest. Running tests through pytest will not work.
:lang sh
! Couldn’t find shellcheck. Shell script linting will not work

There are 6 warnings!

I could not find anything related to fortran in there

There are a few more things we can check:

  1. Did you run a doom sync -u after adding the +intel flag?
  2. Did you follow the installation instructions listed in SPC h d m fortran regarding ifort?
  3. Outside of Emacs, is ifort on your PATH? Does running ifort in the terminal do anything?
  1. yes
  2. yes except that i installed for root.
  3. yes compiling works from the shell.

Please try installing it locally, as non-root.

Does anyone know how to override the formatting options properly? I would like fprettify to leave spaces around member selection characters (%) but I can’t get the option to take. I’ve tried setting it up in my config.el with variations of this but nothing works.

;; attempting to tweak fprettify to my tastes
(after! fortran ;; and f90, no change
  (set-formatter! 'fprettify
    '("fprettify"
      "--enable-decl -w 4 -") :modes '(f90-mode fortran-mode)
    ))

Looking at the original config as defined within Doom, (after! f90 ...) should be correct. The rest of the settings look alright to me.

As the next thing to check, can you SPC h v apheleia-formatters, look for 'fprettify’s entry, and confirm for me what its entry is?

Hi! From a fresh doom startup with the above, but f90 instead of fortran, I see:

apheleia-formatter nil
apheleia-mode-major-mode #'f90-mode
apheleia-mode-hook (apheleia-mode-set-explicitly)
apheleia-formatters ... not defined

After making a change to the Fortran source and doing a save, I see

apheleia-formatters (fprettify "fprettify" "--enable-decl -w 4 -")
apheleia-mode-alist (f90-mode . fprettify)

But when I edit the code and save, affected lines are not reformatted.

I checked buffers B i and I see no errors. I do see file write messages. lsp related buffers show no errors.

Confused here :slight_smile:

Edit: I ran the fprettify command in a terminal session without the trailing “-” but specifying the file name, and the formatting commands worked as expected. It looks as if apheleia wants to use stdin though. Using fprettify as a filter with redirection in the terminal works too. So, we know the command arguments are correct.

Reading back, when I say the affected lines are not reformatted, I mean no reformatting is done. If I enter extraneous spaces or blank lines, they are not removed with the attempted override in place within doom. If I remove my config changes, they are.

One more thing to quickly check. What does SPC c f do, when you do have lines present that should be reformatted?

Also nothing, with no diagnostics in messages. I also tried selecting a region that should be formatted and tried SPC c f, no change.

That’s actually a surprise. I had though that SPC c f and automatic reformat-on-save had a slightly different code path, but I’ll reconfirm.

@blametroi Could you supply a particular code snippet that’s failing to format? Things seem to be working on my end, so I’d like to confirm with the same code you’re looking at.

I’ll get you something smaller than the code I’m working on in a bit, but if it’s working for you I wonder if it’s a local install issue. Mac M2 air (current on all updates). Doom doctor throws a few warnings (see below) that are unrelated to Fortran. fprettify is from homebrew, v 0.3.7.

(base) troi ~ $ doom doctor
The doctor will see you now...

> Checking your Emacs version...
> Checking for Doom's prerequisites...
> Checking for Emacs config conflicts...
> Checking for missing Emacs features...
  ! Emacs was not built with native compilation support
    Users will see a substantial performance gain by building Emacs with
    native compilation support, availible in emacs 28+.You must install a
> Checking for missing Emacs features...
  ! Emacs was not built with native compilation support
    Users will see a substantial performance gain by building Emacs with
    native compilation support, availible in emacs 28+.You must install a
    prebuilt Emacs binary with this included, or compile Emacs with the
    --with-native-compilation option.
> Checking for private config conflicts...
> Checking for common environmental issues...
> Checking for stale elc files...
> Checking for problematic git global settings...
> Checking Doom Emacs...
  ✓ Initialized Doom Emacs 3.0.0-pre
  ✓ Detected 54 modules
  ✓ Detected 206 packages
  > Checking Doom core for irregularities...
    ! Your $HOME is recognized as a project root
      Emacs will assume $HOME is the root of any project living under $HOME. If this
      isn't desired, you will need to remove ".git" from
      `projectile-project-root-files-bottom-up' (a variable), e.g.

        (after! projectile (setq projectile-project-root-files-bottom-up (remove ".git"
          projectile-project-root-files-bottom-up)))
    Found font NFM.ttf
  > Checking for stale elc files in your DOOMDIR...
  > Checking your enabled modules...
    > :completion vertico
      ! The installed grep binary was not built with support for PCRE lookaheads
    > :lang cc
      ! Couldn't find glslangValidator. GLSL code completion is disabled
      ! Irony server isn't installed. Run M-x irony-install-server
      ! Couldn't find the rtag client and/or server programs (rdm rc). Disabling rtags support

There are 6 warnings!

More in a bit, and thanks again for your help!

Updating doom was a bit of an adventure…a bit noisy but done. I had only synced over the past two weeks.

First, here’s a Fortran program that exhibits the behavior on my system. Some other notes following:

program list
   use iso_fortran_env
   implicit none
   type node_t
      integer :: this
      type(node_t), pointer :: next
   end type node_t
   type(node_t), pointer :: root
   type(node_t), pointer :: curr
   integer :: i, j, k
   nullify (root)
   nullify (curr)
   do i = 1, 100
      if (.not. associated(root)) then
         allocate (curr)
         curr%this = i
         root => curr
         cycle
      end if
      allocate (curr%next)
      curr%next%this = i
      curr => curr%next
   end do
   curr => root
   k = 0
   do while (associated(curr))
      k = k + curr%this
      curr => curr%next
   end do
   print *, k
end program list

Without the attempted override in my config.el, the default fprettify behavior (see line curr => curr%next) is as expected. If you edit that line to put spaces around the % and save, they are removed.

fprettify at the command line with the options I want produces what I expect, spaces around the %.

Additionally, I restarted doom emacs and tried the SPC c f and if I have not yet changed the file and saved it, apheleia is not loaded so I get:

and: Symbol’s function definition is void: apheleia--get-formatters

With the overrides in place in my config.el, I get no formatting at all. No messages, no change to text. And the apheleia-formatters entry does show my overrides.

A head scratcher for sure.

I’m not an emacs power user, so my config/init/packages for doom aren’t tweaked. My config sets theme and fonts and loads a custom pascal mode, but I’m not doing any pascal right now.

I’ll beat on it some more. If you think of anything I should try, let me know, and thanks.

@fosskers, I think I found the problem, and I feel kinda dumb. My change below (from original report) looks ok to us humans, but when I went to the apheleia repo I noticed that one example they had for using black passed each option as a separate quoted string.

I changed the options to "--enable-decl" "-w 4" "-" and it works now.

I find the lack of an error report from apheleia annoying.

Thanks for your help and time, and for creating the module.

Troy.

1 Like

Ah great, that was going to be the next thing I suggested if I couldn’t reproduce the issue with your code.

Okay, I’m glad that worked out! Please let me know if you have any other issues.

@blametroi docs(fortran): show how to customize fprettier by fosskers · Pull Request #7659 · doomemacs/doomemacs · GitHub

1 Like