From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kelly Dean Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Run hook when variable is set Date: Fri, 30 Jan 2015 07:34:23 +0000 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1422603344 11409 80.91.229.3 (30 Jan 2015 07:35:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 30 Jan 2015 07:35:44 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jan 30 08:35:44 2015 Return-path: Envelope-to: ged-emacs-devel@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 1YH67C-0002fC-Q7 for ged-emacs-devel@m.gmane.org; Fri, 30 Jan 2015 08:35:42 +0100 Original-Received: from localhost ([::1]:35112 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YH67C-0005PA-80 for ged-emacs-devel@m.gmane.org; Fri, 30 Jan 2015 02:35:42 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50458) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YH676-0005P2-F5 for emacs-devel@gnu.org; Fri, 30 Jan 2015 02:35:37 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YH672-0006AR-SJ for emacs-devel@gnu.org; Fri, 30 Jan 2015 02:35:36 -0500 Original-Received: from relay5-d.mail.gandi.net ([2001:4b98:c:538::197]:37764) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YH672-0006AM-I6 for emacs-devel@gnu.org; Fri, 30 Jan 2015 02:35:32 -0500 Original-Received: from mfilter19-d.gandi.net (mfilter19-d.gandi.net [217.70.178.147]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id 8342D41C074; Fri, 30 Jan 2015 08:35:31 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter19-d.gandi.net Original-Received: from relay5-d.mail.gandi.net ([217.70.183.197]) by mfilter19-d.gandi.net (mfilter19-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id pf5uOBHk0Hhj; Fri, 30 Jan 2015 08:35:29 +0100 (CET) X-Originating-IP: 66.220.3.179 Original-Received: from localhost (gm179.geneticmail.com [66.220.3.179]) (Authenticated sender: kelly@prtime.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id CA46D41C064; Fri, 30 Jan 2015 08:35:28 +0100 (CET) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4b98:c:538::197 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:182026 Archived-At: > If we want to use such hooks for purposes such as "automatically > recompute values of dependent vars", then I think the right way is to > introduce a new layer which checks&runs these hooks, using the "raw" > `setq' underneath. You mean something like setq-with-hook, which you can use in place of set= q? Then in general, you also need set-with-hook, setq-default-with-hook, = set-default-with-hook, setq-local-with-hook, and let-with-hook. That seem= s cumbersome. Varhook handles even that last case. E.g. with my fix for bug #19068, you= can do: message-directory ; =E2=86=92 "~/mail/" message-auto-save-directory ; =E2=86=92 "/root/mail/drafts/" (let ((message-directory "foo")) message-auto-save-directory ; =E2=86=92 "/root/foo/drafts/" (setq message-directory "bar") message-auto-save-directory) ; =E2=86=92 "/root/bar/drafts/" message-directory ; =E2=86=92 "~/mail/" message-auto-save-directory ; =E2=86=92 "/root/mail/drafts/" (restored be= cause the =C2=ABlet=C2=BB exited) I didn't do anything special to enable synchronized let-binding for #1906= 8; that ability comes automatically from varhook. Of course, in the parti= cular case of message-directory, you're unlikely to want to let-bind it. = But in general, varhook lets you easily keep your variables synchronized. > For the same reason I want to kill the `intangible' text-property: this > operates at too-low a level, so it's bound to introduce buggy > interactions between unsuspecting packages. But for variables that are supposed to be linked, requiring use of higher= -level =C2=AB-with-hook=C2=BB functions results in bugs when you use the = regular =C2=ABset=C2=BB functions. Having documentation saying, =E2=80=9Ffor this variable, use the =C2=AB-w= ith-hook=C2=BB functions rather than the regular =C2=ABset=C2=BB function= s=E2=80=9D, and expecting everybody to remember to do that, doesn't seem = like a good solution. If you do that, then in case a user is prone to forgetting which variable= s need setq-with-hook and which ones only need setq, he can just always u= se the former (which works like setq if there's no hook). But then, why u= se the longer name for the more common function? It makes more sense to have the default behavior (and short name) be to r= un the hook. You can still disable the hook (or remove the relevant funct= ion from the hook) when you need to intentionally unsynchronize your vari= ables, which you'll normally only need to do during debugging. >> And I explained why your code doesn't provide a complete solution. >> You didn't respond. > > I must have misunderstood or overlooked it. Can you retry? The message is here: https://lists.gnu.org/archive/html/emacs-devel/2015-01/msg00786.html In summary: cursor-type can be changed buffer-locally, which doesn't affect other buf= fers or the global setting. Therefore dynamic-cursor-mode must be disable= d in the same buffer, but not in other buffers or globally. CT can be changed globally, which doesn't affect CT in buffers that have = it set locally. Therefore DCM must be disabled globally, but not in buffe= rs that have it enabled locally. Turning on DCM globally must work, regardless of whether the user previou= sly globally set CT to a nonstandard value. Turning on DCM locally must not affect CT globally. Turning off DCM locally must affect neither CT nor DCM in other buffers. It doesn't appear to be possible to satisfy all of those conditions witho= ut varhook. With varhook, it's easy: the hook function disables DCM globa= lly when CT is set globally, and disables DCM locally when CT is set loca= lly. BTW, define-minor-mode (with the fix for bug #19685 applied) does produce= documentation implying that it's appropriate to set a mode's variable di= rectly; you were right about that. So the updated patch I sent you a coup= le days ago implements DCM as a mode. And I implemented a minor enhancement (bug #19690) to help prevent users = from being confused about setting local vs. global minor modes in general= .