I was starting to code some roc code and I do feel confortable with emacs (doom emacs), so I was thinking that maybe there is someone that already fall in this problem and has some starting guide for me?
Hi @Vincenzo Palazzo (vincenzopalazzo), I'm not sure what you meant precisely. Are you looking for a roc emacs plugin?
Anton said:
Hi Vincenzo Palazzo (vincenzopalazzo), I'm not sure what you meant precisely. Are you looking for a roc emacs plugin?
Sorry if I was not clear, I would like configigure roc syntax hightlight with doom emacs but I was not able to find nothing arond
I'm not aware of any syntax highlighting for emacs but perhaps this solution for vscode could be easily adapted.
An extra note, coffee script and elixir syntax highlighting work ok (and I assume exists for emacs). So you can try those and see if it works for you.
Now we have language server and tree-sitter parser for Roc, so the «roc-mode» for Emacs can be defined relatively easy. After some problems with tree-sitter configuration I got a mode with syntax highlighting and type inference (smart autocompletion is unfortunately don't supported by Roc language server yet):
;;; Roc
(define-derived-mode roc-mode fundamental-mode "Roc")
(add-to-list 'auto-mode-alist '("\\.roc\\'" . roc-mode))
;; LSP
(require 'lsp)
(with-eval-after-load 'lsp-mode
(add-to-list 'lsp-language-id-configuration
'(roc-mode . "roc"))
(lsp-register-client
(make-lsp-client :new-connection (lsp-stdio-connection "roc_ls")
:activation-fn (lsp-activate-on "roc")
:server-id 'theme-check)))
;; tree-sitter
(require 'treesit)
(defun roc-mode-setup ()
(interactive)
(defvar roc-font-lock-rules
(treesit-font-lock-rules
:language 'roc
:feature 'string
'((string) @font-lock-string-face)
:language 'roc
:feature 'comment
'((line_comment) @font-lock-comment-face)
:language 'roc
:feature 'definition
'((value_declaration_left
(identifier_pattern
(long_identifier (identifier) @font-lock-constant-face))))
:language 'roc
:feature 'function
'((application_expression
caller:
(long_identifier_or_op
(long_identifier (identifier) @font-lock-function-name-face))))))
(setq-local treesit-font-lock-settings
roc-font-lock-rules)
(setq-local treesit-font-lock-feature-list
'((string comment definition function variable)))
(treesit-major-mode-setup))
(add-hook 'roc-mode-hook (lambda ()
(roc-mode-setup)
(lsp)
(setq treesit-font-lock-level 4)))
Would you mind putting this into a gist or something shareable? I would love to add this to roc-awesome for others to find.
@Luke Boswell It's not a full-functional Emacs mode, just a proof of concept. I assume it will always be edited by other Emacs users. So I'm afraid gist will not be self-explanatory enough. I believe the link to my answer to myself on Emacs StackExchange with the links to documentation and some explanations would be better: https://emacs.stackexchange.com/a/79675/27177
P.S. Thank you for roc-awesome!
@Yuriy Al. Shirokov
I think @Tad Lispy was working on something similar for doom emacs.
https://discourse.doomemacs.org/t/private-module-for-the-roc-programming-language-major-mode-lsp-support/4254
I don't know enough about emacs to say smart things about this. But I'm gonna try messing with the doom module once I've completed today's AoC :)
I got roc-mode
installed using:
(use-package roc-mode :elpaca (roc-mode :host gitlab :repo "tad-lispy/roc-mode"))
and after I installed the treesitter grammar (by adding (roc "https://github.com/faldor20/tree-sitter-roc")
to my treesit-language-source-alist
and doing M-x treesit-install-language-grammar
), I'm successfully in roc-mode and getting syntax highlighting.
Should automatically tabbing to the right indent and re-indenting regions work?
(Although I've used emacs for many years, I've never really learned the elisp APIs… it took me quite a bit of bludgeoning to find the right incantation to install roc-mode
using elpaca
)
Oooh I didn't see that @Tad Lispy put up a proper repo for roc-mode.
I was just using a file copy-pasted from their nixos repo into mine :sweat_smile:
I also installed the tree sitter grammar in the same way from the same place as you.
There are a few bugs for me as well. Expressions like this ("foo: \(bar) baz")
gets confused about escaping delimiters and mis-colors until EOF.
@Asbjørn Olling could you make an issue on the repo: https://github.com/faldor20/tree-sitter-roc and I'll get it fixed :)
Hi there! Been reading through Roc's documentation past couple of days and am ready to dive in the real thing. My google-fu is failing to find existing stuff, hence reaching out.
Is there something in-progress for Emacs? I am also on NixOS, so any instructions there would also help. I see there is a flake.nix, will check it out
mkrieger1 has marked this topic as unresolved.
A message was moved here from #beginners > ✔ Most basic way to split code across files by mkrieger1.
Last updated: Jul 05 2025 at 12:14 UTC