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