Basically that: would like to find an easy way to convert all those consecutive blank spaces into one in Emacs. Thanks for your help.
This:
text text text text text text text
Into this:
text text text text text text text
Basically that: would like to find an easy way to convert all those consecutive blank spaces into one in Emacs. Thanks for your help.
This:
text text text text text text text
Into this:
text text text text text text text
[Comment made into an answer]
(replace-regexp " +" " " nil (point-min) (point-max))
should do that. The regexp matches two or more spaces and the replacement is a single space. point-min
and point-max
return the positions of the (visible) portion of the buffer, so they establish the whole (visible) buffer as the region to apply the replacement to - you can season to taste.
As usual, read the doc string of the function in its entirety with C-h f replace-regexp
for the details (the following is an edited version to highlight details relevant to the question):
(replace-regexp REGEXP TO-STRING &optional DELIMITED START END
BACKWARD REGION-NONCONTIGUOUS-P)
Replace things after point matching REGEXP with TO-STRING.
Preserve case in each match if ‘case-replace’ and ‘case-fold-search’
are non-nil and REGEXP has no uppercase letters.
...
In Transient Mark mode, if the mark is active, operate on the contents
of the region. Otherwise, operate from point to the end of the buffer’s
accessible portion.
...
Fourth and fifth arg START and END specify the region to operate on.
...
replace-regexp
count?(replace-regexp " +" " " nil (point-min) (point-max))
should do that. The regexp matches two or more spaces and the replacement is a single space. – NickD Sep 07 '22 at 13:31