From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Greg Bognar Newsgroups: gmane.emacs.help Subject: Re: remove extra whitespace on a line Date: Sat, 02 Dec 2006 12:40:43 -0500 Organization: Harvard University Message-ID: References: <87irgu8pei.fsf@gmx.at> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: sea.gmane.org 1165084836 31080 80.91.229.2 (2 Dec 2006 18:40:36 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 2 Dec 2006 18:40:36 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Dec 02 19:40:33 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GqZmj-0001fL-HE for geh-help-gnu-emacs@m.gmane.org; Sat, 02 Dec 2006 19:40:25 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GqZmj-0000dg-6x for geh-help-gnu-emacs@m.gmane.org; Sat, 02 Dec 2006 13:40:25 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news3.google.com!news.glorb.com!newspeer1.asbnva01.us.to.verio.net!news.harvard.edu!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 45 Original-NNTP-Posting-Host: dhcp-187-212.harvard.edu Original-X-Trace: plato.harvard.edu 1165081243 4642 128.103.187.212 (2 Dec 2006 17:40:43 GMT) Original-X-Complaints-To: news@plato.harvard.edu Original-NNTP-Posting-Date: Sat, 2 Dec 2006 17:40:43 +0000 (UTC) User-Agent: Pan/0.14.2.91 (As She Crawled Across the Table (Debian GNU/Linux)) Original-Xref: shelby.stanford.edu gnu.emacs.help:143605 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:39207 Archived-At: 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" 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)))))