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