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