emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Suggested experimental test


From: Dmitry Gutov
Subject: Re: Suggested experimental test
Date: Sat, 27 Mar 2021 01:34:52 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1

On 25.03.2021 21:30, Yuri Khan wrote:
On Thu, 25 Mar 2021 at 20:20, Dmitry Gutov <dgutov@yandex.ru> wrote:

But C-c doesn't have a dedicated keymap, so solving this seems like the
first step. What could we do?

    (kbd (format "%s C-l" ctl-c-key-sequence) 'some-command)

Or maybe create a bogus ctrl-c keymap and then make sure to refer to its
binding with something like

    (kbd "[C-c] C-l" 'some-command)

...I'm not sure, ideas welcome.

How about this:

* Introduce a virtual key, let’s call it <mode-specific>. Let’s
specifically *not* name it <key-formerly-known-as-C-c>.
* Have all modes use that as the prefix key for mode-specific
commands, instead of C-c.
* In the default configuration, translate C-c to <mode-specific>.

Proof of concept:

     $ emacs -Q

     (define-key help-mode-map (kbd "<mode-specific> <mode-specific>")
                 #'help-follow-symbol)
     (define-key help-mode-map (kbd "<mode-specific> C-b") #'help-go-back)
     (define-key help-mode-map (kbd "<mode-specific> C-f") #'help-go-forward)
     (define-key key-translation-map (kbd "<menu>") (kbd "<mode-specific>"))
     ;; C-x C-e all of the above

     (define-key help-mode-map (kbd "C-c C-c") nil)
     (define-key help-mode-map (kbd "C-c C-b") nil)
     (define-key help-mode-map (kbd "C-c C-f") nil)
     (define-key help-mode-map (kbd "C-c") nil)
     ;; should be unneeded after all modes convert

     (global-set-key (kbd "C-c") #'copy-region-as-kill)
     (global-set-key (kbd "C-v") #'cua-paste)

     <f1> m C-x o
     ;; I’m now in a *Help* buffer listing currently enabled modes

     <f1> b
     ;; I’m now in a *Help* buffer listing bindings

     <menu> C-b
     ;; I’m back to modes

     <menu> C-f
     ;; I’m back to bindings

     S-<down> S-<down> S-<down> C-c
     C-x o C-v
     ;; I have a copy of a few lines from *Help* in my *scratch*

This is a solid proposal. We can go with it, especially if we don't mind the key sequence ergonomics in keymaps, as well as backward incompatibility.

Perhaps we could instead do something with key-translation-map (or one of its friends) that works on existing keymaps?

The use of 'menu-item' allows us to filter based on whether the key is first in the sequence:

(define-key key-translation-map (kbd "<menu>") (kbd "C-c"))
(define-key key-translation-map (kbd "C-c")
  `(menu-item "" ,(kbd "<C-c-translated>")
              :filter my--head-of-sequence-p))
(global-set-key (kbd "<C-c-translated>") 'kill-ring-save)

(defun my--head-of-sequence-p (cmd)
  (if (> (length (this-command-keys-vector)) 1)
      (kbd "C-c")
    cmd))

This seems backward-compatible enough, but the main downside is that Emacs now says 'C-c-' in the echo area when you hit <menu>. Which must be confusing to the main target audience.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]