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