unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Robert Pluim <rpluim@gmail.com>
Cc: Lars Ingebrigtsen <larsi@gnus.org>,
	Emacs developers <emacs-devel@gnu.org>
Subject: Re: The new keymap functions
Date: Tue, 15 Nov 2022 20:38:46 +0200	[thread overview]
Message-ID: <86wn7wf6rl.fsf@mail.linkov.net> (raw)
In-Reply-To: <87o86jm83k.fsf@gmail.com> (Robert Pluim's message of "Wed, 17 Nov 2021 10:42:23 +0100")

[-- Attachment #1: Type: text/plain, Size: 653 bytes --]

>> The reason why I'm asking this is to know how the corresponding
>> function/macro for repeat-mode should be named in master.
>> And it seems `define-repeat-map' would be the right name.
>
> Are you sure you need a `define-repeat-map'? Just adding a :repeat
> keyword to `defvar-keymap' would be enough.

Thanks for the patch.  It would be nice to add also
:repeat-enter and :repeat-exit.  For example:

  :repeat-map t
  :repeat-enter '(enter-command ...)
  :repeat-exit '(exit-command ...)

Or maybe a shorter variant would be preferable?

  :repeat '(:enter '(enter-command ...) :exit '(exit-command ...))

Anyway this supports the first variant:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: defvar-keymap-repeat-map.patch --]
[-- Type: text/x-diff, Size: 3993 bytes --]

diff --git a/lisp/bindings.el b/lisp/bindings.el
index c1ad5f7520e..fcaa44648ab 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -1031,12 +1036,10 @@ global-map
 
 (defvar-keymap buffer-navigation-repeat-map
   :doc "Keymap to repeat `next-buffer' and `previous-buffer'.  Used in `repeat-mode'."
+  :repeat-map t
   "<right>" #'next-buffer
   "<left>"  #'previous-buffer)
 
-(put 'next-buffer 'repeat-map 'buffer-navigation-repeat-map)
-(put 'previous-buffer 'repeat-map 'buffer-navigation-repeat-map)
-
 (let ((map minibuffer-local-map))
   (define-key map "\en"   'next-history-element)
   (define-key map [next]  'next-history-element)
diff --git a/lisp/keymap.el b/lisp/keymap.el
index 107565590c1..15b00a8401c 100644
--- a/lisp/keymap.el
+++ b/lisp/keymap.el
@@ -557,22 +557,39 @@ defvar-keymap
 
 In addition to the keywords accepted by `define-keymap', this
 macro also accepts a `:doc' keyword, which (if present) is used
-as the variable documentation string.
+as the variable documentation string.  Also it accepts:
 
-\(fn VARIABLE-NAME &key DOC FULL PARENT SUPPRESS NAME PREFIX KEYMAP &rest [KEY DEFINITION]...)"
+:repeat-map   If non-nil, put the `repeat-map' symbol properties
+              on commands in this map for `repeat-mode'.
+
+:repeat-enter A list of additional commands that only enter `repeat-mode'.
+              When the list is empty then by default all commands in the
+              map enter `repeat-mode'.  This is applicable when a command
+              has the `repeat-map' symbol property on its symbol, but
+              doesn't exist in the map.
+
+:repeat-exit A list of commands that exit `repeat-mode'.  When the
+             list is empty, no commands in the map exit `repeat-mode'.
+             This is applicable when a command exists in the map, but
+             doesn't have the `repeat-map' symbol property on its symbol.
+
+\(fn VARIABLE-NAME &key DOC FULL PARENT SUPPRESS NAME PREFIX KEYMAP REPEAT-MAP REPEAT-ENTER REPEAT-EXIT &rest [KEY DEFINITION]...)"
   (declare (indent 1))
   (let ((opts nil)
-        doc)
+        doc repeat-map repeat-enter repeat-exit props)
     (while (and defs
                 (keywordp (car defs))
                 (not (eq (car defs) :menu)))
       (let ((keyword (pop defs)))
         (unless defs
           (error "Uneven number of keywords"))
-        (if (eq keyword :doc)
-            (setq doc (pop defs))
-          (push keyword opts)
-          (push (pop defs) opts))))
+        (pcase keyword
+          (:doc (setq doc (pop defs)))
+          (:repeat-map   (setq repeat-map   (pop defs)))
+          (:repeat-enter (setq repeat-enter (pop defs)))
+          (:repeat-exit  (setq repeat-exit  (pop defs)))
+          (_ (push keyword opts)
+             (push (pop defs) opts)))))
     (unless (zerop (% (length defs) 2))
       (error "Uneven number of key/definition pairs: %s" defs))
     (let ((defs defs)
@@ -585,9 +602,24 @@ defvar-keymap
               (error "Duplicate definition for key '%s' in keymap '%s'"
                      key variable-name)
             (push key seen-keys)))))
-    `(defvar ,variable-name
-       (define-keymap ,@(nreverse opts) ,@defs)
-       ,@(and doc (list doc)))))
+    (when repeat-map
+      (let ((defs defs)
+            def)
+        (while defs
+          (pop defs)
+          (setq def (pop defs))
+          (when (and (or (eq (car def) 'function)
+                         (eq (car def) 'quote))
+                     (or (null repeat-exit)
+                         (not (memq def repeat-exit))))
+            (push `(put ,def 'repeat-map ',variable-name) props)))
+        (dolist (def repeat-enter)
+          (push `(put ',def 'repeat-map ',variable-name) props))))
+    `(progn
+       (defvar ,variable-name
+         (define-keymap ,@(nreverse opts) ,@defs)
+         ,@(and doc (list doc)))
+       ,@props)))
 
 (defun make-non-key-event (symbol)
   "Mark SYMBOL as an event that shouldn't be returned from `where-is'."

  parent reply	other threads:[~2022-11-15 18:38 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-13  6:56 The new keymap functions Lars Ingebrigtsen
2021-11-13  7:31 ` Stefan Kangas
2021-11-13  7:50   ` Lars Ingebrigtsen
2021-11-13 11:36 ` Joost Kremers
2021-11-13 12:07   ` Lars Ingebrigtsen
2021-11-15 13:01     ` Dmitry Gutov
2021-11-15 16:53       ` Lars Ingebrigtsen
2021-11-16  7:28         ` Lars Ingebrigtsen
2021-11-16 14:08           ` Eli Zaretskii
2021-11-16 14:24             ` Lars Ingebrigtsen
2021-11-16 15:13               ` Eli Zaretskii
2021-11-16 15:19                 ` Lars Ingebrigtsen
2021-11-16 17:16                   ` Eli Zaretskii
2021-11-17  7:30                     ` Lars Ingebrigtsen
2021-11-13 15:09 ` Stefan Monnier
2021-11-13 15:24   ` Lars Ingebrigtsen
2021-11-14  3:17 ` Lars Ingebrigtsen
2021-11-14  5:05 ` Phil Sainty
2021-11-14  5:14   ` Lars Ingebrigtsen
2021-11-14  7:15     ` Eli Zaretskii
2021-11-14 10:53       ` Lars Ingebrigtsen
2021-11-14 11:01         ` Lars Ingebrigtsen
2021-11-14  7:41     ` Yuri Khan
2021-11-15  4:52 ` Richard Stallman
2021-11-15  5:14   ` Lars Ingebrigtsen
2021-11-16  4:05   ` Richard Stallman
2021-11-16  7:38     ` Lars Ingebrigtsen
2021-11-16 16:25       ` [External] : " Drew Adams
2021-11-17  4:16       ` Richard Stallman
2021-11-17  7:55         ` Lars Ingebrigtsen
2021-11-17 16:06           ` [External] : " Drew Adams
2021-11-16 16:24     ` Drew Adams
2021-11-16 20:14 ` Juri Linkov
2021-11-17  4:16   ` Richard Stallman
2021-11-17  7:36   ` Lars Ingebrigtsen
2021-11-17  8:10     ` Juri Linkov
2021-11-17  9:42       ` Robert Pluim
2021-11-17 17:03         ` Juri Linkov
2021-11-18  9:15           ` Lars Ingebrigtsen
2021-11-18 10:25             ` Robert Pluim
2021-11-18 10:33               ` Lars Ingebrigtsen
2021-11-18 10:37                 ` Lars Ingebrigtsen
2021-11-18 10:54                   ` Robert Pluim
2021-11-18 10:59                     ` Lars Ingebrigtsen
2022-11-15 18:38         ` Juri Linkov [this message]
2022-11-17  7:31           ` Juri Linkov
2022-11-17  8:35             ` Robert Pluim
2022-11-17 15:04               ` Robert Pluim
2022-11-17 17:29                 ` Juri Linkov
2022-11-18  8:33                   ` Robert Pluim
2022-11-18 15:41                     ` Robert Pluim
2023-03-17 14:48                 ` Robert Pluim
2023-03-18 18:04                   ` Juri Linkov
2023-03-20  8:54                     ` Robert Pluim
2021-11-17 20:57     ` Bob Rogers
2021-11-18  3:53       ` Richard Stallman
  -- strict thread matches above, loose matches on Subject: below --
2021-11-13 18:59 xenodasein--- via Emacs development discussions.
2021-11-14  0:42 ` Lars Ingebrigtsen
2021-11-14  4:56   ` Lars Ingebrigtsen
2021-11-14 15:41     ` Stefan Monnier
2021-11-14 18:00       ` Lars Ingebrigtsen
2021-11-14 12:04   ` xenodasein--- via Emacs development discussions.

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=86wn7wf6rl.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=emacs-devel@gnu.org \
    --cc=larsi@gnus.org \
    --cc=rpluim@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).