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)
2
  • Hungry delete mode?
    – Kirill
    Commented Oct 3, 2018 at 6: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
    Commented Oct 3, 2018 at 15:03

3 Answers 3

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.

0
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))))
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))

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.