From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Aaron Meurer Newsgroups: gmane.emacs.help Subject: Re: Clear trailing whitespace on save, but not at the cursor Date: Fri, 23 Mar 2012 13:57:58 -0600 Message-ID: References: <495248DFDEA08C469BBDED2D4AA6C614409AB6@DAKIYA1.pegasus.local> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1332532719 29654 80.91.229.3 (23 Mar 2012 19:58:39 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 23 Mar 2012 19:58:39 +0000 (UTC) Cc: "help-gnu-emacs@gnu.org" To: Doug Lewan Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Mar 23 20:58:39 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 1SBAdC-00013G-8k for geh-help-gnu-emacs@m.gmane.org; Fri, 23 Mar 2012 20:58:38 +0100 Original-Received: from localhost ([::1]:34850 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SBAdB-0006Wx-OP for geh-help-gnu-emacs@m.gmane.org; Fri, 23 Mar 2012 15:58:37 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:38952) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SBAd4-0006WB-R7 for help-gnu-emacs@gnu.org; Fri, 23 Mar 2012 15:58:34 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SBAcx-0006bf-Nr for help-gnu-emacs@gnu.org; Fri, 23 Mar 2012 15:58:30 -0400 Original-Received: from mail-yx0-f169.google.com ([209.85.213.169]:35514) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SBAcx-0006az-HN for help-gnu-emacs@gnu.org; Fri, 23 Mar 2012 15:58:23 -0400 Original-Received: by yenm8 with SMTP id m8so3620770yen.0 for ; Fri, 23 Mar 2012 12:58:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=T0clWJK6Q2P9aPTr7DOX4nHtBj6x06wLzRGUQy4FaR8=; b=C2So3V1nUZNJIOQYtTAiBv/R9GpfTjhkVWGIpRsyxlamx4+TXrg9RzlMfD6tdc5lET 5Yp2tzecg8l9TuBhGOjIL1WBtErsfhvbmEVVu4Td+OSRABaDc99NfiaSR5HYz4fRE/eB MJ5bx+1TCTcqKE8R+D5pI9d6LAE3TdnMeUXK5E+3kxX9KYa/ga9y7Nh96Ey0RVcg73pl D01ARAZWXAKjNiKaWxpreOu+C2PhajfDijgLAJRMU9o31lQ+ob26WUlnghFO4cd64ogJ Sh5xYaiCquwls5iEqdWWfCJsN6FKEqc6f37SwTA2JIg3jl1f9jHkz+Bax1CgecvV19wl UL8w== Original-Received: by 10.60.4.199 with SMTP id m7mr15666989oem.65.1332532698978; Fri, 23 Mar 2012 12:58:18 -0700 (PDT) Original-Received: by 10.182.109.41 with HTTP; Fri, 23 Mar 2012 12:57:58 -0700 (PDT) In-Reply-To: <495248DFDEA08C469BBDED2D4AA6C614409AB6@DAKIYA1.pegasus.local> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.213.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:84100 Archived-At: On Thu, Mar 22, 2012 at 3:08 PM, Doug Lewan wr= ote: > 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, "hookin= g" >> is given the much auspicious name "monkey patching"). > > First: > > Today I learned "monkey patching" (and, by going to Wikipedia, it's synon= ym "duck punching"). Thanks for giving me a techno-chuckle. > > Second: > > (Assuming I understand the meaning of monkey patching) Hooks are /not/ th= e same thing. Hooks are favors you ask for when something happens. Hooks ar= e easily removed. Often they are if they are badly behaved. See the documen= tation for after-change-functions. 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. 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). 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). Aaron Meurer > > Advice seem like they fit the definition of monkey patching. A piece of a= dvice 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 legitimat= e 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 > > >