Spacemacs - General Discussion, Blog Posts, Wiki

Is there a shortcut for embedded Elixir?

<%= %>

Currently you have to type the opening <%= and it will automatically add the closing %> but this is more key presses than in other editors.

Also, html tags - usually you can type something like p then tab and it will give you the opening and closing <p> tags… but this doesn’t work in Spacemacs. Typing p seems to give you the option but pressing enter doesn’t seem to do anything :confused:

The p + tab is done using emmet mode and I got it working with eex, haml and react files. My .spacemacs file is pretty messy but I think I got it working with this customization or this one. Hope it helps.

And these lines are to enable it in react and haml.

  (add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
  (setq web-mode-content-types-alist
        '(("jsx" . "\\.js[x]?\\'")))

  ;; Use emmet mode in other modes (React and Haml)
  (add-hook 'react-mode-hook 'emmet-mode)
  (add-hook 'haml-mode-hook 'emmet-mode)
1 Like

What is necessary for supporting jump-to-definitions (SPC m g g)? I recently install GNU global tags to get this function to work in the Elixir layer. However, Spacemacs keeps asking for the Tags file even after I generated the tag file in the project root. Then I read Alchemist should be all I need. I feel I am holding it wrong.

Anyone have a helpful blog article or forum post on properly configuring Spacemacs/Elixir to jump to definitions and symbol searching?

1 Like

I wrote about this on the erlang channel on Slack a while ago and was told that Alchemist may have issues not working with the latest Elixir. All you should need in a spacemacs setup is to add the Elixir layer and go and this used to work beautifully, but as I said I’ve had issues lately too.

For the time being I’m using neovim with Alchemist.vim instead and I’m having a good time. Then again, I usually switch back and forth every now and then, so I have no issue switching to neovim for a language or two.

3 Likes

@bill.c @gon782 My jump to definition also seems broken, but you can use “dump-jump-go” instead, which is a separate package from Alchemist and works fine with Elixir. I’ve defined the following shortcut:

(defun dotspacemacs/user-config ()
  "..."
  (spacemacs/set-leader-keys-for-major-mode 'elixir-mode "j d" 'dumb-jump-go)
)

This will define SPC m j d in Elixir mode.

3 Likes

perfect! thanks!!

Anyone attempting Language Server Protocol integration in their spacemacs yet? :slight_smile:

I don’t see much RLS action on the spacemacs repo yet.

3 Likes

Does anyone know a way to quickly navigate to a function defined in the current module by name?

3 Likes

SPC j i

4 Likes

Ah, perfect! Just what I was looking for. Thanks!

2 Likes

Do you use format-on-save? How are they using it?

You mean

  (add-hook 'elixir-mode-hook
            (lambda () (add-hook 'before-save-hook 'elixir-format nil t)))

in your dotspacemacs/user-config ?

2 Likes

Yes, this work but sometimes no work.

If no work, I use SPC p ! and I execute mix format.

2 Likes

I am using elixir ls and lsp mode but linting seems not working.
how do I enable code linting ?

I’m curious, has anyone has figured out how to setup code folding yet?

Do you mean linting like autoformatting on save?
Then, I think you want to add the following to your dotspacemacs/user-config

(add-hook 'elixir-mode-hook
            (lambda ()
              (add-hook 'before-save-hook #'lsp-format-buffer nil t)
              ))

This will add a hook that will perform a lsp-format-buffer before saving the file.
If that does not work check if SPC SPC lsp-format-buffer lints your buffer.

For lsp-Integration and code suggestions I think the following lines helped me to allow my lsp to watch all files, prefer flycheck instead of flymake and enable its lsp integration.

 '(lsp-file-watch-threshold 3000)
 '(lsp-prefer-flymake nil)
 '(lsp-ui-flycheck-enable t)

My current setup looks like this:

Is that what you want?
Does this help you?

2 Likes

Thanks for your help.

This is my setup.
And it doesn’t look like ‘before-save-hook’ working.
It doesn’t display error before save.

argh, sry

sometimes I should read my own comments, before talking smart :joy:
I also set a hook to set the checkers for flycheck

My whole config regarding elixir-lsp:

;; dotspacemacs-configuration-layers
(elixir :variables elixir-backend 'lsp)

...

  ;; dotspacemacs/user-config 
  (use-package lsp-mode
    :commands lsp
    :ensure t
    :diminish lsp-mode
    :hook
    (elixir-mode . lsp)
    :init
    (add-to-list 'exec-path "~/Repositories/Other/elixir-ls/release"))
  ;; flycheck does static code analytics - we need to add credo to it
  (add-hook 'lsp-after-initialize-hook
            (lambda () (flycheck-add-next-checker 'lsp-ui 'elixir-credo))) 
  ;; adds a hook that formats the code
  (add-hook 'elixir-mode-hook
            (lambda ()
              (add-hook 'before-save-hook #'lsp-format-buffer nil t)
              ))

I also recommend to see if the message buffer (SPC b m) has anything to say regarding the lsp

2 Likes

Yes, it does:

LSP :: No formatting changes provided

The hook to format code on save doesn’t work for me on .exs files, how can I fix it? The .ex file formatting on save does work though:

LSP :: Applying 1 edits to `repo.ex' ...
Applying 1 edits to `repo.ex' ...done

Mh,
strange…
I just tried that and when I create a new file I’ve got the same problem like you.
However, after lsp-restart-workspace it worked as it should. Maybe the language server is running stale after some time and does not include the right file? Is there any command to force “add” a buffer to a lsp session?

Oh, and does lsp-format-buffer do anything for you?

1 Like