annotate lisp/emulation/viper-macs.el @ 14556:e5c95b865af5

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