8

I'm looking for a command that deletes automatically deletes spaces up to the next parens:

from:

(do |                 
            (do-something)
    true)

to:

(do |(do-something)
    true)
Drew
  • 77,472
  • 10
  • 114
  • 243
zcaudate
  • 647
  • 4
  • 14
  • Hungry delete mode? – Kirill Oct 03 '18 at 06:54
  • See the Elisp manual, node User-Level Deletion. It presents and describes fixup-whitespace, just-one-space, delete-horizontal-space, delete-indentation, delete-blank-lines, and delete-trailing-whitespace, each of which might be relevant, depending on exactly what you want. – Drew Oct 03 '18 at 15:03

3 Answers3

12

There is the command just-one-space which collapses all whitespace around the point down to a single space character. It works in any mode, not just paredit. By default it's bound to M-SPC, which can be hard to type since most window managers have a keyboard shortcut there that opens a menu. You can instead type Esc SPC.

db48x
  • 17,977
  • 1
  • 22
  • 28
7

For deleting white spaces there are a few commands in Emacs. You can find it all in EmacsWiki DeletingWhiteSpaces

Here are two examples from the wiki:

delete-horizontal-space

M-\ or M-x delete-horizontal-space will join two word, removing all the white spaces.

delete-horizontal-space-forward

Further down in the wiki page a function for deleting all white spaces forward (essentially what is asked in the example of the question) You can add it to your configuration and bind a key to it.

(defun delete-horizontal-space-forward () ; adapted from `delete-horizontal-space'
  "*Delete all spaces and tabs after point."
  (interactive "*")
  (delete-region (point) (progn (skip-chars-forward " \t") (point))))
manandearth
  • 2,118
  • 1
  • 13
  • 23
3

Also, package https://github.com/jcpetkovich/shrink-whitespace.el is very convenient as it progressively reduces whitespace around the cursor. This is how I use it:

(use-package shrink-whitespace
  :bind ("M-SPC" . shrink-whitespace))
Heikki
  • 3,066
  • 12
  • 19