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: Sat, 31 Jan 2015 09:18:03 +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 1422695961 25323 80.91.229.3 (31 Jan 2015 09:19:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 31 Jan 2015 09:19:21 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jan 31 10:19:20 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 1YHUD2-0001iy-Dv for ged-emacs-devel@m.gmane.org; Sat, 31 Jan 2015 10:19:20 +0100 Original-Received: from localhost ([::1]:40099 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHUD1-00015F-1W for ged-emacs-devel@m.gmane.org; Sat, 31 Jan 2015 04:19:19 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHUCx-000156-DM for emacs-devel@gnu.org; Sat, 31 Jan 2015 04:19:16 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YHUCt-0000kS-D0 for emacs-devel@gnu.org; Sat, 31 Jan 2015 04:19:15 -0500 Original-Received: from relay5-d.mail.gandi.net ([2001:4b98:c:538::197]:51193) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHUCt-0000kD-4W for emacs-devel@gnu.org; Sat, 31 Jan 2015 04:19:11 -0500 Original-Received: from mfilter18-d.gandi.net (mfilter18-d.gandi.net [217.70.178.146]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id 3ACD441DBA3; Sat, 31 Jan 2015 10:19:09 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter18-d.gandi.net Original-Received: from relay5-d.mail.gandi.net ([217.70.183.197]) by mfilter18-d.gandi.net (mfilter18-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id 4bzTQAADJTiU; Sat, 31 Jan 2015 10:19:07 +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 3DF0641D37A; Sat, 31 Jan 2015 10:19:04 +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:182119 Archived-At: Stefan Monnier wrote: > you can drop the let-with-hook Without it, code which would be simply: (let-with-hook ((hooked-var foo)) (body)) would have to become: (setq tmp hooked-var) (setq-with-hook hooked-var foo) (body) (setq-with-hook hooked-var tmp) That's cumbersome. > since it would be a misfeature anyway, If it's missing (and you don't manually do it as above), then the hooked = variable and the dependent variable become unsynchronized when the former= is let-bound. That's bound to introduce bugs. > and then > consolidate the remaining 4 into a single function. How do you combine setq-with-hook, set-with-hook, setq-default-with-hook,= set-default-with-hook, and setq-local-with-hook into a single function? However you do it, if it's really a reasonable thing to do, then why aren= 't setq, set, setq-default, set-default, and setq-local also combined int= o a single function in the same way? Anyway, since you said varhook, or something like it, would be useful for= debugging even though you don't want to use it to implement regular feat= ures, is my implementation reasonably close to what you had in mind? WRT DCM, in deactivate-mark, you put: (when dynamic-cursor-mode (if (and dynamic-cursor-mode--set (eq cursor-type 'bar)) (setq cursor-type t)) (setq dynamic-cursor-mode--set nil)) and in activate-mark: (if (and dynamic-cursor-mode (eq cursor-type t)) (setq cursor-type 'bar dynamic-cursor-mode--set t)) That would fail in this case: (setq-default cursor-type 'bar) Later in the same Emacs session... (dynamic-cursor-mode) The user would reasonably think that DCM's failure to work in that case i= s a bug. To solve that, you wrote, =E2=8C=9Cdynamic-cursor-mode can do (setq-defau= lt cursor-type t).=E2=8C=9D IIUC, you meant: (define-minor-mode dynamic-cursor-mode "docs..." :global t :init-value t (if dynamic-cursor-mode (setq-default cursor-type t))) In that case, how do you turn it on buffer-locally? If cursor-type isn't = set to t, and you do: (setq-local dynamic-cursor-mode t) then it won't work. If you instead do: (make-local-variable 'dynamic-cursor-mode) (dynamic-cursor-mode) then DCM is enabled only locally, which is the correct thing to do, but c= ursor-type is globally set to t, which is a bug. Turning on DCM locally m= ust not affect CT globally. I guess you could fix that bug with: (define-minor-mode dynamic-cursor-mode "docs..." :global t :init-value t (if dynamic-cursor-mode (if (assq 'dynamic-cursor-mode (buffer-local-variables)) (setq cursor-type t) (setq-default cursor-type t)))) > The code I provided disables the effect of dynamic-cursor-mode as soon > as the value of cursor-type is not the expected one (without > needing to disable dynamic-cursor-mode). This has the edge case that if the mark happens to be active when you set= cursor-type to 'bar, then the setting doesn't stick; DCM doesn't realize= that CT was set outside of DCM's control, so DCM overrides the setting. = Similarly, if you previously always used a non-standard cursor type, and = were therefore mislead into thinking DCM was disabled, then if you set cu= rsor-type to t, DCM unexpectedly starts operating. That isn't user-friend= ly. Another poor result of your design is that if you set a non-standard curs= or type in your init file, then start Emacs and do C-h m, DCM is listed a= s enabled, even though it's having no effect, which is a great way to con= fuse the user, or convince him that there's a bug. Using varhook for DCM avoids those problems.