Emacs: Delete Text Block 🚀

By Xah Lee. Date: . Last updated: .

Here's a convenient command to delete/kill current text block (aka paragraph).

Call it again to delete next one, or hold a key to keep deleting.

Be sure to give it a key. [see Emacs: Define Keybinding]

put this in your Emacs Init File:

(defun xah-delete-current-text-block ()
  "Delete the current text block plus blank lines, or selection, and copy to `kill-ring'.

URL `http://xahlee.info/emacs/emacs/emacs_delete_block.html'
Version 2017-07-09 2021-08-14"
  (let ($p1 $p2)
    (if (region-active-p)
        (setq $p1 (region-beginning) $p2 (region-end))
        (if (re-search-backward "\n[ \t]*\n+" nil 1)
            (setq $p1 (goto-char (match-end 0)))
          (setq $p1 (point)))
        (re-search-forward "\n[ \t]*\n+" nil 1)
        (setq $p2 (point))))
    (kill-region $p1 $p2)))