Skip to content
Discussions/Outreach/Daml Syntax Highlighting on EmacsForum ↗

Daml Syntax Highlighting on Emacs

Outreach13 posts1,271 views11 likesLast activity Sep 2023
SU
sullyOP
Sep 2021

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. :slightly_smiling_face:

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

  1. daml-mode.el
  2. lsp-mode.el

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

(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!

QU
quidagis
Sep 2021

@sully Great write-up.

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

Thank you :+1:t2:

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.

SU
sully
Sep 2021

Hey thanks @quidagis :blush:

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.

CO
cocreature
Sep 2021

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.

QU
quidagis
Sep 2021

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.

CO
cocreature
Sep 2021

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.

AR
arobertn
Mar 2022

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

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

(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)
)
AR
arobertn
Jun 2022

By the way it would be nice if this package could be added to Melpa 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. 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.

BA
bartfaitamas
Jun 2022

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

BA
bartfaitamas
Jun 2022

Hello guys. I created a repo for this daml-mode here: GitHub - bartfailt/daml-mode

KA
kayvank
Sep 2022

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/"

BA
bartfaitamas
Mar 2023

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.

AR
arobertn
Sep 2023

Hi @bartfaitamas, it’s embarassing how long this has taken, but at any rate I submitted a PR to add this to Melpa. 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.

← Back to Discussions