annotate lisp/emulation/vi.el @ 67004:5a972cf172a7

(ls-lisp-format-file-size): Format file size with 9 digits, not 8, to avoid misalignment for files larger than 100MB.
author Eli Zaretskii <eliz@gnu.org>
date Sat, 19 Nov 2005 11:38:23 +0000
parents c9581f50bd50
children 17d458291533 f9a65d7ebd29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38431
853c3674f20a Fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 18383
diff changeset
1 ;;; vi.el --- major mode for emulating "vi" editor under GNU Emacs
657
fec3f9a1e3e5 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
2
60902
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
3 ;; This file is in the public domain because the authors distributed it
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
4 ;; without a copyright notice before the US signed the Bern Convention.
11184
6878430e42fa Explain why public domain.
Richard M. Stallman <rms@gnu.org>
parents: 9865
diff changeset
5
38431
853c3674f20a Fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 18383
diff changeset
6 ;; This file is part of GNU Emacs.
853c3674f20a Fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 18383
diff changeset
7
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 707
diff changeset
8 ;; Author: Neal Ziring <nz@rsch.wisc.edu>
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 707
diff changeset
9 ;; Felix S. T. Wu <wu@crys.wisc.edu>
812
485e82a8acb5 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 789
diff changeset
10 ;; Keywords: emulations
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 707
diff changeset
11
38431
853c3674f20a Fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 18383
diff changeset
12 ;;; Commentary:
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 707
diff changeset
13
60902
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
14 ;; Originally written by : seismo!wucs!nz@rsch.wisc.edu (Neal Ziring)
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
15 ;; Extensively redesigned and rewritten by wu@crys.wisc.edu (Felix S.T. Wu)
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
16 ;; Last revision: 01/07/87 Wed (for GNU Emacs 18.33)
11184
6878430e42fa Explain why public domain.
Richard M. Stallman <rms@gnu.org>
parents: 9865
diff changeset
17
60902
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
18 ;; INSTALLATION PROCEDURE:
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
19 ;; 1) Add a global key binding for command "vi-mode" (I use ESC ESC instead of
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
20 ;; the single ESC used in real "vi", so I can access other ESC prefixed emacs
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
21 ;; commands while I'm in "vi"), say, by putting the following line in your
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
22 ;; ".emacs" file:
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
23 ;; (define-key global-map "\e\e" 'vi-mode) ;quick switch into vi-mode
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
24 ;; 2) If you wish you can define "find-file-hook" to enter "vi" automatically
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
25 ;; after a file is loaded into the buffer. For example, I defined it as:
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
26 ;; (setq find-file-hook (list
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
27 ;; (function (lambda ()
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
28 ;; (if (not (or (eq major-mode 'Info-mode)
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
29 ;; (eq major-mode 'vi-mode)))
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
30 ;; (vi-mode))))))
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
31 ;; 3) In your .emacs file you can define the command "vi-mode" to be "autoload"
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
32 ;; or you can execute the "load" command to load "vi" directly.
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
33 ;; 4) Read the comments for command "vi-mode" before you start using it.
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
34
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
35 ;; COULD DO
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
36 ;; 1). A general 'define-operator' function to replace current hack
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
37 ;; 2). In operator handling, should allow other point moving Emacs commands
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
38 ;; (such as ESC <, ESC >) to be used as arguments.
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
39
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 707
diff changeset
40 ;;; Code:
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41
17979
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
42 (defvar vi-mode-old-major-mode)
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
43 (defvar vi-mode-old-mode-name)
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
44 (defvar vi-mode-old-local-map)
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
45 (defvar vi-mode-old-case-fold)
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 (if (null (where-is-internal 'vi-switch-mode (current-local-map)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 (define-key ctl-x-map "~" 'vi-switch-mode))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (defvar vi-tilde-map nil
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 "Keymap used for \\[vi-switch-mode] prefix key. Link to various major modes.")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (if vi-tilde-map
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 nil
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 (setq vi-tilde-map (make-keymap))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 (define-key vi-tilde-map "a" 'abbrev-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (define-key vi-tilde-map "c" 'c-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (define-key vi-tilde-map "d" 'vi-debugging)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (define-key vi-tilde-map "e" 'emacs-lisp-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (define-key vi-tilde-map "f" 'auto-fill-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (define-key vi-tilde-map "g" 'prolog-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (define-key vi-tilde-map "h" 'hanoi)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (define-key vi-tilde-map "i" 'info-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (define-key vi-tilde-map "l" 'lisp-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (define-key vi-tilde-map "n" 'nroff-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (define-key vi-tilde-map "o" 'overwrite-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (define-key vi-tilde-map "O" 'outline-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (define-key vi-tilde-map "P" 'picture-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 (define-key vi-tilde-map "r" 'vi-readonly-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (define-key vi-tilde-map "t" 'text-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (define-key vi-tilde-map "v" 'vi-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (define-key vi-tilde-map "x" 'tex-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (define-key vi-tilde-map "~" 'vi-back-to-old-mode))
17979
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
74
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
75 (defun vi-switch-mode (arg mode-char)
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
76 "Switch the major mode of current buffer as specified by the following char \\{vi-tilde-map}"
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
77 (interactive "P\nc")
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
78 (let ((mode-cmd (lookup-key vi-tilde-map (char-to-string mode-char))))
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
79 (if (null mode-cmd)
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
80 (with-output-to-temp-buffer "*Help*"
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
81 (princ (substitute-command-keys "Possible major modes to switch to: \\{vi-tilde-map}"))
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
82 (save-excursion
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
83 (set-buffer standard-output)
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
84 (help-mode)))
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
85 (setq prefix-arg arg) ; prefix arg will be passed down
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
86 (command-execute mode-cmd nil) ; may need to save mode-line-format etc
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
87 (force-mode-line-update)))) ; just in case
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88
17979
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
89
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 (defun vi-debugging (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 "Toggle debug-on-error flag. If prefix arg is given, set t."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 (interactive "P")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 (if arg
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 (setq debug-on-error t)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (setq debug-on-error (not debug-on-error)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (if debug-on-error
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (message "Debug-on-error ...")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (message "NO more debug-on-error")))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 (defun vi-back-to-old-mode ()
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 "Go back to the previous mode without setting up for insertion."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (interactive)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (if vi-mode-old-major-mode
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (progn
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (setq mode-name vi-mode-old-mode-name)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 (use-local-map vi-mode-old-local-map)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (setq major-mode vi-mode-old-major-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (setq case-fold-search vi-mode-old-case-fold)
11567
bcf841745ef2 (vi-switch-mode, vi-back-to-old-mode): Use force-mode-line-update.
Karl Heuer <kwzh@gnu.org>
parents: 11184
diff changeset
109 (force-mode-line-update))))
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (defun vi-readonly-mode ()
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 "Toggle current buffer's readonly flag."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (interactive)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (setq buffer-read-only (not buffer-read-only)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (defvar vi-com-map nil
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 "Keymap used in Evi's command state
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 Command state includes most of the vi editing commands, with some Emacs
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 command extensions.")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (put 'vi-undefined 'suppress-keymap t)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (if vi-com-map nil
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (setq vi-com-map (make-keymap))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 ;;(fillarray vi-com-map 'vi-undefined)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (define-key vi-com-map "\C-@" 'vi-mark-region) ; extension
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (define-key vi-com-map "\C-a" 'vi-ask-for-info) ; extension
13951
b777c515e6dc (vi-backward-windowful): Renamed from vi-backward-windowfull.
Karl Heuer <kwzh@gnu.org>
parents: 12735
diff changeset
127 (define-key vi-com-map "\C-b" 'vi-backward-windowful)
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (define-key vi-com-map "\C-c" 'vi-do-old-mode-C-c-command) ; extension
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (define-key vi-com-map "\C-d" 'vi-scroll-down-window)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (define-key vi-com-map "\C-e" 'vi-expose-line-below)
13951
b777c515e6dc (vi-backward-windowful): Renamed from vi-backward-windowfull.
Karl Heuer <kwzh@gnu.org>
parents: 12735
diff changeset
131 (define-key vi-com-map "\C-f" 'vi-forward-windowful)
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (define-key vi-com-map "\C-g" 'keyboard-quit)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (define-key vi-com-map "\C-i" 'indent-relative-maybe) ; TAB
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (define-key vi-com-map "\C-j" 'vi-next-line) ; LFD
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (define-key vi-com-map "\C-k" 'vi-kill-line) ; extension
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (define-key vi-com-map "\C-l" 'recenter)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (define-key vi-com-map "\C-m" 'vi-next-line-first-nonwhite) ; RET
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (define-key vi-com-map "\C-n" 'vi-next-line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (define-key vi-com-map "\C-o" 'vi-split-open-line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (define-key vi-com-map "\C-p" 'previous-line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (define-key vi-com-map "\C-q" 'vi-query-replace) ; extension
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (define-key vi-com-map "\C-r" 'vi-isearch-backward) ; modification
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (define-key vi-com-map "\C-s" 'vi-isearch-forward) ; extension
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (define-key vi-com-map "\C-t" 'vi-transpose-objects) ; extension
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (define-key vi-com-map "\C-u" 'vi-scroll-up-window)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (define-key vi-com-map "\C-v" 'scroll-up) ; extension
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (define-key vi-com-map "\C-w" 'vi-kill-region) ; extension
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (define-key vi-com-map "\C-x" 'Control-X-prefix) ; extension
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (define-key vi-com-map "\C-y" 'vi-expose-line-above)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (define-key vi-com-map "\C-z" 'suspend-emacs)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (define-key vi-com-map "\e" 'ESC-prefix); C-[ (ESC)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (define-key vi-com-map "\C-\\" 'vi-unimplemented)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (define-key vi-com-map "\C-]" 'find-tag)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (define-key vi-com-map "\C-^" 'vi-locate-def) ; extension
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38431
diff changeset
156 (define-key vi-com-map "\C-_" 'vi-undefined)
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (define-key vi-com-map " " 'forward-char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (define-key vi-com-map "!" 'vi-operator)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (define-key vi-com-map "\"" 'vi-char-argument)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (define-key vi-com-map "#" 'universal-argument) ; extension
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (define-key vi-com-map "$" 'end-of-line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (define-key vi-com-map "%" 'vi-find-matching-paren)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (define-key vi-com-map "&" 'vi-unimplemented)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (define-key vi-com-map "'" 'vi-goto-line-mark)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (define-key vi-com-map "(" 'backward-sexp)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (define-key vi-com-map ")" 'forward-sexp)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (define-key vi-com-map "*" 'vi-name-last-change-or-macro) ; extension
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (define-key vi-com-map "+" 'vi-next-line-first-nonwhite)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (define-key vi-com-map "," 'vi-reverse-last-find-char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (define-key vi-com-map "-" 'vi-previous-line-first-nonwhite)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (define-key vi-com-map "." 'vi-redo-last-change-command)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (define-key vi-com-map "/" 'vi-search-forward)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (define-key vi-com-map "0" 'beginning-of-line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (define-key vi-com-map "1" 'vi-digit-argument)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (define-key vi-com-map "2" 'vi-digit-argument)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (define-key vi-com-map "3" 'vi-digit-argument)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (define-key vi-com-map "4" 'vi-digit-argument)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (define-key vi-com-map "5" 'vi-digit-argument)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (define-key vi-com-map "6" 'vi-digit-argument)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (define-key vi-com-map "7" 'vi-digit-argument)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (define-key vi-com-map "8" 'vi-digit-argument)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (define-key vi-com-map "9" 'vi-digit-argument)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (define-key vi-com-map ":" 'vi-ex-cmd)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (define-key vi-com-map ";" 'vi-repeat-last-find-char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (define-key vi-com-map "<" 'vi-operator)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (define-key vi-com-map "=" 'vi-operator)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (define-key vi-com-map ">" 'vi-operator)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (define-key vi-com-map "?" 'vi-search-backward)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (define-key vi-com-map "@" 'vi-call-named-change-or-macro) ; extension
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (define-key vi-com-map "A" 'vi-append-at-end-of-line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (define-key vi-com-map "B" 'vi-backward-blank-delimited-word)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (define-key vi-com-map "C" 'vi-change-rest-of-line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (define-key vi-com-map "D" 'vi-kill-line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (define-key vi-com-map "E" 'vi-end-of-blank-delimited-word)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (define-key vi-com-map "F" 'vi-backward-find-char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (define-key vi-com-map "G" 'vi-goto-line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (define-key vi-com-map "H" 'vi-home-window-line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (define-key vi-com-map "I" 'vi-insert-before-first-nonwhite)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (define-key vi-com-map "J" 'vi-join-lines)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38431
diff changeset
204 (define-key vi-com-map "K" 'vi-undefined)
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (define-key vi-com-map "L" 'vi-last-window-line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (define-key vi-com-map "M" 'vi-middle-window-line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (define-key vi-com-map "N" 'vi-reverse-last-search)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (define-key vi-com-map "O" 'vi-open-above)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (define-key vi-com-map "P" 'vi-put-before)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (define-key vi-com-map "Q" 'vi-quote-words) ; extension
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (define-key vi-com-map "R" 'vi-replace-chars)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (define-key vi-com-map "S" 'vi-substitute-lines)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (define-key vi-com-map "T" 'vi-backward-upto-char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (define-key vi-com-map "U" 'vi-unimplemented)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38431
diff changeset
215 (define-key vi-com-map "V" 'vi-undefined)
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (define-key vi-com-map "W" 'vi-forward-blank-delimited-word)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (define-key vi-com-map "X" 'call-last-kbd-macro) ; modification/extension
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (define-key vi-com-map "Y" 'vi-yank-line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (define-key vi-com-map "Z" (make-sparse-keymap)) ;allow below prefix command
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (define-key vi-com-map "ZZ" 'vi-save-all-and-exit)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (define-key vi-com-map "[" 'vi-unimplemented)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (define-key vi-com-map "\\" 'vi-operator) ; extension for vi-narrow-op
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (define-key vi-com-map "]" 'vi-unimplemented)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (define-key vi-com-map "^" 'back-to-indentation)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (define-key vi-com-map "_" 'vi-undefined)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (define-key vi-com-map "`" 'vi-goto-char-mark)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (define-key vi-com-map "a" 'vi-insert-after)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (define-key vi-com-map "b" 'backward-word)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (define-key vi-com-map "c" 'vi-operator)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (define-key vi-com-map "d" 'vi-operator)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (define-key vi-com-map "e" 'vi-end-of-word)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (define-key vi-com-map "f" 'vi-forward-find-char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (define-key vi-com-map "g" 'vi-beginning-of-buffer) ; extension
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (define-key vi-com-map "h" 'backward-char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (define-key vi-com-map "i" 'vi-insert-before)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (define-key vi-com-map "j" 'vi-next-line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (define-key vi-com-map "k" 'previous-line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (define-key vi-com-map "l" 'forward-char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (define-key vi-com-map "m" 'vi-set-mark)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (define-key vi-com-map "n" 'vi-repeat-last-search)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (define-key vi-com-map "o" 'vi-open-below)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (define-key vi-com-map "p" 'vi-put-after)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (define-key vi-com-map "q" 'vi-replace)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (define-key vi-com-map "r" 'vi-replace-1-char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (define-key vi-com-map "s" 'vi-substitute-chars)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (define-key vi-com-map "t" 'vi-forward-upto-char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (define-key vi-com-map "u" 'undo)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38431
diff changeset
250 (define-key vi-com-map "v" 'vi-verify-spelling)
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (define-key vi-com-map "w" 'vi-forward-word)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (define-key vi-com-map "x" 'vi-kill-char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (define-key vi-com-map "y" 'vi-operator)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (define-key vi-com-map "z" 'vi-adjust-window)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (define-key vi-com-map "{" 'backward-paragraph)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (define-key vi-com-map "|" 'vi-goto-column)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (define-key vi-com-map "}" 'forward-paragraph)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (define-key vi-com-map "~" 'vi-change-case)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (define-key vi-com-map "\177" 'delete-backward-char))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (put 'backward-char 'point-moving-unit 'char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (put 'vi-next-line 'point-moving-unit 'line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (put 'next-line 'point-moving-unit 'line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (put 'forward-line 'point-moving-unit 'line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (put 'previous-line 'point-moving-unit 'line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (put 'vi-isearch-backward 'point-moving-unit 'search)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (put 'vi-search-backward 'point-moving-unit 'search)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (put 'vi-isearch-forward 'point-moving-unit 'search)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (put 'vi-search-forward 'point-moving-unit 'search)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (put 'forward-char 'point-moving-unit 'char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (put 'end-of-line 'point-moving-unit 'char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (put 'vi-find-matching-paren 'point-moving-unit 'match)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (put 'vi-goto-line-mark 'point-moving-unit 'line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (put 'backward-sexp 'point-moving-unit 'sexp)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (put 'forward-sexp 'point-moving-unit 'sexp)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (put 'vi-next-line-first-nonwhite 'point-moving-unit 'line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (put 'vi-previous-line-first-nonwhite 'point-moving-unit 'line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (put 'vi-reverse-last-find-char 'point-moving-unit 'rev-find)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (put 'vi-re-search-forward 'point-moving-unit 'search)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (put 'beginning-of-line 'point-moving-unit 'char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (put 'vi-beginning-of-buffer 'point-moving-unit 'char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (put 'vi-repeat-last-find-char 'point-moving-unit 'find)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (put 'vi-re-search-backward 'point-moving-unit 'search)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (put 'vi-backward-blank-delimited-word 'point-moving-unit 'WORD)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (put 'vi-end-of-blank-delimited-word 'point-moving-unit 'match)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (put 'vi-backward-find-char 'point-moving-unit 'find)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (put 'vi-goto-line 'point-moving-unit 'line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (put 'vi-home-window-line 'point-moving-unit 'line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (put 'vi-last-window-line 'point-moving-unit 'line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (put 'vi-middle-window-line 'point-moving-unit 'line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (put 'vi-reverse-last-search 'point-moving-unit 'rev-search)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (put 'vi-backward-upto-char 'point-moving-unit 'find)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (put 'vi-forward-blank-delimited-word 'point-moving-unit 'WORD)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (put 'back-to-indentation 'point-moving-unit 'char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (put 'vi-goto-char-mark 'point-moving-unit 'char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 (put 'backward-word 'point-moving-unit 'word)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (put 'vi-end-of-word 'point-moving-unit 'match)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (put 'vi-forward-find-char 'point-moving-unit 'find)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (put 'backward-char 'point-moving-unit 'char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 (put 'vi-forward-char 'point-moving-unit 'char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (put 'vi-repeat-last-search 'point-moving-unit 'search)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (put 'vi-forward-upto-char 'point-moving-unit 'find)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (put 'vi-forward-word 'point-moving-unit 'word)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 (put 'vi-goto-column 'point-moving-unit 'match)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (put 'forward-paragraph 'point-moving-unit 'paragraph)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (put 'backward-paragraph 'point-moving-unit 'paragraph)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 ;;; region mark commands
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 (put 'mark-page 'point-moving-unit 'region)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (put 'mark-paragraph 'point-moving-unit 'region)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (put 'mark-word 'point-moving-unit 'region)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 (put 'mark-sexp 'point-moving-unit 'region)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (put 'mark-defun 'point-moving-unit 'region)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (put 'mark-whole-buffer 'point-moving-unit 'region)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (put 'mark-end-of-sentence 'point-moving-unit 'region)
63942
c9581f50bd50 (vi-mark-region): Use c-mark-function.
Richard M. Stallman <rms@gnu.org>
parents: 63401
diff changeset
317 (put 'c-mark-function 'point-moving-unit 'region)
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 ;;;
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (defvar vi-mark-alist nil
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 "Alist of (NAME . MARK), marks are local to each buffer.")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (defvar vi-scroll-amount (/ (window-height) 2)
12735
2e79a07a9c27 (vi-scroll-amount, vi-shift-width): Fix syntax of doc strings.
Richard M. Stallman <rms@gnu.org>
parents: 11567
diff changeset
324 "Default amount of lines for scrolling (used by \"^D\"/\"^U\").")
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (defvar vi-shift-width 4
12735
2e79a07a9c27 (vi-scroll-amount, vi-shift-width): Fix syntax of doc strings.
Richard M. Stallman <rms@gnu.org>
parents: 11567
diff changeset
327 "Shift amount for \"<\"/\">\" operators.")
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (defvar vi-ins-point nil ; integer
12735
2e79a07a9c27 (vi-scroll-amount, vi-shift-width): Fix syntax of doc strings.
Richard M. Stallman <rms@gnu.org>
parents: 11567
diff changeset
330 "Last insertion point. Should use `mark' instead.")
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (defvar vi-ins-length nil ; integer
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 "Length of last insertion.")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (defvar vi-ins-repetition nil ; integer
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 "The repetition required for last insertion.")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (defvar vi-ins-overwrt-p nil ; boolean
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 "T if last insertion was a replace actually.")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (defvar vi-ins-prefix-code nil ; ready-to-eval sexp
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 "Code to be eval'ed before (redo-)insertion begins.")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (defvar vi-last-find-char nil ; cons cell
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 "Save last direction, char and upto-flag used for char finding.")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (defvar vi-last-change-command nil ; cons cell
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 1577
diff changeset
348 "Save commands for redoing last changes. Each command is in (FUNC . ARGS)
12735
2e79a07a9c27 (vi-scroll-amount, vi-shift-width): Fix syntax of doc strings.
Richard M. Stallman <rms@gnu.org>
parents: 11567
diff changeset
349 form that is ready to be `apply'ed.")
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (defvar vi-last-shell-command nil ; last shell op command line
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 "Save last shell command given for \"!\" operator.")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (defvar vi-insert-state nil ; boolean
12735
2e79a07a9c27 (vi-scroll-amount, vi-shift-width): Fix syntax of doc strings.
Richard M. Stallman <rms@gnu.org>
parents: 11567
diff changeset
355 "Non-nil if it is in insert state.")
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 ; in "loaddefs.el"
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38431
diff changeset
358 ;(defvar search-last-string ""
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 ; "Last string search for by a search command.")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 (defvar vi-search-last-command nil ; (re-)search-forward(backward)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 "Save last search command for possible redo.")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (defvar vi-mode-old-local-map nil
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 "Save the local-map used before entering vi-mode.")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (defvar vi-mode-old-mode-name nil
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 "Save the mode-name before entering vi-mode.")
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38431
diff changeset
369
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (defvar vi-mode-old-major-mode nil
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 "Save the major-mode before entering vi-mode.")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (defvar vi-mode-old-case-fold nil)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38431
diff changeset
374
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 ;(defconst vi-add-to-mode-line-1
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 ; '(overwrite-mode nil " Insert"))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 ;; Value is same as vi-add-to-mode-line-1 when in vi mode,
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 ;; but nil in other buffers.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 ;(defvar vi-add-to-mode-line nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (defun vi-mode-setup ()
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 "Setup a buffer for vi-mode by creating necessary buffer-local variables."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 ; (make-local-variable 'vi-add-to-mode-line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 ; (setq vi-add-to-mode-line vi-add-to-mode-line-1)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 ; (or (memq vi-add-to-mode-line minor-mode-alist)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 ; (setq minor-mode-alist (cons vi-add-to-mode-line minor-mode-alist)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 (make-local-variable 'vi-scroll-amount)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 (setq vi-scroll-amount (/ (window-height) 2))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 (make-local-variable 'vi-shift-width)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 (setq vi-shift-width 4)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (make-local-variable 'vi-ins-point)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (make-local-variable 'vi-ins-length)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 (make-local-variable 'vi-ins-repetition)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (make-local-variable 'vi-ins-overwrt-p)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 (make-local-variable 'vi-ins-prefix-code)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (make-local-variable 'vi-last-change-command)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 (make-local-variable 'vi-last-shell-command)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 (make-local-variable 'vi-last-find-char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (make-local-variable 'vi-mark-alist)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 (make-local-variable 'vi-insert-state)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 (make-local-variable 'vi-mode-old-local-map)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 (make-local-variable 'vi-mode-old-mode-name)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (make-local-variable 'vi-mode-old-major-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (make-local-variable 'vi-mode-old-case-fold)
62758
3225f62f5e9f (vi-mode-setup): Use run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents: 60902
diff changeset
406 (run-mode-hooks 'vi-mode-hook))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38431
diff changeset
407
258
1e0bc00dca7a *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 6
diff changeset
408 ;;;###autoload
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (defun vi-mode ()
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 "Major mode that acts like the `vi' editor.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 The purpose of this mode is to provide you the combined power of vi (namely,
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 the \"cross product\" effect of commands and repeat last changes) and Emacs.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 This command redefines nearly all keys to look like vi commands.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 It records the previous major mode, and any vi command for input
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 \(`i', `a', `s', etc.) switches back to that mode.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 Thus, ordinary Emacs (in whatever major mode you had been using)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 is \"input\" mode as far as vi is concerned.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 To get back into vi from \"input\" mode, you must issue this command again.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 Therefore, it is recommended that you assign it to a key.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 Major differences between this mode and real vi :
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 * Limitations and unsupported features
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 - Search patterns with line offset (e.g. /pat/+3 or /pat/z.) are
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 not supported.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 - Ex commands are not implemented; try ':' to get some hints.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 - No line undo (i.e. the 'U' command), but multi-undo is a standard feature.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 * Modifications
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 - The stopping positions for some point motion commands (word boundary,
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 pattern search) are slightly different from standard 'vi'.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 Also, no automatic wrap around at end of buffer for pattern searching.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 - Since changes are done in two steps (deletion then insertion), you need
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 to undo twice to completely undo a change command. But this is not needed
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 for undoing a repeated change command.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 - No need to set/unset 'magic', to search for a string with regular expr
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 in it just put a prefix arg for the search commands. Replace cmds too.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 - ^R is bound to incremental backward search, so use ^L to redraw screen.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 * Extensions
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 - Some standard (or modified) Emacs commands were integrated, such as
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 incremental search, query replace, transpose objects, and keyboard macros.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 - In command state, ^X links to the 'ctl-x-map', and ESC can be linked to
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 esc-map or set undefined. These can give you the full power of Emacs.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 - See vi-com-map for those keys that are extensions to standard vi, e.g.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 `vi-name-last-change-or-macro', `vi-verify-spelling', `vi-locate-def',
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 `vi-mark-region', and 'vi-quote-words'. Some of them are quite handy.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 - Use \\[vi-switch-mode] to switch among different modes quickly.
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38431
diff changeset
451
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 Syntax table and abbrevs while in vi mode remain as they were in Emacs."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 (interactive)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 (if (null vi-mode-old-major-mode) ; very first call for current buffer
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 (vi-mode-setup))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (if (eq major-mode 'vi-mode)
53863
3c9fc6a0a6db (vi-mode): Remove extra format string argument.
Andreas Schwab <schwab@suse.de>
parents: 52401
diff changeset
458 (progn (ding) (message "Already in vi-mode."))
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 (setq vi-mode-old-local-map (current-local-map))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 (setq vi-mode-old-mode-name mode-name)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 (setq vi-mode-old-major-mode major-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 (setq vi-mode-old-case-fold case-fold-search) ; this is needed !!
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 (setq case-fold-search nil) ; exact case match in searching
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 (use-local-map vi-com-map)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 (setq major-mode 'vi-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 (setq mode-name "VI")
11567
bcf841745ef2 (vi-switch-mode, vi-back-to-old-mode): Use force-mode-line-update.
Karl Heuer <kwzh@gnu.org>
parents: 11184
diff changeset
467 (force-mode-line-update) ; force mode line update
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 (if vi-insert-state ; this is a return from insertion
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 (vi-end-of-insert-state))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 (defun vi-ding()
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 "Ding !"
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 (interactive)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 (ding))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 (defun vi-save-all-and-exit ()
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 "Save all modified buffers without asking, then exits emacs."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 (interactive)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 (save-some-buffers t)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 (kill-emacs))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 ;; to be used by "ex" commands
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 (defvar vi-replaced-string nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 (defvar vi-replacing-string nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 (defun vi-ex-cmd ()
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 "Ex commands are not implemented in Evi mode. For some commonly used ex
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 commands, you can use the following alternatives for similar effect :
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 w C-x C-s (save-buffer)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 wq C-x C-c (save-buffers-kill-emacs)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 w fname C-x C-w (write-file)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 e fname C-x C-f (find-file)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 r fname C-x i (insert-file)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 s/old/new use q (vi-replace) to do unconditional replace
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 use C-q (vi-query-replace) to do query replace
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 set sw=n M-x set-variable vi-shift-width n "
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 (interactive)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 ;; (let ((cmd (read-string ":")) (lines 1))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 ;; (cond ((string-match "s"))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 (with-output-to-temp-buffer "*Help*"
9842
6f9b0830f124 (vi-switch-mode, vi-ex-cmd): Set help-mode in *Help* buffer.
Karl Heuer <kwzh@gnu.org>
parents: 3591
diff changeset
501 (princ (documentation 'vi-ex-cmd))
6f9b0830f124 (vi-switch-mode, vi-ex-cmd): Set help-mode in *Help* buffer.
Karl Heuer <kwzh@gnu.org>
parents: 3591
diff changeset
502 (save-excursion
6f9b0830f124 (vi-switch-mode, vi-ex-cmd): Set help-mode in *Help* buffer.
Karl Heuer <kwzh@gnu.org>
parents: 3591
diff changeset
503 (set-buffer standard-output)
6f9b0830f124 (vi-switch-mode, vi-ex-cmd): Set help-mode in *Help* buffer.
Karl Heuer <kwzh@gnu.org>
parents: 3591
diff changeset
504 (help-mode))))
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 (defun vi-undefined ()
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 (interactive)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 (message "Command key \"%s\" is undefined in Evi."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 (single-key-description last-command-char))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 (ding))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 (defun vi-unimplemented ()
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 (interactive)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 (message "Command key \"%s\" is not implemented in Evi."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 (single-key-description last-command-char))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 (ding))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 ;;;;;
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 (defun vi-goto-insert-state (repetition &optional prefix-code do-it-now-p)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 "Go into insert state, the text entered will be repeated if REPETITION > 1.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 If PREFIX-CODE is given, do it before insertion begins if DO-IT-NOW-P is T.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 In any case, the prefix-code will be done before each 'redo-insert'.
63401
f32aaa9cbdf6 (vi-goto-insert-state): Fix quoting in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 62758
diff changeset
523 This function expects `overwrite-mode' being set properly beforehand."
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 (if do-it-now-p (apply (car prefix-code) (cdr prefix-code)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 (setq vi-ins-point (point))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 (setq vi-ins-repetition repetition)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 (setq vi-ins-prefix-code prefix-code)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 (setq mode-name vi-mode-old-mode-name)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 (setq case-fold-search vi-mode-old-case-fold)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 (use-local-map vi-mode-old-local-map)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 (setq major-mode vi-mode-old-major-mode)
11567
bcf841745ef2 (vi-switch-mode, vi-back-to-old-mode): Use force-mode-line-update.
Karl Heuer <kwzh@gnu.org>
parents: 11184
diff changeset
532 (force-mode-line-update)
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 (setq vi-insert-state t))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 (defun vi-end-of-insert-state ()
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 "Terminate insertion and set up last change command."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 (if (or (< (point) vi-ins-point) ;Check if there is any effective change
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 (and (= (point) vi-ins-point) (null vi-ins-prefix-code))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 (<= vi-ins-repetition 0))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 (vi-goto-command-state t)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 (if (> vi-ins-repetition 1)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38431
diff changeset
542 (progn
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 (let ((str (buffer-substring vi-ins-point (point))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 (while (> vi-ins-repetition 1)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 (insert str)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 (setq vi-ins-repetition (1- vi-ins-repetition))))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 (vi-set-last-change-command 'vi-first-redo-insertion vi-ins-point (point)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 overwrite-mode vi-ins-prefix-code)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 (vi-goto-command-state t)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 (defun vi-first-redo-insertion (begin end &optional overwrite-p prefix-code)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 "Redo last insertion the first time. Extract the string and save it for
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 future redoes. Do prefix-code if it's given, use overwrite mode if asked."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 (let ((str (buffer-substring begin end)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 (if prefix-code (apply (car prefix-code) (cdr prefix-code)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 (if overwrite-p (delete-region (point) (+ (point) (length str))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 (insert str)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 (vi-set-last-change-command 'vi-more-redo-insertion str overwrite-p prefix-code)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 (defun vi-more-redo-insertion (str &optional overwrite-p prefix-code)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 "Redo more insertion : copy string from STR to point, use overwrite mode
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 if overwrite-p is T; apply prefix-code first if it's non-nil."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 (if prefix-code (apply (car prefix-code) (cdr prefix-code)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 (if overwrite-p (delete-region (point) (+ (point) (length str))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 (insert str))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 (defun vi-goto-command-state (&optional from-insert-state-p)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568 "Go to vi-mode command state. If optional arg exists, means return from
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569 insert state."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 (use-local-map vi-com-map)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 (setq vi-insert-state nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 (if from-insert-state-p
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 (if overwrite-mode
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 (overwrite-mode 0)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 ; (set-minor-mode 'ins "Insert" nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 )))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 (defun vi-kill-line (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 "kill specified number of lines (=d$), text saved in the kill ring."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 (interactive "*P")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 (kill-line arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 (vi-set-last-change-command 'kill-line arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583
9865
9ca8b94a9f07 (vi-kill-region): Pass args to kill-region.
Karl Heuer <kwzh@gnu.org>
parents: 9842
diff changeset
584 (defun vi-kill-region (start end)
9ca8b94a9f07 (vi-kill-region): Pass args to kill-region.
Karl Heuer <kwzh@gnu.org>
parents: 9842
diff changeset
585 (interactive "*r")
9ca8b94a9f07 (vi-kill-region): Pass args to kill-region.
Karl Heuer <kwzh@gnu.org>
parents: 9842
diff changeset
586 (kill-region start end)
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 (vi-set-last-change-command 'kill-region))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38431
diff changeset
588
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 (defun vi-append-at-end-of-line (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 "go to end of line and then go into vi insert state."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 (interactive "*p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 (vi-goto-insert-state arg '(end-of-line) t))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 (defun vi-change-rest-of-line (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595 "Change the rest of (ARG) lines (= c$ in vi)."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 (interactive "*P")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597 (vi-goto-insert-state 1 (list 'kill-line arg) t))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599 (defun vi-insert-before-first-nonwhite (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 "(= ^i in vi)"
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601 (interactive "*p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602 (vi-goto-insert-state arg '(back-to-indentation) t))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604 (defun vi-open-above (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605 "open new line(s) above current line and enter insert state."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 (interactive "*p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607 (vi-goto-insert-state 1
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 (list (function (lambda (x)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 (or (beginning-of-line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610 (open-line x)))) arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 t))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 (defun vi-open-below (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614 "open new line(s) and go into insert mode on the last line."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 (interactive "*p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616 (vi-goto-insert-state 1
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617 (list (function (lambda (x)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 (or (end-of-line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619 (open-line x)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620 (forward-line x)))) arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621 t))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623 (defun vi-insert-after (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 "start vi insert state after cursor."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625 (interactive "*p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 (vi-goto-insert-state arg
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627 (list (function (lambda ()
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628 (if (not (eolp)) (forward-char)))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
629 t))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
630
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631 (defun vi-insert-before (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 "enter insert state before the cursor."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 (interactive "*p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 (vi-goto-insert-state arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636 (defun vi-goto-line (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637 "Go to ARGth line."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 (interactive "P")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639 (if (null (vi-raw-numeric-prefix arg))
63942
c9581f50bd50 (vi-mark-region): Use c-mark-function.
Richard M. Stallman <rms@gnu.org>
parents: 63401
diff changeset
640 (with-no-warnings
c9581f50bd50 (vi-mark-region): Use c-mark-function.
Richard M. Stallman <rms@gnu.org>
parents: 63401
diff changeset
641 (end-of-buffer))
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 (goto-line (vi-prefix-numeric-value arg))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 (defun vi-beginning-of-buffer ()
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 "Move point to the beginning of current buffer."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 (interactive)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647 (goto-char (point-min)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 ;;;;; not used now
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650 ;;(defvar regexp-search t ; string
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 ;; "*T if search string can contain regular expressions. (= set magic in vi)")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 ;;;;;
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654 (defun vi-isearch-forward (arg)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38431
diff changeset
655 "Incremental search forward. Use regexp version if ARG is non-nil."
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656 (interactive "P")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657 (let ((scmd (if arg 'isearch-forward-regexp 'isearch-forward))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658 (opoint (point)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659 (call-interactively scmd)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660 (if (= opoint (point))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661 nil
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 (setq vi-search-last-command (if arg 're-search-forward 'search-forward)))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 (defun vi-isearch-backward (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665 "Incremental search backward. Use regexp version if ARG is non-nil."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666 (interactive "P")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667 (let ((scmd (if arg 'isearch-backward-regexp 'isearch-backward))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 (opoint (point)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669 (call-interactively scmd)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670 (if (= opoint (point))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 nil
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 (setq vi-search-last-command (if arg 're-search-backward 'search-backward)))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 (defun vi-search-forward (arg string)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 "Nonincremental search forward. Use regexp version if ARG is non-nil."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 (interactive (if current-prefix-arg
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677 (list t (read-string "regexp/" nil))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678 (list nil (read-string "/" nil))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 (setq vi-search-last-command (if arg 're-search-forward 'search-forward))
17979
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
680 (if (> (length string) 0)
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
681 (isearch-update-ring string arg))
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
682 (funcall vi-search-last-command string nil nil 1))
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684 (defun vi-search-backward (arg string)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 "Nonincremental search backward. Use regexp version if ARG is non-nil."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686 (interactive (if current-prefix-arg
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687 (list t (read-string "regexp?" nil))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 (list nil (read-string "?" nil))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
689 (setq vi-search-last-command (if arg 're-search-backward 'search-backward))
17979
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
690 (if (> (length string) 0)
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
691 (isearch-update-ring string arg))
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
692 (funcall vi-search-last-command string nil nil 1))
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694 (defun vi-repeat-last-search (arg &optional search-command search-string)
17979
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
695 "Repeat last search command.
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
696 If optional search-command/string are given,
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 use those instead of the ones saved."
17979
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
698 (interactive "p")
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
699 (if (null search-command) (setq search-command vi-search-last-command))
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
700 (if (null search-string)
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
701 (setq search-string
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
702 (car (if (memq search-command
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
703 '(re-search-forward re-search-backward))
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
704 regexp-search-ring
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
705 search-ring))))
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
706 (if (null search-command)
53863
3c9fc6a0a6db (vi-mode): Remove extra format string argument.
Andreas Schwab <schwab@suse.de>
parents: 52401
diff changeset
707 (progn (ding) (message "No last search command to repeat."))
17979
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
708 (funcall search-command search-string nil nil arg)))
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710 (defun vi-reverse-last-search (arg &optional search-command search-string)
17979
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
711 "Redo last search command in reverse direction.
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
712 If the optional search args are given, use those instead of the ones saved."
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713 (interactive "p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 (if (null search-command) (setq search-command vi-search-last-command))
17979
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
715 (if (null search-string)
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
716 (setq search-string
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
717 (car (if (memq search-command
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
718 '(re-search-forward re-search-backward))
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
719 regexp-search-ring
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
720 search-ring))))
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 (if (null search-command)
53863
3c9fc6a0a6db (vi-mode): Remove extra format string argument.
Andreas Schwab <schwab@suse.de>
parents: 52401
diff changeset
722 (progn (ding) (message "No last search command to repeat."))
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 (funcall (cond ((eq search-command 're-search-forward) 're-search-backward)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724 ((eq search-command 're-search-backward) 're-search-forward)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
725 ((eq search-command 'search-forward) 'search-backward)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726 ((eq search-command 'search-backward) 'search-forward))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727 search-string nil nil arg)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38431
diff changeset
728
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729 (defun vi-join-lines (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730 "join ARG lines from current line (default 2), cleaning up white space."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731 (interactive "P")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
732 (if (null (vi-raw-numeric-prefix arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733 (delete-indentation t)
17979
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
734 (let ((count (vi-prefix-numeric-value arg)))
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
735 (while (>= count 2)
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
736 (delete-indentation t)
2265b685be6a (vi-join-lines): Locally bind count.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
737 (setq count (1- count)))))
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738 (vi-set-last-change-command 'vi-join-lines arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
740 (defun vi-backward-kill-line ()
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741 "kill the current line. Only works in insert state."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742 (interactive)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
743 (if (not vi-insert-state)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744 nil
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745 (beginning-of-line 1)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
746 (kill-line nil)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
747
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748 (defun vi-abort-ins ()
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 "abort insert state, kill inserted text and go back to command state."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
750 (interactive)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
751 (if (not vi-insert-state)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752 nil
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753 (if (> (point) vi-ins-point)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
754 (kill-region vi-ins-point (point)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755 (vi-goto-command-state t)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
756
13951
b777c515e6dc (vi-backward-windowful): Renamed from vi-backward-windowfull.
Karl Heuer <kwzh@gnu.org>
parents: 12735
diff changeset
757 (defun vi-backward-windowful (count)
b777c515e6dc (vi-backward-windowful): Renamed from vi-backward-windowfull.
Karl Heuer <kwzh@gnu.org>
parents: 12735
diff changeset
758 "Backward COUNT windowfuls. Default is one."
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
759 (interactive "p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
760 ; (set-mark-command nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
761 (while (> count 0)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762 (scroll-down nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
763 (setq count (1- count))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
764
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
765 (defun vi-scroll-down-window (count)
1577
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
766 "Scrolls down window COUNT lines.
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
767 If COUNT is nil (actually, non-integer), scrolls default amount.
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
768 The given COUNT is remembered for future scrollings."
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
769 (interactive "P")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
770 (if (integerp count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
771 (setq vi-scroll-amount count))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
772 (scroll-up vi-scroll-amount))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
773
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774 (defun vi-expose-line-below (count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775 "Expose COUNT more lines below the current window. Default COUNT is 1."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
776 (interactive "p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
777 (scroll-up count))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
778
13951
b777c515e6dc (vi-backward-windowful): Renamed from vi-backward-windowfull.
Karl Heuer <kwzh@gnu.org>
parents: 12735
diff changeset
779 (defun vi-forward-windowful (count)
b777c515e6dc (vi-backward-windowful): Renamed from vi-backward-windowfull.
Karl Heuer <kwzh@gnu.org>
parents: 12735
diff changeset
780 "Forward COUNT windowfuls. Default is one."
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
781 (interactive "p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
782 ; (set-mark-command nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
783 (while (> count 0)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
784 (scroll-up nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
785 (setq count (1- count))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
786
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
787 (defun vi-next-line (count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
788 "Go down count lines, try to keep at the same column."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
789 (interactive "p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
790 (setq this-command 'next-line) ; this is a needed trick
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
791 (if (= (point) (or (line-move count) (point)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
792 (ding) ; no moving, already at end of buffer
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
793 (setq last-command 'next-line)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
794
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
795 (defun vi-next-line-first-nonwhite (count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
796 "Go down COUNT lines. Stop at first non-white."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
797 (interactive "p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
798 (if (= (point) (progn (forward-line count) (back-to-indentation) (point)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
799 (ding))) ; no moving, already at end of buffer
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
800
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
801 (defun vi-previous-line-first-nonwhite (count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
802 "Go up COUNT lines. Stop at first non-white."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
803 (interactive "p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
804 (previous-line count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
805 (back-to-indentation))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
806
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
807 (defun vi-scroll-up-window (count)
1577
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
808 "Scrolls up window COUNT lines.
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
809 If COUNT is nil (actually, non-integer), scrolls default amount.
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
810 The given COUNT is remembered for future scrollings."
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
811 (interactive "P")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
812 (if (integerp count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
813 (setq vi-scroll-amount count))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
814 (scroll-down vi-scroll-amount))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
815
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
816 (defun vi-expose-line-above (count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
817 "Expose COUNT more lines above the current window. Default COUNT is 1."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
818 (interactive "p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
819 (scroll-down count))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
820
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
821 (defun vi-char-argument (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
822 "Get following character (could be any CHAR) as part of the prefix argument.
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 1577
diff changeset
823 Possible prefix-arg cases are NIL, INTEGER, (NIL . CHAR) or (INTEGER . CHAR)."
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
824 (interactive "P")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
825 (let ((char (read-char)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
826 (cond ((null arg) (setq prefix-arg (cons nil char)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
827 ((integerp arg) (setq prefix-arg (cons arg char)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
828 ; This can happen only if the user changed his/her mind for CHAR,
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
829 ; Or there are some leading "universal-argument"s
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
830 (t (setq prefix-arg (cons (car arg) char))))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
831
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
832 (defun vi-goto-mark (mark-char &optional line-flag)
1577
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
833 "Go to marked position or line (if line-flag is given).
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
834 Goto mark '@' means jump into and pop the top mark on the mark ring."
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
835 (cond ((char-equal mark-char last-command-char) ; `` or ''
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
836 (exchange-point-and-mark) (if line-flag (back-to-indentation)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
837 ((char-equal mark-char ?@) ; jump and pop mark
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
838 (set-mark-command t) (if line-flag (back-to-indentation)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
839 (t
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
840 (let ((mark (vi-get-mark mark-char)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
841 (if (null mark)
53863
3c9fc6a0a6db (vi-mode): Remove extra format string argument.
Andreas Schwab <schwab@suse.de>
parents: 52401
diff changeset
842 (progn (vi-ding) (message "Mark register undefined."))
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
843 (set-mark-command nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
844 (goto-char mark)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
845 (if line-flag (back-to-indentation)))))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38431
diff changeset
846
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
847 (defun vi-goto-line-mark (char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
848 "Go to the line (at first non-white) marked by next char."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
849 (interactive "c")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
850 (vi-goto-mark char t))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
851
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
852 (defun vi-goto-char-mark (char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
853 "Go to the char position marked by next mark-char."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
854 (interactive "c")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
855 (vi-goto-mark char))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
856
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
857 (defun vi-digit-argument (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
858 "Set numeric prefix argument."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
859 (interactive "P")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
860 (cond ((null arg) (digit-argument arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
861 ((integerp arg) (digit-argument nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
862 (setq prefix-arg (* prefix-arg arg)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
863 (t (digit-argument nil) ; in (NIL . CHAR) or (NUM . CHAR) form
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
864 (setq prefix-arg (cons (* prefix-arg
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
865 (if (null (car arg)) 1 (car arg)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
866 (cdr arg))))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
867
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
868 (defun vi-raw-numeric-prefix (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
869 "Return the raw value of numeric part prefix argument."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
870 (if (consp arg) (car arg) arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
871
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
872 (defun vi-prefix-numeric-value (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
873 "Return numeric meaning of the raw prefix argument. This is a modification
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
874 to the standard one provided in `callint.c' to handle (_ . CHAR) cases."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
875 (cond ((null arg) 1)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
876 ((integerp arg) arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
877 ((consp arg) (if (car arg) (car arg) 1))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
878
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
879 (defun vi-reverse-last-find-char (count &optional find-arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
880 "Reverse last f F t T operation COUNT times. If the optional FIND-ARG
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
881 is given, it is used instead of the saved one."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
882 (interactive "p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
883 (if (null find-arg) (setq find-arg vi-last-find-char))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
884 (if (null find-arg)
53863
3c9fc6a0a6db (vi-mode): Remove extra format string argument.
Andreas Schwab <schwab@suse.de>
parents: 52401
diff changeset
885 (progn (ding) (message "No last find char to repeat."))
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
886 (vi-find-char (cons (* (car find-arg) -1) (cdr find-arg)) count))) ;6/13/86
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
887
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
888 (defun vi-find-char (arg count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
889 "Find in DIRECTION (1/-1) for CHAR of COUNT'th times on current line.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
890 If UPTO-FLAG is T, stop before the char. ARG = (DIRECTION.CHAR.UPTO-FLAG."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
891 (let* ((direction (car arg)) (char (car (cdr arg)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
892 (upto-flag (cdr (cdr arg))) (pos (+ (point) direction)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
893 (if (catch 'exit-find-char
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
894 (while t
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
895 (cond ((null (char-after pos)) (throw 'exit-find-char nil))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
896 ((char-equal (char-after pos) ?\n) (throw 'exit-find-char nil))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
897 ((char-equal char (char-after pos)) (setq count (1- count))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
898 (if (= count 0)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
899 (throw 'exit-find-char
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
900 (if upto-flag
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
901 (setq pos (- pos direction))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
902 pos)))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
903 (setq pos (+ pos direction))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
904 (goto-char pos)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
905 (ding))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
906
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
907 (defun vi-repeat-last-find-char (count &optional find-arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
908 "Repeat last f F t T operation COUNT times. If optional FIND-ARG is given,
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
909 it is used instead of the saved one."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
910 (interactive "p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
911 (if (null find-arg) (setq find-arg vi-last-find-char))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
912 (if (null find-arg)
53863
3c9fc6a0a6db (vi-mode): Remove extra format string argument.
Andreas Schwab <schwab@suse.de>
parents: 52401
diff changeset
913 (progn (ding) (message "No last find char to repeat."))
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
914 (vi-find-char find-arg count)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
915
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
916 (defun vi-backward-find-char (count char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
917 "Find the COUNT'th CHAR backward on current line."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
918 (interactive "p\nc")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
919 (setq vi-last-find-char (cons -1 (cons char nil)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
920 (vi-repeat-last-find-char count))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
921
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
922 (defun vi-forward-find-char (count char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
923 "Find the COUNT'th CHAR forward on current line."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
924 (interactive "p\nc")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
925 (setq vi-last-find-char (cons 1 (cons char nil)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
926 (vi-repeat-last-find-char count))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
927
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
928 (defun vi-backward-upto-char (count char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
929 "Find upto the COUNT'th CHAR backward on current line."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
930 (interactive "p\nc")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
931 (setq vi-last-find-char (cons -1 (cons char t)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
932 (vi-repeat-last-find-char count))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
933
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
934 (defun vi-forward-upto-char (count char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
935 "Find upto the COUNT'th CHAR forward on current line."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
936 (interactive "p\nc")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
937 (setq vi-last-find-char (cons 1 (cons char t)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
938 (vi-repeat-last-find-char count))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
939
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
940 (defun vi-end-of-word (count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
941 "Move forward until encountering the end of a word.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
942 With argument, do this that many times."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
943 (interactive "p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
944 (if (not (eobp)) (forward-char))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
945 (if (re-search-forward "\\W*\\w+\\>" nil t count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
946 (backward-char)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
947
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
948 (defun vi-replace-1-char (count char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
949 "Replace char after point by CHAR. Repeat COUNT times."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
950 (interactive "p\nc")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
951 (delete-char count nil) ; don't save in kill ring
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
952 (setq last-command-char char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
953 (self-insert-command count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
954 (vi-set-last-change-command 'vi-replace-1-char count char))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
955
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
956 (defun vi-replace-chars (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
957 "Replace chars over old ones."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
958 (interactive "*p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
959 (overwrite-mode 1)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
960 (vi-goto-insert-state arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
961
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
962 (defun vi-substitute-chars (count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
963 "Substitute COUNT chars by the input chars, enter insert state."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
964 (interactive "*p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
965 (vi-goto-insert-state 1 (list (function (lambda (c) ; this is a bit tricky
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
966 (delete-region (point)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
967 (+ (point) c))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
968 count) t))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
969
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
970 (defun vi-substitute-lines (count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
971 "Substitute COUNT lines by the input chars. (=cc in vi)"
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
972 (interactive "*p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
973 (vi-goto-insert-state 1 (list 'vi-delete-op 'next-line (1- count)) t))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
974
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
975 (defun vi-prefix-char-value (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
976 "Get the char part of the current prefix argument."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
977 (cond ((null arg) nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
978 ((integerp arg) nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
979 ((consp arg) (cdr arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
980 (t nil)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
981
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
982 (defun vi-operator (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
983 "Handling vi operators (d/c/</>/!/=/y). Current implementation requires
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
984 the key bindings of the operators being fixed."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
985 (interactive "P")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
986 (catch 'vi-exit-op
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
987 (let ((this-op-char last-command-char))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
988 (setq last-command-char (read-char))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
989 (setq this-command (lookup-key vi-com-map (char-to-string last-command-char)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
990 (if (not (eq this-command 'vi-digit-argument))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
991 (setq prefix-arg arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
992 (vi-digit-argument arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
993 (setq last-command-char (read-char))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
994 (setq this-command (lookup-key vi-com-map (char-to-string last-command-char))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
995 (cond ((char-equal this-op-char last-command-char) ; line op
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
996 (vi-execute-op this-op-char 'next-line
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
997 (cons (1- (vi-prefix-numeric-value prefix-arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
998 (vi-prefix-char-value prefix-arg))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
999 ;; We assume any command that has no property 'point-moving-unit'
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1000 ;; as having that property with the value 'CHAR'. 3/12/86
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1001 (t ;; (get this-command 'point-moving-unit)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1002 (vi-execute-op this-op-char this-command prefix-arg))))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1003 ;; (t (throw 'vi-exit-op (ding)))))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1004
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1005 (defun vi-execute-op (op-char motion-command arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1006 "Execute vi edit operator as specified by OP-CHAR, the operand is the region
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1007 determined by the MOTION-COMMAND with ARG."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1008 (cond ((= op-char ?d)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1009 (if (vi-delete-op motion-command arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1010 (vi-set-last-change-command 'vi-delete-op (vi-repeat-command-of motion-command) arg)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1011 ((= op-char ?c)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1012 (if (vi-delete-op motion-command arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1013 (vi-goto-insert-state 1 (list 'vi-delete-op
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1014 (vi-repeat-command-of motion-command) arg) nil)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1015 ((= op-char ?y)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1016 (if (vi-yank-op motion-command arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1017 (vi-set-last-change-command 'vi-yank-op (vi-repeat-command-of motion-command) arg)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1018 ((= op-char ?!)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1019 (if (vi-shell-op motion-command arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1020 (vi-set-last-change-command 'vi-shell-op (vi-repeat-command-of motion-command) arg vi-last-shell-command)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1021 ((= op-char ?<)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1022 (if (vi-shift-op motion-command arg (- vi-shift-width))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1023 (vi-set-last-change-command 'vi-shift-op (vi-repeat-command-of motion-command) arg (- vi-shift-width))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1024 ((= op-char ?>)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1025 (if (vi-shift-op motion-command arg vi-shift-width)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1026 (vi-set-last-change-command 'vi-shift-op (vi-repeat-command-of motion-command) arg vi-shift-width)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1027 ((= op-char ?=)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1028 (if (vi-indent-op motion-command arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1029 (vi-set-last-change-command 'vi-indent-op (vi-repeat-command-of motion-command) arg)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1030 ((= op-char ?\\)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1031 (vi-narrow-op motion-command arg))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1032
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1033 (defun vi-repeat-command-of (command)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1034 "Return the command for redo the given command."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1035 (let ((cmd-type (get command 'point-moving-unit)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1036 (cond ((eq cmd-type 'search) 'vi-repeat-last-search)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1037 ((eq cmd-type 'find) 'vi-repeat-last-find-char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1038 (t command))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1039
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1040 (defun vi-effective-range (motion-command arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1041 "Return (begin . end) of the range spanned by executing the given
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1042 MOTION-COMMAND with ARG.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1043 MOTION-COMMAND in ready-to-eval list form is not yet supported."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1044 (save-excursion
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1045 (let ((begin (point)) end opoint
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1046 (moving-unit (get motion-command 'point-moving-unit)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1047 (setq prefix-arg arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1048 (setq opoint (point))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1049 (command-execute motion-command nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1050 ;; Check if there is any effective motion. Note that for single line operation
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1051 ;; the motion-command causes no effective point movement (since it moves up or
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1052 ;; down zero lines), but it should be counted as effectively moved.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1053 (if (and (= (point) opoint) (not (eq moving-unit 'line)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1054 (cons opoint opoint) ; no effective motion
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1055 (if (eq moving-unit 'region)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1056 (setq begin (or (mark) (point))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1057 (if (<= begin (point))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1058 (setq end (point))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1059 (setq end begin)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1060 (setq begin (point)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1061 (cond ((or (eq moving-unit 'match) (eq moving-unit 'find))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1062 (setq end (1+ end)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1063 ((eq moving-unit 'line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1064 (goto-char begin) (beginning-of-line) (setq begin (point))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1065 (goto-char end) (next-line 1) (beginning-of-line) (setq end (point))))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38431
diff changeset
1066 (if (> end (point-max)) (setq end (point-max))) ; force in buffer region
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1067 (cons begin end)))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1068
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1069 (defun vi-delete-op (motion-command arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1070 "Delete range specified by MOTION-COMMAND with ARG."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1071 (let* ((range (vi-effective-range motion-command arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1072 (begin (car range)) (end (cdr range)) reg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1073 (if (= begin end)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1074 nil ; point not moved, abort op
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1075 (setq reg (vi-prefix-char-value arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1076 (if (null reg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1077 (kill-region begin end) ; kill ring as unnamed registers
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1078 (if (and (>= reg ?A) (<= reg ?Z))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1079 (append-to-register (downcase reg) begin end t)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1080 (copy-to-register reg begin end t)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1081 t)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1082
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1083 (defun vi-yank-op (motion-command arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1084 "Yank (in vi sense) range specified by MOTION-COMMAND with ARG."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1085 (let* ((range (vi-effective-range motion-command arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1086 (begin (car range)) (end (cdr range)) reg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1087 (if (= begin end)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1088 nil ; point not moved, abort op
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1089 (setq reg (vi-prefix-char-value arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1090 (if (null reg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1091 (copy-region-as-kill begin end); kill ring as unnamed registers
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1092 (if (and (>= reg ?A) (<= reg ?Z))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1093 (append-to-register (downcase reg) begin end nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1094 (copy-to-register reg begin end nil)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1095 t)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1096
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1097 (defun vi-yank-line (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1098 "Yank (in vi sense) lines (= `yy' command)."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1099 (interactive "*P")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1100 (setq arg (cons (1- (vi-prefix-numeric-value arg)) (vi-prefix-char-value arg)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1101 (if (vi-yank-op 'next-line arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1102 (vi-set-last-change-command 'vi-yank-op 'next-line arg)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1103
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1104 (defun vi-string-end-with-nl-p (string)
1577
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
1105 "See if STRING ends with a newline char.
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
1106 Used in checking whether the yanked text should be put back as lines or not."
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1107 (= (aref string (1- (length string))) ?\n))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1108
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1109 (defun vi-put-before (arg &optional after-p)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38431
diff changeset
1110 "Put yanked (in vi sense) text back before/above cursor.
1577
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
1111 If a numeric prefix value (currently it should be >1) is given, put back
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
1112 text as lines. If the optional after-p is given, put after/below the cursor."
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1113 (interactive "P")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1114 (let ((reg (vi-prefix-char-value arg)) put-text)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1115 (if (and reg (or (< reg ?1) (> reg ?9)) (null (get-register reg)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1116 (error "Nothing in register %c" reg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1117 (if (null reg) (setq reg ?1)) ; the default is the last text killed
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1118 (setq put-text
707
e4253da532fb *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 657
diff changeset
1119 (cond
e4253da532fb *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 657
diff changeset
1120 ((and (>= reg ?1) (<= reg ?9))
e4253da532fb *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 657
diff changeset
1121 (setq this-command 'yank) ; So we may yank-pop !!
e4253da532fb *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 657
diff changeset
1122 (current-kill (- reg ?0 1) 'do-not-rotate))
e4253da532fb *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 657
diff changeset
1123 ((stringp (get-register reg)) (get-register reg))
e4253da532fb *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 657
diff changeset
1124 (t (error "Register %c is not containing text string" reg))))
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1125 (if (vi-string-end-with-nl-p put-text) ; put back text as lines
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1126 (if after-p
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1127 (progn (next-line 1) (beginning-of-line))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1128 (beginning-of-line))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1129 (if after-p (forward-char 1)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1130 (push-mark (point))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1131 (insert put-text)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1132 (exchange-point-and-mark)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1133 ;; (back-to-indentation) ; this is not allowed if we allow yank-pop
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1134 (vi-set-last-change-command 'vi-put-before arg after-p))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1135
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1136 (defun vi-put-after (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1137 "Put yanked (in vi sense) text back after/below cursor."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1138 (interactive "P")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1139 (vi-put-before arg t))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1140
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1141 (defun vi-shell-op (motion-command arg &optional shell-command)
1577
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
1142 "Perform shell command (as filter).
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
1143 Performs command on range specified by MOTION-COMMAND
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1144 with ARG. If SHELL-COMMAND is not given, ask for one from minibuffer.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1145 If char argument is given, it directs the output to a *temp* buffer."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1146 (let* ((range (vi-effective-range motion-command arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1147 (begin (car range)) (end (cdr range)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1148 (if (= begin end)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1149 nil ; point not moved, abort op
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1150 (cond ((null shell-command)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1151 (setq shell-command (read-string "!" nil))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1152 (setq vi-last-shell-command shell-command)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1153 (shell-command-on-region begin end shell-command (not (vi-prefix-char-value arg)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1154 t)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1155
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1156 (defun vi-shift-op (motion-command arg amount)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1157 "Perform shift command on range specified by MOTION-COMMAND with ARG for
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1158 AMOUNT on each line. Negative amount means shift left.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1159 SPECIAL FEATURE: char argument can be used to specify shift amount(1-9)."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1160 (let* ((range (vi-effective-range motion-command arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1161 (begin (car range)) (end (cdr range)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1162 (if (= begin end)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1163 nil ; point not moved, abort op
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1164 (if (vi-prefix-char-value arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1165 (setq amount (if (> amount 0)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1166 (- (vi-prefix-char-value arg) ?0)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1167 (- ?0 (vi-prefix-char-value arg)))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1168 (indent-rigidly begin end amount)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1169 t)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1170
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1171 (defun vi-indent-op (motion-command arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1172 "Perform indent command on range specified by MOTION-COMMAND with ARG."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1173 (let* ((range (vi-effective-range motion-command arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1174 (begin (car range)) (end (cdr range)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1175 (if (= begin end)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1176 nil ; point not moved, abort op
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1177 (indent-region begin end nil) ; insert TAB as indent command
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1178 t)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1179
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1180 (defun vi-narrow-op (motion-command arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1181 "Narrow to region specified by MOTION-COMMAND with ARG."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1182 (let* ((range (vi-effective-range motion-command arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1183 (begin (car range)) (end (cdr range)) reg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1184 (if (= begin end)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1185 nil ; point not moved, abort op
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1186 (narrow-to-region begin end))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1187
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1188 (defun vi-get-mark (char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1189 "Return contents of vi mark register named CHAR, or nil if undefined."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1190 (cdr (assq char vi-mark-alist)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1191
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1192 (defun vi-set-mark (char)
1577
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
1193 "Set contents of vi mark register named CHAR to current point.
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
1194 '@' is the special anonymous mark register."
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1195 (interactive "c")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1196 (if (char-equal char ?@)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1197 (set-mark-command nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1198 (let ((aelt (assq char vi-mark-alist)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1199 (if aelt
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1200 (move-marker (cdr aelt) (point)) ; fixed 6/12/86
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1201 (setq aelt (cons char (copy-marker (point))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1202 (setq vi-mark-alist (cons aelt vi-mark-alist))))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1203
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1204 (defun vi-find-matching-paren ()
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1205 "Locate the matching paren. It's a hack right now."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1206 (interactive)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1207 (cond ((looking-at "[[({]") (forward-sexp 1) (backward-char 1))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1208 ((looking-at "[])}]") (forward-char 1) (backward-sexp 1))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1209 (t (ding))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1210
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1211 (defun vi-backward-blank-delimited-word (count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1212 "Backward COUNT blank-delimited words."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1213 (interactive "p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1214 (if (re-search-backward "[ \t\n\`][^ \t\n\`]+" nil t count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1215 (if (not (bobp)) (forward-char 1))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1216
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1217 (defun vi-forward-blank-delimited-word (count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1218 "Forward COUNT blank-delimited words."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1219 (interactive "p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1220 (if (re-search-forward "[^ \t\n]*[ \t\n]+[^ \t\n]" nil t count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1221 (if (not (eobp)) (backward-char 1))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1222
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1223 (defun vi-end-of-blank-delimited-word (count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1224 "Forward to the end of the COUNT'th blank-delimited word."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1225 (interactive "p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1226 (if (re-search-forward "[^ \t\n\']+[ \t\n\']" nil t count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1227 (if (not (eobp)) (backward-char 2))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1228
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1229 (defun vi-home-window-line (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1230 "To window home or arg'th line from the top of the window."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1231 (interactive "p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1232 (move-to-window-line (1- arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1233 (back-to-indentation))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1234
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1235 (defun vi-last-window-line (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1236 "To window last line or arg'th line from the bottom of the window."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1237 (interactive "p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1238 (move-to-window-line (- arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1239 (back-to-indentation))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1240
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1241 (defun vi-middle-window-line ()
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1242 "To the middle line of the window."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1243 (interactive)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1244 (move-to-window-line nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1245 (back-to-indentation))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1246
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1247 (defun vi-forward-word (count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1248 "Stop at the beginning of the COUNT'th words from point."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1249 (interactive "p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1250 (if (re-search-forward "\\w*\\W+\\<" nil t count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1251 t
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1252 (vi-ding)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1253
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1254 (defun vi-set-last-change-command (fun &rest args)
1577
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
1255 "Set (FUN . ARGS) as the `last-change-command'."
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1256 (setq vi-last-change-command (cons fun args)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1257
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1258 (defun vi-redo-last-change-command (count &optional command)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1259 "Redo last change command COUNT times. If the optional COMMAND is given,
1577
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
1260 it is used instead of the current `last-change-command'."
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1261 (interactive "p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1262 (if (null command)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1263 (setq command vi-last-change-command))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1264 (if (null command)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1265 (message "No last change command available.")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1266 (while (> count 0)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1267 (apply (car command) (cdr command))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1268 (setq count (1- count)))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1269
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1270 (defun vi-kill-char (count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1271 "Kill COUNT chars from current point."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1272 (interactive "*p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1273 (delete-char count t) ; save in kill ring
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1274 (vi-set-last-change-command 'delete-char count t))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1275
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1276 (defun vi-transpose-objects (arg unit)
1577
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
1277 "Transpose objects.
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
1278 The following char specifies unit of objects to be
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1279 transposed -- \"c\" for chars, \"l\" for lines, \"w\" for words, \"s\" for
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1280 sexp, \"p\" for paragraph.
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1281 For the use of the prefix-arg, refer to individual functions called."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1282 (interactive "*P\nc")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1283 (if (char-equal unit ??)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1284 (progn
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1285 (message "Transpose: c(har), l(ine), p(aragraph), s(-exp), w(ord),")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1286 (setq unit (read-char))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1287 (vi-set-last-change-command 'vi-transpose-objects arg unit)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1288 (cond ((char-equal unit ?c) (transpose-chars arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1289 ((char-equal unit ?l) (transpose-lines (vi-prefix-numeric-value arg)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1290 ((char-equal unit ?p) (transpose-paragraphs (vi-prefix-numeric-value arg)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1291 ((char-equal unit ?s) (transpose-sexps (vi-prefix-numeric-value arg)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1292 ((char-equal unit ?w) (transpose-words (vi-prefix-numeric-value arg)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1293 (t (vi-transpose-objects arg ??))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1294
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1295 (defun vi-query-replace (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1296 "Query replace, use regexp version if ARG is non-nil."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1297 (interactive "*P")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1298 (let ((rcmd (if arg 'query-replace-regexp 'query-replace)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1299 (call-interactively rcmd nil)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1300
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1301 (defun vi-replace (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1302 "Replace strings, use regexp version if ARG is non-nil."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1303 (interactive "*P")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1304 (let ((rcmd (if arg 'replace-regexp 'replace-string)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1305 (call-interactively rcmd nil)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38431
diff changeset
1306
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1307 (defun vi-adjust-window (arg position)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1308 "Move current line to the top/center/bottom of the window."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1309 (interactive "p\nc")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1310 (cond ((char-equal position ?\r) (recenter 0))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1311 ((char-equal position ?-) (recenter -1))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1312 ((char-equal position ?.) (recenter (/ (window-height) 2)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1313 (t (message "Move current line to: \\r(top) -(bottom) .(middle)")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1314 (setq position (read-char))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1315 (vi-adjust-window arg position))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1316
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1317 (defun vi-goto-column (col)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1318 "Go to given column of the current line."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1319 (interactive "p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1320 (let ((opoint (point)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1321 (beginning-of-line)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1322 (while (> col 1)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1323 (if (eolp)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1324 (setq col 0)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1325 (forward-char 1)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1326 (setq col (1- col))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1327 (if (= col 1)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1328 t
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1329 (goto-char opoint)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1330 (ding))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1331
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1332 (defun vi-name-last-change-or-macro (arg char)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38431
diff changeset
1333 "Give name to the last change command or just defined kbd macro.
1577
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
1334 If prefix ARG is given, name last macro, otherwise name last change command.
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
1335 The following CHAR will be the name for the command or macro."
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1336 (interactive "P\nc")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1337 (if arg
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1338 (name-last-kbd-macro (intern (char-to-string char)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1339 (if (eq (car vi-last-change-command) 'vi-first-redo-insertion)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1340 (let* ((args (cdr vi-last-change-command)) ; save the insertion text
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1341 (str (buffer-substring (nth 0 args) (nth 1 args)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1342 (overwrite-p (nth 2 args))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1343 (prefix-code (nth 3 args)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1344 (vi-set-last-change-command 'vi-more-redo-insertion str
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1345 overwrite-p prefix-code)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1346 (fset (intern (char-to-string char)) vi-last-change-command)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38431
diff changeset
1347
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1348 (defun vi-call-named-change-or-macro (count char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1349 "Execute COUNT times the keyboard macro definition named by the following CHAR."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1350 (interactive "p\nc")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1351 (if (stringp (symbol-function (intern (char-to-string char))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1352 (execute-kbd-macro (intern (char-to-string char)) count)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1353 (vi-redo-last-change-command count (symbol-function (intern (char-to-string char))))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1354
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1355 (defun vi-change-case (arg) ; could be made as an operator ?
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1356 "Change the case of the char after point."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1357 (interactive "*p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1358 (catch 'exit
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1359 (if (looking-at "[a-z]")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1360 (upcase-region (point) (+ (point) arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1361 (if (looking-at "[A-Z]")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1362 (downcase-region (point) (+ (point) arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1363 (ding)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1364 (throw 'exit nil)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1365 (vi-set-last-change-command 'vi-change-case arg) ;should avoid redundant save
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1366 (forward-char arg)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1367
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1368 (defun vi-ask-for-info (char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1369 "Inquire status info. The next CHAR will specify the particular info requested."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1370 (interactive "c")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1371 (cond ((char-equal char ?l) (what-line))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1372 ((char-equal char ?c) (what-cursor-position))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1373 ((char-equal char ?p) (what-page))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1374 (t (message "Ask for: l(ine number), c(ursor position), p(age number)")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1375 (setq char (read-char))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1376 (vi-ask-for-info char))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1377
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1378 (defun vi-mark-region (arg region)
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 1577
diff changeset
1379 "Mark region appropriately. The next char REGION is d(efun),s(-exp),b(uffer),
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1380 p(aragraph), P(age), f(unction in C/Pascal etc.), w(ord), e(nd of sentence),
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1381 l(ines)."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1382 (interactive "p\nc")
9865
9ca8b94a9f07 (vi-kill-region): Pass args to kill-region.
Karl Heuer <kwzh@gnu.org>
parents: 9842
diff changeset
1383 (cond ((char-equal region ?d) (mark-defun))
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1384 ((char-equal region ?s) (mark-sexp arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1385 ((char-equal region ?b) (mark-whole-buffer))
9865
9ca8b94a9f07 (vi-kill-region): Pass args to kill-region.
Karl Heuer <kwzh@gnu.org>
parents: 9842
diff changeset
1386 ((char-equal region ?p) (mark-paragraph))
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1387 ((char-equal region ?P) (mark-page arg))
63942
c9581f50bd50 (vi-mark-region): Use c-mark-function.
Richard M. Stallman <rms@gnu.org>
parents: 63401
diff changeset
1388 ((char-equal region ?f) (c-mark-function))
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1389 ((char-equal region ?w) (mark-word arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1390 ((char-equal region ?e) (mark-end-of-sentence arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1391 ((char-equal region ?l) (vi-mark-lines arg))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1392 (t (message "Mark: d(efun),s(-exp),b(uf),p(arag),P(age),f(unct),w(ord),e(os),l(ines)")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1393 (setq region (read-char))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1394 (vi-mark-region arg region))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1395
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1396 (defun vi-mark-lines (num)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1397 "Mark NUM of lines from current line as current region."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1398 (beginning-of-line 1)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1399 (push-mark)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1400 (end-of-line num))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1401
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1402 (defun vi-verify-spelling (arg unit)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1403 "Verify spelling for the objects specified by char UNIT : [b(uffer),
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1404 r(egion), s(tring), w(ord) ]."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1405 (interactive "P\nc")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1406 (setq prefix-arg arg) ; seems not needed
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1407 (cond ((char-equal unit ?b) (call-interactively 'spell-buffer))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1408 ((char-equal unit ?r) (call-interactively 'spell-region))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1409 ((char-equal unit ?s) (call-interactively 'spell-string))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1410 ((char-equal unit ?w) (call-interactively 'spell-word))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1411 (t (message "Spell check: b(uffer), r(egion), s(tring), w(ord)")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1412 (setq unit (read-char))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1413 (vi-verify-spelling arg unit))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1414
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1415 (defun vi-do-old-mode-C-c-command (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1416 "This is a hack for accessing mode specific C-c commands in vi-mode."
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1417 (interactive "P")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1418 (let ((cmd (lookup-key vi-mode-old-local-map
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1419 (concat "\C-c" (char-to-string (read-char))))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1420 (if (catch 'exit-vi-mode ; kludge hack due to dynamic binding
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1421 ; of case-fold-search
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1422 (if (null cmd)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1423 (progn (ding) nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1424 (let ((case-fold-search vi-mode-old-case-fold)) ; a hack
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1425 (setq prefix-arg arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1426 (command-execute cmd nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1427 nil)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1428 (progn
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1429 (vi-back-to-old-mode)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1430 (setq prefix-arg arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1431 (command-execute cmd nil)))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1432
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1433 (defun vi-quote-words (arg char)
1577
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
1434 "Quote ARG words from the word point is on with pattern specified by CHAR.
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
1435 Currently, CHAR could be [,{,(,\",',`,<,*, etc."
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1436 (interactive "*p\nc")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1437 (while (not (string-match "[[({<\"'`*]" (char-to-string char)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1438 (message "Enter any of [,{,(,<,\",',`,* as quoting character.")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1439 (setq char (read-char)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1440 (vi-set-last-change-command 'vi-quote-words arg char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1441 (if (not (looking-at "\\<")) (forward-word -1))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1442 (insert char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1443 (cond ((char-equal char ?[) (setq char ?]))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1444 ((char-equal char ?{) (setq char ?}))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1445 ((char-equal char ?<) (setq char ?>))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1446 ((char-equal char ?() (setq char ?)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1447 ((char-equal char ?`) (setq char ?')))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1448 (vi-end-of-word arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1449 (forward-char 1)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1450 (insert char))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1451
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1452 (defun vi-locate-def ()
1577
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
1453 "Locate definition in current file for the name before the point.
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
1454 It assumes a `(def..' always starts at the beginning of a line."
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1455 (interactive)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1456 (let (name)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1457 (save-excursion
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1458 (setq name (buffer-substring (progn (vi-backward-blank-delimited-word 1)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1459 (skip-chars-forward "^a-zA-Z")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1460 (point))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1461 (progn (vi-end-of-blank-delimited-word 1)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1462 (forward-char)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1463 (skip-chars-backward "^a-zA-Z")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1464 (point)))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1465 (set-mark-command nil)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1466 (goto-char (point-min))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1467 (if (re-search-forward (concat "^(def[unvarconst ]*" name) nil t)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1468 nil
53863
3c9fc6a0a6db (vi-mode): Remove extra format string argument.
Andreas Schwab <schwab@suse.de>
parents: 52401
diff changeset
1469 (ding)
3c9fc6a0a6db (vi-mode): Remove extra format string argument.
Andreas Schwab <schwab@suse.de>
parents: 52401
diff changeset
1470 (message "No definition for \"%s\" in current file." name)
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1471 (set-mark-command t))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1472
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1473 (defun vi-split-open-line (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1474 "Insert a newline and leave point before it.
1577
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
1475 With ARG, inserts that many newlines."
6
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1476 (interactive "*p")
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1477 (vi-goto-insert-state 1
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1478 (list (function (lambda (arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1479 (let ((flag (and (bolp) (not (bobp)))))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1480 (if flag (forward-char -1))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1481 (while (> arg 0)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1482 (save-excursion
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1483 (insert ?\n)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1484 (if fill-prefix (insert fill-prefix)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1485 (setq arg (1- arg)))
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1486 (if flag (forward-char 1))))) arg)
058329560a88 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1487 t))
657
fec3f9a1e3e5 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
1488
18383
11218164bc54 Add provide call.
Richard M. Stallman <rms@gnu.org>
parents: 17979
diff changeset
1489 (provide 'vi)
11218164bc54 Add provide call.
Richard M. Stallman <rms@gnu.org>
parents: 17979
diff changeset
1490
60902
7160fe3a7ef1 find-file-hooks -> find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53863
diff changeset
1491 ;; arch-tag: ac9bdac3-8acb-4ddd-bdae-c6dd873153b3
657
fec3f9a1e3e5 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
1492 ;;; vi.el ends here