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