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