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: Manuel Giraud
Subject: Re: delete all whitespace (space) in a region
Date: Wed, 08 Nov 2023 20:15:37 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Uwe Brauer <oub@mat.ucm.es> writes:

> Hi
>
> I have constructs like
> $\left[ \left( \partial_{t}\Phi  \right)^{2} -                 \left\vert 
> \nabla\Phi \right\vert^{2}   \right]^{\frac{1+K}{2K}}$:
>
> That contain to much ........
>
> So I am looking for a region-wise command deleting all this .. With the result
> $\left[\left(\partial_{t}\Phi\right)^{2}-\left\vert 
> \nabla\Phi\right\vert^{2}\right]^{\frac{1+K}{2K}}$:
>
> (defun my-delete-all-whitespace-region (beg end)
>   (interactive "r")
>   (query-replace " " "" nil beg end nil nil))
>
> Seems to be a very simple solution, but maybe too simple?

If you don't want to confirm for the replacements, you could instead do
this:

--8<---------------cut here---------------start------------->8---
(defun my-delete-all-whitespace-region (beg end)
  (interactive "r")
  (save-excursion
    (goto-char beg)
    (while (re-search-forward " " end t)
      (replace-match ""))))
--8<---------------cut here---------------end--------------->8---
-- 
Manuel Giraud



reply via email to

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