help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: delete all whitespace (space) in a region


From: Emanuel Berg
Subject: Re: delete all whitespace (space) in a region
Date: Thu, 09 Nov 2023 03:43:16 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

tpeplt wrote:

> Emacs 28 added the function ‘replace-string-in-region’.
>
> (defun my-delete-all-whitespace-region (beg end)
>   (interactive "r")
>   (save-excursion
>     (replace-string-in-region " " "" beg end)))

(defun delete-all-whitespace (&optional beg end)
  (interactive
    (when (use-region-p)
      (list (region-beginning) (region-end)) ))
  (or beg (setq beg (point-min)))
  (or end (setq end (point-max)))
  (save-mark-and-excursion
    (replace-string-in-region " " "" beg end) ))

A pretty fancy interface to a one-liner function with
hardcoded data :)

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]