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