From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Deniz Dogan Newsgroups: gmane.emacs.help Subject: Re: Clear trailing whitespace on save, but not at the cursor Date: Mon, 05 Mar 2012 17:04:57 +0100 Message-ID: <4F54E429.2020309@dogan.se> References: <87aa3vwbsf.fsf@gnuvola.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1330963563 11405 80.91.229.3 (5 Mar 2012 16:06:03 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 5 Mar 2012 16:06:03 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Mar 05 17:06:00 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1S4aQB-0001FL-Pe for geh-help-gnu-emacs@m.gmane.org; Mon, 05 Mar 2012 17:05:59 +0100 Original-Received: from localhost ([::1]:54146 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4aQB-0001KB-1g for geh-help-gnu-emacs@m.gmane.org; Mon, 05 Mar 2012 11:05:59 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:52349) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4aQ1-0001Jx-BO for help-gnu-emacs@gnu.org; Mon, 05 Mar 2012 11:05:55 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S4aPt-0004C3-UD for help-gnu-emacs@gnu.org; Mon, 05 Mar 2012 11:05:48 -0500 Original-Received: from ch-smtp05.sth.basefarm.net ([80.76.153.6]:46148) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4aPt-0004BQ-Jc for help-gnu-emacs@gnu.org; Mon, 05 Mar 2012 11:05:41 -0500 Original-Received: from c80-216-107-103.bredband.comhem.se ([80.216.107.103]:53628 helo=[192.168.0.10]) by ch-smtp05.sth.basefarm.net with esmtp (Exim 4.76) (envelope-from ) id 1S4aPM-0000MO-Gs for help-gnu-emacs@gnu.org; Mon, 05 Mar 2012 17:05:13 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 In-Reply-To: <87aa3vwbsf.fsf@gnuvola.org> X-Originating-IP: 80.216.107.103 X-Scan-Result: No virus found in message 1S4aPM-0000MO-Gs. X-Scan-Signature: ch-smtp05.sth.basefarm.net 1S4aPM-0000MO-Gs f849fddb89971396de1ba3472565638f X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.76.153.6 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:83941 Archived-At: On 2012-03-05 12:02, Thien-Thi Nguyen wrote: > () Aaron Meurer > () Sun, 4 Mar 2012 17:48:21 -0700 > > Is there a way to clear whitespace on save, but > then "put it back" where the cursor is? > > Here is one way: > > (defadvice delete-trailing-whitespace > (around except-for-current-line activate) > "However, leave trailing whitespace before point alone." > (let ((save (when (looking-back "\\s-+" (line-beginning-position) t) > (match-string 0)))) > ad-do-it > (when save (insert save)))) > You could also use a function like the following: (defun damd-delete-trailing-whitespace-except-current-line () (interactive) (let ((back (1- (point-at-bol))) (front (1+ (point-at-eol)))) (delete-trailing-whitespace (point-min) back) (delete-trailing-whitespace front (point-max)))) As you can see, I use the optional boundary arguments of `delete-trailing-whitespace' to achieve the affect. It needs some tweaking, as in its current state it doesn't really check anything about the position of point in the current line. Deniz