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