Skip to content
An emacs package to delete whitespace between words, parenthesis and other delimiters in a (not very) smart way.
Branch: master
Clone or download
Latest commit 7c1d56a Apr 16, 2017
Type Name Latest commit message Commit time
Failed to load latest commit information.
doc add: documentation Apr 11, 2017 fix: github url handling Apr 16, 2017
smart-hungry-delete.el cln: follow lint styleguide for naming Apr 12, 2017


Delete whitespace between words, parenthesis and other delimiters in a smart (dumb) way.

Suppose you have this text in the buffer:


With smart-hungry-delete/backward-char, it will delete all but one (white-)space between word and paren:


If you delete here:


it deletes all whitespace, because it’s on the inside of a paren:


Inside of right paren:



This is configured for C-like languages (e.g. Python), where : usually has no space to the left:



It has space to the right though:



This also works for (nested) parentheses:




Between words it will leave a space:




Here’s a small demonstration video:

Demonstration Video


It’s in MELPA, so if you have that in your package lists, just M-x package-install smart-hungry-delete, and bind smart-hungry-delete-backward-char and smart-hungry-delete-forward-char:

(require 'smart-hungry-delete)
(global-set-key (kbd "<backspace>") 'smart-hungry-delete-backward-char)
(global-set-key (kbd "C-d") 'smart-hungry-delete-forward-char)

If you use use-package:

(use-package smart-hungry-delete
  :ensure t
  :bind (("<backspace>" . smart-hungry-delete-backward-char)
		 ("C-d" . smart-hungry-delete-forward-char))
  :defer nil ;; dont defer so we can add our functions to hooks 
  :config (smart-hungry-delete-add-default-hooks)

Here’s the basic el-get recipe:

(:name smart-hungry-delete
 :type github
 :pkgname "hrehfeld/emacs-smart-hungry-delete")


smart-hungry-delete deletes hungrily if three regexps match:


or with smart-hungry-delete-forward-char:


You can configure these on a per buffer basis:

smart-hungry-delete-char-kill-regexp is a buffer-local variable holding a regex that defines what will be hungrily deleted (<kill>).

smart-hungry-delete-char-trigger-killall-regexps is a list of pairs:

'(("\\[" . ".") ;; delete when <left> is "[" and <right> is any of "."
  ("." . "\\]") ;; delete when <left> is any of "." and <right> is "]"

smart-hungry-delete-add-regexps-left-right makes it easy to add left-right combinations of chars like parentheses:

(smart-hungry-delete-add-regexps-left-right "\\{" "\\}") ;;as above, but with "{" and "}"

smart-hungry-delete-add-default-hooks will add some good defaults for (some) programming modes. Check out the smart-hungry-delete-default-*-hook functions.

If you have good suggestions for more defaults, make sure to suggest the recipes!

You can’t perform that action at this time.