Mercurial > emacs
annotate lisp/emulation/vip.el @ 21677:f42b78e033db
(readevalloop): New arg UNIBYTE. Callers changed.
Use it to bind load_convert_to_unibyte.
(Feval_buffer): New arg UNIBYTE. Pass it to readevalloop.
(readevalloop_1): New unwind-protect subroutine.
(load_convert_to_unibyte): New variable.
(syms_of_lread): Set up Lisp var.
(read1): If load_convert_to_unibyte, convert strings to unibyte.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 20 Apr 1998 07:09:58 +0000 |
parents | 4a3e3887c0dc |
children | 6d7124c97b6b |
rev | line source |
---|---|
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
1 ;;; vip.el --- a VI Package for GNU Emacs |
11 | 2 |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
3 ;; Author: Masahiko Sato <ms@sail.stanford.edu> |
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
4 ;; Version: 3.5 |
812
485e82a8acb5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
773
diff
changeset
|
5 ;; Keywords: emulations |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
6 |
14169 | 7 ;; This file is part of GNU Emacs. |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
23 | |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
24 ;;; Commentary: |
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
25 |
2319
d98c49df2acd
Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1821
diff
changeset
|
26 ;; A full-featured vi(1) emulator. |
d98c49df2acd
Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1821
diff
changeset
|
27 ;; |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
28 ;; In Japan, the author's address is: masahiko@sato.riec.tohoku.junet |
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
29 ;; |
11 | 30 ;; Send suggestions and bug reports to one of the above addresses. |
31 ;; When you report a bug, be sure to include the version number of VIP and | |
32 ;; Emacs you are using. | |
33 | |
34 ;; Execute info command by typing "M-x info" to get information on VIP. | |
35 | |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
36 ;;; Code: |
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
37 |
21628 | 38 (defgroup vip nil |
39 "A VI Package for GNU Emacs." | |
40 :prefix "vip-" | |
41 :group 'emulations) | |
42 | |
11 | 43 ;; external variables |
44 | |
45 (defvar vip-emacs-local-map nil | |
16424
8ce8051df140
Doc fixes on most variables.
Richard M. Stallman <rms@gnu.org>
parents:
14431
diff
changeset
|
46 "Local map used in emacs mode. (Buffer-specific.)") |
11 | 47 |
48 (defvar vip-insert-local-map nil | |
16424
8ce8051df140
Doc fixes on most variables.
Richard M. Stallman <rms@gnu.org>
parents:
14431
diff
changeset
|
49 "Local map used in insert command mode. (Buffer-specific.)") |
11 | 50 |
51 (make-variable-buffer-local 'vip-emacs-local-map) | |
52 (make-variable-buffer-local 'vip-insert-local-map) | |
53 | |
54 (defvar vip-insert-point nil | |
16424
8ce8051df140
Doc fixes on most variables.
Richard M. Stallman <rms@gnu.org>
parents:
14431
diff
changeset
|
55 "Remember insert point as a marker. (Buffer-specific.)") |
11 | 56 |
57 (set-default 'vip-insert-point (make-marker)) | |
58 (make-variable-buffer-local 'vip-insert-point) | |
59 | |
60 (defvar vip-com-point nil | |
16424
8ce8051df140
Doc fixes on most variables.
Richard M. Stallman <rms@gnu.org>
parents:
14431
diff
changeset
|
61 "Remember com point as a marker. (Buffer-specific.)") |
11 | 62 |
63 (set-default 'vip-com-point (make-marker)) | |
64 (make-variable-buffer-local 'vip-com-point) | |
65 | |
66 (defvar vip-current-mode nil | |
16424
8ce8051df140
Doc fixes on most variables.
Richard M. Stallman <rms@gnu.org>
parents:
14431
diff
changeset
|
67 "Current mode. One of `emacs-mode', `vi-mode', `insert-mode'.") |
11 | 68 |
69 (make-variable-buffer-local 'vip-current-mode) | |
70 (setq-default vip-current-mode 'emacs-mode) | |
71 | |
72 (defvar vip-emacs-mode-line-buffer-identification nil | |
16424
8ce8051df140
Doc fixes on most variables.
Richard M. Stallman <rms@gnu.org>
parents:
14431
diff
changeset
|
73 "Value of mode-line-buffer-identification in Emacs mode within vip.") |
11 | 74 (make-variable-buffer-local 'vip-emacs-mode-line-buffer-identification) |
75 (setq-default vip-emacs-mode-line-buffer-identification | |
76 '("Emacs: %17b")) | |
77 | |
78 (defvar vip-current-major-mode nil | |
79 "vip-current-major-mode is the major-mode vi considers it is now. | |
80 \(buffer specific\)") | |
81 | |
82 (make-variable-buffer-local 'vip-current-major-mode) | |
83 | |
84 (defvar vip-last-shell-com nil | |
16424
8ce8051df140
Doc fixes on most variables.
Richard M. Stallman <rms@gnu.org>
parents:
14431
diff
changeset
|
85 "Last shell command executed by ! command.") |
11 | 86 |
87 (defvar vip-use-register nil | |
16424
8ce8051df140
Doc fixes on most variables.
Richard M. Stallman <rms@gnu.org>
parents:
14431
diff
changeset
|
88 "Name of register to store deleted or yanked strings.") |
11 | 89 |
90 (defvar vip-d-com nil | |
16424
8ce8051df140
Doc fixes on most variables.
Richard M. Stallman <rms@gnu.org>
parents:
14431
diff
changeset
|
91 "How to reexecute last destructive command. Value is list (M-COM VAL COM).") |
11 | 92 |
21628 | 93 (defcustom vip-shift-width 8 |
94 "*The number of columns shifted by > and < command." | |
95 :type 'integer | |
96 :group 'vip) | |
11 | 97 |
21628 | 98 (defcustom vip-re-replace nil |
99 "*If t then do regexp replace, if nil then do string replace." | |
100 :type 'boolean | |
101 :group 'vip) | |
11 | 102 |
103 (defvar vip-d-char nil | |
16424
8ce8051df140
Doc fixes on most variables.
Richard M. Stallman <rms@gnu.org>
parents:
14431
diff
changeset
|
104 "The character remembered by the vi \"r\" command.") |
11 | 105 |
106 (defvar vip-f-char nil | |
16424
8ce8051df140
Doc fixes on most variables.
Richard M. Stallman <rms@gnu.org>
parents:
14431
diff
changeset
|
107 "For use by \";\" command.") |
11 | 108 |
109 (defvar vip-F-char nil | |
16424
8ce8051df140
Doc fixes on most variables.
Richard M. Stallman <rms@gnu.org>
parents:
14431
diff
changeset
|
110 "For use by \".\" command.") |
11 | 111 |
112 (defvar vip-f-forward nil | |
16424
8ce8051df140
Doc fixes on most variables.
Richard M. Stallman <rms@gnu.org>
parents:
14431
diff
changeset
|
113 "For use by \";\" command.") |
11 | 114 |
115 (defvar vip-f-offset nil | |
16424
8ce8051df140
Doc fixes on most variables.
Richard M. Stallman <rms@gnu.org>
parents:
14431
diff
changeset
|
116 "For use by \";\" command.") |
11 | 117 |
21628 | 118 (defcustom vip-search-wrap-around t |
119 "*If t, search wraps around." | |
120 :type 'boolean | |
121 :group 'vip) | |
11 | 122 |
21628 | 123 (defcustom vip-re-search nil |
124 "*If t, search is reg-exp search, otherwise vanilla search." | |
125 :type 'boolean | |
126 :group 'vip) | |
11 | 127 |
128 (defvar vip-s-string nil | |
16424
8ce8051df140
Doc fixes on most variables.
Richard M. Stallman <rms@gnu.org>
parents:
14431
diff
changeset
|
129 "Last vip search string.") |
11 | 130 |
131 (defvar vip-s-forward nil | |
16424
8ce8051df140
Doc fixes on most variables.
Richard M. Stallman <rms@gnu.org>
parents:
14431
diff
changeset
|
132 "If t, search is forward.") |
11 | 133 |
21628 | 134 (defcustom vip-case-fold-search nil |
135 "*If t, search ignores cases." | |
136 :type 'boolean | |
137 :group 'vip) | |
11 | 138 |
21628 | 139 (defcustom vip-re-query-replace nil |
140 "*If t then do regexp replace, if nil then do string replace." | |
141 :type 'boolean | |
142 :group 'vip) | |
11 | 143 |
21628 | 144 (defcustom vip-open-with-indent nil |
145 "*If t, indent when open a new line." | |
146 :type 'boolean | |
147 :group 'vip) | |
11 | 148 |
21628 | 149 (defcustom vip-help-in-insert-mode nil |
16424
8ce8051df140
Doc fixes on most variables.
Richard M. Stallman <rms@gnu.org>
parents:
14431
diff
changeset
|
150 "*If t then C-h is bound to help-command in insert mode. |
21628 | 151 If nil then it is bound to `delete-backward-char'." |
152 :type 'boolean | |
153 :group 'vip) | |
11 | 154 |
155 (defvar vip-quote-string "> " | |
16424
8ce8051df140
Doc fixes on most variables.
Richard M. Stallman <rms@gnu.org>
parents:
14431
diff
changeset
|
156 "String inserted at the beginning of region.") |
11 | 157 |
158 (defvar vip-tags-file-name "TAGS") | |
159 | |
160 (defvar vip-inhibit-startup-message nil) | |
13907
c4f965637f22
(vip-startup-file): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12358
diff
changeset
|
161 |
c4f965637f22
(vip-startup-file): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12358
diff
changeset
|
162 (defvar vip-startup-file (convert-standard-filename "~/.vip") |
16424
8ce8051df140
Doc fixes on most variables.
Richard M. Stallman <rms@gnu.org>
parents:
14431
diff
changeset
|
163 "Filename used as startup file for vip.") |
11 | 164 |
18424
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
165 ;; key bindings |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
166 |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
167 (defvar vip-mode-map (make-keymap)) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
168 |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
169 (define-key vip-mode-map "\C-a" 'beginning-of-line) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
170 (define-key vip-mode-map "\C-b" 'vip-scroll-back) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
171 (define-key vip-mode-map "\C-c" 'vip-ctl-c) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
172 (define-key vip-mode-map "\C-d" 'vip-scroll-up) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
173 (define-key vip-mode-map "\C-e" 'vip-scroll-up-one) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
174 (define-key vip-mode-map "\C-f" 'vip-scroll) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
175 (define-key vip-mode-map "\C-g" 'vip-keyboard-quit) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
176 (define-key vip-mode-map "\C-h" 'help-command) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
177 (define-key vip-mode-map "\C-m" 'vip-scroll-back) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
178 (define-key vip-mode-map "\C-n" 'vip-other-window) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
179 (define-key vip-mode-map "\C-o" 'vip-open-line-at-point) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
180 (define-key vip-mode-map "\C-u" 'vip-scroll-down) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
181 (define-key vip-mode-map "\C-x" 'vip-ctl-x) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
182 (define-key vip-mode-map "\C-y" 'vip-scroll-down-one) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
183 (define-key vip-mode-map "\C-z" 'vip-change-mode-to-emacs) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
184 (define-key vip-mode-map "\e" 'vip-ESC) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
185 |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
186 (define-key vip-mode-map " " 'vip-scroll) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
187 (define-key vip-mode-map "!" 'vip-command-argument) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
188 (define-key vip-mode-map "\"" 'vip-command-argument) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
189 (define-key vip-mode-map "#" 'vip-command-argument) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
190 (define-key vip-mode-map "$" 'vip-goto-eol) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
191 (define-key vip-mode-map "%" 'vip-paren-match) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
192 (define-key vip-mode-map "&" 'vip-nil) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
193 (define-key vip-mode-map "'" 'vip-goto-mark-and-skip-white) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
194 (define-key vip-mode-map "(" 'vip-backward-sentence) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
195 (define-key vip-mode-map ")" 'vip-forward-sentence) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
196 (define-key vip-mode-map "*" 'call-last-kbd-macro) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
197 (define-key vip-mode-map "+" 'vip-next-line-at-bol) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
198 (define-key vip-mode-map "," 'vip-repeat-find-opposite) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
199 (define-key vip-mode-map "-" 'vip-previous-line-at-bol) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
200 (define-key vip-mode-map "." 'vip-repeat) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
201 (define-key vip-mode-map "/" 'vip-search-forward) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
202 |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
203 (define-key vip-mode-map "0" 'vip-beginning-of-line) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
204 (define-key vip-mode-map "1" 'vip-digit-argument) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
205 (define-key vip-mode-map "2" 'vip-digit-argument) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
206 (define-key vip-mode-map "3" 'vip-digit-argument) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
207 (define-key vip-mode-map "4" 'vip-digit-argument) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
208 (define-key vip-mode-map "5" 'vip-digit-argument) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
209 (define-key vip-mode-map "6" 'vip-digit-argument) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
210 (define-key vip-mode-map "7" 'vip-digit-argument) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
211 (define-key vip-mode-map "8" 'vip-digit-argument) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
212 (define-key vip-mode-map "9" 'vip-digit-argument) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
213 |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
214 (define-key vip-mode-map ":" 'vip-ex) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
215 (define-key vip-mode-map ";" 'vip-repeat-find) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
216 (define-key vip-mode-map "<" 'vip-command-argument) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
217 (define-key vip-mode-map "=" 'vip-command-argument) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
218 (define-key vip-mode-map ">" 'vip-command-argument) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
219 (define-key vip-mode-map "?" 'vip-search-backward) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
220 (define-key vip-mode-map "@" 'vip-nil) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
221 |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
222 (define-key vip-mode-map "A" 'vip-Append) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
223 (define-key vip-mode-map "B" 'vip-backward-Word) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
224 (define-key vip-mode-map "C" 'vip-ctl-c-equivalent) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
225 (define-key vip-mode-map "D" 'vip-kill-line) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
226 (define-key vip-mode-map "E" 'vip-end-of-Word) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
227 (define-key vip-mode-map "F" 'vip-find-char-backward) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
228 (define-key vip-mode-map "G" 'vip-goto-line) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
229 (define-key vip-mode-map "H" 'vip-window-top) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
230 (define-key vip-mode-map "I" 'vip-Insert) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
231 (define-key vip-mode-map "J" 'vip-join-lines) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
232 (define-key vip-mode-map "K" 'vip-kill-buffer) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
233 (define-key vip-mode-map "L" 'vip-window-bottom) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
234 (define-key vip-mode-map "M" 'vip-window-middle) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
235 (define-key vip-mode-map "N" 'vip-search-Next) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
236 (define-key vip-mode-map "O" 'vip-Open-line) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
237 (define-key vip-mode-map "P" 'vip-Put-back) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
238 (define-key vip-mode-map "Q" 'vip-query-replace) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
239 (define-key vip-mode-map "R" 'vip-replace-string) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
240 (define-key vip-mode-map "S" 'vip-switch-to-buffer-other-window) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
241 (define-key vip-mode-map "T" 'vip-goto-char-backward) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
242 (define-key vip-mode-map "U" 'vip-nil) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
243 (define-key vip-mode-map "V" 'vip-find-file-other-window) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
244 (define-key vip-mode-map "W" 'vip-forward-Word) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
245 (define-key vip-mode-map "X" 'vip-ctl-x-equivalent) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
246 (define-key vip-mode-map "Y" 'vip-yank-line) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
247 (define-key vip-mode-map "ZZ" 'save-buffers-kill-emacs) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
248 |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
249 (define-key vip-mode-map "[" 'vip-nil) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
250 (define-key vip-mode-map "\\" 'vip-escape-to-emacs) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
251 (define-key vip-mode-map "]" 'vip-nil) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
252 (define-key vip-mode-map "^" 'vip-bol-and-skip-white) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
253 (define-key vip-mode-map "_" 'vip-nil) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
254 (define-key vip-mode-map "`" 'vip-goto-mark) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
255 |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
256 (define-key vip-mode-map "a" 'vip-append) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
257 (define-key vip-mode-map "b" 'vip-backward-word) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
258 (define-key vip-mode-map "c" 'vip-command-argument) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
259 (define-key vip-mode-map "d" 'vip-command-argument) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
260 (define-key vip-mode-map "e" 'vip-end-of-word) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
261 (define-key vip-mode-map "f" 'vip-find-char-forward) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
262 (define-key vip-mode-map "g" 'vip-info-on-file) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
263 (define-key vip-mode-map "h" 'vip-backward-char) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
264 (define-key vip-mode-map "i" 'vip-insert) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
265 (define-key vip-mode-map "j" 'vip-next-line) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
266 (define-key vip-mode-map "k" 'vip-previous-line) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
267 (define-key vip-mode-map "l" 'vip-forward-char) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
268 (define-key vip-mode-map "m" 'vip-mark-point) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
269 (define-key vip-mode-map "n" 'vip-search-next) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
270 (define-key vip-mode-map "o" 'vip-open-line) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
271 (define-key vip-mode-map "p" 'vip-put-back) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
272 (define-key vip-mode-map "q" 'vip-nil) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
273 (define-key vip-mode-map "r" 'vip-replace-char) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
274 (define-key vip-mode-map "s" 'vip-switch-to-buffer) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
275 (define-key vip-mode-map "t" 'vip-goto-char-forward) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
276 (define-key vip-mode-map "u" 'vip-undo) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
277 (define-key vip-mode-map "v" 'vip-find-file) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
278 (define-key vip-mode-map "w" 'vip-forward-word) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
279 (define-key vip-mode-map "x" 'vip-delete-char) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
280 (define-key vip-mode-map "y" 'vip-command-argument) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
281 (define-key vip-mode-map "zH" 'vip-line-to-top) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
282 (define-key vip-mode-map "zM" 'vip-line-to-middle) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
283 (define-key vip-mode-map "zL" 'vip-line-to-bottom) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
284 (define-key vip-mode-map "z\C-m" 'vip-line-to-top) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
285 (define-key vip-mode-map "z." 'vip-line-to-middle) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
286 (define-key vip-mode-map "z-" 'vip-line-to-bottom) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
287 |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
288 (define-key vip-mode-map "{" 'vip-backward-paragraph) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
289 (define-key vip-mode-map "|" 'vip-goto-col) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
290 (define-key vip-mode-map "}" 'vip-forward-paragraph) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
291 (define-key vip-mode-map "~" 'vip-nil) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
292 (define-key vip-mode-map "\177" 'vip-delete-backward-char) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
293 |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
294 (define-key ctl-x-map "3" 'vip-buffer-in-two-windows) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
295 (define-key ctl-x-map "\C-i" 'insert-file) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
296 |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
297 (defun vip-version () |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
298 (interactive) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
299 (message "VIP version 3.5 of September 15, 1987")) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
300 |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
301 |
11 | 302 ;; basic set up |
303 | |
304 (global-set-key "\C-z" 'vip-change-mode-to-vi) | |
305 | |
306 (defmacro vip-loop (count body) | |
307 "(COUNT BODY) Execute BODY COUNT times." | |
308 (list 'let (list (list 'count count)) | |
309 (list 'while (list '> 'count 0) | |
310 body | |
311 (list 'setq 'count (list '1- 'count))))) | |
312 | |
313 (defun vip-push-mark-silent (&optional location) | |
314 "Set mark at LOCATION (point, by default) and push old mark on mark ring. | |
315 No message." | |
12358
fe8779b08103
(vip-push-mark-silent): Use (mark t).
Richard M. Stallman <rms@gnu.org>
parents:
11566
diff
changeset
|
316 (if (null (mark t)) |
11 | 317 nil |
318 (setq mark-ring (cons (copy-marker (mark-marker)) mark-ring)) | |
319 (if (> (length mark-ring) mark-ring-max) | |
320 (progn | |
321 (move-marker (car (nthcdr mark-ring-max mark-ring)) nil) | |
322 (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil)))) | |
323 (set-mark (or location (point)))) | |
324 | |
325 (defun vip-goto-col (arg) | |
326 "Go to ARG's column." | |
327 (interactive "P") | |
328 (let ((val (vip-p-val arg)) | |
329 (com (vip-getcom arg))) | |
330 (save-excursion | |
331 (end-of-line) | |
332 (if (> val (1+ (current-column))) (error ""))) | |
333 (if com (move-marker vip-com-point (point))) | |
334 (beginning-of-line) | |
335 (forward-char (1- val)) | |
336 (if com (vip-execute-com 'vip-goto-col val com)))) | |
337 | |
338 (defun vip-copy-keymap (map) | |
339 (if (null map) (make-sparse-keymap) (copy-keymap map))) | |
340 | |
341 | |
342 ;; changing mode | |
343 | |
344 (defun vip-change-mode (new-mode) | |
3519
093c4dc7e884
(vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents:
2319
diff
changeset
|
345 "Change mode to NEW-MODE---either emacs-mode, vi-mode, or insert-mode." |
11 | 346 (or (eq new-mode vip-current-mode) |
347 (progn | |
348 (cond ((eq new-mode 'vi-mode) | |
349 (if (eq vip-current-mode 'insert-mode) | |
350 (progn | |
351 (vip-copy-region-as-kill (point) vip-insert-point) | |
352 (vip-repeat-insert-command)) | |
353 (setq vip-emacs-local-map (current-local-map) | |
354 vip-emacs-mode-line-buffer-identification | |
355 mode-line-buffer-identification | |
356 vip-insert-local-map (vip-copy-keymap | |
357 (current-local-map)))) | |
358 (vip-change-mode-line "Vi: ") | |
359 (use-local-map vip-mode-map)) | |
360 ((eq new-mode 'insert-mode) | |
361 (move-marker vip-insert-point (point)) | |
362 (if (eq vip-current-mode 'emacs-mode) | |
363 (setq vip-emacs-local-map (current-local-map) | |
364 vip-emacs-mode-line-buffer-identification | |
365 mode-line-buffer-identification | |
366 vip-insert-local-map (vip-copy-keymap | |
367 (current-local-map))) | |
368 (setq vip-insert-local-map (vip-copy-keymap | |
369 vip-emacs-local-map))) | |
370 (vip-change-mode-line "Insert") | |
371 (use-local-map vip-insert-local-map) | |
372 (define-key vip-insert-local-map "\e" 'vip-change-mode-to-vi) | |
373 (define-key vip-insert-local-map "\C-z" 'vip-ESC) | |
374 (define-key vip-insert-local-map "\C-h" | |
375 (if vip-help-in-insert-mode 'help-command | |
376 'delete-backward-char)) | |
377 (define-key vip-insert-local-map "\C-w" | |
378 'vip-delete-backward-word)) | |
379 ((eq new-mode 'emacs-mode) | |
380 (vip-change-mode-line "Emacs:") | |
381 (use-local-map vip-emacs-local-map))) | |
382 (setq vip-current-mode new-mode) | |
11566
506881d20003
(vip-change-mode): Use force-mode-line-update.
Karl Heuer <kwzh@gnu.org>
parents:
7639
diff
changeset
|
383 (force-mode-line-update)))) |
11 | 384 |
385 (defun vip-copy-region-as-kill (beg end) | |
386 "If BEG and END do not belong to the same buffer, it copies empty region." | |
387 (condition-case nil | |
388 (copy-region-as-kill beg end) | |
389 (error (copy-region-as-kill beg beg)))) | |
390 | |
391 (defun vip-change-mode-line (string) | |
392 "Assuming that the mode line format contains the string \"Emacs:\", this | |
393 function replaces the string by \"Vi: \" etc." | |
394 (setq mode-line-buffer-identification | |
395 (if (string= string "Emacs:") | |
396 vip-emacs-mode-line-buffer-identification | |
397 (list (concat string " %17b"))))) | |
398 | |
258 | 399 ;;;###autoload |
11 | 400 (defun vip-mode () |
401 "Turn on VIP emulation of VI." | |
402 (interactive) | |
403 (if (not vip-inhibit-startup-message) | |
404 (progn | |
405 (switch-to-buffer "VIP Startup Message") | |
406 (erase-buffer) | |
407 (insert | |
408 "VIP is a Vi emulation package for GNU Emacs. VIP provides most Vi commands | |
409 including Ex commands. VIP is however different from Vi in several points. | |
410 You can get more information on VIP by: | |
411 1. Typing `M-x info' and selecting menu item \"vip\". | |
412 2. Typing `C-h k' followed by a key whose description you want. | |
413 3. Printing VIP manual which can be found as GNU/man/vip.texinfo | |
414 4. Printing VIP Reference Card which can be found as GNU/etc/vipcard.tex | |
415 | |
416 This startup message appears whenever you load VIP unless you type `y' now. | |
417 Type `n' to quit this window for now.\n") | |
418 (goto-char (point-min)) | |
419 (if (y-or-n-p "Inhibit VIP startup message? ") | |
420 (progn | |
421 (save-excursion | |
422 (set-buffer | |
13907
c4f965637f22
(vip-startup-file): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12358
diff
changeset
|
423 (find-file-noselect |
c4f965637f22
(vip-startup-file): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12358
diff
changeset
|
424 (substitute-in-file-name vip-startup-file))) |
11 | 425 (goto-char (point-max)) |
426 (insert "\n(setq vip-inhibit-startup-message t)\n") | |
427 (save-buffer) | |
428 (kill-buffer (current-buffer))) | |
429 (message "VIP startup message inhibited.") | |
430 (sit-for 2))) | |
431 (kill-buffer (current-buffer)) | |
432 (message "") | |
433 (setq vip-inhibit-startup-message t))) | |
434 (vip-change-mode-to-vi)) | |
435 | |
436 (defun vip-change-mode-to-vi () | |
437 "Change mode to vi mode." | |
438 (interactive) | |
439 (vip-change-mode 'vi-mode)) | |
440 | |
441 (defun vip-change-mode-to-insert () | |
442 "Change mode to insert mode." | |
443 (interactive) | |
444 (vip-change-mode 'insert-mode)) | |
445 | |
446 (defun vip-change-mode-to-emacs () | |
447 "Change mode to emacs mode." | |
448 (interactive) | |
449 (vip-change-mode 'emacs-mode)) | |
450 | |
451 | |
2319
d98c49df2acd
Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1821
diff
changeset
|
452 ;; escape to emacs mode temporarily |
11 | 453 |
3519
093c4dc7e884
(vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents:
2319
diff
changeset
|
454 (defun vip-escape-to-emacs (arg &optional events) |
093c4dc7e884
(vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents:
2319
diff
changeset
|
455 "Escape to Emacs mode for one Emacs command. |
093c4dc7e884
(vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents:
2319
diff
changeset
|
456 ARG is used as the prefix value for the executed command. If |
093c4dc7e884
(vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents:
2319
diff
changeset
|
457 EVENTS is a list of events, which become the beginning of the command." |
11 | 458 (interactive "P") |
3519
093c4dc7e884
(vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents:
2319
diff
changeset
|
459 (let (com key (old-map (current-local-map))) |
093c4dc7e884
(vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents:
2319
diff
changeset
|
460 (if events (setq unread-command-events events)) |
11 | 461 (setq prefix-arg arg) |
3519
093c4dc7e884
(vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents:
2319
diff
changeset
|
462 (use-local-map vip-emacs-local-map) |
093c4dc7e884
(vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents:
2319
diff
changeset
|
463 (unwind-protect |
093c4dc7e884
(vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents:
2319
diff
changeset
|
464 (setq com (key-binding (setq key (read-key-sequence nil)))) |
093c4dc7e884
(vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents:
2319
diff
changeset
|
465 (use-local-map old-map)) |
093c4dc7e884
(vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents:
2319
diff
changeset
|
466 (command-execute com prefix-arg) |
11 | 467 (setq prefix-arg nil) ;; reset prefix arg |
468 )) | |
469 | |
470 (defun vip-message-conditions (conditions) | |
471 "Print CONDITIONS as a message." | |
472 (let ((case (car conditions)) (msg (cdr conditions))) | |
473 (if (null msg) | |
474 (message "%s" case) | |
475 (message "%s %s" case (prin1-to-string msg))) | |
476 (ding))) | |
477 | |
478 (defun vip-ESC (arg) | |
479 "Emulate ESC key in Emacs mode." | |
480 (interactive "P") | |
3519
093c4dc7e884
(vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents:
2319
diff
changeset
|
481 (vip-escape-to-emacs arg '(?\e))) |
11 | 482 |
483 (defun vip-ctl-c (arg) | |
484 "Emulate C-c key in Emacs mode." | |
485 (interactive "P") | |
3519
093c4dc7e884
(vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents:
2319
diff
changeset
|
486 (vip-escape-to-emacs arg '(?\C-c))) |
11 | 487 |
488 (defun vip-ctl-x (arg) | |
489 "Emulate C-x key in Emacs mode." | |
490 (interactive "P") | |
3519
093c4dc7e884
(vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents:
2319
diff
changeset
|
491 (vip-escape-to-emacs arg '(?\C-x))) |
11 | 492 |
493 (defun vip-ctl-h (arg) | |
494 "Emulate C-h key in Emacs mode." | |
495 (interactive "P") | |
3519
093c4dc7e884
(vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents:
2319
diff
changeset
|
496 (vip-escape-to-emacs arg '(?\C-h))) |
11 | 497 |
498 | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3519
diff
changeset
|
499 ;; prefix argument for vi mode |
11 | 500 |
501 ;; In vi mode, prefix argument is a dotted pair (NUM . COM) where NUM | |
502 ;; represents the numeric value of the prefix argument and COM represents | |
503 ;; command prefix such as "c", "d", "m" and "y". | |
504 | |
505 (defun vip-prefix-arg-value (char value com) | |
506 "Compute numeric prefix arg value. Invoked by CHAR. VALUE is the value | |
507 obtained so far, and COM is the command part obtained so far." | |
508 (while (and (>= char ?0) (<= char ?9)) | |
509 (setq value (+ (* (if (numberp value) value 0) 10) (- char ?0))) | |
510 (setq char (read-char))) | |
511 (setq prefix-arg value) | |
512 (if com (setq prefix-arg (cons prefix-arg com))) | |
513 (while (= char ?U) | |
514 (vip-describe-arg prefix-arg) | |
515 (setq char (read-char))) | |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1625
diff
changeset
|
516 (setq unread-command-events (list char))) |
11 | 517 |
518 (defun vip-prefix-arg-com (char value com) | |
519 "Vi operator as prefix argument." | |
520 (let ((cont t)) | |
521 (while (and cont | |
522 (or (= char ?c) (= char ?d) (= char ?y) | |
523 (= char ?!) (= char ?<) (= char ?>) (= char ?=) | |
524 (= char ?#) (= char ?r) (= char ?R) (= char ?\"))) | |
525 (if com | |
526 ;; this means that we already have a command character, so we | |
527 ;; construct a com list and exit while. however, if char is " | |
528 ;; it is an error. | |
529 (progn | |
530 ;; new com is (CHAR . OLDCOM) | |
531 (if (or (= char ?#) (= char ?\")) (error "")) | |
532 (setq com (cons char com)) | |
533 (setq cont nil)) | |
534 ;; if com is nil we set com as char, and read more. again, if char | |
535 ;; is ", we read the name of register and store it in vip-use-register. | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3519
diff
changeset
|
536 ;; if char is !, =, or #, a complete com is formed so we exit while. |
11 | 537 (cond ((or (= char ?!) (= char ?=)) |
538 (setq com char) | |
539 (setq char (read-char)) | |
540 (setq cont nil)) | |
541 ((= char ?#) | |
542 ;; read a char and encode it as com | |
543 (setq com (+ 128 (read-char))) | |
544 (setq char (read-char)) | |
545 (setq cont nil)) | |
546 ((or (= char ?<) (= char ?>)) | |
547 (setq com char) | |
548 (setq char (read-char)) | |
549 (if (= com char) (setq com (cons char com))) | |
550 (setq cont nil)) | |
551 ((= char ?\") | |
552 (let ((reg (read-char))) | |
553 (if (or (and (<= ?A reg) (<= reg ?z)) | |
554 (and (<= ?1 reg) (<= reg ?9))) | |
555 (setq vip-use-register reg) | |
556 (error "")) | |
557 (setq char (read-char)))) | |
558 (t | |
559 (setq com char) | |
560 (setq char (read-char))))))) | |
561 (if (atom com) | |
562 ;; com is a single char, so we construct prefix-arg | |
563 ;; and if char is ?, describe prefix arg, otherwise exit by | |
564 ;; pushing the char back | |
565 (progn | |
566 (setq prefix-arg (cons value com)) | |
567 (while (= char ?U) | |
568 (vip-describe-arg prefix-arg) | |
569 (setq char (read-char))) | |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1625
diff
changeset
|
570 (setq unread-command-events (list char))) |
11 | 571 ;; as com is non-nil, this means that we have a command to execute |
572 (if (or (= (car com) ?r) (= (car com) ?R)) | |
14013 | 573 ;; execute appropriate region command. |
11 | 574 (let ((char (car com)) (com (cdr com))) |
575 (setq prefix-arg (cons value com)) | |
576 (if (= char ?r) (vip-region prefix-arg) | |
577 (vip-Region prefix-arg)) | |
578 ;; reset prefix-arg | |
579 (setq prefix-arg nil)) | |
580 ;; otherwise, reset prefix arg and call appropriate command | |
581 (setq value (if (null value) 1 value)) | |
582 (setq prefix-arg nil) | |
583 (cond ((equal com '(?c . ?c)) (vip-line (cons value ?C))) | |
584 ((equal com '(?d . ?d)) (vip-line (cons value ?D))) | |
585 ((equal com '(?d . ?y)) (vip-yank-defun)) | |
586 ((equal com '(?y . ?y)) (vip-line (cons value ?Y))) | |
587 ((equal com '(?< . ?<)) (vip-line (cons value ?<))) | |
588 ((equal com '(?> . ?>)) (vip-line (cons value ?>))) | |
589 ((equal com '(?! . ?!)) (vip-line (cons value ?!))) | |
590 ((equal com '(?= . ?=)) (vip-line (cons value ?=))) | |
591 (t (error "")))))) | |
592 | |
593 (defun vip-describe-arg (arg) | |
594 (let (val com) | |
595 (setq val (vip-P-val arg) | |
596 com (vip-getcom arg)) | |
597 (if (null val) | |
598 (if (null com) | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3519
diff
changeset
|
599 (message "Value is nil, and command is nil.") |
11 | 600 (message "Value is nil, and command is %c." com)) |
601 (if (null com) | |
602 (message "Value is %d, and command is nil." val) | |
603 (message "Value is %d, and command is %c." val com))))) | |
604 | |
605 (defun vip-digit-argument (arg) | |
606 "Begin numeric argument for the next command." | |
607 (interactive "P") | |
608 (vip-prefix-arg-value last-command-char nil | |
609 (if (consp arg) (cdr arg) nil))) | |
610 | |
611 (defun vip-command-argument (arg) | |
612 "Accept a motion command as an argument." | |
613 (interactive "P") | |
614 (condition-case conditions | |
615 (vip-prefix-arg-com | |
616 last-command-char | |
617 (cond ((null arg) nil) | |
618 ((consp arg) (car arg)) | |
619 ((numberp arg) arg) | |
620 (t (error "strange arg"))) | |
621 (cond ((null arg) nil) | |
622 ((consp arg) (cdr arg)) | |
623 ((numberp arg) nil) | |
624 (t (error "strange arg")))) | |
625 (quit | |
626 (setq vip-use-register nil) | |
627 (signal 'quit nil)))) | |
628 | |
629 (defun vip-p-val (arg) | |
630 "Get value part of prefix-argument ARG." | |
631 (cond ((null arg) 1) | |
632 ((consp arg) (if (null (car arg)) 1 (car arg))) | |
633 (t arg))) | |
634 | |
635 (defun vip-P-val (arg) | |
636 "Get value part of prefix-argument ARG." | |
637 (cond ((consp arg) (car arg)) | |
638 (t arg))) | |
639 | |
640 (defun vip-getcom (arg) | |
641 "Get com part of prefix-argument ARG." | |
642 (cond ((null arg) nil) | |
643 ((consp arg) (cdr arg)) | |
644 (t nil))) | |
645 | |
646 (defun vip-getCom (arg) | |
647 "Get com part of prefix-argument ARG and modify it." | |
648 (let ((com (vip-getcom arg))) | |
649 (cond ((equal com ?c) ?C) | |
650 ((equal com ?d) ?D) | |
651 ((equal com ?y) ?Y) | |
652 (t com)))) | |
653 | |
654 | |
655 ;; repeat last destructive command | |
656 | |
657 (defun vip-append-to-register (reg start end) | |
658 "Append region to text in register REG. | |
659 START and END are buffer positions indicating what to append." | |
660 (set-register reg (concat (or (get-register reg) "") | |
661 (buffer-substring start end)))) | |
662 | |
663 (defun vip-execute-com (m-com val com) | |
664 "(M-COM VAL COM) Execute command COM. The list (M-COM VAL COM) is set | |
665 to vip-d-com for later use by vip-repeat" | |
666 (let ((reg vip-use-register)) | |
667 (if com | |
668 (cond ((= com ?c) (vip-change vip-com-point (point))) | |
669 ((= com (- ?c)) (vip-change-subr vip-com-point (point))) | |
670 ((or (= com ?C) (= com (- ?C))) | |
671 (save-excursion | |
672 (set-mark vip-com-point) | |
673 (vip-enlarge-region (mark) (point)) | |
674 (if vip-use-register | |
675 (progn | |
676 (cond ((and (<= ?a vip-use-register) | |
677 (<= vip-use-register ?z)) | |
678 (copy-to-register | |
679 vip-use-register (mark) (point) nil)) | |
680 ((and (<= ?A vip-use-register) | |
681 (<= vip-use-register ?Z)) | |
682 (vip-append-to-register | |
683 (+ vip-use-register 32) (mark) (point))) | |
684 (t (setq vip-use-register nil) | |
685 (error ""))) | |
686 (setq vip-use-register nil))) | |
687 (delete-region (mark) (point))) | |
688 (open-line 1) | |
689 (if (= com ?C) (vip-change-mode-to-insert) (yank))) | |
690 ((= com ?d) | |
691 (if vip-use-register | |
692 (progn | |
693 (cond ((and (<= ?a vip-use-register) | |
694 (<= vip-use-register ?z)) | |
695 (copy-to-register | |
696 vip-use-register vip-com-point (point) nil)) | |
697 ((and (<= ?A vip-use-register) | |
698 (<= vip-use-register ?Z)) | |
699 (vip-append-to-register | |
700 (+ vip-use-register 32) vip-com-point (point))) | |
701 (t (setq vip-use-register nil) | |
702 (error ""))) | |
703 (setq vip-use-register nil))) | |
704 (setq last-command | |
705 (if (eq last-command 'd-command) 'kill-region nil)) | |
706 (kill-region vip-com-point (point)) | |
707 (setq this-command 'd-command)) | |
708 ((= com ?D) | |
709 (save-excursion | |
710 (set-mark vip-com-point) | |
711 (vip-enlarge-region (mark) (point)) | |
712 (if vip-use-register | |
713 (progn | |
714 (cond ((and (<= ?a vip-use-register) | |
715 (<= vip-use-register ?z)) | |
716 (copy-to-register | |
717 vip-use-register (mark) (point) nil)) | |
718 ((and (<= ?A vip-use-register) | |
719 (<= vip-use-register ?Z)) | |
720 (vip-append-to-register | |
721 (+ vip-use-register 32) (mark) (point))) | |
722 (t (setq vip-use-register nil) | |
723 (error ""))) | |
724 (setq vip-use-register nil))) | |
725 (setq last-command | |
726 (if (eq last-command 'D-command) 'kill-region nil)) | |
727 (kill-region (mark) (point)) | |
728 (if (eq m-com 'vip-line) (setq this-command 'D-command))) | |
729 (back-to-indentation)) | |
730 ((= com ?y) | |
731 (if vip-use-register | |
732 (progn | |
733 (cond ((and (<= ?a vip-use-register) | |
734 (<= vip-use-register ?z)) | |
735 (copy-to-register | |
736 vip-use-register vip-com-point (point) nil)) | |
737 ((and (<= ?A vip-use-register) | |
738 (<= vip-use-register ?Z)) | |
739 (vip-append-to-register | |
740 (+ vip-use-register 32) vip-com-point (point))) | |
741 (t (setq vip-use-register nil) | |
742 (error ""))) | |
743 (setq vip-use-register nil))) | |
744 (setq last-command nil) | |
745 (copy-region-as-kill vip-com-point (point)) | |
746 (goto-char vip-com-point)) | |
747 ((= com ?Y) | |
748 (save-excursion | |
749 (set-mark vip-com-point) | |
750 (vip-enlarge-region (mark) (point)) | |
751 (if vip-use-register | |
752 (progn | |
753 (cond ((and (<= ?a vip-use-register) | |
754 (<= vip-use-register ?z)) | |
755 (copy-to-register | |
756 vip-use-register (mark) (point) nil)) | |
757 ((and (<= ?A vip-use-register) | |
758 (<= vip-use-register ?Z)) | |
759 (vip-append-to-register | |
760 (+ vip-use-register 32) (mark) (point))) | |
761 (t (setq vip-use-register nil) | |
762 (error ""))) | |
763 (setq vip-use-register nil))) | |
764 (setq last-command nil) | |
765 (copy-region-as-kill (mark) (point))) | |
766 (goto-char vip-com-point)) | |
767 ((or (= com ?!) (= com (- ?!))) | |
768 (save-excursion | |
769 (set-mark vip-com-point) | |
770 (vip-enlarge-region (mark) (point)) | |
771 (shell-command-on-region | |
772 (mark) (point) | |
773 (if (= com ?!) | |
774 (setq vip-last-shell-com (vip-read-string "!")) | |
775 vip-last-shell-com) | |
776 t))) | |
777 ((= com ?=) | |
778 (save-excursion | |
779 (set-mark vip-com-point) | |
780 (vip-enlarge-region (mark) (point)) | |
781 (if (> (mark) (point)) (exchange-point-and-mark)) | |
782 (indent-region (mark) (point) nil))) | |
783 ((= com ?<) | |
784 (save-excursion | |
785 (set-mark vip-com-point) | |
786 (vip-enlarge-region (mark) (point)) | |
787 (indent-rigidly (mark) (point) (- vip-shift-width))) | |
788 (goto-char vip-com-point)) | |
789 ((= com ?>) | |
790 (save-excursion | |
791 (set-mark vip-com-point) | |
792 (vip-enlarge-region (mark) (point)) | |
793 (indent-rigidly (mark) (point) vip-shift-width)) | |
794 (goto-char vip-com-point)) | |
795 ((>= com 128) | |
796 ;; this is special command # | |
797 (vip-special-prefix-com (- com 128))))) | |
798 (setq vip-d-com (list m-com val (if (or (= com ?c) (= com ?C) (= com ?!)) | |
799 (- com) com) | |
800 reg)))) | |
801 | |
802 (defun vip-repeat (arg) | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3519
diff
changeset
|
803 "(ARG) Re-execute last destructive command. vip-d-com has the form |
7639 | 804 \(COM ARG CH REG), where COM is the command to be re-executed, ARG is the |
11 | 805 argument for COM, CH is a flag for repeat, and REG is optional and if exists |
806 is the name of the register for COM." | |
807 (interactive "P") | |
808 (if (eq last-command 'vip-undo) | |
809 ;; if the last command was vip-undo, then undo-more | |
810 (vip-undo-more) | |
811 ;; otherwise execute the command stored in vip-d-com. if arg is non-nil | |
812 ;; its prefix value is used as new prefix value for the command. | |
813 (let ((m-com (car vip-d-com)) | |
814 (val (vip-P-val arg)) | |
815 (com (car (cdr (cdr vip-d-com)))) | |
816 (reg (nth 3 vip-d-com))) | |
817 (if (null val) (setq val (car (cdr vip-d-com)))) | |
818 (if (null m-com) (error "No previous command to repeat.")) | |
819 (setq vip-use-register reg) | |
820 (funcall m-com (cons val com))))) | |
821 | |
822 (defun vip-special-prefix-com (char) | |
823 "This command is invoked interactively by the key sequence #<char>" | |
824 (cond ((= char ?c) | |
825 (downcase-region (min vip-com-point (point)) | |
826 (max vip-com-point (point)))) | |
827 ((= char ?C) | |
828 (upcase-region (min vip-com-point (point)) | |
829 (max vip-com-point (point)))) | |
830 ((= char ?g) | |
831 (set-mark vip-com-point) | |
832 (vip-global-execute)) | |
833 ((= char ?q) | |
834 (set-mark vip-com-point) | |
835 (vip-quote-region)) | |
836 ((= char ?s) (spell-region vip-com-point (point))))) | |
837 | |
838 | |
839 ;; undoing | |
840 | |
841 (defun vip-undo () | |
842 "Undo previous change." | |
843 (interactive) | |
844 (message "undo!") | |
845 (undo-start) | |
846 (undo-more 2) | |
847 (setq this-command 'vip-undo)) | |
848 | |
849 (defun vip-undo-more () | |
850 "Continue undoing previous changes." | |
851 (message "undo more!") | |
852 (undo-more 1) | |
853 (setq this-command 'vip-undo)) | |
854 | |
855 | |
856 ;; utilities | |
857 | |
858 (defun vip-string-tail (str) | |
859 (if (or (null str) (string= str "")) nil | |
860 (substring str 1))) | |
861 | |
862 (defun vip-yank-defun () | |
863 (mark-defun) | |
864 (copy-region-as-kill (point) (mark))) | |
865 | |
866 (defun vip-enlarge-region (beg end) | |
867 "Enlarge region between BEG and END." | |
868 (if (< beg end) | |
869 (progn (goto-char beg) (set-mark end)) | |
870 (goto-char end) | |
871 (set-mark beg)) | |
872 (beginning-of-line) | |
873 (exchange-point-and-mark) | |
874 (if (or (not (eobp)) (not (bolp))) (next-line 1)) | |
875 (beginning-of-line) | |
876 (if (> beg end) (exchange-point-and-mark))) | |
877 | |
878 (defun vip-global-execute () | |
879 "Call last keyboad macro for each line in the region." | |
880 (if (> (point) (mark)) (exchange-point-and-mark)) | |
881 (beginning-of-line) | |
882 (call-last-kbd-macro) | |
883 (while (< (point) (mark)) | |
884 (forward-line 1) | |
885 (beginning-of-line) | |
886 (call-last-kbd-macro))) | |
887 | |
888 (defun vip-quote-region () | |
889 "Quote region by inserting the user supplied string at the beginning of | |
890 each line in the region." | |
891 (setq vip-quote-string | |
892 (let ((str | |
893 (vip-read-string (format "quote string \(default \"%s\"\): " | |
894 vip-quote-string)))) | |
895 (if (string= str "") vip-quote-string str))) | |
896 (vip-enlarge-region (point) (mark)) | |
897 (if (> (point) (mark)) (exchange-point-and-mark)) | |
898 (insert vip-quote-string) | |
899 (beginning-of-line) | |
900 (forward-line 1) | |
901 (while (and (< (point) (mark)) (bolp)) | |
902 (insert vip-quote-string) | |
903 (beginning-of-line) | |
904 (forward-line 1))) | |
905 | |
906 (defun vip-end-with-a-newline-p (string) | |
907 "Check if the string ends with a newline." | |
18424
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
908 (or (string= string "") |
11 | 909 (= (aref string (1- (length string))) ?\n))) |
910 | |
18424
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
911 (defvar vip-save-minibuffer-local-map) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
912 |
11 | 913 (defun vip-read-string (prompt &optional init) |
18424
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
914 (setq vip-save-minibuffer-local-map (copy-keymap minibuffer-local-map)) |
11 | 915 (define-key minibuffer-local-map "\C-h" 'backward-char) |
916 (define-key minibuffer-local-map "\C-w" 'backward-word) | |
917 (define-key minibuffer-local-map "\e" 'exit-minibuffer) | |
918 (let (str) | |
919 (condition-case conditions | |
920 (setq str (read-string prompt init)) | |
921 (quit | |
18424
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
922 (setq minibuffer-local-map vip-save-minibuffer-local-map) |
11 | 923 (signal 'quit nil))) |
18424
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
924 (setq minibuffer-local-map vip-save-minibuffer-local-map) |
11 | 925 str)) |
926 | |
927 | |
928 ;; insertion commands | |
929 | |
930 (defun vip-repeat-insert-command () | |
931 "This function is called when mode changes from insertion mode to | |
932 vi command mode. It will repeat the insertion command if original insertion | |
933 command was invoked with argument > 1." | |
934 (let ((i-com (car vip-d-com)) (val (car (cdr vip-d-com)))) | |
935 (if (and val (> val 1)) ;; first check that val is non-nil | |
936 (progn | |
937 (setq vip-d-com (list i-com (1- val) ?r)) | |
938 (vip-repeat nil) | |
939 (setq vip-d-com (list i-com val ?r)))))) | |
940 | |
941 (defun vip-insert (arg) "" | |
942 (interactive "P") | |
943 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
944 (setq vip-d-com (list 'vip-insert val ?r)) | |
945 (if com (vip-loop val (yank)) | |
946 (vip-change-mode-to-insert)))) | |
947 | |
948 (defun vip-append (arg) | |
949 "Append after point." | |
950 (interactive "P") | |
951 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
952 (setq vip-d-com (list 'vip-append val ?r)) | |
953 (if (not (eolp)) (forward-char)) | |
954 (if (equal com ?r) | |
955 (vip-loop val (yank)) | |
956 (vip-change-mode-to-insert)))) | |
957 | |
958 (defun vip-Append (arg) | |
959 "Append at end of line." | |
960 (interactive "P") | |
961 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
962 (setq vip-d-com (list 'vip-Append val ?r)) | |
963 (end-of-line) | |
964 (if (equal com ?r) | |
965 (vip-loop val (yank)) | |
966 (vip-change-mode-to-insert)))) | |
967 | |
968 (defun vip-Insert (arg) | |
969 "Insert before first non-white." | |
970 (interactive "P") | |
971 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
972 (setq vip-d-com (list 'vip-Insert val ?r)) | |
973 (back-to-indentation) | |
974 (if (equal com ?r) | |
975 (vip-loop val (yank)) | |
976 (vip-change-mode-to-insert)))) | |
977 | |
978 (defun vip-open-line (arg) | |
979 "Open line below." | |
980 (interactive "P") | |
981 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
982 (setq vip-d-com (list 'vip-open-line val ?r)) | |
983 (let ((col (current-indentation))) | |
984 (if (equal com ?r) | |
985 (vip-loop val | |
986 (progn | |
987 (end-of-line) | |
988 (newline 1) | |
989 (if vip-open-with-indent (indent-to col)) | |
990 (yank))) | |
991 (end-of-line) | |
992 (newline 1) | |
993 (if vip-open-with-indent (indent-to col)) | |
994 (vip-change-mode-to-insert))))) | |
995 | |
996 (defun vip-Open-line (arg) | |
997 "Open line above." | |
998 (interactive "P") | |
999 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
1000 (setq vip-d-com (list 'vip-Open-line val ?r)) | |
1001 (let ((col (current-indentation))) | |
1002 (if (equal com ?r) | |
1003 (vip-loop val | |
1004 (progn | |
1005 (beginning-of-line) | |
1006 (open-line 1) | |
1007 (if vip-open-with-indent (indent-to col)) | |
1008 (yank))) | |
1009 (beginning-of-line) | |
1010 (open-line 1) | |
1011 (if vip-open-with-indent (indent-to col)) | |
1012 (vip-change-mode-to-insert))))) | |
1013 | |
1014 (defun vip-open-line-at-point (arg) | |
1015 "Open line at point." | |
1016 (interactive "P") | |
1017 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
1018 (setq vip-d-com (list 'vip-open-line-at-point val ?r)) | |
1019 (if (equal com ?r) | |
1020 (vip-loop val | |
1021 (progn | |
1022 (open-line 1) | |
1023 (yank))) | |
1024 (open-line 1) | |
1025 (vip-change-mode-to-insert)))) | |
1026 | |
1027 (defun vip-substitute (arg) | |
1028 "Substitute characters." | |
1029 (interactive "P") | |
1030 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
1031 (save-excursion | |
1032 (set-mark (point)) | |
1033 (forward-char val) | |
1034 (if (equal com ?r) | |
1035 (vip-change-subr (mark) (point)) | |
1036 (vip-change (mark) (point)))) | |
1037 (setq vip-d-com (list 'vip-substitute val ?r)))) | |
1038 | |
1039 (defun vip-substitute-line (arg) | |
1040 "Substitute lines." | |
1041 (interactive "p") | |
1042 (vip-line (cons arg ?C))) | |
1043 | |
1044 | |
1045 ;; line command | |
1046 | |
1047 (defun vip-line (arg) | |
1048 (let ((val (car arg)) (com (cdr arg))) | |
1049 (move-marker vip-com-point (point)) | |
1050 (next-line (1- val)) | |
1051 (vip-execute-com 'vip-line val com))) | |
1052 | |
1053 (defun vip-yank-line (arg) | |
1054 "Yank ARG lines (in vi's sense)" | |
1055 (interactive "P") | |
1056 (let ((val (vip-p-val arg))) | |
1057 (vip-line (cons val ?Y)))) | |
1058 | |
1059 | |
1060 ;; region command | |
1061 | |
1062 (defun vip-region (arg) | |
1063 (interactive "P") | |
1064 (let ((val (vip-P-val arg)) | |
1065 (com (vip-getcom arg))) | |
1066 (move-marker vip-com-point (point)) | |
1067 (exchange-point-and-mark) | |
1068 (vip-execute-com 'vip-region val com))) | |
1069 | |
1070 (defun vip-Region (arg) | |
1071 (interactive "P") | |
1072 (let ((val (vip-P-val arg)) | |
1073 (com (vip-getCom arg))) | |
1074 (move-marker vip-com-point (point)) | |
1075 (exchange-point-and-mark) | |
1076 (vip-execute-com 'vip-Region val com))) | |
1077 | |
1078 (defun vip-replace-char (arg) | |
1079 "Replace the following ARG chars by the character read." | |
1080 (interactive "P") | |
1081 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
1082 (setq vip-d-com (list 'vip-replace-char val ?r)) | |
1083 (vip-replace-char-subr (if (equal com ?r) vip-d-char (read-char)) val))) | |
1084 | |
1085 (defun vip-replace-char-subr (char arg) | |
1086 (delete-char arg t) | |
1087 (setq vip-d-char char) | |
1088 (vip-loop (if (> arg 0) arg (- arg)) (insert char)) | |
1089 (backward-char arg)) | |
1090 | |
1091 (defun vip-replace-string () | |
1092 "Replace string. If you supply null string as the string to be replaced, | |
1093 the query replace mode will toggle between string replace and regexp replace." | |
1094 (interactive) | |
1095 (let (str) | |
1096 (setq str (vip-read-string | |
1097 (if vip-re-replace "Replace regexp: " "Replace string: "))) | |
1098 (if (string= str "") | |
1099 (progn | |
1100 (setq vip-re-replace (not vip-re-replace)) | |
14345
e37ae69fce10
(vip-replace-string, vip-search-forward, vip-search-backward): Delete format call inside message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
1101 (message "Replace mode changed to %s." |
e37ae69fce10
(vip-replace-string, vip-search-forward, vip-search-backward): Delete format call inside message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
1102 (if vip-re-replace "regexp replace" |
e37ae69fce10
(vip-replace-string, vip-search-forward, vip-search-backward): Delete format call inside message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
1103 "string replace"))) |
11 | 1104 (if vip-re-replace |
5308
f14639c69ed3
(vip-replace-string): Don't use replace-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
1105 ;; (replace-regexp |
f14639c69ed3
(vip-replace-string): Don't use replace-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
1106 ;; str |
f14639c69ed3
(vip-replace-string): Don't use replace-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
1107 ;; (vip-read-string (format "Replace regexp \"%s\" with: " str))) |
f14639c69ed3
(vip-replace-string): Don't use replace-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
1108 (while (re-search-forward str nil t) |
f14639c69ed3
(vip-replace-string): Don't use replace-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
1109 (replace-match (vip-read-string |
f14639c69ed3
(vip-replace-string): Don't use replace-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
1110 (format "Replace regexp \"%s\" with: " str)) |
f14639c69ed3
(vip-replace-string): Don't use replace-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
1111 nil nil)) |
11 | 1112 (replace-string |
1113 str | |
1114 (vip-read-string (format "Replace \"%s\" with: " str))))))) | |
1115 | |
1116 | |
1117 ;; basic cursor movement. j, k, l, m commands. | |
1118 | |
1119 (defun vip-forward-char (arg) | |
1120 "Move point right ARG characters (left if ARG negative).On reaching end | |
1121 of buffer, stop and signal error." | |
1122 (interactive "P") | |
1123 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
1124 (if com (move-marker vip-com-point (point))) | |
1125 (forward-char val) | |
1126 (if com (vip-execute-com 'vip-forward-char val com)))) | |
1127 | |
1128 (defun vip-backward-char (arg) | |
1129 "Move point left ARG characters (right if ARG negative). On reaching | |
1130 beginning of buffer, stop and signal error." | |
1131 (interactive "P") | |
1132 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
1133 (if com (move-marker vip-com-point (point))) | |
1134 (backward-char val) | |
1135 (if com (vip-execute-com 'vip-backward-char val com)))) | |
1136 | |
1137 | |
1138 ;; word command | |
1139 | |
1140 (defun vip-forward-word (arg) | |
1141 "Forward word." | |
1142 (interactive "P") | |
1143 (let ((val (vip-p-val arg)) | |
1144 (com (vip-getcom arg))) | |
1145 (if com (move-marker vip-com-point (point))) | |
1146 (forward-word val) | |
1147 (skip-chars-forward " \t\n") | |
1148 (if com | |
1149 (progn | |
1150 (if (or (= com ?c) (= com (- ?c))) | |
1151 (progn (backward-word 1) (forward-word 1))) | |
1152 (if (or (= com ?d) (= com ?y)) | |
1153 (progn | |
1154 (backward-word 1) | |
1155 (forward-word 1) | |
1156 (skip-chars-forward " \t"))) | |
1157 (vip-execute-com 'vip-forward-word val com))))) | |
1158 | |
1159 (defun vip-end-of-word (arg) | |
1160 "Move point to end of current word." | |
1161 (interactive "P") | |
1162 (let ((val (vip-p-val arg)) | |
1163 (com (vip-getcom arg))) | |
1164 (if com (move-marker vip-com-point (point))) | |
1165 (forward-char) | |
1166 (forward-word val) | |
1167 (backward-char) | |
1168 (if com | |
1169 (progn | |
1170 (forward-char) | |
1171 (vip-execute-com 'vip-end-of-word val com))))) | |
1172 | |
1173 (defun vip-backward-word (arg) | |
1174 "Backward word." | |
1175 (interactive "P") | |
1176 (let ((val (vip-p-val arg)) | |
1177 (com (vip-getcom arg))) | |
1178 (if com (move-marker vip-com-point (point))) | |
1179 (backward-word val) | |
1180 (if com (vip-execute-com 'vip-backward-word val com)))) | |
1181 | |
1182 (defun vip-forward-Word (arg) | |
1183 "Forward word delimited by white character." | |
1184 (interactive "P") | |
1185 (let ((val (vip-p-val arg)) | |
1186 (com (vip-getcom arg))) | |
1187 (if com (move-marker vip-com-point (point))) | |
1188 (re-search-forward "[^ \t\n]*[ \t\n]+" nil t val) | |
1189 (if com | |
1190 (progn | |
1191 (if (or (= com ?c) (= com (- ?c))) | |
1192 (progn (backward-word 1) (forward-word 1))) | |
1193 (if (or (= com ?d) (= com ?y)) | |
1194 (progn | |
1195 (backward-word 1) | |
1196 (forward-word 1) | |
1197 (skip-chars-forward " \t"))) | |
1198 (vip-execute-com 'vip-forward-Word val com))))) | |
1199 | |
1200 (defun vip-end-of-Word (arg) | |
1201 "Move forward to end of word delimited by white character." | |
1202 (interactive "P") | |
1203 (let ((val (vip-p-val arg)) | |
1204 (com (vip-getcom arg))) | |
1205 (if com (move-marker vip-com-point (point))) | |
1206 (forward-char) | |
1207 (if (re-search-forward "[^ \t\n]+" nil t val) (backward-char)) | |
1208 (if com | |
1209 (progn | |
1210 (forward-char) | |
1211 (vip-execute-com 'vip-end-of-Word val com))))) | |
1212 | |
1213 (defun vip-backward-Word (arg) | |
1214 "Backward word delimited by white character." | |
1215 (interactive "P") | |
1216 (let ((val (vip-p-val arg)) | |
1217 (com (vip-getcom arg))) | |
1218 (if com (move-marker vip-com-point (point))) | |
1219 (if (re-search-backward "[ \t\n]+[^ \t\n]+" nil t val) | |
1220 (forward-char) | |
1221 (goto-char (point-min))) | |
1222 (if com (vip-execute-com 'vip-backward-Word val com)))) | |
1223 | |
1224 (defun vip-beginning-of-line (arg) | |
1225 "Go to beginning of line." | |
1226 (interactive "P") | |
1227 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
1228 (if com (move-marker vip-com-point (point))) | |
1229 (beginning-of-line val) | |
1230 (if com (vip-execute-com 'vip-beginning-of-line val com)))) | |
1231 | |
1232 (defun vip-bol-and-skip-white (arg) | |
1233 "Beginning of line at first non-white character." | |
1234 (interactive "P") | |
1235 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
1236 (if com (move-marker vip-com-point (point))) | |
1237 (back-to-indentation) | |
1238 (if com (vip-execute-com 'vip-bol-and-skip-white val com)))) | |
1239 | |
1240 (defun vip-goto-eol (arg) | |
1241 "Go to end of line." | |
1242 (interactive "P") | |
1243 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
1244 (if com (move-marker vip-com-point (point))) | |
1245 (end-of-line val) | |
1246 (if com (vip-execute-com 'vip-goto-eol val com)))) | |
1247 | |
1248 (defun vip-next-line (arg) | |
1249 "Go to next line." | |
1250 (interactive "P") | |
1251 (let ((val (vip-p-val arg)) (com (vip-getCom arg))) | |
1252 (if com (move-marker vip-com-point (point))) | |
1253 (line-move val) | |
1254 (setq this-command 'next-line) | |
1255 (if com (vip-execute-com 'vip-next-line val com)))) | |
1256 | |
1257 (defun vip-next-line-at-bol (arg) | |
1258 "Next line at beginning of line." | |
1259 (interactive "P") | |
1260 (let ((val (vip-p-val arg)) (com (vip-getCom arg))) | |
1261 (if com (move-marker vip-com-point (point))) | |
1262 (next-line val) | |
1263 (back-to-indentation) | |
1264 (if com (vip-execute-com 'vip-next-line-at-bol val com)))) | |
1265 | |
1266 (defun vip-previous-line (arg) | |
1267 "Go to previous line." | |
1268 (interactive "P") | |
1269 (let ((val (vip-p-val arg)) (com (vip-getCom arg))) | |
1270 (if com (move-marker vip-com-point (point))) | |
1271 (next-line (- val)) | |
1272 (setq this-command 'previous-line) | |
1273 (if com (vip-execute-com 'vip-previous-line val com)))) | |
1274 | |
1275 (defun vip-previous-line-at-bol (arg) | |
1276 "Previous line at beginning of line." | |
1277 (interactive "P") | |
1278 (let ((val (vip-p-val arg)) (com (vip-getCom arg))) | |
1279 (if com (move-marker vip-com-point (point))) | |
1280 (next-line (- val)) | |
1281 (back-to-indentation) | |
1282 (if com (vip-execute-com 'vip-previous-line val com)))) | |
1283 | |
1284 (defun vip-change-to-eol (arg) | |
1285 "Change to end of line." | |
1286 (interactive "P") | |
1287 (vip-goto-eol (cons arg ?c))) | |
1288 | |
1289 (defun vip-kill-line (arg) | |
1290 "Delete line." | |
1291 (interactive "P") | |
1292 (vip-goto-eol (cons arg ?d))) | |
1293 | |
1294 | |
1295 ;; moving around | |
1296 | |
1297 (defun vip-goto-line (arg) | |
1298 "Go to ARG's line. Without ARG go to end of buffer." | |
1299 (interactive "P") | |
1300 (let ((val (vip-P-val arg)) (com (vip-getCom arg))) | |
1301 (move-marker vip-com-point (point)) | |
1302 (set-mark (point)) | |
1303 (if (null val) | |
1304 (goto-char (point-max)) | |
1305 (goto-char (point-min)) | |
1306 (forward-line (1- val))) | |
1307 (back-to-indentation) | |
1308 (if com (vip-execute-com 'vip-goto-line val com)))) | |
1309 | |
1310 (defun vip-find-char (arg char forward offset) | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3519
diff
changeset
|
1311 "Find ARG's occurrence of CHAR on the current line. If FORWARD then |
11 | 1312 search is forward, otherwise backward. OFFSET is used to adjust point |
1313 after search." | |
1314 (let ((arg (if forward arg (- arg))) point) | |
1315 (save-excursion | |
1316 (save-restriction | |
1317 (if (> arg 0) | |
1318 (narrow-to-region | |
1319 ;; forward search begins here | |
1320 (if (eolp) (error "") (point)) | |
1321 ;; forward search ends here | |
1322 (progn (next-line 1) (beginning-of-line) (point))) | |
1323 (narrow-to-region | |
1324 ;; backward search begins from here | |
1325 (if (bolp) (error "") (point)) | |
1326 ;; backward search ends here | |
1327 (progn (beginning-of-line) (point)))) | |
1328 ;; if arg > 0, point is forwarded before search. | |
1329 (if (> arg 0) (goto-char (1+ (point-min))) | |
1330 (goto-char (point-max))) | |
1331 (let ((case-fold-search nil)) | |
1332 (search-forward (char-to-string char) nil 0 arg)) | |
1333 (setq point (point)) | |
1334 (if (or (and (> arg 0) (= point (point-max))) | |
1335 (and (< arg 0) (= point (point-min)))) | |
1336 (error "")))) | |
1337 (goto-char (+ point (if (> arg 0) (if offset -2 -1) (if offset 1 0)))))) | |
1338 | |
1339 (defun vip-find-char-forward (arg) | |
1340 "Find char on the line. If called interactively read the char to find | |
1341 from the terminal, and if called from vip-repeat, the char last used is | |
1342 used. This behaviour is controlled by the sign of prefix numeric value." | |
1343 (interactive "P") | |
1344 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
1345 (if (> val 0) | |
1346 ;; this means that the function was called interactively | |
1347 (setq vip-f-char (read-char) | |
1348 vip-f-forward t | |
1349 vip-f-offset nil) | |
1350 (setq val (- val))) | |
1351 (if com (move-marker vip-com-point (point))) | |
1352 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t nil) | |
1353 (setq val (- val)) | |
1354 (if com | |
1355 (progn | |
1356 (setq vip-F-char vip-f-char);; set new vip-F-char | |
1357 (forward-char) | |
1358 (vip-execute-com 'vip-find-char-forward val com))))) | |
1359 | |
1360 (defun vip-goto-char-forward (arg) | |
1361 "Go up to char ARG forward on line." | |
1362 (interactive "P") | |
1363 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
1364 (if (> val 0) | |
1365 ;; this means that the function was called interactively | |
1366 (setq vip-f-char (read-char) | |
1367 vip-f-forward t | |
1368 vip-f-offset t) | |
1369 (setq val (- val))) | |
1370 (if com (move-marker vip-com-point (point))) | |
1371 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t t) | |
1372 (setq val (- val)) | |
1373 (if com | |
1374 (progn | |
1375 (setq vip-F-char vip-f-char);; set new vip-F-char | |
1376 (forward-char) | |
1377 (vip-execute-com 'vip-goto-char-forward val com))))) | |
1378 | |
1379 (defun vip-find-char-backward (arg) | |
1380 "Find char ARG on line backward." | |
1381 (interactive "P") | |
1382 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
1383 (if (> val 0) | |
1384 ;; this means that the function was called interactively | |
1385 (setq vip-f-char (read-char) | |
1386 vip-f-forward nil | |
1387 vip-f-offset nil) | |
1388 (setq val (- val))) | |
1389 (if com (move-marker vip-com-point (point))) | |
1390 (vip-find-char | |
1391 val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil nil) | |
1392 (setq val (- val)) | |
1393 (if com | |
1394 (progn | |
1395 (setq vip-F-char vip-f-char);; set new vip-F-char | |
1396 (vip-execute-com 'vip-find-char-backward val com))))) | |
1397 | |
1398 (defun vip-goto-char-backward (arg) | |
1399 "Go up to char ARG backward on line." | |
1400 (interactive "P") | |
1401 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
1402 (if (> val 0) | |
1403 ;; this means that the function was called interactively | |
1404 (setq vip-f-char (read-char) | |
1405 vip-f-forward nil | |
1406 vip-f-offset t) | |
1407 (setq val (- val))) | |
1408 (if com (move-marker vip-com-point (point))) | |
1409 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil t) | |
1410 (setq val (- val)) | |
1411 (if com | |
1412 (progn | |
1413 (setq vip-F-char vip-f-char);; set new vip-F-char | |
1414 (vip-execute-com 'vip-goto-char-backward val com))))) | |
1415 | |
1416 (defun vip-repeat-find (arg) | |
1417 "Repeat previous find command." | |
1418 (interactive "P") | |
1419 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
1420 (if com (move-marker vip-com-point (point))) | |
1421 (vip-find-char val vip-f-char vip-f-forward vip-f-offset) | |
1422 (if com | |
1423 (progn | |
1424 (if vip-f-forward (forward-char)) | |
1425 (vip-execute-com 'vip-repeat-find val com))))) | |
1426 | |
1427 (defun vip-repeat-find-opposite (arg) | |
1428 "Repeat previous find command in the opposite direction." | |
1429 (interactive "P") | |
1430 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
1431 (if com (move-marker vip-com-point (point))) | |
1432 (vip-find-char val vip-f-char (not vip-f-forward) vip-f-offset) | |
1433 (if com | |
1434 (progn | |
1435 (if vip-f-forward (forward-char)) | |
1436 (vip-execute-com 'vip-repeat-find-opposite val com))))) | |
1437 | |
1438 | |
1439 ;; window scrolling etc. | |
1440 | |
1441 (defun vip-other-window (arg) | |
1442 "Switch to other window." | |
1443 (interactive "p") | |
1444 (other-window arg) | |
1445 (or (not (eq vip-current-mode 'emacs-mode)) | |
1446 (string= (buffer-name (current-buffer)) " *Minibuf-1*") | |
1447 (vip-change-mode-to-vi))) | |
1448 | |
1449 (defun vip-window-top (arg) | |
1450 "Go to home window line." | |
1451 (interactive "P") | |
1452 (let ((val (vip-p-val arg)) | |
1453 (com (vip-getCom arg))) | |
1454 (if com (move-marker vip-com-point (point))) | |
1455 (move-to-window-line (1- val)) | |
1456 (if com (vip-execute-com 'vip-window-top val com)))) | |
1457 | |
1458 (defun vip-window-middle (arg) | |
1459 "Go to middle window line." | |
1460 (interactive "P") | |
1461 (let ((val (vip-p-val arg)) | |
1462 (com (vip-getCom arg))) | |
1463 (if com (move-marker vip-com-point (point))) | |
1464 (move-to-window-line (+ (/ (1- (window-height)) 2) (1- val))) | |
1465 (if com (vip-execute-com 'vip-window-middle val com)))) | |
1466 | |
1467 (defun vip-window-bottom (arg) | |
1468 "Go to last window line." | |
1469 (interactive "P") | |
1470 (let ((val (vip-p-val arg)) | |
1471 (com (vip-getCom arg))) | |
1472 (if com (move-marker vip-com-point (point))) | |
1473 (move-to-window-line (- val)) | |
1474 (if com (vip-execute-com 'vip-window-bottom val com)))) | |
1475 | |
1476 (defun vip-line-to-top (arg) | |
1477 "Put current line on the home line." | |
1478 (interactive "p") | |
1479 (recenter (1- arg))) | |
1480 | |
1481 (defun vip-line-to-middle (arg) | |
1482 "Put current line on the middle line." | |
1483 (interactive "p") | |
1484 (recenter (+ (1- arg) (/ (1- (window-height)) 2)))) | |
1485 | |
1486 (defun vip-line-to-bottom (arg) | |
1487 "Put current line on the last line." | |
1488 (interactive "p") | |
1489 (recenter (- (window-height) (1+ arg)))) | |
1490 | |
1491 | |
1492 ;; paren match | |
1493 | |
1494 (defun vip-paren-match (arg) | |
1495 "Go to the matching parenthesis." | |
1496 (interactive "P") | |
1497 (let ((com (vip-getcom arg))) | |
1498 (if (numberp arg) | |
1499 (if (or (> arg 99) (< arg 1)) | |
1500 (error "Prefix must be between 1 and 99.") | |
1501 (goto-char | |
1502 (if (> (point-max) 80000) | |
1503 (* (/ (point-max) 100) arg) | |
1504 (/ (* (point-max) arg) 100))) | |
1505 (back-to-indentation)) | |
1506 (cond ((looking-at "[\(\[{]") | |
1507 (if com (move-marker vip-com-point (point))) | |
1508 (forward-sexp 1) | |
1509 (if com | |
1510 (vip-execute-com 'vip-paren-match nil com) | |
1511 (backward-char))) | |
1512 ((looking-at "[])}]") | |
1513 (forward-char) | |
1514 (if com (move-marker vip-com-point (point))) | |
1515 (backward-sexp 1) | |
1516 (if com (vip-execute-com 'vip-paren-match nil com))) | |
1517 (t (error "")))))) | |
1518 | |
1519 | |
1520 ;; sentence and paragraph | |
1521 | |
1522 (defun vip-forward-sentence (arg) | |
1523 "Forward sentence." | |
1524 (interactive "P") | |
1525 (let ((val (vip-p-val arg)) | |
1526 (com (vip-getcom arg))) | |
1527 (if com (move-marker vip-com-point (point))) | |
1528 (forward-sentence val) | |
1529 (if com (vip-execute-com 'vip-forward-sentence nil com)))) | |
1530 | |
1531 (defun vip-backward-sentence (arg) | |
1532 "Backward sentence." | |
1533 (interactive "P") | |
1534 (let ((val (vip-p-val arg)) | |
1535 (com (vip-getcom arg))) | |
1536 (if com (move-marker vip-com-point (point))) | |
1537 (backward-sentence val) | |
1538 (if com (vip-execute-com 'vip-backward-sentence nil com)))) | |
1539 | |
1540 (defun vip-forward-paragraph (arg) | |
1541 "Forward paragraph." | |
1542 (interactive "P") | |
1543 (let ((val (vip-p-val arg)) | |
1544 (com (vip-getCom arg))) | |
1545 (if com (move-marker vip-com-point (point))) | |
1546 (forward-paragraph val) | |
1547 (if com (vip-execute-com 'vip-forward-paragraph nil com)))) | |
1548 | |
1549 (defun vip-backward-paragraph (arg) | |
1550 "Backward paragraph." | |
1551 (interactive "P") | |
1552 (let ((val (vip-p-val arg)) | |
1553 (com (vip-getCom arg))) | |
1554 (if com (move-marker vip-com-point (point))) | |
1555 (backward-paragraph val) | |
1556 (if com (vip-execute-com 'vip-backward-paragraph nil com)))) | |
1557 | |
1558 | |
1559 ;; scrolling | |
1560 | |
1561 (defun vip-scroll (arg) | |
1562 "Scroll to next screen." | |
1563 (interactive "p") | |
1564 (if (> arg 0) | |
1565 (while (> arg 0) | |
1566 (scroll-up) | |
1567 (setq arg (1- arg))) | |
1568 (while (> 0 arg) | |
1569 (scroll-down) | |
1570 (setq arg (1+ arg))))) | |
1571 | |
1572 (defun vip-scroll-back (arg) | |
1573 "Scroll to previous screen." | |
1574 (interactive "p") | |
1575 (vip-scroll (- arg))) | |
1576 | |
1577 (defun vip-scroll-down (arg) | |
1578 "Scroll up half screen." | |
1579 (interactive "P") | |
1580 (if (null arg) (scroll-down (/ (window-height) 2)) | |
1581 (scroll-down arg))) | |
1582 | |
1583 (defun vip-scroll-down-one (arg) | |
1584 "Scroll up one line." | |
1585 (interactive "p") | |
1586 (scroll-down arg)) | |
1587 | |
1588 (defun vip-scroll-up (arg) | |
1589 "Scroll down half screen." | |
1590 (interactive "P") | |
1591 (if (null arg) (scroll-up (/ (window-height) 2)) | |
1592 (scroll-up arg))) | |
1593 | |
1594 (defun vip-scroll-up-one (arg) | |
1595 "Scroll down one line." | |
1596 (interactive "p") | |
1597 (scroll-up arg)) | |
1598 | |
1599 | |
1600 ;; splitting window | |
1601 | |
1602 (defun vip-buffer-in-two-windows () | |
1603 "Show current buffer in two windows." | |
1604 (interactive) | |
1605 (delete-other-windows) | |
1606 (split-window-vertically nil)) | |
1607 | |
1608 | |
1609 ;; searching | |
1610 | |
1611 (defun vip-search-forward (arg) | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3519
diff
changeset
|
1612 "Search a string forward. ARG is used to find the ARG's occurrence |
11 | 1613 of the string. Default is vanilla search. Search mode can be toggled by |
1614 giving null search string." | |
1615 (interactive "P") | |
1616 (let ((val (vip-P-val arg)) (com (vip-getcom arg))) | |
1617 (setq vip-s-forward t | |
1618 vip-s-string (vip-read-string (if vip-re-search "RE-/" "/"))) | |
1619 (if (string= vip-s-string "") | |
1620 (progn | |
1621 (setq vip-re-search (not vip-re-search)) | |
14345
e37ae69fce10
(vip-replace-string, vip-search-forward, vip-search-backward): Delete format call inside message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
1622 (message "Search mode changed to %s search." |
e37ae69fce10
(vip-replace-string, vip-search-forward, vip-search-backward): Delete format call inside message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
1623 (if vip-re-search "regular expression" |
e37ae69fce10
(vip-replace-string, vip-search-forward, vip-search-backward): Delete format call inside message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
1624 "vanilla"))) |
11 | 1625 (vip-search vip-s-string t val) |
1626 (if com | |
1627 (progn | |
1628 (move-marker vip-com-point (mark)) | |
1629 (vip-execute-com 'vip-search-next val com)))))) | |
1630 | |
1631 (defun vip-search-backward (arg) | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3519
diff
changeset
|
1632 "Search a string backward. ARG is used to find the ARG's occurrence |
11 | 1633 of the string. Default is vanilla search. Search mode can be toggled by |
1634 giving null search string." | |
1635 (interactive "P") | |
1636 (let ((val (vip-P-val arg)) (com (vip-getcom arg))) | |
1637 (setq vip-s-forward nil | |
1638 vip-s-string (vip-read-string (if vip-re-search "RE-?" "?"))) | |
1639 (if (string= vip-s-string "") | |
1640 (progn | |
1641 (setq vip-re-search (not vip-re-search)) | |
14345
e37ae69fce10
(vip-replace-string, vip-search-forward, vip-search-backward): Delete format call inside message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
1642 (message "Search mode changed to %s search." |
e37ae69fce10
(vip-replace-string, vip-search-forward, vip-search-backward): Delete format call inside message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
1643 (if vip-re-search "regular expression" |
e37ae69fce10
(vip-replace-string, vip-search-forward, vip-search-backward): Delete format call inside message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
1644 "vanilla"))) |
11 | 1645 (vip-search vip-s-string nil val) |
1646 (if com | |
1647 (progn | |
1648 (move-marker vip-com-point (mark)) | |
1649 (vip-execute-com 'vip-search-next val com)))))) | |
1650 | |
1651 (defun vip-search (string forward arg &optional no-offset init-point) | |
1652 "(STRING FORWARD COUNT &optional NO-OFFSET) Search COUNT's occurrence of | |
1653 STRING. Search will be forward if FORWARD, otherwise backward." | |
1654 (let ((val (vip-p-val arg)) (com (vip-getcom arg)) | |
1655 (null-arg (null (vip-P-val arg))) (offset (not no-offset)) | |
1656 (case-fold-search vip-case-fold-search) | |
1657 (start-point (or init-point (point)))) | |
1658 (if forward | |
1659 (condition-case conditions | |
1660 (progn | |
1661 (if (and offset (not (eobp))) (forward-char)) | |
1662 (if vip-re-search | |
1663 (progn | |
1664 (re-search-forward string nil nil val) | |
1665 (re-search-backward string)) | |
1666 (search-forward string nil nil val) | |
1667 (search-backward string)) | |
1668 (push-mark start-point)) | |
1669 (search-failed | |
1670 (if (and null-arg vip-search-wrap-around) | |
1671 (progn | |
1672 (goto-char (point-min)) | |
1673 (vip-search string forward (cons 1 com) t start-point)) | |
1674 (goto-char start-point) | |
1675 (signal 'search-failed (cdr conditions))))) | |
1676 (condition-case conditions | |
1677 (progn | |
1678 (if vip-re-search | |
1679 (re-search-backward string nil nil val) | |
1680 (search-backward string nil nil val)) | |
1681 (push-mark start-point)) | |
1682 (search-failed | |
1683 (if (and null-arg vip-search-wrap-around) | |
1684 (progn | |
1685 (goto-char (point-max)) | |
1686 (vip-search string forward (cons 1 com) t start-point)) | |
1687 (goto-char start-point) | |
1688 (signal 'search-failed (cdr conditions)))))))) | |
1689 | |
1690 (defun vip-search-next (arg) | |
1691 "Repeat previous search." | |
1692 (interactive "P") | |
1693 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
1694 (if (null vip-s-string) (error "No previous search string.")) | |
1695 (vip-search vip-s-string vip-s-forward arg) | |
1696 (if com (vip-execute-com 'vip-search-next val com)))) | |
1697 | |
1698 (defun vip-search-Next (arg) | |
1699 "Repeat previous search in the reverse direction." | |
1700 (interactive "P") | |
1701 (let ((val (vip-p-val arg)) (com (vip-getcom arg))) | |
1702 (if (null vip-s-string) (error "No previous search string.")) | |
1703 (vip-search vip-s-string (not vip-s-forward) arg) | |
1704 (if com (vip-execute-com 'vip-search-Next val com)))) | |
1705 | |
1706 | |
1707 ;; visiting and killing files, buffers | |
1708 | |
1709 (defun vip-switch-to-buffer () | |
1710 "Switch to buffer in the current window." | |
1711 (interactive) | |
1712 (let (buffer) | |
1713 (setq buffer | |
1714 (read-buffer | |
1715 (format "switch to buffer \(%s\): " | |
1716 (buffer-name (other-buffer (current-buffer)))))) | |
1717 (switch-to-buffer buffer) | |
1718 (vip-change-mode-to-vi))) | |
1719 | |
1720 (defun vip-switch-to-buffer-other-window () | |
1721 "Switch to buffer in another window." | |
1722 (interactive) | |
1723 (let (buffer) | |
1724 (setq buffer | |
1725 (read-buffer | |
1726 (format "Switch to buffer \(%s\): " | |
1727 (buffer-name (other-buffer (current-buffer)))))) | |
1728 (switch-to-buffer-other-window buffer) | |
1729 (vip-change-mode-to-vi))) | |
1730 | |
1731 (defun vip-kill-buffer () | |
1732 "Kill a buffer." | |
1733 (interactive) | |
1734 (let (buffer buffer-name) | |
1735 (setq buffer-name | |
1736 (read-buffer | |
1737 (format "Kill buffer \(%s\): " | |
1738 (buffer-name (current-buffer))))) | |
1739 (setq buffer | |
1740 (if (null buffer-name) | |
1741 (current-buffer) | |
1742 (get-buffer buffer-name))) | |
1743 (if (null buffer) (error "Buffer %s nonexistent." buffer-name)) | |
1744 (if (or (not (buffer-modified-p buffer)) | |
1745 (y-or-n-p "Buffer is modified, are you sure? ")) | |
1746 (kill-buffer buffer) | |
1747 (error "Buffer not killed.")))) | |
1748 | |
1749 (defun vip-find-file () | |
1750 "Visit file in the current window." | |
1751 (interactive) | |
1752 (let (file) | |
1753 (setq file (read-file-name "visit file: ")) | |
1754 (switch-to-buffer (find-file-noselect file)) | |
1755 (vip-change-mode-to-vi))) | |
1756 | |
1757 (defun vip-find-file-other-window () | |
1758 "Visit file in another window." | |
1759 (interactive) | |
1760 (let (file) | |
1761 (setq file (read-file-name "Visit file: ")) | |
1762 (switch-to-buffer-other-window (find-file-noselect file)) | |
1763 (vip-change-mode-to-vi))) | |
1764 | |
1765 (defun vip-info-on-file () | |
1766 "Give information of the file associated to the current buffer." | |
1767 (interactive) | |
1768 (message "\"%s\" line %d of %d" | |
1769 (if (buffer-file-name) (buffer-file-name) "") | |
1770 (1+ (count-lines (point-min) (point))) | |
1771 (1+ (count-lines (point-min) (point-max))))) | |
1772 | |
1773 | |
1774 ;; yank and pop | |
1775 | |
1776 (defun vip-yank (text) | |
1777 "yank TEXT silently." | |
1778 (save-excursion | |
1779 (vip-push-mark-silent (point)) | |
1780 (insert text) | |
1781 (exchange-point-and-mark)) | |
1782 (skip-chars-forward " \t")) | |
1783 | |
1784 (defun vip-put-back (arg) | |
1785 "Put back after point/below line." | |
1786 (interactive "P") | |
1787 (let ((val (vip-p-val arg)) | |
1788 (text (if vip-use-register | |
1789 (if (and (<= ?1 vip-use-register) (<= vip-use-register ?9)) | |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
1790 (current-kill (- vip-use-register ?1) 'do-not-rotate) |
11 | 1791 (get-register vip-use-register)) |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
1792 (current-kill 0)))) |
11 | 1793 (if (null text) |
1794 (if vip-use-register | |
1795 (let ((reg vip-use-register)) | |
1796 (setq vip-use-register nil) | |
1797 (error "Nothing in register %c" reg)) | |
1798 (error ""))) | |
1799 (setq vip-use-register nil) | |
1800 (if (vip-end-with-a-newline-p text) | |
1801 (progn | |
1802 (next-line 1) | |
1803 (beginning-of-line)) | |
1804 (if (and (not (eolp)) (not (eobp))) (forward-char))) | |
1805 (setq vip-d-com (list 'vip-put-back val nil vip-use-register)) | |
1806 (vip-loop val (vip-yank text)))) | |
1807 | |
1808 (defun vip-Put-back (arg) | |
1809 "Put back at point/above line." | |
1810 (interactive "P") | |
1811 (let ((val (vip-p-val arg)) | |
1812 (text (if vip-use-register | |
1813 (if (and (<= ?1 vip-use-register) (<= vip-use-register ?9)) | |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
1814 (current-kill (- vip-use-register ?1) 'do-not-rotate) |
11 | 1815 (get-register vip-use-register)) |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
1816 (current-kill 0)))) |
11 | 1817 (if (null text) |
1818 (if vip-use-register | |
1819 (let ((reg vip-use-register)) | |
1820 (setq vip-use-register nil) | |
1821 (error "Nothing in register %c" reg)) | |
1822 (error ""))) | |
1823 (setq vip-use-register nil) | |
1824 (if (vip-end-with-a-newline-p text) (beginning-of-line)) | |
1825 (setq vip-d-com (list 'vip-Put-back val nil vip-use-register)) | |
1826 (vip-loop val (vip-yank text)))) | |
1827 | |
1828 (defun vip-delete-char (arg) | |
1829 "Delete character." | |
1830 (interactive "P") | |
1831 (let ((val (vip-p-val arg))) | |
1832 (setq vip-d-com (list 'vip-delete-char val nil)) | |
1833 (if vip-use-register | |
1834 (progn | |
1835 (if (and (<= ?A vip-use-register) (<= vip-use-register ?Z)) | |
1836 (vip-append-to-register | |
1625
376427dea90a
* bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents:
1577
diff
changeset
|
1837 (+ vip-use-register 32) (point) (- (point) val)) |
11 | 1838 (copy-to-register vip-use-register (point) (- (point) val) nil)) |
1839 (setq vip-use-register nil))) | |
1840 (delete-char val t))) | |
1841 | |
1842 (defun vip-delete-backward-char (arg) | |
1843 "Delete previous character." | |
1844 (interactive "P") | |
1845 (let ((val (vip-p-val arg))) | |
1846 (setq vip-d-com (list 'vip-delete-backward-char val nil)) | |
1847 (if vip-use-register | |
1848 (progn | |
1849 (if (and (<= ?A vip-use-register) (<= vip-use-register ?Z)) | |
1850 (vip-append-to-register | |
1625
376427dea90a
* bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents:
1577
diff
changeset
|
1851 (+ vip-use-register 32) (point) (+ (point) val)) |
11 | 1852 (copy-to-register vip-use-register (point) (+ (point) val) nil)) |
1853 (setq vip-use-register nil))) | |
1854 (delete-backward-char val t))) | |
1855 | |
1856 | |
1857 ;; join lines. | |
1858 | |
1859 (defun vip-join-lines (arg) | |
1860 "Join this line to next, if ARG is nil. Otherwise, join ARG lines" | |
1861 (interactive "*P") | |
1862 (let ((val (vip-P-val arg))) | |
1863 (setq vip-d-com (list 'vip-join-lines val nil)) | |
1864 (vip-loop (if (null val) 1 (1- val)) | |
1865 (progn | |
1866 (end-of-line) | |
1867 (if (not (eobp)) | |
1868 (progn | |
1869 (forward-line 1) | |
1870 (delete-region (point) (1- (point))) | |
1871 (fixup-whitespace))))))) | |
1872 | |
1873 | |
1874 ;; making small changes | |
1875 | |
18424
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
1876 (defvar vip-c-string) |
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
1877 |
11 | 1878 (defun vip-change (beg end) |
18424
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
1879 (setq vip-c-string |
11 | 1880 (vip-read-string (format "%s => " (buffer-substring beg end)))) |
1881 (vip-change-subr beg end)) | |
1882 | |
1883 (defun vip-change-subr (beg end) | |
1884 (if vip-use-register | |
1885 (progn | |
1886 (copy-to-register vip-use-register beg end nil) | |
1887 (setq vip-use-register nil))) | |
1888 (kill-region beg end) | |
1889 (setq this-command 'vip-change) | |
18424
395e1d352d3b
(vip-mode-map): Add defvar; move earlier.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
1890 (insert vip-c-string)) |
11 | 1891 |
1892 | |
1893 ;; query replace | |
1894 | |
1895 (defun vip-query-replace () | |
1896 "Query replace. If you supply null string as the string to be replaced, | |
1897 the query replace mode will toggle between string replace and regexp replace." | |
1898 (interactive) | |
1899 (let (str) | |
1900 (setq str (vip-read-string | |
1901 (if vip-re-query-replace "Query replace regexp: " | |
1902 "Query replace: "))) | |
1903 (if (string= str "") | |
1904 (progn | |
1905 (setq vip-re-query-replace (not vip-re-query-replace)) | |
1906 (message "Query replace mode changed to %s." | |
1907 (if vip-re-query-replace "regexp replace" | |
1908 "string replace"))) | |
1909 (if vip-re-query-replace | |
1910 (query-replace-regexp | |
1911 str | |
1912 (vip-read-string (format "Query replace regexp \"%s\" with: " str))) | |
1913 (query-replace | |
1914 str | |
1915 (vip-read-string (format "Query replace \"%s\" with: " str))))))) | |
1916 | |
1917 | |
1918 ;; marking | |
1919 | |
1920 (defun vip-mark-beginning-of-buffer () | |
1921 (interactive) | |
1922 (set-mark (point)) | |
1923 (goto-char (point-min)) | |
1924 (exchange-point-and-mark) | |
1925 (message "mark set at the beginning of buffer")) | |
1926 | |
1927 (defun vip-mark-end-of-buffer () | |
1928 (interactive) | |
1929 (set-mark (point)) | |
1930 (goto-char (point-max)) | |
1931 (exchange-point-and-mark) | |
1932 (message "mark set at the end of buffer")) | |
1933 | |
1934 (defun vip-mark-point (char) | |
1935 (interactive "c") | |
1936 (cond ((and (<= ?a char) (<= char ?z)) | |
1625
376427dea90a
* bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents:
1577
diff
changeset
|
1937 (point-to-register (- char (- ?a ?\C-a)) nil)) |
11 | 1938 ((= char ?<) (vip-mark-beginning-of-buffer)) |
1939 ((= char ?>) (vip-mark-end-of-buffer)) | |
1940 ((= char ?.) (push-mark)) | |
1941 ((= char ?,) (set-mark-command 1)) | |
1942 ((= char ?D) (mark-defun)) | |
1943 (t (error "")))) | |
1944 | |
1945 (defun vip-goto-mark (arg) | |
1946 "Go to mark." | |
1947 (interactive "P") | |
1948 (let ((char (read-char)) (com (vip-getcom arg))) | |
1949 (vip-goto-mark-subr char com nil))) | |
1950 | |
1951 (defun vip-goto-mark-and-skip-white (arg) | |
1952 "Go to mark and skip to first non-white on line." | |
1953 (interactive "P") | |
1954 (let ((char (read-char)) (com (vip-getCom arg))) | |
1955 (vip-goto-mark-subr char com t))) | |
1956 | |
1957 (defun vip-goto-mark-subr (char com skip-white) | |
1958 (cond ((and (<= ?a char) (<= char ?z)) | |
1959 (let ((buff (current-buffer))) | |
1960 (if com (move-marker vip-com-point (point))) | |
1961 (goto-char (register-to-point (- char (- ?a ?\C-a)))) | |
1962 (if skip-white (back-to-indentation)) | |
1963 (vip-change-mode-to-vi) | |
1964 (if com | |
1965 (if (equal buff (current-buffer)) | |
1966 (vip-execute-com (if skip-white | |
1967 'vip-goto-mark-and-skip-white | |
1968 'vip-goto-mark) | |
1969 nil com) | |
1970 (switch-to-buffer buff) | |
1971 (goto-char vip-com-point) | |
1972 (vip-change-mode-to-vi) | |
1973 (error ""))))) | |
1974 ((and (not skip-white) (= char ?`)) | |
1975 (if com (move-marker vip-com-point (point))) | |
1976 (exchange-point-and-mark) | |
1977 (if com (vip-execute-com 'vip-goto-mark nil com))) | |
1978 ((and skip-white (= char ?')) | |
1979 (if com (move-marker vip-com-point (point))) | |
1980 (exchange-point-and-mark) | |
1981 (back-to-indentation) | |
1982 (if com (vip-execute-com 'vip-goto-mark-and-skip-white nil com))) | |
1983 (t (error "")))) | |
1984 | |
1985 (defun vip-exchange-point-and-mark () | |
1986 (interactive) | |
1987 (exchange-point-and-mark) | |
1988 (back-to-indentation)) | |
1989 | |
1990 (defun vip-keyboard-quit () | |
1991 "Abort partially formed or running command." | |
1992 (interactive) | |
1993 (setq vip-use-register nil) | |
1994 (keyboard-quit)) | |
1995 | |
1996 (defun vip-ctl-c-equivalent (arg) | |
1997 "Emulate C-c in Emacs mode." | |
1998 (interactive "P") | |
1999 (vip-ctl-key-equivalent "\C-c" arg)) | |
2000 | |
2001 (defun vip-ctl-x-equivalent (arg) | |
2002 "Emulate C-x in Emacs mode." | |
2003 (interactive "P") | |
2004 (vip-ctl-key-equivalent "\C-x" arg)) | |
2005 | |
2006 (defun vip-ctl-key-equivalent (key arg) | |
2007 (let ((char (read-char))) | |
2008 (if (and (<= ?A char) (<= char ?Z)) | |
2009 (setq char (- char (- ?A ?\C-a)))) | |
3519
093c4dc7e884
(vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents:
2319
diff
changeset
|
2010 (vip-escape-to-emacs arg (list (aref key 0) char)))) |
11 | 2011 |
2012 ;; commands in insertion mode | |
2013 | |
2014 (defun vip-delete-backward-word (arg) | |
2015 "Delete previous word." | |
2016 (interactive "p") | |
2017 (save-excursion | |
2018 (set-mark (point)) | |
2019 (backward-word arg) | |
2020 (delete-region (point) (mark)))) | |
2021 | |
2022 | |
2023 ;; implement ex commands | |
2024 | |
2025 (defvar ex-token-type nil | |
2026 "type of token. if non-nil, gives type of address. if nil, it | |
2027 is a command.") | |
2028 | |
2029 (defvar ex-token nil | |
2030 "value of token.") | |
2031 | |
2032 (defvar ex-addresses nil | |
2033 "list of ex addresses") | |
2034 | |
2035 (defvar ex-flag nil | |
2036 "flag for ex flag") | |
2037 | |
2038 (defvar ex-buffer nil | |
2039 "name of ex buffer") | |
2040 | |
2041 (defvar ex-count nil | |
2042 "value of ex count") | |
2043 | |
2044 (defvar ex-g-flag nil | |
2045 "flag for global command") | |
2046 | |
2047 (defvar ex-g-variant nil | |
2048 "if t global command is executed on lines not matching ex-g-pat") | |
2049 | |
2050 (defvar ex-reg-exp nil | |
2051 "save reg-exp used in substitute") | |
2052 | |
2053 (defvar ex-repl nil | |
2054 "replace pattern for substitute") | |
2055 | |
2056 (defvar ex-g-pat nil | |
2057 "pattern for global command") | |
2058 | |
2059 (defvar ex-map (make-sparse-keymap) | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3519
diff
changeset
|
2060 "save commands for mapped keys") |
11 | 2061 |
2062 (defvar ex-tag nil | |
2063 "save ex tag") | |
2064 | |
2065 (defvar ex-file nil) | |
2066 | |
2067 (defvar ex-variant nil) | |
2068 | |
2069 (defvar ex-offset nil) | |
2070 | |
2071 (defvar ex-append nil) | |
2072 | |
2073 (defun vip-nil () | |
2074 (interactive) | |
2075 (error "")) | |
2076 | |
2077 (defun vip-looking-back (str) | |
2078 "returns t if looking back reg-exp STR before point." | |
2079 (and (save-excursion (re-search-backward str nil t)) | |
2080 (= (point) (match-end 0)))) | |
2081 | |
2082 (defun vip-check-sub (str) | |
2083 "check if ex-token is an initial segment of STR" | |
2084 (let ((length (length ex-token))) | |
2085 (if (and (<= length (length str)) | |
2086 (string= ex-token (substring str 0 length))) | |
2087 (setq ex-token str) | |
2088 (setq ex-token-type "non-command")))) | |
2089 | |
2090 (defun vip-get-ex-com-subr () | |
2091 "get a complete ex command" | |
2092 (set-mark (point)) | |
2093 (re-search-forward "[a-z][a-z]*") | |
2094 (setq ex-token-type "command") | |
2095 (setq ex-token (buffer-substring (point) (mark))) | |
2096 (exchange-point-and-mark) | |
2097 (cond ((looking-at "a") | |
2098 (cond ((looking-at "ab") (vip-check-sub "abbreviate")) | |
2099 ((looking-at "ar") (vip-check-sub "args")) | |
2100 (t (vip-check-sub "append")))) | |
2101 ((looking-at "[bh]") (setq ex-token-type "non-command")) | |
2102 ((looking-at "c") | |
2103 (if (looking-at "co") (vip-check-sub "copy") | |
2104 (vip-check-sub "change"))) | |
2105 ((looking-at "d") (vip-check-sub "delete")) | |
2106 ((looking-at "e") | |
2107 (if (looking-at "ex") (vip-check-sub "ex") | |
2108 (vip-check-sub "edit"))) | |
2109 ((looking-at "f") (vip-check-sub "file")) | |
2110 ((looking-at "g") (vip-check-sub "global")) | |
2111 ((looking-at "i") (vip-check-sub "insert")) | |
2112 ((looking-at "j") (vip-check-sub "join")) | |
2113 ((looking-at "l") (vip-check-sub "list")) | |
2114 ((looking-at "m") | |
2115 (cond ((looking-at "map") (vip-check-sub "map")) | |
2116 ((looking-at "mar") (vip-check-sub "mark")) | |
2117 (t (vip-check-sub "move")))) | |
2118 ((looking-at "n") | |
2119 (if (looking-at "nu") (vip-check-sub "number") | |
2120 (vip-check-sub "next"))) | |
2121 ((looking-at "o") (vip-check-sub "open")) | |
2122 ((looking-at "p") | |
2123 (cond ((looking-at "pre") (vip-check-sub "preserve")) | |
2124 ((looking-at "pu") (vip-check-sub "put")) | |
2125 (t (vip-check-sub "print")))) | |
2126 ((looking-at "q") (vip-check-sub "quit")) | |
2127 ((looking-at "r") | |
2128 (cond ((looking-at "rec") (vip-check-sub "recover")) | |
2129 ((looking-at "rew") (vip-check-sub "rewind")) | |
2130 (t (vip-check-sub "read")))) | |
2131 ((looking-at "s") | |
2132 (cond ((looking-at "se") (vip-check-sub "set")) | |
2133 ((looking-at "sh") (vip-check-sub "shell")) | |
2134 ((looking-at "so") (vip-check-sub "source")) | |
2135 ((looking-at "st") (vip-check-sub "stop")) | |
2136 (t (vip-check-sub "substitute")))) | |
2137 ((looking-at "t") | |
2138 (if (looking-at "ta") (vip-check-sub "tag") | |
2139 (vip-check-sub "t"))) | |
2140 ((looking-at "u") | |
2141 (cond ((looking-at "una") (vip-check-sub "unabbreviate")) | |
2142 ((looking-at "unm") (vip-check-sub "unmap")) | |
2143 (t (vip-check-sub "undo")))) | |
2144 ((looking-at "v") | |
2145 (cond ((looking-at "ve") (vip-check-sub "version")) | |
2146 ((looking-at "vi") (vip-check-sub "visual")) | |
2147 (t (vip-check-sub "v")))) | |
2148 ((looking-at "w") | |
2149 (if (looking-at "wq") (vip-check-sub "wq") | |
2150 (vip-check-sub "write"))) | |
2151 ((looking-at "x") (vip-check-sub "xit")) | |
2152 ((looking-at "y") (vip-check-sub "yank")) | |
2153 ((looking-at "z") (vip-check-sub "z"))) | |
2154 (exchange-point-and-mark)) | |
2155 | |
2156 (defun vip-get-ex-token () | |
2157 "get an ex-token which is either an address or a command. | |
2158 a token has type \(command, address, end-mark\) and value." | |
2159 (save-window-excursion | |
2160 (set-buffer " *ex-working-space*") | |
2161 (skip-chars-forward " \t") | |
2162 (cond ((looking-at "[k#]") | |
2163 (setq ex-token-type "command") | |
2164 (setq ex-token (char-to-string (following-char))) | |
2165 (forward-char 1)) | |
2166 ((looking-at "[a-z]") (vip-get-ex-com-subr)) | |
2167 ((looking-at "\\.") | |
2168 (forward-char 1) | |
2169 (setq ex-token-type "dot")) | |
2170 ((looking-at "[0-9]") | |
2171 (set-mark (point)) | |
2172 (re-search-forward "[0-9]*") | |
2173 (setq ex-token-type | |
2174 (cond ((string= ex-token-type "plus") "add-number") | |
2175 ((string= ex-token-type "minus") "sub-number") | |
2176 (t "abs-number"))) | |
2177 (setq ex-token (string-to-int (buffer-substring (point) (mark))))) | |
2178 ((looking-at "\\$") | |
2179 (forward-char 1) | |
2180 (setq ex-token-type "end")) | |
2181 ((looking-at "%") | |
2182 (forward-char 1) | |
2183 (setq ex-token-type "whole")) | |
2184 ((looking-at "+") | |
2185 (cond ((or (looking-at "+[-+]") (looking-at "+[\n|]")) | |
2186 (forward-char 1) | |
2187 (insert "1") | |
2188 (backward-char 1) | |
2189 (setq ex-token-type "plus")) | |
2190 ((looking-at "+[0-9]") | |
2191 (forward-char 1) | |
2192 (setq ex-token-type "plus")) | |
2193 (t | |
2194 (error "Badly formed address")))) | |
2195 ((looking-at "-") | |
2196 (cond ((or (looking-at "-[-+]") (looking-at "-[\n|]")) | |
2197 (forward-char 1) | |
2198 (insert "1") | |
2199 (backward-char 1) | |
2200 (setq ex-token-type "minus")) | |
2201 ((looking-at "-[0-9]") | |
2202 (forward-char 1) | |
2203 (setq ex-token-type "minus")) | |
2204 (t | |
2205 (error "Badly formed address")))) | |
2206 ((looking-at "/") | |
2207 (forward-char 1) | |
2208 (set-mark (point)) | |
2209 (let ((cont t)) | |
2210 (while (and (not (eolp)) cont) | |
2211 ;;(re-search-forward "[^/]*/") | |
2212 (re-search-forward "[^/]*\\(/\\|\n\\)") | |
2213 (if (not (vip-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\/")) | |
2214 (setq cont nil)))) | |
2215 (backward-char 1) | |
2216 (setq ex-token (buffer-substring (point) (mark))) | |
2217 (if (looking-at "/") (forward-char 1)) | |
2218 (setq ex-token-type "search-forward")) | |
2219 ((looking-at "\\?") | |
2220 (forward-char 1) | |
2221 (set-mark (point)) | |
2222 (let ((cont t)) | |
2223 (while (and (not (eolp)) cont) | |
2224 ;;(re-search-forward "[^\\?]*\\?") | |
2225 (re-search-forward "[^\\?]*\\(\\?\\|\n\\)") | |
2226 (if (not (vip-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\\\?")) | |
2227 (setq cont nil)) | |
2228 (backward-char 1) | |
2229 (if (not (looking-at "\n")) (forward-char 1)))) | |
2230 (setq ex-token-type "search-backward") | |
2231 (setq ex-token (buffer-substring (1- (point)) (mark)))) | |
2232 ((looking-at ",") | |
2233 (forward-char 1) | |
2234 (setq ex-token-type "comma")) | |
2235 ((looking-at ";") | |
2236 (forward-char 1) | |
2237 (setq ex-token-type "semi-colon")) | |
2238 ((looking-at "[!=><&~]") | |
2239 (setq ex-token-type "command") | |
2240 (setq ex-token (char-to-string (following-char))) | |
2241 (forward-char 1)) | |
2242 ((looking-at "'") | |
2243 (setq ex-token-type "goto-mark") | |
2244 (forward-char 1) | |
2245 (cond ((looking-at "'") (setq ex-token nil)) | |
2246 ((looking-at "[a-z]") (setq ex-token (following-char))) | |
2247 (t (error "Marks are ' and a-z"))) | |
2248 (forward-char 1)) | |
2249 ((looking-at "\n") | |
2250 (setq ex-token-type "end-mark") | |
2251 (setq ex-token "goto")) | |
2252 (t | |
2253 (error "illegal token"))))) | |
2254 | |
2255 (defun vip-ex (&optional string) | |
2256 "ex commands within VIP." | |
2257 (interactive) | |
2258 (or string | |
2259 (setq ex-g-flag nil | |
2260 ex-g-variant nil)) | |
2261 (let ((com-str (or string (vip-read-string ":"))) | |
2262 (address nil) (cont t) (dot (point))) | |
2263 (save-window-excursion | |
2264 (set-buffer (get-buffer-create " *ex-working-space*")) | |
2265 (delete-region (point-min) (point-max)) | |
2266 (insert com-str "\n") | |
2267 (goto-char (point-min))) | |
2268 (setq ex-token-type "") | |
2269 (setq ex-addresses nil) | |
2270 (while cont | |
2271 (vip-get-ex-token) | |
2272 (cond ((or (string= ex-token-type "command") | |
2273 (string= ex-token-type "end-mark")) | |
2274 (if address (setq ex-addresses (cons address ex-addresses))) | |
2275 (cond ((string= ex-token "global") | |
2276 (ex-global nil) | |
2277 (setq cont nil)) | |
2278 ((string= ex-token "v") | |
2279 (ex-global t) | |
2280 (setq cont nil)) | |
2281 (t | |
2282 (vip-execute-ex-command) | |
2283 (save-window-excursion | |
2284 (set-buffer " *ex-working-space*") | |
2285 (skip-chars-forward " \t") | |
2286 (cond ((looking-at "|") | |
2287 (forward-char 1)) | |
2288 ((looking-at "\n") | |
2289 (setq cont nil)) | |
2290 (t (error "Extra character at end of a command"))))))) | |
2291 ((string= ex-token-type "non-command") | |
2292 (error (format "%s: Not an editor command" ex-token))) | |
2293 ((string= ex-token-type "whole") | |
2294 (setq ex-addresses | |
2295 (cons (point-max) (cons (point-min) ex-addresses)))) | |
2296 ((string= ex-token-type "comma") | |
2297 (setq ex-addresses | |
2298 (cons (if (null address) (point) address) ex-addresses))) | |
2299 ((string= ex-token-type "semi-colon") | |
2300 (if address (setq dot address)) | |
2301 (setq ex-addresses | |
2302 (cons (if (null address) (point) address) ex-addresses))) | |
2303 (t (let ((ans (vip-get-ex-address-subr address dot))) | |
2304 (if ans (setq address ans)))))))) | |
2305 | |
2306 (defun vip-get-ex-pat () | |
2307 "get a regular expression and set ex-variant if found" | |
2308 (save-window-excursion | |
2309 (set-buffer " *ex-working-space*") | |
2310 (skip-chars-forward " \t") | |
2311 (if (looking-at "!") | |
2312 (progn | |
2313 (setq ex-g-variant (not ex-g-variant) | |
2314 ex-g-flag (not ex-g-flag)) | |
2315 (forward-char 1) | |
2316 (skip-chars-forward " \t"))) | |
2317 (if (looking-at "/") | |
2318 (progn | |
2319 (forward-char 1) | |
2320 (set-mark (point)) | |
2321 (let ((cont t)) | |
2322 (while (and (not (eolp)) cont) | |
2323 (re-search-forward "[^/]*\\(/\\|\n\\)") | |
2324 ;;(re-search-forward "[^/]*/") | |
2325 (if (not (vip-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\/")) | |
2326 (setq cont nil)))) | |
2327 (setq ex-token | |
2328 (if (= (mark) (point)) "" | |
2329 (buffer-substring (1- (point)) (mark)))) | |
2330 (backward-char 1)) | |
2331 (setq ex-token nil)))) | |
2332 | |
2333 (defun vip-get-ex-command () | |
2334 "get an ex command" | |
2335 (save-window-excursion | |
2336 (set-buffer " *ex-working-space*") | |
2337 (if (looking-at "/") (forward-char 1)) | |
2338 (skip-chars-forward " \t") | |
2339 (cond ((looking-at "[a-z]") | |
2340 (vip-get-ex-com-subr) | |
2341 (if (string= ex-token-type "non-command") | |
2342 (error "%s: not an editor command" ex-token))) | |
2343 ((looking-at "[!=><&~]") | |
2344 (setq ex-token (char-to-string (following-char))) | |
2345 (forward-char 1)) | |
2346 (t (error "Could not find an ex command"))))) | |
2347 | |
2348 (defun vip-get-ex-opt-gc () | |
2349 "get an ex option g or c" | |
2350 (save-window-excursion | |
2351 (set-buffer " *ex-working-space*") | |
2352 (if (looking-at "/") (forward-char 1)) | |
2353 (skip-chars-forward " \t") | |
2354 (cond ((looking-at "g") | |
2355 (setq ex-token "g") | |
2356 (forward-char 1) | |
2357 t) | |
2358 ((looking-at "c") | |
2359 (setq ex-token "c") | |
2360 (forward-char 1) | |
2361 t) | |
2362 (t nil)))) | |
2363 | |
2364 (defun vip-default-ex-addresses (&optional whole-flag) | |
2365 "compute default addresses. whole-flag means whole buffer." | |
2366 (cond ((null ex-addresses) | |
2367 (setq ex-addresses | |
2368 (if whole-flag | |
2369 (cons (point-max) (cons (point-min) nil)) | |
2370 (cons (point) (cons (point) nil))))) | |
2371 ((null (cdr ex-addresses)) | |
2372 (setq ex-addresses | |
2373 (cons (car ex-addresses) ex-addresses))))) | |
2374 | |
2375 (defun vip-get-ex-address () | |
2376 "get an ex-address as a marker and set ex-flag if a flag is found" | |
2377 (let ((address (point-marker)) (cont t)) | |
2378 (setq ex-token "") | |
2379 (setq ex-flag nil) | |
2380 (while cont | |
2381 (vip-get-ex-token) | |
2382 (cond ((string= ex-token-type "command") | |
2383 (if (or (string= ex-token "print") (string= ex-token "list") | |
2384 (string= ex-token "#")) | |
2385 (progn | |
2386 (setq ex-flag t) | |
2387 (setq cont nil)) | |
2388 (error "address expected"))) | |
2389 ((string= ex-token-type "end-mark") | |
2390 (setq cont nil)) | |
2391 ((string= ex-token-type "whole") | |
2392 (error "a trailing address is expected")) | |
2393 ((string= ex-token-type "comma") | |
2394 (error "Extra characters after an address")) | |
2395 (t (let ((ans (vip-get-ex-address-subr address (point-marker)))) | |
2396 (if ans (setq address ans)))))) | |
2397 address)) | |
2398 | |
2399 (defun vip-get-ex-address-subr (old-address dot) | |
2400 "returns an address as a point" | |
2401 (let ((address nil)) | |
2402 (if (null old-address) (setq old-address dot)) | |
2403 (cond ((string= ex-token-type "dot") | |
2404 (setq address dot)) | |
2405 ((string= ex-token-type "add-number") | |
2406 (save-excursion | |
2407 (goto-char old-address) | |
2408 (forward-line (if (= old-address 0) (1- ex-token) ex-token)) | |
2409 (setq address (point-marker)))) | |
2410 ((string= ex-token-type "sub-number") | |
2411 (save-excursion | |
2412 (goto-char old-address) | |
2413 (forward-line (- ex-token)) | |
2414 (setq address (point-marker)))) | |
2415 ((string= ex-token-type "abs-number") | |
2416 (save-excursion | |
2417 (goto-char (point-min)) | |
2418 (if (= ex-token 0) (setq address 0) | |
2419 (forward-line (1- ex-token)) | |
2420 (setq address (point-marker))))) | |
2421 ((string= ex-token-type "end") | |
2422 (setq address (point-max-marker))) | |
2423 ((string= ex-token-type "plus") t);; do nothing | |
2424 ((string= ex-token-type "minus") t);; do nothing | |
2425 ((string= ex-token-type "search-forward") | |
2426 (save-excursion | |
2427 (ex-search-address t) | |
2428 (setq address (point-marker)))) | |
2429 ((string= ex-token-type "search-backward") | |
2430 (save-excursion | |
2431 (ex-search-address nil) | |
2432 (setq address (point-marker)))) | |
2433 ((string= ex-token-type "goto-mark") | |
2434 (save-excursion | |
2435 (if (null ex-token) | |
2436 (exchange-point-and-mark) | |
2437 (goto-char (register-to-point (- ex-token (- ?a ?\C-a))))) | |
2438 (setq address (point-marker))))) | |
2439 address)) | |
2440 | |
2441 (defun ex-search-address (forward) | |
2442 "search pattern and set address" | |
2443 (if (string= ex-token "") | |
2444 (if (null vip-s-string) (error "No previous search string") | |
2445 (setq ex-token vip-s-string)) | |
2446 (setq vip-s-string ex-token)) | |
2447 (if forward | |
2448 (progn | |
2449 (forward-line 1) | |
2450 (re-search-forward ex-token)) | |
2451 (forward-line -1) | |
2452 (re-search-backward ex-token))) | |
2453 | |
2454 (defun vip-get-ex-buffer () | |
2455 "get a buffer name and set ex-count and ex-flag if found" | |
2456 (setq ex-buffer nil) | |
2457 (setq ex-count nil) | |
2458 (setq ex-flag nil) | |
2459 (save-window-excursion | |
2460 (set-buffer " *ex-working-space*") | |
2461 (skip-chars-forward " \t") | |
2462 (if (looking-at "[a-zA-Z]") | |
2463 (progn | |
2464 (setq ex-buffer (following-char)) | |
2465 (forward-char 1) | |
2466 (skip-chars-forward " \t"))) | |
2467 (if (looking-at "[0-9]") | |
2468 (progn | |
2469 (set-mark (point)) | |
2470 (re-search-forward "[0-9][0-9]*") | |
2471 (setq ex-count (string-to-int (buffer-substring (point) (mark)))) | |
2472 (skip-chars-forward " \t"))) | |
2473 (if (looking-at "[pl#]") | |
2474 (progn | |
2475 (setq ex-flag t) | |
2476 (forward-char 1))) | |
2477 (if (not (looking-at "[\n|]")) | |
2478 (error "Illegal extra characters")))) | |
2479 | |
2480 (defun vip-get-ex-count () | |
2481 (setq ex-variant nil | |
2482 ex-count nil | |
2483 ex-flag nil) | |
2484 (save-window-excursion | |
2485 (set-buffer " *ex-working-space*") | |
2486 (skip-chars-forward " \t") | |
2487 (if (looking-at "!") | |
2488 (progn | |
2489 (setq ex-variant t) | |
2490 (forward-char 1))) | |
2491 (skip-chars-forward " \t") | |
2492 (if (looking-at "[0-9]") | |
2493 (progn | |
2494 (set-mark (point)) | |
2495 (re-search-forward "[0-9][0-9]*") | |
2496 (setq ex-count (string-to-int (buffer-substring (point) (mark)))) | |
2497 (skip-chars-forward " \t"))) | |
2498 (if (looking-at "[pl#]") | |
2499 (progn | |
2500 (setq ex-flag t) | |
2501 (forward-char 1))) | |
2502 (if (not (looking-at "[\n|]")) | |
2503 (error "Illegal extra characters")))) | |
2504 | |
2505 (defun vip-get-ex-file () | |
2506 "get a file name and set ex-variant, ex-append and ex-offset if found" | |
2507 (setq ex-file nil | |
2508 ex-variant nil | |
2509 ex-append nil | |
2510 ex-offset nil) | |
2511 (save-window-excursion | |
2512 (set-buffer " *ex-working-space*") | |
2513 (skip-chars-forward " \t") | |
2514 (if (looking-at "!") | |
2515 (progn | |
2516 (setq ex-variant t) | |
2517 (forward-char 1) | |
2518 (skip-chars-forward " \t"))) | |
2519 (if (looking-at ">>") | |
2520 (progn | |
2521 (setq ex-append t | |
2522 ex-variant t) | |
2523 (forward-char 2) | |
2524 (skip-chars-forward " \t"))) | |
2525 (if (looking-at "+") | |
2526 (progn | |
2527 (forward-char 1) | |
2528 (set-mark (point)) | |
2529 (re-search-forward "[ \t\n]") | |
2530 (backward-char 1) | |
2531 (setq ex-offset (buffer-substring (point) (mark))) | |
2532 (forward-char 1) | |
2533 (skip-chars-forward " \t"))) | |
2534 (set-mark (point)) | |
2535 (re-search-forward "[ \t\n]") | |
2536 (backward-char 1) | |
2537 (setq ex-file (buffer-substring (point) (mark))))) | |
2538 | |
2539 (defun vip-execute-ex-command () | |
2540 "execute ex command using the value of addresses." | |
2541 (cond ((string= ex-token "goto") (ex-goto)) | |
2542 ((string= ex-token "copy") (ex-copy nil)) | |
2543 ((string= ex-token "delete") (ex-delete)) | |
2544 ((string= ex-token "edit") (ex-edit)) | |
2545 ((string= ex-token "file") (vip-info-on-file)) | |
2546 ;((string= ex-token "global") (ex-global nil)) | |
2547 ((string= ex-token "join") (ex-line "join")) | |
2548 ((string= ex-token "k") (ex-mark)) | |
2549 ((string= ex-token "mark") (ex-mark)) | |
2550 ((string= ex-token "map") (ex-map)) | |
2551 ((string= ex-token "move") (ex-copy t)) | |
2552 ((string= ex-token "put") (ex-put)) | |
2553 ((string= ex-token "quit") (ex-quit)) | |
2554 ((string= ex-token "read") (ex-read)) | |
2555 ((string= ex-token "set") (ex-set)) | |
2556 ((string= ex-token "shell") (ex-shell)) | |
2557 ((string= ex-token "substitute") (ex-substitute)) | |
2558 ((string= ex-token "stop") (suspend-emacs)) | |
2559 ((string= ex-token "t") (ex-copy nil)) | |
2560 ((string= ex-token "tag") (ex-tag)) | |
2561 ((string= ex-token "undo") (vip-undo)) | |
2562 ((string= ex-token "unmap") (ex-unmap)) | |
2563 ;((string= ex-token "v") (ex-global t)) | |
2564 ((string= ex-token "version") (vip-version)) | |
2565 ((string= ex-token "visual") (ex-edit)) | |
2566 ((string= ex-token "write") (ex-write nil)) | |
2567 ((string= ex-token "wq") (ex-write t)) | |
2568 ((string= ex-token "yank") (ex-yank)) | |
2569 ((string= ex-token "!") (ex-command)) | |
2570 ((string= ex-token "=") (ex-line-no)) | |
2571 ((string= ex-token ">") (ex-line "right")) | |
2572 ((string= ex-token "<") (ex-line "left")) | |
2573 ((string= ex-token "&") (ex-substitute t)) | |
2574 ((string= ex-token "~") (ex-substitute t t)) | |
2575 ((or (string= ex-token "append") | |
2576 (string= ex-token "args") | |
2577 (string= ex-token "change") | |
2578 (string= ex-token "insert") | |
2579 (string= ex-token "open") | |
2580 ) | |
14431
d1b9ec5dc9fc
(vip-execute-ex-command, ex-write): Fix error format string.
Karl Heuer <kwzh@gnu.org>
parents:
14345
diff
changeset
|
2581 (error "%s: no such command from VIP" ex-token)) |
11 | 2582 ((or (string= ex-token "abbreviate") |
2583 (string= ex-token "list") | |
2584 (string= ex-token "next") | |
2585 (string= ex-token "print") | |
2586 (string= ex-token "preserve") | |
2587 (string= ex-token "recover") | |
2588 (string= ex-token "rewind") | |
2589 (string= ex-token "source") | |
2590 (string= ex-token "unabbreviate") | |
2591 (string= ex-token "xit") | |
2592 (string= ex-token "z") | |
2593 ) | |
14431
d1b9ec5dc9fc
(vip-execute-ex-command, ex-write): Fix error format string.
Karl Heuer <kwzh@gnu.org>
parents:
14345
diff
changeset
|
2594 (error "%s: not implemented in VIP" ex-token)) |
d1b9ec5dc9fc
(vip-execute-ex-command, ex-write): Fix error format string.
Karl Heuer <kwzh@gnu.org>
parents:
14345
diff
changeset
|
2595 (t (error "%s: Not an editor command" ex-token)))) |
11 | 2596 |
2597 (defun ex-goto () | |
2598 "ex goto command" | |
2599 (if (null ex-addresses) | |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
2600 (setq ex-addresses (cons (point) nil))) |
11 | 2601 (push-mark (point)) |
2602 (goto-char (car ex-addresses)) | |
2603 (beginning-of-line)) | |
2604 | |
2605 (defun ex-copy (del-flag) | |
2606 "ex copy and move command. DEL-FLAG means delete." | |
2607 (vip-default-ex-addresses) | |
2608 (let ((address (vip-get-ex-address)) | |
2609 (end (car ex-addresses)) (beg (car (cdr ex-addresses)))) | |
2610 (goto-char end) | |
2611 (save-excursion | |
2612 (set-mark beg) | |
2613 (vip-enlarge-region (mark) (point)) | |
2614 (if del-flag (kill-region (point) (mark)) | |
2615 (copy-region-as-kill (point) (mark))) | |
2616 (if ex-flag | |
2617 (progn | |
2618 (with-output-to-temp-buffer "*copy text*" | |
2619 (princ | |
2620 (if (or del-flag ex-g-flag ex-g-variant) | |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
2621 (current-kill 0) |
11 | 2622 (buffer-substring (point) (mark))))) |
2623 (condition-case nil | |
2624 (progn | |
2625 (vip-read-string "[Hit return to continue] ") | |
2626 (save-excursion (kill-buffer "*copy text*"))) | |
2627 (quit | |
2628 (save-excursion (kill-buffer "*copy text*")) | |
2629 (signal 'quit nil)))))) | |
2630 (if (= address 0) | |
2631 (goto-char (point-min)) | |
2632 (goto-char address) | |
2633 (forward-line 1)) | |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
2634 (insert (current-kill 0)))) |
11 | 2635 |
2636 (defun ex-delete () | |
2637 "ex delete" | |
2638 (vip-default-ex-addresses) | |
2639 (vip-get-ex-buffer) | |
2640 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses)))) | |
2641 (if (> beg end) (error "First address exceeds second")) | |
2642 (save-excursion | |
2643 (vip-enlarge-region beg end) | |
2644 (exchange-point-and-mark) | |
2645 (if ex-count | |
2646 (progn | |
2647 (set-mark (point)) | |
2648 (forward-line (1- ex-count))) | |
2649 (set-mark end)) | |
2650 (vip-enlarge-region (point) (mark)) | |
2651 (if ex-flag | |
2652 ;; show text to be deleted and ask for confirmation | |
2653 (progn | |
2654 (with-output-to-temp-buffer " *delete text*" | |
2655 (princ (buffer-substring (point) (mark)))) | |
2656 (condition-case conditions | |
2657 (vip-read-string "[Hit return to continue] ") | |
2658 (quit | |
2659 (save-excursion (kill-buffer " *delete text*")) | |
2660 (error ""))) | |
2661 (save-excursion (kill-buffer " *delete text*"))) | |
2662 (if ex-buffer | |
2663 (if (and (<= ?A ex-buffer) (<= ex-buffer ?Z)) | |
2664 (vip-append-to-register | |
1625
376427dea90a
* bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents:
1577
diff
changeset
|
2665 (+ ex-buffer 32) (point) (mark)) |
11 | 2666 (copy-to-register ex-buffer (point) (mark) nil))) |
2667 (delete-region (point) (mark)))))) | |
2668 | |
2669 (defun ex-edit () | |
2670 "ex-edit" | |
2671 (vip-get-ex-file) | |
2672 (if (and (not ex-variant) (buffer-modified-p) buffer-file-name) | |
2673 (error "No write since last change \(:e! overrides\)")) | |
2674 (vip-change-mode-to-emacs) | |
2675 (set-buffer | |
2676 (find-file-noselect (concat default-directory ex-file))) | |
2677 (vip-change-mode-to-vi) | |
2678 (goto-char (point-min)) | |
2679 (if ex-offset | |
2680 (progn | |
2681 (save-window-excursion | |
2682 (set-buffer " *ex-working-space*") | |
2683 (delete-region (point-min) (point-max)) | |
2684 (insert ex-offset "\n") | |
2685 (goto-char (point-min))) | |
2686 (goto-char (vip-get-ex-address)) | |
2687 (beginning-of-line)))) | |
2688 | |
2689 (defun ex-global (variant) | |
2690 "ex global command" | |
2691 (if (or ex-g-flag ex-g-variant) | |
2692 (error "Global within global not allowed") | |
2693 (if variant | |
2694 (setq ex-g-flag nil | |
2695 ex-g-variant t) | |
2696 (setq ex-g-flag t | |
2697 ex-g-variant nil))) | |
2698 (vip-get-ex-pat) | |
2699 (if (null ex-token) | |
2700 (error "Missing regular expression for global command")) | |
2701 (if (string= ex-token "") | |
2702 (if (null vip-s-string) (error "No previous search string") | |
2703 (setq ex-g-pat vip-s-string)) | |
2704 (setq ex-g-pat ex-token | |
2705 vip-s-string ex-token)) | |
2706 (if (null ex-addresses) | |
2707 (setq ex-addresses (list (point-max) (point-min)))) | |
2708 (let ((marks nil) (mark-count 0) | |
2709 com-str (end (car ex-addresses)) (beg (car (cdr ex-addresses)))) | |
2710 (if (> beg end) (error "First address exceeds second")) | |
2711 (save-excursion | |
2712 (vip-enlarge-region beg end) | |
2713 (exchange-point-and-mark) | |
2714 (let ((cont t) (limit (point-marker))) | |
2715 (exchange-point-and-mark) | |
2716 ;; skip the last line if empty | |
2717 (beginning-of-line) | |
2718 (if (and (eobp) (not (bobp))) (backward-char 1)) | |
2719 (while (and cont (not (bobp)) (>= (point) limit)) | |
2720 (beginning-of-line) | |
2721 (set-mark (point)) | |
2722 (end-of-line) | |
2723 (let ((found (re-search-backward ex-g-pat (mark) t))) | |
2724 (if (or (and ex-g-flag found) | |
2725 (and ex-g-variant (not found))) | |
2726 (progn | |
2727 (end-of-line) | |
2728 (setq mark-count (1+ mark-count)) | |
2729 (setq marks (cons (point-marker) marks))))) | |
2730 (beginning-of-line) | |
2731 (if (bobp) (setq cont nil) | |
2732 (forward-line -1) | |
2733 (end-of-line))))) | |
2734 (save-window-excursion | |
2735 (set-buffer " *ex-working-space*") | |
2736 (setq com-str (buffer-substring (1+ (point)) (1- (point-max))))) | |
2737 (while marks | |
2738 (goto-char (car marks)) | |
2739 ; report progress of execution on a slow machine. | |
2740 ;(message "Executing global command...") | |
2741 ;(if (zerop (% mark-count 10)) | |
2742 ;(message "Executing global command...%d" mark-count)) | |
2743 (vip-ex com-str) | |
2744 (setq mark-count (1- mark-count)) | |
2745 (setq marks (cdr marks))))) | |
2746 ;(message "Executing global command...done"))) | |
2747 | |
2748 (defun ex-line (com) | |
2749 "ex line commands. COM is join, shift-right or shift-left." | |
2750 (vip-default-ex-addresses) | |
2751 (vip-get-ex-count) | |
2752 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))) point) | |
2753 (if (> beg end) (error "First address exceeds second")) | |
2754 (save-excursion | |
2755 (vip-enlarge-region beg end) | |
2756 (exchange-point-and-mark) | |
2757 (if ex-count | |
2758 (progn | |
2759 (set-mark (point)) | |
2760 (forward-line ex-count))) | |
2761 (if ex-flag | |
2762 ;; show text to be joined and ask for confirmation | |
2763 (progn | |
2764 (with-output-to-temp-buffer " *text*" | |
2765 (princ (buffer-substring (point) (mark)))) | |
2766 (condition-case conditions | |
2767 (progn | |
2768 (vip-read-string "[Hit return to continue] ") | |
2769 (ex-line-subr com (point) (mark))) | |
2770 (quit | |
2771 (ding))) | |
2772 (save-excursion (kill-buffer " *text*"))) | |
2773 (ex-line-subr com (point) (mark))) | |
2774 (setq point (point))) | |
2775 (goto-char (1- point)) | |
2776 (beginning-of-line))) | |
2777 | |
2778 (defun ex-line-subr (com beg end) | |
2779 (cond ((string= com "join") | |
2780 (goto-char (min beg end)) | |
2781 (while (and (not (eobp)) (< (point) (max beg end))) | |
2782 (end-of-line) | |
2783 (if (and (<= (point) (max beg end)) (not (eobp))) | |
2784 (progn | |
2785 (forward-line 1) | |
2786 (delete-region (point) (1- (point))) | |
2787 (if (not ex-variant) (fixup-whitespace)))))) | |
2788 ((or (string= com "right") (string= com "left")) | |
2789 (indent-rigidly | |
2790 (min beg end) (max beg end) | |
2791 (if (string= com "right") vip-shift-width (- vip-shift-width))) | |
2792 (goto-char (max beg end)) | |
2793 (end-of-line) | |
2794 (forward-char 1)))) | |
2795 | |
2796 (defun ex-mark () | |
2797 "ex mark" | |
2798 (let (char) | |
2799 (if (null ex-addresses) | |
2800 (setq ex-addresses | |
2801 (cons (point) nil))) | |
2802 (save-window-excursion | |
2803 (set-buffer " *ex-working-space*") | |
2804 (skip-chars-forward " \t") | |
2805 (if (looking-at "[a-z]") | |
2806 (progn | |
2807 (setq char (following-char)) | |
2808 (forward-char 1) | |
2809 (skip-chars-forward " \t") | |
2810 (if (not (looking-at "[\n|]")) | |
2811 (error "Extra characters at end of \"k\" command"))) | |
2812 (if (looking-at "[\n|]") | |
2813 (error "\"k\" requires a following letter") | |
2814 (error "Mark must specify a letter")))) | |
2815 (save-excursion | |
2816 (goto-char (car ex-addresses)) | |
1625
376427dea90a
* bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents:
1577
diff
changeset
|
2817 (point-to-register (- char (- ?a ?\C-a)) nil)))) |
11 | 2818 |
2819 (defun ex-map () | |
2820 "ex map" | |
2821 (let (char string) | |
2822 (save-window-excursion | |
2823 (set-buffer " *ex-working-space*") | |
2824 (skip-chars-forward " \t") | |
2825 (setq char (char-to-string (following-char))) | |
2826 (forward-char 1) | |
2827 (skip-chars-forward " \t") | |
2828 (if (looking-at "[\n|]") (error "Missing rhs")) | |
2829 (set-mark (point)) | |
2830 (end-of-buffer) | |
2831 (backward-char 1) | |
2832 (setq string (buffer-substring (mark) (point)))) | |
2833 (if (not (lookup-key ex-map char)) | |
2834 (define-key ex-map char | |
2835 (or (lookup-key vip-mode-map char) 'vip-nil))) | |
2836 (define-key vip-mode-map char | |
2837 (eval | |
2838 (list 'quote | |
2839 (cons 'lambda | |
2840 (list '(count) | |
2841 '(interactive "p") | |
2842 (list 'execute-kbd-macro string 'count)))))))) | |
2843 | |
2844 (defun ex-unmap () | |
2845 "ex unmap" | |
2846 (let (char) | |
2847 (save-window-excursion | |
2848 (set-buffer " *ex-working-space*") | |
2849 (skip-chars-forward " \t") | |
2850 (setq char (char-to-string (following-char))) | |
2851 (forward-char 1) | |
2852 (skip-chars-forward " \t") | |
2853 (if (not (looking-at "[\n|]")) (error "Macro must be a character"))) | |
2854 (if (not (lookup-key ex-map char)) | |
2855 (error "That macro wasn't mapped")) | |
2856 (define-key vip-mode-map char (lookup-key ex-map char)) | |
2857 (define-key ex-map char nil))) | |
2858 | |
2859 (defun ex-put () | |
2860 "ex put" | |
2861 (let ((point (if (null ex-addresses) (point) (car ex-addresses)))) | |
2862 (vip-get-ex-buffer) | |
2863 (setq vip-use-register ex-buffer) | |
2864 (goto-char point) | |
2865 (if (= point 0) (vip-Put-back 1) (vip-put-back 1)))) | |
2866 | |
2867 (defun ex-quit () | |
2868 "ex quit" | |
2869 (let (char) | |
2870 (save-window-excursion | |
2871 (set-buffer " *ex-working-space*") | |
2872 (skip-chars-forward " \t") | |
2873 (setq char (following-char))) | |
2874 (if (= char ?!) (kill-emacs t) (save-buffers-kill-emacs)))) | |
2875 | |
2876 (defun ex-read () | |
2877 "ex read" | |
2878 (let ((point (if (null ex-addresses) (point) (car ex-addresses))) | |
2879 (variant nil) command file) | |
2880 (goto-char point) | |
2881 (if (not (= point 0)) (next-line 1)) | |
2882 (beginning-of-line) | |
2883 (save-window-excursion | |
2884 (set-buffer " *ex-working-space*") | |
2885 (skip-chars-forward " \t") | |
2886 (if (looking-at "!") | |
2887 (progn | |
2888 (setq variant t) | |
2889 (forward-char 1) | |
2890 (skip-chars-forward " \t") | |
2891 (set-mark (point)) | |
2892 (end-of-line) | |
2893 (setq command (buffer-substring (mark) (point)))) | |
2894 (set-mark (point)) | |
2895 (re-search-forward "[ \t\n]") | |
2896 (backward-char 1) | |
2897 (setq file (buffer-substring (point) (mark))))) | |
2898 (if variant | |
2899 (shell-command command t) | |
2900 (insert-file file)))) | |
2901 | |
2902 (defun ex-set () | |
2903 (eval (list 'setq | |
2904 (read-variable "Variable: ") | |
2905 (eval (read-minibuffer "Value: "))))) | |
2906 | |
2907 (defun ex-shell () | |
2908 "ex shell" | |
2909 (vip-change-mode-to-emacs) | |
2910 (shell)) | |
2911 | |
2912 (defun ex-substitute (&optional repeat r-flag) | |
1577 | 2913 "ex substitute. |
2914 If REPEAT use previous reg-exp which is ex-reg-exp or | |
11 | 2915 vip-s-string" |
2916 (let (pat repl (opt-g nil) (opt-c nil) (matched-pos nil)) | |
2917 (if repeat (setq ex-token nil) (vip-get-ex-pat)) | |
2918 (if (null ex-token) | |
2919 (setq pat (if r-flag vip-s-string ex-reg-exp) | |
2920 repl ex-repl) | |
2921 (setq pat (if (string= ex-token "") vip-s-string ex-token)) | |
2922 (setq vip-s-string pat | |
2923 ex-reg-exp pat) | |
2924 (vip-get-ex-pat) | |
2925 (if (null ex-token) | |
2926 (setq ex-token "" | |
2927 ex-repl "") | |
2928 (setq repl ex-token | |
2929 ex-repl ex-token))) | |
2930 (while (vip-get-ex-opt-gc) | |
2931 (if (string= ex-token "g") (setq opt-g t) (setq opt-c t))) | |
2932 (vip-get-ex-count) | |
2933 (if ex-count | |
2934 (save-excursion | |
2935 (if ex-addresses (goto-char (car ex-addresses))) | |
2936 (set-mark (point)) | |
2937 (forward-line (1- ex-count)) | |
2938 (setq ex-addresses (cons (point) (cons (mark) nil)))) | |
2939 (if (null ex-addresses) | |
2940 (setq ex-addresses (cons (point) (cons (point) nil))) | |
2941 (if (null (cdr ex-addresses)) | |
2942 (setq ex-addresses (cons (car ex-addresses) ex-addresses))))) | |
2943 ;(setq G opt-g) | |
2944 (let ((beg (car ex-addresses)) (end (car (cdr ex-addresses))) | |
2945 (cont t) eol-mark) | |
2946 (save-excursion | |
2947 (vip-enlarge-region beg end) | |
2948 (let ((limit (save-excursion | |
2949 (goto-char (max (point) (mark))) | |
2950 (point-marker)))) | |
2951 (goto-char (min (point) (mark))) | |
2952 (while (< (point) limit) | |
2953 (end-of-line) | |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
2954 (setq eol-mark (point-marker)) |
11 | 2955 (beginning-of-line) |
2956 (if opt-g | |
2957 (progn | |
2958 (while (and (not (eolp)) | |
2959 (re-search-forward pat eol-mark t)) | |
2960 (if (or (not opt-c) (y-or-n-p "Replace? ")) | |
2961 (progn | |
2962 (setq matched-pos (point)) | |
2963 (replace-match repl)))) | |
2964 (end-of-line) | |
2965 (forward-char)) | |
2966 (if (and (re-search-forward pat eol-mark t) | |
2967 (or (not opt-c) (y-or-n-p "Replace? "))) | |
2968 (progn | |
2969 (setq matched-pos (point)) | |
2970 (replace-match repl))) | |
2971 (end-of-line) | |
2972 (forward-char)))))) | |
2973 (if matched-pos (goto-char matched-pos)) | |
2974 (beginning-of-line) | |
2975 (if opt-c (message "done")))) | |
2976 | |
2977 (defun ex-tag () | |
2978 "ex tag" | |
2979 (let (tag) | |
2980 (save-window-excursion | |
2981 (set-buffer " *ex-working-space*") | |
2982 (skip-chars-forward " \t") | |
2983 (set-mark (point)) | |
2984 (skip-chars-forward "^ |\t\n") | |
2985 (setq tag (buffer-substring (mark) (point)))) | |
2986 (if (not (string= tag "")) (setq ex-tag tag)) | |
2987 (vip-change-mode-to-emacs) | |
2988 (condition-case conditions | |
2989 (progn | |
2990 (if (string= tag "") | |
2991 (find-tag ex-tag t) | |
2992 (find-tag-other-window ex-tag)) | |
2993 (vip-change-mode-to-vi)) | |
2994 (error | |
2995 (vip-change-mode-to-vi) | |
2996 (vip-message-conditions conditions))))) | |
2997 | |
2998 (defun ex-write (q-flag) | |
2999 "ex write" | |
3000 (vip-default-ex-addresses t) | |
3001 (vip-get-ex-file) | |
3002 (if (string= ex-file "") | |
3003 (progn | |
3004 (if (null buffer-file-name) | |
3005 (error "No file associated with this buffer")) | |
3006 (setq ex-file buffer-file-name)) | |
3007 (setq ex-file (expand-file-name ex-file))) | |
3008 (if (and (not (string= ex-file (buffer-file-name))) | |
3009 (file-exists-p ex-file) | |
3010 (not ex-variant)) | |
14431
d1b9ec5dc9fc
(vip-execute-ex-command, ex-write): Fix error format string.
Karl Heuer <kwzh@gnu.org>
parents:
14345
diff
changeset
|
3011 (error "\"%s\" File exists - use w! to override" ex-file)) |
11 | 3012 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses)))) |
3013 (if (> beg end) (error "First address exceeds second")) | |
3014 (save-excursion | |
3015 (vip-enlarge-region beg end) | |
3016 (write-region (point) (mark) ex-file ex-append t))) | |
3017 (if (null buffer-file-name) (setq buffer-file-name ex-file)) | |
3018 (if q-flag (save-buffers-kill-emacs))) | |
3019 | |
3020 (defun ex-yank () | |
3021 "ex yank" | |
3022 (vip-default-ex-addresses) | |
3023 (vip-get-ex-buffer) | |
3024 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses)))) | |
3025 (if (> beg end) (error "First address exceeds second")) | |
3026 (save-excursion | |
3027 (vip-enlarge-region beg end) | |
3028 (exchange-point-and-mark) | |
3029 (if (or ex-g-flag ex-g-variant) (error "Can't yank within global")) | |
3030 (if ex-count | |
3031 (progn | |
3032 (set-mark (point)) | |
3033 (forward-line (1- ex-count))) | |
3034 (set-mark end)) | |
3035 (vip-enlarge-region (point) (mark)) | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3519
diff
changeset
|
3036 (if ex-flag (error "Extra characters at end of command")) |
11 | 3037 (if ex-buffer |
3038 (copy-to-register ex-buffer (point) (mark) nil)) | |
3039 (copy-region-as-kill (point) (mark))))) | |
3040 | |
3041 (defun ex-command () | |
3042 "execute shell command" | |
3043 (let (command) | |
3044 (save-window-excursion | |
3045 (set-buffer " *ex-working-space*") | |
3046 (skip-chars-forward " \t") | |
3047 (set-mark (point)) | |
3048 (end-of-line) | |
3049 (setq command (buffer-substring (mark) (point)))) | |
3050 (if (null ex-addresses) | |
3051 (shell-command command) | |
3052 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses)))) | |
3053 (if (null beg) (setq beg end)) | |
3054 (save-excursion | |
3055 (goto-char beg) | |
3056 (set-mark end) | |
3057 (vip-enlarge-region (point) (mark)) | |
3058 (shell-command-on-region (point) (mark) command t)) | |
3059 (goto-char beg))))) | |
3060 | |
3061 (defun ex-line-no () | |
3062 "print line number" | |
3063 (message "%d" | |
3064 (1+ (count-lines | |
3065 (point-min) | |
3066 (if (null ex-addresses) (point-max) (car ex-addresses)))))) | |
3067 | |
13907
c4f965637f22
(vip-startup-file): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12358
diff
changeset
|
3068 (if (file-exists-p vip-startup-file) (load vip-startup-file)) |
11 | 3069 |
18383 | 3070 (provide 'vip) |
3071 | |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
3072 ;;; vip.el ends here |