all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Deniz Dogan <deniz@dogan.se>
To: help-gnu-emacs@gnu.org
Subject: Re: Clear trailing whitespace on save, but not at the cursor
Date: Mon, 05 Mar 2012 17:04:57 +0100	[thread overview]
Message-ID: <4F54E429.2020309@dogan.se> (raw)
In-Reply-To: <87aa3vwbsf.fsf@gnuvola.org>

On 2012-03-05 12:02, Thien-Thi Nguyen wrote:
> () 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))))
>

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



  parent reply	other threads:[~2012-03-05 16:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-05  0:48 Clear trailing whitespace on save, but not at the cursor Aaron Meurer
2012-03-05 11:02 ` Thien-Thi Nguyen
2012-03-05 15:07   ` Juanma Barranquero
2012-03-06  8:23     ` Thien-Thi Nguyen
2012-03-22  0:13       ` Aaron Meurer
2012-03-22 15:45         ` Le Wang
2012-03-22 16:56           ` Aaron Meurer
2012-03-05 16:04   ` Deniz Dogan [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-03-22 21:08 Doug Lewan
2012-03-23 19:57 ` Aaron Meurer
2012-03-25 14:12   ` Le Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F54E429.2020309@dogan.se \
    --to=deniz@dogan.se \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.