Emacs: Delete Paragraph, 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-text-block ()
  "Delete current/next text block or selection, and also copy to `kill-ring'.

A “block” is text between blank lines.
The “current block” is the block the cursor is at.
If cursor is not on a block, deletes the next block.
If there's a text selection, just delete that region.

URL `http://ergoemacs.org/emacs/emacs_delete_block.html'
Version 2016-10-10"
  (interactive)
  (if (use-region-p)
      (kill-region (region-beginning) (region-end))
    (progn
      (beginning-of-line)
      (if (re-search-forward "[[:graph:]]" (line-end-position) "NOERROR" )
          (xah-delete-current-text-block)
        (when (re-search-forward "[[:graph:]]" )
          (xah-delete-current-text-block))))))

(defun xah-delete-current-text-block ()
  "Delete the current text block and also copy to `kill-ring'.

A “block” is text between blank lines.
The “current block” is the block the cursor is at.
If cursor is not on a block nor on edge of a block, delete 2 empty lines.
If there's a text selection, ignore it.

URL `http://ergoemacs.org/emacs/emacs_delete_block.html'
Version 2016-10-10"
  (interactive)
  (let (-p1 -p2)
    (progn
      (if (re-search-backward "\n[ \t]*\n" nil "NOERROR")
          (progn (re-search-forward "\n[ \t]*\n")
                 (setq -p1 (point)))
        (setq -p1 (point)))
      (re-search-forward "\n[ \t]*\n" nil "NOERROR")
      (setq -p2 (point)))
    (kill-region -p1 -p2)))

Enhanced Editing Commands Topic

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

Working with Brackets Topic

  1. Emacs: Select Line, between Quotes, Extend Selection
  2. Emacs: Insert Brackets by Pair
  3. Emacs: Move Cursor to Bracket/Quote
  4. Emacs: Delete Backward Char or Bracket Text
Like it? Buy Xah Emacs Tutorial. Thanks.

or, buy something from Best Keyboard for Emacs