Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected pairing of do/end in multiline strings/comments (elixir-mode) #877

Closed
bitwalker opened this issue Mar 25, 2018 · 3 comments
Closed

Comments

@bitwalker
Copy link

Expected behavior

In a multi-line comment (such as those used in @moduledoc or @doc attributes, which are basically just triple-" quoted multi-line strings), I would expect no automatic pairing.

Actual behavior

Smartparens (at least I think it is), performs automatic insertion of do and end after a keyword like if when it occurs in the text of the comment/string. This happens anytime I'm typing docs or multi-line strings :(

Steps to reproduce the problem

Try defining this module by hand in a buffer with elixir-mode active (note: I'm using Spacemacs, there may be something buried in it that is causing this, but if we can figure out what is causing it, I can handle getting a fix upstream :):

defmodule Foo do
  @moduledoc """
   If I do

To be clear about how I'm typing this, I'll write it with any command sequences or (in my case I'm using evil-mode) command-mode keys wrapped in <>: defmodule<spc>Foo<esc><o>@moduledoc<spc>"""<ret>If I do<spc>. When I type that last <spc>, it inserts end.

Backtraces if necessary (M-x toggle-debug-on-error)

No errors

Environment & version information

In recent enough smartparens you can call M-x sp-describe-system to generate this report. Please fill manually what we could not detect automatically. Edit the output as you see fit to protect your privacy.

  • smartparens version: 20180308.1042 (as found in my elpa directory)
  • Active major-mode: elixir-mode
  • Emacs version (M-x emacs-version): 25.3.1
  • Spacemacs/Evil/Other starterkit (specify which)/Vanilla: Spacemacs+Evil
  • OS: macOS 10.12.6

If I'm doing something stupid, please let me know, or if this is the fault of another package, let me know that too, and I'll take it from there :)

@Fuco1
Copy link
Owner

Fuco1 commented Mar 25, 2018

All the other pairs are disabled in comments and strings except do for some strange reason. I think it's reasonable to also ignore it.

I'll have a patch later today, it's quite simple.

@Fuco1 Fuco1 closed this as completed in 6eea872 Mar 25, 2018
@bitwalker
Copy link
Author

Thanks! Great library by the way :)

@d4ncer
Copy link

d4ncer commented Jun 26, 2023

I'm seeing a similar issue in elixir-ts-mode, but it inserts both the do and end (on the next line) when I type any of the pairs that match all the following criteria:

  • Have the closing pair set to end
  • Have the :post-handlers include sp-elixir-do-block-post-handler
  • Have the sp-in-comment-p :unless guard set

I've confirmed your fix works as expected in elixir-mode and it works in strings in elixir-ts-mode. It only breaks in multi-line comments (i.e. @doc or @moduledoc triple quoted strings).

I'm not sure if the issue is here or on the elixir-ts-mode side, but I've got a temporary workaround of redefining all matching local pairs with a new :unless guard that runs a treesit based check rather than an sp based check. I'm sure there is a better way to do this :)

What I'm using at the moment is:

  (defun rk-sp/in-quoted-content-p (id action context)
    (let ((n (treesit-node-at (point))))
      (string= (treesit-node-type n) "quoted_content")))

  (sp-with-modes '(elixir-ts-mode)
    (sp-local-pair "do" "end"
                   :when '(("SPC" "RET" "<evil-ret>"))
                   :skip-match 'sp-elixir-skip-def-p
                   :unless '(rk-sp/in-quoted-content-p))
    ;; ... more pairs
    )

Happy to open a new issue to avoid overloading this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants