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: Sun, 25 Mar 2012 22:12:45 +0800 Message-ID: References: <495248DFDEA08C469BBDED2D4AA6C614409AB6@DAKIYA1.pegasus.local> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=bcaec53d55f106328e04bc11dabe X-Trace: dough.gmane.org 1332684782 4017 80.91.229.3 (25 Mar 2012 14:13:02 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 25 Mar 2012 14:13:02 +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 Sun Mar 25 16:13:01 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 1SBoBo-0001Av-CW for geh-help-gnu-emacs@m.gmane.org; Sun, 25 Mar 2012 16:13:00 +0200 Original-Received: from localhost ([::1]:39314 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SBoBn-0004uq-DW for geh-help-gnu-emacs@m.gmane.org; Sun, 25 Mar 2012 10:12:59 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:50680) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SBoBf-0004uY-Sj for help-gnu-emacs@gnu.org; Sun, 25 Mar 2012 10:12:54 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SBoBd-0003Yb-Lz for help-gnu-emacs@gnu.org; Sun, 25 Mar 2012 10:12:51 -0400 Original-Received: from mail-wi0-f177.google.com ([209.85.212.177]:38192) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SBoBd-0003YX-6q for help-gnu-emacs@gnu.org; Sun, 25 Mar 2012 10:12:49 -0400 Original-Received: by wibhj13 with SMTP id hj13so2741366wib.12 for ; Sun, 25 Mar 2012 07:12:45 -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=U4vZX5xeggGBTidQ4xjHE1YmXoEM86XiZI5Xg+gH5Nk=; b=eGR25Ty45yFPqgfz2i0pc+LLKE9B0+Zbacq/ktpDQ4TM9GkpaiAeJR8SKoL25Rg5s/ 3V00r4ojdbtQbgD8hLfjMeXGYTneHzEnkZcwumfhZnT5SkNqr8fQdOLURcOXqVkeAJxK u9OFGvdpTARp2kitZPcVGjbDrPoTN7Edu/J85UgzKRAUVhOfxDk/xIDetxVOZpqcFfMo mlv0OUSECmIJpCpKW6V2nRttrrp7JbkWchLD/BWka8bum9Y+tsVj9LKCkPjM1CEZbIKV GWTuicwbQi9SN1Aiwyhqo4Nglj5hGSG76C1/rvkza9lzd14X2YvdgJMr+hTQtCGsRk2P sfQQ== Original-Received: by 10.180.19.196 with SMTP id h4mr11379476wie.12.1332684765147; Sun, 25 Mar 2012 07:12:45 -0700 (PDT) Original-Received: by 10.216.226.224 with HTTP; Sun, 25 Mar 2012 07:12:45 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.212.177 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:84101 Archived-At: --bcaec53d55f106328e04bc11dabe Content-Type: text/plain; charset=ISO-8859-1 On Sat, Mar 24, 2012 at 3:57 AM, Aaron Meurer wrote: > I guess they're not the same in the sense that they're officially > supported. This was kind of the whole point of my question, which is, > to what point are these things supposed to be the way you do things? > > Like I said, they can be problematic. For example, take the seemingly > innocent (add-hook 'before-save-hook 'delete-trailing-whitespace), > which is the universally recommended way make emacs to clear > whitespace on save. As far as I can tell, with this active, it is > impossible to save without clearing whitespace, unless you clear the > hook. With the global-set-key solution, I can easily save without > clearing by doing M-x save-buffer. > I don't know about "universally recommended"; as you point out, this really isn't a nice solution, at a minimum you should wrap `delete-trailing-white-space' in a function you can configure to be on/off on a per-file basis through a variable. It's the easy solution. And people like easy. It's necessary for you to differenciate between recommended practices and "practices I saw from a snippet posted to emacswiki". `add-hook' solutions are hacks. The end-user should not have to call add-hook. Package maintainers should define minor-modes that manage hooks for the end-user, or use the customize facilities to do something even smarter. I'm sure there is a "delete trailing white space" minor-mode out there somewhere. > Hooks are fine if all they do is enable some mode, because I can > easily turn that off if I don't want it. But other than that, you run > into the above issue. Or maybe there's an easy way to bypass hooks > that I just don't know about. > > There's other potential problems that are shared by hooks and monkey > patching, like expected invariants that are no longer met. I suppose > the very existence of hooks means that there really can be no expected > invariants about anything. But to me, this is impossible (you have to > expect that what you use will work, or else you can't really say > anything about your program). > Defadvice are hacks. You (as the end-user) should not have to use it. However, where would we be without it? How would you change a certain aspect of a package you use daily? You'd redefine the relevant function. Now, clearly defadvice provides a structure that is superior to plain function redefinition. The manual is clear on this. Defadvice is a last resort solution, not a line of first defense. And by the way, I wasn't just referring to defadvice for monkey > patching. That actually seems like a better way to do it, because at > least it warns you. I was also talking about how in emacs lisp, > pretty much everything is a global variable, > so you can often "fix" something by just changing some internal variable > to do what you want > (usually with knowledge of how it is used internally). > You (as the end-user) should not have to do this. If you had to set a "magic" internal variable to get what you want, then that's a bug in the package. The variables meant to be customized by the end-user are clearly marked and documented through the customize facility. > Aaron Meurer > -- Le --bcaec53d55f106328e04bc11dabe Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Sat, Mar 24, 2012 at 3:57 AM, Aaron Meurer <asmeurer@gmail.com> wrote:
=
I guess they're not the same in the sense that they're officially supported. =A0This was kind of the whole point of my question, which is, to what point are these things supposed to be the way you do things?

Like I said, they can be problematic. =A0For example, take the seemingly innocent (add-hook 'before-save-hook 'delete-trailing-whitespace),<= br> which is the universally recommended way make emacs to clear
whitespace on save. =A0As far as I can tell, with this active, it is
impossible to save without clearing whitespace, unless you clear the
hook. =A0With the global-set-key solution, I can easily save without
clearing by doing M-x save-buffer.

I don't kno= w about "universally recommended"; as you point out, this really = isn't a nice solution, at a minimum you should wrap `delete-trailing-wh= ite-space' in a function you can configure to be on/off on a per-file b= asis through a variable.

It's the easy solution.=A0 And people like easy.

It's ne= cessary for you to differenciate between recommended practices and "pr= actices I saw from a snippet posted to emacswiki".=A0 `add-hook' s= olutions are hacks.=A0 The end-user should not have to call add-hook.=A0 Pa= ckage maintainers should define minor-modes that manage hooks for the end-u= ser, or use the customize facilities to do something even smarter.=A0 I'= ;m sure there is a "delete trailing white space" minor-mode out t= here somewhere.
=A0
Hooks are fine if all they do is enable some mode, because I can
easily turn that off if I don't want it. But other than that, you run into the above issue. Or maybe there's an easy way to bypass hooks
that I just don't know about.

There's other potential problems that are shared by hooks and monkey patching, like expected invariants that are no longer met. =A0I suppose
the very existence of hooks means that there really can be no expected
invariants about anything. But to me, this is impossible (you have to
expect that what you use will work, or else you can't really say
anything about your program).

Defadvice are hacks.= =A0 You (as the end-user) should not have to use it.=A0

However, wh= ere would we be without it?

How would you change a certain aspect of= a package you use daily?=A0 You'd redefine the relevant function.=A0 N= ow, clearly defadvice provides a structure that is superior to plain functi= on redefinition.

The manual is clear on this.=A0 Defadvice is a last resort solution, no= t a line of first defense.

And by the way, I wasn't just referring to defadvice for monkey
patching. =A0That actually seems like a better way to do it, because at
least it warns you. =A0I was also talking about how in emacs lisp,
pretty much everything is a global variable,
=A0
so you can often "fix&q= uot; something by just changing some internal variable to do what you want<= br> (usually with knowledge of how it is used internally).

You (as t= he end-user) should not have to do this. If you had to set a "magic&qu= ot; internal variable to get what you want, then that's a bug in the pa= ckage.=A0 The variables meant to be customized by the end-user are clearly = marked and documented through the customize facility.

=A0
Aaron Meurer

--
L= e
--bcaec53d55f106328e04bc11dabe--