From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.emacs.help Subject: Re: Clear trailing whitespace on save, but not at the cursor Date: Mon, 05 Mar 2012 12:02:40 +0100 Message-ID: <87aa3vwbsf.fsf@gnuvola.org> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1330945476 26267 80.91.229.3 (5 Mar 2012 11:04:36 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 5 Mar 2012 11:04:36 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Aaron Meurer Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Mar 05 12:04:35 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 1S4ViT-00043g-VJ for geh-help-gnu-emacs@m.gmane.org; Mon, 05 Mar 2012 12:04:34 +0100 Original-Received: from localhost ([::1]:37762 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4ViT-00016a-53 for geh-help-gnu-emacs@m.gmane.org; Mon, 05 Mar 2012 06:04:33 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:46978) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4Vi4-0000Rc-Kq for help-gnu-emacs@gnu.org; Mon, 05 Mar 2012 06:04:23 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S4Vi2-0003FP-Uk for help-gnu-emacs@gnu.org; Mon, 05 Mar 2012 06:04:08 -0500 Original-Received: from smtp205.alice.it ([82.57.200.101]:41180) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4Vi2-00038P-NU for help-gnu-emacs@gnu.org; Mon, 05 Mar 2012 06:04:06 -0500 Original-Received: from ambire (82.58.3.149) by smtp205.alice.it (8.6.023.02) id 4F421F7B01AD52C1; Mon, 5 Mar 2012 12:03:47 +0100 Original-Received: from ttn by ambire with local (Exim 4.72) (envelope-from ) id 1S4Vge-0001Sr-Gc; Mon, 05 Mar 2012 12:02:40 +0100 In-Reply-To: (Aaron Meurer's message of "Sun, 4 Mar 2012 17:48:21 -0700") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 82.57.200.101 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:83938 Archived-At: () 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))))