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 reformat stray closing parens and prevent extra closing parens #778

Closed
mfiano opened this issue Jul 23, 2017 · 7 comments
Closed

Comments

@mfiano
Copy link

mfiano commented Jul 23, 2017

2 problems I could not find the answer to while deciding if this package is right for me:

  1. If I have say the following, where _ is the point:
(((_

)   )
      )

In paredit, pressing ) 3 times would result in ((()))_. How do I replicate this behavior in strict-mode?

  1. In strict-mode, how do I prevent extra closing parens from being inserted if I type ) at the end of a pair?
@Fuco1
Copy link
Owner

Fuco1 commented Jul 24, 2017

  1. Calling sp-up-sexp instead of ) will jump out and also realign. We might add a feature to do the same on ) when it is configured to jump out (I personally always use sp-up-sexp because that's in my muscle-memory, in fact, I have ) rebound to entirely different command because I never use it. This is probably the reason why it isn't implemented yet)

  2. That should not happen. Make sure you have the latest version. When you try to insert a closing delimiter without an opening one you should get a message We can not insert unbalanced closing delimiter in strict mode. in the minibuffer.

@mfiano
Copy link
Author

mfiano commented Jul 24, 2017

@Fuco1, Issue 1 is fixed. ~~~For issue 2, this is not the case for me. If I type ()) The minibuffer says Search failed. This means there is unmatched expression somewhere or we are at the beginning/end of the file. and I now have a literal ()) in the buffer, the second one being colored red.~~~ Edit: Issue 2 is also solved. dotspacemacs-smart-closing-parenthesis was non-NIL. I am trying to convert from my vanilla Emacs config to spacemacs, and this was the last hurdle. Thank you for your help.

@mfiano mfiano closed this as completed Jul 24, 2017
@mfiano
Copy link
Author

mfiano commented Jul 25, 2017

With strict-mode enabled, and binding ) to sp-up-sexp, this has the unfortunate but understandable side effect of not allowing any ) characters to be inserted manually - particularly troublesome when needing to create double-quoted strings containing parens. Do you have a quick workaround for this?

@mfiano mfiano reopened this Jul 25, 2017
@Fuco1
Copy link
Owner

Fuco1 commented Jul 25, 2017

You can use C-q to insert any key literally in emacs. So C-q ) will insert ) in the buffer no matter what you bind to it.

It should be relatively simple to add the "cleanup" behaviour to the ) in strict-mode. Let's leave this issue open so I have a reminder. Then you can just leave it be and it would work (hopefully). In the meantime, the above should help.

@mfiano
Copy link
Author

mfiano commented Jul 25, 2017

Ok, thank you for the quick reply.

@Fuco1
Copy link
Owner

Fuco1 commented Oct 5, 2017

So I finally got to this, turns out it is already implemented, I just need to pass an additional flag to the function.

It should be enabled by default for all lisp modes and you can customize the behaviour by tweaking sp-navigate-reindent-after-up (but shouldn't need to)

So after you pull the latest patch you shouldn't need to do anything and it will just work (provided you use strict mode), which means you can also unbind the ) to be just the regular paren.

@Fuco1 Fuco1 closed this as completed in 456b78c Oct 5, 2017
@mfiano
Copy link
Author

mfiano commented Nov 21, 2017

Thanks. At first glance this seems to work great

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

2 participants