all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Clear trailing whitespace on save, but not at the cursor
@ 2012-03-05  0:48 Aaron Meurer
  2012-03-05 11:02 ` Thien-Thi Nguyen
  0 siblings, 1 reply; 11+ messages in thread
From: Aaron Meurer @ 2012-03-05  0:48 UTC (permalink / raw
  To: help-gnu-emacs

Hi.

I have the following line in my .emacs

(add-hook 'before-save-hook 'delete-trailing-whitespace)

This clears trailing whitespace on save. I like this behavior, except
that it's a little disorienting if I happen to save in the middle of
typing something.  Is there a way to clear whitespace on save, but
then "put it back" where the cursor is?  I imagine I could write a
custom hook to do this, but I'm wondering if it's possible to do it in
such a way that if I save and then quit, it doesn't bug me about
saving because it modified the file again with the new whitespace.  I
don't want to ever save the trailing whitespace to the file itself,
even at the cursor.

Let me know if any of that doesn't make sense, and I will try to
explain it better.

Aaron Meurer



^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: Clear trailing whitespace on save, but not at the cursor
@ 2012-03-22 21:08 Doug Lewan
  2012-03-23 19:57 ` Aaron Meurer
  0 siblings, 1 reply; 11+ messages in thread
From: Doug Lewan @ 2012-03-22 21:08 UTC (permalink / raw
  To: help-gnu-emacs@gnu.org

Aaron Meurer writes:

> But it seems to me that the whole emacs lisp system is designed 
> from the ground up to do hooking (by the way, where I come from, "hooking"
> is given the much auspicious name "monkey patching").

First: 

Today I learned "monkey patching" (and, by going to Wikipedia, it's synonym "duck punching"). Thanks for giving me a techno-chuckle.

Second: 

(Assuming I understand the meaning of monkey patching) Hooks are /not/ the same thing. Hooks are favors you ask for when something happens. Hooks are easily removed. Often they are if they are badly behaved. See the documentation for after-change-functions.

Advice seem like they fit the definition of monkey patching. A piece of advice can be enabled and disabled, but it stays once it has been (defadvice)d.

The emacs lisp manual has lots of warnings about advice. It has legitimate uses, but they are rare -- typically there's-no-other-darn-way-to-do-this kind of things. It's usually worthwhile spending time to find another way because it's hard to write interesting advice that doesn't have unexpected consequences.

The emacs lisp manual has no general warnings about hooks.

There's probably something to that.

,Douglas
Douglas Lewan
Shubert Ticketing
(201) 489-8600 ext 224





^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-03-25 14:12 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
  -- 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

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.