# Daml Syntax Highlighting on Emacs

**URL:** <https://forum.canton.network/t/daml-syntax-highlighting-on-emacs/3174>\
**Category:** Outreach\
**Tags:** daml, emacs, daml-sdk\
**Created:** [September 20, 2021, 4:21pm UTC](https://forum.canton.network/t/daml-syntax-highlighting-on-emacs/3174 "2021-09-20T16:21:01Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![sully](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/sully/32/2129_2.png) [@sully](https://forum.canton.network/u/sully)\
**Post date:** [September 20, 2021, 4:21pm UTC](https://forum.canton.network/t/daml-syntax-highlighting-on-emacs/3174/1 "2021-09-20T16:21:02Z")

</div>

I have been using this `daml-mode` in Emacs and I find it quite good. Much thanks to @bartfaitamas who, as I understand it, is the author of this code.

These instructions also include an `lsp-mode` for Daml that I haven’t had a chance to play around with yet. When I do get a chance, hopefully I can write another tutorial on that. Or maybe somebody will beat me to it. 🙂

First, create a directory `${HOME}/.emacs.d/lisp/daml-mode`, and copy the following two files into that directory:

1. [daml-mode.el](https://gist.githubusercontent.com/sullivan-da/467d80e042bb4198285c98f942c4461c/raw/8a113d0e6e16d0ea79789945cae7cbb25e3a95af/daml-mode.el)
2. [lsp-mode.el](https://gist.githubusercontent.com/sullivan-da/467d80e042bb4198285c98f942c4461c/raw/8a113d0e6e16d0ea79789945cae7cbb25e3a95af/lsp-daml.el)

Next, add the following snippet into your `${HOME}/.emacs` file:

```haskell
(use-package daml-mode
  :load-path "lisp/daml-mode/"
  :mode "\\.daml\'"
  :bind (:map daml-mode-map
         ("M-n" . flymake-goto-next-error)
         ("M-p" . flymake-goto-next-error)
         ("<tab>" . haskell-indent-cycle))
  :config
  (require 'lsp-daml)
  ;; (setq lsp-daml-extra-arguments '("--scenarios" "no" "--telemetry" "--ghc-option" "-XMonoLocalBinds" "--ghc-option" "-W" "--ghc-option" "-Wno-unused-binds" "--ghc-option" "-Wno-unused-matches" "--RTS" "--jobs" "16" "+RTS" "-N16" "-H10G" "-M12G" "-A20M" "-RTS"))
  )

```

Finally, restart your Emacs server. At this point, you should get syntax highlighting when you open up a .daml file in Emacs!

---

<div class="post-metadata">

**Author:** ![quidagis](https://avatars.discourse-cdn.com/v4/letter/q/dbc845/32.png) [@quidagis](https://forum.canton.network/u/quidagis)\
**Post date:** [September 20, 2021, 11:05pm UTC](https://forum.canton.network/t/daml-syntax-highlighting-on-emacs/3174/2 "2021-09-20T23:05:36Z")

</div>

@sully Great write-up.

Apart from installing Emacs & Lisp, this is simple and in one location.

Thank you 👍🏻

P.S. What is the lag like when you demand highlighting in-code? Using VIM-LSP there is a noticeable lag, when the LSP Server is called to serve. Mildly annoying.

---

<div class="post-metadata">

**Author:** ![sully](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/sully/32/2129_2.png) [@sully](https://forum.canton.network/u/sully)\
**Post date:** [September 21, 2021, 3:01pm UTC](https://forum.canton.network/t/daml-syntax-highlighting-on-emacs/3174/3 "2021-09-21T15:01:08Z")

</div>

Hey thanks @quidagis 😊

I notice no lag for the daml-mode syntax highlighting. As far as the lsp-mode goes, I couldn’t tell you yet. I hope to get around to trying out the LSP at some point.

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [September 21, 2021, 3:42pm UTC](https://forum.canton.network/t/daml-syntax-highlighting-on-emacs/3174/4 "2021-09-21T15:42:09Z")

</div>

The daml language server does not provide any form of syntax highlighting. That’s done on the client side by a bunch of regex specific to your editor. So it really shouldn’t introduce any lag in that regard.

---

<div class="post-metadata">

**Author:** ![quidagis](https://avatars.discourse-cdn.com/v4/letter/q/dbc845/32.png) [@quidagis](https://forum.canton.network/u/quidagis)\
**Post date:** [September 21, 2021, 9:42pm UTC](https://forum.canton.network/t/daml-syntax-highlighting-on-emacs/3174/5 "2021-09-21T21:42:48Z")

</div>

Maybe it _should_ not, but on the 8 Core Desktop, everytime the LSP-Server would detect a Daml term, I could hear the noticeable difference in CPU, therefore CPU fan activity. About 1-3 seconds, then the Daml highlighting would render and the CPU activity would drop back to normal. Verified with Htop.

I was using the Daml-on-Vim config that I posted above. No wonder it is now Headless.

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [September 22, 2021, 6:36am UTC](https://forum.canton.network/t/daml-syntax-highlighting-on-emacs/3174/6 "2021-09-22T06:36:40Z")

</div>

Maybe the vim setup blocks on something else. The language server literally has no code for syntax highlighting so it cannot be slow because of that.

---

<div class="post-metadata">

**Author:** ![arobertn](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@arobertn](https://forum.canton.network/u/arobertn)\
**Post date:** [March 29, 2022, 2:19pm UTC](https://forum.canton.network/t/daml-syntax-highlighting-on-emacs/3174/7 "2022-03-29T14:19:38Z")

</div>

I had to make a couple of tweaks to the lsp mode file to get it working with lsp-mode 8. I’m not able to attach the modified file due to being a new user, but it can be found here: [GitHub gist](https://gist.github.com/arobertn/6018faff699eb412975d6ec81f409233)

Also, a backslash got eaten from the `.emacs` snippet posted above. Here is a repaired version:

```haskell
(use-package daml-mode
  :load-path "/usr/local/share/emacs/site-lisp/daml-mode/"
  :mode "\\.daml\\'"
  :bind (:map daml-mode-map
         ("M-n" . flymake-goto-next-error)
         ("M-p" . flymake-goto-next-error)
         ("<tab>" . haskell-indent-cycle))
  :config
  (require 'lsp-daml)
)

```

---

<div class="post-metadata">

**Author:** ![arobertn](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@arobertn](https://forum.canton.network/u/arobertn)\
**Post date:** [June 3, 2022, 2:28pm UTC](https://forum.canton.network/t/daml-syntax-highlighting-on-emacs/3174/8 "2022-06-03T14:28:16Z")

</div>

By the way it would be nice if this package could be added to [Melpa](https://melpa.org/#/) so it could be easily installed from Emacs directly via `M-x package-install`. [This would entail putting the package itself somewhere publically accessible such as Github, and licensing it with a GPL-compatible license](https://github.com/melpa/melpa/blob/master/README.md#contributing). As the original author, this part would be up to @bartfaitamas. If this _were_ done, then in principle anyone could submit a “recipe” request to the Melpa repo, although in practice it’s preferred that the package author themselves do so.

---

<div class="post-metadata">

**Author:** ![bartfaitamas](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/bartfaitamas/32/95_2.png) [@bartfaitamas](https://forum.canton.network/u/bartfaitamas)\
**Post date:** [June 7, 2022, 7:29am UTC](https://forum.canton.network/t/daml-syntax-highlighting-on-emacs/3174/9 "2022-06-07T07:29:36Z")

</div>

@arobertn I’m trying to find some time this week to start cleaning my code up, make it public and submit it to melpa.

---

<div class="post-metadata">

**Author:** ![bartfaitamas](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/bartfaitamas/32/95_2.png) [@bartfaitamas](https://forum.canton.network/u/bartfaitamas)\
**Post date:** [June 19, 2022, 8:30am UTC](https://forum.canton.network/t/daml-syntax-highlighting-on-emacs/3174/10 "2022-06-19T08:30:04Z")

</div>

Hello guys. I created a repo for this daml-mode here: [GitHub - bartfailt/daml-mode](https://github.com/bartfailt/daml-mode)

---

<div class="post-metadata">

**Author:** ![kayvank](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/kayvank/32/4586_2.png) [@kayvank](https://forum.canton.network/u/kayvank)\
**Post date:** [September 16, 2022, 11:02pm UTC](https://forum.canton.network/t/daml-syntax-highlighting-on-emacs/3174/11 "2022-09-16T23:02:38Z")

</div>

Thank you for the writeup. This worked great on my emacs doom. The only modification I had to make was to the load-path to make fit into my setup.  
` :load-path "~/.emacs.d/lisp/daml-mode/"`

---

<div class="post-metadata">

**Author:** ![bartfaitamas](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/bartfaitamas/32/95_2.png) [@bartfaitamas](https://forum.canton.network/u/bartfaitamas)\
**Post date:** [March 27, 2023, 5:30am UTC](https://forum.canton.network/t/daml-syntax-highlighting-on-emacs/3174/12 "2023-03-27T05:30:23Z")

</div>

I updated daml-mode in my repository.

- lsp-mode now supports displaying script results  
You need to click the “lens” next to your script declaration. It is stlil buggy a little bit: if you kill the result buffer, and then open it up again clicking on the lens, it will be empty until you change the script.
- lsp-mode now gives feedback about processing, as in VSCode
- Syntax highlighting now supports daml 2.x keywords

Haven’t fully tested it yet, so there might be other errors or missing some syntax highlight keywords, please let me know if that’s the case

Also, the script result page is not interactive, you can;t filter out archived contracts, etc.

---

<div class="post-metadata">

**Author:** ![arobertn](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@arobertn](https://forum.canton.network/u/arobertn)\
**Post date:** [September 29, 2023, 12:23pm UTC](https://forum.canton.network/t/daml-syntax-highlighting-on-emacs/3174/13 "2023-09-29T12:23:35Z")

</div>

Hi @bartfaitamas, it’s embarassing how long this has taken, but at any rate I submitted [a PR to add this to Melpa](https://github.com/melpa/melpa/pull/8764). It’s basically a pointer to HEAD of your repo’s main branch. If no objections, I will submit a PR to yours to mention the availability of a Melpa install, and clean up a couple of small docstring linting issues `checkdoc` found.
