annotate lisp/emulation/viper-macs.el @ 94709:2281719c874d

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