From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Run hook when variable is set Date: Sat, 31 Jan 2015 15:48:08 -0500 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1422737315 4675 80.91.229.3 (31 Jan 2015 20:48:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 31 Jan 2015 20:48:35 +0000 (UTC) Cc: emacs-devel@gnu.org To: Kelly Dean Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jan 31 21:48:35 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 1YHey2-0008VX-6d for ged-emacs-devel@m.gmane.org; Sat, 31 Jan 2015 21:48:34 +0100 Original-Received: from localhost ([::1]:42796 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHey1-00061W-CP for ged-emacs-devel@m.gmane.org; Sat, 31 Jan 2015 15:48:33 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43191) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHexk-0005xm-LZ for emacs-devel@gnu.org; Sat, 31 Jan 2015 15:48:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YHexf-0004rI-6V for emacs-devel@gnu.org; Sat, 31 Jan 2015 15:48:16 -0500 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:54102) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHexf-0004r4-3S for emacs-devel@gnu.org; Sat, 31 Jan 2015 15:48:11 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjwPAOwQflRLd/lW/2dsb2JhbABbgweDYIVaxR0EAgKBJBcBAQEBAQF8hAMBAQMBRw8jBQsLNBIUGA0kiEoJxTGRKAEBAQcBAQEBAR2QbweESAWLAaQugXiEGSGCdwEBAQ X-IPAS-Result: AjwPAOwQflRLd/lW/2dsb2JhbABbgweDYIVaxR0EAgKBJBcBAQEBAQF8hAMBAQMBRw8jBQsLNBIUGA0kiEoJxTGRKAEBAQcBAQEBAR2QbweESAWLAaQugXiEGSGCdwEBAQ X-IronPort-AV: E=Sophos;i="5.07,502,1413259200"; d="scan'208";a="109330473" Original-Received: from 75-119-249-86.dsl.teksavvy.com (HELO fmsmemgm.homelinux.net) ([75.119.249.86]) by ironport2-out.teksavvy.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 31 Jan 2015 15:48:08 -0500 Original-Received: by fmsmemgm.homelinux.net (Postfix, from userid 20848) id B7204AE11B; Sat, 31 Jan 2015 15:48:08 -0500 (EST) In-Reply-To: (Kelly Dean's message of "Sat, 31 Jan 2015 09:18:03 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 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:182146 Archived-At: >> 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. No, if you really need it, it's a simple (cl-letf (((get-var) foo)) ...). >> 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. Right, and I think the bug is in let-binding such vars. > 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? The obvious way: (set-with-hook VAR VALUE LOCAL) > 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 features, is my implementation reasonably close to what you > had in mind? I think I'd rather have something yet a bit simpler: - extend the `constant' bit to allow a "hooked" value, for efficiency. Provide a function to set/unset this "hooked" annotation. - when setting a hooked var, call a global Elisp function with args VAR and VAL. Then you can provide debugging functions to "watch/unwatch" variables. > That would fail in this case: > (setq-default cursor-type 'bar) > Later in the same Emacs session... > (dynamic-cursor-mode) As I already said, enabling dynamic-cursor-mode should set cursor-type to t. > The user would reasonably think that DCM's failure to work in that case is a bug. > In that case, how do you turn it on buffer-locally? I don't see a need for it. > then it won't work. If you instead do: > (make-local-variable 'dynamic-cursor-mode) > (dynamic-cursor-mode) > then DCM is enabled only locally, Not really. Such usage is unsupported. Users who do that get what they deserve. > 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; That's right. I'm not worried about that either. Stefan