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