unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: hugo@heagren.com
Cc: 72460@debbugs.gnu.org
Subject: bug#72460: [patch] add commands for setting keyboard translations interactively
Date: Sat, 31 Aug 2024 09:56:58 -0400	[thread overview]
Message-ID: <jwvwmjwresn.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <ed0eede1b3ac4e6da54c2449e3c8ea4f@heagren.com> (hugo@heagren.com's message of "Tue, 20 Aug 2024 14:01:53 +0100")

>> > +(defcustom key-translate-selection-function #'key-select-translation
>> Do we need this?
> Short answer: yes.
>
> I wanted a way for users to customise how the current translation
> pairs are presented when they choose one to remove. The initial
> motivation was that some users might want to customise the formatting
> of the pairs; "X -> Y" vs "X → Y" vs "X Y" etc. (I'm the sort of user
> who cares about this sort of thing a lot).

Rewriting a whole new `key-translate-selection-function` function for
that is not significantly easier than rewriting a whole new
`key-translate-remove`, so I think this is firmly in the overengineering
side of the camp.

> I also envisage that many users will want to use/expect
> completing-read (as in the default) and will want the from/to elements
> vertically aligned (again, I am this user).

AFAICT, you're the first user to propose this functionality in Emacs's
40 years life, so I wouldn't bet on "many users".

BTW, I just noticed:

> +    ;; Populate collection
> +    (map-char-table format-func keyboard-translate-table)
> +    (get-text-property 0 'key-translate-from
> +                       (completing-read "Key Translation: " collection))))

You can't trust `get-text-property` here (especially since you don't
even force `completing-read` to `require-match`).
Instead you should do something like `key-parse`.

> I think here I was just copying the current calling convention for the
> existing (non-interactive) `key-translate'. Its docstring reads:
>
>> Both FROM and TO should be specified by strings that satisfy
>> `key-valid-p'.
>
> I sort of assumed someone cleverer than me had a good reason.

I suspect this is because we expect this function to be called from
a `~/.emacs` with a literal constant as argument, and we've tried to
unify on using the "KBD" syntax for those cases, since it's a friendlier
syntax than the "vector of events" where you need to distinguish between
symbols and chars with/without modifiers.

Since the arg of `key-translate` can be only a valid char (rather than
any arbitrary key potentially with modifiers), the argument is much less
strong, but my guess is that it was uniformity.

In the case of `key-translate-remove` I don't expect the arg to be
a literal constant in the code, so "nice/uniform syntax to write the
argument value" shouldn't be a concern.  🙂


        Stefan






  parent reply	other threads:[~2024-08-31 13:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-04 12:16 bug#72460: [patch] add commands for setting keyboard translations interactively hugo
2024-08-17  8:46 ` Eli Zaretskii
2024-08-19 14:42 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-08-31  8:08   ` Eli Zaretskii
     [not found]   ` <ed0eede1b3ac4e6da54c2449e3c8ea4f@heagren.com>
2024-08-31 13:56     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-09-14  7:38       ` Eli Zaretskii

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=jwvwmjwresn.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=72460@debbugs.gnu.org \
    --cc=hugo@heagren.com \
    --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).