Mercurial > emacs
annotate lisp/emulation/viper-cmd.el @ 26599:e10a1d0deb4b
Require comint when compiling.
(hippie-expand): Add :links.
(hippie-expand-try-functions-list): Customize.
author | Dave Love <fx@gnu.org> |
---|---|
date | Thu, 25 Nov 1999 19:18:15 +0000 |
parents | 76b6a75471e1 |
children | 8be2b52389a5 |
rev | line source |
---|---|
18129 | 1 ;;; viper-cmd.el --- Vi command support for Viper |
2 ;; Copyright (C) 1997 Free Software Foundation, Inc. | |
3 | |
19905
9a4cdbf423ea
(viper-smart-suffix-list): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents:
19891
diff
changeset
|
4 ;; This file is part of GNU Emacs. |
9a4cdbf423ea
(viper-smart-suffix-list): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents:
19891
diff
changeset
|
5 |
9a4cdbf423ea
(viper-smart-suffix-list): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents:
19891
diff
changeset
|
6 ;; GNU Emacs is free software; you can redistribute it and/or modify |
9a4cdbf423ea
(viper-smart-suffix-list): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents:
19891
diff
changeset
|
7 ;; it under the terms of the GNU General Public License as published by |
9a4cdbf423ea
(viper-smart-suffix-list): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents:
19891
diff
changeset
|
8 ;; the Free Software Foundation; either version 2, or (at your option) |
9a4cdbf423ea
(viper-smart-suffix-list): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents:
19891
diff
changeset
|
9 ;; any later version. |
9a4cdbf423ea
(viper-smart-suffix-list): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents:
19891
diff
changeset
|
10 |
9a4cdbf423ea
(viper-smart-suffix-list): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents:
19891
diff
changeset
|
11 ;; GNU Emacs is distributed in the hope that it will be useful, |
9a4cdbf423ea
(viper-smart-suffix-list): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents:
19891
diff
changeset
|
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
9a4cdbf423ea
(viper-smart-suffix-list): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents:
19891
diff
changeset
|
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
9a4cdbf423ea
(viper-smart-suffix-list): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents:
19891
diff
changeset
|
14 ;; GNU General Public License for more details. |
9a4cdbf423ea
(viper-smart-suffix-list): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents:
19891
diff
changeset
|
15 |
9a4cdbf423ea
(viper-smart-suffix-list): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents:
19891
diff
changeset
|
16 ;; You should have received a copy of the GNU General Public License |
9a4cdbf423ea
(viper-smart-suffix-list): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents:
19891
diff
changeset
|
17 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
9a4cdbf423ea
(viper-smart-suffix-list): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents:
19891
diff
changeset
|
18 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
9a4cdbf423ea
(viper-smart-suffix-list): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents:
19891
diff
changeset
|
19 ;; Boston, MA 02111-1307, USA. |
18129 | 20 |
21 ;; Code | |
22 | |
23 (provide 'viper-cmd) | |
18172 | 24 (require 'advice) |
18129 | 25 |
26 ;; Compiler pacifier | |
19078 | 27 (defvar viper-minibuffer-current-face) |
28 (defvar viper-minibuffer-insert-face) | |
29 (defvar viper-minibuffer-vi-face) | |
30 (defvar viper-minibuffer-emacs-face) | |
18289 | 31 (defvar viper-always) |
19078 | 32 (defvar viper-mode-string) |
33 (defvar viper-custom-file-name) | |
18129 | 34 (defvar iso-accents-mode) |
19462 | 35 (defvar quail-mode) |
36 (defvar quail-current-str) | |
18129 | 37 (defvar zmacs-region-stays) |
38 (defvar mark-even-if-inactive) | |
39 | |
18172 | 40 ;; loading happens only in non-interactive compilation |
41 ;; in order to spare non-viperized emacs from being viperized | |
42 (if noninteractive | |
43 (eval-when-compile | |
44 (let ((load-path (cons (expand-file-name ".") load-path))) | |
45 (or (featurep 'viper-util) | |
46 (load "viper-util.el" nil nil 'nosuffix)) | |
47 (or (featurep 'viper-keym) | |
48 (load "viper-keym.el" nil nil 'nosuffix)) | |
49 (or (featurep 'viper-mous) | |
50 (load "viper-mous.el" nil nil 'nosuffix)) | |
51 (or (featurep 'viper-macs) | |
52 (load "viper-macs.el" nil nil 'nosuffix)) | |
53 (or (featurep 'viper-ex) | |
54 (load "viper-ex.el" nil nil 'nosuffix)) | |
55 ))) | |
18129 | 56 ;; end pacifier |
57 | |
58 | |
59 (require 'viper-util) | |
60 (require 'viper-keym) | |
61 (require 'viper-mous) | |
62 (require 'viper-macs) | |
63 (require 'viper-ex) | |
64 | |
65 | |
66 | |
67 ;; Generic predicates | |
68 | |
69 ;; These test functions are shamelessly lifted from vip 4.4.2 by Aamod Sane | |
70 | |
71 ;; generate test functions | |
72 ;; given symbol foo, foo-p is the test function, foos is the set of | |
73 ;; Viper command keys | |
19078 | 74 ;; (macroexpand '(viper-test-com-defun foo)) |
18129 | 75 ;; (defun foo-p (com) (consp (memq (if (< com 0) (- com) com) foos))) |
76 | |
19078 | 77 (defmacro viper-test-com-defun (name) |
18129 | 78 (let* ((snm (symbol-name name)) |
79 (nm-p (intern (concat snm "-p"))) | |
80 (nms (intern (concat snm "s")))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
81 `(defun ,nm-p (com) |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
82 (consp (memq (if (and (viper-characterp com) (< com 0)) |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
83 (- com) com) ,nms))))) |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
84 |
18129 | 85 ;; Variables for defining VI commands |
86 | |
87 ;; Modifying commands that can be prefixes to movement commands | |
19078 | 88 (defconst viper-prefix-commands '(?c ?d ?y ?! ?= ?# ?< ?> ?\")) |
89 ;; define viper-prefix-command-p | |
90 (viper-test-com-defun viper-prefix-command) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
91 |
18129 | 92 ;; Commands that are pairs eg. dd. r and R here are a hack |
19078 | 93 (defconst viper-charpair-commands '(?c ?d ?y ?! ?= ?< ?> ?r ?R)) |
94 ;; define viper-charpair-command-p | |
95 (viper-test-com-defun viper-charpair-command) | |
96 | |
97 (defconst viper-movement-commands '(?b ?B ?e ?E ?f ?F ?G ?h ?H ?j ?k ?l | |
18129 | 98 ?H ?M ?L ?n ?t ?T ?w ?W ?$ ?% |
99 ?^ ?( ?) ?- ?+ ?| ?{ ?} ?[ ?] ?' ?` | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
100 ?\; ?, ?0 ?? ?/ ?\ ?\C-m |
19078 | 101 space return |
102 delete backspace | |
18129 | 103 ) |
104 "Movement commands") | |
19078 | 105 ;; define viper-movement-command-p |
106 (viper-test-com-defun viper-movement-command) | |
18129 | 107 |
18839 | 108 ;; Vi digit commands |
19078 | 109 (defconst viper-digit-commands '(?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)) |
110 | |
111 ;; define viper-digit-command-p | |
112 (viper-test-com-defun viper-digit-command) | |
18129 | 113 |
114 ;; Commands that can be repeated by . (dotted) | |
19078 | 115 (defconst viper-dotable-commands '(?c ?d ?C ?s ?S ?D ?> ?<)) |
116 ;; define viper-dotable-command-p | |
117 (viper-test-com-defun viper-dotable-command) | |
18129 | 118 |
119 ;; Commands that can follow a # | |
19078 | 120 (defconst viper-hash-commands '(?c ?C ?g ?q ?s)) |
121 ;; define viper-hash-command-p | |
122 (viper-test-com-defun viper-hash-command) | |
18129 | 123 |
124 ;; Commands that may have registers as prefix | |
19078 | 125 (defconst viper-regsuffix-commands '(?d ?y ?Y ?D ?p ?P ?x ?X)) |
126 ;; define viper-regsuffix-command-p | |
127 (viper-test-com-defun viper-regsuffix-command) | |
128 | |
129 (defconst viper-vi-commands (append viper-movement-commands | |
130 viper-digit-commands | |
131 viper-dotable-commands | |
132 viper-charpair-commands | |
133 viper-hash-commands | |
134 viper-prefix-commands | |
135 viper-regsuffix-commands) | |
18129 | 136 "The list of all commands in Vi-state.") |
19078 | 137 ;; define viper-vi-command-p |
138 (viper-test-com-defun viper-vi-command) | |
18129 | 139 |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
140 ;; Where viper saves mark. This mark is resurrected by m^ |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
141 (defvar viper-saved-mark nil) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
142 |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
143 |
18129 | 144 |
145 ;;; CODE | |
146 | |
147 ;; sentinels | |
148 | |
19078 | 149 ;; Runs viper-after-change-functions inside after-change-functions |
150 (defun viper-after-change-sentinel (beg end len) | |
21940 | 151 (run-hook-with-args 'viper-after-change-functions beg end len)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
152 |
19078 | 153 ;; Runs viper-before-change-functions inside before-change-functions |
154 (defun viper-before-change-sentinel (beg end) | |
21940 | 155 (run-hook-with-args 'viper-before-change-functions beg end)) |
18129 | 156 |
19078 | 157 (defsubst viper-post-command-sentinel () |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
158 (run-hooks 'viper-post-command-hooks) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
159 (if (eq viper-current-state 'vi-state) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
160 (viper-restore-cursor-color 'after-insert-mode))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
161 |
19078 | 162 (defsubst viper-pre-command-sentinel () |
163 (run-hooks 'viper-pre-command-hooks)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
164 |
18129 | 165 ;; Needed so that Viper will be able to figure the last inserted |
166 ;; chunk of text with reasonable accuracy. | |
19078 | 167 (defsubst viper-insert-state-post-command-sentinel () |
168 (if (and (memq viper-current-state '(insert-state replace-state)) | |
169 viper-insert-point | |
170 (>= (point) viper-insert-point)) | |
171 (setq viper-last-posn-while-in-insert-state (point-marker))) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
172 (or (viper-overlay-p viper-replace-overlay) |
18129 | 173 (progn |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
174 (viper-set-replace-overlay (point-min) (point-min)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
175 (viper-hide-replace-overlay))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
176 (if (eq viper-current-state 'insert-state) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
177 (let ((has-saved-cursor-color-in-insert-mode |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
178 (stringp (viper-get-saved-cursor-color-in-insert-mode)))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
179 (or has-saved-cursor-color-in-insert-mode |
19078 | 180 (string= (viper-get-cursor-color) viper-insert-state-cursor-color) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
181 ;; save current color, if not already saved |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
182 (viper-save-cursor-color 'before-insert-mode)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
183 ;; set insert mode cursor color |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
184 (viper-change-cursor-color viper-insert-state-cursor-color))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
185 |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
186 (if (and (memq this-command '(dabbrev-expand hippie-expand)) |
19078 | 187 (integerp viper-pre-command-point) |
19756 | 188 (markerp viper-insert-point) |
189 (marker-position viper-insert-point) | |
19078 | 190 (> viper-insert-point viper-pre-command-point)) |
19756 | 191 (viper-move-marker-locally viper-insert-point viper-pre-command-point)) |
18129 | 192 ) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
193 |
19078 | 194 (defsubst viper-insert-state-pre-command-sentinel () |
18129 | 195 (or (memq this-command '(self-insert-command)) |
19078 | 196 (memq (viper-event-key last-command-event) |
18129 | 197 '(up down left right (meta f) (meta b) |
198 (control n) (control p) (control f) (control b))) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
199 (viper-restore-cursor-color 'after-insert-mode)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
200 (if (and (memq this-command '(dabbrev-expand hippie-expand)) |
19078 | 201 (markerp viper-insert-point) |
202 (marker-position viper-insert-point)) | |
203 (setq viper-pre-command-point (marker-position viper-insert-point)))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
204 |
19078 | 205 (defsubst viper-R-state-post-command-sentinel () |
18129 | 206 ;; Restoring cursor color is needed despite |
19078 | 207 ;; viper-replace-state-pre-command-sentinel: When you jump to another buffer |
208 ;; in another frame, the pre-command hook won't change cursor color to | |
209 ;; default in that other frame. So, if the second frame cursor was red and | |
210 ;; we set the point outside the replacement region, then the cursor color | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
211 ;; will remain red. Restoring the default, below, prevents this. |
19078 | 212 (if (and (<= (viper-replace-start) (point)) |
213 (<= (point) (viper-replace-end))) | |
214 (viper-change-cursor-color viper-replace-overlay-cursor-color) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
215 (viper-restore-cursor-color 'after-replace-mode) |
18129 | 216 )) |
217 | |
218 ;; to speed up, don't change cursor color before self-insert | |
219 ;; and common move commands | |
19078 | 220 (defsubst viper-replace-state-pre-command-sentinel () |
18129 | 221 (or (memq this-command '(self-insert-command)) |
19078 | 222 (memq (viper-event-key last-command-event) |
18129 | 223 '(up down left right (meta f) (meta b) |
224 (control n) (control p) (control f) (control b))) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
225 (viper-restore-cursor-color 'after-replace-mode))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
226 |
19078 | 227 (defun viper-replace-state-post-command-sentinel () |
18129 | 228 ;; Restoring cursor color is needed despite |
19078 | 229 ;; viper-replace-state-pre-command-sentinel: When one jumps to another buffer |
18129 | 230 ;; in another frame, the pre-command hook won't change cursor color to |
231 ;; default in that other frame. So, if the second frame cursor was red and | |
232 ;; we set the point outside the replacement region, then the cursor color | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
233 ;; will remain red. Restoring the default, below, fixes this problem. |
18129 | 234 ;; |
235 ;; We optimize for self-insert-command's here, since they either don't change | |
236 ;; cursor color or, if they terminate replace mode, the color will be changed | |
19078 | 237 ;; in viper-finish-change |
18129 | 238 (or (memq this-command '(self-insert-command)) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
239 (viper-restore-cursor-color 'after-replace-mode)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
240 (cond |
19078 | 241 ((eq viper-current-state 'replace-state) |
18129 | 242 ;; delete characters to compensate for inserted chars. |
19078 | 243 (let ((replace-boundary (viper-replace-end))) |
18129 | 244 (save-excursion |
19078 | 245 (goto-char viper-last-posn-in-replace-region) |
19462 | 246 (viper-trim-replace-chars-to-delete-if-necessary) |
19078 | 247 (delete-char viper-replace-chars-to-delete) |
19462 | 248 (setq viper-replace-chars-to-delete 0) |
18129 | 249 ;; terminate replace mode if reached replace limit |
19462 | 250 (if (= viper-last-posn-in-replace-region (viper-replace-end)) |
251 (viper-finish-change))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
252 |
19462 | 253 (if (viper-pos-within-region |
254 (point) (viper-replace-start) replace-boundary) | |
18129 | 255 (progn |
19078 | 256 ;; the state may have changed in viper-finish-change above |
257 (if (eq viper-current-state 'replace-state) | |
258 (viper-change-cursor-color viper-replace-overlay-cursor-color)) | |
259 (setq viper-last-posn-in-replace-region (point-marker)))) | |
18129 | 260 )) |
19462 | 261 ;; terminate replace mode if changed Viper states. |
262 (t (viper-finish-change)))) | |
18129 | 263 |
264 | |
265 ;; changing mode | |
266 | |
267 ;; Change state to NEW-STATE---either emacs-state, vi-state, or insert-state. | |
19078 | 268 (defun viper-change-state (new-state) |
269 ;; Keep viper-post/pre-command-hooks fresh. | |
270 ;; We remove then add viper-post/pre-command-sentinel since it is very | |
271 ;; desirable that viper-pre-command-sentinel is the last hook and | |
272 ;; viper-post-command-sentinel is the first hook. | |
21940 | 273 |
274 (make-local-hook 'viper-after-change-functions) | |
275 (make-local-hook 'viper-before-change-functions) | |
276 (make-local-hook 'viper-post-command-hooks) | |
277 (make-local-hook 'viper-pre-command-hooks) | |
278 | |
19078 | 279 (remove-hook 'post-command-hook 'viper-post-command-sentinel) |
280 (add-hook 'post-command-hook 'viper-post-command-sentinel) | |
281 (remove-hook 'pre-command-hook 'viper-pre-command-sentinel) | |
282 (add-hook 'pre-command-hook 'viper-pre-command-sentinel t) | |
18129 | 283 ;; These hooks will be added back if switching to insert/replace mode |
21940 | 284 (remove-hook 'viper-post-command-hooks |
285 'viper-insert-state-post-command-sentinel 'local) | |
286 (remove-hook 'viper-pre-command-hooks | |
287 'viper-insert-state-pre-command-sentinel 'local) | |
19078 | 288 (setq viper-intermediate-command nil) |
18129 | 289 (cond ((eq new-state 'vi-state) |
19078 | 290 (cond ((member viper-current-state '(insert-state replace-state)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
291 |
19078 | 292 ;; move viper-last-posn-while-in-insert-state |
18129 | 293 ;; This is a normal hook that is executed in insert/replace |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
294 ;; states after each command. In Vi/Emacs state, it does |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
295 ;; nothing. We need to execute it here to make sure that |
18129 | 296 ;; the last posn was recorded when we hit ESC. |
297 ;; It may be left unrecorded if the last thing done in | |
298 ;; insert/repl state was dabbrev-expansion or abbrev | |
299 ;; expansion caused by hitting ESC | |
19078 | 300 (viper-insert-state-post-command-sentinel) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
301 |
18129 | 302 (condition-case conds |
303 (progn | |
19078 | 304 (viper-save-last-insertion |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
305 viper-insert-point |
19078 | 306 viper-last-posn-while-in-insert-state) |
307 (if viper-began-as-replace | |
308 (setq viper-began-as-replace nil) | |
18129 | 309 ;; repeat insert commands if numerical arg > 1 |
310 (save-excursion | |
19078 | 311 (viper-repeat-insert-command)))) |
18129 | 312 (error |
19078 | 313 (viper-message-conditions conds))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
314 |
19078 | 315 (if (> (length viper-last-insertion) 0) |
316 (viper-push-onto-ring viper-last-insertion | |
317 'viper-insertion-ring)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
318 |
19462 | 319 (if viper-ex-style-editing |
18129 | 320 (or (bolp) (backward-char 1)))) |
321 )) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
322 |
18129 | 323 ;; insert or replace |
324 ((memq new-state '(insert-state replace-state)) | |
19078 | 325 (if (memq viper-current-state '(emacs-state vi-state)) |
326 (viper-move-marker-locally 'viper-insert-point (point))) | |
327 (viper-move-marker-locally | |
328 'viper-last-posn-while-in-insert-state (point)) | |
21940 | 329 (add-hook 'viper-post-command-hooks |
330 'viper-insert-state-post-command-sentinel t 'local) | |
331 (add-hook 'viper-pre-command-hooks | |
332 'viper-insert-state-pre-command-sentinel t 'local)) | |
18129 | 333 ) ; outermost cond |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
334 |
18129 | 335 ;; Nothing needs to be done to switch to emacs mode! Just set some |
19078 | 336 ;; variables, which is already done in viper-change-state-to-emacs! |
337 | |
19462 | 338 ;; ISO accents |
339 ;; always turn off iso-accents-mode in vi-state, or else we won't be able to | |
340 ;; use the keys `,',^ , as they will do accents instead of Vi actions. | |
341 (cond ((eq new-state 'vi-state) (viper-set-iso-accents-mode nil));accents off | |
342 (viper-automatic-iso-accents (viper-set-iso-accents-mode t));accents on | |
343 (t (viper-set-iso-accents-mode nil))) | |
344 ;; Always turn off quail mode in vi state | |
345 (cond ((eq new-state 'vi-state) (viper-set-input-method nil)) ;intl input off | |
346 (viper-special-input-method (viper-set-input-method t)) ;intl input on | |
347 (t (viper-set-input-method nil))) | |
348 | |
19078 | 349 (setq viper-current-state new-state) |
19462 | 350 |
351 (viper-update-syntax-classes) | |
19078 | 352 (viper-normalize-minor-mode-map-alist) |
353 (viper-adjust-keys-for new-state) | |
354 (viper-set-mode-vars-for new-state) | |
355 (viper-refresh-mode-line) | |
18129 | 356 ) |
357 | |
358 | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
359 |
19078 | 360 (defun viper-adjust-keys-for (state) |
18129 | 361 "Make necessary adjustments to keymaps before entering STATE." |
362 (cond ((memq state '(insert-state replace-state)) | |
19078 | 363 (if viper-auto-indent |
18129 | 364 (progn |
19078 | 365 (define-key viper-insert-basic-map "\C-m" 'viper-autoindent) |
366 (if viper-want-emacs-keys-in-insert | |
18129 | 367 ;; expert |
19078 | 368 (define-key viper-insert-basic-map "\C-j" nil) |
18129 | 369 ;; novice |
19078 | 370 (define-key viper-insert-basic-map "\C-j" 'viper-autoindent))) |
371 (define-key viper-insert-basic-map "\C-m" nil) | |
372 (define-key viper-insert-basic-map "\C-j" nil)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
373 |
19078 | 374 (setq viper-insert-diehard-minor-mode |
375 (not viper-want-emacs-keys-in-insert)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
376 |
19078 | 377 (if viper-want-ctl-h-help |
19891 | 378 (progn |
379 (define-key viper-insert-basic-map "\C-h" 'help-command) | |
380 (define-key viper-replace-map "\C-h" 'help-command)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
381 (define-key viper-insert-basic-map |
19891 | 382 "\C-h" 'viper-del-backward-char-in-insert) |
19462 | 383 (define-key viper-replace-map |
19891 | 384 "\C-h" 'viper-del-backward-char-in-replace)) |
385 ;; In XEmacs, C-h overrides backspace, so we make sure it doesn't. | |
386 (define-key viper-insert-basic-map | |
387 [backspace] 'viper-del-backward-char-in-insert) | |
388 (define-key viper-replace-map | |
389 [backspace] 'viper-del-backward-char-in-replace) | |
390 ) ; end insert/replace case | |
18129 | 391 (t ; Vi state |
19078 | 392 (setq viper-vi-diehard-minor-mode (not viper-want-emacs-keys-in-vi)) |
393 (if viper-want-ctl-h-help | |
19891 | 394 (define-key viper-vi-basic-map "\C-h" 'help-command) |
395 (define-key viper-vi-basic-map "\C-h" 'viper-backward-char)) | |
396 ;; In XEmacs, C-h overrides backspace, so we make sure it doesn't. | |
397 (define-key viper-vi-basic-map [backspace] 'viper-backward-char)) | |
18129 | 398 )) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
399 |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
400 |
18129 | 401 ;; Normalizes minor-mode-map-alist by putting Viper keymaps first. |
402 ;; This ensures that Viper bindings are in effect, regardless of which minor | |
403 ;; modes were turned on by the user or by other packages. | |
19078 | 404 (defun viper-normalize-minor-mode-map-alist () |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
405 (setq minor-mode-map-alist |
19078 | 406 (viper-append-filter-alist |
26588
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
407 (list (cons 'viper-vi-intercept-minor-mode viper-vi-intercept-map) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
408 (cons 'viper-vi-minibuffer-minor-mode viper-minibuffer-map) |
19078 | 409 (cons 'viper-vi-local-user-minor-mode viper-vi-local-user-map) |
410 (cons 'viper-vi-kbd-minor-mode viper-vi-kbd-map) | |
411 (cons 'viper-vi-global-user-minor-mode viper-vi-global-user-map) | |
412 (cons 'viper-vi-state-modifier-minor-mode | |
18129 | 413 (if (keymapp |
19203 | 414 (cdr (assoc major-mode |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
415 viper-vi-state-modifier-alist))) |
19078 | 416 (cdr (assoc major-mode viper-vi-state-modifier-alist)) |
417 viper-empty-keymap)) | |
418 (cons 'viper-vi-diehard-minor-mode viper-vi-diehard-map) | |
419 (cons 'viper-vi-basic-minor-mode viper-vi-basic-map) | |
19203 | 420 (cons 'viper-insert-intercept-minor-mode |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
421 viper-insert-intercept-map) |
19078 | 422 (cons 'viper-replace-minor-mode viper-replace-map) |
423 ;; viper-insert-minibuffer-minor-mode must come after | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
424 ;; viper-replace-minor-mode |
19078 | 425 (cons 'viper-insert-minibuffer-minor-mode |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
426 viper-minibuffer-map) |
19078 | 427 (cons 'viper-insert-local-user-minor-mode |
428 viper-insert-local-user-map) | |
429 (cons 'viper-insert-kbd-minor-mode viper-insert-kbd-map) | |
430 (cons 'viper-insert-global-user-minor-mode | |
431 viper-insert-global-user-map) | |
432 (cons 'viper-insert-state-modifier-minor-mode | |
18129 | 433 (if (keymapp |
19203 | 434 (cdr (assoc major-mode |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
435 viper-insert-state-modifier-alist))) |
19203 | 436 (cdr (assoc major-mode |
437 viper-insert-state-modifier-alist)) | |
19078 | 438 viper-empty-keymap)) |
439 (cons 'viper-insert-diehard-minor-mode viper-insert-diehard-map) | |
440 (cons 'viper-insert-basic-minor-mode viper-insert-basic-map) | |
441 (cons 'viper-emacs-intercept-minor-mode | |
442 viper-emacs-intercept-map) | |
443 (cons 'viper-emacs-local-user-minor-mode | |
444 viper-emacs-local-user-map) | |
445 (cons 'viper-emacs-kbd-minor-mode viper-emacs-kbd-map) | |
446 (cons 'viper-emacs-global-user-minor-mode | |
447 viper-emacs-global-user-map) | |
448 (cons 'viper-emacs-state-modifier-minor-mode | |
18129 | 449 (if (keymapp |
450 (cdr | |
19078 | 451 (assoc major-mode viper-emacs-state-modifier-alist))) |
18129 | 452 (cdr |
19078 | 453 (assoc major-mode viper-emacs-state-modifier-alist)) |
454 viper-empty-keymap)) | |
18129 | 455 ) |
456 minor-mode-map-alist))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
457 |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
458 |
18129 | 459 |
460 ;; Viper mode-changing commands and utilities | |
461 | |
462 ;; Modifies mode-line-buffer-identification. | |
19078 | 463 (defun viper-refresh-mode-line () |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
464 (setq viper-mode-string |
19078 | 465 (cond ((eq viper-current-state 'emacs-state) viper-emacs-state-id) |
466 ((eq viper-current-state 'vi-state) viper-vi-state-id) | |
467 ((eq viper-current-state 'replace-state) viper-replace-state-id) | |
468 ((eq viper-current-state 'insert-state) viper-insert-state-id))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
469 |
18129 | 470 ;; Sets Viper mode string in global-mode-string |
471 (force-mode-line-update)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
472 |
18129 | 473 |
474 ;; Switch from Insert state to Vi state. | |
19078 | 475 (defun viper-exit-insert-state () |
18129 | 476 (interactive) |
19078 | 477 (viper-change-state-to-vi)) |
478 | |
479 (defun viper-set-mode-vars-for (state) | |
18129 | 480 "Sets Viper minor mode variables to put Viper's state STATE in effect." |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
481 |
18129 | 482 ;; Emacs state |
19078 | 483 (setq viper-vi-minibuffer-minor-mode nil |
484 viper-insert-minibuffer-minor-mode nil | |
485 viper-vi-intercept-minor-mode nil | |
486 viper-insert-intercept-minor-mode nil | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
487 |
19078 | 488 viper-vi-local-user-minor-mode nil |
489 viper-vi-kbd-minor-mode nil | |
490 viper-vi-global-user-minor-mode nil | |
491 viper-vi-state-modifier-minor-mode nil | |
492 viper-vi-diehard-minor-mode nil | |
493 viper-vi-basic-minor-mode nil | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
494 |
19078 | 495 viper-replace-minor-mode nil |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
496 |
19078 | 497 viper-insert-local-user-minor-mode nil |
498 viper-insert-kbd-minor-mode nil | |
499 viper-insert-global-user-minor-mode nil | |
500 viper-insert-state-modifier-minor-mode nil | |
501 viper-insert-diehard-minor-mode nil | |
502 viper-insert-basic-minor-mode nil | |
503 viper-emacs-intercept-minor-mode t | |
504 viper-emacs-local-user-minor-mode t | |
505 viper-emacs-kbd-minor-mode (not (viper-is-in-minibuffer)) | |
506 viper-emacs-global-user-minor-mode t | |
507 viper-emacs-state-modifier-minor-mode t | |
18129 | 508 ) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
509 |
18129 | 510 ;; Vi state |
511 (if (eq state 'vi-state) ; adjust for vi-state | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
512 (setq |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
513 viper-vi-intercept-minor-mode t |
19078 | 514 viper-vi-minibuffer-minor-mode (viper-is-in-minibuffer) |
515 viper-vi-local-user-minor-mode t | |
516 viper-vi-kbd-minor-mode (not (viper-is-in-minibuffer)) | |
517 viper-vi-global-user-minor-mode t | |
518 viper-vi-state-modifier-minor-mode t | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
519 ;; don't let the diehard keymap block command completion |
18129 | 520 ;; and other things in the minibuffer |
19078 | 521 viper-vi-diehard-minor-mode (not |
522 (or viper-want-emacs-keys-in-vi | |
523 (viper-is-in-minibuffer))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
524 viper-vi-basic-minor-mode t |
19078 | 525 viper-emacs-intercept-minor-mode nil |
526 viper-emacs-local-user-minor-mode nil | |
527 viper-emacs-kbd-minor-mode nil | |
528 viper-emacs-global-user-minor-mode nil | |
529 viper-emacs-state-modifier-minor-mode nil | |
18129 | 530 )) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
531 |
18129 | 532 ;; Insert and Replace states |
533 (if (member state '(insert-state replace-state)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
534 (setq |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
535 viper-insert-intercept-minor-mode t |
19078 | 536 viper-replace-minor-mode (eq state 'replace-state) |
537 viper-insert-minibuffer-minor-mode (viper-is-in-minibuffer) | |
538 viper-insert-local-user-minor-mode t | |
539 viper-insert-kbd-minor-mode (not (viper-is-in-minibuffer)) | |
540 viper-insert-global-user-minor-mode t | |
541 viper-insert-state-modifier-minor-mode t | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
542 ;; don't let the diehard keymap block command completion |
18129 | 543 ;; and other things in the minibuffer |
19078 | 544 viper-insert-diehard-minor-mode (not |
545 (or | |
546 viper-want-emacs-keys-in-insert | |
547 (viper-is-in-minibuffer))) | |
548 viper-insert-basic-minor-mode t | |
549 viper-emacs-intercept-minor-mode nil | |
550 viper-emacs-local-user-minor-mode nil | |
551 viper-emacs-kbd-minor-mode nil | |
552 viper-emacs-global-user-minor-mode nil | |
553 viper-emacs-state-modifier-minor-mode nil | |
18129 | 554 )) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
555 |
18129 | 556 ;; minibuffer faces |
19078 | 557 (if (viper-has-face-support-p) |
558 (setq viper-minibuffer-current-face | |
559 (cond ((eq state 'emacs-state) viper-minibuffer-emacs-face) | |
560 ((eq state 'vi-state) viper-minibuffer-vi-face) | |
18129 | 561 ((memq state '(insert-state replace-state)) |
19078 | 562 viper-minibuffer-insert-face)))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
563 |
19078 | 564 (if (viper-is-in-minibuffer) |
565 (viper-set-minibuffer-overlay)) | |
18129 | 566 ) |
567 | |
568 ;; This also takes care of the annoying incomplete lines in files. | |
569 ;; Also, this fixes `undo' to work vi-style for complex commands. | |
19078 | 570 (defun viper-change-state-to-vi () |
18129 | 571 "Change Viper state to Vi." |
572 (interactive) | |
19078 | 573 (if (and viper-first-time (not (viper-is-in-minibuffer))) |
18129 | 574 (viper-mode) |
575 (if overwrite-mode (overwrite-mode nil)) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
576 (or (viper-overlay-p viper-replace-overlay) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
577 (viper-set-replace-overlay (point-min) (point-min))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
578 (viper-hide-replace-overlay) |
18129 | 579 (if abbrev-mode (expand-abbrev)) |
580 (if (and auto-fill-function (> (current-column) fill-column)) | |
581 (funcall auto-fill-function)) | |
582 ;; don't leave whitespace lines around | |
583 (if (and (memq last-command | |
19078 | 584 '(viper-autoindent |
585 viper-open-line viper-Open-line | |
586 viper-replace-state-exit-cmd)) | |
587 (viper-over-whitespace-line)) | |
18129 | 588 (indent-to-left-margin)) |
19078 | 589 (viper-add-newline-at-eob-if-necessary) |
19462 | 590 (viper-adjust-undo) |
19078 | 591 (viper-change-state 'vi-state) |
18129 | 592 |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
593 (viper-restore-cursor-color 'after-insert-mode) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
594 |
19462 | 595 ;; Protect against user errors in hooks |
18129 | 596 (condition-case conds |
19078 | 597 (run-hooks 'viper-vi-state-hook) |
18129 | 598 (error |
19078 | 599 (viper-message-conditions conds))))) |
600 | |
601 (defun viper-change-state-to-insert () | |
18129 | 602 "Change Viper state to Insert." |
603 (interactive) | |
19078 | 604 (viper-change-state 'insert-state) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
605 |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
606 (or (viper-overlay-p viper-replace-overlay) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
607 (viper-set-replace-overlay (point-min) (point-min))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
608 (viper-hide-replace-overlay) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
609 |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
610 (let ((has-saved-cursor-color-in-insert-mode |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
611 (stringp (viper-get-saved-cursor-color-in-insert-mode)))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
612 (or has-saved-cursor-color-in-insert-mode |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
613 (string= (viper-get-cursor-color) viper-insert-state-cursor-color) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
614 (viper-save-cursor-color 'before-insert-mode)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
615 (viper-change-cursor-color viper-insert-state-cursor-color)) |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
616 |
19462 | 617 ;; Protect against user errors in hooks |
18129 | 618 (condition-case conds |
19078 | 619 (run-hooks 'viper-insert-state-hook) |
18129 | 620 (error |
19078 | 621 (viper-message-conditions conds)))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
622 |
19078 | 623 (defsubst viper-downgrade-to-insert () |
624 (setq viper-current-state 'insert-state | |
19203 | 625 viper-replace-minor-mode nil)) |
18129 | 626 |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
627 |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
628 |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
629 ;; Change to replace state. When the end of replacement region is reached, |
18129 | 630 ;; replace state changes to insert state. |
19078 | 631 (defun viper-change-state-to-replace (&optional non-R-cmd) |
632 (viper-change-state 'replace-state) | |
18129 | 633 ;; Run insert-state-hook |
634 (condition-case conds | |
19078 | 635 (run-hooks 'viper-insert-state-hook 'viper-replace-state-hook) |
18129 | 636 (error |
19078 | 637 (viper-message-conditions conds))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
638 |
18129 | 639 (if non-R-cmd |
19078 | 640 (viper-start-replace) |
18129 | 641 ;; 'R' is implemented using Emacs's overwrite-mode |
19078 | 642 (viper-start-R-mode)) |
18129 | 643 ) |
644 | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
645 |
19078 | 646 (defun viper-change-state-to-emacs () |
18129 | 647 "Change Viper state to Emacs." |
648 (interactive) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
649 (or (viper-overlay-p viper-replace-overlay) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
650 (viper-set-replace-overlay (point-min) (point-min))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
651 (viper-hide-replace-overlay) |
19078 | 652 (viper-change-state 'emacs-state) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
653 |
19462 | 654 ;; Protect agains user errors in hooks |
18129 | 655 (condition-case conds |
19078 | 656 (run-hooks 'viper-emacs-state-hook) |
18129 | 657 (error |
19078 | 658 (viper-message-conditions conds)))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
659 |
18129 | 660 ;; escape to emacs mode termporarily |
19078 | 661 (defun viper-escape-to-emacs (arg &optional events) |
18129 | 662 "Escape to Emacs state from Vi state for one Emacs command. |
663 ARG is used as the prefix value for the executed command. If | |
664 EVENTS is a list of events, which become the beginning of the command." | |
665 (interactive "P") | |
666 (if (= last-command-char ?\\) | |
667 (message "Switched to EMACS state for the next command...")) | |
19078 | 668 (viper-escape-to-state arg events 'emacs-state)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
669 |
18129 | 670 ;; escape to Vi mode termporarily |
19078 | 671 (defun viper-escape-to-vi (arg) |
18129 | 672 "Escape from Emacs state to Vi state for one Vi 1-character command. |
673 If the Vi command that the user types has a prefix argument, e.g., `d2w', then | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
674 Vi's prefix argument will be used. Otherwise, the prefix argument passed to |
19078 | 675 `viper-escape-to-vi' is used." |
18129 | 676 (interactive "P") |
677 (message "Switched to VI state for the next command...") | |
19078 | 678 (viper-escape-to-state arg nil 'vi-state)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
679 |
18129 | 680 ;; Escape to STATE mode for one Emacs command. |
19078 | 681 (defun viper-escape-to-state (arg events state) |
18129 | 682 ;;(let (com key prefix-arg) |
683 (let (com key) | |
684 ;; this temporarily turns off Viper's minor mode keymaps | |
19078 | 685 (viper-set-mode-vars-for state) |
686 (viper-normalize-minor-mode-map-alist) | |
687 (if events (viper-set-unread-command-events events)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
688 |
18129 | 689 ;; protect against keyboard quit and other errors |
690 (condition-case nil | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
691 (let (viper-vi-kbd-minor-mode |
19078 | 692 viper-insert-kbd-minor-mode |
693 viper-emacs-kbd-minor-mode) | |
18129 | 694 (unwind-protect |
695 (progn | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
696 (setq com (key-binding (setq key |
19078 | 697 (if viper-xemacs-p |
18129 | 698 (read-key-sequence nil) |
699 (read-key-sequence nil t))))) | |
700 ;; In case of binding indirection--chase definitions. | |
701 ;; Have to do it here because we execute this command under | |
702 ;; different keymaps, so command-execute may not do the | |
703 ;; right thing there | |
704 (while (vectorp com) (setq com (key-binding com)))) | |
705 nil) | |
706 ;; Execute command com in the original Viper state, not in state | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
707 ;; `state'. Otherwise, if we switch buffers while executing the |
18129 | 708 ;; escaped to command, Viper's mode vars will remain those of |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
709 ;; `state'. When we return to the orig buffer, the bindings will be |
18129 | 710 ;; screwed up. |
19078 | 711 (viper-set-mode-vars-for viper-current-state) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
712 |
18129 | 713 ;; this-command, last-command-char, last-command-event |
714 (setq this-command com) | |
19078 | 715 (if viper-xemacs-p ; XEmacs represents key sequences as vectors |
716 (setq last-command-event | |
717 (viper-copy-event (viper-seq-last-elt key)) | |
18129 | 718 last-command-char (event-to-character last-command-event)) |
719 ;; Emacs represents them as sequences (str or vec) | |
19078 | 720 (setq last-command-event |
721 (viper-copy-event (viper-seq-last-elt key)) | |
18129 | 722 last-command-char last-command-event)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
723 |
18129 | 724 (if (commandp com) |
725 (progn | |
726 (setq prefix-arg (or prefix-arg arg)) | |
727 (command-execute com))) | |
728 ) | |
729 (quit (ding)) | |
730 (error (beep 1)))) | |
731 ;; set state in the new buffer | |
19078 | 732 (viper-set-mode-vars-for viper-current-state)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
733 |
19078 | 734 (defun viper-exec-form-in-vi (form) |
18129 | 735 "Execute FORM in Vi state, regardless of the Ccurrent Vi state." |
736 (let ((buff (current-buffer)) | |
737 result) | |
19078 | 738 (viper-set-mode-vars-for 'vi-state) |
18129 | 739 |
740 (condition-case nil | |
19078 | 741 (let (viper-vi-kbd-minor-mode) ; execute without kbd macros |
742 (setq result (eval form)) | |
743 ) | |
18129 | 744 (error |
745 (signal 'quit nil))) | |
746 | |
747 (if (not (equal buff (current-buffer))) ; cmd switched buffer | |
748 (save-excursion | |
749 (set-buffer buff) | |
19078 | 750 (viper-set-mode-vars-for viper-current-state))) |
751 (viper-set-mode-vars-for viper-current-state) | |
18129 | 752 result)) |
753 | |
19078 | 754 (defun viper-exec-form-in-emacs (form) |
18129 | 755 "Execute FORM in Emacs, temporarily disabling Viper's minor modes. |
19078 | 756 Similar to viper-escape-to-emacs, but accepts forms rather than keystrokes." |
18129 | 757 (let ((buff (current-buffer)) |
758 result) | |
19078 | 759 (viper-set-mode-vars-for 'emacs-state) |
18129 | 760 (setq result (eval form)) |
761 (if (not (equal buff (current-buffer))) ; cmd switched buffer | |
762 (save-excursion | |
763 (set-buffer buff) | |
19078 | 764 (viper-set-mode-vars-for viper-current-state))) |
765 (viper-set-mode-vars-for viper-current-state) | |
18129 | 766 result)) |
767 | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
768 |
18129 | 769 ;; This is needed because minor modes sometimes override essential Viper |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
770 ;; bindings. By letting Viper know which files these modes are in, it will |
18129 | 771 ;; arrange to reorganize minor-mode-map-alist so that things will work right. |
19078 | 772 (defun viper-harness-minor-mode (load-file) |
18129 | 773 "Familiarize Viper with a minor mode defined in LOAD_FILE. |
774 Minor modes that have their own keymaps may overshadow Viper keymaps. | |
775 This function is designed to make Viper aware of the packages that define | |
776 such minor modes. | |
777 Usage: | |
19078 | 778 (viper-harness-minor-mode load-file) |
18129 | 779 |
780 LOAD-FILE is a name of the file where the specific minor mode is defined. | |
781 Suffixes such as .el or .elc should be stripped." | |
782 | |
783 (interactive "sEnter name of the load file: ") | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
784 |
19078 | 785 (eval-after-load load-file '(viper-normalize-minor-mode-map-alist)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
786 |
18129 | 787 ;; Change the default for minor-mode-map-alist each time a harnessed minor |
788 ;; mode adds its own keymap to the a-list. | |
19078 | 789 (eval-after-load |
18129 | 790 load-file '(setq-default minor-mode-map-alist minor-mode-map-alist)) |
791 ) | |
792 | |
793 | |
19078 | 794 (defun viper-ESC (arg) |
18129 | 795 "Emulate ESC key in Emacs. |
19078 | 796 Prevents multiple escape keystrokes if viper-no-multiple-ESC is true. |
797 If viper-no-multiple-ESC is 'twice double ESC would ding in vi-state. | |
18129 | 798 Other ESC sequences are emulated via the current Emacs's major mode |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
799 keymap. This is more convenient on TTYs, since this won't block |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
800 function keys such as up,down, etc. ESC will also will also work as |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
801 a Meta key in this case. When viper-no-multiple-ESC is nil, ESC functions |
18129 | 802 as a Meta key and any number of multiple escapes is allowed." |
803 (interactive "P") | |
804 (let (char) | |
19078 | 805 (cond ((and (not viper-no-multiple-ESC) (eq viper-current-state 'vi-state)) |
806 (setq char (viper-read-char-exclusive)) | |
807 (viper-escape-to-emacs arg (list ?\e char) )) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
808 ((and (eq viper-no-multiple-ESC 'twice) |
19078 | 809 (eq viper-current-state 'vi-state)) |
810 (setq char (viper-read-char-exclusive)) | |
811 (if (= char (string-to-char viper-ESC-key)) | |
18129 | 812 (ding) |
19078 | 813 (viper-escape-to-emacs arg (list ?\e char) ))) |
18129 | 814 (t (ding))) |
815 )) | |
816 | |
19078 | 817 (defun viper-alternate-Meta-key (arg) |
18129 | 818 "Simulate Emacs Meta key." |
819 (interactive "P") | |
820 (sit-for 1) (message "ESC-") | |
19078 | 821 (viper-escape-to-emacs arg '(?\e))) |
822 | |
823 (defun viper-toggle-key-action () | |
824 "Action bound to `viper-toggle-key'." | |
18129 | 825 (interactive) |
19078 | 826 (if (and (< viper-expert-level 2) (equal viper-toggle-key "\C-z")) |
827 (if (viper-window-display-p) | |
828 (viper-iconify) | |
18129 | 829 (suspend-emacs)) |
19078 | 830 (viper-change-state-to-emacs))) |
18129 | 831 |
832 | |
833 ;; Intercept ESC sequences on dumb terminals. | |
834 ;; Based on the idea contributed by Marcelino Veiga Tuimil <mveiga@dit.upm.es> | |
835 | |
836 ;; Check if last key was ESC and if so try to reread it as a function key. | |
837 ;; But only if there are characters to read during a very short time. | |
838 ;; Returns the last event, if any. | |
19078 | 839 (defun viper-envelop-ESC-key () |
18129 | 840 (let ((event last-input-event) |
841 (keyseq [nil]) | |
842 inhibit-quit) | |
19078 | 843 (if (viper-ESC-event-p event) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
844 (progn |
19078 | 845 (if (viper-fast-keysequence-p) |
18129 | 846 (progn |
847 (let (minor-mode-map-alist) | |
19078 | 848 (viper-set-unread-command-events event) |
18129 | 849 (setq keyseq |
850 (funcall | |
851 (ad-get-orig-definition 'read-key-sequence) nil)) | |
852 ) ; let | |
853 ;; If keyseq translates into something that still has ESC | |
854 ;; at the beginning, separate ESC from the rest of the seq. | |
855 ;; In XEmacs we check for events that are keypress meta-key | |
856 ;; and convert them into [escape key] | |
857 ;; | |
858 ;; This is needed for the following reason: | |
859 ;; If ESC is the first symbol, we interpret it as if the | |
860 ;; user typed ESC and then quickly some other symbols. | |
861 ;; If ESC is not the first one, then the key sequence | |
862 ;; entered was apparently translated into a function key or | |
863 ;; something (e.g., one may have | |
864 ;; (define-key function-key-map "\e[192z" [f11]) | |
865 ;; which would translate the escape-sequence generated by | |
866 ;; f11 in an xterm window into the symbolic key f11. | |
867 ;; | |
868 ;; If `first-key' is not an ESC event, we make it into the | |
869 ;; last-command-event in order to pretend that this key was | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
870 ;; pressed. This is needed to allow arrow keys to be bound to |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
871 ;; macros. Otherwise, viper-exec-mapped-kbd-macro will think |
19078 | 872 ;; that the last event was ESC and so it'll execute whatever is |
18129 | 873 ;; bound to ESC. (Viper macros can't be bound to |
874 ;; ESC-sequences). | |
875 (let* ((first-key (elt keyseq 0)) | |
876 (key-mod (event-modifiers first-key))) | |
19078 | 877 (cond ((viper-ESC-event-p first-key) |
18129 | 878 ;; put keys following ESC on the unread list |
879 ;; and return ESC as the key-sequence | |
19078 | 880 (viper-set-unread-command-events (subseq keyseq 1)) |
18129 | 881 (setq last-input-event event |
19078 | 882 keyseq (if viper-emacs-p |
18129 | 883 "\e" |
884 (vector (character-to-event ?\e))))) | |
19078 | 885 ((and viper-xemacs-p |
18129 | 886 (key-press-event-p first-key) |
887 (equal '(meta) key-mod)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
888 (viper-set-unread-command-events |
18129 | 889 (vconcat (vector |
890 (character-to-event (event-key first-key))) | |
891 (subseq keyseq 1))) | |
892 (setq last-input-event event | |
893 keyseq (vector (character-to-event ?\e)))) | |
894 ((eventp first-key) | |
19078 | 895 (setq last-command-event |
896 (viper-copy-event first-key))) | |
18129 | 897 )) |
898 ) ; end progn | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
899 |
18129 | 900 ;; this is escape event with nothing after it |
901 ;; put in unread-command-event and then re-read | |
19078 | 902 (viper-set-unread-command-events event) |
18129 | 903 (setq keyseq |
904 (funcall (ad-get-orig-definition 'read-key-sequence) nil)) | |
905 )) | |
906 ;; not an escape event | |
907 (setq keyseq (vector event))) | |
908 keyseq)) | |
909 | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
910 |
18129 | 911 |
912 ;; Listen to ESC key. | |
913 ;; If a sequence of keys starting with ESC is issued with very short delays, | |
914 ;; interpret these keys in Emacs mode, so ESC won't be interpreted as a Vi key. | |
19078 | 915 (defun viper-intercept-ESC-key () |
18129 | 916 "Function that implements ESC key in Viper emulation of Vi." |
917 (interactive) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
918 (let ((cmd (or (key-binding (viper-envelop-ESC-key)) |
18129 | 919 '(lambda () (interactive) (error ""))))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
920 |
18129 | 921 ;; call the actual function to execute ESC (if no other symbols followed) |
922 ;; or the key bound to the ESC sequence (if the sequence was issued | |
923 ;; with very short delay between characters. | |
19078 | 924 (if (eq cmd 'viper-intercept-ESC-key) |
18129 | 925 (setq cmd |
19078 | 926 (cond ((eq viper-current-state 'vi-state) |
927 'viper-ESC) | |
928 ((eq viper-current-state 'insert-state) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
929 'viper-exit-insert-state) |
19078 | 930 ((eq viper-current-state 'replace-state) |
931 'viper-replace-state-exit-cmd) | |
932 (t 'viper-change-state-to-vi) | |
18129 | 933 ))) |
934 (call-interactively cmd))) | |
935 | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
936 |
18129 | 937 |
938 | |
939 ;; prefix argument for Vi mode | |
940 | |
941 ;; In Vi mode, prefix argument is a dotted pair (NUM . COM) where NUM | |
942 ;; represents the numeric value of the prefix argument and COM represents | |
943 ;; command prefix such as "c", "d", "m" and "y". | |
944 | |
945 ;; Get value part of prefix-argument ARG. | |
19078 | 946 (defsubst viper-p-val (arg) |
18129 | 947 (cond ((null arg) 1) |
948 ((consp arg) | |
949 (if (or (null (car arg)) (equal (car arg) '(nil))) | |
950 1 (car arg))) | |
951 (t arg))) | |
952 | |
953 ;; Get raw value part of prefix-argument ARG. | |
19078 | 954 (defsubst viper-P-val (arg) |
18129 | 955 (cond ((consp arg) (car arg)) |
956 (t arg))) | |
957 | |
958 ;; Get com part of prefix-argument ARG. | |
19078 | 959 (defsubst viper-getcom (arg) |
18129 | 960 (cond ((null arg) nil) |
961 ((consp arg) (cdr arg)) | |
962 (t nil))) | |
963 | |
964 ;; Get com part of prefix-argument ARG and modify it. | |
19078 | 965 (defun viper-getCom (arg) |
966 (let ((com (viper-getcom arg))) | |
967 (cond ((equal com ?c) ?c) | |
968 ;; Previously, ?c was being converted to ?C, but this prevented | |
969 ;; multiline replace regions. | |
970 ;;((equal com ?c) ?C) | |
18129 | 971 ((equal com ?d) ?D) |
972 ((equal com ?y) ?Y) | |
973 (t com)))) | |
974 | |
975 | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
976 ;; Compute numeric prefix arg value. |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
977 ;; Invoked by EVENT. COM is the command part obtained so far. |
21940 | 978 (defun viper-prefix-arg-value (event-char com) |
19078 | 979 (let ((viper-intermediate-command 'viper-digit-argument) |
980 value func) | |
18129 | 981 ;; read while number |
21940 | 982 (while (and (viper-characterp event-char) |
983 (>= event-char ?0) (<= event-char ?9)) | |
984 (setq value (+ (* (if (integerp value) value 0) 10) (- event-char ?0))) | |
985 (setq event-char (viper-read-event-convert-to-char))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
986 |
18129 | 987 (setq prefix-arg value) |
988 (if com (setq prefix-arg (cons prefix-arg com))) | |
21940 | 989 (while (eq event-char ?U) |
19078 | 990 (viper-describe-arg prefix-arg) |
21940 | 991 (setq event-char (viper-read-event-convert-to-char))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
992 |
19078 | 993 (if (or com (and (not (eq viper-current-state 'vi-state)) |
18129 | 994 ;; make sure it is a Vi command |
21940 | 995 (viper-characterp event-char) |
996 (viper-vi-command-p event-char) | |
18129 | 997 )) |
998 ;; If appears to be one of the vi commands, | |
999 ;; then execute it with funcall and clear prefix-arg in order to not | |
1000 ;; confuse subsequent commands | |
1001 (progn | |
1002 ;; last-command-char is the char we want emacs to think was typed | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1003 ;; last. If com is not nil, the viper-digit-argument command was |
19078 | 1004 ;; called from within viper-prefix-arg command, such as `d', `w', |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1005 ;; etc., i.e., the user typed, say, d2. In this case, `com' would be |
19078 | 1006 ;; `d', `w', etc. If viper-digit-argument was invoked by |
1007 ;; viper-escape-to-vi (which is indicated by the fact that the | |
21940 | 1008 ;; current state is not vi-state), then `event-char' represents the |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1009 ;; vi command to be executed (e.g., `d', `w', etc). Again, |
19078 | 1010 ;; last-command-char must make emacs believe that this is the command |
1011 ;; we typed. | |
21940 | 1012 (cond ((eq event-char 'return) (setq event-char ?\C-m)) |
1013 ((eq event-char 'delete) (setq event-char ?\C-?)) | |
1014 ((eq event-char 'backspace) (setq event-char ?\C-h)) | |
1015 ((eq event-char 'space) (setq event-char ?\ ))) | |
1016 (setq last-command-char (or com event-char)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1017 (setq func (viper-exec-form-in-vi |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1018 `(key-binding (char-to-string ,event-char)))) |
18129 | 1019 (funcall func prefix-arg) |
1020 (setq prefix-arg nil)) | |
26588
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1021 ;; some other command -- let emacs do it in its own way |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1022 (viper-set-unread-command-events event-char)) |
18129 | 1023 )) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1024 |
18129 | 1025 |
1026 ;; Vi operator as prefix argument." | |
19078 | 1027 (defun viper-prefix-arg-com (char value com) |
18129 | 1028 (let ((cont t) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1029 cmd-info |
18958 | 1030 cmd-to-exec-at-end) |
18129 | 1031 (while (and cont |
1032 (memq char | |
1033 (list ?c ?d ?y ?! ?< ?> ?= ?# ?r ?R ?\" | |
19078 | 1034 viper-buffer-search-char))) |
18129 | 1035 (if com |
1036 ;; this means that we already have a command character, so we | |
1037 ;; construct a com list and exit while. however, if char is " | |
1038 ;; it is an error. | |
1039 (progn | |
1040 ;; new com is (CHAR . OLDCOM) | |
1041 (if (memq char '(?# ?\")) (error "")) | |
1042 (setq com (cons char com)) | |
1043 (setq cont nil)) | |
26588
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1044 ;; If com is nil we set com as char, and read more. Again, if char is |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1045 ;; ", we read the name of register and store it in viper-use-register. |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1046 ;; if char is !, =, or #, a complete com is formed so we exit the while |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1047 ;; loop. |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1048 (cond ((memq char '(?! ?=)) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1049 (setq com char) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1050 (setq char (read-char)) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1051 (setq cont nil)) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1052 ((= char ?#) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1053 ;; read a char and encode it as com |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1054 (setq com (+ 128 (read-char))) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1055 (setq char (read-char))) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1056 ((= char ?\") |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1057 (let ((reg (read-char))) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1058 (if (viper-valid-register reg) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1059 (setq viper-use-register reg) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1060 (error "")) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1061 (setq char (read-char)))) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1062 (t |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1063 (setq com char) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1064 (setq char (read-char)))))) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1065 |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1066 (if (atom com) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1067 ;; `com' is a single char, so we construct the command argument |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1068 ;; and if `char' is `?', we describe the arg; otherwise |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1069 ;; we prepare the command that will be executed at the end. |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1070 (progn |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1071 (setq cmd-info (cons value com)) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1072 (while (= char ?U) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1073 (viper-describe-arg cmd-info) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1074 (setq char (read-char))) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1075 ;; `char' is a movement cmd, a digit arg cmd, or a register cmd---so we |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1076 ;; execute it at the very end |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1077 (or (viper-movement-command-p char) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1078 (viper-digit-command-p char) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1079 (viper-regsuffix-command-p char) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1080 (= char ?!) ; bang command |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1081 (error "")) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1082 (setq cmd-to-exec-at-end |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1083 (viper-exec-form-in-vi |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1084 `(key-binding (char-to-string ,char))))) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1085 |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1086 ;; as com is non-nil, this means that we have a command to execute |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1087 (if (memq (car com) '(?r ?R)) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1088 ;; execute apropriate region command. |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1089 (let ((char (car com)) (com (cdr com))) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1090 (setq prefix-arg (cons value com)) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1091 (if (= char ?r) (viper-region prefix-arg) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1092 (viper-Region prefix-arg)) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1093 ;; reset prefix-arg |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1094 (setq prefix-arg nil)) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1095 ;; otherwise, reset prefix arg and call appropriate command |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1096 (setq value (if (null value) 1 value)) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1097 (setq prefix-arg nil) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1098 (cond |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1099 ;; If we change ?C to ?c here, then cc will enter replacement mode |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1100 ;; rather than deleting lines. However, it will affect 1 less line than |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1101 ;; normal. We decided to not use replacement mode here and follow Vi, |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1102 ;; since replacement mode on n full lines can be achieved with nC. |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1103 ((equal com '(?c . ?c)) (viper-line (cons value ?C))) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1104 ((equal com '(?d . ?d)) (viper-line (cons value ?D))) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1105 ((equal com '(?d . ?y)) (viper-yank-defun)) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1106 ((equal com '(?y . ?y)) (viper-line (cons value ?Y))) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1107 ((equal com '(?< . ?<)) (viper-line (cons value ?<))) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1108 ((equal com '(?> . ?>)) (viper-line (cons value ?>))) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1109 ((equal com '(?! . ?!)) (viper-line (cons value ?!))) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1110 ((equal com '(?= . ?=)) (viper-line (cons value ?=))) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1111 (t (error ""))))) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1112 |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1113 (if cmd-to-exec-at-end |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1114 (progn |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1115 (setq last-command-char char) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1116 (setq last-command-event |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1117 (viper-copy-event |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1118 (if viper-xemacs-p (character-to-event char) char))) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1119 (condition-case nil |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1120 (funcall cmd-to-exec-at-end cmd-info) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1121 (error |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1122 (error ""))))) |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1123 )) |
18129 | 1124 |
19078 | 1125 (defun viper-describe-arg (arg) |
18129 | 1126 (let (val com) |
19078 | 1127 (setq val (viper-P-val arg) |
1128 com (viper-getcom arg)) | |
18129 | 1129 (if (null val) |
1130 (if (null com) | |
1131 (message "Value is nil, and command is nil") | |
1132 (message "Value is nil, and command is `%c'" com)) | |
1133 (if (null com) | |
1134 (message "Value is `%d', and command is nil" val) | |
1135 (message "Value is `%d', and command is `%c'" val com))))) | |
1136 | |
19078 | 1137 (defun viper-digit-argument (arg) |
18129 | 1138 "Begin numeric argument for the next command." |
1139 (interactive "P") | |
19078 | 1140 (viper-leave-region-active) |
1141 (viper-prefix-arg-value | |
18129 | 1142 last-command-char (if (consp arg) (cdr arg) nil))) |
1143 | |
19078 | 1144 (defun viper-command-argument (arg) |
18129 | 1145 "Accept a motion command as an argument." |
1146 (interactive "P") | |
19078 | 1147 (let ((viper-intermediate-command 'viper-command-argument)) |
18129 | 1148 (condition-case nil |
19078 | 1149 (viper-prefix-arg-com |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1150 last-command-char |
18129 | 1151 (cond ((null arg) nil) |
1152 ((consp arg) (car arg)) | |
1153 ((integerp arg) arg) | |
19078 | 1154 (t (error viper-InvalidCommandArgument))) |
18129 | 1155 (cond ((null arg) nil) |
1156 ((consp arg) (cdr arg)) | |
1157 ((integerp arg) nil) | |
19078 | 1158 (t (error viper-InvalidCommandArgument)))) |
1159 (quit (setq viper-use-register nil) | |
18129 | 1160 (signal 'quit nil))) |
19078 | 1161 (viper-deactivate-mark))) |
18129 | 1162 |
1163 | |
1164 ;; repeat last destructive command | |
1165 | |
1166 ;; Append region to text in register REG. | |
1167 ;; START and END are buffer positions indicating what to append. | |
19078 | 1168 (defsubst viper-append-to-register (reg start end) |
18129 | 1169 (set-register reg (concat (if (stringp (get-register reg)) |
1170 (get-register reg) "") | |
1171 (buffer-substring start end)))) | |
1172 | |
19078 | 1173 ;; Saves last inserted text for possible use by viper-repeat command. |
1174 (defun viper-save-last-insertion (beg end) | |
19756 | 1175 (condition-case nil |
1176 (setq viper-last-insertion (buffer-substring beg end)) | |
1177 (error | |
1178 ;; beg or end marker are somehow screwed up | |
1179 (setq viper-last-insertion nil))) | |
19078 | 1180 (setq viper-last-insertion (buffer-substring beg end)) |
1181 (or (< (length viper-d-com) 5) | |
1182 (setcar (nthcdr 4 viper-d-com) viper-last-insertion)) | |
1183 (or (null viper-command-ring) | |
1184 (ring-empty-p viper-command-ring) | |
18129 | 1185 (progn |
19078 | 1186 (setcar (nthcdr 4 (viper-current-ring-item viper-command-ring)) |
1187 viper-last-insertion) | |
18129 | 1188 ;; del most recent elt, if identical to the second most-recent |
19078 | 1189 (viper-cleanup-ring viper-command-ring))) |
18129 | 1190 ) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1191 |
19078 | 1192 (defsubst viper-yank-last-insertion () |
1193 "Inserts the text saved by the previous viper-save-last-insertion command." | |
18129 | 1194 (condition-case nil |
19078 | 1195 (insert viper-last-insertion) |
18129 | 1196 (error nil))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1197 |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1198 |
18129 | 1199 ;; define functions to be executed |
1200 | |
1201 ;; invoked by the `C' command | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1202 (defun viper-exec-change (m-com com) |
19078 | 1203 (or (and (markerp viper-com-point) (marker-position viper-com-point)) |
1204 (set-marker viper-com-point (point) (current-buffer))) | |
18129 | 1205 ;; handle C cmd at the eol and at eob. |
19078 | 1206 (if (or (and (eolp) (= viper-com-point (point))) |
1207 (= viper-com-point (point-max))) | |
18129 | 1208 (progn |
1209 (insert " ")(backward-char 1))) | |
19078 | 1210 (if (= viper-com-point (point)) |
1211 (viper-forward-char-carefully)) | |
1212 (set-mark viper-com-point) | |
1213 (if (eq m-com 'viper-next-line-at-bol) | |
1214 (viper-enlarge-region (mark t) (point))) | |
1215 (if (< (point) (mark t)) | |
1216 (exchange-point-and-mark)) | |
1217 (if (eq (preceding-char) ?\n) | |
1218 (viper-backward-char-carefully)) ; give back the newline | |
18129 | 1219 (if (= com ?c) |
19078 | 1220 (viper-change (mark t) (point)) |
1221 (viper-change-subr (mark t) (point)))) | |
1222 | |
1223 ;; this is invoked by viper-substitute-line | |
1224 (defun viper-exec-Change (m-com com) | |
18129 | 1225 (save-excursion |
19078 | 1226 (set-mark viper-com-point) |
1227 (viper-enlarge-region (mark t) (point)) | |
1228 (if viper-use-register | |
18129 | 1229 (progn |
19078 | 1230 (cond ((viper-valid-register viper-use-register '(letter digit)) |
18129 | 1231 (copy-to-register |
19078 | 1232 viper-use-register (mark t) (point) nil)) |
1233 ((viper-valid-register viper-use-register '(Letter)) | |
1234 (viper-append-to-register | |
1235 (downcase viper-use-register) (mark t) (point))) | |
1236 (t (setq viper-use-register nil) | |
1237 (error viper-InvalidRegister viper-use-register))) | |
1238 (setq viper-use-register nil))) | |
18129 | 1239 (delete-region (mark t) (point))) |
1240 (open-line 1) | |
19078 | 1241 (if (= com ?C) |
1242 (viper-change-state-to-insert) | |
1243 (viper-yank-last-insertion))) | |
1244 | |
1245 (defun viper-exec-delete (m-com com) | |
1246 (or (and (markerp viper-com-point) (marker-position viper-com-point)) | |
1247 (set-marker viper-com-point (point) (current-buffer))) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1248 (let (chars-deleted) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1249 (if viper-use-register |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1250 (progn |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1251 (cond ((viper-valid-register viper-use-register '(letter digit)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1252 (copy-to-register |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1253 viper-use-register viper-com-point (point) nil)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1254 ((viper-valid-register viper-use-register '(Letter)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1255 (viper-append-to-register |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1256 (downcase viper-use-register) viper-com-point (point))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1257 (t (setq viper-use-register nil) |
19078 | 1258 (error viper-InvalidRegister viper-use-register))) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1259 (setq viper-use-register nil))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1260 (setq last-command |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1261 (if (eq last-command 'd-command) 'kill-region nil)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1262 (setq chars-deleted (abs (- (point) viper-com-point))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1263 (if (> chars-deleted viper-change-notification-threshold) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1264 (message "Deleted %d characters" chars-deleted)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1265 (kill-region viper-com-point (point)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1266 (setq this-command 'd-command) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1267 (if viper-ex-style-motion |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1268 (if (and (eolp) (not (bolp))) (backward-char 1))))) |
18129 | 1269 |
19078 | 1270 (defun viper-exec-Delete (m-com com) |
18129 | 1271 (save-excursion |
19078 | 1272 (set-mark viper-com-point) |
1273 (viper-enlarge-region (mark t) (point)) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1274 (let (lines-deleted) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1275 (if viper-use-register |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1276 (progn |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1277 (cond ((viper-valid-register viper-use-register '(letter digit)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1278 (copy-to-register |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1279 viper-use-register (mark t) (point) nil)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1280 ((viper-valid-register viper-use-register '(Letter)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1281 (viper-append-to-register |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1282 (downcase viper-use-register) (mark t) (point))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1283 (t (setq viper-use-register nil) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1284 (error viper-InvalidRegister viper-use-register))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1285 (setq viper-use-register nil))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1286 (setq last-command |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1287 (if (eq last-command 'D-command) 'kill-region nil)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1288 (setq lines-deleted (count-lines (point) viper-com-point)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1289 (if (> lines-deleted viper-change-notification-threshold) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1290 (message "Deleted %d lines" lines-deleted)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1291 (kill-region (mark t) (point)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1292 (if (eq m-com 'viper-line) (setq this-command 'D-command))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1293 (back-to-indentation))) |
18129 | 1294 |
21940 | 1295 ;; save region |
19078 | 1296 (defun viper-exec-yank (m-com com) |
1297 (or (and (markerp viper-com-point) (marker-position viper-com-point)) | |
1298 (set-marker viper-com-point (point) (current-buffer))) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1299 (let (chars-saved) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1300 (if viper-use-register |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1301 (progn |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1302 (cond ((viper-valid-register viper-use-register '(letter digit)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1303 (copy-to-register |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1304 viper-use-register viper-com-point (point) nil)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1305 ((viper-valid-register viper-use-register '(Letter)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1306 (viper-append-to-register |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1307 (downcase viper-use-register) viper-com-point (point))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1308 (t (setq viper-use-register nil) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1309 (error viper-InvalidRegister viper-use-register))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1310 (setq viper-use-register nil))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1311 (setq last-command nil) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1312 (copy-region-as-kill viper-com-point (point)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1313 (setq chars-saved (abs (- (point) viper-com-point))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1314 (if (> chars-saved viper-change-notification-threshold) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1315 (message "Saved %d characters" chars-saved)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1316 (goto-char viper-com-point))) |
19078 | 1317 |
21940 | 1318 ;; save lines |
19078 | 1319 (defun viper-exec-Yank (m-com com) |
18129 | 1320 (save-excursion |
19078 | 1321 (set-mark viper-com-point) |
1322 (viper-enlarge-region (mark t) (point)) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1323 (let (lines-saved) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1324 (if viper-use-register |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1325 (progn |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1326 (cond ((viper-valid-register viper-use-register '(letter digit)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1327 (copy-to-register |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1328 viper-use-register (mark t) (point) nil)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1329 ((viper-valid-register viper-use-register '(Letter)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1330 (viper-append-to-register |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1331 (downcase viper-use-register) (mark t) (point))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1332 (t (setq viper-use-register nil) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1333 (error viper-InvalidRegister viper-use-register))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1334 (setq viper-use-register nil))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1335 (setq last-command nil) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1336 (copy-region-as-kill (mark t) (point)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1337 (setq lines-saved (count-lines (mark t) (point))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1338 (if (> lines-saved viper-change-notification-threshold) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1339 (message "Saved %d lines" lines-saved)))) |
19078 | 1340 (viper-deactivate-mark) |
1341 (goto-char viper-com-point)) | |
1342 | |
1343 (defun viper-exec-bang (m-com com) | |
18129 | 1344 (save-excursion |
19078 | 1345 (set-mark viper-com-point) |
1346 (viper-enlarge-region (mark t) (point)) | |
18958 | 1347 (exchange-point-and-mark) |
18129 | 1348 (shell-command-on-region |
1349 (mark t) (point) | |
1350 (if (= com ?!) | |
19078 | 1351 (setq viper-last-shell-com |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1352 (viper-read-string-with-history |
18129 | 1353 "!" |
1354 nil | |
19078 | 1355 'viper-shell-history |
1356 (car viper-shell-history) | |
18129 | 1357 )) |
19078 | 1358 viper-last-shell-com) |
18129 | 1359 t))) |
1360 | |
19078 | 1361 (defun viper-exec-equals (m-com com) |
18129 | 1362 (save-excursion |
19078 | 1363 (set-mark viper-com-point) |
1364 (viper-enlarge-region (mark t) (point)) | |
18129 | 1365 (if (> (mark t) (point)) (exchange-point-and-mark)) |
1366 (indent-region (mark t) (point) nil))) | |
1367 | |
19078 | 1368 (defun viper-exec-shift (m-com com) |
18129 | 1369 (save-excursion |
19078 | 1370 (set-mark viper-com-point) |
1371 (viper-enlarge-region (mark t) (point)) | |
18129 | 1372 (if (> (mark t) (point)) (exchange-point-and-mark)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1373 (indent-rigidly (mark t) (point) |
18129 | 1374 (if (= com ?>) |
19078 | 1375 viper-shift-width |
1376 (- viper-shift-width)))) | |
18129 | 1377 ;; return point to where it was before shift |
19078 | 1378 (goto-char viper-com-point)) |
18129 | 1379 |
1380 ;; this is needed because some commands fake com by setting it to ?r, which | |
1381 ;; denotes repeated insert command. | |
19078 | 1382 (defsubst viper-exec-dummy (m-com com) |
18129 | 1383 nil) |
1384 | |
19078 | 1385 (defun viper-exec-buffer-search (m-com com) |
1386 (setq viper-s-string (buffer-substring (point) viper-com-point)) | |
1387 (setq viper-s-forward t) | |
1388 (setq viper-search-history (cons viper-s-string viper-search-history)) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1389 (setq viper-intermediate-command 'viper-exec-buffer-search) |
19078 | 1390 (viper-search viper-s-string viper-s-forward 1)) |
1391 | |
1392 (defvar viper-exec-array (make-vector 128 nil)) | |
18129 | 1393 |
1394 ;; Using a dispatch array allows adding functions like buffer search | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1395 ;; without affecting other functions. Buffer search can now be bound |
18129 | 1396 ;; to any character. |
1397 | |
19078 | 1398 (aset viper-exec-array ?c 'viper-exec-change) |
1399 (aset viper-exec-array ?C 'viper-exec-Change) | |
1400 (aset viper-exec-array ?d 'viper-exec-delete) | |
1401 (aset viper-exec-array ?D 'viper-exec-Delete) | |
1402 (aset viper-exec-array ?y 'viper-exec-yank) | |
1403 (aset viper-exec-array ?Y 'viper-exec-Yank) | |
1404 (aset viper-exec-array ?r 'viper-exec-dummy) | |
1405 (aset viper-exec-array ?! 'viper-exec-bang) | |
1406 (aset viper-exec-array ?< 'viper-exec-shift) | |
1407 (aset viper-exec-array ?> 'viper-exec-shift) | |
1408 (aset viper-exec-array ?= 'viper-exec-equals) | |
18129 | 1409 |
1410 | |
1411 | |
1412 ;; This function is called by various movement commands to execute a | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1413 ;; destructive command on the region specified by the movement command. For |
19078 | 1414 ;; instance, if the user types cw, then the command viper-forward-word will |
1415 ;; call viper-execute-com to execute viper-exec-change, which eventually will | |
1416 ;; call viper-change to invoke the replace mode on the region. | |
18129 | 1417 ;; |
19078 | 1418 ;; The var viper-d-com is set to (M-COM VAL COM REG INSETED-TEXT COMMAND-KEYS) |
1419 ;; via a call to viper-set-destructive-command, for later use by viper-repeat. | |
1420 (defun viper-execute-com (m-com val com) | |
1421 (let ((reg viper-use-register)) | |
18129 | 1422 ;; this is the special command `#' |
1423 (if (> com 128) | |
19078 | 1424 (viper-special-prefix-com (- com 128)) |
1425 (let ((fn (aref viper-exec-array (if (< com 0) (- com) com)))) | |
18129 | 1426 (if (null fn) |
19078 | 1427 (error "%c: %s" com viper-InvalidViCommand) |
18129 | 1428 (funcall fn m-com com)))) |
19078 | 1429 (if (viper-dotable-command-p com) |
1430 (viper-set-destructive-command | |
18129 | 1431 (list m-com val |
1432 (if (memq com (list ?c ?C ?!)) (- com) com) | |
1433 reg nil nil))) | |
1434 )) | |
1435 | |
1436 | |
19078 | 1437 (defun viper-repeat (arg) |
18129 | 1438 "Re-execute last destructive command. |
19078 | 1439 Use the info in viper-d-com, which has the form |
18129 | 1440 \(com val ch reg inserted-text command-keys\), |
1441 where `com' is the command to be re-executed, `val' is the | |
1442 argument to `com', `ch' is a flag for repeat, and `reg' is optional; | |
1443 if it exists, it is the name of the register for `com'. | |
1444 If the prefix argument, ARG, is non-nil, it is used instead of `val'." | |
1445 (interactive "P") | |
1446 (let ((save-point (point)) ; save point before repeating prev cmd | |
1447 ;; Pass along that we are repeating a destructive command | |
19078 | 1448 ;; This tells viper-set-destructive-command not to update |
1449 ;; viper-command-ring | |
1450 (viper-intermediate-command 'viper-repeat)) | |
1451 (if (eq last-command 'viper-undo) | |
1452 ;; if the last command was viper-undo, then undo-more | |
1453 (viper-undo-more) | |
1454 ;; otherwise execute the command stored in viper-d-com. if arg is | |
1455 ;; non-nil its prefix value is used as new prefix value for the command. | |
1456 (let ((m-com (car viper-d-com)) | |
1457 (val (viper-P-val arg)) | |
1458 (com (nth 2 viper-d-com)) | |
1459 (reg (nth 3 viper-d-com))) | |
1460 (if (null val) (setq val (nth 1 viper-d-com))) | |
18129 | 1461 (if (null m-com) (error "No previous command to repeat.")) |
19078 | 1462 (setq viper-use-register reg) |
1463 (if (nth 4 viper-d-com) ; text inserted by command | |
1464 (setq viper-last-insertion (nth 4 viper-d-com) | |
1465 viper-d-char (nth 4 viper-d-com))) | |
18129 | 1466 (funcall m-com (cons val com)) |
19078 | 1467 (cond ((and (< save-point (point)) viper-keep-point-on-repeat) |
18839 | 1468 (goto-char save-point)) ; go back to before repeat. |
19462 | 1469 ((and (< save-point (point)) viper-ex-style-editing) |
18839 | 1470 (or (bolp) (backward-char 1)))) |
18129 | 1471 (if (and (eolp) (not (bolp))) |
1472 (backward-char 1)) | |
1473 )) | |
19462 | 1474 (viper-adjust-undo) ; take care of undo |
18129 | 1475 ;; If the prev cmd was rotating the command ring, this means that `.' has |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1476 ;; just executed a command from that ring. So, push it on the ring again. |
19078 | 1477 ;; If we are just executing previous command , then don't push viper-d-com |
1478 ;; because viper-d-com is not fully constructed in this case (its keys and | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1479 ;; the inserted text may be nil). Besides, in this case, the command |
18129 | 1480 ;; executed by `.' is already on the ring. |
19078 | 1481 (if (eq last-command 'viper-display-current-destructive-command) |
1482 (viper-push-onto-ring viper-d-com 'viper-command-ring)) | |
1483 (viper-deactivate-mark) | |
18129 | 1484 )) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1485 |
19078 | 1486 (defun viper-repeat-from-history () |
18129 | 1487 "Repeat a destructive command from history. |
19078 | 1488 Doesn't change viper-command-ring in any way, so `.' will work as before |
18129 | 1489 executing this command. |
1490 This command is supposed to be bound to a two-character Vi macro where | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1491 the second character is a digit 0 to 9. The digit indicates which |
18129 | 1492 history command to execute. `<char>0' is equivalent to `.', `<char>1' |
1493 invokes the command before that, etc." | |
1494 (interactive) | |
19078 | 1495 (let* ((viper-intermediate-command 'repeating-display-destructive-command) |
1496 (idx (cond (viper-this-kbd-macro | |
18129 | 1497 (string-to-number |
19078 | 1498 (symbol-name (elt viper-this-kbd-macro 1)))) |
18129 | 1499 (t 0))) |
1500 (num idx) | |
19078 | 1501 (viper-d-com viper-d-com)) |
18129 | 1502 |
1503 (or (and (numberp num) (<= 0 num) (<= num 9)) | |
1504 (progn | |
1505 (setq idx 0 | |
1506 num 0) | |
1507 (message | |
19078 | 1508 "`viper-repeat-from-history' must be invoked as a Vi macro bound to `<key><digit>'"))) |
18129 | 1509 (while (< 0 num) |
19078 | 1510 (setq viper-d-com (viper-special-ring-rotate1 viper-command-ring -1)) |
18129 | 1511 (setq num (1- num))) |
19078 | 1512 (viper-repeat nil) |
18129 | 1513 (while (> idx num) |
19078 | 1514 (viper-special-ring-rotate1 viper-command-ring 1) |
18129 | 1515 (setq num (1+ num))) |
1516 )) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1517 |
18129 | 1518 |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1519 ;; The hash-command. It is invoked interactively by the key sequence #<char>. |
19078 | 1520 ;; The chars that can follow `#' are determined by viper-hash-command-p |
1521 (defun viper-special-prefix-com (char) | |
18129 | 1522 (cond ((= char ?c) |
19078 | 1523 (downcase-region (min viper-com-point (point)) |
1524 (max viper-com-point (point)))) | |
18129 | 1525 ((= char ?C) |
19078 | 1526 (upcase-region (min viper-com-point (point)) |
1527 (max viper-com-point (point)))) | |
18129 | 1528 ((= char ?g) |
19078 | 1529 (push-mark viper-com-point t) |
1530 (viper-global-execute)) | |
18129 | 1531 ((= char ?q) |
19078 | 1532 (push-mark viper-com-point t) |
1533 (viper-quote-region)) | |
1534 ((= char ?s) (funcall viper-spell-function viper-com-point (point))) | |
1535 (t (error "#%c: %s" char viper-InvalidViCommand)))) | |
18129 | 1536 |
1537 | |
1538 ;; undoing | |
1539 | |
19078 | 1540 (defun viper-undo () |
18129 | 1541 "Undo previous change." |
1542 (interactive) | |
1543 (message "undo!") | |
1544 (let ((modified (buffer-modified-p)) | |
1545 (before-undo-pt (point-marker)) | |
1546 (after-change-functions after-change-functions) | |
1547 undo-beg-posn undo-end-posn) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1548 |
18129 | 1549 ;; no need to remove this hook, since this var has scope inside a let. |
1550 (add-hook 'after-change-functions | |
1551 '(lambda (beg end len) | |
1552 (setq undo-beg-posn beg | |
1553 undo-end-posn (or end beg)))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1554 |
18129 | 1555 (undo-start) |
1556 (undo-more 2) | |
1557 (setq undo-beg-posn (or undo-beg-posn before-undo-pt) | |
1558 undo-end-posn (or undo-end-posn undo-beg-posn)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1559 |
18129 | 1560 (goto-char undo-beg-posn) |
1561 (sit-for 0) | |
19078 | 1562 (if (and viper-keep-point-on-undo |
18129 | 1563 (pos-visible-in-window-p before-undo-pt)) |
1564 (progn | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1565 (push-mark (point-marker) t) |
19078 | 1566 (viper-sit-for-short 300) |
18129 | 1567 (goto-char undo-end-posn) |
19078 | 1568 (viper-sit-for-short 300) |
19462 | 1569 (if (and (> (viper-chars-in-region undo-beg-posn before-undo-pt) 1) |
1570 (> (viper-chars-in-region undo-end-posn before-undo-pt) 1)) | |
18129 | 1571 (goto-char before-undo-pt) |
1572 (goto-char undo-beg-posn))) | |
1573 (push-mark before-undo-pt t)) | |
1574 (if (and (eolp) (not (bolp))) (backward-char 1)) | |
1575 (if (not modified) (set-buffer-modified-p t))) | |
19078 | 1576 (setq this-command 'viper-undo)) |
18129 | 1577 |
1578 ;; Continue undoing previous changes. | |
19078 | 1579 (defun viper-undo-more () |
18129 | 1580 (message "undo more!") |
1581 (condition-case nil | |
1582 (undo-more 1) | |
1583 (error (beep) | |
1584 (message "No further undo information in this buffer"))) | |
1585 (if (and (eolp) (not (bolp))) (backward-char 1)) | |
19078 | 1586 (setq this-command 'viper-undo)) |
18129 | 1587 |
1588 ;; The following two functions are used to set up undo properly. | |
1589 ;; In VI, unlike Emacs, if you open a line, say, and add a bunch of lines, | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1590 ;; they are undone all at once. |
19078 | 1591 (defun viper-adjust-undo () |
19462 | 1592 (if viper-undo-needs-adjustment |
1593 (let ((inhibit-quit t) | |
1594 tmp tmp2) | |
1595 (setq viper-undo-needs-adjustment nil) | |
1596 (if (listp buffer-undo-list) | |
1597 (if (setq tmp (memq viper-buffer-undo-list-mark buffer-undo-list)) | |
1598 (progn | |
1599 (setq tmp2 (cdr tmp)) ; the part after mark | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1600 |
19462 | 1601 ;; cut tail from buffer-undo-list temporarily by direct |
1602 ;; manipulation with pointers in buffer-undo-list | |
1603 (setcdr tmp nil) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1604 |
19462 | 1605 (setq buffer-undo-list (delq nil buffer-undo-list)) |
1606 (setq buffer-undo-list | |
1607 (delq viper-buffer-undo-list-mark buffer-undo-list)) | |
1608 ;; restore tail of buffer-undo-list | |
1609 (setq buffer-undo-list (nconc buffer-undo-list tmp2))) | |
1610 (setq buffer-undo-list (delq nil buffer-undo-list))))) | |
1611 )) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1612 |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1613 |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1614 (defun viper-set-complex-command-for-undo () |
18129 | 1615 (if (listp buffer-undo-list) |
19078 | 1616 (if (not viper-undo-needs-adjustment) |
18129 | 1617 (let ((inhibit-quit t)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1618 (setq buffer-undo-list |
19078 | 1619 (cons viper-buffer-undo-list-mark buffer-undo-list)) |
1620 (setq viper-undo-needs-adjustment t))))) | |
18129 | 1621 |
1622 | |
1623 | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1624 |
19078 | 1625 (defun viper-display-current-destructive-command () |
1626 (let ((text (nth 4 viper-d-com)) | |
1627 (keys (nth 5 viper-d-com)) | |
18129 | 1628 (max-text-len 30)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1629 |
19078 | 1630 (setq this-command 'viper-display-current-destructive-command) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1631 |
18129 | 1632 (message " `.' runs %s%s" |
19078 | 1633 (concat "`" (viper-array-to-string keys) "'") |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1634 (viper-abbreviate-string |
19079 | 1635 (if viper-xemacs-p |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1636 (replace-in-string |
19462 | 1637 (cond ((characterp text) (char-to-string text)) |
1638 ((stringp text) text) | |
1639 (t "")) | |
1640 "\n" "^J") | |
19079 | 1641 text) |
1642 max-text-len | |
1643 " inserting `" "'" " .......")) | |
18129 | 1644 )) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1645 |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1646 |
19078 | 1647 ;; don't change viper-d-com if it was viper-repeat command invoked with `.' |
18129 | 1648 ;; or in some other way (non-interactively). |
19078 | 1649 (defun viper-set-destructive-command (list) |
1650 (or (eq viper-intermediate-command 'viper-repeat) | |
18129 | 1651 (progn |
19078 | 1652 (setq viper-d-com list) |
1653 (setcar (nthcdr 5 viper-d-com) | |
1654 (viper-array-to-string (if (arrayp viper-this-command-keys) | |
1655 viper-this-command-keys | |
1656 (this-command-keys)))) | |
1657 (viper-push-onto-ring viper-d-com 'viper-command-ring))) | |
1658 (setq viper-this-command-keys nil)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1659 |
26588
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1660 |
19078 | 1661 (defun viper-prev-destructive-command (next) |
18129 | 1662 "Find previous destructive command in the history of destructive commands. |
1663 With prefix argument, find next destructive command." | |
1664 (interactive "P") | |
19078 | 1665 (let (cmd viper-intermediate-command) |
1666 (if (eq last-command 'viper-display-current-destructive-command) | |
18129 | 1667 ;; repeated search through command history |
19078 | 1668 (setq viper-intermediate-command |
1669 'repeating-display-destructive-command) | |
18129 | 1670 ;; first search through command history--set temp ring |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1671 (setq viper-temp-command-ring (copy-list viper-command-ring))) |
18129 | 1672 (setq cmd (if next |
19078 | 1673 (viper-special-ring-rotate1 viper-temp-command-ring 1) |
1674 (viper-special-ring-rotate1 viper-temp-command-ring -1))) | |
18129 | 1675 (if (null cmd) |
1676 () | |
19078 | 1677 (setq viper-d-com cmd)) |
1678 (viper-display-current-destructive-command))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1679 |
26588
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1680 |
19078 | 1681 (defun viper-next-destructive-command () |
18129 | 1682 "Find next destructive command in the history of destructive commands." |
1683 (interactive) | |
19078 | 1684 (viper-prev-destructive-command 'next)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1685 |
26588
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1686 |
19078 | 1687 (defun viper-insert-prev-from-insertion-ring (arg) |
18129 | 1688 "Cycle through insertion ring in the direction of older insertions. |
1689 Undoes previous insertion and inserts new. | |
1690 With prefix argument, cycles in the direction of newer elements. | |
1691 In minibuffer, this command executes whatever the invocation key is bound | |
1692 to in the global map, instead of cycling through the insertion ring." | |
1693 (interactive "P") | |
19078 | 1694 (let (viper-intermediate-command) |
1695 (if (eq last-command 'viper-insert-from-insertion-ring) | |
18129 | 1696 (progn ; repeated search through insertion history |
19078 | 1697 (setq viper-intermediate-command 'repeating-insertion-from-ring) |
1698 (if (eq viper-current-state 'replace-state) | |
18129 | 1699 (undo 1) |
19078 | 1700 (if viper-last-inserted-string-from-insertion-ring |
18129 | 1701 (backward-delete-char |
19078 | 1702 (length viper-last-inserted-string-from-insertion-ring)))) |
18129 | 1703 ) |
1704 ;;first search through insertion history | |
19078 | 1705 (setq viper-temp-insertion-ring (copy-list viper-insertion-ring))) |
1706 (setq this-command 'viper-insert-from-insertion-ring) | |
18129 | 1707 ;; so that things will be undone properly |
1708 (setq buffer-undo-list (cons nil buffer-undo-list)) | |
19078 | 1709 (setq viper-last-inserted-string-from-insertion-ring |
1710 (viper-special-ring-rotate1 viper-temp-insertion-ring (if arg 1 -1))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1711 |
19078 | 1712 ;; this change of viper-intermediate-command must come after |
1713 ;; viper-special-ring-rotate1, so that the ring will rotate, but before the | |
18129 | 1714 ;; insertion. |
19078 | 1715 (setq viper-intermediate-command nil) |
1716 (if viper-last-inserted-string-from-insertion-ring | |
1717 (insert viper-last-inserted-string-from-insertion-ring)) | |
18129 | 1718 )) |
1719 | |
19078 | 1720 (defun viper-insert-next-from-insertion-ring () |
18129 | 1721 "Cycle through insertion ring in the direction of older insertions. |
1722 Undo previous insertion and inserts new." | |
1723 (interactive) | |
19078 | 1724 (viper-insert-prev-from-insertion-ring 'next)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1725 |
26588
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1726 |
18129 | 1727 |
1728 ;; some region utilities | |
1729 | |
1730 ;; If at the last line of buffer, add \\n before eob, if newline is missing. | |
19078 | 1731 (defun viper-add-newline-at-eob-if-necessary () |
18129 | 1732 (save-excursion |
1733 (end-of-line) | |
1734 ;; make sure all lines end with newline, unless in the minibuffer or | |
1735 ;; when requested otherwise (require-final-newline is nil) | |
1736 (if (and (eobp) | |
1737 (not (bolp)) | |
1738 require-final-newline | |
19078 | 1739 (not (viper-is-in-minibuffer)) |
18129 | 1740 (not buffer-read-only)) |
1741 (insert "\n")))) | |
1742 | |
19078 | 1743 (defun viper-yank-defun () |
18129 | 1744 (mark-defun) |
1745 (copy-region-as-kill (point) (mark t))) | |
1746 | |
1747 ;; Enlarge region between BEG and END. | |
19078 | 1748 (defun viper-enlarge-region (beg end) |
18129 | 1749 (or beg (setq beg end)) ; if beg is nil, set to end |
1750 (or end (setq end beg)) ; if end is nil, set to beg | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1751 |
18129 | 1752 (if (< beg end) |
1753 (progn (goto-char beg) (set-mark end)) | |
1754 (goto-char end) | |
1755 (set-mark beg)) | |
1756 (beginning-of-line) | |
1757 (exchange-point-and-mark) | |
1758 (if (or (not (eobp)) (not (bolp))) (forward-line 1)) | |
1759 (if (not (eobp)) (beginning-of-line)) | |
1760 (if (> beg end) (exchange-point-and-mark))) | |
1761 | |
1762 | |
1763 ;; Quote region by each line with a user supplied string. | |
19078 | 1764 (defun viper-quote-region () |
20343 | 1765 (let ((quote-str viper-quote-string) |
1766 (donot-change-dafault t)) | |
1767 (setq quote-str | |
1768 (viper-read-string-with-history | |
1769 "Quote string: " | |
1770 nil | |
1771 'viper-quote-region-history | |
1772 (cond ((string-match "tex.*-mode" (symbol-name major-mode)) "%%") | |
1773 ((string-match "java.*-mode" (symbol-name major-mode)) "//") | |
1774 ((string-match "perl.*-mode" (symbol-name major-mode)) "#") | |
1775 ((string-match "lisp.*-mode" (symbol-name major-mode)) ";;") | |
1776 ((memq major-mode '(c-mode cc-mode c++-mode)) "//") | |
1777 ((memq major-mode '(sh-mode shell-mode)) "#") | |
1778 (t (setq donot-change-dafault nil) | |
1779 quote-str)))) | |
1780 (or donot-change-dafault | |
1781 (setq viper-quote-string quote-str)) | |
1782 (viper-enlarge-region (point) (mark t)) | |
1783 (if (> (point) (mark t)) (exchange-point-and-mark)) | |
1784 (insert quote-str) | |
18129 | 1785 (beginning-of-line) |
20343 | 1786 (forward-line 1) |
1787 (while (and (< (point) (mark t)) (bolp)) | |
1788 (insert quote-str) | |
1789 (beginning-of-line) | |
1790 (forward-line 1)))) | |
18129 | 1791 |
1792 ;; Tells whether BEG is on the same line as END. | |
1793 ;; If one of the args is nil, it'll return nil. | |
19078 | 1794 (defun viper-same-line (beg end) |
18129 | 1795 (let ((selective-display nil) |
1796 (incr 0) | |
1797 temp) | |
1798 (if (and beg end (> beg end)) | |
1799 (setq temp beg | |
1800 beg end | |
1801 end temp)) | |
1802 (if (and beg end) | |
1803 (cond ((or (> beg (point-max)) (> end (point-max))) ; out of range | |
1804 nil) | |
1805 (t | |
1806 ;; This 'if' is needed because Emacs treats the next empty line | |
1807 ;; as part of the previous line. | |
19078 | 1808 (if (= (viper-line-pos 'start) end) |
18129 | 1809 (setq incr 1)) |
1810 (<= (+ incr (count-lines beg end)) 1)))) | |
1811 )) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1812 |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1813 |
18129 | 1814 ;; Check if the string ends with a newline. |
19078 | 1815 (defun viper-end-with-a-newline-p (string) |
18129 | 1816 (or (string= string "") |
19078 | 1817 (= (viper-seq-last-elt string) ?\n))) |
1818 | |
1819 (defun viper-tmp-insert-at-eob (msg) | |
18129 | 1820 (let ((savemax (point-max))) |
1821 (goto-char savemax) | |
1822 (insert msg) | |
1823 (sit-for 2) | |
1824 (goto-char savemax) (delete-region (point) (point-max)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1825 )) |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1826 |
18129 | 1827 |
1828 | |
1829 ;;; Minibuffer business | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1830 |
19078 | 1831 (defsubst viper-set-minibuffer-style () |
1832 (add-hook 'minibuffer-setup-hook 'viper-minibuffer-setup-sentinel)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1833 |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1834 |
19078 | 1835 (defun viper-minibuffer-setup-sentinel () |
1836 (let ((hook (if viper-vi-style-in-minibuffer | |
1837 'viper-change-state-to-insert | |
1838 'viper-change-state-to-emacs))) | |
18129 | 1839 (funcall hook) |
1840 )) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1841 |
26588
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
1842 |
19756 | 1843 ;; Interpret last event in the local map first; if fails, use exit-minibuffer. |
1844 ;; Run viper-minibuffer-exit-hook before exiting. | |
19078 | 1845 (defun viper-exit-minibuffer () |
19756 | 1846 "Exit minibuffer Viper way." |
18129 | 1847 (interactive) |
1848 (let (command) | |
1849 (setq command (local-key-binding (char-to-string last-command-char))) | |
19756 | 1850 (run-hooks 'viper-minibuffer-exit-hook) |
18129 | 1851 (if command |
1852 (command-execute command) | |
1853 (exit-minibuffer)))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1854 |
19756 | 1855 |
1856 (defcustom viper-smart-suffix-list | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1857 '("" "tex" "c" "cc" "C" "el" "java" "html" "htm" "pl" "flr" "P" "p") |
19905
9a4cdbf423ea
(viper-smart-suffix-list): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents:
19891
diff
changeset
|
1858 "*List of suffixes that Viper tries to append to filenames ending with a `.'. |
19756 | 1859 This is useful when you the current directory contains files with the same |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1860 prefix and many different suffixes. Usually, only one of the suffixes |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1861 represents an editable file. However, file completion will stop at the `.' |
19756 | 1862 The smart suffix feature lets you hit RET in such a case, and Viper will |
1863 select the appropriate suffix. | |
1864 | |
1865 Suffixes are tried in the order given and the first suffix for which a | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1866 corresponding file exists is selected. If no file exists for any of the |
19756 | 1867 suffixes, the user is asked to confirm. |
1868 | |
1869 To turn this feature off, set this variable to nil." | |
19905
9a4cdbf423ea
(viper-smart-suffix-list): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents:
19891
diff
changeset
|
1870 :type '(repeat string) |
20003 | 1871 :group 'viper-misc) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1872 |
19756 | 1873 |
1874 ;; Try to add a suitable suffix to files whose name ends with a `.' | |
1875 ;; Useful when the user hits RET on a non-completed file name. | |
1876 ;; Used as a minibuffer exit hook in read-file-name | |
1877 (defun viper-file-add-suffix () | |
1878 (let ((count 0) | |
1879 (len (length viper-smart-suffix-list)) | |
1880 (file (buffer-string)) | |
1881 found key cmd suff) | |
1882 (goto-char (point-max)) | |
1883 (if (and viper-smart-suffix-list (string-match "\\.$" file)) | |
1884 (progn | |
1885 (while (and (not found) (< count len)) | |
1886 (setq suff (nth count viper-smart-suffix-list) | |
1887 count (1+ count)) | |
1888 (if (file-exists-p | |
1889 (format "%s%s" (substitute-in-file-name file) suff)) | |
1890 (progn | |
1891 (setq found t) | |
1892 (insert suff)))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1893 |
19756 | 1894 (if found |
1895 () | |
1896 (viper-tmp-insert-at-eob " [Please complete file name]") | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1897 (unwind-protect |
19756 | 1898 (while (not (memq cmd |
1899 '(exit-minibuffer viper-exit-minibuffer))) | |
1900 (setq cmd | |
1901 (key-binding (setq key (read-key-sequence nil)))) | |
1902 (cond ((eq cmd 'self-insert-command) | |
1903 (if viper-xemacs-p | |
1904 (insert (events-to-keys key)) | |
1905 (insert key))) | |
1906 ((memq cmd '(exit-minibuffer viper-exit-minibuffer)) | |
1907 nil) | |
1908 (t (command-execute cmd))) | |
1909 ))) | |
1910 )))) | |
1911 | |
1912 | |
1913 (defun viper-minibuffer-trim-tail () | |
1914 "Delete junk at the end of the first line of the minibuffer input. | |
1915 Remove this function from `viper-minibuffer-exit-hook', if this causes | |
1916 problems." | |
1917 (if (viper-is-in-minibuffer) | |
1918 (progn | |
1919 (goto-char (point-min)) | |
1920 (end-of-line) | |
1921 (delete-region (point) (point-max))))) | |
1922 | |
18129 | 1923 |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1924 ;;; Reading string with history |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1925 |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1926 (defun viper-read-string-with-history (prompt &optional initial |
20343 | 1927 history-var default keymap |
1928 init-message) | |
18129 | 1929 ;; Read string, prompting with PROMPT and inserting the INITIAL |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1930 ;; value. Uses HISTORY-VAR. DEFAULT is the default value to accept if the |
20343 | 1931 ;; input is an empty string. |
18129 | 1932 ;; Default value is displayed until the user types something in the |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1933 ;; minibuffer. |
20343 | 1934 ;; KEYMAP is used, if given, instead of minibuffer-local-map. |
1935 ;; INIT-MESSAGE is the message temporarily displayed after entering the | |
1936 ;; minibuffer. | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1937 (let ((minibuffer-setup-hook |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1938 (lambda () |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1939 (if (stringp init-message) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1940 (viper-tmp-insert-at-eob init-message)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1941 (if (stringp initial) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1942 (progn |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1943 ;; don't wait if we have unread events or in kbd macro |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1944 (or unread-command-events |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1945 executing-kbd-macro |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1946 (sit-for 840)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1947 (erase-buffer) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1948 (insert initial))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1949 (viper-minibuffer-setup-sentinel))) |
18129 | 1950 (val "") |
1951 (padding "") | |
1952 temp-msg) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1953 |
18129 | 1954 (setq keymap (or keymap minibuffer-local-map) |
1955 initial (or initial "") | |
1956 temp-msg (if default | |
1957 (format "(default: %s) " default) | |
1958 "")) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1959 |
19078 | 1960 (setq viper-incomplete-ex-cmd nil) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1961 (setq val (read-from-minibuffer prompt |
18129 | 1962 (concat temp-msg initial val padding) |
1963 keymap nil history-var)) | |
1964 (setq minibuffer-setup-hook nil | |
19078 | 1965 padding (viper-array-to-string (this-command-keys)) |
18129 | 1966 temp-msg "") |
1967 ;; the following tries to be smart about what to put in history | |
1968 (if (not (string= val (car (eval history-var)))) | |
1969 (set history-var (cons val (eval history-var)))) | |
1970 (if (or (string= (nth 0 (eval history-var)) (nth 1 (eval history-var))) | |
1971 (string= (nth 0 (eval history-var)) "")) | |
1972 (set history-var (cdr (eval history-var)))) | |
19078 | 1973 ;; If the user enters nothing but the prev cmd wasn't viper-ex, |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1974 ;; viper-command-argument, or `! shell-command', this probably means |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
1975 ;; that the user typed something then erased. Return "" in this case, not |
18129 | 1976 ;; the default---the default is too confusing in this case. |
1977 (cond ((and (string= val "") | |
1978 (not (string= prompt "!")) ; was a `! shell-command' | |
1979 (not (memq last-command | |
19078 | 1980 '(viper-ex |
1981 viper-command-argument | |
18129 | 1982 t) |
1983 ))) | |
1984 "") | |
1985 ((string= val "") (or default "")) | |
1986 (t val)) | |
1987 )) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
1988 |
18129 | 1989 |
1990 | |
1991 ;; insertion commands | |
1992 | |
1993 ;; Called when state changes from Insert Vi command mode. | |
1994 ;; Repeats the insertion command if Insert state was entered with prefix | |
1995 ;; argument > 1. | |
19078 | 1996 (defun viper-repeat-insert-command () |
1997 (let ((i-com (car viper-d-com)) | |
1998 (val (nth 1 viper-d-com)) | |
1999 (char (nth 2 viper-d-com))) | |
18129 | 2000 (if (and val (> val 1)) ; first check that val is non-nil |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2001 (progn |
19078 | 2002 (setq viper-d-com (list i-com (1- val) ?r nil nil nil)) |
2003 (viper-repeat nil) | |
2004 (setq viper-d-com (list i-com val char nil nil nil)) | |
18129 | 2005 )))) |
2006 | |
19078 | 2007 (defun viper-insert (arg) |
18129 | 2008 "Insert before point." |
2009 (interactive "P") | |
19078 | 2010 (viper-set-complex-command-for-undo) |
2011 (let ((val (viper-p-val arg)) | |
2012 (com (viper-getcom arg))) | |
2013 (viper-set-destructive-command (list 'viper-insert val ?r nil nil nil)) | |
18129 | 2014 (if com |
19078 | 2015 (viper-loop val (viper-yank-last-insertion)) |
2016 (viper-change-state-to-insert)))) | |
2017 | |
2018 (defun viper-append (arg) | |
18129 | 2019 "Append after point." |
2020 (interactive "P") | |
19078 | 2021 (viper-set-complex-command-for-undo) |
2022 (let ((val (viper-p-val arg)) | |
2023 (com (viper-getcom arg))) | |
2024 (viper-set-destructive-command (list 'viper-append val ?r nil nil nil)) | |
18129 | 2025 (if (not (eolp)) (forward-char)) |
2026 (if (equal com ?r) | |
19078 | 2027 (viper-loop val (viper-yank-last-insertion)) |
2028 (viper-change-state-to-insert)))) | |
2029 | |
2030 (defun viper-Append (arg) | |
18129 | 2031 "Append at end of line." |
2032 (interactive "P") | |
19078 | 2033 (viper-set-complex-command-for-undo) |
2034 (let ((val (viper-p-val arg)) | |
2035 (com (viper-getcom arg))) | |
2036 (viper-set-destructive-command (list 'viper-Append val ?r nil nil nil)) | |
18129 | 2037 (end-of-line) |
2038 (if (equal com ?r) | |
19078 | 2039 (viper-loop val (viper-yank-last-insertion)) |
2040 (viper-change-state-to-insert)))) | |
2041 | |
2042 (defun viper-Insert (arg) | |
18129 | 2043 "Insert before first non-white." |
2044 (interactive "P") | |
19078 | 2045 (viper-set-complex-command-for-undo) |
2046 (let ((val (viper-p-val arg)) | |
2047 (com (viper-getcom arg))) | |
2048 (viper-set-destructive-command (list 'viper-Insert val ?r nil nil nil)) | |
18129 | 2049 (back-to-indentation) |
2050 (if (equal com ?r) | |
19078 | 2051 (viper-loop val (viper-yank-last-insertion)) |
2052 (viper-change-state-to-insert)))) | |
2053 | |
2054 (defun viper-open-line (arg) | |
18129 | 2055 "Open line below." |
2056 (interactive "P") | |
19078 | 2057 (viper-set-complex-command-for-undo) |
2058 (let ((val (viper-p-val arg)) | |
2059 (com (viper-getcom arg))) | |
2060 (viper-set-destructive-command (list 'viper-open-line val ?r nil nil nil)) | |
18129 | 2061 (let ((col (current-indentation))) |
2062 (if (equal com ?r) | |
19078 | 2063 (viper-loop val |
18129 | 2064 (end-of-line) |
2065 (newline 1) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2066 (if viper-auto-indent |
18129 | 2067 (progn |
19078 | 2068 (setq viper-cted t) |
2069 (if viper-electric-mode | |
18129 | 2070 (indent-according-to-mode) |
2071 (indent-to col)) | |
2072 )) | |
19462 | 2073 (viper-yank-last-insertion)) |
18129 | 2074 (end-of-line) |
2075 (newline 1) | |
19078 | 2076 (if viper-auto-indent |
18129 | 2077 (progn |
19078 | 2078 (setq viper-cted t) |
2079 (if viper-electric-mode | |
18129 | 2080 (indent-according-to-mode) |
2081 (indent-to col)))) | |
19078 | 2082 (viper-change-state-to-insert))))) |
2083 | |
2084 (defun viper-Open-line (arg) | |
18129 | 2085 "Open line above." |
2086 (interactive "P") | |
19078 | 2087 (viper-set-complex-command-for-undo) |
2088 (let ((val (viper-p-val arg)) | |
2089 (com (viper-getcom arg))) | |
2090 (viper-set-destructive-command (list 'viper-Open-line val ?r nil nil nil)) | |
18129 | 2091 (let ((col (current-indentation))) |
2092 (if (equal com ?r) | |
19078 | 2093 (viper-loop val |
18129 | 2094 (beginning-of-line) |
2095 (open-line 1) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2096 (if viper-auto-indent |
18129 | 2097 (progn |
19078 | 2098 (setq viper-cted t) |
2099 (if viper-electric-mode | |
18129 | 2100 (indent-according-to-mode) |
2101 (indent-to col)) | |
2102 )) | |
19462 | 2103 (viper-yank-last-insertion)) |
18129 | 2104 (beginning-of-line) |
2105 (open-line 1) | |
19078 | 2106 (if viper-auto-indent |
18129 | 2107 (progn |
19078 | 2108 (setq viper-cted t) |
2109 (if viper-electric-mode | |
18129 | 2110 (indent-according-to-mode) |
2111 (indent-to col)) | |
2112 )) | |
19078 | 2113 (viper-change-state-to-insert))))) |
2114 | |
2115 (defun viper-open-line-at-point (arg) | |
18129 | 2116 "Open line at point." |
2117 (interactive "P") | |
19078 | 2118 (viper-set-complex-command-for-undo) |
2119 (let ((val (viper-p-val arg)) | |
2120 (com (viper-getcom arg))) | |
2121 (viper-set-destructive-command | |
2122 (list 'viper-open-line-at-point val ?r nil nil nil)) | |
18129 | 2123 (if (equal com ?r) |
19078 | 2124 (viper-loop val |
18129 | 2125 (open-line 1) |
19462 | 2126 (viper-yank-last-insertion)) |
18129 | 2127 (open-line 1) |
19078 | 2128 (viper-change-state-to-insert)))) |
2129 | |
2130 (defun viper-substitute (arg) | |
18129 | 2131 "Substitute characters." |
2132 (interactive "P") | |
19078 | 2133 (let ((val (viper-p-val arg)) |
2134 (com (viper-getcom arg))) | |
18129 | 2135 (push-mark nil t) |
2136 (forward-char val) | |
2137 (if (equal com ?r) | |
19078 | 2138 (viper-change-subr (mark t) (point)) |
2139 (viper-change (mark t) (point))) | |
2140 (viper-set-destructive-command (list 'viper-substitute val ?r nil nil nil)) | |
18129 | 2141 )) |
2142 | |
19078 | 2143 ;; Command bound to S |
2144 (defun viper-substitute-line (arg) | |
18129 | 2145 "Substitute lines." |
2146 (interactive "p") | |
19078 | 2147 (viper-set-complex-command-for-undo) |
2148 (viper-line (cons arg ?C))) | |
18129 | 2149 |
2150 ;; Prepare for replace | |
19078 | 2151 (defun viper-start-replace () |
2152 (setq viper-began-as-replace t | |
2153 viper-sitting-in-replace t | |
19462 | 2154 viper-replace-chars-to-delete 0) |
21940 | 2155 (add-hook |
2156 'viper-after-change-functions 'viper-replace-mode-spy-after t 'local) | |
2157 (add-hook | |
2158 'viper-before-change-functions 'viper-replace-mode-spy-before t 'local) | |
18129 | 2159 ;; this will get added repeatedly, but no harm |
19078 | 2160 (add-hook 'after-change-functions 'viper-after-change-sentinel t) |
2161 (add-hook 'before-change-functions 'viper-before-change-sentinel t) | |
21940 | 2162 (viper-move-marker-locally |
2163 'viper-last-posn-in-replace-region (viper-replace-start)) | |
2164 (add-hook | |
2165 'viper-post-command-hooks 'viper-replace-state-post-command-sentinel | |
2166 t 'local) | |
2167 (add-hook | |
2168 'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel t 'local) | |
18129 | 2169 ;; guard against a smartie who switched from R-replace to normal replace |
21940 | 2170 (remove-hook |
2171 'viper-post-command-hooks 'viper-R-state-post-command-sentinel 'local) | |
18129 | 2172 (if overwrite-mode (overwrite-mode nil)) |
2173 ) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2174 |
18129 | 2175 |
19078 | 2176 (defun viper-replace-mode-spy-before (beg end) |
19462 | 2177 (setq viper-replace-region-chars-deleted (viper-chars-in-region beg end)) |
2178 ) | |
2179 | |
2180 ;; Invoked as an after-change-function to calculate how many chars have to be | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
2181 ;; deleted. This function may be called several times within a single command, |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
2182 ;; if this command performs several separate buffer changes. Therefore, if |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
2183 ;; adds up the number of chars inserted and subtracts the number of chars |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2184 ;; deleted. |
19078 | 2185 (defun viper-replace-mode-spy-after (beg end length) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2186 (if (memq viper-intermediate-command |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
2187 '(dabbrev-expand hippie-expand repeating-insertion-from-ring)) |
19462 | 2188 ;; Take special care of text insertion from insertion ring inside |
2189 ;; replacement overlays. | |
18129 | 2190 (progn |
19078 | 2191 (setq viper-replace-chars-to-delete 0) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2192 (viper-move-marker-locally |
19078 | 2193 'viper-last-posn-in-replace-region (point))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2194 |
19462 | 2195 (let* ((real-end (min end (viper-replace-end))) |
2196 (column-shift (- (save-excursion (goto-char real-end) | |
2197 (current-column)) | |
2198 (save-excursion (goto-char beg) | |
2199 (current-column)))) | |
2200 (chars-deleted 0)) | |
2201 | |
2202 (if (> length 0) | |
2203 (setq chars-deleted viper-replace-region-chars-deleted)) | |
2204 (setq viper-replace-region-chars-deleted 0) | |
2205 (setq viper-replace-chars-to-delete | |
2206 (+ viper-replace-chars-to-delete | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2207 (- |
19462 | 2208 ;; if column shift is bigger, due to a TAB insertion, take |
2209 ;; column-shift instead of the number of inserted chars | |
2210 (max (viper-chars-in-region beg real-end) | |
2211 ;; This test accounts for Chinese/Japanese/... chars, | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
2212 ;; which occupy 2 columns instead of one. If we use |
19462 | 2213 ;; column-shift here, we may delete two chars instead of |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
2214 ;; one when the user types one Chinese character. |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
2215 ;; Deleting two would be OK, if they were European chars, |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
2216 ;; but it is not OK if they are Chinese chars. |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
2217 ;; Since it is hard to |
19462 | 2218 ;; figure out which characters are being deleted in any |
2219 ;; given region, we decided to treat Eastern and European | |
2220 ;; characters equally, even though Eastern chars may | |
2221 ;; occupy more columns. | |
2222 (if (memq this-command '(self-insert-command | |
2223 quoted-insert viper-insert-tab)) | |
2224 column-shift | |
2225 0)) | |
2226 ;; the number of deleted chars | |
2227 chars-deleted))) | |
2228 | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2229 (viper-move-marker-locally |
19078 | 2230 'viper-last-posn-in-replace-region |
19462 | 2231 (max (if (> end (viper-replace-end)) (viper-replace-end) end) |
19078 | 2232 (or (marker-position viper-last-posn-in-replace-region) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2233 (viper-replace-start)) |
18129 | 2234 )) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2235 |
18129 | 2236 ))) |
2237 | |
19462 | 2238 ;; Make sure we don't delete more than needed. |
2239 ;; This is executed at viper-last-posn-in-replace-region | |
2240 (defsubst viper-trim-replace-chars-to-delete-if-necessary () | |
2241 (setq viper-replace-chars-to-delete | |
2242 (max 0 | |
2243 (min viper-replace-chars-to-delete | |
2244 ;; Don't delete more than to the end of repl overlay | |
2245 (viper-chars-in-region | |
2246 (viper-replace-end) viper-last-posn-in-replace-region) | |
2247 ;; point is viper-last-posn-in-replace-region now | |
2248 ;; So, this limits deletion to the end of line | |
2249 (viper-chars-in-region (point) (viper-line-pos 'end)) | |
2250 )))) | |
2251 | |
2252 | |
2253 ;; Delete stuff between viper-last-posn-in-replace-region and the end of | |
2254 ;; viper-replace-overlay-marker, if viper-last-posn-in-replace-region is within | |
2255 ;; the overlay and current point is before the end of the overlay. | |
2256 ;; Don't delete anything if current point is past the end of the overlay. | |
2257 (defun viper-finish-change () | |
21940 | 2258 (remove-hook |
2259 'viper-after-change-functions 'viper-replace-mode-spy-after 'local) | |
2260 (remove-hook | |
2261 'viper-before-change-functions 'viper-replace-mode-spy-before 'local) | |
2262 (remove-hook | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2263 'viper-post-command-hooks 'viper-replace-state-post-command-sentinel 'local) |
21940 | 2264 (remove-hook |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2265 'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel 'local) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
2266 (viper-restore-cursor-color 'after-replace-mode) |
19078 | 2267 (setq viper-sitting-in-replace nil) ; just in case we'll need to know it |
18129 | 2268 (save-excursion |
19462 | 2269 (if (and viper-replace-overlay |
2270 (viper-pos-within-region viper-last-posn-in-replace-region | |
2271 (viper-replace-start) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2272 (viper-replace-end)) |
19462 | 2273 (< (point) (viper-replace-end))) |
2274 (delete-region | |
2275 viper-last-posn-in-replace-region (viper-replace-end)))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2276 |
19078 | 2277 (if (eq viper-current-state 'replace-state) |
2278 (viper-downgrade-to-insert)) | |
2279 ;; replace mode ended => nullify viper-last-posn-in-replace-region | |
2280 (viper-move-marker-locally 'viper-last-posn-in-replace-region nil) | |
2281 (viper-hide-replace-overlay) | |
2282 (viper-refresh-mode-line) | |
2283 (viper-put-string-on-kill-ring viper-last-replace-region) | |
18129 | 2284 ) |
2285 | |
2286 ;; Make STRING be the first element of the kill ring. | |
19078 | 2287 (defun viper-put-string-on-kill-ring (string) |
18129 | 2288 (setq kill-ring (cons string kill-ring)) |
2289 (if (> (length kill-ring) kill-ring-max) | |
2290 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)) | |
2291 (setq kill-ring-yank-pointer kill-ring)) | |
2292 | |
19078 | 2293 (defun viper-finish-R-mode () |
21940 | 2294 (remove-hook |
2295 'viper-post-command-hooks 'viper-R-state-post-command-sentinel 'local) | |
2296 (remove-hook | |
2297 'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel 'local) | |
19078 | 2298 (viper-downgrade-to-insert)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2299 |
19078 | 2300 (defun viper-start-R-mode () |
18129 | 2301 ;; Leave arg as 1, not t: XEmacs insists that it must be a pos number |
2302 (overwrite-mode 1) | |
21940 | 2303 (add-hook |
2304 'viper-post-command-hooks 'viper-R-state-post-command-sentinel t 'local) | |
2305 (add-hook | |
2306 'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel t 'local) | |
18129 | 2307 ;; guard against a smartie who switched from R-replace to normal replace |
21940 | 2308 (remove-hook |
2309 'viper-post-command-hooks 'viper-replace-state-post-command-sentinel 'local) | |
18129 | 2310 ) |
2311 | |
2312 | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2313 |
19078 | 2314 (defun viper-replace-state-exit-cmd () |
18129 | 2315 "Binding for keys that cause Replace state to switch to Vi or to Insert. |
2316 These keys are ESC, RET, and LineFeed" | |
2317 (interactive) | |
19462 | 2318 (if overwrite-mode ; if in replace mode invoked via 'R' |
19078 | 2319 (viper-finish-R-mode) |
19462 | 2320 (viper-finish-change)) |
18129 | 2321 (let (com) |
19078 | 2322 (if (eq this-command 'viper-intercept-ESC-key) |
2323 (setq com 'viper-exit-insert-state) | |
2324 (viper-set-unread-command-events last-input-char) | |
18129 | 2325 (setq com (key-binding (read-key-sequence nil)))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2326 |
18129 | 2327 (condition-case conds |
2328 (command-execute com) | |
2329 (error | |
19078 | 2330 (viper-message-conditions conds))) |
18129 | 2331 ) |
19078 | 2332 (viper-hide-replace-overlay)) |
2333 | |
2334 | |
2335 (defun viper-replace-state-carriage-return () | |
2336 "Carriage return in Viper replace state." | |
18129 | 2337 (interactive) |
2338 ;; If Emacs start supporting overlay maps, as it currently supports | |
19078 | 2339 ;; text-property maps, we could do away with viper-replace-minor-mode and |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
2340 ;; just have keymap attached to replace overlay. Then the "if part" of this |
18129 | 2341 ;; statement can be deleted. |
19078 | 2342 (if (or (< (point) (viper-replace-start)) |
2343 (> (point) (viper-replace-end))) | |
2344 (let (viper-replace-minor-mode com) | |
2345 (viper-set-unread-command-events last-input-char) | |
18129 | 2346 (setq com (key-binding (read-key-sequence nil))) |
2347 (condition-case conds | |
2348 (command-execute com) | |
2349 (error | |
19078 | 2350 (viper-message-conditions conds)))) |
2351 (if (not viper-allow-multiline-replace-regions) | |
2352 (viper-replace-state-exit-cmd) | |
2353 (if (viper-same-line (point) (viper-replace-end)) | |
2354 (viper-replace-state-exit-cmd) | |
2355 ;; delete the rest of line | |
2356 (delete-region (point) (viper-line-pos 'end)) | |
2357 (save-excursion | |
2358 (end-of-line) | |
2359 (if (eobp) (error "Last line in buffer"))) | |
2360 ;; skip to the next line | |
2361 (forward-line 1) | |
2362 (back-to-indentation) | |
2363 )))) | |
18129 | 2364 |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2365 |
18129 | 2366 ;; This is the function bound to 'R'---unlimited replace. |
2367 ;; Similar to Emacs's own overwrite-mode. | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2368 (defun viper-overwrite (arg) |
18129 | 2369 "Begin overwrite mode." |
2370 (interactive "P") | |
19078 | 2371 (let ((val (viper-p-val arg)) |
2372 (com (viper-getcom arg)) (len)) | |
2373 (viper-set-destructive-command (list 'viper-overwrite val ?r nil nil nil)) | |
18129 | 2374 (if com |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2375 (progn |
19078 | 2376 ;; Viper saves inserted text in viper-last-insertion |
2377 (setq len (length viper-last-insertion)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2378 (delete-char len) |
19078 | 2379 (viper-loop val (viper-yank-last-insertion))) |
2380 (setq last-command 'viper-overwrite) | |
2381 (viper-set-complex-command-for-undo) | |
2382 (viper-set-replace-overlay (point) (viper-line-pos 'end)) | |
2383 (viper-change-state-to-replace) | |
18129 | 2384 ))) |
2385 | |
2386 | |
2387 ;; line commands | |
2388 | |
19078 | 2389 (defun viper-line (arg) |
18129 | 2390 (let ((val (car arg)) |
2391 (com (cdr arg))) | |
19078 | 2392 (viper-move-marker-locally 'viper-com-point (point)) |
18129 | 2393 (if (not (eobp)) |
19078 | 2394 (viper-next-line-carefully (1- val))) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
2395 ;; the following ensures that dd, cc, D, yy will do the right thing on the |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
2396 ;; last line of buffer when this line has no \n. |
19078 | 2397 (viper-add-newline-at-eob-if-necessary) |
2398 (viper-execute-com 'viper-line val com)) | |
18129 | 2399 (if (and (eobp) (not (bobp))) (forward-line -1)) |
2400 ) | |
2401 | |
19078 | 2402 (defun viper-yank-line (arg) |
18129 | 2403 "Yank ARG lines (in Vi's sense)." |
2404 (interactive "P") | |
19078 | 2405 (let ((val (viper-p-val arg))) |
2406 (viper-line (cons val ?Y)))) | |
18129 | 2407 |
2408 | |
2409 ;; region commands | |
2410 | |
19078 | 2411 (defun viper-region (arg) |
18129 | 2412 "Execute command on a region." |
2413 (interactive "P") | |
19078 | 2414 (let ((val (viper-P-val arg)) |
2415 (com (viper-getcom arg))) | |
2416 (viper-move-marker-locally 'viper-com-point (point)) | |
18129 | 2417 (exchange-point-and-mark) |
19078 | 2418 (viper-execute-com 'viper-region val com))) |
2419 | |
2420 (defun viper-Region (arg) | |
18129 | 2421 "Execute command on a Region." |
2422 (interactive "P") | |
19078 | 2423 (let ((val (viper-P-val arg)) |
2424 (com (viper-getCom arg))) | |
2425 (viper-move-marker-locally 'viper-com-point (point)) | |
18129 | 2426 (exchange-point-and-mark) |
19078 | 2427 (viper-execute-com 'viper-Region val com))) |
2428 | |
2429 (defun viper-replace-char (arg) | |
18129 | 2430 "Replace the following ARG chars by the character read." |
2431 (interactive "P") | |
2432 (if (and (eolp) (bolp)) (error "No character to replace here")) | |
19078 | 2433 (let ((val (viper-p-val arg)) |
2434 (com (viper-getcom arg))) | |
2435 (viper-replace-char-subr com val) | |
18129 | 2436 (if (and (eolp) (not (bolp))) (forward-char 1)) |
19462 | 2437 (setq viper-this-command-keys |
2438 (format "%sr" (if (integerp arg) arg ""))) | |
19078 | 2439 (viper-set-destructive-command |
2440 (list 'viper-replace-char val ?r nil viper-d-char nil)) | |
18129 | 2441 )) |
2442 | |
19078 | 2443 (defun viper-replace-char-subr (com arg) |
19462 | 2444 (let (char) |
18129 | 2445 (setq char (if (equal com ?r) |
19078 | 2446 viper-d-char |
18129 | 2447 (read-char))) |
19462 | 2448 (let (inhibit-quit) ; preserve consistency of undo-list and iso-accents |
2449 (if (and viper-automatic-iso-accents (memq char '(?' ?\" ?^ ?~))) | |
2450 ;; get European characters | |
2451 (progn | |
2452 (viper-set-iso-accents-mode t) | |
2453 (viper-set-unread-command-events char) | |
2454 (setq char (aref (read-key-sequence nil) 0)) | |
2455 (viper-set-iso-accents-mode nil))) | |
2456 (viper-set-complex-command-for-undo) | |
2457 (if (eq char ?\C-m) (setq char ?\n)) | |
2458 (if (and viper-special-input-method (fboundp 'quail-start-translation)) | |
2459 ;; get Intl. characters | |
2460 (progn | |
2461 (viper-set-input-method t) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2462 (setq last-command-event |
19462 | 2463 (viper-copy-event |
2464 (if viper-xemacs-p (character-to-event char) char))) | |
2465 (delete-char 1 t) | |
2466 (condition-case nil | |
2467 (if com | |
2468 (insert char) | |
2469 (if viper-emacs-p | |
2470 (quail-start-translation 1) | |
2471 (quail-start-translation))) | |
2472 (error)) | |
2473 ;; quail translation failed | |
2474 (if (and (not (stringp quail-current-str)) | |
2475 (not (viper-characterp quail-current-str))) | |
2476 (progn | |
2477 (viper-adjust-undo) | |
2478 (undo-start) | |
2479 (undo-more 1) | |
2480 (viper-set-input-method nil) | |
2481 (error "Composing character failed, changes undone"))) | |
2482 ;; quail translation seems ok | |
2483 (or com | |
2484 ;;(setq char quail-current-str)) | |
2485 (setq char (viper-char-at-pos 'backward))) | |
2486 (setq viper-d-char char) | |
2487 (viper-loop (1- (if (> arg 0) arg (- arg))) | |
2488 (delete-char 1 t) | |
2489 (insert char)) | |
2490 (viper-set-input-method nil)) | |
2491 (delete-char arg t) | |
2492 (setq viper-d-char char) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2493 (viper-loop (if (> arg 0) arg (- arg)) |
19462 | 2494 (insert char))) |
2495 (viper-adjust-undo) | |
2496 (backward-char arg)))) | |
18129 | 2497 |
2498 | |
2499 ;; basic cursor movement. j, k, l, h commands. | |
2500 | |
19078 | 2501 (defun viper-forward-char (arg) |
18129 | 2502 "Move point right ARG characters (left if ARG negative). |
2503 On reaching end of line, stop and signal error." | |
2504 (interactive "P") | |
19078 | 2505 (viper-leave-region-active) |
2506 (let ((val (viper-p-val arg)) | |
2507 (com (viper-getcom arg))) | |
2508 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
2509 (if viper-ex-style-motion | |
18129 | 2510 (progn |
2511 ;; the boundary condition check gets weird here because | |
2512 ;; forward-char may be the parameter of a delete, and 'dl' works | |
2513 ;; just like 'x' for the last char on a line, so we have to allow | |
19078 | 2514 ;; the forward motion before the 'viper-execute-com', but, of |
18129 | 2515 ;; course, 'dl' doesn't work on an empty line, so we have to |
19078 | 2516 ;; catch that condition before 'viper-execute-com' |
18129 | 2517 (if (and (eolp) (bolp)) (error "") (forward-char val)) |
19078 | 2518 (if com (viper-execute-com 'viper-forward-char val com)) |
18129 | 2519 (if (eolp) (progn (backward-char 1) (error "")))) |
2520 (forward-char val) | |
19078 | 2521 (if com (viper-execute-com 'viper-forward-char val com))))) |
2522 | |
26588
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
2523 |
19078 | 2524 (defun viper-backward-char (arg) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2525 "Move point left ARG characters (right if ARG negative). |
18129 | 2526 On reaching beginning of line, stop and signal error." |
2527 (interactive "P") | |
19078 | 2528 (viper-leave-region-active) |
2529 (let ((val (viper-p-val arg)) | |
2530 (com (viper-getcom arg))) | |
2531 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
2532 (if viper-ex-style-motion | |
18129 | 2533 (progn |
2534 (if (bolp) (error "") (backward-char val)) | |
19078 | 2535 (if com (viper-execute-com 'viper-backward-char val com))) |
18129 | 2536 (backward-char val) |
19078 | 2537 (if com (viper-execute-com 'viper-backward-char val com))))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2538 |
26588
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
2539 |
18129 | 2540 ;; Like forward-char, but doesn't move at end of buffer. |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2541 ;; Returns distance traveled |
19462 | 2542 ;; (positive or 0, if arg positive; negative if arg negative). |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2543 (defun viper-forward-char-carefully (&optional arg) |
18129 | 2544 (setq arg (or arg 1)) |
19462 | 2545 (let ((pt (point))) |
2546 (condition-case nil | |
2547 (forward-char arg) | |
2548 (error)) | |
2549 (if (< (point) pt) ; arg was negative | |
2550 (- (viper-chars-in-region pt (point))) | |
2551 (viper-chars-in-region pt (point))))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2552 |
26588
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
2553 |
19462 | 2554 ;; Like backward-char, but doesn't move at beg of buffer. |
2555 ;; Returns distance traveled | |
2556 ;; (negative or 0, if arg positive; positive if arg negative). | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2557 (defun viper-backward-char-carefully (&optional arg) |
18129 | 2558 (setq arg (or arg 1)) |
19462 | 2559 (let ((pt (point))) |
2560 (condition-case nil | |
2561 (backward-char arg) | |
2562 (error)) | |
2563 (if (> (point) pt) ; arg was negative | |
2564 (viper-chars-in-region pt (point)) | |
2565 (- (viper-chars-in-region pt (point)))))) | |
18129 | 2566 |
19078 | 2567 (defun viper-next-line-carefully (arg) |
18129 | 2568 (condition-case nil |
2569 (next-line arg) | |
2570 (error nil))) | |
2571 | |
2572 | |
2573 | |
2574 ;;; Word command | |
2575 | |
19078 | 2576 ;; Words are formed from alpha's and nonalphas - <sp>,\t\n are separators for |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
2577 ;; word movement. When executed with a destructive command, \n is usually left |
19078 | 2578 ;; untouched for the last word. Viper uses syntax table to determine what is a |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
2579 ;; word and what is a separator. However, \n is always a separator. Also, if |
19078 | 2580 ;; viper-syntax-preference is 'vi, then `_' is part of the word. |
18129 | 2581 |
2582 ;; skip only one \n | |
19078 | 2583 (defun viper-skip-separators (forward) |
18129 | 2584 (if forward |
2585 (progn | |
19078 | 2586 (viper-skip-all-separators-forward 'within-line) |
18129 | 2587 (if (looking-at "\n") |
2588 (progn | |
2589 (forward-char) | |
19078 | 2590 (viper-skip-all-separators-forward 'within-line)))) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
2591 ;; check for eob and white space before it. move off of eob |
22283
3649674ebf29
(viper-backward-Word, viper-skip-separators): Bug fixes.
Karl Heuer <kwzh@gnu.org>
parents:
21940
diff
changeset
|
2592 (if (and (eobp) (save-excursion |
3649674ebf29
(viper-backward-Word, viper-skip-separators): Bug fixes.
Karl Heuer <kwzh@gnu.org>
parents:
21940
diff
changeset
|
2593 (viper-backward-char-carefully) |
3649674ebf29
(viper-backward-Word, viper-skip-separators): Bug fixes.
Karl Heuer <kwzh@gnu.org>
parents:
21940
diff
changeset
|
2594 (viper-looking-at-separator))) |
3649674ebf29
(viper-backward-Word, viper-skip-separators): Bug fixes.
Karl Heuer <kwzh@gnu.org>
parents:
21940
diff
changeset
|
2595 (viper-backward-char-carefully)) |
19078 | 2596 (viper-skip-all-separators-backward 'within-line) |
19462 | 2597 (viper-backward-char-carefully) |
18129 | 2598 (if (looking-at "\n") |
19078 | 2599 (viper-skip-all-separators-backward 'within-line) |
22283
3649674ebf29
(viper-backward-Word, viper-skip-separators): Bug fixes.
Karl Heuer <kwzh@gnu.org>
parents:
21940
diff
changeset
|
2600 (or (bobp) (forward-char))))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2601 |
26588
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
2602 |
19078 | 2603 (defun viper-forward-word-kernel (val) |
18129 | 2604 (while (> val 0) |
19078 | 2605 (cond ((viper-looking-at-alpha) |
2606 (viper-skip-alpha-forward "_") | |
2607 (viper-skip-separators t)) | |
2608 ((viper-looking-at-separator) | |
2609 (viper-skip-separators t)) | |
2610 ((not (viper-looking-at-alphasep)) | |
2611 (viper-skip-nonalphasep-forward) | |
2612 (viper-skip-separators t))) | |
18129 | 2613 (setq val (1- val)))) |
2614 | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
2615 ;; first skip non-newline separators backward, then skip \n. Then, if TWICE is |
19462 | 2616 ;; non-nil, skip non-\n back again, but don't overshoot the limit LIM. |
2617 (defun viper-separator-skipback-special (twice lim) | |
2618 (let ((prev-char (viper-char-at-pos 'backward)) | |
2619 (saved-point (point))) | |
2620 ;; skip non-newline separators backward | |
2621 (while (and (not (memq prev-char '(nil \n))) | |
2622 (< lim (point)) | |
2623 ;; must be non-newline separator | |
2624 (if (eq viper-syntax-preference 'strict-vi) | |
2625 (memq prev-char '(?\ ?\t)) | |
2626 (memq (char-syntax prev-char) '(?\ ?-)))) | |
2627 (viper-backward-char-carefully) | |
2628 (setq prev-char (viper-char-at-pos 'backward))) | |
2629 | |
2630 (if (and (< lim (point)) (eq prev-char ?\n)) | |
2631 (backward-char) | |
2632 ;; If we skipped to the next word and the prefix of this line doesn't | |
2633 ;; consist of separators preceded by a newline, then don't skip backwards | |
2634 ;; at all. | |
2635 (goto-char saved-point)) | |
2636 (setq prev-char (viper-char-at-pos 'backward)) | |
2637 | |
2638 ;; skip again, but make sure we don't overshoot the limit | |
2639 (if twice | |
2640 (while (and (not (memq prev-char '(nil \n))) | |
2641 (< lim (point)) | |
2642 ;; must be non-newline separator | |
2643 (if (eq viper-syntax-preference 'strict-vi) | |
2644 (memq prev-char '(?\ ?\t)) | |
2645 (memq (char-syntax prev-char) '(?\ ?-)))) | |
2646 (viper-backward-char-carefully) | |
2647 (setq prev-char (viper-char-at-pos 'backward)))) | |
2648 | |
2649 (if (= (point) lim) | |
2650 (viper-forward-char-carefully)) | |
2651 )) | |
18129 | 2652 |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2653 |
19078 | 2654 (defun viper-forward-word (arg) |
18129 | 2655 "Forward word." |
2656 (interactive "P") | |
19078 | 2657 (viper-leave-region-active) |
2658 (let ((val (viper-p-val arg)) | |
2659 (com (viper-getcom arg))) | |
2660 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
2661 (viper-forward-word-kernel val) | |
18129 | 2662 (if com (progn |
2663 (cond ((memq com (list ?c (- ?c))) | |
19462 | 2664 (viper-separator-skipback-special 'twice viper-com-point)) |
18129 | 2665 ;; Yank words including the whitespace, but not newline |
2666 ((memq com (list ?y (- ?y))) | |
19462 | 2667 (viper-separator-skipback-special nil viper-com-point)) |
19078 | 2668 ((viper-dotable-command-p com) |
19462 | 2669 (viper-separator-skipback-special nil viper-com-point))) |
19078 | 2670 (viper-execute-com 'viper-forward-word val com))))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2671 |
18129 | 2672 |
19078 | 2673 (defun viper-forward-Word (arg) |
18129 | 2674 "Forward word delimited by white characters." |
2675 (interactive "P") | |
19078 | 2676 (viper-leave-region-active) |
2677 (let ((val (viper-p-val arg)) | |
2678 (com (viper-getcom arg))) | |
2679 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
2680 (viper-loop val | |
2681 (viper-skip-nonseparators 'forward) | |
19462 | 2682 (viper-skip-separators t)) |
18129 | 2683 (if com (progn |
2684 (cond ((memq com (list ?c (- ?c))) | |
19462 | 2685 (viper-separator-skipback-special 'twice viper-com-point)) |
18129 | 2686 ;; Yank words including the whitespace, but not newline |
2687 ((memq com (list ?y (- ?y))) | |
19462 | 2688 (viper-separator-skipback-special nil viper-com-point)) |
19078 | 2689 ((viper-dotable-command-p com) |
19462 | 2690 (viper-separator-skipback-special nil viper-com-point))) |
19078 | 2691 (viper-execute-com 'viper-forward-Word val com))))) |
18129 | 2692 |
2693 | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2694 ;; this is a bit different from Vi, but Vi's end of word |
18129 | 2695 ;; makes no sense whatsoever |
19078 | 2696 (defun viper-end-of-word-kernel () |
2697 (if (viper-end-of-word-p) (forward-char)) | |
2698 (if (viper-looking-at-separator) | |
2699 (viper-skip-all-separators-forward)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2700 |
19078 | 2701 (cond ((viper-looking-at-alpha) (viper-skip-alpha-forward "_")) |
2702 ((not (viper-looking-at-alphasep)) (viper-skip-nonalphasep-forward))) | |
2703 (viper-backward-char-carefully)) | |
2704 | |
2705 (defun viper-end-of-word-p () | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2706 (or (eobp) |
18129 | 2707 (save-excursion |
19078 | 2708 (cond ((viper-looking-at-alpha) |
18129 | 2709 (forward-char) |
19078 | 2710 (not (viper-looking-at-alpha))) |
2711 ((not (viper-looking-at-alphasep)) | |
18129 | 2712 (forward-char) |
19078 | 2713 (viper-looking-at-alphasep)))))) |
2714 | |
2715 | |
2716 (defun viper-end-of-word (arg &optional careful) | |
18129 | 2717 "Move point to end of current word." |
2718 (interactive "P") | |
19078 | 2719 (viper-leave-region-active) |
2720 (let ((val (viper-p-val arg)) | |
2721 (com (viper-getcom arg))) | |
2722 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
2723 (viper-loop val (viper-end-of-word-kernel)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2724 (if com |
18129 | 2725 (progn |
2726 (forward-char) | |
19078 | 2727 (viper-execute-com 'viper-end-of-word val com))))) |
2728 | |
2729 (defun viper-end-of-Word (arg) | |
18129 | 2730 "Forward to end of word delimited by white character." |
2731 (interactive "P") | |
19078 | 2732 (viper-leave-region-active) |
2733 (let ((val (viper-p-val arg)) | |
2734 (com (viper-getcom arg))) | |
2735 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
2736 (viper-loop val | |
2737 (viper-end-of-word-kernel) | |
2738 (viper-skip-nonseparators 'forward) | |
19462 | 2739 (backward-char)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2740 (if com |
18129 | 2741 (progn |
2742 (forward-char) | |
19078 | 2743 (viper-execute-com 'viper-end-of-Word val com))))) |
2744 | |
2745 (defun viper-backward-word-kernel (val) | |
18129 | 2746 (while (> val 0) |
19462 | 2747 (viper-backward-char-carefully) |
19078 | 2748 (cond ((viper-looking-at-alpha) |
2749 (viper-skip-alpha-backward "_")) | |
2750 ((viper-looking-at-separator) | |
18129 | 2751 (forward-char) |
19078 | 2752 (viper-skip-separators nil) |
19462 | 2753 (viper-backward-char-carefully) |
19078 | 2754 (cond ((viper-looking-at-alpha) |
2755 (viper-skip-alpha-backward "_")) | |
2756 ((not (viper-looking-at-alphasep)) | |
2757 (viper-skip-nonalphasep-backward)) | |
19462 | 2758 ((bobp)) ; could still be at separator, but at beg of buffer |
18129 | 2759 (t (forward-char)))) |
19078 | 2760 ((not (viper-looking-at-alphasep)) |
2761 (viper-skip-nonalphasep-backward))) | |
18129 | 2762 (setq val (1- val)))) |
2763 | |
19078 | 2764 (defun viper-backward-word (arg) |
18129 | 2765 "Backward word." |
2766 (interactive "P") | |
19078 | 2767 (viper-leave-region-active) |
2768 (let ((val (viper-p-val arg)) | |
2769 (com (viper-getcom arg))) | |
18129 | 2770 (if com |
2771 (let (i) | |
2772 (if (setq i (save-excursion (backward-char) (looking-at "\n"))) | |
2773 (backward-char)) | |
19078 | 2774 (viper-move-marker-locally 'viper-com-point (point)) |
18129 | 2775 (if i (forward-char)))) |
19078 | 2776 (viper-backward-word-kernel val) |
2777 (if com (viper-execute-com 'viper-backward-word val com)))) | |
2778 | |
2779 (defun viper-backward-Word (arg) | |
18129 | 2780 "Backward word delimited by white character." |
2781 (interactive "P") | |
19078 | 2782 (viper-leave-region-active) |
2783 (let ((val (viper-p-val arg)) | |
2784 (com (viper-getcom arg))) | |
18129 | 2785 (if com |
2786 (let (i) | |
2787 (if (setq i (save-excursion (backward-char) (looking-at "\n"))) | |
2788 (backward-char)) | |
19078 | 2789 (viper-move-marker-locally 'viper-com-point (point)) |
18129 | 2790 (if i (forward-char)))) |
19078 | 2791 (viper-loop val |
19462 | 2792 (viper-skip-separators nil) ; nil means backward here |
2793 (viper-skip-nonseparators 'backward)) | |
19078 | 2794 (if com (viper-execute-com 'viper-backward-Word val com)))) |
18129 | 2795 |
2796 | |
2797 | |
2798 ;; line commands | |
2799 | |
19078 | 2800 (defun viper-beginning-of-line (arg) |
18129 | 2801 "Go to beginning of line." |
2802 (interactive "P") | |
19078 | 2803 (viper-leave-region-active) |
2804 (let ((val (viper-p-val arg)) | |
2805 (com (viper-getcom arg))) | |
2806 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
18129 | 2807 (beginning-of-line val) |
19078 | 2808 (if com (viper-execute-com 'viper-beginning-of-line val com)))) |
2809 | |
2810 (defun viper-bol-and-skip-white (arg) | |
18129 | 2811 "Beginning of line at first non-white character." |
2812 (interactive "P") | |
19078 | 2813 (viper-leave-region-active) |
2814 (let ((val (viper-p-val arg)) | |
2815 (com (viper-getcom arg))) | |
2816 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
18129 | 2817 (forward-to-indentation (1- val)) |
19078 | 2818 (if com (viper-execute-com 'viper-bol-and-skip-white val com)))) |
2819 | |
2820 (defun viper-goto-eol (arg) | |
18129 | 2821 "Go to end of line." |
2822 (interactive "P") | |
19078 | 2823 (viper-leave-region-active) |
2824 (let ((val (viper-p-val arg)) | |
2825 (com (viper-getcom arg))) | |
2826 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
18129 | 2827 (end-of-line val) |
19078 | 2828 (if com (viper-execute-com 'viper-goto-eol val com)) |
2829 (if viper-ex-style-motion | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2830 (if (and (eolp) (not (bolp)) |
19078 | 2831 ;; a fix for viper-change-to-eol |
2832 (not (equal viper-current-state 'insert-state))) | |
18129 | 2833 (backward-char 1) |
2834 )))) | |
2835 | |
2836 | |
19078 | 2837 (defun viper-goto-col (arg) |
18129 | 2838 "Go to ARG's column." |
2839 (interactive "P") | |
19078 | 2840 (viper-leave-region-active) |
2841 (let ((val (viper-p-val arg)) | |
2842 (com (viper-getcom arg)) | |
18129 | 2843 line-len) |
19462 | 2844 (setq line-len |
2845 (viper-chars-in-region | |
2846 (viper-line-pos 'start) (viper-line-pos 'end))) | |
19078 | 2847 (if com (viper-move-marker-locally 'viper-com-point (point))) |
18129 | 2848 (beginning-of-line) |
2849 (forward-char (1- (min line-len val))) | |
2850 (while (> (current-column) (1- val)) | |
2851 (backward-char 1)) | |
19078 | 2852 (if com (viper-execute-com 'viper-goto-col val com)) |
18129 | 2853 (save-excursion |
2854 (end-of-line) | |
2855 (if (> val (current-column)) (error ""))) | |
2856 )) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2857 |
18129 | 2858 |
19078 | 2859 (defun viper-next-line (arg) |
18129 | 2860 "Go to next line." |
2861 (interactive "P") | |
19078 | 2862 (viper-leave-region-active) |
2863 (let ((val (viper-p-val arg)) | |
2864 (com (viper-getCom arg))) | |
2865 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
18129 | 2866 (next-line val) |
19078 | 2867 (if viper-ex-style-motion |
18129 | 2868 (if (and (eolp) (not (bolp))) (backward-char 1))) |
2869 (setq this-command 'next-line) | |
19078 | 2870 (if com (viper-execute-com 'viper-next-line val com)))) |
2871 | |
2872 (defun viper-next-line-at-bol (arg) | |
18129 | 2873 "Next line at beginning of line." |
2874 (interactive "P") | |
19078 | 2875 (viper-leave-region-active) |
18129 | 2876 (save-excursion |
2877 (end-of-line) | |
2878 (if (eobp) (error "Last line in buffer"))) | |
19078 | 2879 (let ((val (viper-p-val arg)) |
2880 (com (viper-getCom arg))) | |
2881 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
18129 | 2882 (forward-line val) |
2883 (back-to-indentation) | |
19078 | 2884 (if com (viper-execute-com 'viper-next-line-at-bol val com)))) |
2885 | |
26588
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
2886 |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2887 (defun viper-previous-line (arg) |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2888 "Go to previous line." |
18129 | 2889 (interactive "P") |
19078 | 2890 (viper-leave-region-active) |
2891 (let ((val (viper-p-val arg)) | |
2892 (com (viper-getCom arg))) | |
2893 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
18129 | 2894 (previous-line val) |
19078 | 2895 (if viper-ex-style-motion |
18129 | 2896 (if (and (eolp) (not (bolp))) (backward-char 1))) |
2897 (setq this-command 'previous-line) | |
19078 | 2898 (if com (viper-execute-com 'viper-previous-line val com)))) |
2899 | |
2900 | |
2901 (defun viper-previous-line-at-bol (arg) | |
18129 | 2902 "Previous line at beginning of line." |
2903 (interactive "P") | |
19078 | 2904 (viper-leave-region-active) |
18129 | 2905 (save-excursion |
2906 (beginning-of-line) | |
2907 (if (bobp) (error "First line in buffer"))) | |
19078 | 2908 (let ((val (viper-p-val arg)) |
2909 (com (viper-getCom arg))) | |
2910 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
18129 | 2911 (forward-line (- val)) |
2912 (back-to-indentation) | |
19078 | 2913 (if com (viper-execute-com 'viper-previous-line val com)))) |
2914 | |
2915 (defun viper-change-to-eol (arg) | |
18129 | 2916 "Change to end of line." |
2917 (interactive "P") | |
19078 | 2918 (viper-goto-eol (cons arg ?c))) |
2919 | |
2920 (defun viper-kill-line (arg) | |
18129 | 2921 "Delete line." |
2922 (interactive "P") | |
19078 | 2923 (viper-goto-eol (cons arg ?d))) |
2924 | |
2925 (defun viper-erase-line (arg) | |
18129 | 2926 "Erase line." |
2927 (interactive "P") | |
19078 | 2928 (viper-beginning-of-line (cons arg ?d))) |
18129 | 2929 |
2930 | |
2931 ;;; Moving around | |
2932 | |
19078 | 2933 (defun viper-goto-line (arg) |
18129 | 2934 "Go to ARG's line. Without ARG go to end of buffer." |
2935 (interactive "P") | |
19078 | 2936 (let ((val (viper-P-val arg)) |
2937 (com (viper-getCom arg))) | |
2938 (viper-move-marker-locally 'viper-com-point (point)) | |
2939 (viper-deactivate-mark) | |
18129 | 2940 (push-mark nil t) |
2941 (if (null val) | |
2942 (goto-char (point-max)) | |
2943 (goto-char (point-min)) | |
2944 (forward-line (1- val))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2945 |
18129 | 2946 ;; positioning is done twice: before and after command execution |
2947 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) | |
2948 (back-to-indentation) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2949 |
19078 | 2950 (if com (viper-execute-com 'viper-goto-line val com)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2951 |
18129 | 2952 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
2953 (back-to-indentation) | |
2954 )) | |
2955 | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
2956 ;; Find ARG's occurrence of CHAR on the current line. |
18129 | 2957 ;; If FORWARD then search is forward, otherwise backward. OFFSET is used to |
2958 ;; adjust point after search. | |
19078 | 2959 (defun viper-find-char (arg char forward offset) |
18129 | 2960 (or (char-or-string-p char) (error "")) |
2961 (let ((arg (if forward arg (- arg))) | |
19078 | 2962 (cmd (if (eq viper-intermediate-command 'viper-repeat) |
2963 (nth 5 viper-d-com) | |
2964 (viper-array-to-string (this-command-keys)))) | |
21940 | 2965 point region-beg region-end) |
18129 | 2966 (save-excursion |
2967 (save-restriction | |
21940 | 2968 (if (> arg 0) ; forward |
2969 (progn | |
2970 (setq region-beg (point)) | |
2971 (if viper-allow-multiline-replace-regions | |
2972 (viper-forward-paragraph 1) | |
2973 (end-of-line)) | |
2974 (setq region-end (point))) | |
2975 (setq region-end (point)) | |
2976 (if viper-allow-multiline-replace-regions | |
2977 (viper-backward-paragraph 1) | |
2978 (beginning-of-line)) | |
2979 (setq region-beg (point))) | |
2980 (if (or (and (< arg 0) | |
2981 (< (- region-end region-beg) | |
2982 (if viper-allow-multiline-replace-regions | |
2983 2 1)) | |
2984 (bolp)) | |
2985 (and (> arg 0) | |
2986 (< (- region-end region-beg) | |
2987 (if viper-allow-multiline-replace-regions | |
2988 3 2)) | |
2989 (eolp))) | |
2990 (error "Command `%s': At %s of %s" | |
2991 cmd | |
2992 (if (> arg 0) "end" "beginning") | |
2993 (if viper-allow-multiline-replace-regions | |
2994 "paragraph" "line"))) | |
2995 (narrow-to-region region-beg region-end) | |
18129 | 2996 ;; if arg > 0, point is forwarded before search. |
2997 (if (> arg 0) (goto-char (1+ (point-min))) | |
2998 (goto-char (point-max))) | |
2999 (if (let ((case-fold-search nil)) | |
3000 (search-forward (char-to-string char) nil 0 arg)) | |
3001 (setq point (point)) | |
3002 (error "Command `%s': `%c' not found" cmd char)))) | |
19462 | 3003 (goto-char point) |
3004 (if (> arg 0) | |
3005 (backward-char (if offset 2 1)) | |
3006 (forward-char (if offset 1 0))))) | |
18129 | 3007 |
19078 | 3008 (defun viper-find-char-forward (arg) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3009 "Find char on the line. |
18129 | 3010 If called interactively read the char to find from the terminal, and if |
19078 | 3011 called from viper-repeat, the char last used is used. This behaviour is |
18129 | 3012 controlled by the sign of prefix numeric value." |
3013 (interactive "P") | |
19078 | 3014 (let ((val (viper-p-val arg)) |
3015 (com (viper-getcom arg)) | |
3016 (cmd-representation (nth 5 viper-d-com))) | |
18129 | 3017 (if (> val 0) |
3018 ;; this means that the function was called interactively | |
19078 | 3019 (setq viper-f-char (read-char) |
3020 viper-f-forward t | |
3021 viper-f-offset nil) | |
3022 ;; viper-repeat --- set viper-F-char from command-keys | |
3023 (setq viper-F-char (if (stringp cmd-representation) | |
3024 (viper-seq-last-elt cmd-representation) | |
3025 viper-F-char) | |
3026 viper-f-char viper-F-char) | |
18129 | 3027 (setq val (- val))) |
19078 | 3028 (if com (viper-move-marker-locally 'viper-com-point (point))) |
3029 (viper-find-char | |
3030 val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) t nil) | |
18129 | 3031 (setq val (- val)) |
3032 (if com | |
3033 (progn | |
19078 | 3034 (setq viper-F-char viper-f-char) ; set new viper-F-char |
18129 | 3035 (forward-char) |
19078 | 3036 (viper-execute-com 'viper-find-char-forward val com))))) |
3037 | |
3038 (defun viper-goto-char-forward (arg) | |
18129 | 3039 "Go up to char ARG forward on line." |
3040 (interactive "P") | |
19078 | 3041 (let ((val (viper-p-val arg)) |
3042 (com (viper-getcom arg)) | |
3043 (cmd-representation (nth 5 viper-d-com))) | |
18129 | 3044 (if (> val 0) |
3045 ;; this means that the function was called interactively | |
19078 | 3046 (setq viper-f-char (read-char) |
3047 viper-f-forward t | |
3048 viper-f-offset t) | |
3049 ;; viper-repeat --- set viper-F-char from command-keys | |
3050 (setq viper-F-char (if (stringp cmd-representation) | |
3051 (viper-seq-last-elt cmd-representation) | |
3052 viper-F-char) | |
3053 viper-f-char viper-F-char) | |
18129 | 3054 (setq val (- val))) |
19078 | 3055 (if com (viper-move-marker-locally 'viper-com-point (point))) |
3056 (viper-find-char | |
3057 val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) t t) | |
18129 | 3058 (setq val (- val)) |
3059 (if com | |
3060 (progn | |
19078 | 3061 (setq viper-F-char viper-f-char) ; set new viper-F-char |
18129 | 3062 (forward-char) |
19078 | 3063 (viper-execute-com 'viper-goto-char-forward val com))))) |
3064 | |
3065 (defun viper-find-char-backward (arg) | |
18129 | 3066 "Find char ARG on line backward." |
3067 (interactive "P") | |
19078 | 3068 (let ((val (viper-p-val arg)) |
3069 (com (viper-getcom arg)) | |
3070 (cmd-representation (nth 5 viper-d-com))) | |
18129 | 3071 (if (> val 0) |
3072 ;; this means that the function was called interactively | |
19078 | 3073 (setq viper-f-char (read-char) |
3074 viper-f-forward nil | |
3075 viper-f-offset nil) | |
3076 ;; viper-repeat --- set viper-F-char from command-keys | |
3077 (setq viper-F-char (if (stringp cmd-representation) | |
3078 (viper-seq-last-elt cmd-representation) | |
3079 viper-F-char) | |
3080 viper-f-char viper-F-char) | |
18129 | 3081 (setq val (- val))) |
19078 | 3082 (if com (viper-move-marker-locally 'viper-com-point (point))) |
3083 (viper-find-char | |
3084 val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) nil nil) | |
18129 | 3085 (setq val (- val)) |
3086 (if com | |
3087 (progn | |
19078 | 3088 (setq viper-F-char viper-f-char) ; set new viper-F-char |
3089 (viper-execute-com 'viper-find-char-backward val com))))) | |
3090 | |
3091 (defun viper-goto-char-backward (arg) | |
18129 | 3092 "Go up to char ARG backward on line." |
3093 (interactive "P") | |
19078 | 3094 (let ((val (viper-p-val arg)) |
3095 (com (viper-getcom arg)) | |
3096 (cmd-representation (nth 5 viper-d-com))) | |
18129 | 3097 (if (> val 0) |
3098 ;; this means that the function was called interactively | |
19078 | 3099 (setq viper-f-char (read-char) |
3100 viper-f-forward nil | |
3101 viper-f-offset t) | |
3102 ;; viper-repeat --- set viper-F-char from command-keys | |
3103 (setq viper-F-char (if (stringp cmd-representation) | |
3104 (viper-seq-last-elt cmd-representation) | |
3105 viper-F-char) | |
3106 viper-f-char viper-F-char) | |
18129 | 3107 (setq val (- val))) |
19078 | 3108 (if com (viper-move-marker-locally 'viper-com-point (point))) |
3109 (viper-find-char | |
3110 val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) nil t) | |
18129 | 3111 (setq val (- val)) |
3112 (if com | |
3113 (progn | |
19078 | 3114 (setq viper-F-char viper-f-char) ; set new viper-F-char |
3115 (viper-execute-com 'viper-goto-char-backward val com))))) | |
3116 | |
3117 (defun viper-repeat-find (arg) | |
18129 | 3118 "Repeat previous find command." |
3119 (interactive "P") | |
19078 | 3120 (let ((val (viper-p-val arg)) |
3121 (com (viper-getcom arg))) | |
3122 (viper-deactivate-mark) | |
3123 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
3124 (viper-find-char val viper-f-char viper-f-forward viper-f-offset) | |
18129 | 3125 (if com |
3126 (progn | |
19078 | 3127 (if viper-f-forward (forward-char)) |
3128 (viper-execute-com 'viper-repeat-find val com))))) | |
3129 | |
3130 (defun viper-repeat-find-opposite (arg) | |
18129 | 3131 "Repeat previous find command in the opposite direction." |
3132 (interactive "P") | |
19078 | 3133 (let ((val (viper-p-val arg)) |
3134 (com (viper-getcom arg))) | |
3135 (viper-deactivate-mark) | |
3136 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
3137 (viper-find-char val viper-f-char (not viper-f-forward) viper-f-offset) | |
18129 | 3138 (if com |
3139 (progn | |
19078 | 3140 (if viper-f-forward (forward-char)) |
3141 (viper-execute-com 'viper-repeat-find-opposite val com))))) | |
18129 | 3142 |
3143 | |
3144 ;; window scrolling etc. | |
3145 | |
19078 | 3146 (defun viper-window-top (arg) |
18129 | 3147 "Go to home window line." |
3148 (interactive "P") | |
19078 | 3149 (let ((val (viper-p-val arg)) |
3150 (com (viper-getCom arg))) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3151 (viper-leave-region-active) |
19078 | 3152 (if com (viper-move-marker-locally 'viper-com-point (point))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3153 (push-mark nil t) |
18129 | 3154 (move-to-window-line (1- val)) |
3155 | |
3156 ;; positioning is done twice: before and after command execution | |
3157 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) | |
3158 (back-to-indentation) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3159 |
19078 | 3160 (if com (viper-execute-com 'viper-window-top val com)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3161 |
18129 | 3162 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
3163 (back-to-indentation) | |
3164 )) | |
3165 | |
19078 | 3166 (defun viper-window-middle (arg) |
18129 | 3167 "Go to middle window line." |
3168 (interactive "P") | |
19078 | 3169 (let ((val (viper-p-val arg)) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3170 (com (viper-getCom arg))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3171 (viper-leave-region-active) |
19078 | 3172 (if com (viper-move-marker-locally 'viper-com-point (point))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3173 (push-mark nil t) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3174 (move-to-window-line (+ (/ (1- (window-height)) 2) (1- val))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3175 |
18129 | 3176 ;; positioning is done twice: before and after command execution |
3177 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) | |
3178 (back-to-indentation) | |
3179 | |
19078 | 3180 (if com (viper-execute-com 'viper-window-middle val com)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3181 |
18129 | 3182 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
3183 (back-to-indentation) | |
3184 )) | |
3185 | |
19078 | 3186 (defun viper-window-bottom (arg) |
18129 | 3187 "Go to last window line." |
3188 (interactive "P") | |
19078 | 3189 (let ((val (viper-p-val arg)) |
3190 (com (viper-getCom arg))) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3191 (viper-leave-region-active) |
19078 | 3192 (if com (viper-move-marker-locally 'viper-com-point (point))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3193 (push-mark nil t) |
18129 | 3194 (move-to-window-line (- val)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3195 |
18129 | 3196 ;; positioning is done twice: before and after command execution |
3197 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) | |
3198 (back-to-indentation) | |
3199 | |
19078 | 3200 (if com (viper-execute-com 'viper-window-bottom val com)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3201 |
18129 | 3202 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
3203 (back-to-indentation) | |
3204 )) | |
3205 | |
19078 | 3206 (defun viper-line-to-top (arg) |
18129 | 3207 "Put current line on the home line." |
3208 (interactive "p") | |
3209 (recenter (1- arg))) | |
3210 | |
19078 | 3211 (defun viper-line-to-middle (arg) |
18129 | 3212 "Put current line on the middle line." |
3213 (interactive "p") | |
3214 (recenter (+ (1- arg) (/ (1- (window-height)) 2)))) | |
3215 | |
19078 | 3216 (defun viper-line-to-bottom (arg) |
18129 | 3217 "Put current line on the last line." |
3218 (interactive "p") | |
3219 (recenter (- (window-height) (1+ arg)))) | |
3220 | |
19078 | 3221 ;; If point is within viper-search-scroll-threshold of window top or bottom, |
18129 | 3222 ;; scroll up or down 1/7 of window height, depending on whether we are at the |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3223 ;; bottom or at the top of the window. This function is called by viper-search |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3224 ;; (which is called from viper-search-forward/backward/next). If the value of |
19078 | 3225 ;; viper-search-scroll-threshold is negative - don't scroll. |
3226 (defun viper-adjust-window () | |
3227 (let ((win-height (if viper-emacs-p | |
18129 | 3228 (1- (window-height)) ; adjust for modeline |
3229 (window-displayed-height))) | |
3230 (pt (point)) | |
3231 at-top-p at-bottom-p | |
3232 min-scroll direction) | |
3233 (save-excursion | |
3234 (move-to-window-line 0) ; top | |
3235 (setq at-top-p | |
3236 (<= (count-lines pt (point)) | |
19078 | 3237 viper-search-scroll-threshold)) |
18129 | 3238 (move-to-window-line -1) ; bottom |
3239 (setq at-bottom-p | |
19078 | 3240 (<= (count-lines pt (point)) viper-search-scroll-threshold)) |
18129 | 3241 ) |
19078 | 3242 (cond (at-top-p (setq min-scroll (1- viper-search-scroll-threshold) |
18129 | 3243 direction 1)) |
19078 | 3244 (at-bottom-p (setq min-scroll (1+ viper-search-scroll-threshold) |
18129 | 3245 direction -1))) |
3246 (if min-scroll | |
3247 (recenter | |
3248 (* (max min-scroll (/ win-height 7)) direction))) | |
3249 )) | |
3250 | |
3251 | |
3252 ;; paren match | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3253 ;; must correct this to only match ( to ) etc. On the other hand |
18129 | 3254 ;; it is good that paren match gets confused, because that way you |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3255 ;; catch _all_ imbalances. |
18129 | 3256 |
19078 | 3257 (defun viper-paren-match (arg) |
18129 | 3258 "Go to the matching parenthesis." |
3259 (interactive "P") | |
19078 | 3260 (viper-leave-region-active) |
3261 (let ((com (viper-getcom arg)) | |
3262 (parse-sexp-ignore-comments viper-parse-sexp-ignore-comments) | |
18129 | 3263 anchor-point) |
3264 (if (integerp arg) | |
3265 (if (or (> arg 99) (< arg 1)) | |
3266 (error "Prefix must be between 1 and 99") | |
3267 (goto-char | |
3268 (if (> (point-max) 80000) | |
3269 (* (/ (point-max) 100) arg) | |
3270 (/ (* (point-max) arg) 100))) | |
3271 (back-to-indentation)) | |
3272 (let (beg-lim end-lim) | |
3273 (if (and (eolp) (not (bolp))) (forward-char -1)) | |
3274 (if (not (looking-at "[][(){}]")) | |
3275 (setq anchor-point (point))) | |
3276 (save-excursion | |
3277 (beginning-of-line) | |
3278 (setq beg-lim (point)) | |
3279 (end-of-line) | |
3280 (setq end-lim (point))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3281 (cond ((re-search-forward "[][(){}]" end-lim t) |
18129 | 3282 (backward-char) ) |
3283 ((re-search-backward "[][(){}]" beg-lim t)) | |
3284 (t | |
3285 (error "No matching character on line")))) | |
3286 (cond ((looking-at "[\(\[{]") | |
19078 | 3287 (if com (viper-move-marker-locally 'viper-com-point (point))) |
18129 | 3288 (forward-sexp 1) |
3289 (if com | |
19078 | 3290 (viper-execute-com 'viper-paren-match nil com) |
18129 | 3291 (backward-char))) |
3292 (anchor-point | |
3293 (if com | |
3294 (progn | |
19078 | 3295 (viper-move-marker-locally 'viper-com-point anchor-point) |
18129 | 3296 (forward-char 1) |
19078 | 3297 (viper-execute-com 'viper-paren-match nil com) |
18129 | 3298 ))) |
3299 ((looking-at "[])}]") | |
3300 (forward-char) | |
19078 | 3301 (if com (viper-move-marker-locally 'viper-com-point (point))) |
18129 | 3302 (backward-sexp 1) |
19078 | 3303 (if com (viper-execute-com 'viper-paren-match nil com))) |
18129 | 3304 (t (error "")))))) |
3305 | |
19078 | 3306 (defun viper-toggle-parse-sexp-ignore-comments () |
18129 | 3307 (interactive) |
19078 | 3308 (setq viper-parse-sexp-ignore-comments |
3309 (not viper-parse-sexp-ignore-comments)) | |
18839 | 3310 (princ (format |
3311 "From now on, `%%' will %signore parentheses inside comment fields" | |
19078 | 3312 (if viper-parse-sexp-ignore-comments "" "NOT ")))) |
18129 | 3313 |
3314 | |
21940 | 3315 ;; sentence, paragraph and heading |
18129 | 3316 |
19078 | 3317 (defun viper-forward-sentence (arg) |
18129 | 3318 "Forward sentence." |
3319 (interactive "P") | |
20003 | 3320 (or (eq last-command this-command) |
3321 (push-mark nil t)) | |
19078 | 3322 (let ((val (viper-p-val arg)) |
3323 (com (viper-getcom arg))) | |
3324 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
18129 | 3325 (forward-sentence val) |
19078 | 3326 (if com (viper-execute-com 'viper-forward-sentence nil com)))) |
3327 | |
3328 (defun viper-backward-sentence (arg) | |
18129 | 3329 "Backward sentence." |
3330 (interactive "P") | |
20003 | 3331 (or (eq last-command this-command) |
3332 (push-mark nil t)) | |
19078 | 3333 (let ((val (viper-p-val arg)) |
3334 (com (viper-getcom arg))) | |
3335 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
18129 | 3336 (backward-sentence val) |
19078 | 3337 (if com (viper-execute-com 'viper-backward-sentence nil com)))) |
3338 | |
3339 (defun viper-forward-paragraph (arg) | |
18129 | 3340 "Forward paragraph." |
3341 (interactive "P") | |
20003 | 3342 (or (eq last-command this-command) |
3343 (push-mark nil t)) | |
19078 | 3344 (let ((val (viper-p-val arg)) |
21940 | 3345 ;; if you want d} operate on whole lines, change viper-getcom to |
3346 ;; viper-getCom below | |
3347 (com (viper-getcom arg))) | |
19078 | 3348 (if com (viper-move-marker-locally 'viper-com-point (point))) |
18129 | 3349 (forward-paragraph val) |
3350 (if com | |
3351 (progn | |
3352 (backward-char 1) | |
19078 | 3353 (viper-execute-com 'viper-forward-paragraph nil com))))) |
3354 | |
3355 (defun viper-backward-paragraph (arg) | |
18129 | 3356 "Backward paragraph." |
3357 (interactive "P") | |
20003 | 3358 (or (eq last-command this-command) |
3359 (push-mark nil t)) | |
19078 | 3360 (let ((val (viper-p-val arg)) |
21940 | 3361 ;; if you want d{ operate on whole lines, change viper-getcom to |
3362 ;; viper-getCom below | |
3363 (com (viper-getcom arg))) | |
19078 | 3364 (if com (viper-move-marker-locally 'viper-com-point (point))) |
18129 | 3365 (backward-paragraph val) |
3366 (if com | |
3367 (progn | |
3368 (forward-char 1) | |
19078 | 3369 (viper-execute-com 'viper-backward-paragraph nil com) |
18129 | 3370 (backward-char 1))))) |
3371 | |
20003 | 3372 ;; should be mode-specific |
19078 | 3373 (defun viper-prev-heading (arg) |
18129 | 3374 (interactive "P") |
19078 | 3375 (let ((val (viper-p-val arg)) |
3376 (com (viper-getCom arg))) | |
3377 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
3378 (re-search-backward viper-heading-start nil t val) | |
18129 | 3379 (goto-char (match-beginning 0)) |
19078 | 3380 (if com (viper-execute-com 'viper-prev-heading nil com)))) |
3381 | |
3382 (defun viper-heading-end (arg) | |
18129 | 3383 (interactive "P") |
19078 | 3384 (let ((val (viper-p-val arg)) |
3385 (com (viper-getCom arg))) | |
3386 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
3387 (re-search-forward viper-heading-end nil t val) | |
18129 | 3388 (goto-char (match-beginning 0)) |
19078 | 3389 (if com (viper-execute-com 'viper-heading-end nil com)))) |
3390 | |
3391 (defun viper-next-heading (arg) | |
18129 | 3392 (interactive "P") |
19078 | 3393 (let ((val (viper-p-val arg)) |
3394 (com (viper-getCom arg))) | |
3395 (if com (viper-move-marker-locally 'viper-com-point (point))) | |
18129 | 3396 (end-of-line) |
19078 | 3397 (re-search-forward viper-heading-start nil t val) |
18129 | 3398 (goto-char (match-beginning 0)) |
19078 | 3399 (if com (viper-execute-com 'viper-next-heading nil com)))) |
18129 | 3400 |
3401 | |
3402 ;; scrolling | |
3403 | |
19078 | 3404 (defun viper-scroll-screen (arg) |
18129 | 3405 "Scroll to next screen." |
3406 (interactive "p") | |
3407 (condition-case nil | |
3408 (if (> arg 0) | |
3409 (while (> arg 0) | |
3410 (scroll-up) | |
3411 (setq arg (1- arg))) | |
3412 (while (> 0 arg) | |
3413 (scroll-down) | |
3414 (setq arg (1+ arg)))) | |
3415 (error (beep 1) | |
3416 (if (> arg 0) | |
3417 (progn | |
3418 (message "End of buffer") | |
3419 (goto-char (point-max))) | |
3420 (message "Beginning of buffer") | |
3421 (goto-char (point-min)))) | |
3422 )) | |
3423 | |
19078 | 3424 (defun viper-scroll-screen-back (arg) |
18129 | 3425 "Scroll to previous screen." |
3426 (interactive "p") | |
19078 | 3427 (viper-scroll-screen (- arg))) |
3428 | |
3429 (defun viper-scroll-down (arg) | |
18129 | 3430 "Pull down half screen." |
3431 (interactive "P") | |
3432 (condition-case nil | |
3433 (if (null arg) | |
3434 (scroll-down (/ (window-height) 2)) | |
3435 (scroll-down arg)) | |
3436 (error (beep 1) | |
3437 (message "Beginning of buffer") | |
3438 (goto-char (point-min))))) | |
3439 | |
19078 | 3440 (defun viper-scroll-down-one (arg) |
18129 | 3441 "Scroll up one line." |
3442 (interactive "p") | |
3443 (scroll-down arg)) | |
3444 | |
19078 | 3445 (defun viper-scroll-up (arg) |
18129 | 3446 "Pull up half screen." |
3447 (interactive "P") | |
3448 (condition-case nil | |
3449 (if (null arg) | |
3450 (scroll-up (/ (window-height) 2)) | |
3451 (scroll-up arg)) | |
3452 (error (beep 1) | |
3453 (message "End of buffer") | |
3454 (goto-char (point-max))))) | |
3455 | |
19078 | 3456 (defun viper-scroll-up-one (arg) |
18129 | 3457 "Scroll down one line." |
3458 (interactive "p") | |
3459 (scroll-up arg)) | |
3460 | |
3461 | |
3462 ;; searching | |
3463 | |
19078 | 3464 (defun viper-if-string (prompt) |
3465 (if (memq viper-intermediate-command | |
3466 '(viper-command-argument viper-digit-argument viper-repeat)) | |
3467 (setq viper-this-command-keys (this-command-keys))) | |
3468 (let ((s (viper-read-string-with-history | |
18129 | 3469 prompt |
3470 nil ; no initial | |
19078 | 3471 'viper-search-history |
3472 (car viper-search-history)))) | |
18129 | 3473 (if (not (string= s "")) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3474 (setq viper-s-string s)))) |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3475 |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3476 |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3477 (defun viper-toggle-search-style (arg) |
19078 | 3478 "Toggle the value of viper-case-fold-search/viper-re-search. |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3479 Without prefix argument, will ask which search style to toggle. With prefix |
19078 | 3480 arg 1,toggles viper-case-fold-search; with arg 2 toggles viper-re-search. |
3481 | |
3482 Although this function is bound to \\[viper-toggle-search-style], the most | |
18129 | 3483 convenient way to use it is to bind `//' to the macro |
19078 | 3484 `1 M-x viper-toggle-search-style' and `///' to |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3485 `2 M-x viper-toggle-search-style'. In this way, hitting `//' quickly will |
18129 | 3486 toggle case-fold-search and hitting `/' three times witth toggle regexp |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3487 search. Macros are more convenient in this case because they don't affect |
18129 | 3488 the Emacs binding of `/'." |
3489 (interactive "P") | |
3490 (let (msg) | |
3491 (cond ((or (eq arg 1) | |
3492 (and (null arg) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3493 (y-or-n-p (format "Search style: '%s'. Want '%s'? " |
19078 | 3494 (if viper-case-fold-search |
18129 | 3495 "case-insensitive" "case-sensitive") |
19078 | 3496 (if viper-case-fold-search |
18129 | 3497 "case-sensitive" |
3498 "case-insensitive"))))) | |
19078 | 3499 (setq viper-case-fold-search (null viper-case-fold-search)) |
3500 (if viper-case-fold-search | |
18129 | 3501 (setq msg "Search becomes case-insensitive") |
3502 (setq msg "Search becomes case-sensitive"))) | |
3503 ((or (eq arg 2) | |
3504 (and (null arg) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3505 (y-or-n-p (format "Search style: '%s'. Want '%s'? " |
19078 | 3506 (if viper-re-search |
18129 | 3507 "regexp-search" "vanilla-search") |
19078 | 3508 (if viper-re-search |
18129 | 3509 "vanilla-search" |
3510 "regexp-search"))))) | |
19078 | 3511 (setq viper-re-search (null viper-re-search)) |
3512 (if viper-re-search | |
18129 | 3513 (setq msg "Search becomes regexp-style") |
3514 (setq msg "Search becomes vanilla-style"))) | |
3515 (t | |
3516 (setq msg "Search style remains unchanged"))) | |
18839 | 3517 (princ msg t))) |
3518 | |
19078 | 3519 (defun viper-set-searchstyle-toggling-macros (unset) |
18129 | 3520 "Set the macros for toggling the search style in Viper's vi-state. |
3521 The macro that toggles case sensitivity is bound to `//', and the one that | |
3522 toggles regexp search is bound to `///'. | |
3523 With a prefix argument, this function unsets the macros. " | |
3524 (interactive "P") | |
3525 (or noninteractive | |
3526 (if (not unset) | |
3527 (progn | |
3528 ;; toggle case sensitivity in search | |
19078 | 3529 (viper-record-kbd-macro |
18129 | 3530 "//" 'vi-state |
19078 | 3531 [1 (meta x) v i p e r - t o g g l e - s e a r c h - s t y l e return] |
18129 | 3532 't) |
3533 ;; toggle regexp/vanila search | |
19078 | 3534 (viper-record-kbd-macro |
18129 | 3535 "///" 'vi-state |
19078 | 3536 [2 (meta x) v i p e r - t o g g l e - s e a r c h - s t y l e return] |
18129 | 3537 't) |
3538 (if (interactive-p) | |
3539 (message | |
18839 | 3540 "// and /// now toggle case-sensitivity and regexp search"))) |
19078 | 3541 (viper-unrecord-kbd-macro "//" 'vi-state) |
18129 | 3542 (sit-for 2) |
19078 | 3543 (viper-unrecord-kbd-macro "///" 'vi-state)))) |
3544 | |
3545 | |
3546 (defun viper-set-parsing-style-toggling-macro (unset) | |
18839 | 3547 "Set `%%%' to be a macro that toggles whether comment fields should be parsed for matching parentheses. |
3548 This is used in conjunction with the `%' command. | |
3549 | |
3550 With a prefix argument, unsets the macro." | |
3551 (interactive "P") | |
3552 (or noninteractive | |
3553 (if (not unset) | |
3554 (progn | |
3555 ;; Make %%% toggle parsing comments for matching parentheses | |
19078 | 3556 (viper-record-kbd-macro |
18839 | 3557 "%%%" 'vi-state |
19078 | 3558 [(meta x) v i p e r - t o g g l e - p a r s e - s e x p - i g n o r e - c o m m e n t s return] |
18839 | 3559 't) |
3560 (if (interactive-p) | |
3561 (message | |
3562 "%%%%%% now toggles whether comments should be parsed for matching parentheses"))) | |
19078 | 3563 (viper-unrecord-kbd-macro "%%%" 'vi-state)))) |
3564 | |
3565 | |
3566 (defun viper-set-emacs-state-searchstyle-macros (unset &optional arg-majormode) | |
18129 | 3567 "Set the macros for toggling the search style in Viper's emacs-state. |
3568 The macro that toggles case sensitivity is bound to `//', and the one that | |
3569 toggles regexp search is bound to `///'. | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3570 With a prefix argument, this function unsets the macros. |
18129 | 3571 If the optional prefix argument is non-nil and specifies a valid major mode, |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3572 this sets the macros only in the macros in that major mode. Otherwise, |
18129 | 3573 the macros are set in the current major mode. |
3574 \(When unsetting the macros, the second argument has no effect.\)" | |
3575 (interactive "P") | |
3576 (or noninteractive | |
3577 (if (not unset) | |
3578 (progn | |
3579 ;; toggle case sensitivity in search | |
19078 | 3580 (viper-record-kbd-macro |
18129 | 3581 "//" 'emacs-state |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3582 [1 (meta x) v i p e r - t o g g l e - s e a r c h - s t y l e return] |
18129 | 3583 (or arg-majormode major-mode)) |
3584 ;; toggle regexp/vanila search | |
19078 | 3585 (viper-record-kbd-macro |
18129 | 3586 "///" 'emacs-state |
19078 | 3587 [2 (meta x) v i p e r - t o g g l e - s e a r c h - s t y l e return] |
18129 | 3588 (or arg-majormode major-mode)) |
3589 (if (interactive-p) | |
3590 (message | |
3591 "// and /// now toggle case-sensitivity and regexp search."))) | |
19078 | 3592 (viper-unrecord-kbd-macro "//" 'emacs-state) |
18129 | 3593 (sit-for 2) |
19078 | 3594 (viper-unrecord-kbd-macro "///" 'emacs-state)))) |
3595 | |
3596 | |
3597 (defun viper-search-forward (arg) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3598 "Search a string forward. |
18129 | 3599 ARG is used to find the ARG's occurrence of the string. |
3600 Null string will repeat previous search." | |
3601 (interactive "P") | |
19078 | 3602 (let ((val (viper-P-val arg)) |
3603 (com (viper-getcom arg)) | |
3604 (old-str viper-s-string)) | |
3605 (setq viper-s-forward t) | |
3606 (viper-if-string "/") | |
18129 | 3607 ;; this is not used at present, but may be used later |
19078 | 3608 (if (or (not (equal old-str viper-s-string)) |
3609 (not (markerp viper-local-search-start-marker)) | |
3610 (not (marker-buffer viper-local-search-start-marker))) | |
3611 (setq viper-local-search-start-marker (point-marker))) | |
3612 (viper-search viper-s-string t val) | |
18129 | 3613 (if com |
3614 (progn | |
19078 | 3615 (viper-move-marker-locally 'viper-com-point (mark t)) |
3616 (viper-execute-com 'viper-search-next val com))))) | |
3617 | |
3618 (defun viper-search-backward (arg) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3619 "Search a string backward. |
18129 | 3620 ARG is used to find the ARG's occurrence of the string. |
3621 Null string will repeat previous search." | |
3622 (interactive "P") | |
19078 | 3623 (let ((val (viper-P-val arg)) |
3624 (com (viper-getcom arg)) | |
3625 (old-str viper-s-string)) | |
3626 (setq viper-s-forward nil) | |
3627 (viper-if-string "?") | |
18129 | 3628 ;; this is not used at present, but may be used later |
19078 | 3629 (if (or (not (equal old-str viper-s-string)) |
3630 (not (markerp viper-local-search-start-marker)) | |
3631 (not (marker-buffer viper-local-search-start-marker))) | |
3632 (setq viper-local-search-start-marker (point-marker))) | |
3633 (viper-search viper-s-string nil val) | |
18129 | 3634 (if com |
3635 (progn | |
19078 | 3636 (viper-move-marker-locally 'viper-com-point (mark t)) |
3637 (viper-execute-com 'viper-search-next val com))))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3638 |
18129 | 3639 |
3640 ;; Search for COUNT's occurrence of STRING. | |
3641 ;; Search is forward if FORWARD is non-nil, otherwise backward. | |
3642 ;; INIT-POINT is the position where search is to start. | |
3643 ;; Arguments: | |
3644 ;; (STRING FORW COUNT &optional NO-OFFSET INIT-POINT LIMIT FAIL-IF-NOT-FOUND) | |
19078 | 3645 (defun viper-search (string forward arg |
3646 &optional no-offset init-point fail-if-not-found) | |
18129 | 3647 (if (not (equal string "")) |
19078 | 3648 (let ((val (viper-p-val arg)) |
3649 (com (viper-getcom arg)) | |
18129 | 3650 (offset (not no-offset)) |
19078 | 3651 (case-fold-search viper-case-fold-search) |
18129 | 3652 (start-point (or init-point (point)))) |
19078 | 3653 (viper-deactivate-mark) |
18129 | 3654 (if forward |
3655 (condition-case nil | |
3656 (progn | |
19078 | 3657 (if offset (viper-forward-char-carefully)) |
3658 (if viper-re-search | |
18129 | 3659 (progn |
3660 (re-search-forward string nil nil val) | |
3661 (re-search-backward string)) | |
3662 (search-forward string nil nil val) | |
3663 (search-backward string)) | |
3664 (if (not (equal start-point (point))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3665 (push-mark start-point t))) |
18129 | 3666 (search-failed |
19078 | 3667 (if (and (not fail-if-not-found) viper-search-wrap-around-t) |
18129 | 3668 (progn |
3669 (message "Search wrapped around BOTTOM of buffer") | |
3670 (goto-char (point-min)) | |
19078 | 3671 (viper-search string forward (cons 1 com) t start-point 'fail) |
18129 | 3672 ;; don't wait in macros |
19078 | 3673 (or executing-kbd-macro |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3674 (memq viper-intermediate-command |
19078 | 3675 '(viper-repeat |
3676 viper-digit-argument | |
3677 viper-command-argument)) | |
3678 (sit-for 2)) | |
18129 | 3679 ;; delete the wrap-around message |
3680 (message "") | |
3681 ) | |
3682 (goto-char start-point) | |
3683 (error "`%s': %s not found" | |
3684 string | |
19078 | 3685 (if viper-re-search "Pattern" "String")) |
18129 | 3686 ))) |
3687 ;; backward | |
3688 (condition-case nil | |
3689 (progn | |
19078 | 3690 (if viper-re-search |
18129 | 3691 (re-search-backward string nil nil val) |
3692 (search-backward string nil nil val)) | |
3693 (if (not (equal start-point (point))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3694 (push-mark start-point t))) |
18129 | 3695 (search-failed |
19078 | 3696 (if (and (not fail-if-not-found) viper-search-wrap-around-t) |
18129 | 3697 (progn |
3698 (message "Search wrapped around TOP of buffer") | |
3699 (goto-char (point-max)) | |
19078 | 3700 (viper-search string forward (cons 1 com) t start-point 'fail) |
18129 | 3701 ;; don't wait in macros |
19078 | 3702 (or executing-kbd-macro |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3703 (memq viper-intermediate-command |
19078 | 3704 '(viper-repeat |
3705 viper-digit-argument | |
3706 viper-command-argument)) | |
3707 (sit-for 2)) | |
18129 | 3708 ;; delete the wrap-around message |
3709 (message "") | |
3710 ) | |
3711 (goto-char start-point) | |
3712 (error "`%s': %s not found" | |
3713 string | |
19078 | 3714 (if viper-re-search "Pattern" "String")) |
18129 | 3715 )))) |
3716 ;; pull up or down if at top/bottom of window | |
19078 | 3717 (viper-adjust-window) |
18129 | 3718 ;; highlight the result of search |
3719 ;; don't wait and don't highlight in macros | |
3720 (or executing-kbd-macro | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3721 (memq viper-intermediate-command |
19078 | 3722 '(viper-repeat viper-digit-argument viper-command-argument)) |
3723 (viper-flash-search-pattern)) | |
18129 | 3724 ))) |
3725 | |
19078 | 3726 (defun viper-search-next (arg) |
18129 | 3727 "Repeat previous search." |
3728 (interactive "P") | |
19078 | 3729 (let ((val (viper-p-val arg)) |
3730 (com (viper-getcom arg))) | |
3731 (if (null viper-s-string) (error viper-NoPrevSearch)) | |
3732 (viper-search viper-s-string viper-s-forward arg) | |
18129 | 3733 (if com |
3734 (progn | |
19078 | 3735 (viper-move-marker-locally 'viper-com-point (mark t)) |
3736 (viper-execute-com 'viper-search-next val com))))) | |
3737 | |
3738 (defun viper-search-Next (arg) | |
18129 | 3739 "Repeat previous search in the reverse direction." |
3740 (interactive "P") | |
19078 | 3741 (let ((val (viper-p-val arg)) |
3742 (com (viper-getcom arg))) | |
3743 (if (null viper-s-string) (error viper-NoPrevSearch)) | |
3744 (viper-search viper-s-string (not viper-s-forward) arg) | |
18129 | 3745 (if com |
3746 (progn | |
19078 | 3747 (viper-move-marker-locally 'viper-com-point (mark t)) |
3748 (viper-execute-com 'viper-search-Next val com))))) | |
18129 | 3749 |
3750 | |
3751 ;; Search contents of buffer defined by one of Viper's motion commands. | |
3752 ;; Repeatable via `n' and `N'. | |
19078 | 3753 (defun viper-buffer-search-enable (&optional c) |
3754 (cond (c (setq viper-buffer-search-char c)) | |
3755 ((null viper-buffer-search-char) | |
3756 (setq viper-buffer-search-char ?g))) | |
3757 (define-key viper-vi-basic-map | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3758 (cond ((viper-characterp viper-buffer-search-char) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3759 (char-to-string viper-buffer-search-char)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3760 (t (error "viper-buffer-search-char: wrong value type, %s" |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3761 viper-buffer-search-char))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3762 'viper-command-argument) |
19078 | 3763 (aset viper-exec-array viper-buffer-search-char 'viper-exec-buffer-search) |
3764 (setq viper-prefix-commands | |
3765 (cons viper-buffer-search-char viper-prefix-commands))) | |
18129 | 3766 |
3767 ;; This is a Viper wraper for isearch-forward. | |
19078 | 3768 (defun viper-isearch-forward (arg) |
18129 | 3769 "Do incremental search forward." |
3770 (interactive "P") | |
3771 ;; emacs bug workaround | |
3772 (if (listp arg) (setq arg (car arg))) | |
19078 | 3773 (viper-exec-form-in-emacs (list 'isearch-forward arg))) |
18129 | 3774 |
3775 ;; This is a Viper wraper for isearch-backward." | |
19078 | 3776 (defun viper-isearch-backward (arg) |
18129 | 3777 "Do incremental search backward." |
3778 (interactive "P") | |
3779 ;; emacs bug workaround | |
3780 (if (listp arg) (setq arg (car arg))) | |
19078 | 3781 (viper-exec-form-in-emacs (list 'isearch-backward arg))) |
18129 | 3782 |
3783 | |
3784 ;; visiting and killing files, buffers | |
3785 | |
19078 | 3786 (defun viper-switch-to-buffer () |
18129 | 3787 "Switch to buffer in the current window." |
3788 (interactive) | |
22283
3649674ebf29
(viper-backward-Word, viper-skip-separators): Bug fixes.
Karl Heuer <kwzh@gnu.org>
parents:
21940
diff
changeset
|
3789 (let ((other-buffer (other-buffer (current-buffer))) |
3649674ebf29
(viper-backward-Word, viper-skip-separators): Bug fixes.
Karl Heuer <kwzh@gnu.org>
parents:
21940
diff
changeset
|
3790 buffer) |
18129 | 3791 (setq buffer |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3792 (funcall viper-read-buffer-function |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3793 "Switch to buffer in this window: " other-buffer)) |
22283
3649674ebf29
(viper-backward-Word, viper-skip-separators): Bug fixes.
Karl Heuer <kwzh@gnu.org>
parents:
21940
diff
changeset
|
3794 (switch-to-buffer buffer))) |
18129 | 3795 |
19078 | 3796 (defun viper-switch-to-buffer-other-window () |
18129 | 3797 "Switch to buffer in another window." |
3798 (interactive) | |
22283
3649674ebf29
(viper-backward-Word, viper-skip-separators): Bug fixes.
Karl Heuer <kwzh@gnu.org>
parents:
21940
diff
changeset
|
3799 (let ((other-buffer (other-buffer (current-buffer))) |
3649674ebf29
(viper-backward-Word, viper-skip-separators): Bug fixes.
Karl Heuer <kwzh@gnu.org>
parents:
21940
diff
changeset
|
3800 buffer) |
18129 | 3801 (setq buffer |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3802 (funcall viper-read-buffer-function |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3803 "Switch to buffer in another window: " other-buffer)) |
22283
3649674ebf29
(viper-backward-Word, viper-skip-separators): Bug fixes.
Karl Heuer <kwzh@gnu.org>
parents:
21940
diff
changeset
|
3804 (switch-to-buffer-other-window buffer))) |
18129 | 3805 |
19078 | 3806 (defun viper-kill-buffer () |
18129 | 3807 "Kill a buffer." |
3808 (interactive) | |
3809 (let (buffer buffer-name) | |
3810 (setq buffer-name | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3811 (funcall viper-read-buffer-function |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3812 (format "Kill buffer \(%s\): " |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3813 (buffer-name (current-buffer))))) |
18129 | 3814 (setq buffer |
3815 (if (null buffer-name) | |
3816 (current-buffer) | |
3817 (get-buffer buffer-name))) | |
3818 (if (null buffer) (error "`%s': No such buffer" buffer-name)) | |
3819 (if (or (not (buffer-modified-p buffer)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3820 (y-or-n-p |
18129 | 3821 (format |
3822 "Buffer `%s' is modified, are you sure you want to kill it? " | |
3823 buffer-name))) | |
3824 (kill-buffer buffer) | |
3825 (error "Buffer not killed")))) | |
3826 | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3827 |
18129 | 3828 |
3829 ;; yank and pop | |
3830 | |
19078 | 3831 (defsubst viper-yank (text) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3832 "Yank TEXT silently. This works correctly with Emacs's yank-pop command." |
18129 | 3833 (insert text) |
3834 (setq this-command 'yank)) | |
3835 | |
19078 | 3836 (defun viper-put-back (arg) |
18129 | 3837 "Put back after point/below line." |
3838 (interactive "P") | |
19078 | 3839 (let ((val (viper-p-val arg)) |
3840 (text (if viper-use-register | |
3841 (cond ((viper-valid-register viper-use-register '(digit)) | |
3842 (current-kill | |
3843 (- viper-use-register ?1) 'do-not-rotate)) | |
3844 ((viper-valid-register viper-use-register) | |
3845 (get-register (downcase viper-use-register))) | |
3846 (t (error viper-InvalidRegister viper-use-register))) | |
21940 | 3847 (current-kill 0))) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3848 sv-point chars-inserted lines-inserted) |
18129 | 3849 (if (null text) |
19078 | 3850 (if viper-use-register |
3851 (let ((reg viper-use-register)) | |
3852 (setq viper-use-register nil) | |
3853 (error viper-EmptyRegister reg)) | |
18129 | 3854 (error ""))) |
19078 | 3855 (setq viper-use-register nil) |
3856 (if (viper-end-with-a-newline-p text) | |
18129 | 3857 (progn |
3858 (end-of-line) | |
3859 (if (eobp) | |
3860 (insert "\n") | |
3861 (forward-line 1)) | |
3862 (beginning-of-line)) | |
19078 | 3863 (if (not (eolp)) (viper-forward-char-carefully))) |
3864 (set-marker (viper-mark-marker) (point) (current-buffer)) | |
3865 (viper-set-destructive-command | |
3866 (list 'viper-put-back val nil viper-use-register nil nil)) | |
21940 | 3867 (setq sv-point (point)) |
3868 (viper-loop val (viper-yank text)) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3869 (setq chars-inserted (abs (- (point) sv-point)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3870 lines-inserted (abs (count-lines (point) sv-point))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3871 (if (or (> chars-inserted viper-change-notification-threshold) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3872 (> lines-inserted viper-change-notification-threshold)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3873 (message "Inserted %d character(s), %d line(s)" |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3874 chars-inserted lines-inserted))) |
18129 | 3875 ;; Vi puts cursor on the last char when the yanked text doesn't contain a |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3876 ;; newline; it leaves the cursor at the beginning when the text contains |
18129 | 3877 ;; a newline |
19078 | 3878 (if (viper-same-line (point) (mark)) |
3879 (or (= (point) (mark)) (viper-backward-char-carefully)) | |
18129 | 3880 (exchange-point-and-mark) |
3881 (if (bolp) | |
3882 (back-to-indentation))) | |
19078 | 3883 (viper-deactivate-mark)) |
3884 | |
3885 (defun viper-Put-back (arg) | |
18129 | 3886 "Put back at point/above line." |
3887 (interactive "P") | |
19078 | 3888 (let ((val (viper-p-val arg)) |
3889 (text (if viper-use-register | |
3890 (cond ((viper-valid-register viper-use-register '(digit)) | |
3891 (current-kill | |
3892 (- viper-use-register ?1) 'do-not-rotate)) | |
3893 ((viper-valid-register viper-use-register) | |
3894 (get-register (downcase viper-use-register))) | |
3895 (t (error viper-InvalidRegister viper-use-register))) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3896 (current-kill 0))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3897 sv-point chars-inserted lines-inserted) |
18129 | 3898 (if (null text) |
19078 | 3899 (if viper-use-register |
3900 (let ((reg viper-use-register)) | |
3901 (setq viper-use-register nil) | |
3902 (error viper-EmptyRegister reg)) | |
18129 | 3903 (error ""))) |
19078 | 3904 (setq viper-use-register nil) |
3905 (if (viper-end-with-a-newline-p text) (beginning-of-line)) | |
3906 (viper-set-destructive-command | |
3907 (list 'viper-Put-back val nil viper-use-register nil nil)) | |
3908 (set-marker (viper-mark-marker) (point) (current-buffer)) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3909 (setq sv-point (point)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3910 (viper-loop val (viper-yank text)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3911 (setq chars-inserted (abs (- (point) sv-point)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3912 lines-inserted (abs (count-lines (point) sv-point))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3913 (if (or (> chars-inserted viper-change-notification-threshold) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3914 (> lines-inserted viper-change-notification-threshold)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3915 (message "Inserted %d character(s), %d line(s)" |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3916 chars-inserted lines-inserted))) |
18129 | 3917 ;; Vi puts cursor on the last char when the yanked text doesn't contain a |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3918 ;; newline; it leaves the cursor at the beginning when the text contains |
18129 | 3919 ;; a newline |
19078 | 3920 (if (viper-same-line (point) (mark)) |
3921 (or (= (point) (mark)) (viper-backward-char-carefully)) | |
18129 | 3922 (exchange-point-and-mark) |
3923 (if (bolp) | |
3924 (back-to-indentation))) | |
19078 | 3925 (viper-deactivate-mark)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3926 |
18129 | 3927 |
3928 ;; Copy region to kill-ring. | |
3929 ;; If BEG and END do not belong to the same buffer, copy empty region. | |
19078 | 3930 (defun viper-copy-region-as-kill (beg end) |
18129 | 3931 (condition-case nil |
3932 (copy-region-as-kill beg end) | |
3933 (error (copy-region-as-kill beg beg)))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3934 |
18129 | 3935 |
19078 | 3936 (defun viper-delete-char (arg) |
19462 | 3937 "Delete next character." |
18129 | 3938 (interactive "P") |
19462 | 3939 (let ((val (viper-p-val arg)) |
3940 end-del-pos) | |
19078 | 3941 (viper-set-destructive-command |
3942 (list 'viper-delete-char val nil nil nil nil)) | |
19462 | 3943 (if (and viper-ex-style-editing |
3944 (> val (viper-chars-in-region (point) (viper-line-pos 'end)))) | |
3945 (setq val (viper-chars-in-region (point) (viper-line-pos 'end)))) | |
19078 | 3946 (if (and viper-ex-style-motion (eolp)) |
18129 | 3947 (if (bolp) (error "") (setq val 0))) ; not bol---simply back 1 ch |
19462 | 3948 (save-excursion |
3949 (viper-forward-char-carefully val) | |
3950 (setq end-del-pos (point))) | |
19078 | 3951 (if viper-use-register |
18129 | 3952 (progn |
19078 | 3953 (cond ((viper-valid-register viper-use-register '((Letter))) |
3954 (viper-append-to-register | |
19462 | 3955 (downcase viper-use-register) (point) end-del-pos)) |
19078 | 3956 ((viper-valid-register viper-use-register) |
18129 | 3957 (copy-to-register |
19462 | 3958 viper-use-register (point) end-del-pos nil)) |
19078 | 3959 (t (error viper-InvalidRegister viper-use-register))) |
3960 (setq viper-use-register nil))) | |
19462 | 3961 |
3962 (delete-char val t) | |
19078 | 3963 (if viper-ex-style-motion |
19462 | 3964 (if (and (eolp) (not (bolp))) (backward-char 1))) |
3965 )) | |
18129 | 3966 |
19078 | 3967 (defun viper-delete-backward-char (arg) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
3968 "Delete previous character. On reaching beginning of line, stop and beep." |
18129 | 3969 (interactive "P") |
19462 | 3970 (let ((val (viper-p-val arg)) |
3971 end-del-pos) | |
19078 | 3972 (viper-set-destructive-command |
3973 (list 'viper-delete-backward-char val nil nil nil nil)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3974 (if (and |
19462 | 3975 viper-ex-style-editing |
3976 (> val (viper-chars-in-region (viper-line-pos 'start) (point)))) | |
3977 (setq val (viper-chars-in-region (viper-line-pos 'start) (point)))) | |
3978 (save-excursion | |
3979 (viper-backward-char-carefully val) | |
3980 (setq end-del-pos (point))) | |
19078 | 3981 (if viper-use-register |
18129 | 3982 (progn |
19078 | 3983 (cond ((viper-valid-register viper-use-register '(Letter)) |
3984 (viper-append-to-register | |
19462 | 3985 (downcase viper-use-register) end-del-pos (point))) |
19078 | 3986 ((viper-valid-register viper-use-register) |
18129 | 3987 (copy-to-register |
19462 | 3988 viper-use-register end-del-pos (point) nil)) |
19078 | 3989 (t (error viper-InvalidRegister viper-use-register))) |
3990 (setq viper-use-register nil))) | |
19462 | 3991 (if (and (bolp) viper-ex-style-editing) |
3992 (ding)) | |
3993 (delete-backward-char val t))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3994 |
26588
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
3995 |
19078 | 3996 (defun viper-del-backward-char-in-insert () |
18129 | 3997 "Delete 1 char backwards while in insert mode." |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
3998 (interactive) |
19462 | 3999 (if (and viper-ex-style-editing (bolp)) |
18129 | 4000 (beep 1) |
4001 (delete-backward-char 1 t))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4002 |
26588
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
4003 |
19078 | 4004 (defun viper-del-backward-char-in-replace () |
18129 | 4005 "Delete one character in replace mode. |
19078 | 4006 If `viper-delete-backwards-in-replace' is t, then DEL key actually deletes |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4007 charecters. If it is nil, then the cursor just moves backwards, similarly |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4008 to Vi. The variable `viper-ex-style-editing', if t, doesn't let the |
18129 | 4009 cursor move past the beginning of line." |
4010 (interactive) | |
19078 | 4011 (cond (viper-delete-backwards-in-replace |
18129 | 4012 (cond ((not (bolp)) |
4013 (delete-backward-char 1 t)) | |
19462 | 4014 (viper-ex-style-editing |
18129 | 4015 (beep 1)) |
4016 ((bobp) | |
4017 (beep 1)) | |
4018 (t | |
4019 (delete-backward-char 1 t)))) | |
19462 | 4020 (viper-ex-style-editing |
18129 | 4021 (if (bolp) |
4022 (beep 1) | |
4023 (backward-char 1))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4024 (t |
18129 | 4025 (backward-char 1)))) |
4026 | |
4027 | |
4028 | |
4029 ;; join lines. | |
4030 | |
19078 | 4031 (defun viper-join-lines (arg) |
18129 | 4032 "Join this line to next, if ARG is nil. Otherwise, join ARG lines." |
4033 (interactive "*P") | |
19078 | 4034 (let ((val (viper-P-val arg))) |
4035 (viper-set-destructive-command | |
4036 (list 'viper-join-lines val nil nil nil nil)) | |
4037 (viper-loop (if (null val) 1 (1- val)) | |
18129 | 4038 (end-of-line) |
4039 (if (not (eobp)) | |
4040 (progn | |
4041 (forward-line 1) | |
4042 (delete-region (point) (1- (point))) | |
18839 | 4043 (fixup-whitespace) |
4044 ;; fixup-whitespace sometimes does not leave space | |
4045 ;; between objects, so we insert it as in Vi | |
4046 (or (looking-at " ") | |
4047 (insert " ") | |
4048 (backward-char 1)) | |
19462 | 4049 ))))) |
18129 | 4050 |
4051 | |
4052 ;; Replace state | |
4053 | |
19078 | 4054 (defun viper-change (beg end) |
18129 | 4055 (if (markerp beg) (setq beg (marker-position beg))) |
4056 (if (markerp end) (setq end (marker-position end))) | |
4057 ;; beg is sometimes (mark t), which may be nil | |
4058 (or beg (setq beg end)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4059 |
19078 | 4060 (viper-set-complex-command-for-undo) |
4061 (if viper-use-register | |
18129 | 4062 (progn |
19078 | 4063 (copy-to-register viper-use-register beg end nil) |
4064 (setq viper-use-register nil))) | |
4065 (viper-set-replace-overlay beg end) | |
18129 | 4066 (setq last-command nil) ; separate repl text from prev kills |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4067 |
19078 | 4068 (if (= (viper-replace-start) (point-max)) |
18129 | 4069 (error "End of buffer")) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4070 |
19078 | 4071 (setq viper-last-replace-region |
4072 (buffer-substring (viper-replace-start) | |
4073 (viper-replace-end))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4074 |
18129 | 4075 ;; protect against error while inserting "@" and other disasters |
4076 ;; (e.g., read-only buff) | |
4077 (condition-case conds | |
19078 | 4078 (if (or viper-allow-multiline-replace-regions |
4079 (viper-same-line (viper-replace-start) | |
19203 | 4080 (viper-replace-end))) |
18129 | 4081 (progn |
4082 ;; tabs cause problems in replace, so untabify | |
19078 | 4083 (goto-char (viper-replace-end)) |
18129 | 4084 (insert-before-markers "@") ; put placeholder after the TAB |
19078 | 4085 (untabify (viper-replace-start) (point)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4086 ;; del @, don't put on kill ring |
18129 | 4087 (delete-backward-char 1) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4088 |
19078 | 4089 (viper-set-replace-overlay-glyphs |
4090 viper-replace-region-start-delimiter | |
4091 viper-replace-region-end-delimiter) | |
18129 | 4092 ;; this move takes care of the last posn in the overlay, which |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4093 ;; has to be shifted because of insert. We can't simply insert |
18129 | 4094 ;; "$" before-markers because then overlay-start will shift the |
4095 ;; beginning of the overlay in case we are replacing a single | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4096 ;; character. This fixes the bug with `s' and `cl' commands. |
19078 | 4097 (viper-move-replace-overlay (viper-replace-start) (point)) |
4098 (goto-char (viper-replace-start)) | |
4099 (viper-change-state-to-replace t)) | |
4100 (kill-region (viper-replace-start) | |
4101 (viper-replace-end)) | |
4102 (viper-hide-replace-overlay) | |
4103 (viper-change-state-to-insert)) | |
18129 | 4104 (error ;; make sure that the overlay doesn't stay. |
4105 ;; go back to the original point | |
19078 | 4106 (goto-char (viper-replace-start)) |
4107 (viper-hide-replace-overlay) | |
4108 (viper-message-conditions conds)))) | |
4109 | |
4110 | |
4111 (defun viper-change-subr (beg end) | |
18129 | 4112 ;; beg is sometimes (mark t), which may be nil |
4113 (or beg (setq beg end)) | |
19078 | 4114 (if viper-use-register |
18129 | 4115 (progn |
19078 | 4116 (copy-to-register viper-use-register beg end nil) |
4117 (setq viper-use-register nil))) | |
18129 | 4118 (kill-region beg end) |
19078 | 4119 (setq this-command 'viper-change) |
4120 (viper-yank-last-insertion)) | |
4121 | |
4122 (defun viper-toggle-case (arg) | |
18129 | 4123 "Toggle character case." |
4124 (interactive "P") | |
19078 | 4125 (let ((val (viper-p-val arg)) (c)) |
4126 (viper-set-destructive-command | |
4127 (list 'viper-toggle-case val nil nil nil nil)) | |
18129 | 4128 (while (> val 0) |
4129 (setq c (following-char)) | |
4130 (delete-char 1 nil) | |
4131 (if (eq c (upcase c)) | |
4132 (insert-char (downcase c) 1) | |
4133 (insert-char (upcase c) 1)) | |
4134 (if (eolp) (backward-char 1)) | |
4135 (setq val (1- val))))) | |
4136 | |
4137 | |
4138 ;; query replace | |
4139 | |
19078 | 4140 (defun viper-query-replace () |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4141 "Query replace. |
18129 | 4142 If a null string is suplied as the string to be replaced, |
4143 the query replace mode will toggle between string replace | |
4144 and regexp replace." | |
4145 (interactive) | |
4146 (let (str) | |
19078 | 4147 (setq str (viper-read-string-with-history |
4148 (if viper-re-query-replace "Query replace regexp: " | |
18129 | 4149 "Query replace: ") |
4150 nil ; no initial | |
19078 | 4151 'viper-replace1-history |
4152 (car viper-replace1-history) ; default | |
18129 | 4153 )) |
4154 (if (string= str "") | |
4155 (progn | |
19078 | 4156 (setq viper-re-query-replace (not viper-re-query-replace)) |
18129 | 4157 (message "Query replace mode changed to %s" |
19078 | 4158 (if viper-re-query-replace "regexp replace" |
18129 | 4159 "string replace"))) |
19078 | 4160 (if viper-re-query-replace |
18129 | 4161 (query-replace-regexp |
4162 str | |
19078 | 4163 (viper-read-string-with-history |
18129 | 4164 (format "Query replace regexp `%s' with: " str) |
4165 nil ; no initial | |
19078 | 4166 'viper-replace1-history |
4167 (car viper-replace1-history) ; default | |
18129 | 4168 )) |
4169 (query-replace | |
4170 str | |
19078 | 4171 (viper-read-string-with-history |
18129 | 4172 (format "Query replace `%s' with: " str) |
4173 nil ; no initial | |
19078 | 4174 'viper-replace1-history |
4175 (car viper-replace1-history) ; default | |
18129 | 4176 )))))) |
4177 | |
4178 | |
4179 ;; marking | |
4180 | |
19078 | 4181 (defun viper-mark-beginning-of-buffer () |
18129 | 4182 "Mark beginning of buffer." |
4183 (interactive) | |
4184 (push-mark (point)) | |
4185 (goto-char (point-min)) | |
4186 (exchange-point-and-mark) | |
4187 (message "Mark set at the beginning of buffer")) | |
4188 | |
19078 | 4189 (defun viper-mark-end-of-buffer () |
18129 | 4190 "Mark end of buffer." |
4191 (interactive) | |
4192 (push-mark (point)) | |
4193 (goto-char (point-max)) | |
4194 (exchange-point-and-mark) | |
4195 (message "Mark set at the end of buffer")) | |
4196 | |
19078 | 4197 (defun viper-mark-point () |
18129 | 4198 "Set mark at point of buffer." |
4199 (interactive) | |
4200 (let ((char (read-char))) | |
4201 (cond ((and (<= ?a char) (<= char ?z)) | |
4202 (point-to-register (1+ (- char ?a)))) | |
19078 | 4203 ((= char ?<) (viper-mark-beginning-of-buffer)) |
4204 ((= char ?>) (viper-mark-end-of-buffer)) | |
4205 ((= char ?.) (viper-set-mark-if-necessary)) | |
4206 ((= char ?,) (viper-cycle-through-mark-ring)) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4207 ((= char ?^) (push-mark viper-saved-mark t t)) |
18129 | 4208 ((= char ?D) (mark-defun)) |
4209 (t (error "")) | |
4210 ))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4211 |
18129 | 4212 ;; Algorithm: If first invocation of this command save mark on ring, goto |
4213 ;; mark, M0, and pop the most recent elt from the mark ring into mark, | |
4214 ;; making it into the new mark, M1. | |
4215 ;; Push this mark back and set mark to the original point position, p1. | |
4216 ;; So, if you hit '' or `` then you can return to p1. | |
4217 ;; | |
4218 ;; If repeated command, pop top elt from the ring into mark and | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4219 ;; jump there. This forgets the position, p1, and puts M1 back into mark. |
18129 | 4220 ;; Then we save the current pos, which is M0, jump to M1 and pop M2 from |
4221 ;; the ring into mark. Push M2 back on the ring and set mark to M0. | |
4222 ;; etc. | |
19078 | 4223 (defun viper-cycle-through-mark-ring () |
18129 | 4224 "Visit previous locations on the mark ring. |
4225 One can use `` and '' to temporarily jump 1 step back." | |
4226 (let* ((sv-pt (point))) | |
4227 ;; if repeated `m,' command, pop the previously saved mark. | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4228 ;; Prev saved mark is actually prev saved point. It is used if the |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4229 ;; user types `` or '' and is discarded |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4230 ;; from the mark ring by the next `m,' command. |
18129 | 4231 ;; In any case, go to the previous or previously saved mark. |
4232 ;; Then push the current mark (popped off the ring) and set current | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4233 ;; point to be the mark. Current pt as mark is discarded by the next |
18129 | 4234 ;; m, command. |
19078 | 4235 (if (eq last-command 'viper-cycle-through-mark-ring) |
18129 | 4236 () |
4237 ;; save current mark if the first iteration | |
19078 | 4238 (setq mark-ring (delete (viper-mark-marker) mark-ring)) |
18129 | 4239 (if (mark t) |
4240 (push-mark (mark t) t)) ) | |
4241 (pop-mark) | |
4242 (set-mark-command 1) | |
4243 ;; don't duplicate mark on the ring | |
19078 | 4244 (setq mark-ring (delete (viper-mark-marker) mark-ring)) |
18129 | 4245 (push-mark sv-pt t) |
19078 | 4246 (viper-deactivate-mark) |
4247 (setq this-command 'viper-cycle-through-mark-ring) | |
18129 | 4248 )) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4249 |
18129 | 4250 |
19078 | 4251 (defun viper-goto-mark (arg) |
18129 | 4252 "Go to mark." |
4253 (interactive "P") | |
4254 (let ((char (read-char)) | |
19078 | 4255 (com (viper-getcom arg))) |
4256 (viper-goto-mark-subr char com nil))) | |
4257 | |
4258 (defun viper-goto-mark-and-skip-white (arg) | |
18129 | 4259 "Go to mark and skip to first non-white character on line." |
4260 (interactive "P") | |
4261 (let ((char (read-char)) | |
19078 | 4262 (com (viper-getCom arg))) |
4263 (viper-goto-mark-subr char com t))) | |
4264 | |
4265 (defun viper-goto-mark-subr (char com skip-white) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4266 (if (eobp) |
18129 | 4267 (if (bobp) |
4268 (error "Empty buffer") | |
4269 (backward-char 1))) | |
19078 | 4270 (cond ((viper-valid-register char '(letter)) |
18129 | 4271 (let* ((buff (current-buffer)) |
4272 (reg (1+ (- char ?a))) | |
4273 (text-marker (get-register reg))) | |
19078 | 4274 (if com (viper-move-marker-locally 'viper-com-point (point))) |
4275 (if (not (viper-valid-marker text-marker)) | |
4276 (error viper-EmptyTextmarker char)) | |
4277 (if (and (viper-same-line (point) viper-last-jump) | |
4278 (= (point) viper-last-jump-ignore)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4279 (push-mark viper-last-jump t) |
18129 | 4280 (push-mark nil t)) ; no msg |
19078 | 4281 (viper-register-to-point reg) |
4282 (setq viper-last-jump (point-marker)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4283 (cond (skip-white |
18129 | 4284 (back-to-indentation) |
19078 | 4285 (setq viper-last-jump-ignore (point)))) |
18129 | 4286 (if com |
4287 (if (equal buff (current-buffer)) | |
19078 | 4288 (viper-execute-com (if skip-white |
4289 'viper-goto-mark-and-skip-white | |
4290 'viper-goto-mark) | |
18129 | 4291 nil com) |
4292 (switch-to-buffer buff) | |
19078 | 4293 (goto-char viper-com-point) |
4294 (viper-change-state-to-vi) | |
18129 | 4295 (error ""))))) |
4296 ((and (not skip-white) (= char ?`)) | |
19078 | 4297 (if com (viper-move-marker-locally 'viper-com-point (point))) |
4298 (if (and (viper-same-line (point) viper-last-jump) | |
4299 (= (point) viper-last-jump-ignore)) | |
4300 (goto-char viper-last-jump)) | |
18129 | 4301 (if (null (mark t)) (error "Mark is not set in this buffer")) |
4302 (if (= (point) (mark t)) (pop-mark)) | |
4303 (exchange-point-and-mark) | |
19078 | 4304 (setq viper-last-jump (point-marker) |
4305 viper-last-jump-ignore 0) | |
4306 (if com (viper-execute-com 'viper-goto-mark nil com))) | |
18129 | 4307 ((and skip-white (= char ?')) |
19078 | 4308 (if com (viper-move-marker-locally 'viper-com-point (point))) |
4309 (if (and (viper-same-line (point) viper-last-jump) | |
4310 (= (point) viper-last-jump-ignore)) | |
4311 (goto-char viper-last-jump)) | |
18129 | 4312 (if (= (point) (mark t)) (pop-mark)) |
4313 (exchange-point-and-mark) | |
19078 | 4314 (setq viper-last-jump (point)) |
18129 | 4315 (back-to-indentation) |
19078 | 4316 (setq viper-last-jump-ignore (point)) |
4317 (if com (viper-execute-com 'viper-goto-mark-and-skip-white nil com))) | |
4318 (t (error viper-InvalidTextmarker char)))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4319 |
19078 | 4320 (defun viper-insert-tab () |
18129 | 4321 (interactive) |
4322 (insert-tab)) | |
4323 | |
19078 | 4324 (defun viper-exchange-point-and-mark () |
18129 | 4325 (interactive) |
4326 (exchange-point-and-mark) | |
4327 (back-to-indentation)) | |
4328 | |
4329 ;; Input Mode Indentation | |
4330 | |
4331 ;; Returns t, if the string before point matches the regexp STR. | |
19078 | 4332 (defsubst viper-looking-back (str) |
18129 | 4333 (and (save-excursion (re-search-backward str nil t)) |
4334 (= (point) (match-end 0)))) | |
4335 | |
4336 | |
19078 | 4337 (defun viper-forward-indent () |
18129 | 4338 "Indent forward -- `C-t' in Vi." |
4339 (interactive) | |
19078 | 4340 (setq viper-cted t) |
4341 (indent-to (+ (current-column) viper-shift-width))) | |
4342 | |
4343 (defun viper-backward-indent () | |
18129 | 4344 "Backtab, C-d in VI" |
4345 (interactive) | |
19078 | 4346 (if viper-cted |
18129 | 4347 (let ((p (point)) (c (current-column)) bol (indent t)) |
19078 | 4348 (if (viper-looking-back "[0^]") |
18129 | 4349 (progn |
4350 (if (eq ?^ (preceding-char)) | |
19078 | 4351 (setq viper-preserve-indent t)) |
18129 | 4352 (delete-backward-char 1) |
4353 (setq p (point)) | |
4354 (setq indent nil))) | |
4355 (save-excursion | |
4356 (beginning-of-line) | |
4357 (setq bol (point))) | |
4358 (if (re-search-backward "[^ \t]" bol 1) (forward-char)) | |
4359 (delete-region (point) p) | |
4360 (if indent | |
19078 | 4361 (indent-to (- c viper-shift-width))) |
4362 (if (or (bolp) (viper-looking-back "[^ \t]")) | |
4363 (setq viper-cted nil))))) | |
4364 | |
4365 (defun viper-autoindent () | |
18129 | 4366 "Auto Indentation, Vi-style." |
4367 (interactive) | |
4368 (let ((col (current-indentation))) | |
4369 (if abbrev-mode (expand-abbrev)) | |
19078 | 4370 (if viper-preserve-indent |
4371 (setq viper-preserve-indent nil) | |
4372 (setq viper-current-indent col)) | |
18129 | 4373 ;; don't leave whitespace lines around |
4374 (if (memq last-command | |
19078 | 4375 '(viper-autoindent |
4376 viper-open-line viper-Open-line | |
4377 viper-replace-state-exit-cmd)) | |
18129 | 4378 (indent-to-left-margin)) |
4379 ;; use \n instead of newline, or else <Return> will move the insert point | |
4380 ;;(newline 1) | |
4381 (insert "\n") | |
19078 | 4382 (if viper-auto-indent |
18129 | 4383 (progn |
19078 | 4384 (setq viper-cted t) |
4385 (if (and viper-electric-mode | |
4386 (not | |
4387 (memq major-mode '(fundamental-mode | |
4388 text-mode | |
4389 paragraph-indent-text-mode )))) | |
18129 | 4390 (indent-according-to-mode) |
19078 | 4391 (indent-to viper-current-indent)) |
18129 | 4392 )) |
4393 )) | |
4394 | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4395 |
18129 | 4396 ;; Viewing registers |
4397 | |
19078 | 4398 (defun viper-ket-function (arg) |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4399 "Function called by \], the ket. View registers and call \]\]." |
18129 | 4400 (interactive "P") |
4401 (let ((reg (read-char))) | |
19078 | 4402 (cond ((viper-valid-register reg '(letter Letter)) |
18129 | 4403 (view-register (downcase reg))) |
19078 | 4404 ((viper-valid-register reg '(digit)) |
18129 | 4405 (let ((text (current-kill (- reg ?1) 'do-not-rotate))) |
20003 | 4406 (with-output-to-temp-buffer " *viper-info*" |
4407 (princ (format "Register %c contains the string:\n" reg)) | |
4408 (princ text)) | |
4409 )) | |
18129 | 4410 ((= ?\] reg) |
19078 | 4411 (viper-next-heading arg)) |
18129 | 4412 (t (error |
19078 | 4413 viper-InvalidRegister reg))))) |
4414 | |
4415 (defun viper-brac-function (arg) | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4416 "Function called by \[, the brac. View textmarkers and call \[\[" |
18129 | 4417 (interactive "P") |
4418 (let ((reg (read-char))) | |
4419 (cond ((= ?\[ reg) | |
19078 | 4420 (viper-prev-heading arg)) |
18129 | 4421 ((= ?\] reg) |
19078 | 4422 (viper-heading-end arg)) |
4423 ((viper-valid-register reg '(letter)) | |
18129 | 4424 (let* ((val (get-register (1+ (- reg ?a)))) |
20003 | 4425 (buf (if (not (markerp val)) |
19078 | 4426 (error viper-EmptyTextmarker reg) |
18129 | 4427 (marker-buffer val))) |
4428 (pos (marker-position val)) | |
4429 line-no text (s pos) (e pos)) | |
20003 | 4430 (with-output-to-temp-buffer " *viper-info*" |
18129 | 4431 (if (and buf pos) |
4432 (progn | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4433 (save-excursion |
18129 | 4434 (set-buffer buf) |
4435 (setq line-no (1+ (count-lines (point-min) val))) | |
4436 (goto-char pos) | |
4437 (beginning-of-line) | |
4438 (if (re-search-backward "[^ \t]" nil t) | |
4439 (progn | |
4440 (beginning-of-line) | |
4441 (setq s (point)))) | |
4442 (goto-char pos) | |
4443 (forward-line 1) | |
4444 (if (re-search-forward "[^ \t]" nil t) | |
4445 (progn | |
4446 (end-of-line) | |
4447 (setq e (point)))) | |
4448 (setq text (buffer-substring s e)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4449 (setq text (format "%s<%c>%s" |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4450 (substring text 0 (- pos s)) |
18129 | 4451 reg (substring text (- pos s))))) |
20003 | 4452 (princ |
18129 | 4453 (format |
4454 "Textmarker `%c' is in buffer `%s' at line %d.\n" | |
4455 reg (buffer-name buf) line-no)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4456 (princ (format "Here is some text around %c:\n\n %s" |
18129 | 4457 reg text))) |
20003 | 4458 (princ (format viper-EmptyTextmarker reg)))) |
4459 )) | |
19078 | 4460 (t (error viper-InvalidTextmarker reg))))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4461 |
18129 | 4462 |
4463 | |
4464 ;; commands in insertion mode | |
4465 | |
19078 | 4466 (defun viper-delete-backward-word (arg) |
18129 | 4467 "Delete previous word." |
4468 (interactive "p") | |
4469 (save-excursion | |
4470 (push-mark nil t) | |
4471 (backward-word arg) | |
4472 (delete-region (point) (mark t)) | |
4473 (pop-mark))) | |
4474 | |
4475 | |
18839 | 4476 (defun viper-set-expert-level (&optional dont-change-unless) |
18129 | 4477 "Sets the expert level for a Viper user. |
4478 Can be called interactively to change (temporarily or permanently) the | |
4479 current expert level. | |
4480 | |
18289 | 4481 The optional argument DONT-CHANGE-UNLESS, if not nil, says that |
18129 | 4482 the level should not be changed, unless its current value is |
4483 meaningless (i.e., not one of 1,2,3,4,5). | |
4484 | |
4485 User level determines the setting of Viper variables that are most | |
4486 sensitive for VI-style look-and-feel." | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4487 |
18129 | 4488 (interactive) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4489 |
18839 | 4490 (if (not (natnump viper-expert-level)) (setq viper-expert-level 0)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4491 |
18129 | 4492 (save-window-excursion |
4493 (delete-other-windows) | |
18839 | 4494 ;; if 0 < viper-expert-level < viper-max-expert-level |
18129 | 4495 ;; & dont-change-unless = t -- use it; else ask |
19078 | 4496 (viper-ask-level dont-change-unless)) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4497 |
19078 | 4498 (setq viper-always t |
4499 viper-ex-style-motion t | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4500 viper-ex-style-editing t |
19078 | 4501 viper-want-ctl-h-help nil) |
18129 | 4502 |
18839 | 4503 (cond ((eq viper-expert-level 1) ; novice or beginner |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4504 (global-set-key ; in emacs-state |
19078 | 4505 viper-toggle-key |
4506 (if (viper-window-display-p) 'viper-iconify 'suspend-emacs)) | |
4507 (setq viper-no-multiple-ESC t | |
4508 viper-re-search t | |
4509 viper-vi-style-in-minibuffer t | |
4510 viper-search-wrap-around-t t | |
4511 viper-electric-mode nil | |
4512 viper-want-emacs-keys-in-vi nil | |
4513 viper-want-emacs-keys-in-insert nil)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4514 |
18839 | 4515 ((and (> viper-expert-level 1) (< viper-expert-level 5)) |
18129 | 4516 ;; intermediate to guru |
19078 | 4517 (setq viper-no-multiple-ESC (if (viper-window-display-p) |
4518 t 'twice) | |
4519 viper-electric-mode t | |
4520 viper-want-emacs-keys-in-vi t | |
4521 viper-want-emacs-keys-in-insert (> viper-expert-level 2)) | |
4522 | |
4523 (if (eq viper-expert-level 4) ; respect user's ex-style motion | |
4524 ; and viper-no-multiple-ESC | |
18129 | 4525 (progn |
18839 | 4526 (setq-default |
19462 | 4527 viper-ex-style-editing |
4528 (viper-standard-value 'viper-ex-style-editing) | |
19078 | 4529 viper-ex-style-motion |
4530 (viper-standard-value 'viper-ex-style-motion)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4531 (setq viper-ex-style-motion |
19078 | 4532 (viper-standard-value 'viper-ex-style-motion) |
19462 | 4533 viper-ex-style-editing |
4534 (viper-standard-value 'viper-ex-style-editing) | |
19078 | 4535 viper-re-search |
4536 (viper-standard-value 'viper-re-search) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4537 viper-no-multiple-ESC |
19078 | 4538 (viper-standard-value 'viper-no-multiple-ESC))))) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4539 |
18129 | 4540 ;; A wizard!! |
4541 ;; Ideally, if 5 is selected, a buffer should pop up to let the | |
4542 ;; user toggle the values of variables. | |
19462 | 4543 (t (setq-default viper-ex-style-editing |
4544 (viper-standard-value 'viper-ex-style-editing) | |
19078 | 4545 viper-ex-style-motion |
4546 (viper-standard-value 'viper-ex-style-motion)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4547 (setq viper-want-ctl-h-help |
19078 | 4548 (viper-standard-value 'viper-want-ctl-h-help) |
18289 | 4549 viper-always |
18839 | 4550 (viper-standard-value 'viper-always) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4551 viper-no-multiple-ESC |
19078 | 4552 (viper-standard-value 'viper-no-multiple-ESC) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4553 viper-ex-style-motion |
19078 | 4554 (viper-standard-value 'viper-ex-style-motion) |
19462 | 4555 viper-ex-style-editing |
4556 (viper-standard-value 'viper-ex-style-editing) | |
19078 | 4557 viper-re-search |
4558 (viper-standard-value 'viper-re-search) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4559 viper-electric-mode |
19078 | 4560 (viper-standard-value 'viper-electric-mode) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4561 viper-want-emacs-keys-in-vi |
19078 | 4562 (viper-standard-value 'viper-want-emacs-keys-in-vi) |
4563 viper-want-emacs-keys-in-insert | |
4564 (viper-standard-value 'viper-want-emacs-keys-in-insert)))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4565 |
19078 | 4566 (viper-set-mode-vars-for viper-current-state) |
18289 | 4567 (if (or viper-always |
18839 | 4568 (and (> viper-expert-level 0) (> 5 viper-expert-level))) |
19078 | 4569 (viper-set-hooks))) |
18129 | 4570 |
26588
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
4571 |
18129 | 4572 ;; Ask user expert level. |
19078 | 4573 (defun viper-ask-level (dont-change-unless) |
4574 (let ((ask-buffer " *viper-ask-level*") | |
18129 | 4575 level-changed repeated) |
4576 (save-window-excursion | |
4577 (switch-to-buffer ask-buffer) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4578 |
18839 | 4579 (while (or (> viper-expert-level viper-max-expert-level) |
4580 (< viper-expert-level 1) | |
18129 | 4581 (null dont-change-unless)) |
4582 (erase-buffer) | |
4583 (if repeated | |
4584 (progn | |
4585 (message "Invalid user level") | |
4586 (beep 1)) | |
4587 (setq repeated t)) | |
4588 (setq dont-change-unless t | |
4589 level-changed t) | |
4590 (insert " | |
4591 Please specify your level of familiarity with the venomous VI PERil | |
4592 (and the VI Plan for Emacs Rescue). | |
18839 | 4593 You can change it at any time by typing `M-x viper-set-expert-level RET' |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4594 |
18129 | 4595 1 -- BEGINNER: Almost all Emacs features are suppressed. |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4596 Feels almost like straight Vi. File name completion and |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4597 command history in the minibuffer are thrown in as a bonus. |
19078 | 4598 To use Emacs productively, you must reach level 3 or higher. |
18129 | 4599 2 -- MASTER: C-c now has its standard Emacs meaning in Vi command state, |
19078 | 4600 so most Emacs commands can be used when Viper is in Vi state. |
4601 Good progress---you are well on the way to level 3! | |
18129 | 4602 3 -- GRAND MASTER: Like 3, but most Emacs commands are available also |
19078 | 4603 in Viper's insert state. |
4604 4 -- GURU: Like 3, but user settings are respected for viper-no-multiple-ESC, | |
19462 | 4605 viper-ex-style-motion, viper-ex-style-editing, and |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4606 viper-re-search variables. Adjust these settings to your taste. |
18289 | 4607 5 -- WIZARD: Like 4, but user settings are also respected for viper-always, |
19078 | 4608 viper-electric-mode, viper-want-ctl-h-help, viper-want-emacs-keys-in-vi, |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4609 and viper-want-emacs-keys-in-insert. Adjust these to your taste. |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4610 |
18129 | 4611 Please, specify your level now: ") |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4612 |
19078 | 4613 (setq viper-expert-level (- (viper-read-char-exclusive) ?0)) |
18129 | 4614 ) ; end while |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4615 |
18129 | 4616 ;; tell the user if level was changed |
4617 (and level-changed | |
4618 (progn | |
4619 (insert | |
4620 (format "\n\n\n\n\n\t\tYou have selected user level %d" | |
18839 | 4621 viper-expert-level)) |
18129 | 4622 (if (y-or-n-p "Do you wish to make this change permanent? ") |
18839 | 4623 ;; save the setting for viper-expert-level |
19078 | 4624 (viper-save-setting |
18839 | 4625 'viper-expert-level |
4626 (format "Saving user level %d ..." viper-expert-level) | |
19078 | 4627 viper-custom-file-name)) |
18129 | 4628 )) |
4629 (bury-buffer) ; remove ask-buffer from screen | |
4630 (message "") | |
4631 ))) | |
4632 | |
4633 | |
19078 | 4634 (defun viper-nil () |
18129 | 4635 (interactive) |
4636 (beep 1)) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4637 |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4638 |
18129 | 4639 ;; if ENFORCE-BUFFER is not nil, error if CHAR is a marker in another buffer |
19078 | 4640 (defun viper-register-to-point (char &optional enforce-buffer) |
18129 | 4641 "Like jump-to-register, but switches to another buffer in another window." |
4642 (interactive "cViper register to point: ") | |
4643 (let ((val (get-register char))) | |
4644 (cond | |
4645 ((and (fboundp 'frame-configuration-p) | |
4646 (frame-configuration-p val)) | |
4647 (set-frame-configuration val)) | |
4648 ((window-configuration-p val) | |
4649 (set-window-configuration val)) | |
19078 | 4650 ((viper-valid-marker val) |
18129 | 4651 (if (and enforce-buffer |
4652 (not (equal (current-buffer) (marker-buffer val)))) | |
19078 | 4653 (error (concat viper-EmptyTextmarker " in this buffer") |
18129 | 4654 (1- (+ char ?a)))) |
4655 (pop-to-buffer (marker-buffer val)) | |
4656 (goto-char val)) | |
4657 ((and (consp val) (eq (car val) 'file)) | |
4658 (find-file (cdr val))) | |
4659 (t | |
19078 | 4660 (error viper-EmptyTextmarker (1- (+ char ?a))))))) |
4661 | |
4662 | |
4663 (defun viper-save-kill-buffer () | |
18129 | 4664 "Save then kill current buffer. " |
4665 (interactive) | |
18839 | 4666 (if (< viper-expert-level 2) |
18129 | 4667 (save-buffers-kill-emacs) |
4668 (save-buffer) | |
4669 (kill-buffer (current-buffer)))) | |
4670 | |
4671 | |
4672 | |
4673 ;;; Bug Report | |
4674 | |
19078 | 4675 (defun viper-submit-report () |
18129 | 4676 "Submit bug report on Viper." |
4677 (interactive) | |
4678 (let ((reporter-prompt-for-summary-p t) | |
19078 | 4679 (viper-device-type (viper-device-type)) |
18129 | 4680 color-display-p frame-parameters |
4681 minibuffer-emacs-face minibuffer-vi-face minibuffer-insert-face | |
4682 varlist salutation window-config) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4683 |
18129 | 4684 ;; If mode info is needed, add variable to `let' and then set it below, |
4685 ;; like we did with color-display-p. | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4686 (setq color-display-p (if (viper-window-display-p) |
19078 | 4687 (viper-color-display-p) |
18129 | 4688 'non-x) |
19078 | 4689 minibuffer-vi-face (if (viper-has-face-support-p) |
4690 (viper-get-face viper-minibuffer-vi-face) | |
18129 | 4691 'non-x) |
19078 | 4692 minibuffer-insert-face (if (viper-has-face-support-p) |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4693 (viper-get-face |
19078 | 4694 viper-minibuffer-insert-face) |
18129 | 4695 'non-x) |
19078 | 4696 minibuffer-emacs-face (if (viper-has-face-support-p) |
4697 (viper-get-face | |
4698 viper-minibuffer-emacs-face) | |
18129 | 4699 'non-x) |
4700 frame-parameters (if (fboundp 'frame-parameters) | |
4701 (frame-parameters (selected-frame)))) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4702 |
19078 | 4703 (setq varlist (list 'viper-vi-minibuffer-minor-mode |
4704 'viper-insert-minibuffer-minor-mode | |
4705 'viper-vi-intercept-minor-mode | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4706 'viper-vi-local-user-minor-mode |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4707 'viper-vi-kbd-minor-mode |
19078 | 4708 'viper-vi-global-user-minor-mode |
4709 'viper-vi-state-modifier-minor-mode | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4710 'viper-vi-diehard-minor-mode |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4711 'viper-vi-basic-minor-mode |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4712 'viper-replace-minor-mode |
19078 | 4713 'viper-insert-intercept-minor-mode |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4714 'viper-insert-local-user-minor-mode |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4715 'viper-insert-kbd-minor-mode |
19078 | 4716 'viper-insert-global-user-minor-mode |
4717 'viper-insert-state-modifier-minor-mode | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4718 'viper-insert-diehard-minor-mode |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4719 'viper-insert-basic-minor-mode |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4720 'viper-emacs-intercept-minor-mode |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4721 'viper-emacs-local-user-minor-mode |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4722 'viper-emacs-kbd-minor-mode |
19078 | 4723 'viper-emacs-global-user-minor-mode |
4724 'viper-emacs-state-modifier-minor-mode | |
4725 'viper-automatic-iso-accents | |
19462 | 4726 'viper-special-input-method |
19078 | 4727 'viper-want-emacs-keys-in-insert |
4728 'viper-want-emacs-keys-in-vi | |
4729 'viper-keep-point-on-undo | |
4730 'viper-no-multiple-ESC | |
4731 'viper-electric-mode | |
4732 'viper-ESC-key | |
4733 'viper-want-ctl-h-help | |
19462 | 4734 'viper-ex-style-editing |
19078 | 4735 'viper-delete-backwards-in-replace |
4736 'viper-vi-style-in-minibuffer | |
4737 'viper-vi-state-hook | |
4738 'viper-insert-state-hook | |
4739 'viper-replace-state-hook | |
4740 'viper-emacs-state-hook | |
18129 | 4741 'ex-cycle-other-window |
4742 'ex-cycle-through-non-files | |
18839 | 4743 'viper-expert-level |
18129 | 4744 'major-mode |
19078 | 4745 'viper-device-type |
18129 | 4746 'color-display-p |
4747 'frame-parameters | |
4748 'minibuffer-vi-face | |
4749 'minibuffer-insert-face | |
4750 'minibuffer-emacs-face | |
4751 )) | |
4752 (setq salutation " | |
4753 Congratulations! You may have unearthed a bug in Viper! | |
4754 Please mail a concise, accurate summary of the problem to the address above. | |
4755 | |
4756 -------------------------------------------------------------------") | |
4757 (setq window-config (current-window-configuration)) | |
19078 | 4758 (with-output-to-temp-buffer " *viper-info*" |
4759 (switch-to-buffer " *viper-info*") | |
18129 | 4760 (delete-other-windows) |
4761 (princ " | |
4762 PLEASE FOLLOW THESE PROCEDURES | |
4763 ------------------------------ | |
4764 | |
4765 Before reporting a bug, please verify that it is related to Viper, and is | |
4766 not cause by other packages you are using. | |
4767 | |
4768 Don't report compilation warnings, unless you are certain that there is a | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4769 problem. These warnings are normal and unavoidable. |
18129 | 4770 |
4771 Please note that users should not modify variables and keymaps other than | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4772 those advertised in the manual. Such `customization' is likely to crash |
18129 | 4773 Viper, as it would any other improperly customized Emacs package. |
4774 | |
4775 If you are reporting an error message received while executing one of the | |
4776 Viper commands, type: | |
4777 | |
4778 M-x set-variable <Return> debug-on-error <Return> t <Return> | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4779 |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4780 Then reproduce the error. The above command will cause Emacs to produce a |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4781 back trace of the execution that leads to the error. Please include this |
18129 | 4782 trace in your bug report. |
4783 | |
4784 If you believe that one of Viper's commands goes into an infinite loop | |
4785 \(e.g., Emacs freezes\), type: | |
4786 | |
4787 M-x set-variable <Return> debug-on-quit <Return> t <Return> | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4788 |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4789 Then reproduce the problem. Wait for a few seconds, then type C-g to abort |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4790 the current command. Include the resulting back trace in the bug report. |
18129 | 4791 |
4792 Mail anyway (y or n)? ") | |
4793 (if (y-or-n-p "Mail anyway? ") | |
4794 () | |
4795 (set-window-configuration window-config) | |
4796 (error "Bug report aborted"))) | |
4797 | |
4798 (require 'reporter) | |
4799 (set-window-configuration window-config) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4800 |
18129 | 4801 (reporter-submit-bug-report "kifer@cs.sunysb.edu" |
19078 | 4802 (viper-version) |
18129 | 4803 varlist |
4804 nil 'delete-other-windows | |
4805 salutation) | |
4806 )) | |
26429
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4807 |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4808 |
e20b16957cdd
* emulation/viper-init.el (viper-deflocalvar, viper-loop,
Sam Steingold <sds@gnu.org>
parents:
26263
diff
changeset
|
4809 |
18129 | 4810 ;; Smoothes out the difference between Emacs' unread-command-events |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4811 ;; and XEmacs unread-command-event. Arg is a character, an event, a list of |
18129 | 4812 ;; events or a sequence of keys. |
4813 ;; | |
4814 ;; Due to the way unread-command-events in Emacs (not XEmacs), a non-event | |
4815 ;; symbol in unread-command-events list may cause Emacs to turn this symbol | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4816 ;; into an event. Below, we delete nil from event lists, since nil is the most |
18129 | 4817 ;; common symbol that might appear in this wrong context. |
19078 | 4818 (defun viper-set-unread-command-events (arg) |
4819 (if viper-emacs-p | |
18129 | 4820 (setq |
4821 unread-command-events | |
4822 (let ((new-events | |
4823 (cond ((eventp arg) (list arg)) | |
4824 ((listp arg) arg) | |
4825 ((sequencep arg) | |
4826 (listify-key-sequence arg)) | |
4827 (t (error | |
19078 | 4828 "viper-set-unread-command-events: Invalid argument, %S" |
18129 | 4829 arg))))) |
4830 (if (not (eventp nil)) | |
4831 (setq new-events (delq nil new-events))) | |
4832 (append new-events unread-command-events))) | |
4833 ;; XEmacs | |
4834 (setq | |
4835 unread-command-events | |
4836 (append | |
19078 | 4837 (cond ((viper-characterp arg) (list (character-to-event arg))) |
18129 | 4838 ((eventp arg) (list arg)) |
4839 ((stringp arg) (mapcar 'character-to-event arg)) | |
4840 ((vectorp arg) (append arg nil)) ; turn into list | |
19078 | 4841 ((listp arg) (viper-eventify-list-xemacs arg)) |
18129 | 4842 (t (error |
19078 | 4843 "viper-set-unread-command-events: Invalid argument, %S" arg))) |
18129 | 4844 unread-command-events)))) |
4845 | |
4846 ;; list is assumed to be a list of events of characters | |
19078 | 4847 (defun viper-eventify-list-xemacs (lis) |
18129 | 4848 (mapcar |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4849 (lambda (elt) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4850 (cond ((viper-characterp elt) (character-to-event elt)) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4851 ((eventp elt) elt) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4852 (t (error |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4853 "viper-eventify-list-xemacs: can't convert to event, %S" |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
23313
diff
changeset
|
4854 elt)))) |
18129 | 4855 lis)) |
26588
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
4856 |
76b6a75471e1
* viper*el: replaced old-style backquotes.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26429
diff
changeset
|
4857 |
18129 | 4858 |
4859 ;;; viper-cmd.el ends here |