Fuco1 / smartparens

Minor mode for Emacs that deals with parens pairs and tries to be smart about it.
GNU General Public License v3.0
1.82k stars 195 forks source link

question | feature request: pull existing paren up when entering final paren #1160

Closed TLINDEN closed 1 year ago

TLINDEN commented 1 year ago

This is just a question if smartparens supports this feature or a feature request if it doesn't:

I am currently still using electric-pair-mode just because of this feature. Given the following code (| denoting point):

(defun blah()
  (message "foo"|
  )

When I now enter ) in electric-pair-mode it doesn't insert a paren but instead pulls the already existing paren up to where it should be instead of inserting an additional paren:

(defun blah()
  (message "foo")|

This doesn't work when I disable electric-pair-mode. In fact, an additional paren will be inserted which results in unbalanced parens.

Would be great if this could be achieved with smartparens.

Environment & version information

Fuco1 commented 1 year ago

This should be default in lisp modes. It's configured via sp-navigate-reindent-after-up. This makes sp-up-sexp also reindent the closing paren if necessary.

To make ) act as sp-up-sexp, you can use the strict mode (smartparens-strict-mode) which adds some other features though, or you can remap ) to sp-up-sexp. This is not that crazy because you should rarely need to insert the closing pair manually, and if necessary, C-q ) can insert it literally.

TLINDEN commented 1 year ago

Mapping ) to sp-up-sexp works like a charm! Thanks a lot for the help!