() Stefan Monnier () 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