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