0
|
1 ;;; viper-keym.el --- Viper keymaps
|
|
2
|
82
|
3 ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
|
0
|
4
|
|
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 the
|
|
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 ;; Boston, MA 02111-1307, USA.
|
|
21
|
|
22 ;; Code
|
|
23
|
80
|
24 (provide 'viper-keym)
|
|
25
|
|
26 ;; compiler pacifier
|
|
27 (defvar vip-always)
|
|
28 (defvar vip-current-state)
|
|
29 (defvar vip-mode-string)
|
|
30 (defvar vip-expert-level)
|
|
31 (defvar vip-ex-style-editing-in-insert)
|
|
32 (defvar vip-ex-style-motion)
|
|
33
|
|
34 (eval-when-compile
|
82
|
35 (let ((load-path (cons (expand-file-name ".") load-path)))
|
80
|
36 (or (featurep 'viper-util)
|
|
37 (load "viper-util.el" nil nil 'nosuffix))
|
|
38 ))
|
|
39 ;; end pacifier
|
|
40
|
0
|
41 (require 'viper-util)
|
|
42
|
82
|
43
|
0
|
44 ;;; Variables
|
|
45
|
78
|
46 (defvar vip-toggle-key "\C-z"
|
|
47 "The key used to change states from emacs to Vi and back.
|
|
48 In insert mode, this key also functions as Meta.
|
|
49 Must be set in .vip file or prior to loading Viper.
|
|
50 This setting cannot be changed interactively.")
|
|
51
|
|
52 (defvar vip-ESC-key "\e"
|
|
53 "Key used to ESC.
|
|
54 Must be set in .vip file or prior to loading Viper.
|
|
55 This setting cannot be changed interactively.")
|
80
|
56
|
|
57 ;;; Emacs keys in other states.
|
|
58
|
|
59 (defvar vip-want-emacs-keys-in-insert t
|
|
60 "*Set to nil if you want complete Vi compatibility in insert mode.
|
|
61 Complete compatibility with Vi is not recommended for power use of Viper.")
|
|
62
|
|
63 (defvar vip-want-emacs-keys-in-vi t
|
|
64 "*Set to nil if you want complete Vi compatibility in Vi mode.
|
|
65 Full Vi compatibility is not recommended for power use of Viper.")
|
|
66
|
|
67 (defvar vip-no-multiple-ESC t
|
|
68 "*If true, multiple ESC in Vi mode will cause bell to ring.
|
|
69 This is set to t on a windowing terminal and to 'twice on a dumb
|
|
70 terminal (unless the user level is 1, 2, or 5). On a dumb terminal, this
|
|
71 enables cursor keys and is generally more convenient, as terminals usually
|
|
72 don't have a convenient Meta key.
|
|
73 Setting vip-no-multiple-ESC to nil will allow as many multiple ESC,
|
|
74 as is allowed by the major mode in effect.")
|
|
75
|
|
76 (defvar vip-want-ctl-h-help nil
|
|
77 "*If t then C-h is bound to help-command in insert mode, if nil then it is
|
|
78 bound to delete-backward-char.")
|
78
|
79
|
|
80
|
0
|
81 ;;; Keymaps
|
|
82
|
|
83 ;; Keymaps for vital things like \e and C-z.
|
|
84 ;; Not for users
|
|
85 (defvar vip-vi-intercept-map (make-sparse-keymap))
|
|
86 (defvar vip-insert-intercept-map (make-sparse-keymap))
|
|
87 (defvar vip-emacs-intercept-map (make-sparse-keymap))
|
|
88
|
|
89 ;; keymap used to zap all keymaps other than function-key-map,
|
|
90 ;; device-function-key-map, etc.
|
|
91 (defvar vip-overriding-map (make-sparse-keymap))
|
|
92
|
|
93 (vip-deflocalvar vip-vi-local-user-map (make-sparse-keymap)
|
|
94 "Keymap for user-defined local bindings.
|
|
95 Useful for changing bindings such as ZZ in certain major modes.
|
|
96 For instance, in letter-mode, one may want to bind ZZ to
|
|
97 mh-send-letter. In a newsreader such as gnus, tin, or rn, ZZ could be bound
|
|
98 to save-buffers-kill-emacs then post article, etc.")
|
|
99 (put 'vip-vi-local-user-map 'permanent-local t)
|
|
100
|
|
101 (defvar vip-vi-global-user-map (make-sparse-keymap)
|
|
102 "Keymap for user-defined global bindings.
|
|
103 These bindings are seen in all Viper buffers.")
|
|
104
|
|
105 (defvar vip-vi-basic-map (make-keymap)
|
|
106 "This is the main keymap in effect in Viper's Vi state.
|
|
107 This map is global, shared by all buffers.")
|
|
108
|
|
109 (defvar vip-vi-kbd-map (make-sparse-keymap)
|
|
110 "This keymap keeps keyboard macros defined via the :map command.")
|
|
111
|
|
112 (defvar vip-vi-diehard-map (make-sparse-keymap)
|
|
113 "This keymap is in use when the user asks Viper to simulate Vi very closely.
|
|
114 This happens when vip-expert-level is 1 or 2. See vip-set-expert-level.")
|
|
115
|
|
116
|
|
117 (vip-deflocalvar vip-insert-local-user-map (make-sparse-keymap)
|
|
118 "Auxiliary map for per-buffer user-defined keybindings in Insert state.")
|
|
119 (put 'vip-insert-local-user-map 'permanent-local t)
|
|
120
|
|
121 (defvar vip-insert-global-user-map (make-sparse-keymap)
|
|
122 "Auxiliary map for global user-defined bindings in Insert state.")
|
|
123
|
|
124 (defvar vip-insert-basic-map (make-sparse-keymap)
|
|
125 "The basic insert-mode keymap.")
|
|
126
|
|
127 (defvar vip-insert-diehard-map (make-keymap)
|
|
128 "Map used when user wants vi-style keys in insert mode.
|
|
129 Most of the Emacs keys are suppressed. This map overshadows
|
|
130 vip-insert-basic-map. Not recommended, except for novice users.")
|
|
131
|
|
132 (defvar vip-insert-kbd-map (make-sparse-keymap)
|
|
133 "This keymap keeps VI-style kbd macros for insert mode.")
|
|
134
|
|
135 (defvar vip-replace-map (make-sparse-keymap)
|
|
136 "Map used in Viper's replace state.")
|
|
137
|
|
138 (defvar vip-emacs-global-user-map (make-sparse-keymap)
|
|
139 "Auxiliary map for global user-defined bindings in Emacs state.")
|
|
140
|
|
141 (defvar vip-emacs-kbd-map (make-sparse-keymap)
|
|
142 "This keymap keeps Vi-style kbd macros for emacs mode.")
|
|
143
|
|
144 (vip-deflocalvar vip-emacs-local-user-map (make-sparse-keymap)
|
|
145 "Auxiliary map for local user-defined bindings in Emacs state.")
|
|
146 (put 'vip-emacs-local-user-map 'permanent-local t)
|
|
147
|
|
148 ;; This keymap should stay empty
|
|
149 (defvar vip-empty-keymap (make-sparse-keymap))
|
|
150
|
|
151 ;; This was the main Vi mode in old versions of VIP which may have been
|
|
152 ;; extensively used by VIP users. We declare it as a global var
|
|
153 ;; and, after .vip is loaded, we add this keymap to vip-vi-basic-map.
|
|
154 (defvar vip-mode-map (make-sparse-keymap))
|
|
155
|
|
156
|
|
157 ;;; Variables used by minor modes
|
|
158
|
|
159 ;; Association list of the form
|
|
160 ;; ((major-mode . keymap) (major-mode . keymap) ...)
|
|
161 ;; Viper uses these keymaps to make user-requested adjustments
|
|
162 ;; to its Vi state in various major modes.")
|
|
163 (defvar vip-vi-state-modifier-alist nil)
|
|
164
|
|
165 ;; Association list of the form
|
|
166 ;; ((major-mode . keymap) (major-mode . keymap) ...)
|
|
167 ;; Viper uses these keymaps to make user-requested adjustments
|
|
168 ;; to its Insert state in various major modes.")
|
|
169 (defvar vip-insert-state-modifier-alist nil)
|
|
170
|
|
171 ;; Association list of the form
|
|
172 ;; ((major-mode . keymap) (major-mode . keymap) ...)
|
|
173 ;; Viper uses these keymaps to make user-requested adjustments
|
|
174 ;; to its Emacs state in various major modes.
|
|
175 (defvar vip-emacs-state-modifier-alist nil)
|
|
176
|
|
177 ;; Tells vip-add-local-keys to create a new vip-vi-local-user-map for new
|
|
178 ;; buffers. Not a user option.
|
|
179 (vip-deflocalvar vip-need-new-vi-local-map t "")
|
|
180 (put 'vip-need-new-vi-local-map 'permanent-local t)
|
|
181
|
|
182 ;; Tells vip-add-local-keys to create a new vip-insert-local-user-map for new
|
|
183 ;; buffers. Not a user option.
|
|
184 (vip-deflocalvar vip-need-new-insert-local-map t "")
|
|
185 (put 'vip-need-new-insert-local-map 'permanent-local t)
|
|
186
|
|
187 ;; Tells vip-add-local-keys to create a new vip-emacs-local-user-map for new
|
|
188 ;; buffers. Not a user option.
|
|
189 (vip-deflocalvar vip-need-new-emacs-local-map t "")
|
|
190 (put 'vip-need-new-emacs-local-map 'permanent-local t)
|
|
191
|
|
192
|
|
193
|
|
194 ;; Insert mode keymap
|
|
195
|
|
196 ;; for novice users, pretend you are the real vi.
|
|
197 (define-key vip-insert-diehard-map "\t" 'vip-insert-tab)
|
|
198 (define-key vip-insert-diehard-map "\C-a" 'self-insert-command)
|
|
199 (define-key vip-insert-diehard-map "\C-b" 'self-insert-command)
|
|
200 (define-key vip-insert-diehard-map "\C-c" 'vip-change-state-to-vi)
|
|
201 (define-key vip-insert-diehard-map "\C-e" 'self-insert-command)
|
|
202 (define-key vip-insert-diehard-map "\C-f" 'self-insert-command)
|
|
203 (define-key vip-insert-diehard-map "\C-g" 'self-insert-command)
|
|
204 (define-key vip-insert-diehard-map "\C-i" 'self-insert-command)
|
|
205 (define-key vip-insert-diehard-map "\C-k" 'self-insert-command)
|
|
206 (define-key vip-insert-diehard-map "\C-l" 'self-insert-command)
|
|
207 (define-key vip-insert-diehard-map "\C-n" 'self-insert-command)
|
|
208 (define-key vip-insert-diehard-map "\C-o" 'self-insert-command)
|
|
209 (define-key vip-insert-diehard-map "\C-p" 'self-insert-command)
|
|
210 (define-key vip-insert-diehard-map "\C-q" 'self-insert-command)
|
|
211 (define-key vip-insert-diehard-map "\C-r" 'self-insert-command)
|
|
212 (define-key vip-insert-diehard-map "\C-s" 'self-insert-command)
|
|
213 (define-key vip-insert-diehard-map "\C-u" 'vip-erase-line)
|
|
214 (define-key vip-insert-diehard-map "\C-x" 'self-insert-command)
|
|
215 (define-key vip-insert-diehard-map "\C-y" 'self-insert-command)
|
|
216 (define-key vip-insert-diehard-map "\C-z" 'self-insert-command)
|
|
217 (define-key vip-insert-diehard-map "\C-]" 'self-insert-command)
|
|
218 (define-key vip-insert-diehard-map "\C-_" 'self-insert-command)
|
|
219
|
|
220 (let ((i ?\ ))
|
|
221 (while (<= i ?~)
|
|
222 (define-key vip-insert-diehard-map (make-string 1 i) 'self-insert-command)
|
|
223 (setq i (1+ i))))
|
|
224
|
|
225 ;; Insert mode map when user wants emacs style
|
|
226 (define-key vip-insert-basic-map "\C-d" 'vip-backward-indent)
|
|
227 (define-key vip-insert-basic-map "\C-w" 'vip-delete-backward-word)
|
|
228 (define-key vip-insert-basic-map "\C-t" 'vip-forward-indent)
|
|
229 (define-key vip-insert-basic-map
|
|
230 (if vip-xemacs-p [(shift tab)] [S-tab]) 'vip-insert-tab)
|
|
231 (define-key vip-insert-basic-map "\C-v" 'quoted-insert)
|
|
232 (define-key vip-insert-basic-map "\C-?" 'vip-del-backward-char-in-insert)
|
78
|
233 (define-key vip-insert-basic-map "\C-\\" 'vip-alternate-Meta-key)
|
|
234 (define-key vip-insert-basic-map vip-toggle-key 'vip-escape-to-vi)
|
0
|
235 (define-key vip-insert-basic-map "\C-c\M-p"
|
|
236 'vip-insert-prev-from-insertion-ring)
|
|
237 (define-key vip-insert-basic-map "\C-c\M-n"
|
|
238 'vip-insert-next-from-insertion-ring)
|
|
239
|
|
240
|
|
241 ;; Replace keymap
|
|
242 (define-key vip-replace-map "\C-t" 'vip-forward-indent)
|
82
|
243 (define-key vip-replace-map "\C-j" 'vip-replace-state-carriage-return)
|
|
244 (define-key vip-replace-map "\C-m" 'vip-replace-state-carriage-return)
|
0
|
245 (define-key vip-replace-map "\C-?" 'vip-del-backward-char-in-replace)
|
|
246
|
|
247
|
|
248
|
|
249 ;; Vi keymaps
|
|
250
|
|
251 (define-key vip-vi-basic-map "\C-^"
|
|
252 (function (lambda () (interactive) (vip-ex "e#"))))
|
78
|
253 (define-key vip-vi-basic-map "\C-b" 'vip-scroll-screen-back)
|
0
|
254 (define-key vip-vi-basic-map "\C-d" 'vip-scroll-up)
|
|
255 (define-key vip-vi-basic-map "\C-e" 'vip-scroll-up-one)
|
78
|
256 (define-key vip-vi-basic-map "\C-f" 'vip-scroll-screen)
|
0
|
257 (define-key vip-vi-basic-map "\C-m" 'vip-next-line-at-bol)
|
|
258 (define-key vip-vi-basic-map "\C-u" 'vip-scroll-down)
|
|
259 (define-key vip-vi-basic-map "\C-y" 'vip-scroll-down-one)
|
|
260 (define-key vip-vi-basic-map "\C-s" 'vip-isearch-forward)
|
|
261 (define-key vip-vi-basic-map "\C-r" 'vip-isearch-backward)
|
|
262 (define-key vip-vi-basic-map "\C-c/" 'vip-toggle-search-style)
|
|
263 (define-key vip-vi-basic-map "\C-cg" 'vip-info-on-file)
|
|
264
|
|
265 (define-key vip-vi-basic-map "\C-c\M-p" 'vip-prev-destructive-command)
|
|
266 (define-key vip-vi-basic-map "\C-c\M-n" 'vip-next-destructive-command)
|
|
267
|
|
268
|
|
269 (define-key vip-vi-basic-map " " 'vip-forward-char)
|
|
270 (define-key vip-vi-basic-map "!" 'vip-command-argument)
|
|
271 (define-key vip-vi-basic-map "\"" 'vip-command-argument)
|
|
272 (define-key vip-vi-basic-map "#" 'vip-command-argument)
|
|
273 (define-key vip-vi-basic-map "$" 'vip-goto-eol)
|
|
274 (define-key vip-vi-basic-map "%" 'vip-paren-match)
|
|
275 (define-key vip-vi-basic-map "&"
|
|
276 (function (lambda () (interactive) (vip-ex "&"))))
|
|
277 (define-key vip-vi-basic-map "'" 'vip-goto-mark-and-skip-white)
|
|
278 (define-key vip-vi-basic-map "(" 'vip-backward-sentence)
|
|
279 (define-key vip-vi-basic-map ")" 'vip-forward-sentence)
|
|
280 (define-key vip-vi-basic-map "*" 'call-last-kbd-macro)
|
|
281 (define-key vip-vi-basic-map "+" 'vip-next-line-at-bol)
|
|
282 (define-key vip-vi-basic-map "," 'vip-repeat-find-opposite)
|
|
283 (define-key vip-vi-basic-map "-" 'vip-previous-line-at-bol)
|
|
284 (define-key vip-vi-basic-map "." 'vip-repeat)
|
|
285 (define-key vip-vi-basic-map "/" 'vip-search-forward)
|
|
286
|
|
287 (define-key vip-vi-basic-map "0" 'vip-beginning-of-line)
|
|
288 (define-key vip-vi-basic-map "1" 'vip-digit-argument)
|
|
289 (define-key vip-vi-basic-map "2" 'vip-digit-argument)
|
|
290 (define-key vip-vi-basic-map "3" 'vip-digit-argument)
|
|
291 (define-key vip-vi-basic-map "4" 'vip-digit-argument)
|
|
292 (define-key vip-vi-basic-map "5" 'vip-digit-argument)
|
|
293 (define-key vip-vi-basic-map "6" 'vip-digit-argument)
|
|
294 (define-key vip-vi-basic-map "7" 'vip-digit-argument)
|
|
295 (define-key vip-vi-basic-map "8" 'vip-digit-argument)
|
|
296 (define-key vip-vi-basic-map "9" 'vip-digit-argument)
|
|
297
|
|
298 (define-key vip-vi-basic-map ":" 'vip-ex)
|
|
299 (define-key vip-vi-basic-map ";" 'vip-repeat-find)
|
|
300 (define-key vip-vi-basic-map "<" 'vip-command-argument)
|
|
301 (define-key vip-vi-basic-map "=" 'vip-command-argument)
|
|
302 (define-key vip-vi-basic-map ">" 'vip-command-argument)
|
|
303 (define-key vip-vi-basic-map "?" 'vip-search-backward)
|
|
304 (define-key vip-vi-basic-map "@" 'vip-register-macro)
|
|
305
|
|
306 (define-key vip-vi-basic-map "A" 'vip-Append)
|
|
307 (define-key vip-vi-basic-map "B" 'vip-backward-Word)
|
|
308 (define-key vip-vi-basic-map "C" 'vip-change-to-eol)
|
|
309 (define-key vip-vi-basic-map "D" 'vip-kill-line)
|
|
310 (define-key vip-vi-basic-map "E" 'vip-end-of-Word)
|
|
311 (define-key vip-vi-basic-map "F" 'vip-find-char-backward)
|
|
312 (define-key vip-vi-basic-map "G" 'vip-goto-line)
|
|
313 (define-key vip-vi-basic-map "H" 'vip-window-top)
|
|
314 (define-key vip-vi-basic-map "I" 'vip-Insert)
|
|
315 (define-key vip-vi-basic-map "J" 'vip-join-lines)
|
|
316 (define-key vip-vi-basic-map "K" 'vip-nil)
|
|
317 (define-key vip-vi-basic-map "L" 'vip-window-bottom)
|
|
318 (define-key vip-vi-basic-map "M" 'vip-window-middle)
|
|
319 (define-key vip-vi-basic-map "N" 'vip-search-Next)
|
|
320 (define-key vip-vi-basic-map "O" 'vip-Open-line)
|
|
321 (define-key vip-vi-basic-map "P" 'vip-Put-back)
|
|
322 (define-key vip-vi-basic-map "Q" 'vip-query-replace)
|
|
323 (define-key vip-vi-basic-map "R" 'vip-overwrite)
|
|
324 (define-key vip-vi-basic-map "S" 'vip-substitute-line)
|
|
325 (define-key vip-vi-basic-map "T" 'vip-goto-char-backward)
|
|
326 (define-key vip-vi-basic-map "U" 'vip-undo)
|
|
327 (define-key vip-vi-basic-map "V" 'find-file-other-window)
|
|
328 (define-key vip-vi-basic-map "W" 'vip-forward-Word)
|
|
329 (define-key vip-vi-basic-map "X" 'vip-delete-backward-char)
|
|
330 (define-key vip-vi-basic-map "Y" 'vip-yank-line)
|
|
331 (define-key vip-vi-basic-map "ZZ" 'vip-save-kill-buffer)
|
|
332
|
|
333 (define-key vip-vi-basic-map "\\" 'vip-escape-to-emacs)
|
|
334 (define-key vip-vi-basic-map "[" 'vip-brac-function)
|
|
335 (define-key vip-vi-basic-map "]" 'vip-ket-function)
|
78
|
336 (define-key vip-vi-basic-map "\C-\\" 'vip-alternate-Meta-key)
|
0
|
337 (define-key vip-vi-basic-map "^" 'vip-bol-and-skip-white)
|
|
338 (define-key vip-vi-basic-map "`" 'vip-goto-mark)
|
|
339
|
|
340 (define-key vip-vi-basic-map "a" 'vip-append)
|
|
341 (define-key vip-vi-basic-map "b" 'vip-backward-word)
|
|
342 (define-key vip-vi-basic-map "c" 'vip-command-argument)
|
|
343 (define-key vip-vi-basic-map "d" 'vip-command-argument)
|
|
344 (define-key vip-vi-basic-map "e" 'vip-end-of-word)
|
|
345 (define-key vip-vi-basic-map "f" 'vip-find-char-forward)
|
|
346 (define-key vip-vi-basic-map "g" 'vip-nil)
|
|
347 (define-key vip-vi-basic-map "h" 'vip-backward-char)
|
|
348 (define-key vip-vi-basic-map "i" 'vip-insert)
|
|
349 (define-key vip-vi-basic-map "j" 'vip-next-line)
|
|
350 (define-key vip-vi-basic-map "k" 'vip-previous-line)
|
|
351 (define-key vip-vi-basic-map "l" 'vip-forward-char)
|
|
352 (define-key vip-vi-basic-map "m" 'vip-mark-point)
|
|
353 (define-key vip-vi-basic-map "n" 'vip-search-next)
|
|
354 (define-key vip-vi-basic-map "o" 'vip-open-line)
|
|
355 (define-key vip-vi-basic-map "p" 'vip-put-back)
|
|
356 (define-key vip-vi-basic-map "q" 'vip-nil)
|
|
357 (define-key vip-vi-basic-map "r" 'vip-replace-char)
|
|
358 (define-key vip-vi-basic-map "s" 'vip-substitute)
|
|
359 (define-key vip-vi-basic-map "t" 'vip-goto-char-forward)
|
|
360 (define-key vip-vi-basic-map "u" 'vip-undo)
|
|
361 (define-key vip-vi-basic-map "v" 'find-file)
|
|
362 (define-key vip-vi-basic-map "\C-v" 'find-file-other-frame)
|
|
363 (define-key vip-vi-basic-map "w" 'vip-forward-word)
|
|
364 (define-key vip-vi-basic-map "x" 'vip-delete-char)
|
|
365 (define-key vip-vi-basic-map "y" 'vip-command-argument)
|
|
366 (define-key vip-vi-basic-map "zH" 'vip-line-to-top)
|
|
367 (define-key vip-vi-basic-map "zM" 'vip-line-to-middle)
|
|
368 (define-key vip-vi-basic-map "zL" 'vip-line-to-bottom)
|
|
369 (define-key vip-vi-basic-map "z\C-m" 'vip-line-to-top)
|
|
370 (define-key vip-vi-basic-map "z." 'vip-line-to-middle)
|
|
371 (define-key vip-vi-basic-map "z-" 'vip-line-to-bottom)
|
|
372
|
|
373 (define-key vip-vi-basic-map "{" 'vip-backward-paragraph)
|
|
374 (define-key vip-vi-basic-map "|" 'vip-goto-col)
|
|
375 (define-key vip-vi-basic-map "}" 'vip-forward-paragraph)
|
|
376 (define-key vip-vi-basic-map "~" 'vip-toggle-case)
|
|
377 (define-key vip-vi-basic-map "\C-?" 'vip-backward-char)
|
78
|
378 (define-key vip-vi-basic-map "_" 'vip-nil)
|
80
|
379
|
0
|
380 ;;; Escape from Emacs to Vi for one command
|
78
|
381 (global-set-key "\C-c\\" 'vip-escape-to-vi) ; everywhere
|
0
|
382
|
|
383 ;;; This is vip-vi-diehard-map. Used when vip-vi-diehard-minor-mode is on.
|
|
384
|
|
385 (define-key vip-vi-diehard-map "\C-a" 'vip-nil)
|
|
386 (define-key vip-vi-diehard-map "\C-c" 'vip-nil)
|
|
387 (define-key vip-vi-diehard-map "\C-g" 'vip-info-on-file)
|
|
388 (define-key vip-vi-diehard-map "\C-i" 'vip-nil)
|
|
389 (define-key vip-vi-diehard-map "\C-k" 'vip-nil)
|
|
390 (define-key vip-vi-diehard-map "\C-l" 'redraw-display)
|
|
391 (define-key vip-vi-diehard-map "\C-n" 'vip-next-line)
|
|
392 (define-key vip-vi-diehard-map "\C-o" 'vip-nil)
|
|
393 (define-key vip-vi-diehard-map "\C-p" 'vip-previous-line)
|
|
394 (define-key vip-vi-diehard-map "\C-q" 'vip-nil)
|
|
395 (define-key vip-vi-diehard-map "\C-r" 'redraw-display)
|
|
396 (define-key vip-vi-diehard-map "\C-s" 'vip-nil)
|
|
397 (define-key vip-vi-diehard-map "\C-t" 'vip-nil)
|
|
398 (define-key vip-vi-diehard-map "\C-v" 'vip-nil)
|
|
399 (define-key vip-vi-diehard-map "\C-w" 'vip-nil)
|
|
400 (define-key vip-vi-diehard-map "@" 'vip-nil)
|
78
|
401 (define-key vip-vi-diehard-map "_" 'vip-nil)
|
0
|
402 (define-key vip-vi-diehard-map "*" 'vip-nil)
|
|
403 (define-key vip-vi-diehard-map "#" 'vip-nil)
|
|
404 (define-key vip-vi-diehard-map "\C-_" 'vip-nil)
|
78
|
405 (define-key vip-vi-diehard-map "\C-]" 'vip-nil) ; This is actually tags.
|
0
|
406
|
|
407
|
|
408 ;;; Minibuffer keymap
|
|
409
|
|
410
|
|
411 (defvar vip-minibuffer-map (make-sparse-keymap)
|
|
412 "Keymap used to modify keys when Minibuffer is in Insert state.")
|
|
413
|
|
414 (define-key vip-minibuffer-map "\C-m" 'vip-exit-minibuffer)
|
|
415 (define-key vip-minibuffer-map "\C-j" 'vip-exit-minibuffer)
|
|
416
|
|
417 ;; Map used to read Ex-style commands.
|
|
418 (defvar vip-ex-cmd-map (make-sparse-keymap))
|
|
419 (define-key vip-ex-cmd-map " " 'ex-cmd-read-exit)
|
|
420 (define-key vip-ex-cmd-map "\t" 'ex-cmd-complete)
|
|
421
|
|
422 ;; Keymap for reading file names in Ex-style commands.
|
|
423 (defvar ex-read-filename-map (make-sparse-keymap))
|
|
424 (define-key ex-read-filename-map " " 'vip-complete-filename-or-exit)
|
|
425 (define-key ex-read-filename-map "!" 'vip-handle-!)
|
|
426
|
78
|
427 ;; Some other maps
|
|
428 (defvar vip-slash-and-colon-map (make-sparse-keymap)
|
|
429 "This map redefines `/' and `:' to behave as in Vi.
|
|
430 Useful in some modes, such as Gnus, MH, etc.")
|
|
431 (define-key vip-slash-and-colon-map ":" 'vip-ex)
|
|
432 (define-key vip-slash-and-colon-map "/" 'vip-search-forward)
|
0
|
433
|
78
|
434 (defvar vip-comint-mode-modifier-map (make-sparse-keymap)
|
|
435 "This map modifies comint mode.")
|
|
436 (define-key vip-comint-mode-modifier-map "\C-m" 'comint-send-input)
|
|
437 (define-key vip-comint-mode-modifier-map "\C-d" 'comint-delchar-or-maybe-eof)
|
|
438
|
|
439 (defvar vip-dired-modifier-map (make-sparse-keymap)
|
|
440 "This map modifies Dired behavior.")
|
|
441 (define-key vip-dired-modifier-map ":" 'vip-ex)
|
|
442 (define-key vip-dired-modifier-map "/" 'vip-search-forward)
|
|
443
|
|
444
|
0
|
445
|
|
446 ;;; Code
|
|
447
|
|
448 (defun vip-add-local-keys (state alist)
|
|
449 "Override some vi-state or insert-state bindings in the current buffer.
|
|
450 The effect is seen in the current buffer only.
|
|
451 Useful for customizing mailer buffers, gnus, etc.
|
|
452 STATE is 'vi-state, 'insert-state, or 'emacs-state
|
|
453 ALIST is of the form ((key . func) (key . func) ...)
|
|
454 Normally, this would be called from a hook to a major mode or
|
|
455 on a per buffer basis.
|
|
456 Usage:
|
|
457 (vip-add-local-keys state '((key-str . func) (key-str . func)...)) "
|
|
458
|
|
459 (let (map)
|
|
460 (cond ((eq state 'vi-state)
|
|
461 (if vip-need-new-vi-local-map
|
|
462 (setq vip-vi-local-user-map (make-sparse-keymap)))
|
|
463 (setq vip-need-new-vi-local-map nil
|
|
464 map vip-vi-local-user-map))
|
|
465 ((eq state 'insert-state)
|
|
466 (if vip-need-new-insert-local-map
|
|
467 (setq vip-insert-local-user-map (make-sparse-keymap)))
|
|
468 (setq vip-need-new-insert-local-map nil
|
|
469 map vip-insert-local-user-map))
|
|
470 ((eq state 'emacs-state)
|
|
471 (if vip-need-new-emacs-local-map
|
|
472 (setq vip-emacs-local-user-map (make-sparse-keymap)))
|
|
473 (setq vip-need-new-emacs-local-map nil
|
|
474 map vip-emacs-local-user-map))
|
|
475 (t
|
|
476 (error
|
|
477 "Invalid state in vip-add-local-keys: %S. Valid states: vi-state, insert-state or emacs-state" state)))
|
|
478
|
|
479 (vip-modify-keymap map alist)
|
|
480 (vip-normalize-minor-mode-map-alist)
|
|
481 (vip-set-mode-vars-for vip-current-state)))
|
|
482
|
|
483 (defun vip-zap-local-keys ()
|
|
484 "Unconditionally reset Viper vip-*-local-user-map's.
|
80
|
485 Rarely useful, but if u made a mistake by switching to a mode that adds
|
78
|
486 undesirable local keys, e.g., comint-mode, then this function can restore
|
|
487 sanity."
|
0
|
488 (interactive)
|
|
489 (setq vip-vi-local-user-map (make-sparse-keymap)
|
|
490 vip-need-new-vi-local-map nil
|
|
491 vip-insert-local-user-map (make-sparse-keymap)
|
|
492 vip-need-new-insert-local-map nil
|
|
493 vip-emacs-local-user-map (make-sparse-keymap)
|
|
494 vip-need-new-emacs-local-map nil)
|
|
495 (vip-normalize-minor-mode-map-alist))
|
|
496
|
|
497
|
|
498 (defun vip-modify-major-mode (mode state keymap)
|
|
499 "Modify key bindings in a major-mode in a Viper state using a keymap.
|
|
500
|
|
501 If the default for a major mode is emacs-state, then modifications to this
|
|
502 major mode may not take effect until the buffer switches state to Vi,
|
|
503 Insert or Emacs. If this happens, add vip-change-state-to-emacs to this
|
|
504 major mode's hook. If no such hook exists, you may have to put an advice on
|
|
505 the function that invokes the major mode. See vip-set-hooks for hints.
|
|
506
|
|
507 The above needs not to be done for major modes that come up in Vi or Insert
|
|
508 state by default.
|
|
509
|
|
510 Arguments: (major-mode vip-state keymap)"
|
|
511 (let ((alist
|
|
512 (cond ((eq state 'vi-state) 'vip-vi-state-modifier-alist)
|
|
513 ((eq state 'insert-state) 'vip-insert-state-modifier-alist)
|
|
514 ((eq state 'emacs-state) 'vip-emacs-state-modifier-alist)))
|
|
515 elt)
|
|
516 (if (setq elt (assoc mode (eval alist)))
|
|
517 (set alist (delq elt (eval alist))))
|
|
518 (set alist (cons (cons mode keymap) (eval alist)))
|
|
519
|
|
520 ;; Normalization usually doesn't help here, since one needs to
|
|
521 ;; normalize in the actual buffer where changes to the keymap are
|
|
522 ;; to take place. However, it doesn't hurt, and it helps whenever this
|
|
523 ;; function is actually called from within the right buffer.
|
|
524 (vip-normalize-minor-mode-map-alist)
|
|
525
|
|
526 (vip-set-mode-vars-for vip-current-state)))
|
|
527
|
|
528
|
|
529 ;; Displays variables that control Viper's keymaps
|
|
530 (defun vip-debug-keymaps ()
|
|
531 (interactive)
|
|
532 (with-output-to-temp-buffer " *vip-debug*"
|
|
533 (princ (format "Buffer name: %s\n\n" (buffer-name)))
|
|
534 (princ "Variables: \n")
|
|
535 (princ (format "major-mode: %S\n" major-mode))
|
|
536 (princ (format "vip-current-state: %S\n" vip-current-state))
|
|
537 (princ (format "vip-mode-string: %S\n\n" vip-mode-string))
|
|
538 (princ (format "vip-vi-intercept-minor-mode: %S\n"
|
|
539 vip-vi-intercept-minor-mode))
|
|
540 (princ (format "vip-insert-intercept-minor-mode: %S\n"
|
|
541 vip-insert-intercept-minor-mode))
|
|
542 (princ (format "vip-emacs-intercept-minor-mode: %S\n"
|
|
543 vip-emacs-intercept-minor-mode))
|
|
544 (princ (format "vip-vi-minibuffer-minor-mode: %S\n"
|
|
545 vip-vi-minibuffer-minor-mode))
|
|
546 (princ (format "vip-insert-minibuffer-minor-mode: %S\n\n"
|
|
547 vip-insert-minibuffer-minor-mode))
|
|
548 (princ (format "vip-vi-local-user-minor-mode: %S\n"
|
|
549 vip-vi-local-user-minor-mode))
|
|
550 (princ (format "vip-vi-global-user-minor-mode: %S\n"
|
|
551 vip-vi-global-user-minor-mode))
|
|
552 (princ (format "vip-vi-kbd-minor-mode: %S\n" vip-vi-kbd-minor-mode))
|
|
553 (princ (format "vip-vi-state-modifier-minor-mode: %S\n"
|
|
554 vip-vi-state-modifier-minor-mode))
|
|
555 (princ (format "vip-vi-diehard-minor-mode: %S\n"
|
|
556 vip-vi-diehard-minor-mode))
|
|
557 (princ (format "vip-vi-basic-minor-mode: %S\n" vip-vi-basic-minor-mode))
|
|
558 (princ (format "vip-replace-minor-mode: %S\n" vip-replace-minor-mode))
|
|
559 (princ (format "vip-insert-local-user-minor-mode: %S\n"
|
|
560 vip-insert-local-user-minor-mode))
|
|
561 (princ (format "vip-insert-global-user-minor-mode: %S\n"
|
|
562 vip-insert-global-user-minor-mode))
|
|
563 (princ (format "vip-insert-kbd-minor-mode: %S\n"
|
|
564 vip-insert-kbd-minor-mode))
|
|
565 (princ (format "vip-insert-state-modifier-minor-mode: %S\n"
|
|
566 vip-insert-state-modifier-minor-mode))
|
|
567 (princ (format "vip-insert-diehard-minor-mode: %S\n"
|
|
568 vip-insert-diehard-minor-mode))
|
|
569 (princ (format "vip-insert-basic-minor-mode: %S\n"
|
|
570 vip-insert-basic-minor-mode))
|
|
571 (princ (format "vip-emacs-local-user-minor-mode: %S\n"
|
|
572 vip-emacs-local-user-minor-mode))
|
|
573 (princ (format "vip-emacs-kbd-minor-mode: %S\n"
|
|
574 vip-emacs-kbd-minor-mode))
|
|
575 (princ (format "vip-emacs-global-user-minor-mode: %S\n"
|
|
576 vip-emacs-global-user-minor-mode))
|
|
577 (princ (format "vip-emacs-state-modifier-minor-mode: %S\n"
|
|
578 vip-emacs-state-modifier-minor-mode))
|
|
579
|
|
580 (princ (format "\nvip-expert-level %S\n" vip-expert-level))
|
|
581 (princ (format "vip-no-multiple-ESC %S\n" vip-no-multiple-ESC))
|
|
582 (princ (format "vip-always %S\n" vip-always))
|
|
583 (princ (format "vip-ex-style-motion %S\n"
|
|
584 vip-ex-style-motion))
|
|
585 (princ (format "vip-ex-style-editing-in-insert %S\n"
|
|
586 vip-ex-style-editing-in-insert))
|
|
587 (princ (format "vip-want-emacs-keys-in-vi %S\n"
|
|
588 vip-want-emacs-keys-in-vi))
|
|
589 (princ (format "vip-want-emacs-keys-in-insert %S\n"
|
|
590 vip-want-emacs-keys-in-insert))
|
|
591 (princ (format "vip-want-ctl-h-help %S\n" vip-want-ctl-h-help))
|
|
592
|
|
593 (princ "\n\n\n")
|
|
594 (princ (format "Default value for minor-mode-map-alist: \n%S\n\n"
|
|
595 (default-value 'minor-mode-map-alist)))
|
|
596 (princ (format "Actual value for minor-mode-map-alist: \n%S\n"
|
|
597 minor-mode-map-alist))
|
|
598 ))
|
|
599
|
|
600
|
|
601 ;;; Keymap utils
|
|
602
|
|
603 (defun vip-add-keymap (mapsrc mapdst)
|
|
604 "Add contents of mapsrc to mapdst. It is assumed that mapsrc is sparse."
|
|
605 (if vip-xemacs-p
|
|
606 (map-keymap (function (lambda (key binding)
|
|
607 (define-key mapdst key binding)))
|
|
608 mapsrc)
|
|
609 (mapcar
|
|
610 (function (lambda (p)
|
|
611 (define-key mapdst (vector (car p)) (cdr p))
|
|
612 ))
|
|
613 (cdr mapsrc))))
|
|
614
|
|
615 (defun vip-modify-keymap (map alist)
|
|
616 "Modifies MAP with bindings specified in the ALIST. The alist has the
|
|
617 form ((key . function) (key . function) ... )."
|
|
618 (mapcar (function (lambda (p)
|
|
619 (define-key map (eval (car p)) (cdr p))))
|
|
620 alist))
|
|
621
|
|
622
|
|
623 ;;; viper-keym.el ends here
|