unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Thien-Thi Nguyen <ttn@gnu.org>
To: emacs-devel@gnu.org
Subject: Re: [elpa] master 550ae83 1/2: [gnugo int] Decruft: Don't declare hook and keymap vars.
Date: Thu, 09 Feb 2017 18:39:58 +0100	[thread overview]
Message-ID: <87a89vmff5.fsf@zigzag.favinet> (raw)
In-Reply-To: <jwva89w48vn.fsf-monnier+emacsdiffs@gnu.org> (Stefan Monnier's message of "Wed, 08 Feb 2017 17:28:44 -0500")

[-- Attachment #1: Type: text/plain, Size: 2728 bytes --]


() Stefan Monnier <monnier@IRO.UMontreal.CA>
() Wed, 08 Feb 2017 17:28:44 -0500

   why you prefer the non-idiomatic way

I don't know what to call idiomatic or non-idiomatic.  I simply
try to muddle through (i.e., survive w/o {add,los}ing many gray
hairs) the evolution of Emacs.  In the old days, the model was:

 (defvar MODE-map nil)                    ; model A
 (defun MODE () ...)
 (unless MODE-map
   (setq MODE-amp INIT))

This and the byte-compiled result worked fine for many years,
satisfying the design goals: (a) declare once; (b) init once,
even during re-‘load’ (to avoid clobbering customizations); (c)
init only after commands are defined.  Aside: (c) is arguably
non-idiomatic to begin w/ for Emacs Lisp; it's a personal
aesthetic born from exposure to C and Guile, where keeping
definitions topologically sorted makes for less-cluttered code.

Then, at some point ‘define-derived-mode’ was introduced and i
tried the modified model:

 (defvar MODE-map nil)                    ; model B
 (define-derived-mode MODE ...)
 (unless MODE-map
   (setq MODE-map INIT))

This worked sometimes, but not others.  I suspect the times it
didn't work were when byte-compiling substituted the ‘nil’ in
the declaration for ‘(make-sparse-keymap)’, resulting in the
‘unless’ CONDITION evaluating to true and thus precluding init.

Rather than investigate further, i vaguely recall reluctantly
forgoing design goal (c) and adopting the model:

 (defvar MODE-map INIT)                   ; model C
 (define-derived-mode MODE ...)

The comment in the removed INIT in the patch (in Subject) shows
some of the hand-wringing involved w/ the B-C transition.  What
i (somewhat stupidly) didn't realize at the time is that using
‘define-derived-mode’ (models B and later) already departs from
design goal (a).  So that brings us to the present model:

 (define-derived-mode MODE ...)           ; model D
 (unless EXPECTED-MODE-map-BINDING
   (INITIALZE MODE-map))

which once again supports all three design goals, though less
perfectly (CONDITION was algorithmic, now heuristic) than model
A.  I think in this case, the chosen CONDITION is close enough.

Anyway, i especially enjoy the reduction in forms, which is what
i imagine the introduction of ‘define-derived-mode’ was supposed
to achieve.  Pruned profligacy for perplexable programmers!  :-D

-- 
Thien-Thi Nguyen -----------------------------------------------
 (defun responsep (query)
   (pcase (context query)
     (`(technical mailing-list) t)
     ...))                              748E A0E8 1CB8 A748 9BFA
--------------------------------------- 6CE4 6703 2224 4C80 7502


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

  reply	other threads:[~2017-02-09 17:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20170208091858.6699.16542@vcs.savannah.gnu.org>
     [not found] ` <20170208091858.F26CA220010@vcs.savannah.gnu.org>
2017-02-08 22:28   ` [elpa] master 550ae83 1/2: [gnugo int] Decruft: Don't declare hook and keymap vars Stefan Monnier
2017-02-09 17:39     ` Thien-Thi Nguyen [this message]
2017-02-09 18:02       ` Stefan Monnier
2017-02-10  5:15         ` Thien-Thi Nguyen
2017-02-14 14:04           ` Stefan Monnier
2017-02-16  9:41             ` Thien-Thi Nguyen
2017-02-12 11:12         ` Philipp Stephani
2017-02-13  7:29           ` 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=87a89vmff5.fsf@zigzag.favinet \
    --to=ttn@gnu.org \
    --cc=emacs-devel@gnu.org \
    /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).