Stream: beginners

Topic: roc with emacs


view this post on Zulip Vincenzo Palazzo (vincenzopalazzo) (Dec 04 2022 at 17:09):

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?

view this post on Zulip Anton (Dec 05 2022 at 08:23):

Hi @Vincenzo Palazzo (vincenzopalazzo), I'm not sure what you meant precisely. Are you looking for a roc emacs plugin?

view this post on Zulip Vincenzo Palazzo (vincenzopalazzo) (Dec 06 2022 at 16:40):

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

view this post on Zulip Anton (Dec 06 2022 at 16:58):

I'm not aware of any syntax highlighting for emacs but perhaps this solution for vscode could be easily adapted.

view this post on Zulip Brendan Hansknecht (Dec 06 2022 at 17:04):

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.

view this post on Zulip Yuriy Al. Shirokov (Nov 30 2023 at 22:07):

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)))

view this post on Zulip Luke Boswell (Nov 30 2023 at 22:22):

Would you mind putting this into a gist or something shareable? I would love to add this to roc-awesome for others to find.

view this post on Zulip Yuriy Al. Shirokov (Dec 01 2023 at 09:16):

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

view this post on Zulip Asbjørn Olling (Dec 01 2023 at 12:36):

@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 :)

view this post on Zulip Zellyn Hunter (Dec 06 2023 at 23:09):

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?

view this post on Zulip Zellyn Hunter (Dec 06 2023 at 23:11):

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

view this post on Zulip Asbjørn Olling (Dec 07 2023 at 13:17):

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:

view this post on Zulip Asbjørn Olling (Dec 07 2023 at 13:20):

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.

view this post on Zulip Eli Dowling (Dec 10 2023 at 02:29):

@Asbjørn Olling could you make an issue on the repo: https://github.com/faldor20/tree-sitter-roc and I'll get it fixed :)

view this post on Zulip Payas (Dec 14 2023 at 14:45):

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

view this post on Zulip Notification Bot (Dec 14 2023 at 14:58):

mkrieger1 has marked this topic as unresolved.

view this post on Zulip Notification Bot (Dec 14 2023 at 14:58):

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