Emacs: Delete Whitespace around Cursor
In emacs, the following commands lets you delete whitespaces around cursor.
delete-blank-lines【Ctrl+x Ctrl+o】just-one-space【Alt+Space】delete-indentation【Alt+^】delete-horizontal-space【Alt+\】fixup-whitespacecycle-spacing(emacs 24.4)
Here's a command xah-shrink-whitespaces that combine most of them into one.
(defun xah-shrink-whitespaces () "Remove whitespaces around cursor to just one or none. Call this command again to shrink more. 3 calls will remove all whitespaces. URL `http://ergoemacs.org/emacs/emacs_shrink_whitespace.html' Version 2016-12-18" (interactive) (let (($p0 (point)) $line-has-char-p ; current line contains non-white space chars $has-space-tab-neighbor-p $space-or-tab-begin $space-or-tab-end ) (save-excursion (setq $has-space-tab-neighbor-p (or (looking-at " \\|\t") (looking-back " \\|\t" 1))) (beginning-of-line) (setq $line-has-char-p (re-search-forward "[[:graph:]]" (line-end-position) t)) (goto-char $p0) (skip-chars-backward "\t ") (setq $space-or-tab-begin (point)) (goto-char $p0) (skip-chars-forward "\t ") (setq $space-or-tab-end (point))) (if $line-has-char-p (if $has-space-tab-neighbor-p (let ($deleted-text) ;; remove all whitespaces in the range (setq $deleted-text (delete-and-extract-region $space-or-tab-begin $space-or-tab-end)) ;; insert a whitespace only if we have removed something different than a simple whitespace (when (not (string= $deleted-text " ")) (insert " "))) (progn (when (equal (char-before) 10) (delete-char -1)) (when (equal (char-after) 10) (delete-char 1)))) (progn (delete-blank-lines)))))
Give it a easy key. [see Emacs: How to Define Keys]
Whitespace Topic
Enhanced Editing Commands Topic
- Emacs: Select Line, between Quotes, Extend Selection
- Emacs: Copy/Cut Current Line If No Selection
- Emacs: Copy/Cut All or Selection
- Emacs: Paste or Paste Previous
- Emacs: Delete Whitespace around Cursor
- Emacs: Move Cursor to Beginning of Line/Paragraph
- Emacs: Move Cursor by Text Block
- Emacs: Move Cursor to Bracket/Quote
- Emacs: Move Cursor to Punctuation
- Emacs: Delete Text Block
- Emacs: Toggle Comment Current Line
- Emacs: Insert Date Time
Working with Brackets Topic
Liket it? Put $1 at
patreon.
Or Buy Xah Emacs Tutorial. Thanks.