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 Keys: Define Key〕

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'.

If cursor is between blank lines, delete following blank lines.

URL `http://xahlee.info/emacs/emacs/emacs_delete_block.html'
Created: 2017-07-09
Version: 2024-10-07"
  (interactive)
  (let (xbeg xend (xp (point)))
    (if (region-active-p)
        (setq xbeg (region-beginning) xend (region-end))
      (progn
        (setq xbeg
              (if (re-search-backward "\n[ \t]*\n+" nil :move)
                  (match-end 0)
                (point)))
        (goto-char xp)
        (setq xend (if (re-search-forward "\n[ \t]*\n+" nil :move)
                       (match-end 0)
                     (point-max)))))
    (kill-region xbeg xend)))