Daml Syntax Highlighting on Emacs

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!

3 Likes

@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.

1 Like

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.

1 Like

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.

1 Like

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.

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.

1 Like