comparison tests/automated/keymap-tests.el @ 5679:a81a739181dc

Add command remapping, a more robust alternative to #'substitute-key-definition src/ChangeLog addition: 2012-09-02 Aidan Kehoe <kehoea@parhasard.net> * keymap.c: Add command remapping, a more robust equivalent to #'substitute-key-definition. * keymap.c (CHECK_REMAPPING_POSITION): New. * keymap.c (keymap_equal): Correct a comment here. * keymap.c (Fdefine_key): Document the command remapping syntax. * keymap.c (Fremap_command): New. * keymap.c (command_remapping): New. * keymap.c (Fcommand_remapping): New. * keymap.c (commands_remapped_to_mapper): New. * keymap.c (commands_remapped_to_traverser): New. * keymap.c (Fcommands_remapped_to): New. * keymap.c (get_relevant_keymaps): Take a new POSITION argument. * keymap.c (Fcurrent_keymaps, event_binding): Supply the new POSITION argument to get_relevant_keymaps. * keymap.c (Fkey_binding): Add new arguments, NO-REMAP and POSITION. * keymap.c (map_keymap_mapper): * keymap.c (Fwhere_is_internal): * keymap.c (where_is_to_char): * keymap.c (where_is_recursive_mapper): Don't expose the key remapping in these functions. This conflicts with GNU, but is more sane for our callers. Access to command remapping is with the functions #'command-remapping, #'commands-remapped-to, and #'remap-command, not with the general keymap functions, apart from the compatibility hack in #'define-key. * keymap.c (syms_of_keymap): * keymap.c (vars_of_keymap): * keymap.c (complex_vars_of_keymap): * lisp.h: New CHECK_COMMAND macro. man/ChangeLog addition: 2012-09-02 Aidan Kehoe <kehoea@parhasard.net> * lispref/keymaps.texi (Keymaps): * lispref/keymaps.texi (Changing Key Bindings): * lispref/keymaps.texi (Scanning Keymaps): * lispref/keymaps.texi (Remapping commands): * lispref/keymaps.texi (XEmacs): New. * lispref/keymaps.texi (Other Keymap Functions): Document the new command remapping functionality in this file. lisp/ChangeLog addition: 2012-09-02 Aidan Kehoe <kehoea@parhasard.net> * help.el (describe-function-1): Document any command remapping that has been done in this function. tests/ChangeLog addition: 2012-09-02 Aidan Kehoe <kehoea@parhasard.net> * automated/keymap-tests.el: Test the new command remapping functionality.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 02 Sep 2012 14:31:40 +0100
parents
children cf0201de66df
comparison
equal deleted inserted replaced
5678:b0d40183ac79 5679:a81a739181dc
1 ;; Copyright (C) 2012 Free Software Foundation, Inc.
2
3 ;; Author: Aidan Kehoe <kehoea@parhasard.net>
4 ;; Maintainers: Aidan Kehoe <kehoea@parhasard.net>
5 ;; Created: 2012
6 ;; Keywords: tests
7
8 ;; This file is part of XEmacs.
9
10 ;; XEmacs is free software: you can redistribute it and/or modify it
11 ;; under the terms of the GNU General Public License as published by the
12 ;; Free Software Foundation, either version 3 of the License, or (at your
13 ;; option) any later version.
14
15 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT
16 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 ;; for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Synched up with: Not in FSF.
24
25 (let* ((map (make-keymap 'help-map-copy))
26 (parent-map (make-keymap 'help-map-copy-parent))
27 (help-map-copy t)
28 (minor-mode-map-alist (acons 'help-map-copy map minor-mode-map-alist)))
29 (set-keymap-parent map parent-map)
30 (loop for (keys def) on '((shift tab) help-prev-symbol tab
31 help-next-symbol c customize-variable V
32 find-variable-at-point q
33 help-mode-quit f find-function-at-point d
34 describe-function-at-point v
35 describe-variable-at-point i Info-elisp-ref F
36 find-function-at-point Q help-mode-bury button2
37 help-mouse-find-source-or-track p
38 help-prev-section n help-next-section return
39 help-find-source-or-scroll-up)
40 by #'cddr
41 do (define-key map (vector keys) def))
42 (loop for (keys def) on '(u view-scroll-some-lines-down % view-goto-percent
43 \2 digit-argument p view-goto-percent \?
44 view-search-backward - negative-argument k
45 view-scroll-lines-down backspace scroll-down G
46 view-last-windowful f scroll-up \5
47 digit-argument s view-repeat-search \0
48 digit-argument n view-repeat-search = what-line
49 \\ view-search-backward delete scroll-down \8
50 digit-argument E view-file d
51 view-scroll-some-lines-up \3 digit-argument q
52 view-quit ! shell-command (control j)
53 view-scroll-lines-up (control m)
54 view-scroll-lines-up y view-scroll-lines-down
55 linefeed view-scroll-lines-up g view-goto-line
56 \6 digit-argument t toggle-truncate-lines C
57 view-cleanup-backspaces b scroll-down \1
58 digit-argument P view-buffer return
59 view-scroll-lines-up | shell-command-on-region j
60 view-scroll-lines-up \9 digit-argument \'
61 register-to-point e view-scroll-lines-up \4
62 digit-argument r recenter space scroll-up /
63 view-search-forward N view-buffer m
64 point-to-register h view-mode-describe \7
65 digit-argument
66 find-function-at-point view-mode-describe)
67 by #'cddr
68 do (define-key parent-map (vector keys) def))
69 (Assert (eq (key-binding [F]) 'find-function-at-point)
70 "checking normal key lookup works, F")
71 (Assert (eq (key-binding [c]) 'customize-variable)
72 "checking normal key lookup works, c")
73 (Assert (eq (key-binding [\2]) 'digit-argument)
74 "checking normal key parent lookup works, \\2")
75 (Assert (eq (key-binding [|]) 'shell-command-on-region)
76 "checking normal key parent lookup works, |")
77 (define-key map [remap find-function-at-point] #'find-file)
78 (Assert (eq (key-binding [F]) 'find-file)
79 "checking remapped key lookup works, F")
80 (Assert (eq (key-binding [f]) 'find-file)
81 "checking remapped key lookup works, f")
82 (Assert (eq (key-binding [\2]) 'digit-argument)
83 "checking normal key parent lookup works, \\2")
84 (Assert (eq (key-binding [|]) 'shell-command-on-region)
85 "checking normal key parent lookup works, |")
86 (Assert (eq (key-binding [find-function-at-point]) 'view-mode-describe)
87 "checking remapped function doesn't affect key name mapping")
88 (define-key parent-map [remap help-next-symbol] #'find-file)
89 (Assert (eq (key-binding [tab]) 'find-file)
90 "checking remapping in parent extends to child")
91 (Assert (equal (commands-remapped-to 'find-file)
92 '(help-next-symbol find-function-at-point))
93 "checking #'commands-remapped-to is sane")
94 (Check-Error wrong-type-argument (commands-remapped-to pi))
95 (Check-Error wrong-type-argument (commands-remapped-to 'find-file pi))
96 (Check-Error wrong-type-argument (commands-remapped-to 'find-file nil pi))
97 (Assert (eq (command-remapping 'find-function-at-point) 'find-file)
98 "checking #'command-remapping is sane")
99 (Check-Error wrong-type-argument (command-remapping pi))
100 (Check-Error wrong-type-argument (command-remapping 'find-function-at-point
101 pi))
102 (Check-Error wrong-type-argument (command-remapping 'find-function-at-point
103 nil pi)))
104