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: How to Define Keys]

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

URL `http://ergoemacs.org/emacs/emacs_delete_block.html'
Version 2017-07-09"
  (interactive)
  (let ($p1 $p2)
    (if (use-region-p)
        (setq $p1 (region-beginning) $p2 (region-end))
      (progn
        (if (re-search-backward "\n[ \t]*\n+" nil "move")
            (progn (re-search-forward "\n[ \t]*\n+")
                   (setq $p1 (point)))
          (setq $p1 (point)))
        (re-search-forward "\n[ \t]*\n" nil "move")
        (setq $p2 (point))))
    (kill-region $p1 $p2)))

Enhanced Editing Commands Topic

  1. Select Line, between Quotes, Extend Selection
  2. Copy/Cut Current Line If No Selection
  3. Copy/Cut All or Selection
  4. Paste or Paste Previous
  5. Delete Whitespace around Cursor
  6. Move Cursor to Beginning of Line/Paragraph
  7. Move Cursor by Text Block
  8. Move Cursor to Bracket/Quote
  9. Move Cursor to Punctuation
  10. Delete Text Block
  11. Toggle Comment Current Line
  12. Insert Date Time

Working with Brackets

  1. Highlight Brackets ()[]{}
  2. Insert Brackets by Pair
  3. Delete Brackets ()[]{} by Pair
  4. Select Line, between Quotes, Extend Selection
  5. Move Cursor to Bracket/Quote
  6. Change Brackets/Quotes
Patreon me $5 patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

If you have a question, put $5 at patreon and message me.