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