all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Robert Pluim <rpluim@gmail.com>
To: Stefan Kangas <stefan@marxist.se>
Cc: 56873@debbugs.gnu.org
Subject: bug#56873: Make `defvar-keymap' warn on conflicting and redundant bindings
Date: Tue, 02 Aug 2022 10:25:46 +0200	[thread overview]
Message-ID: <87mtcnhx11.fsf@gmail.com> (raw)
In-Reply-To: <CADwFkm=ioq8xYMNyun5od+MqdmYAT8by3Tk9Ff1y84HCA3iLiQ@mail.gmail.com> (Stefan Kangas's message of "Mon, 1 Aug 2022 16:47:10 +0000")

>>>>> On Mon, 1 Aug 2022 16:47:10 +0000, Stefan Kangas <stefan@marxist.se> said:

    Stefan> Severity: wishlist
    Stefan> It would be useful if `defvar-keymap' could warn on conflicting
    Stefan> bindings, such as in:

    Stefan>     (defvar-keymap foo
    Stefan>       "a" #'next-line
    Stefan>       "a" #'previous-line)

Is that a common occurence?

    Stefan> It would also be useful to warn about redundant bindings, such as in:

    Stefan>     (defvar-keymap foo
    Stefan>       "a" #'next-line
    Stefan>       "a" #'next-line)

Thatʼs just a special case of conflicting bindings. This will do it,
but I wonder if `warn' is overkill. I put it in `define-keymap', but
it could equally well go in `defvar-keymap'.

diff --git a/lisp/keymap.el b/lisp/keymap.el
index 376a30f106..b44a961d73 100644
--- a/lisp/keymap.el
+++ b/lisp/keymap.el
@@ -530,7 +530,8 @@ define-keymap
                    (keymap keymap)
                    (prefix (define-prefix-command prefix nil name))
                    (full (make-keymap name))
-                   (t (make-sparse-keymap name)))))
+                   (t (make-sparse-keymap name))))
+          seen-keys)
       (when suppress
         (suppress-keymap keymap (eq suppress 'nodigits)))
       (when parent
@@ -544,6 +545,9 @@ define-keymap
           (let ((def (pop definitions)))
             (if (eq key :menu)
                 (easy-menu-define nil keymap "" def)
+              (if (member key seen-keys)
+                  (warn "Duplicate definition for key: %S" key)
+                (push key seen-keys))
               (keymap-set keymap key def)))))
       keymap)))
 

Robert
-- 





  reply	other threads:[~2022-08-02  8:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-01 16:47 bug#56873: Make `defvar-keymap' warn on conflicting and redundant bindings Stefan Kangas
2022-08-02  8:25 ` Robert Pluim [this message]
2022-08-02  9:48   ` Lars Ingebrigtsen
2022-08-02 15:46     ` Drew Adams
2022-08-02 10:09   ` Stefan Kangas
2022-08-02 11:53     ` Robert Pluim
2022-08-02 12:01       ` Lars Ingebrigtsen
2022-08-02 12:33         ` Robert Pluim
2022-08-02 12:17       ` Stefan Kangas

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mtcnhx11.fsf@gmail.com \
    --to=rpluim@gmail.com \
    --cc=56873@debbugs.gnu.org \
    --cc=stefan@marxist.se \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.