annotate lisp/emulation/vip.el @ 50730:593e537d5449

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