From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Robin Templeton Newsgroups: gmane.emacs.devel Subject: Re: add-hook and defvar Date: Sat, 21 Feb 2015 17:35:10 -0500 Message-ID: <87y4nqopup.fsf@panthera.terpri.org> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1424558140 16339 80.91.229.3 (21 Feb 2015 22:35:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 21 Feb 2015 22:35:40 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Feb 21 23:35:32 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 1YPIe4-00042V-12 for ged-emacs-devel@m.gmane.org; Sat, 21 Feb 2015 23:35:32 +0100 Original-Received: from localhost ([::1]:37677 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YPIe3-00004z-HE for ged-emacs-devel@m.gmane.org; Sat, 21 Feb 2015 17:35:31 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YPIdx-0008WP-4j for emacs-devel@gnu.org; Sat, 21 Feb 2015 17:35:26 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YPIds-00066u-UE for emacs-devel@gnu.org; Sat, 21 Feb 2015 17:35:24 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:58509) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YPIds-00066k-Mf for emacs-devel@gnu.org; Sat, 21 Feb 2015 17:35:20 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1YPIdq-0003xB-N9 for emacs-devel@gnu.org; Sat, 21 Feb 2015 23:35:18 +0100 Original-Received: from cpe-174-097-170-150.nc.res.rr.com ([174.97.170.150]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 21 Feb 2015 23:35:18 +0100 Original-Received: from robin by cpe-174-097-170-150.nc.res.rr.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 21 Feb 2015 23:35:18 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 47 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: cpe-174-097-170-150.nc.res.rr.com User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:hYror7UaqgqrvqvTxdRkjw3pHR4= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:183371 Archived-At: Artur Malabarba writes: > While it's nice that `add-hook' tries to do the right thing even when > the variable isn't defined yet, that's a bit of a false assurance. > Although it's documented in the docstring, it seems undesirable that > it sets the variable. This means that if the hook's defvar were to > specify an initial value, this value won't take effect because of that > preceding `add-hook' invocation. This seems like a bug in the program defining the hook variable, not a problem with `add-hook' per se; programs should always allow for the possibility that the user has set their own value for a variable and that the default value in the defvar form is ignored. I would expect the program to call `add-hook' itself if the default hook functions were important. > In this situation, add-hook doesn't so much "add" as it actually sets > the value of the hook. > > The following patch is one way of having `add-hook' always add, > without overriding the "future" initial value of the hook. It is not > complete, it's intended as a possible outline (hopefully a > conversation starter). > > The big disadvantage is that it's not backwards compatible. Any code > out there that relies on the variable being set by `add-hook' will > break. > There's also the disadvantage that it adds a symbol-property check to > every `defvar' call. > > Any thoughts? Another potential problem is that `add-hook' followed by `run-hooks' will do nothing if the hook variable has not been defined. If the behavior of `add-hook' were changed, I would prefer it if it simply required the variable to be defined; that would avoid the above disadvantages, would make it consistent with functions like `add-to-list', and would normally ensure that the hook is initialized as expected. my 2ยข, robin -- Inteligenta persono lernas la lingvon Esperanton rapide kaj facile. Esperanto estas moderna, kultura lingvo por la mondo. Simpla, fleksebla, belsona, Esperanto estas la praktika solvo de la problemo de universala interkompreno. Lernu la interlingvon Esperanton!