Skip to content

An emacs package to delete whitespace between words, parenthesis and other delimiters in a (not very) smart way.

Notifications You must be signed in to change notification settings

hrehfeld/emacs-smart-hungry-delete

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 

Repository files navigation

Smart-hungry-delete

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

Suppose you have this text in the buffer:

./doc/demo-00-01.png

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

./doc/demo-00-02.png

If you delete here:

./doc/demo-00-03.png

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

./doc/demo-00-04.png

Inside of right paren:

./doc/demo-00-05.png

./doc/demo-00-06.png

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

./doc/demo-00-07.png

./doc/demo-00-08.png

It has space to the right though:

./doc/demo-00-09.png

./doc/demo-00-10.png

This also works for (nested) parentheses:

./doc/demo-00-11.png

./doc/demo-00-12.png

./doc/demo-00-13.png

Between words it will leave a space:

./doc/demo-00-14.png

./doc/demo-00-15.png

./doc/demo-00-16.png

Here’s a small demonstration video:

Demonstration Video

Installing

MELPA

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)
(smart-hungry-delete-add-default-hooks)
(global-set-key (kbd "<backspace>") 'smart-hungry-delete-backward-char)
(global-set-key (kbd "<delete>") 'smart-hungry-delete-backward-char)
(global-set-key (kbd "C-d") 'smart-hungry-delete-forward-char)

use-package

If you use use-package:
(use-package smart-hungry-delete
  :ensure t
  :bind (([remap backward-delete-char-untabify] . smart-hungry-delete-backward-char)
	       ([remap delete-backward-char] . smart-hungry-delete-backward-char)
	       ([remap delete-char] . smart-hungry-delete-forward-char))
  :init (smart-hungry-delete-add-default-hooks))

Only for some modes:

(use-package smart-hungry-delete
  :ensure t
  :bind (:map python-mode-map
              ([remap backward-delete-char-untabify] . smart-hungry-delete-backward-char)
	            ([remap delete-backward-char] . smart-hungry-delete-backward-char)
	            ([remap delete-char] . smart-hungry-delete-forward-char))
  :init (smart-hungry-delete-add-default-hooks))

el-get

Here’s the basic el-get recipe:
(:name smart-hungry-delete
 :type github
 :pkgname "hrehfeld/emacs-smart-hungry-delete")

Configuration

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

<left><kill>(point)<right>

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

<left>(point)<kill><right>

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!

About

An emacs package to delete whitespace between words, parenthesis and other delimiters in a (not very) smart way.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •