7

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
  • 75,699
  • 9
  • 109
  • 225
zcaudate
  • 637
  • 4
  • 14
  • Hungry delete mode? – Kirill Oct 03 '18 at 06:54
  • See the Elisp manual, node [User-Level Deletion](https://www.gnu.org/software/emacs/manual/html_node/elisp/User_002dLevel-Deletion.html). 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

9

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
  • 15,741
  • 1
  • 19
  • 23
6

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,068
  • 1
  • 11
  • 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
  • 2,961
  • 11
  • 18