Skip to content

Conversation

jamescherti
Copy link
Contributor

@jamescherti jamescherti commented Apr 30, 2025

When using electric-pair-mode, the expected behavior when pressing C-h near a pair of adjacent delimiters (e.g., () [] {} "") is that both the opening and closing delimiters should be deleted together if they were inserted as a pair.

This pull request fixes #1974.

This pull request corrects C-h behavior to ensure electric-pair deletes adjacent pairs. It calls the same function as DEL (code 127) in electric-pair-mode-map:

electric-pair-mode-map is a variable defined in ‘elec-pair.el’.

Its value is
(keymap 
 (127 menu-item "" electric-pair-delete-pair :filter
  #f(compiled-function (cmd) #<bytecode 0x115035a9952592b3>)))

This pull request could be improved. Please don't hesitate to comment it if you have any suggestions.

@jamescherti jamescherti force-pushed the jc-fix-elec-pair-C-h branch 2 times, most recently from ef49df9 to cbb8c9a Compare April 30, 2025 15:59
@jamescherti jamescherti force-pushed the jc-fix-elec-pair-C-h branch from def101c to cbb8c9a Compare June 24, 2025 18:21
Copy link
Collaborator

@axelf4 axelf4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we should try to be compatible with the shenanigans of electric-pair-mode, even at the cost of a more fragile C-h binding. Some comments:

Will need to update the lookup-key check in the evil-want-C-h-delete setter:

              ((and (not value)
                    (eq (lookup-key evil-insert-state-map (kbd "C-h"))
                        'evil-delete-backward-char-and-join))

@jamescherti jamescherti force-pushed the jc-fix-elec-pair-C-h branch from cbb8c9a to 3b80eb5 Compare August 7, 2025 13:14
@jamescherti
Copy link
Contributor Author

I agree that we should try to be compatible with the shenanigans of electric-pair-mode, even at the cost of a more fragile C-h binding. Some comments:

Will need to update the lookup-key check in the evil-want-C-h-delete setter:

              ((and (not value)
                    (eq (lookup-key evil-insert-state-map (kbd "C-h"))
                        'evil-delete-backward-char-and-join))

Yes, it is less conflusing to see that C-h behaves exactly like backspace (similar to #1980 for eldoc). It does not only fix electric-pair-mode, but also other packages that rely on backspace (e.g., paredit)

I have modified evil-vars.el to use the following instead:

(define-key evil-insert-state-map (kbd "C-h") (kbd "DEL"))

@jamescherti jamescherti force-pushed the jc-fix-elec-pair-C-h branch 2 times, most recently from 385aafa to 4cdb9db Compare September 6, 2025 03:15
@jamescherti
Copy link
Contributor Author

jamescherti commented Sep 6, 2025

I enhanced the evil-insert-state-bindings mapping for C-h by improving the lambda function.

Have there been any updates on this pull request, @axelf4?

@jamescherti jamescherti force-pushed the jc-fix-elec-pair-C-h branch 2 times, most recently from 72dfb11 to 1527ecf Compare September 6, 2025 03:43
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

Successfully merging this pull request may close these issues.

C-h does not ensure electric-pair deletes adjacent pairs

2 participants