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

**URL:** <https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532>\
**Category:** Announcements\
**Created:** [May 23, 2022, 7:05pm UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532 "2022-05-23T19:05:32Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![fosskers](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fosskers/32/1705_2.png) [@fosskers](https://fortran-lang.discourse.group/u/fosskers)\
**Post date:** [May 23, 2022, 7:05pm UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/1 "2022-05-23T19:05:33Z")

</div>

Hi everyone, we here from the [Doom Emacs](https://github.com/doomemacs/doomemacs) project recently completed its brand-new [Fortran Module](https://github.com/doomemacs/doomemacs/blob/master/modules/lang/fortran/README.org). Out of the box, it automatically supports:

1. Integration with `fpm`.
2. LSP support via `fortls`.
3. Auto-formatting via `fprettier`.
4. (Optional) **Intel Fortran**! (Otherwise `gfortran` is the default).

This should provide a fully-featured, modern Fortran setup for anyone on Linux or MacOS. The Intel support is especially important, given how much of a pain its installation / editor integration has been outside of the classic Windows + Visual Studio setup.

If you try out this module and have any issues, please let me know! I’m also regularly available on Doom’s Discourse or its Discord.

Happy computing!

---

<div class="post-metadata">

**Author:** ![gnikit](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/gnikit/32/1213_2.png) [@gnikit](https://fortran-lang.discourse.group/u/gnikit)\
**Post date:** [May 23, 2022, 8:31pm UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/2 "2022-05-23T20:31:49Z")

</div>

Welcome to the community @fosskers and also nice seeing `fortls` being part of the mix!

---

<div class="post-metadata">

**Author:** ![Aurelius\_Nero](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Aurelius\_Nero](https://fortran-lang.discourse.group/u/Aurelius_Nero)\
**Post date:** [May 23, 2022, 8:43pm UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/3 "2022-05-23T20:43:35Z")

</div>

Small question. Does this work on vanilla Emacs as well or just Doom Emacs ?

---

<div class="post-metadata">

**Author:** ![shahmoradi](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahmoradi/32/3151_2.png) [@shahmoradi](https://fortran-lang.discourse.group/u/shahmoradi)\
**Post date:** [May 23, 2022, 8:52pm UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/4 "2022-05-23T20:52:31Z")

</div>

Thanks for sharing. This is great. Does this also work fully in Microsoft WSL? I just installed it and it seems like it works, but I am not sure if it has all the bells and whistles it gets in the native Unix environment.

---

<div class="post-metadata">

**Author:** ![fosskers](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fosskers/32/1705_2.png) [@fosskers](https://fortran-lang.discourse.group/u/fosskers)\
**Post date:** [May 23, 2022, 9:46pm UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/5 "2022-05-23T21:46:12Z")

</div>

There are Fortran modes for F90 and legacy Fortran built in to Emacs natively, and this module uses those and expands on them. The “module” however, is Doom-specific, so requires Doom to be installed and configured. Note that Doom is just Emacs with a lot of packages/settings pre-configured for convenience.

---

<div class="post-metadata">

**Author:** ![fosskers](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fosskers/32/1705_2.png) [@fosskers](https://fortran-lang.discourse.group/u/fosskers)\
**Post date:** [May 23, 2022, 9:46pm UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/6 "2022-05-23T21:46:52Z")

</div>

I don’t see why not? So long as you get Doom installed, it should work.

---

<div class="post-metadata">

**Author:** ![Pap](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pap/32/1305_2.png) [@Pap](https://fortran-lang.discourse.group/u/Pap)\
**Post date:** [May 24, 2022, 7:33am UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/7 "2022-05-24T07:33:19Z")

</div>

Welcome @fosskers!  
I was about to ask the same question as @Aurelius_Nero just did. Well, I guess it’s time to give Doom Emacs a try - although I must admit I avoided it so far because lots of packages usually means larger memory footprint - and I’m still using some legacy computers with vanilla Emacs somewhat stripped.

---

<div class="post-metadata">

**Author:** ![fosskers](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fosskers/32/1705_2.png) [@fosskers](https://fortran-lang.discourse.group/u/fosskers)\
**Post date:** [May 24, 2022, 4:41pm UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/8 "2022-05-24T16:41:36Z")

</div>

Doom requires at least Emacs 27, but since Emacs 28 is out now, you might as well use that. It features the new Elisp “native compilation” feature which really speeds up Emacs itself. As for memory footprint… my `emacs` process is currently sitting at 2.7% RAM. For comparison, Firefox is over 10%.

---

<div class="post-metadata">

**Author:** ![glemieux](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/glemieux/32/1990_2.png) [@glemieux](https://fortran-lang.discourse.group/u/glemieux)\
**Post date:** [February 17, 2023, 7:47am UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/9 "2023-02-17T07:47:16Z")

</div>

Thanks for this module! I’m a complete emacs (doom or otherwise) noob and I can’t seem to get the module to automatically recognize `.F90` files extensions. By contrast I don’t have an issue with other `:lang` modules (e.g. `julia`). Aside from updating my `.doom.d/init.el` file to use `(fortran +lsp)` (and making sure that `lsp` is also enabled in `:tools`), is there something else that needs to be enabled?

---

<div class="post-metadata">

**Author:** ![Pap](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pap/32/1305_2.png) [@Pap](https://fortran-lang.discourse.group/u/Pap)\
**Post date:** [February 17, 2023, 10:46am UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/10 "2023-02-17T10:46:05Z")

</div>

Hi @glemieux, welcome to the Fortraners Discourse.

By default, Emacs uses Fortran mode for files with several specific extensions (have a look [there](https://www.gnu.org/software/emacs/manual/html_node/emacs/Fortran.html).) The list of recognized extensions doesn’t include `.F90`, but you can easily set this (or any other extension you like) in your `init.el`. For example, Add this:

```auto
(add-to-list 'auto-mode-alist '("\\.foo\\'" . f90-mode))

```

to make Emacs activate Fortran 90 mode for `*.foo` files. I am using “vanilla” Emacs (with some packages from Melpa) but I will be surprised if this doesn’t work in Doom Emacs as well.

---

<div class="post-metadata">

**Author:** ![RonShepard](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@RonShepard](https://fortran-lang.discourse.group/u/RonShepard)\
**Post date:** [February 17, 2023, 2:49pm UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/11 "2023-02-17T14:49:28Z")

</div>

> [@Pap](#):
>
> Add this:
> 
> ```auto
> (add-to-list 'auto-mode-alist '("\\.foo\\'" . fortran-mode))
> 
> ```
> 
> to make Emacs activate Fortran mode for `*.foo` files.

Just to avoid some confusion, emacs has two different fortran modes, fortran-mode for fixed-form and f90-mode for free-form source. They are basically treated like different languages, with different indent options, and so on.

---

<div class="post-metadata">

**Author:** ![Pap](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pap/32/1305_2.png) [@Pap](https://fortran-lang.discourse.group/u/Pap)\
**Post date:** [February 17, 2023, 3:18pm UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/12 "2023-02-17T15:18:29Z")

</div>

You are right, Ron (I’ve set up my Emacs years ago, and I forgot about that.) I corrected my post accordingly.

---

<div class="post-metadata">

**Author:** ![fosskers](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fosskers/32/1705_2.png) [@fosskers](https://fortran-lang.discourse.group/u/fosskers)\
**Post date:** [February 19, 2023, 7:08am UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/13 "2023-02-19T07:08:13Z")

</div>

Hi @glemieux , the use of Doom’s `fortran` means you shouldn’t have to manually set anything yourself as mentioned by @Pap above. If you’ve added any such lines to your config, please remove them.

Could you describe the exact issue you’re facing? While a long shot, does anything change if you downcase the characters of the file extension to `.f90`?

---

<div class="post-metadata">

**Author:** ![glemieux](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/glemieux/32/1990_2.png) [@glemieux](https://fortran-lang.discourse.group/u/glemieux)\
**Post date:** [February 21, 2023, 6:45pm UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/14 "2023-02-21T18:45:10Z")

</div>

@fosskers Sure enough, downcasing the extensions worked! Is this something that is relatively straightfoward to account for in the module `config.el` file? I’m new to emacs lisp as well.

---

<div class="post-metadata">

**Author:** ![RonShepard](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@RonShepard](https://fortran-lang.discourse.group/u/RonShepard)\
**Post date:** [February 21, 2023, 6:57pm UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/15 "2023-02-21T18:57:14Z")

</div>

The instructions for that are given above a few posts up. I put these commands in my .emacs file in my home directory. The above instructions specify a `init.el` file. I don’t know the difference or which is best. Maybe it is OS dependent?

The de facto standard is that upper case .F90 means that compiler should run the preprocessor, lower case .f90 means that it shouldn’t. So as far as emacs is concerned, both extensions should trigger the f90-mode. One can also manually specify the mode with the `M-x f90-mode` command, but you don’t want to have to do that if you are working on dozens or hundreds of files.

---

<div class="post-metadata">

**Author:** ![Pap](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pap/32/1305_2.png) [@Pap](https://fortran-lang.discourse.group/u/Pap)\
**Post date:** [February 21, 2023, 11:04pm UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/16 "2023-02-21T23:04:50Z")

</div>

> [@RonShepard](#):
>
> I put these commands in my .emacs file in my home directory. The above instructions specify a `init.el` file. I don’t know the difference or which is best. Maybe it is OS dependent?

It is not OS-dependent, although it makes perfect sense to guess it is. In relatively recent versions of Emacs, the standard configuration file is considered to be ~/.emacs.d/init.el. However the traditional ~/.emacs file still works. You can leave it as it is, or you can move it to ~/.emacs.d/ and rename it to init.el.

---

<div class="post-metadata">

**Author:** ![fosskers](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fosskers/32/1705_2.png) [@fosskers](https://fortran-lang.discourse.group/u/fosskers)\
**Post date:** [February 24, 2023, 3:52am UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/17 "2023-02-24T03:52:48Z")

</div>

~~I will fix this upstream.~~

Done: [fix(fortran): account for the `.F90` extension by fosskers · Pull Request #7110 · doomemacs/doomemacs · GitHub](https://github.com/doomemacs/doomemacs/pull/7110)

The fix is already merged, so if you update your Doom (assuming you’re using Doom), then you shouldn’t have to worry about the extension case anymore.

---

<div class="post-metadata">

**Author:** ![glemieux](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/glemieux/32/1990_2.png) [@glemieux](https://fortran-lang.discourse.group/u/glemieux)\
**Post date:** [February 24, 2023, 9:55pm UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/18 "2023-02-24T21:55:07Z")

</div>

Thanks @fosskers! That did the trick.

---

<div class="post-metadata">

**Author:** ![dadudeme](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@dadudeme](https://fortran-lang.discourse.group/u/dadudeme)\
**Post date:** [April 13, 2023, 12:53pm UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/19 "2023-04-13T12:53:18Z")

</div>

I am currently trying to use doom emacs in org mode to write fortran and have ifort installed.

I have the package installed by enabling (fortran +lsp +intel).

But when trying to compile the source blocks i get an error telling me that gfortran is missing.  
my doom emacs version is 042fe0c438  
and ifort version is 2021.8.0

---

<div class="post-metadata">

**Author:** ![fosskers](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fosskers/32/1705_2.png) [@fosskers](https://fortran-lang.discourse.group/u/fosskers)\
**Post date:** [April 21, 2023, 1:55am UTC](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532/21 "2023-04-21T01:55:46Z")

</div>

Thanks for reporting; sorry I didn’t notice right away.

Can you tell me the output of `doom doctor`?

[Next page](https://fortran-lang.discourse.group/t/fully-featured-fortran-setup-for-linux-mac-in-emacs-intel-fortran-support-included/3532.md?page=2)
