unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Robert Pluim <rpluim@gmail.com>
To: Stefan Kangas <stefankangas@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: emacs-28 56026242e4: Explain how to bind keys to non-ASCII sequences
Date: Tue, 15 Nov 2022 09:28:17 +0100	[thread overview]
Message-ID: <878rkcei5a.fsf@gmail.com> (raw)
In-Reply-To: <CADwFkm=08U1HQ2+5xziwBWmqjs6tYKYJanczUck9ZHXFY1VPKg@mail.gmail.com> (Stefan Kangas's message of "Mon, 14 Nov 2022 19:40:35 -0800")

>>>>> On Mon, 14 Nov 2022 19:40:35 -0800, Stefan Kangas <stefankangas@gmail.com> said:

    Stefan> This section has changed quite a bit on master, including using
    Stefan> `keymap-global-set' instead.  Unfortunately, I'm not sure what if
    Stefan> anything needs adding to the text already on master.  Could you please
    Stefan> look into it, or even help merge it?

Well this has opened a can of worms:

Item the first:

    (keymap-global-set "C-c h" "h") => [104]

    (keymap-global-set "C-c h" "hello") => 

    Debugger entered--Lisp error: (error "\"hello\" is not a valid key definition; see `key-va...")
      signal(error ("\"hello\" is not a valid key definition; see `key-va..."))
      error("%S is not a valid key definition; see `key-valid-p..." "hello")
      keymap--check("hello")
      keymap-set((keymap #^[nil nil keymap 
      keymap-global-set("C-c h" "hello")

    (keymap-global-set "C-c h" (kbd "hello")) => same

    (keymap-global-set "C-c h" "h e l l o") => [104 101 108 108 111]

    But:

    (keymap-global-set "C-c h" (kbd "olá"))  => [111 108 225]

I think itʼs a bug (and a regression from `global-set-key') to require
that what weʼre binding a key to satifies `key-valid-p' (or we need to
change the output of (kbd "hello") 😺)

(I know that binding keys to strings is not common amongst people who
know how to write their own commands, but plenty of people just want
to insert commonly used strings)

Item the second:

Higher up in that texi file is the following text:

    @findex kbd
      There are several ways to write a key binding using Lisp.  The
    simplest is to use the @code{kbd} function, which converts a textual
    representation of a key sequence---similar to how we have written key
    sequences in this manual---into a form that can be passed as an
    argument to @code{keymap-global-set}.  For example, here's how to bind
    @kbd{C-z} to the @code{shell} command (@pxref{Interactive Shell}):

    @example
    (keymap-global-set "C-z" 'shell)
    @end example

which talks about `kbd' but then never uses it (since
`keymap-global-set' doesnʼt need it).

Item the third:

But wait, maybe the documentation about `kbd' has been moved, so I
look for discussion about non-ASCII, since thatʼs where itʼs useful,
and find the following (in @node Init Non-ASCII):

      To bind non-@acronym{ASCII} keys, you must use a vector (@pxref{Init
    Rebinding}).  The string syntax cannot be used, since the
    non-@acronym{ASCII} characters will be interpreted as meta keys.  For
    instance:

    @example
    (global-set-key [?@var{char}] 'some-function)
    @end example

    @noindent
    Type @kbd{C-q}, followed by the key you want to bind, to insert @var{char}.

where rather than telling people to write vectors by hand, we could
explain how to use `kbd'.

Robert
-- 



  reply	other threads:[~2022-11-15  8:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <166844275725.4187.2343107623845911514@vcs2.savannah.gnu.org>
     [not found] ` <20221114161917.7FC8AC00AB5@vcs2.savannah.gnu.org>
2022-11-15  3:40   ` emacs-28 56026242e4: Explain how to bind keys to non-ASCII sequences Stefan Kangas
2022-11-15  8:28     ` Robert Pluim [this message]
2022-11-15  9:09       ` Stefan Kangas
2022-11-15  9:14         ` Robert Pluim
2022-11-16  7:44           ` Stefan Kangas
2022-11-16  8:50             ` Robert Pluim

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=878rkcei5a.fsf@gmail.com \
    --to=rpluim@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=stefankangas@gmail.com \
    /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).