drym-org / symex.el

An intuitive way to edit Lisp symbolic expressions ("symexes") structurally in Emacs
Other
272 stars 22 forks source link

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

Open anonimitoraf opened 3 months ago

anonimitoraf commented 3 months ago

Hi!

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

https://github.com/drym-org/symex.el/assets/15933322/95e0e582-3158-4f60-a959-5057c90bbfa5

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?

countvajhula commented 3 months ago

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 commented 2 months ago

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 commented 2 months ago

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

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

anonimitoraf commented 2 months ago

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:

Peek 2024-07-20 19-02.webm

countvajhula commented 2 months ago

So there are two meanings of “mode” here. The variable “Symex-mode” refers to a minor mode that affects insert mode/“state”, specifically parentheses, by directly using paredit functions. This minor mode does not do anything else. The other meaning of mode is the modal interface used to edit code, which does not affect insert mode operations. You can use the latter without the former, and in this case, that’s what you’d like to do.The above steps should give us a clue as to whether, in your typescript buffer, it is Symex minor mode that is active or if it is paredit that is active (unbeknownst to you). Depending on that, we can debug further.Sent from my iPhoneOn Jul 20, 2024, at 2:04 AM, Rafael Nicdao @.***> wrote: 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

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

anonimitoraf commented 2 months ago

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 commented 2 months ago

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!