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

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

Re: remove extra whitespace on a line


From: Greg Bognar
Subject: Re: remove extra whitespace on a line
Date: Sat, 02 Dec 2006 12:40:43 -0500
User-agent: Pan/0.14.2.91 (As She Crawled Across the Table (Debian GNU/Linux))

On Sat, 02 Dec 2006 13:55:42 +0100, David Hansen wrote:

> On Sat, 02 Dec 2006 13:15:33 +0100 Markus Triska wrote:
> 
>> "Herbert Euler" <address@hidden> writes:
>>
>>> How about this?
>>>
>>> (defun just-one-space-in-current-line (&optional n)
>>>  (interactive "*p")
>>>  (save-excursion
>>>    (save-restriction
>>>      (narrow-to-region (line-beginning-position)
>>>                     (line-end-position))
>>>      (goto-char (point-min))
>>>      (while (re-search-forward "[ \t]" nil t)
>>>     (just-one-space n)))))
>>
>> Or this:
>>
>> (defun just-one-space-in-current-line (&optional n)
>>  (interactive "*p")
>>  (save-excursion
>>    (beginning-of-line)
>>    (while (re-search-forward "[ \t]" (line-end-position) t)
>>      (just-one-space n))))
> 
> Both will convert two (or more) spaces after the end of a sentence into
> one space.  Narrowing and filling seems to be the right way to me.
> 
> David

So this is what I want, isn't it?

(defun just-one-space-in-current-line ()
  (interactive)
  (save-excursion
    (save-restriction
      (narrow-to-region (line-beginning-position)
                        (line-end-position))
      (goto-char (point-min))
      (canonically-space-region 
        (line-beginning-position) (line-end-position)))))




reply via email to

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