unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Philipp Stephani <p.stephani2@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Artur Malabarba <bruce.connor.am@gmail.com>,
	emacs-devel <emacs-devel@gnu.org>
Subject: Re: add-hook and defvar
Date: Thu, 05 Mar 2015 20:28:08 +0000	[thread overview]
Message-ID: <CAArVCkScF5OsriXerGivyWfm7WpTsZt23fXbm3gksHgN7CZvvQ@mail.gmail.com> (raw)
In-Reply-To: jwv8ufmk8bv.fsf-monnier+emacs@gnu.org


[-- Attachment #1.1: Type: text/plain, Size: 375 bytes --]

Stefan Monnier <monnier@iro.umontreal.ca> schrieb am Mi., 25. Feb. 2015 um
03:56 Uhr:

> > Is this something the byte compiler could warn about? At least normal
> hooks
> > by convention end in "-hook", so a warning could be emitted every time
> such
> > a variable is defined that doesn't have nil as default.
>
> Yes, we could do that.  Patch welcome,
>
>
>
Added a patch.

[-- Attachment #1.2: Type: text/html, Size: 674 bytes --]

[-- Attachment #2: 0001-Warn-if-a-hook-variable-is-given-a-non-nil-init-form.txt --]
[-- Type: text/plain, Size: 966 bytes --]

From 8aad74d2cb12a7afd6067b8737894c3a4b905a20 Mon Sep 17 00:00:00 2001
From: Philipp Stephani <phst@google.com>
Date: Thu, 5 Mar 2015 21:06:07 +0100
Subject: [PATCH] Warn if a hook variable is given a non-nil init form

---
 lisp/emacs-lisp/bytecomp.el | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index e929c02..b9db322 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -2311,6 +2311,9 @@ list that represents a doc string reference.
 (defun byte-compile-file-form-defvar (form)
   (let ((sym (nth 1 form)))
     (byte-compile--declare-var sym)
+    (and (string-suffix-p "-hook" (symbol-name sym))
+         (nth 2 form)
+         (byte-compile-warn "hook variable `%s' has non-nil init value" sym))
     (if (eq (car form) 'defconst)
         (push sym byte-compile-const-variables)))
   (if (and (null (cddr form))		;No `value' provided.
-- 
2.2.0.rc0.207.ga3a616c


  reply	other threads:[~2015-03-05 20:28 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-21 19:55 add-hook and defvar Artur Malabarba
2015-02-21 21:05 ` Drew Adams
2015-02-21 22:35 ` Robin Templeton
2015-02-23  5:00   ` Artur Malabarba
2015-02-22 19:18 ` Stefan Monnier
2015-02-23  5:10   ` Artur Malabarba
2015-02-23 22:31     ` Stefan Monnier
2015-02-24  6:29       ` Philipp Stephani
2015-02-25  2:56         ` Stefan Monnier
2015-03-05 20:28           ` Philipp Stephani [this message]
2015-03-05 21:45             ` Artur Malabarba
2015-03-06 19:05               ` Philipp Stephani
2015-03-06 20:27                 ` Artur Malabarba
2015-03-10  2:14             ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAArVCkScF5OsriXerGivyWfm7WpTsZt23fXbm3gksHgN7CZvvQ@mail.gmail.com \
    --to=p.stephani2@gmail.com \
    --cc=bruce.connor.am@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).