annotate lisp/emulation/viper-macs.el @ 25407:479691c42edf

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