Enabling smartparens-strict-mode breaks hungry-delete-mode as it overrides the hungry-delete remaps for C-d and C-h with smartparens specific functions. Hence, I have disabled smartparens-strict-mode but I want to have the ability to always delete by pairs. I do not want to use electric-pair-mode since it overrides some of the functionality of smartparens.

How can I achieve this while also preserving hungry-delete-mode functionality?


2 Answers 2


One approach here is to use a context-specific key binding for the smartparens commands. (See How can I 'layer' a keybinding?).

Here is some code to have the smartparens commands for deleting forward or backward only called when the next (or previous) char is not whitespace:

(with-eval-after-load 'smartparens

  (dolist (key '( [remap delete-char]
                  [remap delete-forward-char]))

    (define-key smartparens-strict-mode-map key
      '(menu-item "maybe-sp-delete-char" nil
                  :filter (lambda (&optional _)
                            (unless (looking-at-p "[[:space:]\n]")

  (dolist (key '([remap backward-delete-char-untabify]
                 [remap backward-delete-char]
                 [remap delete-backward-char]))

    (define-key smartparens-strict-mode-map key
      '(menu-item "maybe-sp-backward-delete-char" nil
                  :filter (lambda (&optional _)
                            (unless (looking-back "[[:space:]\n]" 1)

This makes the smartparens bindings conditional on the char at or before point. For non-whitespace characters these commands are invoked as usual for smartparens strict mode. However when the next (or previous) char is whitespace, these bindings are nil and it falls back to the appropriate hungry-delete commands.


Just want to point out that the latest smartparens on MELPA has fixed the conflict between hungry-delete-mode and smartparens-strict-mode. The fix by #glucas still works for the most part, except that C-d behavior will throw an error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.