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

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

Re: Clear trailing whitespace on save, but not at the cursor


From: Thien-Thi Nguyen
Subject: Re: Clear trailing whitespace on save, but not at the cursor
Date: Mon, 05 Mar 2012 12:02:40 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

() Aaron Meurer <asmeurer@gmail.com>
() 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))))



reply via email to

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