unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: 54161@debbugs.gnu.org
Subject: bug#54161: 27.2; `define-minor-mode' with alist of key bindings
Date: Fri, 25 Feb 2022 17:48:41 +0000	[thread overview]
Message-ID: <SJ0PR10MB5488E28AC3E53A0C5D919131F33E9@SJ0PR10MB5488.namprd10.prod.outlook.com> (raw)

Apologies for this bug report, as I imagine it must be a duplicate, but
I couldn't find the dup.

And I imagine that there's no bug in behavior, and I'm just
misunderstanding the doc.  (The behavior is longstanding across Emacs
releases.)

In that case, maybe the doc could benefit from some rewording?  I've
reread it a few times now, and I haven't figured out what I'm
misreading.

emacs -Q

These, and similar variants (e.g. using keyword :keymap) produce a
keymap that defines a binding for command `forward-char' with prefix key
`C', followed by `-', followed by `o'.  I would expect them to instead
bind the command to key `C-o'.

(define-minor-mode tata-mode
  "TATA MODE" nil nil '(("\\C-o" . forward-char)))

(define-minor-mode titi-mode
  "TITI MODE" nil nil '(((kbd "C-o") . forward-char)))

Digging into the expansion of `define-minor-mode' I see that those sexps
expand these sexps to produce the keymaps:

(easy-mmode-define-keymap '(("\\C-o" . forward-char)))
(easy-mmode-define-keymap '(((kbd "C-o") . forward-char)))

And those produce this keymap:

(keymap (67 keymap (45 keymap (111 . forward-char))))

That is,

(keymap (?C keymap (?- keymap (?o . forward-char))))

The doc (both Elisp manual and doc string) says this:

 The optional argument KEYMAP specifies the keymap for the minor
 mode.  If non-'nil', it should be a variable name (whose value is a
 keymap), a keymap, or an alist of the form

      (KEY-SEQUENCE . DEFINITION)

 where each KEY-SEQUENCE and DEFINITION are arguments suitable for
 passing to 'define-key'.

I think that's the case in these examples, no?  Both (kbd "C-o") and
"\C-o" are suitable args for `define-key'.

What am I missing?

I searched the Elisp sources and noticed only one occurrence of using an
explicit alist, in refill.el:

 :keymap '(("\177" . backward-delete-char-untabify))

And indeed, if I use this, which has a literal Control-O character,
there's no problem (key `C-o' is bound to `forward-char):

(define-minor-mode toto-mode
  "TOTO MODE" nil nil '(("^O" . forward-char)))

(The Control-O char won't pass through email, so I've substituted the
string "^O", but it is actually a string with just a Control-O char.)

In GNU Emacs 27.2 (build 1, x86_64-w64-mingw32)
 of 2021-03-26 built on CIRROCUMULUS
Repository revision: deef5efafb70f4b171265b896505b92b6eef24e6
Repository branch: HEAD
Windowing system distributor 'Microsoft Corp.', version 10.0.19043
System Description: Microsoft Windows 10 Pro (v10.0.2009.19043.1526)






             reply	other threads:[~2022-02-25 17:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-25 17:48 Drew Adams [this message]
2022-02-25 21:41 ` bug#54161: 27.2; `define-minor-mode' with alist of key bindings Gilles
2022-02-26  3:20   ` bug#54161: [External] : " Drew Adams
2022-02-28  9:46   ` Lars Ingebrigtsen
2022-03-01  1:21   ` Michael Heerdegen
2022-03-01 15:41     ` Lars Ingebrigtsen
2022-03-01 18:16       ` bug#54161: [External] : " Drew Adams
2022-03-01 22:18         ` Michael Heerdegen
2022-03-01 22:52           ` Lars Ingebrigtsen
2022-03-01 23:56             ` Michael Heerdegen
2022-03-02  0:04               ` Michael Heerdegen
2022-03-01 18:11     ` Drew Adams
2022-02-25 22:33 ` Drew Adams
2022-02-25 22:43   ` Drew Adams

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=SJ0PR10MB5488E28AC3E53A0C5D919131F33E9@SJ0PR10MB5488.namprd10.prod.outlook.com \
    --to=drew.adams@oracle.com \
    --cc=54161@debbugs.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).