From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Andreas_R=C3=B6hler?= Newsgroups: gmane.emacs.help Subject: Re: delete all whitespace (space) in a region Date: Tue, 14 Nov 2023 09:41:05 +0100 Message-ID: References: <878r78jfms.fsf@mat.ucm.es> <874jhwhx9i.fsf@ledu-giraud.fr> <87zfzn4qa2.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36046"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 14 09:42:07 2023 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r2ozl-00098D-KR for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 14 Nov 2023 09:42:05 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r2oz6-0005FA-Ci; Tue, 14 Nov 2023 03:41:24 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r2oz3-0005Eg-VQ for help-gnu-emacs@gnu.org; Tue, 14 Nov 2023 03:41:21 -0500 Original-Received: from mout.kundenserver.de ([212.227.17.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r2oyq-00060E-UB for help-gnu-emacs@gnu.org; Tue, 14 Nov 2023 03:41:21 -0500 Original-Received: from [192.168.178.61] ([89.247.171.253]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MvsR7-1rKu863KVD-00stAN for ; Tue, 14 Nov 2023 09:41:05 +0100 Content-Language: en-US In-Reply-To: X-Provags-ID: V03:K1:cXZWgQppmeAOVhHwePyZhnf/NPZHKGVDwQZ/vx8t0uho/HjYatr mFpO8Lgr7/WNkNd7m4GBpKqq6ZVwgwnFOcZsfNuUqJK4etpf7/d+GPC6X3VgDVVdadhixrW 0ydWM7FWAfX+hf8kow6V53x/6nI4HdshEET6T+Om5eFgrD0H3Q2J7e9dwPvUb7CCdDBkUr6 jvIcI+Qx+paQkG0Nr0yUw== UI-OutboundReport: notjunk:1;M01:P0:tNZzJMvUfXQ=;tky5G0/toIAbIR8E0wIFRHoo3UC MDtQe9a7Ojy68OVK505UICi7wY+eQj3WwDzon9LMQspbf61X/nlvzrC+JvOmAbj6uOzagRPNf 8xgEgQLm40njkO1wxxfLHwzaR8iblHGf1tHUWBJiANCwi3j5wW+GOYLVPJ2U2prnL8fI2SAF9 7iwRbgD9OlIKrmnwmFVQ6IGF0SqlwsxLoSfaBc5rrbVDWZflG0wYt7nmzuilKbx0DhHkAkO2k hKFt6lLbhXUQBXgEi80lDNxGCr04Aq6zcKRHixTfJkgvcs5bFqbN//e323ng9yTtEqrnnBYBR huc2p6wpKue0vudcT9TDX5XoY7UBm3ToEbC5dll3p+/nOHJnndUOT9XIWIcIdmmmakajpEDOV i6RxMcGCY9KprDGCrXoJsOrZgjWRNDvzuZ2pjSLSzUNm7HMgozTE3aWesqx3d4Jp+PPEXn5JV YDg/U20olejFP0m6uLo5tJG9AkCGYrUrNCMAgC1c36DyX0YSa7xNYOLhxn7MDRQ7ZR6U2J3LY foCK/EIG9lWtW+gacf7Ffsb8eJ2P2193T55jFZQFss9yhk2CJUKfF6qp/1fxZy4z9aF17hvxv il3F2OKyxHVQoFsiZtgfSDB1JQXeoXhDcvrZnjBfsaEzLJVvL0yj93d+HHe9cKZYwQCrE/iqb U77Qq4LHJPA0DrkYrC0MXl6aSFUW+fC3Lx9IpdrfZ/c1PStM0q85VX7y9ywEXYXTfT5N5FdIV Z9/C0N5VqQ6oVJx6lsVb3GzfgmqAF1E7XjdKsxUK23dGxBbnc7BB2DQ9v4+yXQpJV2g8ZesV Received-SPF: pass client-ip=212.227.17.10; envelope-from=andreas.roehler@easy-emacs.de; helo=mout.kundenserver.de X-Spam_score_int: 14 X-Spam_score: 1.4 X-Spam_bar: + X-Spam_report: (1.4 / 5.0 requ) BAYES_00=-1.9, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:145519 Archived-At: Am 09.11.23 um 06:34 schrieb tomas@tuxteam.de: > On Wed, Nov 08, 2023 at 09:24:53PM -0500, tpeplt wrote: >> Manuel Giraud via Users list for the GNU Emacs text editor >> writes: >>> If you don't want to confirm for the replacements, you could instead do >>> this: >>> >>> (defun my-delete-all-whitespace-region (beg end) >>> (interactive "r") >>> (save-excursion >>> (goto-char beg) >>> (while (re-search-forward " " end t) >>> (replace-match "")))) > A small optimisation would be to use the regexp " +", meaning one > or more spaces. > >> 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))) > To have this here, you'd have to "replace-regexp-in-region", of > course. > > Cheers BTW the code using replace-string-in-region and the form above are not equivalent. The latter updates the end, whereas the previous keeps the old limit, which may do unexpected deletions. Cheers, Andreas