Mercurial > emacs
annotate lisp/emulation/viper-macs.el @ 87272:3cad137a4fe8
revert-buffer docstring fix
author | Vinicius Jose Latorre <viniciusjl@ig.com.br> |
---|---|
date | Wed, 12 Dec 2007 11:25:21 +0000 |
parents | 3824759a1317 |
children | 107ccd98fa12 53108e6cea98 |
rev | line source |
---|---|
13337 | 1 ;;; viper-macs.el --- functions implementing keyboard macros for Viper |
2 | |
64701
34bd8e434dd7
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64215
diff
changeset
|
3 ;; Copyright (C) 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003, 2004, |
75346 | 4 ;; 2005, 2006, 2007 Free Software Foundation, Inc. |
11288 | 5 |
42602
633233bf2bbf
2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
39215
diff
changeset
|
6 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu> |
39215
8dccf2552307
2001-09-09 Michael Kifer <kifer@cs.sunysb.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
38414
diff
changeset
|
7 |
10789 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
78218
ac0efac52065
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
12 ;; the Free Software Foundation; either version 3, or (at your option) |
10789 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
14169 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64085 | 22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 ;; Boston, MA 02110-1301, USA. | |
10789 | 24 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
26263
diff
changeset
|
25 ;;; Commentary: |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
26263
diff
changeset
|
26 |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
26263
diff
changeset
|
27 ;;; Code: |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14587
diff
changeset
|
28 |
18047 | 29 (provide 'viper-macs) |
30 | |
31 ;; compiler pacifier | |
19079 | 32 (defvar viper-ex-work-buf) |
33 (defvar viper-custom-file-name) | |
34 (defvar viper-current-state) | |
35 (defvar viper-fast-keyseq-timeout) | |
18047 | 36 |
18172 | 37 ;; loading happens only in non-interactive compilation |
38 ;; in order to spare non-viperized emacs from being viperized | |
39 (if noninteractive | |
40 (eval-when-compile | |
41 (let ((load-path (cons (expand-file-name ".") load-path))) | |
42 (or (featurep 'viper-cmd) | |
86519
61fc143bbff1
Load viper*.el files silently.
Glenn Morris <rgm@gnu.org>
parents:
85972
diff
changeset
|
43 (load "viper-cmd.el" nil t 'nosuffix)) |
18172 | 44 ))) |
18047 | 45 ;; end pacifier |
46 | |
10789 | 47 (require 'viper-util) |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14587
diff
changeset
|
48 (require 'viper-keym) |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14587
diff
changeset
|
49 |
10789 | 50 |
51 ;;; Variables | |
52 | |
53 ;; Register holding last macro. | |
19079 | 54 (defvar viper-last-macro-reg nil) |
10789 | 55 |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
56 ;; format of the elements of kbd alists: |
10789 | 57 ;; (name ((buf . macr)...(buf . macr)) ((maj-mode . macr)...) (t . macr)) |
58 ;; kbd macro alist for Vi state | |
19079 | 59 (defvar viper-vi-kbd-macro-alist nil) |
10789 | 60 ;; same for insert/replace state |
19079 | 61 (defvar viper-insert-kbd-macro-alist nil) |
10789 | 62 ;; same for emacs state |
19079 | 63 (defvar viper-emacs-kbd-macro-alist nil) |
10789 | 64 |
65 ;; Internal var that passes info between start-kbd-macro and end-kbd-macro | |
66 ;; in :map and :map! | |
19079 | 67 (defvar viper-kbd-macro-parameters nil) |
10789 | 68 |
19079 | 69 (defvar viper-this-kbd-macro nil |
10789 | 70 "Vector of keys representing the name of currently running Viper kbd macro.") |
19079 | 71 (defvar viper-last-kbd-macro nil |
10789 | 72 "Vector of keys representing the name of last Viper keyboard macro.") |
73 | |
19079 | 74 (defcustom viper-repeat-from-history-key 'f12 |
18839 | 75 "Prefix key for accessing previously typed Vi commands. |
10789 | 76 |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
77 The previous command is accessible, as usual, via `.'. The command before this |
18839 | 78 can be invoked as `<this key> 1', and the command before that, and the command |
79 before that one is accessible as `<this key> 2'. | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
80 The notation for these keys is borrowed from XEmacs. Basically, |
10789 | 81 a key is a symbol, e.g., `a', `\\1', `f2', etc., or a list, e.g., |
18839 | 82 `(meta control f1)'." |
19907
819a01a83872
(viper-repeat-from-history-key): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents:
19079
diff
changeset
|
83 :type 'sexp |
18839 | 84 :group 'viper) |
10789 | 85 |
86 | |
87 | |
88 ;;; Code | |
89 | |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
90 ;; Ex map command |
10789 | 91 (defun ex-map () |
92 (let ((mod-char "") | |
93 macro-name macro-body map-args ins) | |
94 (save-window-excursion | |
19079 | 95 (set-buffer viper-ex-work-buf) |
10789 | 96 (if (looking-at "!") |
97 (progn | |
98 (setq ins t | |
99 mod-char "!") | |
100 (forward-char 1)))) | |
101 (setq map-args (ex-map-read-args mod-char) | |
102 macro-name (car map-args) | |
103 macro-body (cdr map-args)) | |
19079 | 104 (setq viper-kbd-macro-parameters (list ins mod-char macro-name macro-body)) |
10789 | 105 (if macro-body |
19079 | 106 (viper-end-mapping-kbd-macro 'ignore) |
10789 | 107 (ex-fixup-history (format "map%s %S" mod-char |
19079 | 108 (viper-display-macro macro-name))) |
10789 | 109 ;; if defining macro for insert, switch there for authentic WYSIWYG |
19079 | 110 (if ins (viper-change-state-to-insert)) |
10789 | 111 (start-kbd-macro nil) |
19079 | 112 (define-key viper-vi-intercept-map "\C-x)" 'viper-end-mapping-kbd-macro) |
113 (define-key viper-insert-intercept-map "\C-x)" 'viper-end-mapping-kbd-macro) | |
114 (define-key viper-emacs-intercept-map "\C-x)" 'viper-end-mapping-kbd-macro) | |
65627
511f8e9d22ca
2005-09-20 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
65589
diff
changeset
|
115 (message "Mapping %S in %s state. Type macro definition followed by `C-x )'" |
19079 | 116 (viper-display-macro macro-name) |
10789 | 117 (if ins "Insert" "Vi"))) |
118 )) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
119 |
10789 | 120 |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
121 ;; Ex unmap |
10789 | 122 (defun ex-unmap () |
123 (let ((mod-char "") | |
124 temp macro-name ins) | |
125 (save-window-excursion | |
19079 | 126 (set-buffer viper-ex-work-buf) |
10789 | 127 (if (looking-at "!") |
128 (progn | |
129 (setq ins t | |
130 mod-char "!") | |
131 (forward-char 1)))) | |
132 | |
133 (setq macro-name (ex-unmap-read-args mod-char)) | |
19079 | 134 (setq temp (viper-fixup-macro (vconcat macro-name))) ;; copy and fixup |
10789 | 135 (ex-fixup-history (format "unmap%s %S" mod-char |
19079 | 136 (viper-display-macro temp))) |
137 (viper-unrecord-kbd-macro macro-name (if ins 'insert-state 'vi-state)) | |
10789 | 138 )) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
139 |
10789 | 140 |
141 ;; read arguments for ex-map | |
142 (defun ex-map-read-args (variant) | |
143 (let ((cursor-in-echo-area t) | |
144 (key-seq []) | |
145 temp key event message | |
146 macro-name macro-body args) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
147 |
10789 | 148 (condition-case nil |
149 (setq args (concat (ex-get-inline-cmd-args ".*map[!]*[ \t]?" "\n\C-m") | |
150 " nil nil ") | |
151 temp (read-from-string args) | |
152 macro-name (car temp) | |
153 macro-body (car (read-from-string args (cdr temp)))) | |
154 (error | |
155 (signal | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
156 'error |
10789 | 157 '("map: Macro name and body must be a quoted string or a vector")))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
158 |
10789 | 159 ;; We expect macro-name to be a vector, a string, or a quoted string. |
160 ;; In the second case, it will emerge as a symbol when read from | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
161 ;; the above read-from-string. So we need to convert it into a string |
10789 | 162 (if macro-name |
163 (cond ((vectorp macro-name) nil) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
164 ((stringp macro-name) |
10789 | 165 (setq macro-name (vconcat macro-name))) |
166 (t (setq macro-name (vconcat (prin1-to-string macro-name))))) | |
65627
511f8e9d22ca
2005-09-20 Michael Kifer <kifer@cs.stonybrook.edu>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
65589
diff
changeset
|
167 (message ":map%s <Macro Name>" variant)(sit-for 2) |
10789 | 168 (while |
169 (not (member key | |
170 '(?\C-m ?\n (control m) (control j) return linefeed))) | |
171 (setq key-seq (vconcat key-seq (if key (vector key) []))) | |
172 ;; the only keys available for editing are these-- no help while there | |
173 (if (member | |
174 key | |
175 '(?\b ?\d '^? '^H (control h) (control \?) backspace delete)) | |
64215
a4c59075cac8
* viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
64085
diff
changeset
|
176 (setq key-seq (viper-subseq key-seq 0 (- (length key-seq) 2)))) |
10789 | 177 (setq message |
14585
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
178 (format |
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
179 ":map%s %s" |
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
180 variant (if (> (length key-seq) 0) |
19079 | 181 (prin1-to-string (viper-display-macro key-seq)) |
14585
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
182 ""))) |
65589
0670efd1e2df
message format spec fixes, commit # 8
Deepak Goel <deego@gnufans.org>
parents:
64701
diff
changeset
|
183 (message "%s" message) |
19079 | 184 (setq event (viper-read-key)) |
185 ;;(setq event (viper-read-event)) | |
10789 | 186 (setq key |
19079 | 187 (if (viper-mouse-event-p event) |
10789 | 188 (progn |
189 (message "%s (No mouse---only keyboard keys, please)" | |
190 message) | |
191 (sit-for 2) | |
192 nil) | |
19079 | 193 (viper-event-key event))) |
10789 | 194 ) |
195 (setq macro-name key-seq)) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
196 |
10789 | 197 (if (= (length macro-name) 0) |
198 (error "Can't map an empty macro name")) | |
19079 | 199 (setq macro-name (viper-fixup-macro macro-name)) |
200 (if (viper-char-array-p macro-name) | |
201 (setq macro-name (viper-char-array-to-macro macro-name))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
202 |
10789 | 203 (if macro-body |
19079 | 204 (cond ((viper-char-array-p macro-body) |
205 (setq macro-body (viper-char-array-to-macro macro-body))) | |
10789 | 206 ((vectorp macro-body) nil) |
207 (t (error "map: Invalid syntax in macro definition")))) | |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
208 (setq cursor-in-echo-area nil)(sit-for 0) ; this overcomes xemacs tty bug |
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
209 (cons macro-name macro-body))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
210 |
10789 | 211 |
212 | |
213 ;; read arguments for ex-unmap | |
214 (defun ex-unmap-read-args (variant) | |
215 (let ((cursor-in-echo-area t) | |
216 (macro-alist (if (string= variant "!") | |
19079 | 217 viper-insert-kbd-macro-alist |
218 viper-vi-kbd-macro-alist)) | |
10789 | 219 ;; these are disabled just in case, to avoid surprises when doing |
220 ;; completing-read | |
19079 | 221 viper-vi-kbd-minor-mode viper-insert-kbd-minor-mode |
222 viper-emacs-kbd-minor-mode | |
223 viper-vi-intercept-minor-mode viper-insert-intercept-minor-mode | |
224 viper-emacs-intercept-minor-mode | |
10789 | 225 event message |
226 key key-seq macro-name) | |
227 (setq macro-name (ex-get-inline-cmd-args ".*unma?p?[!]*[ \t]*")) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
228 |
10789 | 229 (if (> (length macro-name) 0) |
230 () | |
231 (message ":unmap%s <Name>" variant) (sit-for 2) | |
232 (while | |
233 (not | |
234 (member key '(?\C-m ?\n (control m) (control j) return linefeed))) | |
235 (setq key-seq (vconcat key-seq (if key (vector key) []))) | |
236 ;; the only keys available for editing are these-- no help while there | |
237 (cond ((member | |
238 key | |
239 '(?\b ?\d '^? '^H (control h) (control \?) backspace delete)) | |
64215
a4c59075cac8
* viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
64085
diff
changeset
|
240 (setq key-seq (viper-subseq key-seq 0 (- (length key-seq) 2)))) |
10789 | 241 ((member key '(tab (control i) ?\t)) |
64215
a4c59075cac8
* viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
64085
diff
changeset
|
242 (setq key-seq (viper-subseq key-seq 0 (1- (length key-seq)))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
243 (setq message |
14585
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
244 (format |
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
245 ":unmap%s %s" |
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
246 variant (if (> (length key-seq) 0) |
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
247 (prin1-to-string |
19079 | 248 (viper-display-macro key-seq)) |
14585
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
249 ""))) |
10789 | 250 (setq key-seq |
19079 | 251 (viper-do-sequence-completion key-seq macro-alist message)) |
10789 | 252 )) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
253 (setq message |
14585
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
254 (format |
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
255 ":unmap%s %s" |
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
256 variant (if (> (length key-seq) 0) |
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
257 (prin1-to-string |
19079 | 258 (viper-display-macro key-seq)) |
14585
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
259 ""))) |
65589
0670efd1e2df
message format spec fixes, commit # 8
Deepak Goel <deego@gnufans.org>
parents:
64701
diff
changeset
|
260 (message "%s" message) |
19079 | 261 (setq event (viper-read-key)) |
262 ;;(setq event (viper-read-event)) | |
10789 | 263 (setq key |
19079 | 264 (if (viper-mouse-event-p event) |
10789 | 265 (progn |
266 (message "%s (No mouse---only keyboard keys, please)" | |
267 message) | |
268 (sit-for 2) | |
269 nil) | |
19079 | 270 (viper-event-key event))) |
10789 | 271 ) |
272 (setq macro-name key-seq)) | |
273 | |
274 (if (= (length macro-name) 0) | |
275 (error "Can't unmap an empty macro name")) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
276 |
10789 | 277 ;; convert macro names into vector, if starts with a `[' |
278 (if (memq (elt macro-name 0) '(?\[ ?\")) | |
279 (car (read-from-string macro-name)) | |
280 (vconcat macro-name)) | |
281 )) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
282 |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
283 |
14585
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
284 ;; Terminate a Vi kbd macro. |
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
285 ;; optional argument IGNORE, if t, indicates that we are dealing with an |
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
286 ;; existing macro that needs to be registered, but there is no need to |
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
287 ;; terminate a kbd macro. |
19079 | 288 (defun viper-end-mapping-kbd-macro (&optional ignore) |
10789 | 289 (interactive) |
19079 | 290 (define-key viper-vi-intercept-map "\C-x)" nil) |
291 (define-key viper-insert-intercept-map "\C-x)" nil) | |
292 (define-key viper-emacs-intercept-map "\C-x)" nil) | |
10789 | 293 (if (and (not ignore) |
19079 | 294 (or (not viper-kbd-macro-parameters) |
10789 | 295 (not defining-kbd-macro))) |
296 (error "Not mapping a kbd-macro")) | |
19079 | 297 (let ((mod-char (nth 1 viper-kbd-macro-parameters)) |
298 (ins (nth 0 viper-kbd-macro-parameters)) | |
299 (macro-name (nth 2 viper-kbd-macro-parameters)) | |
300 (macro-body (nth 3 viper-kbd-macro-parameters))) | |
301 (setq viper-kbd-macro-parameters nil) | |
10789 | 302 (or ignore |
303 (progn | |
304 (end-kbd-macro nil) | |
19079 | 305 (setq macro-body (viper-events-to-macro last-kbd-macro)) |
10789 | 306 ;; always go back to Vi, since this is where we started |
307 ;; defining macro | |
19079 | 308 (viper-change-state-to-vi))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
309 |
19079 | 310 (viper-record-kbd-macro macro-name |
10789 | 311 (if ins 'insert-state 'vi-state) |
19079 | 312 (viper-display-macro macro-body)) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
313 |
10789 | 314 (ex-fixup-history (format "map%s %S %S" mod-char |
19079 | 315 (viper-display-macro macro-name) |
316 (viper-display-macro macro-body))) | |
10789 | 317 )) |
318 | |
319 | |
320 | |
321 | |
322 ;;; Recording, unrecording, executing | |
323 | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
324 ;; Accepts as macro names: strings and vectors. |
10789 | 325 ;; strings must be strings of characters; vectors must be vectors of keys |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
326 ;; in canonic form. The canonic form is essentially the form used in XEmacs |
60168
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
327 ;; More general definitions are inherited by more specific scopes: |
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
328 ;; global->major mode->buffer. More specific definitions override more general |
19079 | 329 (defun viper-record-kbd-macro (macro-name state macro-body &optional scope) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
330 "Record a Vi macro. Can be used in `.viper' file to define permanent macros. |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
331 MACRO-NAME is a string of characters or a vector of keys. STATE is |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
332 either `vi-state' or `insert-state'. It specifies the Viper state in which to |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
333 define the macro. MACRO-BODY is a string that represents the keyboard macro. |
10789 | 334 Optional SCOPE says whether the macro should be global \(t\), mode-specific |
335 \(a major-mode symbol\), or buffer-specific \(buffer name, a string\). | |
336 If SCOPE is nil, the user is asked to specify the scope." | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
337 (let* (state-name keymap |
10789 | 338 (macro-alist-var |
339 (cond ((eq state 'vi-state) | |
340 (setq state-name "Vi state" | |
19079 | 341 keymap viper-vi-kbd-map) |
342 'viper-vi-kbd-macro-alist) | |
10789 | 343 ((memq state '(insert-state replace-state)) |
344 (setq state-name "Insert state" | |
19079 | 345 keymap viper-insert-kbd-map) |
346 'viper-insert-kbd-macro-alist) | |
10789 | 347 (t |
348 (setq state-name "Emacs state" | |
19079 | 349 keymap viper-emacs-kbd-map) |
350 'viper-emacs-kbd-macro-alist) | |
10789 | 351 )) |
352 new-elt old-elt old-sub-elt msg | |
353 temp lis lis2) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
354 |
10789 | 355 (if (= (length macro-name) 0) |
356 (error "Can't map an empty macro name")) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
357 |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
358 ;; Macro-name is usually a vector. However, command history or macros |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
359 ;; recorded in ~/.viper may be recorded as strings. So, convert to |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
360 ;; vectors. |
19079 | 361 (setq macro-name (viper-fixup-macro macro-name)) |
362 (if (viper-char-array-p macro-name) | |
363 (setq macro-name (viper-char-array-to-macro macro-name))) | |
364 (setq macro-body (viper-fixup-macro macro-body)) | |
365 (if (viper-char-array-p macro-body) | |
366 (setq macro-body (viper-char-array-to-macro macro-body))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
367 |
10789 | 368 ;; don't ask if scope is given and is of the right type |
369 (or (eq scope t) | |
370 (stringp scope) | |
371 (and scope (symbolp scope)) | |
372 (progn | |
373 (setq scope | |
374 (cond | |
375 ((y-or-n-p | |
376 (format | |
377 "Map this macro for buffer `%s' only? " | |
378 (buffer-name))) | |
379 (setq msg | |
380 (format | |
381 "%S is mapped to %s for %s in `%s'" | |
19079 | 382 (viper-display-macro macro-name) |
383 (viper-abbreviate-string | |
10789 | 384 (format |
385 "%S" | |
19079 | 386 (setq temp (viper-display-macro macro-body))) |
10789 | 387 14 "" "" |
388 (if (stringp temp) " ....\"" " ....]")) | |
389 state-name (buffer-name))) | |
390 (buffer-name)) | |
391 ((y-or-n-p | |
392 (format | |
393 "Map this macro for the major mode `%S' only? " | |
394 major-mode)) | |
395 (setq msg | |
396 (format | |
397 "%S is mapped to %s for %s in `%S'" | |
19079 | 398 (viper-display-macro macro-name) |
399 (viper-abbreviate-string | |
10789 | 400 (format |
401 "%S" | |
19079 | 402 (setq temp (viper-display-macro macro-body))) |
10789 | 403 14 "" "" |
404 (if (stringp macro-body) " ....\"" " ....]")) | |
405 state-name major-mode)) | |
406 major-mode) | |
407 (t | |
408 (setq msg | |
409 (format | |
410 "%S is globally mapped to %s in %s" | |
19079 | 411 (viper-display-macro macro-name) |
412 (viper-abbreviate-string | |
10789 | 413 (format |
414 "%S" | |
19079 | 415 (setq temp (viper-display-macro macro-body))) |
10789 | 416 14 "" "" |
417 (if (stringp macro-body) " ....\"" " ....]")) | |
418 state-name)) | |
419 t))) | |
14580
1883960762e0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14433
diff
changeset
|
420 (if (y-or-n-p |
1883960762e0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14433
diff
changeset
|
421 (format "Save this macro in %s? " |
19079 | 422 (viper-abbreviate-file-name viper-custom-file-name))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
423 (viper-save-string-in-file |
19079 | 424 (format "\n(viper-record-kbd-macro %S '%S %s '%S)" |
425 (viper-display-macro macro-name) | |
13211
76308c9753ab
(vip-record-kbd-macro): correctly escapes `.' and `[' now.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12695
diff
changeset
|
426 state |
76308c9753ab
(vip-record-kbd-macro): correctly escapes `.' and `[' now.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12695
diff
changeset
|
427 ;; if we don't let vector macro-body through %S, |
76308c9753ab
(vip-record-kbd-macro): correctly escapes `.' and `[' now.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12695
diff
changeset
|
428 ;; the symbols `\.' `\[' etc will be converted into |
76308c9753ab
(vip-record-kbd-macro): correctly escapes `.' and `[' now.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12695
diff
changeset
|
429 ;; characters, causing invalid read error on recorded |
19079 | 430 ;; macros in .viper. |
13211
76308c9753ab
(vip-record-kbd-macro): correctly escapes `.' and `[' now.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12695
diff
changeset
|
431 ;; I am not sure is macro-body can still be a string at |
76308c9753ab
(vip-record-kbd-macro): correctly escapes `.' and `[' now.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12695
diff
changeset
|
432 ;; this point, but I am preserving this option anyway. |
76308c9753ab
(vip-record-kbd-macro): correctly escapes `.' and `[' now.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12695
diff
changeset
|
433 (if (vectorp macro-body) |
76308c9753ab
(vip-record-kbd-macro): correctly escapes `.' and `[' now.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12695
diff
changeset
|
434 (format "%S" macro-body) |
76308c9753ab
(vip-record-kbd-macro): correctly escapes `.' and `[' now.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12695
diff
changeset
|
435 macro-body) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
436 scope) |
19079 | 437 viper-custom-file-name)) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
438 |
65589
0670efd1e2df
message format spec fixes, commit # 8
Deepak Goel <deego@gnufans.org>
parents:
64701
diff
changeset
|
439 (message "%s" msg) |
10789 | 440 )) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
441 |
10789 | 442 (setq new-elt |
443 (cons macro-name | |
444 (cond ((eq scope t) (list nil nil (cons t nil))) | |
445 ((symbolp scope) | |
446 (list nil (list (cons scope nil)) (cons t nil))) | |
447 ((stringp scope) | |
448 (list (list (cons scope nil)) nil (cons t nil)))))) | |
449 (setq old-elt (assoc macro-name (eval macro-alist-var))) | |
450 | |
60168
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
451 (if (null old-elt) |
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
452 (progn |
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
453 ;; insert new-elt in macro-alist-var and keep the list sorted |
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
454 (define-key |
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
455 keymap |
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
456 (vector (viper-key-to-emacs-key (aref macro-name 0))) |
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
457 'viper-exec-mapped-kbd-macro) |
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
458 (setq lis (eval macro-alist-var)) |
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
459 (while (and lis (string< (viper-array-to-string (car (car lis))) |
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
460 (viper-array-to-string macro-name))) |
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
461 (setq lis2 (cons (car lis) lis2)) |
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
462 (setq lis (cdr lis))) |
84907
80f409ec2b40
(viper-describe-kbd-macros, viper-describe-one-macro):
Juanma Barranquero <lekktu@gmail.com>
parents:
78218
diff
changeset
|
463 |
60168
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
464 (setq lis2 (reverse lis2)) |
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
465 (set macro-alist-var (append lis2 (cons new-elt lis))) |
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
466 (setq old-elt new-elt))) |
10789 | 467 (setq old-sub-elt |
19079 | 468 (cond ((eq scope t) (viper-kbd-global-pair old-elt)) |
469 ((symbolp scope) (assoc scope (viper-kbd-mode-alist old-elt))) | |
470 ((stringp scope) (assoc scope (viper-kbd-buf-alist old-elt))))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
471 (if old-sub-elt |
10789 | 472 (setcdr old-sub-elt macro-body) |
473 (cond ((symbolp scope) (setcar (cdr (cdr old-elt)) | |
474 (cons (cons scope macro-body) | |
19079 | 475 (viper-kbd-mode-alist old-elt)))) |
10789 | 476 ((stringp scope) (setcar (cdr old-elt) |
477 (cons (cons scope macro-body) | |
19079 | 478 (viper-kbd-buf-alist old-elt)))))) |
10789 | 479 )) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
480 |
10789 | 481 |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
482 |
19079 | 483 ;; macro name must be a vector of viper-style keys |
60168
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
484 ;; viper-unrecord-kbd-macro doesn't have scope. Macro definitions are inherited |
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
485 ;; from global -> major mode -> buffer |
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
486 ;; More specific definition overrides more general |
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
487 ;; Can't unrecord definition for more specific, if a more general definition is |
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
488 ;; in effect |
19079 | 489 (defun viper-unrecord-kbd-macro (macro-name state) |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
490 "Delete macro MACRO-NAME from Viper STATE. |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
491 MACRO-NAME must be a vector of viper-style keys. This command is used by Viper |
19079 | 492 internally, but the user can also use it in ~/.viper to delete pre-defined |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
493 macros supplied with Viper. The best way to avoid mistakes in macro names to |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
494 be passed to this function is to use viper-describe-kbd-macros and copy the |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
495 name from there." |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
496 (let* (state-name keymap |
10789 | 497 (macro-alist-var |
498 (cond ((eq state 'vi-state) | |
499 (setq state-name "Vi state" | |
19079 | 500 keymap viper-vi-kbd-map) |
501 'viper-vi-kbd-macro-alist) | |
10789 | 502 ((memq state '(insert-state replace-state)) |
503 (setq state-name "Insert state" | |
19079 | 504 keymap viper-insert-kbd-map) |
505 'viper-insert-kbd-macro-alist) | |
10789 | 506 (t |
507 (setq state-name "Emacs state" | |
19079 | 508 keymap viper-emacs-kbd-map) |
509 'viper-emacs-kbd-macro-alist) | |
10789 | 510 )) |
511 buf-mapping mode-mapping global-mapping | |
512 macro-pair macro-entry) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
513 |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
514 ;; Macro-name is usually a vector. However, command history or macros |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
515 ;; recorded in ~/.viper may appear as strings. So, convert to vectors. |
19079 | 516 (setq macro-name (viper-fixup-macro macro-name)) |
517 (if (viper-char-array-p macro-name) | |
518 (setq macro-name (viper-char-array-to-macro macro-name))) | |
10789 | 519 |
520 (setq macro-entry (assoc macro-name (eval macro-alist-var))) | |
521 (if (= (length macro-name) 0) | |
522 (error "Can't unmap an empty macro name")) | |
523 (if (null macro-entry) | |
524 (error "%S is not mapped to a macro for %s in `%s'" | |
19079 | 525 (viper-display-macro macro-name) |
10789 | 526 state-name (buffer-name))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
527 |
19079 | 528 (setq buf-mapping (viper-kbd-buf-pair macro-entry) |
529 mode-mapping (viper-kbd-mode-pair macro-entry) | |
530 global-mapping (viper-kbd-global-pair macro-entry)) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
531 |
10789 | 532 (cond ((and (cdr buf-mapping) |
533 (or (and (not (cdr mode-mapping)) (not (cdr global-mapping))) | |
534 (y-or-n-p | |
535 (format "Unmap %S for `%s' only? " | |
19079 | 536 (viper-display-macro macro-name) |
10789 | 537 (buffer-name))))) |
538 (setq macro-pair buf-mapping) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
539 (message "%S is unmapped for %s in `%s'" |
19079 | 540 (viper-display-macro macro-name) |
10789 | 541 state-name (buffer-name))) |
542 ((and (cdr mode-mapping) | |
543 (or (not (cdr global-mapping)) | |
544 (y-or-n-p | |
545 (format "Unmap %S for the major mode `%S' only? " | |
19079 | 546 (viper-display-macro macro-name) |
10789 | 547 major-mode)))) |
548 (setq macro-pair mode-mapping) | |
549 (message "%S is unmapped for %s in %S" | |
19079 | 550 (viper-display-macro macro-name) state-name major-mode)) |
60168
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
551 ((cdr (setq macro-pair global-mapping)) |
10789 | 552 (message |
18839 | 553 "Global mapping for %S in %s is removed" |
19079 | 554 (viper-display-macro macro-name) state-name)) |
10789 | 555 (t (error "%S is not mapped to a macro for %s in `%s'" |
19079 | 556 (viper-display-macro macro-name) |
10789 | 557 state-name (buffer-name)))) |
558 (setcdr macro-pair nil) | |
559 (or (cdr buf-mapping) | |
560 (cdr mode-mapping) | |
561 (cdr global-mapping) | |
562 (progn | |
563 (set macro-alist-var (delq macro-entry (eval macro-alist-var))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
564 (if (viper-can-release-key (aref macro-name 0) |
60168
d96e54250eea
* viper-cmd.el (viper-prefix-commands): make into a defconst.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
52401
diff
changeset
|
565 (eval macro-alist-var)) |
10789 | 566 (define-key |
567 keymap | |
19079 | 568 (vector (viper-key-to-emacs-key (aref macro-name 0))) |
10789 | 569 nil)) |
570 )) | |
571 )) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
572 |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
573 ;; Check if MACRO-ALIST has an entry for a macro name starting with |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
574 ;; CHAR. If not, this indicates that the binding for this char |
19079 | 575 ;; in viper-vi/insert-kbd-map can be released. |
576 (defun viper-can-release-key (char macro-alist) | |
10789 | 577 (let ((lis macro-alist) |
578 (can-release t) | |
579 macro-name) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
580 |
10789 | 581 (while (and lis can-release) |
582 (setq macro-name (car (car lis))) | |
583 (if (eq char (aref macro-name 0)) | |
584 (setq can-release nil)) | |
585 (setq lis (cdr lis))) | |
586 can-release)) | |
587 | |
588 | |
19079 | 589 (defun viper-exec-mapped-kbd-macro (count) |
10789 | 590 "Dispatch kbd macro." |
591 (interactive "P") | |
19079 | 592 (let* ((macro-alist (cond ((eq viper-current-state 'vi-state) |
593 viper-vi-kbd-macro-alist) | |
594 ((memq viper-current-state | |
10789 | 595 '(insert-state replace-state)) |
19079 | 596 viper-insert-kbd-macro-alist) |
10789 | 597 (t |
19079 | 598 viper-emacs-kbd-macro-alist))) |
10789 | 599 (unmatched-suffix "") |
600 ;; Macros and keys are executed with other macros turned off | |
601 ;; For macros, this is done to avoid macro recursion | |
19079 | 602 viper-vi-kbd-minor-mode viper-insert-kbd-minor-mode |
603 viper-emacs-kbd-minor-mode | |
10789 | 604 next-best-match keyseq event-seq |
605 macro-first-char macro-alist-elt macro-body | |
606 command) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
607 |
10789 | 608 (setq macro-first-char last-command-event |
19079 | 609 event-seq (viper-read-fast-keysequence macro-first-char macro-alist) |
610 keyseq (viper-events-to-macro event-seq) | |
10789 | 611 macro-alist-elt (assoc keyseq macro-alist) |
19079 | 612 next-best-match (viper-find-best-matching-macro macro-alist keyseq)) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
613 |
10789 | 614 (if (null macro-alist-elt) |
615 (setq macro-alist-elt (car next-best-match) | |
64215
a4c59075cac8
* viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
64085
diff
changeset
|
616 unmatched-suffix (viper-subseq event-seq (cdr next-best-match)))) |
10789 | 617 |
618 (cond ((null macro-alist-elt)) | |
19079 | 619 ((setq macro-body (viper-kbd-buf-definition macro-alist-elt))) |
620 ((setq macro-body (viper-kbd-mode-definition macro-alist-elt))) | |
621 ((setq macro-body (viper-kbd-global-definition macro-alist-elt)))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
622 |
10789 | 623 ;; when defining keyboard macro, don't use the macro mappings |
624 (if (and macro-body (not defining-kbd-macro)) | |
625 ;; block cmd executed as part of a macro from entering command history | |
626 (let ((command-history command-history)) | |
19079 | 627 (setq viper-this-kbd-macro (car macro-alist-elt)) |
628 (execute-kbd-macro (viper-macro-to-events macro-body) count) | |
629 (setq viper-this-kbd-macro nil | |
630 viper-last-kbd-macro (car macro-alist-elt)) | |
631 (viper-set-unread-command-events unmatched-suffix)) | |
10789 | 632 ;; If not a macro, or the macro is suppressed while defining another |
633 ;; macro, put keyseq back on the event queue | |
19079 | 634 (viper-set-unread-command-events event-seq) |
10789 | 635 ;; if the user typed arg, then use it if prefix arg is not set by |
636 ;; some other command (setting prefix arg can happen if we do, say, | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
637 ;; 2dw and there is a macro starting with 2. Then control will go to |
10789 | 638 ;; this routine |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
639 (or prefix-arg (setq prefix-arg count)) |
10789 | 640 (setq command (key-binding (read-key-sequence nil))) |
641 (if (commandp command) | |
642 (command-execute command) | |
643 (beep 1))) | |
644 )) | |
645 | |
646 | |
647 | |
648 ;;; Displaying and completing macros | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
649 |
19079 | 650 (defun viper-describe-kbd-macros () |
10789 | 651 "Show currently defined keyboard macros." |
652 (interactive) | |
19079 | 653 (with-output-to-temp-buffer " *viper-info*" |
10789 | 654 (princ "Macros in Vi state:\n===================\n") |
84907
80f409ec2b40
(viper-describe-kbd-macros, viper-describe-one-macro):
Juanma Barranquero <lekktu@gmail.com>
parents:
78218
diff
changeset
|
655 (mapc 'viper-describe-one-macro viper-vi-kbd-macro-alist) |
10789 | 656 (princ "\n\nMacros in Insert and Replace states:\n====================================\n") |
84907
80f409ec2b40
(viper-describe-kbd-macros, viper-describe-one-macro):
Juanma Barranquero <lekktu@gmail.com>
parents:
78218
diff
changeset
|
657 (mapc 'viper-describe-one-macro viper-insert-kbd-macro-alist) |
10789 | 658 (princ "\n\nMacros in Emacs state:\n======================\n") |
19079 | 659 (mapcar 'viper-describe-one-macro viper-emacs-kbd-macro-alist) |
10789 | 660 )) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
661 |
19079 | 662 (defun viper-describe-one-macro (macro) |
10789 | 663 (princ (format "\n *** Mappings for %S:\n ------------\n" |
19079 | 664 (viper-display-macro (car macro)))) |
10789 | 665 (princ " ** Buffer-specific:") |
19079 | 666 (if (viper-kbd-buf-alist macro) |
84907
80f409ec2b40
(viper-describe-kbd-macros, viper-describe-one-macro):
Juanma Barranquero <lekktu@gmail.com>
parents:
78218
diff
changeset
|
667 (mapc 'viper-describe-one-macro-elt (viper-kbd-buf-alist macro)) |
10789 | 668 (princ " none\n")) |
669 (princ "\n ** Mode-specific:") | |
19079 | 670 (if (viper-kbd-mode-alist macro) |
84907
80f409ec2b40
(viper-describe-kbd-macros, viper-describe-one-macro):
Juanma Barranquero <lekktu@gmail.com>
parents:
78218
diff
changeset
|
671 (mapc 'viper-describe-one-macro-elt (viper-kbd-mode-alist macro)) |
10789 | 672 (princ " none\n")) |
673 (princ "\n ** Global:") | |
19079 | 674 (if (viper-kbd-global-definition macro) |
675 (princ (format "\n %S" (cdr (viper-kbd-global-pair macro)))) | |
10789 | 676 (princ " none")) |
677 (princ "\n")) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
678 |
19079 | 679 (defun viper-describe-one-macro-elt (elt) |
10789 | 680 (let ((name (car elt)) |
681 (defn (cdr elt))) | |
682 (princ (format "\n * %S:\n %S\n" name defn)))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
683 |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
684 |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
685 |
10789 | 686 ;; check if SEQ is a prefix of some car of an element in ALIST |
19079 | 687 (defun viper-keyseq-is-a-possible-macro (seq alist) |
688 (let ((converted-seq (viper-events-to-macro seq))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
689 (eval (cons 'or |
10789 | 690 (mapcar |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
691 (lambda (elt) (viper-prefix-subseq-p converted-seq elt)) |
19079 | 692 (viper-this-buffer-macros alist)))))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
693 |
10789 | 694 ;; whether SEQ1 is a prefix of SEQ2 |
19079 | 695 (defun viper-prefix-subseq-p (seq1 seq2) |
10789 | 696 (let ((len1 (length seq1)) |
697 (len2 (length seq2))) | |
698 (if (<= len1 len2) | |
64215
a4c59075cac8
* viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
64085
diff
changeset
|
699 (equal seq1 (viper-subseq seq2 0 len1))))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
700 |
10789 | 701 ;; find the longest common prefix |
19079 | 702 (defun viper-common-seq-prefix (&rest seqs) |
10789 | 703 (let* ((first (car seqs)) |
704 (rest (cdr seqs)) | |
705 (pref []) | |
706 (idx 0) | |
707 len) | |
708 (if (= (length seqs) 0) | |
709 (setq len 0) | |
710 (setq len (apply 'min (mapcar 'length seqs)))) | |
711 (while (< idx len) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
712 (if (eval (cons 'and |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
713 (mapcar (lambda (s) (equal (elt first idx) (elt s idx))) |
10789 | 714 rest))) |
715 (setq pref (vconcat pref (vector (elt first idx))))) | |
716 (setq idx (1+ idx))) | |
717 pref)) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
718 |
10789 | 719 ;; get all sequences that match PREFIX from a given A-LIST |
19079 | 720 (defun viper-extract-matching-alist-members (pref alist) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
721 (delq nil (mapcar (lambda (elt) (if (viper-prefix-subseq-p pref elt) elt)) |
19079 | 722 (viper-this-buffer-macros alist)))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
723 |
19079 | 724 (defun viper-do-sequence-completion (seq alist compl-message) |
725 (let* ((matches (viper-extract-matching-alist-members seq alist)) | |
726 (new-seq (apply 'viper-common-seq-prefix matches)) | |
10789 | 727 ) |
728 (cond ((and (equal seq new-seq) (= (length matches) 1)) | |
729 (message "%s (Sole completion)" compl-message) | |
730 (sit-for 2)) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
731 ((null matches) |
10789 | 732 (message "%s (No match)" compl-message) |
733 (sit-for 2) | |
734 (setq new-seq seq)) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
735 ((member seq matches) |
10789 | 736 (message "%s (Complete, but not unique)" compl-message) |
737 (sit-for 2) | |
19079 | 738 (viper-display-vector-completions matches)) |
10789 | 739 ((equal seq new-seq) |
19079 | 740 (viper-display-vector-completions matches))) |
10789 | 741 new-seq)) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
742 |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
743 |
19079 | 744 (defun viper-display-vector-completions (list) |
10789 | 745 (with-output-to-temp-buffer "*Completions*" |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
746 (display-completion-list |
10789 | 747 (mapcar 'prin1-to-string |
19079 | 748 (mapcar 'viper-display-macro list))))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
749 |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
750 |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
751 |
10789 | 752 ;; alist is the alist of macros |
753 ;; str is the fast key sequence entered | |
754 ;; returns: (matching-macro-def . unmatched-suffix-start-index) | |
19079 | 755 (defun viper-find-best-matching-macro (alist str) |
10789 | 756 (let ((lis alist) |
757 (def-len 0) | |
758 (str-len (length str)) | |
759 match unmatched-start-idx found macro-def) | |
760 (while (and (not found) lis) | |
761 (setq macro-def (car lis) | |
762 def-len (length (car macro-def))) | |
763 (if (and (>= str-len def-len) | |
64215
a4c59075cac8
* viper-cmd.el (viper--key-maps): new variable.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
64085
diff
changeset
|
764 (equal (car macro-def) (viper-subseq str 0 def-len))) |
19079 | 765 (if (or (viper-kbd-buf-definition macro-def) |
766 (viper-kbd-mode-definition macro-def) | |
767 (viper-kbd-global-definition macro-def)) | |
10789 | 768 (setq found t)) |
769 ) | |
770 (setq lis (cdr lis))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
771 |
10789 | 772 (if found |
773 (setq match macro-def | |
774 unmatched-start-idx def-len) | |
775 (setq match nil | |
776 unmatched-start-idx 0)) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
777 |
10789 | 778 (cons match unmatched-start-idx))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
779 |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
780 |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
781 |
10789 | 782 ;; returns a list of names of macros defined for the current buffer |
19079 | 783 (defun viper-this-buffer-macros (macro-alist) |
10789 | 784 (let (candidates) |
785 (setq candidates | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
786 (mapcar (lambda (elt) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
787 (if (or (viper-kbd-buf-definition elt) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
788 (viper-kbd-mode-definition elt) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
789 (viper-kbd-global-definition elt)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
790 (car elt))) |
10789 | 791 macro-alist)) |
792 (setq candidates (delq nil candidates)))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
793 |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
794 |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
795 ;; if seq of Viper key symbols (representing a macro) can be converted to a |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
796 ;; string--do so. Otherwise, do nothing. |
19079 | 797 (defun viper-display-macro (macro-name-or-body) |
798 (cond ((viper-char-symbol-sequence-p macro-name-or-body) | |
14585
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
799 (mapconcat 'symbol-name macro-name-or-body "")) |
19079 | 800 ((viper-char-array-p macro-name-or-body) |
14585
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
801 (mapconcat 'char-to-string macro-name-or-body "")) |
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
802 (t macro-name-or-body))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
803 |
14587
542db2bd7e38
(vip-events-to-macro): discard events represented as lists in macro
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14585
diff
changeset
|
804 ;; convert sequence of events (that came presumably from emacs kbd macro) into |
542db2bd7e38
(vip-events-to-macro): discard events represented as lists in macro
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14585
diff
changeset
|
805 ;; Viper's macro, which is a vector of the form |
542db2bd7e38
(vip-events-to-macro): discard events represented as lists in macro
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14585
diff
changeset
|
806 ;; [ desc desc ... ] |
542db2bd7e38
(vip-events-to-macro): discard events represented as lists in macro
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14585
diff
changeset
|
807 ;; Each desc is either a symbol of (meta symb), (shift symb), etc. |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
808 ;; Here we purge events that happen to be lists. In most cases, these events |
14587
542db2bd7e38
(vip-events-to-macro): discard events represented as lists in macro
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14585
diff
changeset
|
809 ;; got into a macro definition unintentionally; say, when the user moves mouse |
542db2bd7e38
(vip-events-to-macro): discard events represented as lists in macro
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14585
diff
changeset
|
810 ;; during a macro definition, then something like (switch-frame ...) might get |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
811 ;; in. Another reason for purging lists-events is that we can't store them in |
14587
542db2bd7e38
(vip-events-to-macro): discard events represented as lists in macro
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14585
diff
changeset
|
812 ;; textual form (say, in .emacs) and then read them back. |
19079 | 813 (defun viper-events-to-macro (event-seq) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
814 (vconcat (delq nil (mapcar (lambda (elt) (if (consp elt) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
815 nil |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
816 (viper-event-key elt))) |
14587
542db2bd7e38
(vip-events-to-macro): discard events represented as lists in macro
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14585
diff
changeset
|
817 event-seq)))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
818 |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
819 ;; convert strings or arrays of characters to Viper macro form |
19079 | 820 (defun viper-char-array-to-macro (array) |
10789 | 821 (let ((vec (vconcat array)) |
822 macro) | |
85972
51aa47312c4b
* ediff-init.el (ediff-xemacs-p, ediff-emacs-p): Remove.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
84907
diff
changeset
|
823 (if (featurep 'xemacs) |
10789 | 824 (setq macro (mapcar 'character-to-event vec)) |
825 (setq macro vec)) | |
19079 | 826 (vconcat (mapcar 'viper-event-key macro)))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
827 |
14585
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
828 ;; For macros bodies and names, goes over MACRO and checks if all members are |
10789 | 829 ;; names of keys (actually, it only checks if they are symbols or lists |
14585
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
830 ;; if a digit is found, it is converted into a symbol (e.g., 0 -> \0, etc). |
b6228a159e75
(ex-map-read-args,ex-unmap-read-args): fixed messages.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14581
diff
changeset
|
831 ;; If MACRO is not a list or vector -- doesn't change MACRO. |
19079 | 832 (defun viper-fixup-macro (macro) |
10789 | 833 (let ((len (length macro)) |
834 (idx 0) | |
835 elt break) | |
836 (if (or (vectorp macro) (listp macro)) | |
837 (while (and (< idx len) (not break)) | |
838 (setq elt (elt macro idx)) | |
839 (cond ((numberp elt) | |
840 ;; fix number | |
841 (if (and (<= 0 elt) (<= elt 9)) | |
842 (cond ((arrayp macro) | |
843 (aset macro | |
844 idx | |
845 (intern (char-to-string (+ ?0 elt))))) | |
846 ((listp macro) | |
847 (setcar (nthcdr idx macro) | |
848 (intern (char-to-string (+ ?0 elt))))) | |
849 ))) | |
850 ((listp elt) | |
19079 | 851 (viper-fixup-macro elt)) |
10789 | 852 ((symbolp elt) nil) |
853 (t (setq break t))) | |
854 (setq idx (1+ idx)))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
855 |
10789 | 856 (if break |
857 (error "Wrong type macro component, symbol-or-listp, %S" elt) | |
858 macro))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
859 |
19079 | 860 (defun viper-macro-to-events (macro-body) |
861 (vconcat (mapcar 'viper-key-to-emacs-key macro-body))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
862 |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
863 |
10789 | 864 |
865 ;;; Reading fast key sequences | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
866 |
10789 | 867 ;; Assuming that CHAR was the first character in a fast succession of key |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
868 ;; strokes, read the rest. Return the vector of keys that was entered in |
10789 | 869 ;; this fast succession of key strokes. |
870 ;; A fast keysequence is one that is terminated by a pause longer than | |
19079 | 871 ;; viper-fast-keyseq-timeout. |
872 (defun viper-read-fast-keysequence (event macro-alist) | |
10789 | 873 (let ((lis (vector event)) |
874 next-event) | |
19079 | 875 (while (and (viper-fast-keysequence-p) |
876 (viper-keyseq-is-a-possible-macro lis macro-alist)) | |
877 (setq next-event (viper-read-key)) | |
878 ;;(setq next-event (viper-read-event)) | |
879 (or (viper-mouse-event-p next-event) | |
10789 | 880 (setq lis (vconcat lis (vector next-event))))) |
881 lis)) | |
882 | |
883 | |
884 ;;; Keyboard macros in registers | |
885 | |
886 ;; sets register to last-kbd-macro carefully. | |
19079 | 887 (defun viper-set-register-macro (reg) |
10789 | 888 (if (get-register reg) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
889 (if (y-or-n-p "Register contains data. Overwrite? ") |
10789 | 890 () |
891 (error | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
19907
diff
changeset
|
892 "Macro not saved in register. Can still be invoked via `C-x e'"))) |
10789 | 893 (set-register reg last-kbd-macro)) |
894 | |
19079 | 895 (defun viper-register-macro (count) |
10789 | 896 "Keyboard macros in registers - a modified \@ command." |
897 (interactive "P") | |
898 (let ((reg (downcase (read-char)))) | |
899 (cond ((or (and (<= ?a reg) (<= reg ?z))) | |
19079 | 900 (setq viper-last-macro-reg reg) |
10789 | 901 (if defining-kbd-macro |
902 (progn | |
903 (end-kbd-macro) | |
19079 | 904 (viper-set-register-macro reg)) |
10789 | 905 (execute-kbd-macro (get-register reg) count))) |
906 ((or (= ?@ reg) (= ?\^j reg) (= ?\^m reg)) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
907 (if viper-last-macro-reg |
10789 | 908 nil |
909 (error "No previous kbd macro")) | |
19079 | 910 (execute-kbd-macro (get-register viper-last-macro-reg) count)) |
10789 | 911 ((= ?\# reg) |
912 (start-kbd-macro count)) | |
913 ((= ?! reg) | |
914 (setq reg (downcase (read-char))) | |
915 (if (or (and (<= ?a reg) (<= reg ?z))) | |
916 (progn | |
19079 | 917 (setq viper-last-macro-reg reg) |
918 (viper-set-register-macro reg)))) | |
10789 | 919 (t |
14581
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14580
diff
changeset
|
920 (error "`%c': Unknown register" reg))))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42602
diff
changeset
|
921 |
10789 | 922 |
19079 | 923 (defun viper-global-execute () |
10789 | 924 "Call last keyboad macro for each line in the region." |
925 (if (> (point) (mark t)) (exchange-point-and-mark)) | |
926 (beginning-of-line) | |
927 (call-last-kbd-macro) | |
928 (while (< (point) (mark t)) | |
929 (forward-line 1) | |
930 (beginning-of-line) | |
931 (call-last-kbd-macro))) | |
932 | |
933 | |
52401 | 934 ;;; arch-tag: ecd3cc5c-8cd0-4bbe-b2ec-7e75a4b7d0aa |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
26263
diff
changeset
|
935 ;;; viper-macs.el ends here |