10789
|
1 ;;; viper-keym.el -- Main Viper keymaps
|
|
2
|
11288
|
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
|
|
4
|
10789
|
5 ;; This file is part of GNU Emacs.
|
|
6
|
|
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
8 ;; it under the terms of the GNU General Public License as published by
|
|
9 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
10 ;; any later version.
|
|
11
|
|
12 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 ;; GNU General Public License for more details.
|
|
16
|
|
17 ;; You should have received a copy of the GNU General Public License
|
|
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
|
|
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
20
|
|
21
|
|
22 (require 'viper-util)
|
|
23
|
|
24 ;;; Variables
|
|
25
|
|
26 ;;; Keymaps
|
|
27
|
|
28 ;; Keymaps for vital things like \e and C-z.
|
|
29 ;; Not for users
|
|
30 (defvar vip-vi-intercept-map (make-sparse-keymap))
|
|
31 (defvar vip-insert-intercept-map (make-sparse-keymap))
|
|
32 (defvar vip-emacs-intercept-map (make-sparse-keymap))
|
|
33
|
|
34 (vip-deflocalvar vip-vi-local-user-map (make-sparse-keymap)
|
|
35 "Keymap for user-defined local bindings.
|
|
36 Useful for changing bindings such as ZZ in certain major modes.
|
|
37 For instance, in letter-mode, one may want to bind ZZ to
|
|
38 mh-send-letter. In a newsreader such as gnus, tin, or rn, ZZ could be bound
|
|
39 to save-buffers-kill-emacs then post article, etc.")
|
|
40 (put 'vip-vi-local-user-map 'permanent-local t)
|
|
41
|
|
42 (defvar vip-vi-global-user-map (make-sparse-keymap)
|
|
43 "Keymap for user-defined global bindings.
|
|
44 These bindings are seen in all Viper buffers.")
|
|
45
|
|
46 (defvar vip-vi-basic-map (make-keymap)
|
|
47 "This is the main keymap in effect in Viper's Vi state.
|
|
48 This map is global, shared by all buffers.")
|
|
49
|
|
50 (defvar vip-vi-kbd-map (make-sparse-keymap)
|
|
51 "This keymap keeps keyboard macros defined via the :map command.")
|
|
52
|
|
53 (defvar vip-vi-diehard-map (make-sparse-keymap)
|
|
54 "This keymap is in use when the user asks Viper to simulate Vi very closely.
|
|
55 This happens when vip-expert-level is 1 or 2. See vip-set-expert-level.")
|
|
56
|
|
57
|
|
58 (vip-deflocalvar vip-insert-local-user-map (make-sparse-keymap)
|
|
59 "Auxiliary map for per-buffer user-defined keybindings in Insert state.")
|
|
60 (put 'vip-insert-local-user-map 'permanent-local t)
|
|
61
|
|
62 (defvar vip-insert-global-user-map (make-sparse-keymap)
|
|
63 "Auxiliary map for global user-defined bindings in Insert state.")
|
|
64
|
|
65 (defvar vip-insert-basic-map (make-sparse-keymap)
|
|
66 "The basic insert-mode keymap.")
|
|
67
|
|
68 (defvar vip-insert-diehard-map (make-keymap)
|
|
69 "Map used when user wants vi-style keys in insert mode.
|
|
70 Most of the Emacs keys are suppressed. This map overshadows
|
|
71 vip-insert-basic-map. Not recommended, except for novice users.")
|
|
72
|
|
73 (defvar vip-insert-kbd-map (make-sparse-keymap)
|
|
74 "This keymap keeps VI-style kbd macros for insert mode.")
|
|
75
|
|
76 (defvar vip-replace-map (make-sparse-keymap)
|
|
77 "Map used in Viper's replace state.")
|
|
78
|
|
79 (defvar vip-emacs-global-user-map (make-sparse-keymap)
|
|
80 "Auxiliary map for global user-defined bindings in Emacs state.")
|
|
81
|
|
82 (defvar vip-emacs-kbd-map (make-sparse-keymap)
|
|
83 "This keymap keeps Vi-style kbd macros for emacs mode.")
|
|
84
|
|
85 (vip-deflocalvar vip-emacs-local-user-map (make-sparse-keymap)
|
|
86 "Auxiliary map for local user-defined bindings in Emacs state.")
|
|
87 (put 'vip-emacs-local-user-map 'permanent-local t)
|
|
88
|
|
89 ;; This keymap should stay empty
|
|
90 (defvar vip-empty-keymap (make-sparse-keymap))
|
|
91
|
|
92
|
|
93 ;;; Variables used by minor modes
|
|
94
|
|
95 ;; Association list of the form
|
|
96 ;; ((major-mode . keymap) (major-mode . keymap) ...)
|
|
97 ;; Viper uses these keymaps to make user-requested adjustments
|
|
98 ;; to its Vi state in various major modes.")
|
|
99 (defvar vip-vi-state-modifier-alist nil)
|
|
100
|
|
101 ;; Association list of the form
|
|
102 ;; ((major-mode . keymap) (major-mode . keymap) ...)
|
|
103 ;; Viper uses these keymaps to make user-requested adjustments
|
|
104 ;; to its Insert state in various major modes.")
|
|
105 (defvar vip-insert-state-modifier-alist nil)
|
|
106
|
|
107 ;; Association list of the form
|
|
108 ;; ((major-mode . keymap) (major-mode . keymap) ...)
|
|
109 ;; Viper uses these keymaps to make user-requested adjustments
|
|
110 ;; to its Emacs state in various major modes.
|
|
111 (defvar vip-emacs-state-modifier-alist nil)
|
|
112
|
|
113 ;; Tells vip-add-local-keys to create a new vip-vi-local-user-map for new
|
|
114 ;; buffers. Not a user option.
|
|
115 (vip-deflocalvar vip-need-new-vi-local-map t "")
|
|
116 (put 'vip-need-new-vi-local-map 'permanent-local t)
|
|
117
|
|
118 ;; Tells vip-add-local-keys to create a new vip-insert-local-user-map for new
|
|
119 ;; buffers. Not a user option.
|
|
120 (vip-deflocalvar vip-need-new-insert-local-map t "")
|
|
121 (put 'vip-need-new-insert-local-map 'permanent-local t)
|
|
122
|
|
123 ;; Tells vip-add-local-keys to create a new vip-emacs-local-user-map for new
|
|
124 ;; buffers. Not a user option.
|
|
125 (vip-deflocalvar vip-need-new-emacs-local-map t "")
|
|
126 (put 'vip-need-new-emacs-local-map 'permanent-local t)
|
|
127
|
|
128
|
|
129
|
|
130 ;; Insert mode keymap
|
|
131
|
|
132 ;; for novice users, pretend you are the real vi.
|
|
133 (define-key vip-insert-diehard-map "\t" 'vip-insert-tab)
|
|
134 (define-key vip-insert-diehard-map "\C-a" 'self-insert-command)
|
|
135 (define-key vip-insert-diehard-map "\C-b" 'self-insert-command)
|
|
136 (define-key vip-insert-diehard-map "\C-c" 'vip-change-state-to-vi)
|
|
137 (define-key vip-insert-diehard-map "\C-e" 'self-insert-command)
|
|
138 (define-key vip-insert-diehard-map "\C-f" 'self-insert-command)
|
|
139 (define-key vip-insert-diehard-map "\C-g" 'self-insert-command)
|
|
140 (define-key vip-insert-diehard-map "\C-i" 'self-insert-command)
|
|
141 (define-key vip-insert-diehard-map "\C-k" 'self-insert-command)
|
|
142 (define-key vip-insert-diehard-map "\C-l" 'self-insert-command)
|
|
143 (define-key vip-insert-diehard-map "\C-n" 'self-insert-command)
|
|
144 (define-key vip-insert-diehard-map "\C-o" 'self-insert-command)
|
|
145 (define-key vip-insert-diehard-map "\C-p" 'self-insert-command)
|
|
146 (define-key vip-insert-diehard-map "\C-q" 'self-insert-command)
|
|
147 (define-key vip-insert-diehard-map "\C-r" 'self-insert-command)
|
|
148 (define-key vip-insert-diehard-map "\C-s" 'self-insert-command)
|
|
149 (define-key vip-insert-diehard-map "\C-u" 'vip-erase-line)
|
|
150 (define-key vip-insert-diehard-map "\C-x" 'self-insert-command)
|
|
151 (define-key vip-insert-diehard-map "\C-y" 'self-insert-command)
|
|
152 (define-key vip-insert-diehard-map "\C-z" 'self-insert-command)
|
|
153 (define-key vip-insert-diehard-map "\C-]" 'self-insert-command)
|
|
154 (define-key vip-insert-diehard-map "\C-_" 'self-insert-command)
|
|
155
|
|
156 (let ((i ?\ ))
|
|
157 (while (<= i ?~)
|
|
158 (define-key vip-insert-diehard-map (make-string 1 i) 'self-insert-command)
|
|
159 (setq i (1+ i))))
|
|
160
|
|
161 ;; Insert mode map when user wants emacs style
|
|
162 (define-key vip-insert-basic-map "\C-d" 'vip-backward-indent)
|
|
163 (define-key vip-insert-basic-map "\C-w" 'vip-delete-backward-word)
|
|
164 (define-key vip-insert-basic-map "\C-t" 'vip-forward-indent)
|
|
165 (define-key vip-insert-basic-map
|
|
166 (if vip-xemacs-p [(shift tab)] [S-tab]) 'vip-insert-tab)
|
|
167 (define-key vip-insert-basic-map "\C-v" 'quoted-insert)
|
|
168 (define-key vip-insert-basic-map "\C-?" 'vip-del-backward-char-in-insert)
|
|
169 (define-key vip-insert-basic-map "\C-c\M-p"
|
|
170 'vip-insert-prev-from-insertion-ring)
|
|
171 (define-key vip-insert-basic-map "\C-c\M-n"
|
|
172 'vip-insert-next-from-insertion-ring)
|
|
173
|
|
174
|
|
175 ;; Replace keymap
|
|
176 (define-key vip-replace-map "\C-t" 'vip-forward-indent)
|
|
177 (define-key vip-replace-map "\C-j" 'vip-replace-state-exit-cmd)
|
|
178 (define-key vip-replace-map "\C-m" 'vip-replace-state-exit-cmd)
|
|
179 (define-key vip-replace-map "\C-?" 'vip-del-backward-char-in-replace)
|
|
180
|
|
181
|
|
182
|
|
183 ;; Vi keymaps
|
|
184
|
|
185 (define-key vip-vi-basic-map "\C-^"
|
|
186 (function (lambda () (interactive) (vip-ex "e#"))))
|
|
187 (define-key vip-vi-basic-map "\C-b" 'vip-scroll-back)
|
|
188 (define-key vip-vi-basic-map "\C-d" 'vip-scroll-up)
|
|
189 (define-key vip-vi-basic-map "\C-e" 'vip-scroll-up-one)
|
|
190 (define-key vip-vi-basic-map "\C-f" 'vip-scroll)
|
|
191 (define-key vip-vi-basic-map "\C-m" 'vip-next-line-at-bol)
|
|
192 (define-key vip-vi-basic-map "\C-u" 'vip-scroll-down)
|
|
193 (define-key vip-vi-basic-map "\C-y" 'vip-scroll-down-one)
|
|
194 (define-key vip-vi-basic-map "\C-s" 'vip-isearch-forward)
|
|
195 (define-key vip-vi-basic-map "\C-r" 'vip-isearch-backward)
|
|
196 ;(define-key vip-vi-basic-map "\C-\\" 'universal-argument)
|
|
197 (define-key vip-vi-basic-map "\C-c/" 'vip-toggle-search-style)
|
|
198 (define-key vip-vi-basic-map "\C-cg" 'vip-info-on-file)
|
|
199
|
|
200 (define-key vip-vi-basic-map "\C-c\M-p" 'vip-prev-destructive-command)
|
|
201 (define-key vip-vi-basic-map "\C-c\M-n" 'vip-next-destructive-command)
|
|
202
|
|
203
|
|
204 (define-key vip-vi-basic-map " " 'vip-forward-char)
|
|
205 (define-key vip-vi-basic-map "!" 'vip-command-argument)
|
|
206 (define-key vip-vi-basic-map "\"" 'vip-command-argument)
|
|
207 (define-key vip-vi-basic-map "#" 'vip-command-argument)
|
|
208 (define-key vip-vi-basic-map "$" 'vip-goto-eol)
|
|
209 (define-key vip-vi-basic-map "%" 'vip-paren-match)
|
|
210 (define-key vip-vi-basic-map "&"
|
|
211 (function (lambda () (interactive) (vip-ex "&"))))
|
|
212 (define-key vip-vi-basic-map "'" 'vip-goto-mark-and-skip-white)
|
|
213 (define-key vip-vi-basic-map "(" 'vip-backward-sentence)
|
|
214 (define-key vip-vi-basic-map ")" 'vip-forward-sentence)
|
|
215 (define-key vip-vi-basic-map "*" 'call-last-kbd-macro)
|
|
216 (define-key vip-vi-basic-map "+" 'vip-next-line-at-bol)
|
|
217 (define-key vip-vi-basic-map "," 'vip-repeat-find-opposite)
|
|
218 (define-key vip-vi-basic-map "-" 'vip-previous-line-at-bol)
|
|
219 (define-key vip-vi-basic-map "." 'vip-repeat)
|
|
220 (define-key vip-vi-basic-map "/" 'vip-search-forward)
|
|
221
|
|
222 (define-key vip-vi-basic-map "0" 'vip-beginning-of-line)
|
|
223 (define-key vip-vi-basic-map "1" 'vip-digit-argument)
|
|
224 (define-key vip-vi-basic-map "2" 'vip-digit-argument)
|
|
225 (define-key vip-vi-basic-map "3" 'vip-digit-argument)
|
|
226 (define-key vip-vi-basic-map "4" 'vip-digit-argument)
|
|
227 (define-key vip-vi-basic-map "5" 'vip-digit-argument)
|
|
228 (define-key vip-vi-basic-map "6" 'vip-digit-argument)
|
|
229 (define-key vip-vi-basic-map "7" 'vip-digit-argument)
|
|
230 (define-key vip-vi-basic-map "8" 'vip-digit-argument)
|
|
231 (define-key vip-vi-basic-map "9" 'vip-digit-argument)
|
|
232
|
|
233 (define-key vip-vi-basic-map ":" 'vip-ex)
|
|
234 (define-key vip-vi-basic-map ";" 'vip-repeat-find)
|
|
235 (define-key vip-vi-basic-map "<" 'vip-command-argument)
|
|
236 (define-key vip-vi-basic-map "=" 'vip-command-argument)
|
|
237 (define-key vip-vi-basic-map ">" 'vip-command-argument)
|
|
238 (define-key vip-vi-basic-map "?" 'vip-search-backward)
|
|
239 (define-key vip-vi-basic-map "@" 'vip-register-macro)
|
|
240
|
|
241 (define-key vip-vi-basic-map "A" 'vip-Append)
|
|
242 (define-key vip-vi-basic-map "B" 'vip-backward-Word)
|
|
243 (define-key vip-vi-basic-map "C" 'vip-change-to-eol)
|
|
244 (define-key vip-vi-basic-map "D" 'vip-kill-line)
|
|
245 (define-key vip-vi-basic-map "E" 'vip-end-of-Word)
|
|
246 (define-key vip-vi-basic-map "F" 'vip-find-char-backward)
|
|
247 (define-key vip-vi-basic-map "G" 'vip-goto-line)
|
|
248 (define-key vip-vi-basic-map "H" 'vip-window-top)
|
|
249 (define-key vip-vi-basic-map "I" 'vip-Insert)
|
|
250 (define-key vip-vi-basic-map "J" 'vip-join-lines)
|
|
251 (define-key vip-vi-basic-map "K" 'vip-nil)
|
|
252 (define-key vip-vi-basic-map "L" 'vip-window-bottom)
|
|
253 (define-key vip-vi-basic-map "M" 'vip-window-middle)
|
|
254 (define-key vip-vi-basic-map "N" 'vip-search-Next)
|
|
255 (define-key vip-vi-basic-map "O" 'vip-Open-line)
|
|
256 (define-key vip-vi-basic-map "P" 'vip-Put-back)
|
|
257 (define-key vip-vi-basic-map "Q" 'vip-query-replace)
|
|
258 (define-key vip-vi-basic-map "R" 'vip-overwrite)
|
|
259 (define-key vip-vi-basic-map "S" 'vip-substitute-line)
|
|
260 (define-key vip-vi-basic-map "T" 'vip-goto-char-backward)
|
|
261 (define-key vip-vi-basic-map "U" 'vip-undo)
|
|
262 (define-key vip-vi-basic-map "V" 'find-file-other-window)
|
|
263 (define-key vip-vi-basic-map "W" 'vip-forward-Word)
|
|
264 (define-key vip-vi-basic-map "X" 'vip-delete-backward-char)
|
|
265 (define-key vip-vi-basic-map "Y" 'vip-yank-line)
|
|
266 (define-key vip-vi-basic-map "ZZ" 'vip-save-kill-buffer)
|
|
267
|
|
268 (define-key vip-vi-basic-map "\\" 'vip-escape-to-emacs)
|
|
269 (define-key vip-vi-basic-map "[" 'vip-brac-function)
|
|
270 (define-key vip-vi-basic-map "]" 'vip-ket-function)
|
|
271 (define-key vip-vi-basic-map "_" 'vip-alternate-ESC)
|
|
272 (define-key vip-vi-basic-map "^" 'vip-bol-and-skip-white)
|
|
273 (define-key vip-vi-basic-map "`" 'vip-goto-mark)
|
|
274
|
|
275 (define-key vip-vi-basic-map "a" 'vip-append)
|
|
276 (define-key vip-vi-basic-map "b" 'vip-backward-word)
|
|
277 (define-key vip-vi-basic-map "c" 'vip-command-argument)
|
|
278 (define-key vip-vi-basic-map "d" 'vip-command-argument)
|
|
279 (define-key vip-vi-basic-map "e" 'vip-end-of-word)
|
|
280 (define-key vip-vi-basic-map "f" 'vip-find-char-forward)
|
|
281 (define-key vip-vi-basic-map "g" 'vip-nil)
|
|
282 (define-key vip-vi-basic-map "h" 'vip-backward-char)
|
|
283 (define-key vip-vi-basic-map "i" 'vip-insert)
|
|
284 (define-key vip-vi-basic-map "j" 'vip-next-line)
|
|
285 (define-key vip-vi-basic-map "k" 'vip-previous-line)
|
|
286 (define-key vip-vi-basic-map "l" 'vip-forward-char)
|
|
287 (define-key vip-vi-basic-map "m" 'vip-mark-point)
|
|
288 (define-key vip-vi-basic-map "n" 'vip-search-next)
|
|
289 (define-key vip-vi-basic-map "o" 'vip-open-line)
|
|
290 (define-key vip-vi-basic-map "p" 'vip-put-back)
|
|
291 (define-key vip-vi-basic-map "q" 'vip-nil)
|
|
292 (define-key vip-vi-basic-map "r" 'vip-replace-char)
|
|
293 (define-key vip-vi-basic-map "s" 'vip-substitute)
|
|
294 (define-key vip-vi-basic-map "t" 'vip-goto-char-forward)
|
|
295 (define-key vip-vi-basic-map "u" 'vip-undo)
|
|
296 (define-key vip-vi-basic-map "v" 'find-file)
|
|
297 (define-key vip-vi-basic-map "\C-v" 'vip-find-file-other-frame)
|
|
298 (define-key vip-vi-basic-map "w" 'vip-forward-word)
|
|
299 (define-key vip-vi-basic-map "x" 'vip-delete-char)
|
|
300 (define-key vip-vi-basic-map "y" 'vip-command-argument)
|
|
301 (define-key vip-vi-basic-map "zH" 'vip-line-to-top)
|
|
302 (define-key vip-vi-basic-map "zM" 'vip-line-to-middle)
|
|
303 (define-key vip-vi-basic-map "zL" 'vip-line-to-bottom)
|
|
304 (define-key vip-vi-basic-map "z\C-m" 'vip-line-to-top)
|
|
305 (define-key vip-vi-basic-map "z." 'vip-line-to-middle)
|
|
306 (define-key vip-vi-basic-map "z-" 'vip-line-to-bottom)
|
|
307
|
|
308 (define-key vip-vi-basic-map "{" 'vip-backward-paragraph)
|
|
309 (define-key vip-vi-basic-map "|" 'vip-goto-col)
|
|
310 (define-key vip-vi-basic-map "}" 'vip-forward-paragraph)
|
|
311 (define-key vip-vi-basic-map "~" 'vip-toggle-case)
|
|
312 (define-key vip-vi-basic-map "\C-?" 'vip-backward-char)
|
|
313
|
|
314 ;;; Escape from Emacs to Vi for one command
|
|
315 (global-set-key "\M-\C-z" 'vip-escape-to-vi) ;; in emacs-state
|
|
316
|
|
317 ;;; This is vip-vi-diehard-map. Used when vip-vi-diehard-minor-mode is on.
|
|
318
|
|
319 (define-key vip-vi-diehard-map "\C-a" 'vip-nil)
|
|
320 (define-key vip-vi-diehard-map "\C-c" 'vip-nil)
|
|
321 (define-key vip-vi-diehard-map "\C-g" 'vip-info-on-file)
|
|
322 (define-key vip-vi-diehard-map "\C-i" 'vip-nil)
|
|
323 (define-key vip-vi-diehard-map "\C-k" 'vip-nil)
|
|
324 (define-key vip-vi-diehard-map "\C-l" 'redraw-display)
|
|
325 (define-key vip-vi-diehard-map "\C-n" 'vip-next-line)
|
|
326 (define-key vip-vi-diehard-map "\C-o" 'vip-nil)
|
|
327 (define-key vip-vi-diehard-map "\C-p" 'vip-previous-line)
|
|
328 (define-key vip-vi-diehard-map "\C-q" 'vip-nil)
|
|
329 (define-key vip-vi-diehard-map "\C-r" 'redraw-display)
|
|
330 (define-key vip-vi-diehard-map "\C-s" 'vip-nil)
|
|
331 (define-key vip-vi-diehard-map "\C-t" 'vip-nil)
|
|
332 (define-key vip-vi-diehard-map "\C-v" 'vip-nil)
|
|
333 (define-key vip-vi-diehard-map "\C-w" 'vip-nil)
|
|
334 (define-key vip-vi-diehard-map "@" 'vip-nil)
|
|
335 (define-key vip-vi-diehard-map "*" 'vip-nil)
|
|
336 (define-key vip-vi-diehard-map "#" 'vip-nil)
|
|
337 (define-key vip-vi-diehard-map "\C-_" 'vip-nil)
|
|
338 (define-key vip-vi-diehard-map "\C-]" 'vip-nil);; This is actually tags.
|
|
339
|
|
340
|
|
341 ;;; Minibuffer keymap
|
|
342
|
|
343
|
|
344 (defvar vip-minibuffer-map (make-sparse-keymap)
|
|
345 "Keymap used to modify keys when Minibuffer is in Insert state.")
|
|
346
|
|
347 (define-key vip-minibuffer-map "\C-m" 'vip-exit-minibuffer)
|
|
348 (define-key vip-minibuffer-map "\C-j" 'vip-exit-minibuffer)
|
|
349
|
|
350 ;; Map used to read Ex-style commands.
|
|
351 (defvar vip-ex-cmd-map (make-sparse-keymap))
|
|
352 (define-key vip-ex-cmd-map " " 'ex-cmd-read-exit)
|
|
353 (define-key vip-ex-cmd-map "\t" 'ex-cmd-complete)
|
|
354
|
|
355 ;; Keymap for reading file names in Ex-style commands.
|
|
356 (defvar ex-read-filename-map (make-sparse-keymap))
|
|
357 (define-key ex-read-filename-map " " 'vip-complete-filename-or-exit)
|
|
358
|
|
359
|
|
360
|
|
361
|
|
362 ;;; Code
|
|
363
|
|
364 (defun vip-add-local-keys (state alist)
|
|
365 "Override some vi-state or insert-state bindings in the current buffer.
|
|
366 The effect is seen in the current buffer only.
|
|
367 Useful for customizing mailer buffers, gnus, etc.
|
|
368 STATE is 'vi-state, 'insert-state, or 'emacs-state
|
|
369 ALIST is of the form ((key . func) (key . func) ...)
|
|
370 Normally, this would be called from a hook to a major mode or
|
|
371 on a per buffer basis.
|
|
372 Usage:
|
|
373 (vip-add-local-keys state '((key-str . func) (key-str . func)...)) "
|
|
374
|
|
375 (let (map)
|
|
376 (cond ((eq state 'vi-state)
|
|
377 (if vip-need-new-vi-local-map
|
|
378 (setq vip-vi-local-user-map (make-sparse-keymap)))
|
|
379 (setq vip-need-new-vi-local-map nil
|
|
380 map vip-vi-local-user-map))
|
|
381 ((eq state 'insert-state)
|
|
382 (if vip-need-new-insert-local-map
|
|
383 (setq vip-insert-local-user-map (make-sparse-keymap)))
|
|
384 (setq vip-need-new-insert-local-map nil
|
|
385 map vip-insert-local-user-map))
|
|
386 ((eq state 'emacs-state)
|
|
387 (if vip-need-new-emacs-local-map
|
|
388 (setq vip-emacs-local-user-map (make-sparse-keymap)))
|
|
389 (setq vip-need-new-emacs-local-map nil
|
|
390 map vip-emacs-local-user-map))
|
|
391 (t
|
|
392 (error
|
|
393 "Invalid state in vip-add-local-keys: %S. Valid states: vi-state, insert-state or emacs-state" state)))
|
|
394
|
|
395 (vip-modify-keymap map alist)
|
|
396 (vip-normalize-minor-mode-map-alist)
|
|
397 (vip-set-mode-vars-for vip-current-state)))
|
|
398
|
|
399
|
|
400 (defun vip-modify-major-mode (mode state keymap)
|
|
401 "Modify key bindings in a major-mode in a Viper state using a keymap.
|
|
402
|
|
403 If the default for a major mode is emacs-state, then modifications to this
|
|
404 major mode may not take effect until the buffer switches state to Vi,
|
|
405 Insert or Emacs. If this happens, add vip-change-state-to-emacs to this
|
|
406 major mode's hook. If no such hook exists, you may have to put an advice on
|
|
407 the function that invokes the major mode. See vip-set-hooks for hints.
|
|
408
|
|
409 The above needs not to be done for major modes that come up in Vi or Insert
|
|
410 state by default.
|
|
411
|
|
412 Arguments: (major-mode vip-state keymap)"
|
|
413 (let ((alist
|
|
414 (cond ((eq state 'vi-state) 'vip-vi-state-modifier-alist)
|
|
415 ((eq state 'insert-state) 'vip-insert-state-modifier-alist)
|
|
416 ((eq state 'emacs-state) 'vip-emacs-state-modifier-alist)))
|
|
417 elt)
|
|
418 (if (setq elt (assoc mode (eval alist)))
|
|
419 (set alist (delq elt (eval alist))))
|
|
420 (set alist (cons (cons mode keymap) (eval alist)))
|
|
421
|
|
422 ;; Normalization usually doesn't help here, since one needs to
|
|
423 ;; normalize in the actual buffer where changes to the keymap are
|
|
424 ;; to take place. However, it doesn't hurt, and it helps whenever this
|
|
425 ;; function is actually called from within the right buffer.
|
|
426 (vip-normalize-minor-mode-map-alist)
|
|
427
|
|
428 (vip-set-mode-vars-for vip-current-state)))
|
|
429
|
|
430
|
|
431 (defun vip-debug-keymaps ()
|
|
432 "Displays variables that control Viper's keymaps."
|
|
433 (interactive)
|
|
434 (with-output-to-temp-buffer " *vip-debug*"
|
|
435 (princ (format "Buffer name: %s\n\n" (buffer-name)))
|
|
436 (princ "Variables: \n")
|
|
437 (princ (format "major-mode: %S\n" major-mode))
|
|
438 (princ (format "vip-current-state: %S\n" vip-current-state))
|
|
439 (princ (format "vip-mode-string: %S\n\n" vip-mode-string))
|
|
440 (princ (format "vip-vi-intercept-minor-mode: %S\n"
|
|
441 vip-vi-intercept-minor-mode))
|
|
442 (princ (format "vip-insert-intercept-minor-mode: %S\n"
|
|
443 vip-insert-intercept-minor-mode))
|
|
444 (princ (format "vip-emacs-intercept-minor-mode: %S\n"
|
|
445 vip-emacs-intercept-minor-mode))
|
|
446 (princ (format "vip-vi-minibuffer-minor-mode: %S\n"
|
|
447 vip-vi-minibuffer-minor-mode))
|
|
448 (princ (format "vip-insert-minibuffer-minor-mode: %S\n\n"
|
|
449 vip-insert-minibuffer-minor-mode))
|
|
450 (princ (format "vip-vi-local-user-minor-mode: %S\n"
|
|
451 vip-vi-local-user-minor-mode))
|
|
452 (princ (format "vip-vi-global-user-minor-mode: %S\n"
|
|
453 vip-vi-global-user-minor-mode))
|
|
454 (princ (format "vip-vi-kbd-minor-mode: %S\n" vip-vi-kbd-minor-mode))
|
|
455 (princ (format "vip-vi-state-modifier-minor-mode: %S\n"
|
|
456 vip-vi-state-modifier-minor-mode))
|
|
457 (princ (format "vip-vi-diehard-minor-mode: %S\n"
|
|
458 vip-vi-diehard-minor-mode))
|
|
459 (princ (format "vip-vi-basic-minor-mode: %S\n" vip-vi-basic-minor-mode))
|
|
460 (princ (format "vip-replace-minor-mode: %S\n" vip-replace-minor-mode))
|
|
461 (princ (format "vip-insert-local-user-minor-mode: %S\n"
|
|
462 vip-insert-local-user-minor-mode))
|
|
463 (princ (format "vip-insert-global-user-minor-mode: %S\n"
|
|
464 vip-insert-global-user-minor-mode))
|
|
465 (princ (format "vip-insert-kbd-minor-mode: %S\n"
|
|
466 vip-insert-kbd-minor-mode))
|
|
467 (princ (format "vip-insert-state-modifier-minor-mode: %S\n"
|
|
468 vip-insert-state-modifier-minor-mode))
|
|
469 (princ (format "vip-insert-diehard-minor-mode: %S\n"
|
|
470 vip-insert-diehard-minor-mode))
|
|
471 (princ (format "vip-insert-basic-minor-mode: %S\n"
|
|
472 vip-insert-basic-minor-mode))
|
|
473 (princ (format "vip-emacs-local-user-minor-mode: %S\n"
|
|
474 vip-emacs-local-user-minor-mode))
|
|
475 (princ (format "vip-emacs-kbd-minor-mode: %S\n"
|
|
476 vip-emacs-kbd-minor-mode))
|
|
477 (princ (format "vip-emacs-global-user-minor-mode: %S\n"
|
|
478 vip-emacs-global-user-minor-mode))
|
|
479 (princ (format "vip-emacs-state-modifier-minor-mode: %S\n"
|
|
480 vip-emacs-state-modifier-minor-mode))
|
|
481
|
|
482 (princ (format "\nvip-expert-level %S\n" vip-expert-level))
|
|
483 (princ (format "vip-no-multiple-ESC %S\n" vip-no-multiple-ESC))
|
|
484 (princ (format "vip-always %S\n" vip-always))
|
|
485 (princ (format "vip-ex-style-motion %S\n"
|
|
486 vip-ex-style-motion))
|
|
487 (princ (format "vip-ex-style-editing-in-insert %S\n"
|
|
488 vip-ex-style-editing-in-insert))
|
|
489 (princ (format "vip-want-emacs-keys-in-vi %S\n"
|
|
490 vip-want-emacs-keys-in-vi))
|
|
491 (princ (format "vip-want-emacs-keys-in-insert %S\n"
|
|
492 vip-want-emacs-keys-in-insert))
|
|
493 (princ (format "vip-want-ctl-h-help %S\n" vip-want-ctl-h-help))
|
|
494
|
|
495 (princ "\n\n\n")
|
|
496 (princ (format "Default value for minor-mode-map-alist: \n%S\n\n"
|
|
497 (default-value 'minor-mode-map-alist)))
|
|
498 (princ (format "Actual value for minor-mode-map-alist: \n%S\n"
|
|
499 minor-mode-map-alist))
|
|
500 ))
|
|
501
|
|
502
|
|
503 ;;; Keymap utils
|
|
504
|
|
505 (defun vip-add-keymap (mapsrc mapdst)
|
|
506 "Add contents of mapsrc to mapdst. It is assumed that mapsrc is sparse."
|
|
507 (if vip-xemacs-p
|
|
508 (map-keymap (function (lambda (key binding)
|
|
509 (define-key mapdst key binding)))
|
|
510 mapsrc)
|
|
511 (mapcar
|
|
512 (function (lambda (p)
|
|
513 (define-key mapdst (vector (car p)) (cdr p))
|
|
514 ))
|
|
515 (cdr mapsrc))))
|
|
516
|
|
517 (defun vip-modify-keymap (map alist)
|
|
518 "Modifies MAP with bindings specified in the ALIST. The alist has the
|
|
519 form ((key . function) (key . function) ... )."
|
|
520 (mapcar (function (lambda (p)
|
|
521 (define-key map (eval (car p)) (cdr p))))
|
|
522 alist))
|
|
523
|
|
524
|
|
525 (provide 'viper-keym)
|
|
526
|
|
527 ;;; viper-keym.el ends here
|