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

How to disable auto-formatting after inserting parentheses? #142

Open
anonimitoraf opened this issue Jul 1, 2024 · 7 comments
Open

How to disable auto-formatting after inserting parentheses? #142

anonimitoraf opened this issue Jul 1, 2024 · 7 comments

Comments

@anonimitoraf
Copy link
Contributor

anonimitoraf commented Jul 1, 2024

Hi!

I've noticed (particular with Typescript) that symex does some auto-formatting when I parentheses while in evil INSERT mode.

Screen.Recording.2024-07-01.at.11.05.05.AM.mov

To reproduce, insert parentheses after partition and after f in this snippet:

    const [matched, unmatched] = _.partition // adding a parenthesis here automatically adds a space

    function f { // adding a parenthesis here automatically adds a space and auto-formats the body
      const = 42
    }

Is there a way to completely disable formatting?

@anonimitoraf anonimitoraf changed the title How to disable auto-formatting How to disable auto-formatting? Jul 1, 2024
@anonimitoraf anonimitoraf changed the title How to disable auto-formatting? How to disable auto-formatting after inserting parentheses? Jul 1, 2024
@countvajhula
Copy link
Collaborator

countvajhula commented Jul 2, 2024

I'm surprised by your second example as I don't think Symex does any indentation in insert mode. Could you try disabling Symex and just enabling paredit-mode in your Typescript buffer? Is the behavior any different?

Assuming the behavior is due to the use of paredit (which is used by Symex in insert mode), take a look at #84 as that is related and may resolve this issue when it's addressed. It also contains a link to a workaround, which should be slightly modified now -- this would replace the corresponding line in symex-enter-mode:

(when (member major-mode (symex-get-lisp-modes)
  (symex--ensure-minor-mode))

Does that help?

@anonimitoraf
Copy link
Contributor Author

anonimitoraf commented Jul 19, 2024

Sorry for the late response.

Could you try disabling Symex and just enabling paredit-mode in your Typescript buffer

Yep, same behaviour, so looks like paredit does cause it.

As you've suggested, I patched symex-enter-mode to be:

(defun symex-enter-mode ()
  "Take necessary action upon symex mode entry."
  (when (member major-mode (symex-get-lisp-modes)
    (symex--ensure-minor-mode))
  (symex--adjust-point-on-entry)
  (when symex-remember-branch-positions-p
    (symex--clear-branch-memory))
  (symex-select-nearest)
  (when symex-refocus-p
    ;; smooth scrolling currently not supported
    ;; may add it back in the future
    (symex--set-scroll-margin))
  (symex--enter-mode)))

The behaviour didn't change. Is this what you meant?

@countvajhula
Copy link
Collaborator

@anonimitoraf Yeah, that looks right! Did you close and reopen the buffer after making the change? Or restarting Emacs to be extra sure?

The only places in the code I see symex-mode being enabled are in symex-enter and via major mode hooks for all "Lisp" modes, which Typescript is not, so I would expect the above patch to suffice. You could try a few things to validate some assumptions:

  • evaluate (symex-get-lisp-modes) in iELM. It should only show actual Lisp modes, and Typescript mode (or whatever the major mode is for typescript buffers) should not be present
  • in a buffer where you're seeing the problem, is the symex minor mode enabled -- i.e. C-h v symex-mode? After patching it as you did above (and e.g. after an Emacs restart), I would expect this value to be nil.
  • Similarly, what's the value of paredit-mode, C-h v paredit-mode? It should be nil as well, since Symex uses paredit functionality but does not enable paredit mode. If this mode is active, it's likely that there's something in your config that has enabled it.

Lmk if those assumptions hold up or if there's something unexpected there.

@anonimitoraf
Copy link
Contributor Author

Hi @countvajhula, I'm a bit confused. I'd like to use symex for Typescript files, but just without the auto-format/auto-indent and without the extra spaces when adding parents.

I've noticed that:

  • paredit and symex disabled = no issue
  • paredit disabled and symex enabled = has issue
Peek.2024-07-20.19-02.webm

@countvajhula
Copy link
Collaborator

countvajhula commented Jul 20, 2024 via email

@anonimitoraf
Copy link
Contributor Author

Thanks for explaining! What i've observed is: symex-mode causes the issue while paredit-mode is disabled.

I'll check why symex-mode keeps getting activated for TS files and find a way to disable it then

countvajhula added a commit that referenced this issue Jul 21, 2024
This seems to be better default behavior for tree-sitter buffers than
maintaining the balancing behavior that's desirable in Lisp.

Workaround (fix?) for #142.
@countvajhula
Copy link
Collaborator

countvajhula commented Jul 21, 2024

Sounds good! For now, I've gone ahead and committed the workaround we discussed into the master branch, since it seems like we generally don't want paren balancing behavior in tree-sitter buffers. Please let me know if your investigation reveals any new information, or if the issue is resolved after upgrading.

P.S. I also noticed there was a typo in the workaround in my previous comment -- it could be that that was the problem. Anyhow, please let me know either way, and thanks!

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

No branches or pull requests

2 participants