From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Le Wang Newsgroups: gmane.emacs.help Subject: Re: Clear trailing whitespace on save, but not at the cursor Date: Thu, 22 Mar 2012 23:45:16 +0800 Message-ID: References: <87aa3vwbsf.fsf@gnuvola.org> <87booarvd6.fsf@gnuvola.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=f46d043bdce861e40e04bbd6cb5f X-Trace: dough.gmane.org 1332431143 14622 80.91.229.3 (22 Mar 2012 15:45:43 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 22 Mar 2012 15:45:43 +0000 (UTC) Cc: help-gnu-emacs@gnu.org, Thien-Thi Nguyen To: Aaron Meurer Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Mar 22 16:45:41 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 1SAkCm-0004yO-Oz for geh-help-gnu-emacs@m.gmane.org; Thu, 22 Mar 2012 16:45:36 +0100 Original-Received: from localhost ([::1]:60646 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SAkCm-0000Pk-5v for geh-help-gnu-emacs@m.gmane.org; Thu, 22 Mar 2012 11:45:36 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:54837) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SAkCb-0000IC-EU for help-gnu-emacs@gnu.org; Thu, 22 Mar 2012 11:45:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SAkCV-0000wO-3j for help-gnu-emacs@gnu.org; Thu, 22 Mar 2012 11:45:24 -0400 Original-Received: from mail-we0-f169.google.com ([74.125.82.169]:36740) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SAkCU-0000w0-QD for help-gnu-emacs@gnu.org; Thu, 22 Mar 2012 11:45:19 -0400 Original-Received: by werj55 with SMTP id j55so2511225wer.0 for ; Thu, 22 Mar 2012 08:45:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=V24ao8LRkfTy3tWUFROu9VKJ4UpX4VTTqyQcxDLwU30=; b=0lKUyrZcSkAqps38/0yRl8pdRz6C5x0hZFRVzM+xClZ7oHB6mJMoMzkfthcn+ODLLt pF6ddWeOLMA0NiYsIblFhoZas9j7jz/ANI9QQRmAUIDVwRsuZnoEyb8FWL96YSsAets2 XR1NbKFTXJtxHlHVjZ8ZImSUFCxS2Fu3uuxU38RyImTToyLtXy3q0yRbIKkj5yhjMC2x XJDYXvikxkpmmEI4u0C9QDUM1YXqBI0+QmfkzH1TqA6jRqK0PsLVansTPaPDagka8BQa zBriGM7yxPo7ZV/QJHEKRmEAzTDaAFw2qkU5mDl9WxlJ5nmLYNzkQ/2SUQtwAuhjuzOs 3Tng== Original-Received: by 10.180.101.231 with SMTP id fj7mr6313695wib.15.1332431116428; Thu, 22 Mar 2012 08:45:16 -0700 (PDT) Original-Received: by 10.216.226.224 with HTTP; Thu, 22 Mar 2012 08:45:16 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.82.169 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:84088 Archived-At: --f46d043bdce861e40e04bbd6cb5f Content-Type: text/plain; charset=ISO-8859-1 On Thu, Mar 22, 2012 at 8:13 AM, Aaron Meurer wrote: > Sorry, I'm still *very* new to emacs lisp (lisp in general, actually). > Does this mean that it's possible to modify the above defadvice > function you gave above so that it actually clears it before the save, > but then puts it back? The function works just fine in not clearing > at the cursor, but as noted, this is not quite what I want, because I > do *not* want to save trailing whitespace to file at all (I would > rather have my current annoyance). > The defadvice solution is not ideal. You're changing the fundamental behaviour of a function that could be called by other functions. It's better to make your own command, this should fit all your requirements: (defun my-save-buffer-dtws (arg) "save buffer delete trailing white space, preserve white space before point if point is past text" (interactive "p") (let ((save (when (and (looking-at "\\s-*$") (looking-back "\\s-+" (line-beginning-position) t)) (match-string 0)))) (delete-trailing-whitespace) (save-buffer arg) (when save (insert save) (set-buffer-modified-p nil)))) (global-set-key [remap save-buffer] 'my-save-buffer-dtws) > Aaron Meurer > -- Le --f46d043bdce861e40e04bbd6cb5f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Thu, Mar 22, 2012 at 8:13 AM, Aaron Meurer <asmeurer@gmail.com> wrote:
=
Sorry, I'm still *very* new to emacs lisp (lisp in general, actually).<= br> =A0Does this mean that it's possible to modify the above defadvice
function you gave above so that it actually clears it before the save,
but then puts it back? =A0The function works just fine in not clearing
at the cursor, but as noted, this is not quite what I want, because I
do *not* want to save trailing whitespace to file at all (I would
rather have my current annoyance).

The defadvice solution is not= ideal.=A0 You're changing the fundamental behaviour of a function that= could be called by other functions.=A0 It's better to make your own co= mmand, this should fit all your requirements:

(defun my-save-buffer-dtws (arg)
=A0= "save buffer delete trailing white space, preserve white space before= point if point is past text"
=A0 (interactive "p")
= =A0 (let ((save (when (and (looking-at "\\s-*$")
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (l= ooking-back "\\s-+" (line-beginning-position) t))
=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (match-string 0))))
=A0=A0=A0 (delete-= trailing-whitespace)
=A0=A0=A0 (save-buffer arg)
=A0=A0=A0 (when save=
=A0=A0=A0=A0=A0 (insert save)
=A0=A0=A0=A0=A0 (set-buffer-modified-p nil))))

(global-set-key [rema= p save-buffer] 'my-save-buffer-dtws)


=A0
Aaron Meurer


-- <= br>Le
--f46d043bdce861e40e04bbd6cb5f--