Fork me on GitHub
#emacs
<
2024-03-08
>
Joseph Graham05:03:28

why does paredit refuse to let me fix broken parens?

[response-map ((handler) {:uri "/public/bliblablib"
                                   :query-string nil
                                   :request-method :get
                                   :headers {}
                                   :cookies {"ring-session"
                                             {:value "testsession3"}})]
Paredit or cider correctly identifies the missing } because I see this in *Messages*
Mismatched bracket: found an opening { on line 65 and a closing )
But when I try to type one a } it just ignores my input and moves the cursor forward.

lassemaatta06:03:53

(disclaimer; I use smartparens rather than paredit, but perhaps this might still work) Perhaps there's a better way, but what I usually do is quoted-insert or C-q , e.g. C-q } . Afterwards I can remove any extra ) characters.

3
ag06:03:08

Generally, when you need to figure out what exactly happens when you do anything in Emacs, immediately after pressing a key, you'd run view-lossage command (it's usually bound to C-h l). That will show the last few keys you pressed alongside the commands they bind to. Then you can simply debug the command. In your specific case, however, that would be tricky. Because the command you'd see after pressing the key would be self-insert-command. It's a built-in command (written in C), you can try debugging it by evaling (edebug-instrument-function #'self-insert-command), but that would make your Emacs instance pretty unusable, because it will trigger debugger frame for every single keypress. Alright, when how do you figure out what is happening? You have to check the standard hooks, namely post-command-hook and post-self-insert-hook. Run describe-variable, choose the hook, and you'd see which functions are running every time you try to insert or delete a char. Note that you have to do it in the same buffer - the value may differ depending on the modes activated in a buffer. In your case you'd probably see something prefixed with sp-, which is like Lasse noted, related to smartparens.el, perhaps smartparens-strict-mode is on. Maybe that's why it won't let you add the brace.

ag06:03:39

Relatedly, you may want to use built-in check-parens command, it usually navigates to the unbalanced part, making it easy to fix it.

practicalli-johnny07:03:23

As paredit is designed to prevent this kind of unbalanced parens, it's usually caused by an incorrect copy paste. In which case, try copy paste the missing } character, using one of the } characters just pasted. I also use the smartparens approach, C-q } Or if using Evil editing mode, add a character or space where the } should be and in normal mode use r to substitute that temporary character with } Or toggle paredit minor mode off and enter the character, then toggle paredit minor mode back on again

1
Joseph Graham12:03:05

Wow @U0G75ARHC I didnt know about view-lossage! I'll try to get in thw habit of using that one.

Joseph Graham12:03:48

@U05254DQM yes copy+paste mistake. i'll try that next time.