From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: The new keymap functions Date: Tue, 15 Nov 2022 20:38:46 +0200 Organization: LINKOV.NET Message-ID: <86wn7wf6rl.fsf@mail.linkov.net> References: <87zgq8sfw3.fsf@gnus.org> <86k0h8ts66.fsf@mail.linkov.net> <87r1bfp72g.fsf@gnus.org> <86v90r6w3j.fsf@mail.linkov.net> <87o86jm83k.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32900"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: Lars Ingebrigtsen , Emacs developers To: Robert Pluim Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Nov 15 19:52:35 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ov12w-0008LK-R4 for ged-emacs-devel@m.gmane-mx.org; Tue, 15 Nov 2022 19:52:34 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ov12K-0004jP-1l; Tue, 15 Nov 2022 13:52:03 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ov12D-0004g8-2a for emacs-devel@gnu.org; Tue, 15 Nov 2022 13:51:50 -0500 Original-Received: from relay5-d.mail.gandi.net ([2001:4b98:dc4:8::225]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ov128-0000l5-AJ for emacs-devel@gnu.org; Tue, 15 Nov 2022 13:51:48 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 8DAA31C0003; Tue, 15 Nov 2022 18:51:37 +0000 (UTC) In-Reply-To: <87o86jm83k.fsf@gmail.com> (Robert Pluim's message of "Wed, 17 Nov 2021 10:42:23 +0100") Received-SPF: pass client-ip=2001:4b98:dc4:8::225; envelope-from=juri@linkov.net; helo=relay5-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:299872 Archived-At: --=-=-= Content-Type: text/plain >> 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=defvar-keymap-repeat-map.patch 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 "" #'next-buffer "" #'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'." --=-=-=--