diff options
| author | Lars Ingebrigtsen | 2022-06-18 14:06:00 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2022-06-18 14:06:30 +0200 |
| commit | 0dc75daf1189d2327c6efa4d747fa98fcba03ea3 (patch) | |
| tree | ff53b16faa9c8fef8530590abca8f8e99ba44ccb | |
| parent | d7265d58f8dbab8049be4be0fa3f474e7fef7be6 (diff) | |
| download | emacs-0dc75daf1189d2327c6efa4d747fa98fcba03ea3.tar.gz emacs-0dc75daf1189d2327c6efa4d747fa98fcba03ea3.zip | |
Filter out NS non-key events from `where-is-internal'
* doc/lispref/keymaps.texi (Scanning Keymaps): Document it.
* lisp/keymap.el (make-non-key-event): New function.
* lisp/term/common-win.el (x-setup-function-keys): Mark ns events
as not being keys (bug#55940).
* src/keymap.c (Fwhere_is_internal): Filter out key sequences that
are marked as being non-keys.
| -rw-r--r-- | doc/lispref/keymaps.texi | 5 | ||||
| -rw-r--r-- | etc/NEWS | 6 | ||||
| -rw-r--r-- | lisp/keymap.el | 5 | ||||
| -rw-r--r-- | lisp/term/common-win.el | 27 | ||||
| -rw-r--r-- | src/keymap.c | 14 | ||||
| -rw-r--r-- | test/src/keymap-tests.el | 10 |
6 files changed, 51 insertions, 16 deletions
diff --git a/doc/lispref/keymaps.texi b/doc/lispref/keymaps.texi index a037c228f13..a27b0ea366c 100644 --- a/doc/lispref/keymaps.texi +++ b/doc/lispref/keymaps.texi | |||
| @@ -2209,6 +2209,11 @@ If @var{no-remap} is @code{nil}, return the bindings for | |||
| 2209 | non-@code{nil}, return the bindings for @var{command}, ignoring the | 2209 | non-@code{nil}, return the bindings for @var{command}, ignoring the |
| 2210 | fact that it is remapped. | 2210 | fact that it is remapped. |
| 2211 | @end table | 2211 | @end table |
| 2212 | |||
| 2213 | If a command maps to a key binding like @code{[some-event]}, and | ||
| 2214 | @code{some-event} has a symbol plist containing a non-@code{nil} | ||
| 2215 | @code{non-key-event} property, then that binding is ignored by | ||
| 2216 | @code{where-is-internal}. | ||
| 2212 | @end defun | 2217 | @end defun |
| 2213 | 2218 | ||
| 2214 | @deffn Command describe-bindings &optional prefix buffer-or-name | 2219 | @deffn Command describe-bindings &optional prefix buffer-or-name |
| @@ -2364,6 +2364,12 @@ option. | |||
| 2364 | ** Keymaps and key definitions | 2364 | ** Keymaps and key definitions |
| 2365 | 2365 | ||
| 2366 | +++ | 2366 | +++ |
| 2367 | *** 'where-is-internal' can now filter events marked as non key events. | ||
| 2368 | If a command maps to a key binding like [some-event], and 'some-event' | ||
| 2369 | has a symbol plist containing a non-nil 'non-key-event' property, then | ||
| 2370 | that binding is ignored by 'where-is-internal'. | ||
| 2371 | |||
| 2372 | +++ | ||
| 2367 | *** New functions for defining and manipulating keystrokes. | 2373 | *** New functions for defining and manipulating keystrokes. |
| 2368 | These all take the syntax defined by 'key-valid-p'. None of the older | 2374 | These all take the syntax defined by 'key-valid-p'. None of the older |
| 2369 | functions have been deprecated or altered, but they are now | 2375 | functions have been deprecated or altered, but they are now |
diff --git a/lisp/keymap.el b/lisp/keymap.el index 3a22610499c..ad7d4fbbba1 100644 --- a/lisp/keymap.el +++ b/lisp/keymap.el | |||
| @@ -575,6 +575,11 @@ as the variable documentation string. | |||
| 575 | (define-keymap ,@(nreverse opts) ,@defs) | 575 | (define-keymap ,@(nreverse opts) ,@defs) |
| 576 | ,@(and doc (list doc))))) | 576 | ,@(and doc (list doc))))) |
| 577 | 577 | ||
| 578 | (defun make-non-key-event (symbol) | ||
| 579 | "Mark SYMBOL as an event that shouldn't be returned from `where-is'." | ||
| 580 | (put symbol 'non-key-event t) | ||
| 581 | symbol) | ||
| 582 | |||
| 578 | (provide 'keymap) | 583 | (provide 'keymap) |
| 579 | 584 | ||
| 580 | ;;; keymap.el ends here | 585 | ;;; keymap.el ends here |
diff --git a/lisp/term/common-win.el b/lisp/term/common-win.el index 6f1e322aba5..f7faba9cb7c 100644 --- a/lisp/term/common-win.el +++ b/lisp/term/common-win.el | |||
| @@ -59,20 +59,19 @@ | |||
| 59 | (setq system-key-alist | 59 | (setq system-key-alist |
| 60 | (list | 60 | (list |
| 61 | ;; These are special "keys" used to pass events from C to lisp. | 61 | ;; These are special "keys" used to pass events from C to lisp. |
| 62 | (cons 1 'ns-power-off) | 62 | (cons 1 (make-non-key-event 'ns-power-off)) |
| 63 | (cons 2 'ns-open-file) | 63 | (cons 2 (make-non-key-event 'ns-open-file)) |
| 64 | (cons 3 'ns-open-temp-file) | 64 | (cons 3 (make-non-key-event 'ns-open-temp-file)) |
| 65 | (cons 4 'ns-drag-file) | 65 | (cons 4 (make-non-key-event 'ns-drag-file)) |
| 66 | (cons 5 'ns-drag-color) | 66 | (cons 5 (make-non-key-event 'ns-drag-color)) |
| 67 | (cons 6 'ns-drag-text) | 67 | (cons 6 (make-non-key-event 'ns-drag-text)) |
| 68 | (cons 8 'ns-open-file-line) | 68 | (cons 8 (make-non-key-event 'ns-open-file-line)) |
| 69 | ;;; (cons 9 'ns-insert-working-text) | 69 | ;;; (cons 9 (make-non-key-event 'ns-insert-working-text)) |
| 70 | ;;; (cons 10 'ns-delete-working-text) | 70 | ;;; (cons 10 (make-non-key-event 'ns-delete-working-text)) |
| 71 | (cons 11 'ns-spi-service-call) | 71 | (cons 11 (make-non-key-event 'ns-spi-service-call)) |
| 72 | (cons 12 'ns-new-frame) | 72 | (cons 12 (make-non-key-event 'ns-new-frame)) |
| 73 | (cons 13 'ns-toggle-toolbar) | 73 | (cons 13 (make-non-key-event 'ns-toggle-toolbar)) |
| 74 | (cons 14 'ns-show-prefs) | 74 | (cons 14 (make-non-key-event 'ns-show-prefs)))))) |
| 75 | )))) | ||
| 76 | (set-terminal-parameter frame 'x-setup-function-keys t))) | 75 | (set-terminal-parameter frame 'x-setup-function-keys t))) |
| 77 | 76 | ||
| 78 | (defvar x-invocation-args) | 77 | (defvar x-invocation-args) |
diff --git a/src/keymap.c b/src/keymap.c index c8b01eed6fd..2b77a7fc444 100644 --- a/src/keymap.c +++ b/src/keymap.c | |||
| @@ -2596,7 +2596,10 @@ The optional 5th arg NO-REMAP alters how command remapping is handled: | |||
| 2596 | 2596 | ||
| 2597 | - If DEFINITION is remapped to OTHER-COMMAND, normally return the | 2597 | - If DEFINITION is remapped to OTHER-COMMAND, normally return the |
| 2598 | bindings for OTHER-COMMAND. But if NO-REMAP is non-nil, return the | 2598 | bindings for OTHER-COMMAND. But if NO-REMAP is non-nil, return the |
| 2599 | bindings for DEFINITION instead, ignoring its remapping. */) | 2599 | bindings for DEFINITION instead, ignoring its remapping. |
| 2600 | |||
| 2601 | Keys that are represented as events that have a `non-key-event' non-nil | ||
| 2602 | symbol property are ignored. */) | ||
| 2600 | (Lisp_Object definition, Lisp_Object keymap, Lisp_Object firstonly, Lisp_Object noindirect, Lisp_Object no_remap) | 2603 | (Lisp_Object definition, Lisp_Object keymap, Lisp_Object firstonly, Lisp_Object noindirect, Lisp_Object no_remap) |
| 2601 | { | 2604 | { |
| 2602 | /* The keymaps in which to search. */ | 2605 | /* The keymaps in which to search. */ |
| @@ -2720,7 +2723,12 @@ The optional 5th arg NO-REMAP alters how command remapping is handled: | |||
| 2720 | 2723 | ||
| 2721 | /* It is a true unshadowed match. Record it, unless it's already | 2724 | /* It is a true unshadowed match. Record it, unless it's already |
| 2722 | been seen (as could happen when inheriting keymaps). */ | 2725 | been seen (as could happen when inheriting keymaps). */ |
| 2723 | if (NILP (Fmember (sequence, found))) | 2726 | if (NILP (Fmember (sequence, found)) |
| 2727 | /* Filter out non key events. */ | ||
| 2728 | && !(VECTORP (sequence) | ||
| 2729 | && ASIZE (sequence) == 1 | ||
| 2730 | && SYMBOLP (AREF (sequence, 0)) | ||
| 2731 | && !NILP (Fget (AREF (sequence, 0), Qnon_key_event)))) | ||
| 2724 | found = Fcons (sequence, found); | 2732 | found = Fcons (sequence, found); |
| 2725 | 2733 | ||
| 2726 | /* If firstonly is Qnon_ascii, then we can return the first | 2734 | /* If firstonly is Qnon_ascii, then we can return the first |
| @@ -3461,4 +3469,6 @@ that describe key bindings. That is why the default is nil. */); | |||
| 3461 | 3469 | ||
| 3462 | DEFSYM (Qkey_parse, "key-parse"); | 3470 | DEFSYM (Qkey_parse, "key-parse"); |
| 3463 | DEFSYM (Qkey_valid_p, "key-valid-p"); | 3471 | DEFSYM (Qkey_valid_p, "key-valid-p"); |
| 3472 | |||
| 3473 | DEFSYM (Qnon_key_event, "non-key-event"); | ||
| 3464 | } | 3474 | } |
diff --git a/test/src/keymap-tests.el b/test/src/keymap-tests.el index 69aa7238493..eeac1dbe6d1 100644 --- a/test/src/keymap-tests.el +++ b/test/src/keymap-tests.el | |||
| @@ -418,6 +418,16 @@ g .. h foo | |||
| 418 | (should-error (text-char-description ?\M-c)) | 418 | (should-error (text-char-description ?\M-c)) |
| 419 | (should-error (text-char-description ?\s-c))) | 419 | (should-error (text-char-description ?\s-c))) |
| 420 | 420 | ||
| 421 | (ert-deftest test-non-key-events () | ||
| 422 | (should (null (where-is-internal 'keymap-tests-command))) | ||
| 423 | (keymap-set global-map "C-c g" #'keymap-tests-command) | ||
| 424 | (should (equal (where-is-internal 'keymap-tests-command) '([3 103]))) | ||
| 425 | (keymap-set global-map "<keymap-tests-event>" #'keymap-tests-command) | ||
| 426 | (should (equal (where-is-internal 'keymap-tests-command) | ||
| 427 | '([keymap-tests-event] [3 103]))) | ||
| 428 | (make-non-key-event 'keymap-tests-event) | ||
| 429 | (should (equal (where-is-internal 'keymap-tests-command) '([3 103])))) | ||
| 430 | |||
| 421 | (provide 'keymap-tests) | 431 | (provide 'keymap-tests) |
| 422 | 432 | ||
| 423 | ;;; keymap-tests.el ends here | 433 | ;;; keymap-tests.el ends here |