annotate lisp/viper/viper-cmd.el @ 175:2d532a89d707 r20-3b14

Import from CVS: tag r20-3b14
author cvs
date Mon, 13 Aug 2007 09:50:14 +0200
parents 0132846995bd
children bfd6434d15b3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1 ;;; viper-cmd.el --- Vi command support for Viper
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2 ;; Copyright (C) 1997 Free Software Foundation, Inc.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
5 ;; Code
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
6
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
7 (provide 'viper-cmd)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
8 (require 'advice)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
9
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
10 ;; Compiler pacifier
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
11 (defvar vip-minibuffer-current-face)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
12 (defvar vip-minibuffer-insert-face)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
13 (defvar vip-minibuffer-vi-face)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
14 (defvar vip-minibuffer-emacs-face)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
15 (defvar viper-always)
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
16 (defvar vip-mode-string)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
17 (defvar vip-custom-file-name)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
18 (defvar iso-accents-mode)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
19 (defvar zmacs-region-stays)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
20 (defvar mark-even-if-inactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
21
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
22 ;; loading happens only in non-interactive compilation
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
23 ;; in order to spare non-viperized emacs from being viperized
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
24 (if noninteractive
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
25 (eval-when-compile
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
26 (let ((load-path (cons (expand-file-name ".") load-path)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
27 (or (featurep 'viper-util)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
28 (load "viper-util.el" nil nil 'nosuffix))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
29 (or (featurep 'viper-keym)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
30 (load "viper-keym.el" nil nil 'nosuffix))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
31 (or (featurep 'viper-mous)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
32 (load "viper-mous.el" nil nil 'nosuffix))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
33 (or (featurep 'viper-macs)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
34 (load "viper-macs.el" nil nil 'nosuffix))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
35 (or (featurep 'viper-ex)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
36 (load "viper-ex.el" nil nil 'nosuffix))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
37 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
38 ;; end pacifier
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
39
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
40
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
41 (require 'viper-util)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
42 (require 'viper-keym)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
43 (require 'viper-mous)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
44 (require 'viper-macs)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
45 (require 'viper-ex)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
46
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
47
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
48
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
49 ;; Generic predicates
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
50
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
51 ;; These test functions are shamelessly lifted from vip 4.4.2 by Aamod Sane
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
52
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
53 ;; generate test functions
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
54 ;; given symbol foo, foo-p is the test function, foos is the set of
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
55 ;; Viper command keys
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
56 ;; (macroexpand '(vip-test-com-defun foo))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
57 ;; (defun foo-p (com) (consp (memq (if (< com 0) (- com) com) foos)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
58
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
59 (defmacro vip-test-com-defun (name)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
60 (let* ((snm (symbol-name name))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
61 (nm-p (intern (concat snm "-p")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
62 (nms (intern (concat snm "s"))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
63 (` (defun (, nm-p) (com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
64 (consp (memq (if (< com 0) (- com) com) (, nms)))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
65
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
66 ;; Variables for defining VI commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
67
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
68 ;; Modifying commands that can be prefixes to movement commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
69 (defconst vip-prefix-commands '(?c ?d ?y ?! ?= ?# ?< ?> ?\"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
70 ;; define vip-prefix-command-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
71 (vip-test-com-defun vip-prefix-command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
72
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
73 ;; Commands that are pairs eg. dd. r and R here are a hack
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
74 (defconst vip-charpair-commands '(?c ?d ?y ?! ?= ?< ?> ?r ?R))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
75 ;; define vip-charpair-command-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
76 (vip-test-com-defun vip-charpair-command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
77
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
78 (defconst vip-movement-commands '(?b ?B ?e ?E ?f ?F ?G ?h ?H ?j ?k ?l
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
79 ?H ?M ?L ?n ?t ?T ?w ?W ?$ ?%
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
80 ?^ ?( ?) ?- ?+ ?| ?{ ?} ?[ ?] ?' ?`
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
81 ?; ?, ?0 ?? ?/ ?\C-m ?\
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
82 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
83 "Movement commands")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
84 ;; define vip-movement-command-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
85 (vip-test-com-defun vip-movement-command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
86
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
87 ;; Vi digit commands
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
88 (defconst vip-digit-commands '(?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
89
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
90 ;; define vip-digit-command-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
91 (vip-test-com-defun vip-digit-command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
92
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
93 ;; Commands that can be repeated by . (dotted)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
94 (defconst vip-dotable-commands '(?c ?d ?C ?s ?S ?D ?> ?<))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
95 ;; define vip-dotable-command-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
96 (vip-test-com-defun vip-dotable-command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
97
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
98 ;; Commands that can follow a #
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
99 (defconst vip-hash-commands '(?c ?C ?g ?q ?s))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
100 ;; define vip-hash-command-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
101 (vip-test-com-defun vip-hash-command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
102
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
103 ;; Commands that may have registers as prefix
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
104 (defconst vip-regsuffix-commands '(?d ?y ?Y ?D ?p ?P ?x ?X))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
105 ;; define vip-regsuffix-command-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
106 (vip-test-com-defun vip-regsuffix-command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
107
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
108 (defconst vip-vi-commands (append vip-movement-commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
109 vip-digit-commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
110 vip-dotable-commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
111 vip-charpair-commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
112 vip-hash-commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
113 vip-prefix-commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
114 vip-regsuffix-commands)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
115 "The list of all commands in Vi-state.")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
116 ;; define vip-vi-command-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
117 (vip-test-com-defun vip-vi-command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
118
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
119
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
120 ;;; CODE
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
121
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
122 ;; sentinels
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
123
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
124 ;; Runs vip-after-change-functions inside after-change-functions
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
125 (defun vip-after-change-sentinel (beg end len)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
126 (let ((list vip-after-change-functions))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
127 (while list
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
128 (funcall (car list) beg end len)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
129 (setq list (cdr list)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
130
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
131 ;; Runs vip-before-change-functions inside before-change-functions
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
132 (defun vip-before-change-sentinel (beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
133 (let ((list vip-before-change-functions))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
134 (while list
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
135 (funcall (car list) beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
136 (setq list (cdr list)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
137
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
138 (defsubst vip-post-command-sentinel ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
139 (run-hooks 'vip-post-command-hooks))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
140
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
141 (defsubst vip-pre-command-sentinel ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
142 (run-hooks 'vip-pre-command-hooks))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
143
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
144 ;; Needed so that Viper will be able to figure the last inserted
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
145 ;; chunk of text with reasonable accuracy.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
146 (defsubst vip-insert-state-post-command-sentinel ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
147 (if (and (memq vip-current-state '(insert-state replace-state))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
148 vip-insert-point
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
149 (>= (point) vip-insert-point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
150 (setq vip-last-posn-while-in-insert-state (point-marker)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
151 (if (eq vip-current-state 'insert-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
152 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
153 (or (stringp vip-saved-cursor-color)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
154 (string= (vip-get-cursor-color) vip-insert-state-cursor-color)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
155 (setq vip-saved-cursor-color (vip-get-cursor-color)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
156 (if (stringp vip-saved-cursor-color)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
157 (vip-change-cursor-color vip-insert-state-cursor-color))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
158 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
159 (if (and (eq this-command 'dabbrev-expand)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
160 (integerp vip-pre-command-point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
161 (> vip-insert-point vip-pre-command-point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
162 (move-marker vip-insert-point vip-pre-command-point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
163 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
164
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
165 (defsubst vip-insert-state-pre-command-sentinel ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
166 (or (memq this-command '(self-insert-command))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
167 (memq (vip-event-key last-command-event)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
168 '(up down left right (meta f) (meta b)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
169 (control n) (control p) (control f) (control b)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
170 (vip-restore-cursor-color-after-insert))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
171 (if (and (eq this-command 'dabbrev-expand)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
172 (markerp vip-insert-point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
173 (marker-position vip-insert-point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
174 (setq vip-pre-command-point (marker-position vip-insert-point))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
175
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
176 (defsubst vip-R-state-post-command-sentinel ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
177 ;; Restoring cursor color is needed despite
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
178 ;; vip-replace-state-pre-command-sentinel: When you jump to another buffer in
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
179 ;; another frame, the pre-command hook won't change cursor color to default
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
180 ;; in that other frame. So, if the second frame cursor was red and we set
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
181 ;; the point outside the replacement region, then the cursor color will
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
182 ;; remain red. Restoring the default, below, prevents this.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
183 (if (and (<= (vip-replace-start) (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
184 (<= (point) (vip-replace-end)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
185 (vip-change-cursor-color vip-replace-overlay-cursor-color)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
186 (vip-restore-cursor-color-after-replace)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
187 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
188
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
189 ;; to speed up, don't change cursor color before self-insert
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
190 ;; and common move commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
191 (defsubst vip-replace-state-pre-command-sentinel ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
192 (or (memq this-command '(self-insert-command))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
193 (memq (vip-event-key last-command-event)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
194 '(up down left right (meta f) (meta b)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
195 (control n) (control p) (control f) (control b)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
196 (vip-restore-cursor-color-after-replace)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
197
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
198 (defun vip-replace-state-post-command-sentinel ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
199 ;; Restoring cursor color is needed despite
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
200 ;; vip-replace-state-pre-command-sentinel: When one jumps to another buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
201 ;; in another frame, the pre-command hook won't change cursor color to
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
202 ;; default in that other frame. So, if the second frame cursor was red and
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
203 ;; we set the point outside the replacement region, then the cursor color
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
204 ;; will remain red. Restoring the default, below, fixes this problem.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
205 ;;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
206 ;; We optimize for self-insert-command's here, since they either don't change
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
207 ;; cursor color or, if they terminate replace mode, the color will be changed
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
208 ;; in vip-finish-change
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
209 (or (memq this-command '(self-insert-command))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
210 (vip-restore-cursor-color-after-replace))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
211 (cond
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
212 ((eq vip-current-state 'replace-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
213 ;; delete characters to compensate for inserted chars.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
214 (let ((replace-boundary (vip-replace-end)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
215 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
216 (goto-char vip-last-posn-in-replace-region)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
217 (delete-char vip-replace-chars-to-delete)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
218 (setq vip-replace-chars-to-delete 0
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
219 vip-replace-chars-deleted 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
220 ;; terminate replace mode if reached replace limit
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
221 (if (= vip-last-posn-in-replace-region
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
222 (vip-replace-end))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
223 (vip-finish-change vip-last-posn-in-replace-region)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
224
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
225 (if (and (<= (vip-replace-start) (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
226 (<= (point) replace-boundary))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
227 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
228 ;; the state may have changed in vip-finish-change above
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
229 (if (eq vip-current-state 'replace-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
230 (vip-change-cursor-color vip-replace-overlay-cursor-color))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
231 (setq vip-last-posn-in-replace-region (point-marker))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
232 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
233
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
234 (t ;; terminate replace mode if changed Viper states.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
235 (vip-finish-change vip-last-posn-in-replace-region))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
236
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
237
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
238 ;; changing mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
239
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
240 ;; Change state to NEW-STATE---either emacs-state, vi-state, or insert-state.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
241 (defun vip-change-state (new-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
242 ;; Keep vip-post/pre-command-hooks fresh.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
243 ;; We remove then add vip-post/pre-command-sentinel since it is very
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
244 ;; desirable that vip-pre-command-sentinel is the last hook and
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
245 ;; vip-post-command-sentinel is the first hook.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
246 (remove-hook 'post-command-hook 'vip-post-command-sentinel)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
247 (add-hook 'post-command-hook 'vip-post-command-sentinel)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
248 (remove-hook 'pre-command-hook 'vip-pre-command-sentinel)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
249 (add-hook 'pre-command-hook 'vip-pre-command-sentinel t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
250 ;; These hooks will be added back if switching to insert/replace mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
251 (vip-remove-hook 'vip-post-command-hooks
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
252 'vip-insert-state-post-command-sentinel)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
253 (vip-remove-hook 'vip-pre-command-hooks
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
254 'vip-insert-state-pre-command-sentinel)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
255 (cond ((eq new-state 'vi-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
256 (cond ((member vip-current-state '(insert-state replace-state))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
257
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
258 ;; move vip-last-posn-while-in-insert-state
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
259 ;; This is a normal hook that is executed in insert/replace
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
260 ;; states after each command. In Vi/Emacs state, it does
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
261 ;; nothing. We need to execute it here to make sure that
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
262 ;; the last posn was recorded when we hit ESC.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
263 ;; It may be left unrecorded if the last thing done in
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
264 ;; insert/repl state was dabbrev-expansion or abbrev
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
265 ;; expansion caused by hitting ESC
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
266 (vip-insert-state-post-command-sentinel)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
267
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
268 (condition-case conds
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
269 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
270 (vip-save-last-insertion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
271 vip-insert-point
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
272 vip-last-posn-while-in-insert-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
273 (if vip-began-as-replace
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
274 (setq vip-began-as-replace nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
275 ;; repeat insert commands if numerical arg > 1
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
276 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
277 (vip-repeat-insert-command))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
278 (error
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
279 (vip-message-conditions conds)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
280
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
281 (if (> (length vip-last-insertion) 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
282 (vip-push-onto-ring vip-last-insertion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
283 'vip-insertion-ring))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
284
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
285 (if vip-ex-style-editing-in-insert
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
286 (or (bolp) (backward-char 1))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
287 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
288
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
289 ;; insert or replace
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
290 ((memq new-state '(insert-state replace-state))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
291 (if (memq vip-current-state '(emacs-state vi-state))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
292 (vip-move-marker-locally 'vip-insert-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
293 (vip-move-marker-locally 'vip-last-posn-while-in-insert-state (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
294 (vip-add-hook 'vip-post-command-hooks
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
295 'vip-insert-state-post-command-sentinel t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
296 (vip-add-hook 'vip-pre-command-hooks
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
297 'vip-insert-state-pre-command-sentinel t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
298 ) ; outermost cond
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
299
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
300 ;; Nothing needs to be done to switch to emacs mode! Just set some
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
301 ;; variables, which is already done in vip-change-state-to-emacs!
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
302
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
303 (setq vip-current-state new-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
304 (vip-normalize-minor-mode-map-alist)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
305 (vip-adjust-keys-for new-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
306 (vip-set-mode-vars-for new-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
307 (vip-refresh-mode-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
308 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
309
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
310
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
311
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
312 (defun vip-adjust-keys-for (state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
313 "Make necessary adjustments to keymaps before entering STATE."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
314 (cond ((memq state '(insert-state replace-state))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
315 (if vip-auto-indent
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
316 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
317 (define-key vip-insert-basic-map "\C-m" 'vip-autoindent)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
318 (if vip-want-emacs-keys-in-insert
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
319 ;; expert
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
320 (define-key vip-insert-basic-map "\C-j" nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
321 ;; novice
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
322 (define-key vip-insert-basic-map "\C-j" 'vip-autoindent)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
323 (define-key vip-insert-basic-map "\C-m" nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
324 (define-key vip-insert-basic-map "\C-j" nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
325
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
326 (setq vip-insert-diehard-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
327 (not vip-want-emacs-keys-in-insert))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
328
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
329 (if vip-want-ctl-h-help
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
330 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
331 (define-key vip-insert-basic-map [(control h)] 'help-command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
332 (define-key vip-replace-map [(control h)] 'help-command))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
333 (define-key vip-insert-basic-map
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
334 [(control h)] 'vip-del-backward-char-in-insert)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
335 (define-key vip-replace-map
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
336 [(control h)] 'vip-del-backward-char-in-replace)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
337
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
338 (t ; Vi state
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
339 (setq vip-vi-diehard-minor-mode (not vip-want-emacs-keys-in-vi))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
340 (if vip-want-ctl-h-help
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
341 (define-key vip-vi-basic-map [(control h)] 'help-command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
342 (define-key vip-vi-basic-map [(control h)] 'vip-backward-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
343 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
344
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
345
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
346 ;; Normalizes minor-mode-map-alist by putting Viper keymaps first.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
347 ;; This ensures that Viper bindings are in effect, regardless of which minor
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
348 ;; modes were turned on by the user or by other packages.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
349 (defun vip-normalize-minor-mode-map-alist ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
350 (setq minor-mode-map-alist
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
351 (vip-append-filter-alist
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
352 (list
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
353 (cons 'vip-vi-intercept-minor-mode vip-vi-intercept-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
354 (cons 'vip-vi-minibuffer-minor-mode vip-minibuffer-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
355 (cons 'vip-vi-local-user-minor-mode vip-vi-local-user-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
356 (cons 'vip-vi-kbd-minor-mode vip-vi-kbd-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
357 (cons 'vip-vi-global-user-minor-mode vip-vi-global-user-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
358 (cons 'vip-vi-state-modifier-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
359 (if (keymapp
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
360 (cdr (assoc major-mode vip-vi-state-modifier-alist)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
361 (cdr (assoc major-mode vip-vi-state-modifier-alist))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
362 vip-empty-keymap))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
363 (cons 'vip-vi-diehard-minor-mode vip-vi-diehard-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
364 (cons 'vip-vi-basic-minor-mode vip-vi-basic-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
365 (cons 'vip-insert-intercept-minor-mode vip-insert-intercept-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
366 (cons 'vip-replace-minor-mode vip-replace-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
367 ;; vip-insert-minibuffer-minor-mode must come after
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
368 ;; vip-replace-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
369 (cons 'vip-insert-minibuffer-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
370 vip-minibuffer-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
371 (cons 'vip-insert-local-user-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
372 vip-insert-local-user-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
373 (cons 'vip-insert-kbd-minor-mode vip-insert-kbd-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
374 (cons 'vip-insert-global-user-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
375 vip-insert-global-user-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
376 (cons 'vip-insert-state-modifier-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
377 (if (keymapp
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
378 (cdr
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
379 (assoc major-mode vip-insert-state-modifier-alist)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
380 (cdr
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
381 (assoc major-mode vip-insert-state-modifier-alist))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
382 vip-empty-keymap))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
383 (cons 'vip-insert-diehard-minor-mode vip-insert-diehard-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
384 (cons 'vip-insert-basic-minor-mode vip-insert-basic-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
385 (cons 'vip-emacs-intercept-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
386 vip-emacs-intercept-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
387 (cons 'vip-emacs-local-user-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
388 vip-emacs-local-user-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
389 (cons 'vip-emacs-kbd-minor-mode vip-emacs-kbd-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
390 (cons 'vip-emacs-global-user-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
391 vip-emacs-global-user-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
392 (cons 'vip-emacs-state-modifier-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
393 (if (keymapp
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
394 (cdr
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
395 (assoc major-mode vip-emacs-state-modifier-alist)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
396 (cdr
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
397 (assoc major-mode vip-emacs-state-modifier-alist))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
398 vip-empty-keymap))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
399 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
400 minor-mode-map-alist)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
401
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
402
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
403
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
404
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
405
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
406 ;; Viper mode-changing commands and utilities
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
407
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
408 ;; Modifies mode-line-buffer-identification.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
409 (defun vip-refresh-mode-line ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
410 (setq vip-mode-string
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
411 (cond ((eq vip-current-state 'emacs-state) vip-emacs-state-id)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
412 ((eq vip-current-state 'vi-state) vip-vi-state-id)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
413 ((eq vip-current-state 'replace-state) vip-replace-state-id)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
414 ((eq vip-current-state 'insert-state) vip-insert-state-id)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
415
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
416 ;; Sets Viper mode string in global-mode-string
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
417 (force-mode-line-update))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
418
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
419
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
420 ;; Switch from Insert state to Vi state.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
421 (defun vip-exit-insert-state ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
422 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
423 (vip-change-state-to-vi))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
424
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
425 (defun vip-set-mode-vars-for (state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
426 "Sets Viper minor mode variables to put Viper's state STATE in effect."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
427
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
428 ;; Emacs state
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
429 (setq vip-vi-minibuffer-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
430 vip-insert-minibuffer-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
431 vip-vi-intercept-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
432 vip-insert-intercept-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
433
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
434 vip-vi-local-user-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
435 vip-vi-kbd-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
436 vip-vi-global-user-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
437 vip-vi-state-modifier-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
438 vip-vi-diehard-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
439 vip-vi-basic-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
440
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
441 vip-replace-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
442
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
443 vip-insert-local-user-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
444 vip-insert-kbd-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
445 vip-insert-global-user-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
446 vip-insert-state-modifier-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
447 vip-insert-diehard-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
448 vip-insert-basic-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
449 vip-emacs-intercept-minor-mode t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
450 vip-emacs-local-user-minor-mode t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
451 vip-emacs-kbd-minor-mode (not (vip-is-in-minibuffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
452 vip-emacs-global-user-minor-mode t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
453 vip-emacs-state-modifier-minor-mode t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
454 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
455
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
456 ;; Vi state
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
457 (if (eq state 'vi-state) ; adjust for vi-state
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
458 (setq
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
459 vip-vi-intercept-minor-mode t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
460 vip-vi-minibuffer-minor-mode (vip-is-in-minibuffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
461 vip-vi-local-user-minor-mode t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
462 vip-vi-kbd-minor-mode (not (vip-is-in-minibuffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
463 vip-vi-global-user-minor-mode t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
464 vip-vi-state-modifier-minor-mode t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
465 ;; don't let the diehard keymap block command completion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
466 ;; and other things in the minibuffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
467 vip-vi-diehard-minor-mode (not
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
468 (or vip-want-emacs-keys-in-vi
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
469 (vip-is-in-minibuffer)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
470 vip-vi-basic-minor-mode t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
471 vip-emacs-intercept-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
472 vip-emacs-local-user-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
473 vip-emacs-kbd-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
474 vip-emacs-global-user-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
475 vip-emacs-state-modifier-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
476 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
477
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
478 ;; Insert and Replace states
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
479 (if (member state '(insert-state replace-state))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
480 (setq
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
481 vip-insert-intercept-minor-mode t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
482 vip-replace-minor-mode (eq state 'replace-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
483 vip-insert-minibuffer-minor-mode (vip-is-in-minibuffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
484 vip-insert-local-user-minor-mode t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
485 vip-insert-kbd-minor-mode (not (vip-is-in-minibuffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
486 vip-insert-global-user-minor-mode t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
487 vip-insert-state-modifier-minor-mode t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
488 ;; don't let the diehard keymap block command completion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
489 ;; and other things in the minibuffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
490 vip-insert-diehard-minor-mode (not
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
491 (or vip-want-emacs-keys-in-insert
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
492 (vip-is-in-minibuffer)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
493 vip-insert-basic-minor-mode t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
494 vip-emacs-intercept-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
495 vip-emacs-local-user-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
496 vip-emacs-kbd-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
497 vip-emacs-global-user-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
498 vip-emacs-state-modifier-minor-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
499 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
500
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
501 ;; minibuffer faces
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
502 (if (vip-has-face-support-p)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
503 (setq vip-minibuffer-current-face
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
504 (cond ((eq state 'emacs-state) vip-minibuffer-emacs-face)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
505 ((eq state 'vi-state) vip-minibuffer-vi-face)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
506 ((memq state '(insert-state replace-state))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
507 vip-minibuffer-insert-face))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
508
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
509 (if (vip-is-in-minibuffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
510 (vip-set-minibuffer-overlay))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
511 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
512
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
513 ;; This also takes care of the annoying incomplete lines in files.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
514 ;; Also, this fixes `undo' to work vi-style for complex commands.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
515 (defun vip-change-state-to-vi ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
516 "Change Viper state to Vi."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
517 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
518 (if (and vip-first-time (not (vip-is-in-minibuffer)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
519 (viper-mode)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
520 (if overwrite-mode (overwrite-mode nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
521 (if abbrev-mode (expand-abbrev))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
522 (if (and auto-fill-function (> (current-column) fill-column))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
523 (funcall auto-fill-function))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
524 ;; don't leave whitespace lines around
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
525 (if (and (memq last-command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
526 '(vip-autoindent
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
527 vip-open-line vip-Open-line
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
528 vip-replace-state-exit-cmd))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
529 (vip-over-whitespace-line))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
530 (indent-to-left-margin))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
531 (vip-add-newline-at-eob-if-necessary)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
532 (if vip-undo-needs-adjustment (vip-adjust-undo))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
533 (vip-change-state 'vi-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
534
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
535 ;; always turn off iso-accents-mode, or else we won't be able to use the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
536 ;; keys `,',^ in Vi state, as they will do accents instead of Vi actions.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
537 (if (and (boundp 'iso-accents-mode) iso-accents-mode)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
538 (iso-accents-mode -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
539
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
540 (vip-restore-cursor-color-after-insert)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
541
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
542 ;; Protection against user errors in hooks
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
543 (condition-case conds
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
544 (run-hooks 'vip-vi-state-hook)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
545 (error
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
546 (vip-message-conditions conds)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
547
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
548 (defun vip-change-state-to-insert ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
549 "Change Viper state to Insert."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
550 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
551 (vip-change-state 'insert-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
552 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
553 (iso-accents-mode 1)) ; turn iso accents on
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
554
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
555 (or (stringp vip-saved-cursor-color)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
556 (string= (vip-get-cursor-color) vip-insert-state-cursor-color)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
557 (setq vip-saved-cursor-color (vip-get-cursor-color)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
558 ;; Commented out, because if vip-change-state-to-insert is executed
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
559 ;; non-interactively then the old cursor color may get lost. Same old Emacs
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
560 ;; bug related to local variables?
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
561 ;;;(if (stringp vip-saved-cursor-color)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
562 ;;; (vip-change-cursor-color vip-insert-state-cursor-color))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
563 ;; Protection against user errors in hooks
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
564 (condition-case conds
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
565 (run-hooks 'vip-insert-state-hook)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
566 (error
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
567 (vip-message-conditions conds))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
568
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
569 (defsubst vip-downgrade-to-insert ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
570 (setq vip-current-state 'insert-state
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
571 vip-replace-minor-mode nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
572 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
573
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
574
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
575
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
576 ;; Change to replace state. When the end of replacement region is reached,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
577 ;; replace state changes to insert state.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
578 (defun vip-change-state-to-replace (&optional non-R-cmd)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
579 (vip-change-state 'replace-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
580 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
581 (iso-accents-mode 1)) ; turn iso accents on
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
582 ;; Run insert-state-hook
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
583 (condition-case conds
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
584 (run-hooks 'vip-insert-state-hook 'vip-replace-state-hook)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
585 (error
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
586 (vip-message-conditions conds)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
587
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
588 (if non-R-cmd
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
589 (vip-start-replace)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
590 ;; 'R' is implemented using Emacs's overwrite-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
591 (vip-start-R-mode))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
592 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
593
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
594
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
595 (defun vip-change-state-to-emacs ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
596 "Change Viper state to Emacs."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
597 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
598 (vip-change-state 'emacs-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
599 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
600 (iso-accents-mode 1)) ; turn iso accents on
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
601
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
602 ;; Protection agains user errors in hooks
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
603 (condition-case conds
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
604 (run-hooks 'vip-emacs-state-hook)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
605 (error
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
606 (vip-message-conditions conds))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
607
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
608 ;; escape to emacs mode termporarily
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
609 (defun vip-escape-to-emacs (arg &optional events)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
610 "Escape to Emacs state from Vi state for one Emacs command.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
611 ARG is used as the prefix value for the executed command. If
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
612 EVENTS is a list of events, which become the beginning of the command."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
613 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
614 (if (= last-command-char ?\\)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
615 (message "Switched to EMACS state for the next command..."))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
616 (vip-escape-to-state arg events 'emacs-state))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
617
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
618 ;; escape to Vi mode termporarily
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
619 (defun vip-escape-to-vi (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
620 "Escape from Emacs state to Vi state for one Vi 1-character command.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
621 If the Vi command that the user types has a prefix argument, e.g., `d2w', then
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
622 Vi's prefix argument will be used. Otherwise, the prefix argument passed to
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
623 `vip-escape-to-vi' is used."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
624 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
625 (message "Switched to VI state for the next command...")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
626 (vip-escape-to-state arg nil 'vi-state))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
627
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
628 ;; Escape to STATE mode for one Emacs command.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
629 (defun vip-escape-to-state (arg events state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
630 ;;(let (com key prefix-arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
631 (let (com key)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
632 ;; this temporarily turns off Viper's minor mode keymaps
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
633 (vip-set-mode-vars-for state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
634 (vip-normalize-minor-mode-map-alist)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
635 (if events (vip-set-unread-command-events events))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
636
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
637 ;; protect against keyboard quit and other errors
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
638 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
639 (let (vip-vi-kbd-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
640 vip-insert-kbd-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
641 vip-emacs-kbd-minor-mode)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
642 (unwind-protect
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
643 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
644 (setq com (key-binding (setq key
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
645 (if vip-xemacs-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
646 (read-key-sequence nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
647 (read-key-sequence nil t)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
648 ;; In case of binding indirection--chase definitions.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
649 ;; Have to do it here because we execute this command under
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
650 ;; different keymaps, so command-execute may not do the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
651 ;; right thing there
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
652 (while (vectorp com) (setq com (key-binding com))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
653 nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
654 ;; Execute command com in the original Viper state, not in state
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
655 ;; `state'. Otherwise, if we switch buffers while executing the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
656 ;; escaped to command, Viper's mode vars will remain those of
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
657 ;; `state'. When we return to the orig buffer, the bindings will be
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
658 ;; screwed up.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
659 (vip-set-mode-vars-for vip-current-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
660
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
661 ;; this-command, last-command-char, last-command-event
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
662 (setq this-command com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
663 (if vip-xemacs-p ; XEmacs represents key sequences as vectors
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
664 (setq last-command-event (vip-copy-event (vip-seq-last-elt key))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
665 last-command-char (event-to-character last-command-event))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
666 ;; Emacs represents them as sequences (str or vec)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
667 (setq last-command-event (vip-copy-event (vip-seq-last-elt key))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
668 last-command-char last-command-event))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
669
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
670 (if (commandp com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
671 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
672 (setq prefix-arg (or prefix-arg arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
673 (command-execute com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
674 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
675 (quit (ding))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
676 (error (beep 1))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
677 ;; set state in the new buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
678 (vip-set-mode-vars-for vip-current-state))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
679
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
680 (defun vip-exec-form-in-vi (form)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
681 "Execute FORM in Vi state, regardless of the Ccurrent Vi state."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
682 (let ((buff (current-buffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
683 result)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
684 (vip-set-mode-vars-for 'vi-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
685
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
686 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
687 (setq result (eval form))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
688 (error
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
689 (signal 'quit nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
690
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
691 (if (not (equal buff (current-buffer))) ; cmd switched buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
692 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
693 (set-buffer buff)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
694 (vip-set-mode-vars-for vip-current-state)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
695 (vip-set-mode-vars-for vip-current-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
696 result))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
697
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
698 (defun vip-exec-form-in-emacs (form)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
699 "Execute FORM in Emacs, temporarily disabling Viper's minor modes.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
700 Similar to vip-escape-to-emacs, but accepts forms rather than keystrokes."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
701 (let ((buff (current-buffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
702 result)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
703 (vip-set-mode-vars-for 'emacs-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
704 (setq result (eval form))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
705 (if (not (equal buff (current-buffer))) ; cmd switched buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
706 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
707 (set-buffer buff)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
708 (vip-set-mode-vars-for vip-current-state)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
709 (vip-set-mode-vars-for vip-current-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
710 result))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
711
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
712
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
713 ;; This is needed because minor modes sometimes override essential Viper
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
714 ;; bindings. By letting Viper know which files these modes are in, it will
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
715 ;; arrange to reorganize minor-mode-map-alist so that things will work right.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
716 (defun vip-harness-minor-mode (load-file)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
717 "Familiarize Viper with a minor mode defined in LOAD_FILE.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
718 Minor modes that have their own keymaps may overshadow Viper keymaps.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
719 This function is designed to make Viper aware of the packages that define
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
720 such minor modes.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
721 Usage:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
722 (vip-harness-minor-mode load-file)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
723
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
724 LOAD-FILE is a name of the file where the specific minor mode is defined.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
725 Suffixes such as .el or .elc should be stripped."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
726
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
727 (interactive "sEnter name of the load file: ")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
728
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
729 (vip-eval-after-load load-file '(vip-normalize-minor-mode-map-alist))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
730
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
731 ;; Change the default for minor-mode-map-alist each time a harnessed minor
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
732 ;; mode adds its own keymap to the a-list.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
733 (vip-eval-after-load
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
734 load-file '(setq-default minor-mode-map-alist minor-mode-map-alist))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
735 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
736
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
737
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
738 (defun vip-ESC (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
739 "Emulate ESC key in Emacs.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
740 Prevents multiple escape keystrokes if vip-no-multiple-ESC is true.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
741 If vip-no-multiple-ESC is 'twice double ESC would ding in vi-state.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
742 Other ESC sequences are emulated via the current Emacs's major mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
743 keymap. This is more convenient on TTYs, since this won't block
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
744 function keys such as up,down, etc. ESC will also will also work as
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
745 a Meta key in this case. When vip-no-multiple-ESC is nil, ESC functions
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
746 as a Meta key and any number of multiple escapes is allowed."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
747 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
748 (let (char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
749 (cond ((and (not vip-no-multiple-ESC) (eq vip-current-state 'vi-state))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
750 (setq char (vip-read-char-exclusive))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
751 (vip-escape-to-emacs arg (list ?\e char) ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
752 ((and (eq vip-no-multiple-ESC 'twice)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
753 (eq vip-current-state 'vi-state))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
754 (setq char (vip-read-char-exclusive))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
755 (if (= char (string-to-char vip-ESC-key))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
756 (ding)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
757 (vip-escape-to-emacs arg (list ?\e char) )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
758 (t (ding)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
759 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
760
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
761 (defun vip-alternate-Meta-key (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
762 "Simulate Emacs Meta key."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
763 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
764 (sit-for 1) (message "ESC-")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
765 (vip-escape-to-emacs arg '(?\e)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
766
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
767 (defun vip-toggle-key-action ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
768 "Action bound to `vip-toggle-key'."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
769 (interactive)
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
770 (if (and (< viper-expert-level 2) (equal vip-toggle-key "\C-z"))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
771 (if (vip-window-display-p)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
772 (vip-iconify)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
773 (suspend-emacs))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
774 (vip-change-state-to-emacs)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
775
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
776
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
777 ;; Intercept ESC sequences on dumb terminals.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
778 ;; Based on the idea contributed by Marcelino Veiga Tuimil <mveiga@dit.upm.es>
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
779
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
780 ;; Check if last key was ESC and if so try to reread it as a function key.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
781 ;; But only if there are characters to read during a very short time.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
782 ;; Returns the last event, if any.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
783 (defun vip-envelop-ESC-key ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
784 (let ((event last-input-event)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
785 (keyseq [nil])
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
786 inhibit-quit)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
787 (if (vip-ESC-event-p event)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
788 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
789 (if (vip-fast-keysequence-p)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
790 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
791 (let (minor-mode-map-alist)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
792 (vip-set-unread-command-events event)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
793 (setq keyseq
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
794 (funcall
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
795 (ad-get-orig-definition 'read-key-sequence) nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
796 ) ; let
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
797 ;; If keyseq translates into something that still has ESC
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
798 ;; at the beginning, separate ESC from the rest of the seq.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
799 ;; In XEmacs we check for events that are keypress meta-key
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
800 ;; and convert them into [escape key]
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
801 ;;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
802 ;; This is needed for the following reason:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
803 ;; If ESC is the first symbol, we interpret it as if the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
804 ;; user typed ESC and then quickly some other symbols.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
805 ;; If ESC is not the first one, then the key sequence
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
806 ;; entered was apparently translated into a function key or
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
807 ;; something (e.g., one may have
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
808 ;; (define-key function-key-map "\e[192z" [f11])
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
809 ;; which would translate the escape-sequence generated by
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
810 ;; f11 in an xterm window into the symbolic key f11.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
811 ;;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
812 ;; If `first-key' is not an ESC event, we make it into the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
813 ;; last-command-event in order to pretend that this key was
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
814 ;; pressed. This is needed to allow arrow keys to be bound to
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
815 ;; macros. Otherwise, vip-exec-mapped-kbd-macro will think that
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
816 ;; the last event was ESC and so it'll execute whatever is
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
817 ;; bound to ESC. (Viper macros can't be bound to
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
818 ;; ESC-sequences).
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
819 (let* ((first-key (elt keyseq 0))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
820 (key-mod (event-modifiers first-key)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
821 (cond ((vip-ESC-event-p first-key)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
822 ;; put keys following ESC on the unread list
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
823 ;; and return ESC as the key-sequence
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
824 (vip-set-unread-command-events (subseq keyseq 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
825 (setq last-input-event event
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
826 keyseq (if vip-emacs-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
827 "\e"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
828 (vector (character-to-event ?\e)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
829 ((and vip-xemacs-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
830 (key-press-event-p first-key)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
831 (equal '(meta) key-mod))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
832 (vip-set-unread-command-events
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
833 (vconcat (vector
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
834 (character-to-event (event-key first-key)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
835 (subseq keyseq 1)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
836 (setq last-input-event event
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
837 keyseq (vector (character-to-event ?\e))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
838 ((eventp first-key)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
839 (setq last-command-event (vip-copy-event first-key)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
840 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
841 ) ; end progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
842
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
843 ;; this is escape event with nothing after it
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
844 ;; put in unread-command-event and then re-read
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
845 (vip-set-unread-command-events event)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
846 (setq keyseq
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
847 (funcall (ad-get-orig-definition 'read-key-sequence) nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
848 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
849 ;; not an escape event
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
850 (setq keyseq (vector event)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
851 keyseq))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
852
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
853
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
854
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
855 ;; Listen to ESC key.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
856 ;; If a sequence of keys starting with ESC is issued with very short delays,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
857 ;; interpret these keys in Emacs mode, so ESC won't be interpreted as a Vi key.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
858 (defun vip-intercept-ESC-key ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
859 "Function that implements ESC key in Viper emulation of Vi."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
860 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
861 (let ((cmd (or (key-binding (vip-envelop-ESC-key))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
862 '(lambda () (interactive) (error "")))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
863
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
864 ;; call the actual function to execute ESC (if no other symbols followed)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
865 ;; or the key bound to the ESC sequence (if the sequence was issued
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
866 ;; with very short delay between characters.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
867 (if (eq cmd 'vip-intercept-ESC-key)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
868 (setq cmd
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
869 (cond ((eq vip-current-state 'vi-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
870 'vip-ESC)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
871 ((eq vip-current-state 'insert-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
872 'vip-exit-insert-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
873 ((eq vip-current-state 'replace-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
874 'vip-replace-state-exit-cmd)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
875 (t 'vip-change-state-to-vi)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
876 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
877 (call-interactively cmd)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
878
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
879
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
880
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
881
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
882 ;; prefix argument for Vi mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
883
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
884 ;; In Vi mode, prefix argument is a dotted pair (NUM . COM) where NUM
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
885 ;; represents the numeric value of the prefix argument and COM represents
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
886 ;; command prefix such as "c", "d", "m" and "y".
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
887
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
888 ;; Get value part of prefix-argument ARG.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
889 (defsubst vip-p-val (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
890 (cond ((null arg) 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
891 ((consp arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
892 (if (or (null (car arg)) (equal (car arg) '(nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
893 1 (car arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
894 (t arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
895
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
896 ;; Get raw value part of prefix-argument ARG.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
897 (defsubst vip-P-val (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
898 (cond ((consp arg) (car arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
899 (t arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
900
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
901 ;; Get com part of prefix-argument ARG.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
902 (defsubst vip-getcom (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
903 (cond ((null arg) nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
904 ((consp arg) (cdr arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
905 (t nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
906
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
907 ;; Get com part of prefix-argument ARG and modify it.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
908 (defun vip-getCom (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
909 (let ((com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
910 (cond ((equal com ?c) ?C)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
911 ((equal com ?d) ?D)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
912 ((equal com ?y) ?Y)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
913 (t com))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
914
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
915
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
916 ;; Compute numeric prefix arg value.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
917 ;; Invoked by EVENT. COM is the command part obtained so far.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
918 (defun vip-prefix-arg-value (event com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
919 (let (value func)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
920 ;; read while number
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
921 (while (and (vip-characterp event) (>= event ?0) (<= event ?9))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
922 (setq value (+ (* (if (integerp value) value 0) 10) (- event ?0)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
923 (setq event (vip-read-event-convert-to-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
924
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
925 (setq prefix-arg value)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
926 (if com (setq prefix-arg (cons prefix-arg com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
927 (while (eq event ?U)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
928 (vip-describe-arg prefix-arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
929 (setq event (vip-read-event-convert-to-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
930
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
931 (if (or com (and (not (eq vip-current-state 'vi-state))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
932 ;; make sure it is a Vi command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
933 (vip-characterp event) (vip-vi-command-p event)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
934 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
935 ;; If appears to be one of the vi commands,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
936 ;; then execute it with funcall and clear prefix-arg in order to not
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
937 ;; confuse subsequent commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
938 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
939 ;; last-command-char is the char we want emacs to think was typed
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
940 ;; last. If com is not nil, the vip-digit-argument command was called
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
941 ;; from within vip-prefix-arg command, such as `d', `w', etc., i.e.,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
942 ;; the user typed, say, d2. In this case, `com' would be `d', `w',
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
943 ;; etc.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
944 ;; If vip-digit-argument was invoked by vip-escape-to-vi (which is
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
945 ;; indicated by the fact that the current state is not vi-state),
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
946 ;; then `event' represents the vi command to be executed (e.g., `d',
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
947 ;; `w', etc). Again, last-command-char must make emacs believe that
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
948 ;; this is the command we typed.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
949 (setq last-command-char (or com event))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
950 (setq func (vip-exec-form-in-vi
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
951 (` (key-binding (char-to-string (, event))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
952 (funcall func prefix-arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
953 (setq prefix-arg nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
954 ;; some other command -- let emacs do it in its own way
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
955 (vip-set-unread-command-events event))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
956 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
957
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
958
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
959 ;; Vi operator as prefix argument."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
960 (defun vip-prefix-arg-com (char value com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
961 (let ((cont t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
962 cmd-info mv-or-digit-cmd)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
963 (while (and cont
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
964 (memq char
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
965 (list ?c ?d ?y ?! ?< ?> ?= ?# ?r ?R ?\"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
966 vip-buffer-search-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
967 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
968 ;; this means that we already have a command character, so we
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
969 ;; construct a com list and exit while. however, if char is "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
970 ;; it is an error.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
971 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
972 ;; new com is (CHAR . OLDCOM)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
973 (if (memq char '(?# ?\")) (error ""))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
974 (setq com (cons char com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
975 (setq cont nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
976 ;; If com is nil we set com as char, and read more. Again, if char
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
977 ;; is ", we read the name of register and store it in vip-use-register.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
978 ;; if char is !, =, or #, a complete com is formed so we exit the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
979 ;; while loop.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
980 (cond ((memq char '(?! ?=))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
981 (setq com char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
982 (setq char (read-char))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
983 (setq cont nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
984 ((= char ?#)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
985 ;; read a char and encode it as com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
986 (setq com (+ 128 (read-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
987 (setq char (read-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
988 ((= char ?\")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
989 (let ((reg (read-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
990 (if (vip-valid-register reg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
991 (setq vip-use-register reg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
992 (error ""))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
993 (setq char (read-char))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
994 (t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
995 (setq com char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
996 (setq char (read-char))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
997
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
998 (if (atom com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
999 ;; `com' is a single char, so we construct the command argument
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1000 ;; and if `char' is `?', we describe the arg; otherwise
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1001 ;; we prepare the command that will be executed at the end.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1002 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1003 (setq cmd-info (cons value com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1004 (while (= char ?U)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1005 (vip-describe-arg cmd-info)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1006 (setq char (read-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1007 ;; `char' is a movement cmd, a digit arg cmd, or a register cmd---so we
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1008 ;; execute it at the very end
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1009 (or (vip-movement-command-p char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1010 (vip-digit-command-p char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1011 (vip-regsuffix-command-p char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1012 (error ""))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1013 (setq mv-or-digit-cmd
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1014 (vip-exec-form-in-vi
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1015 (` (key-binding (char-to-string (, char)))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1016
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1017 ;; as com is non-nil, this means that we have a command to execute
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1018 (if (memq (car com) '(?r ?R))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1019 ;; execute apropriate region command.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1020 (let ((char (car com)) (com (cdr com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1021 (setq prefix-arg (cons value com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1022 (if (= char ?r) (vip-region prefix-arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1023 (vip-Region prefix-arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1024 ;; reset prefix-arg
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1025 (setq prefix-arg nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1026 ;; otherwise, reset prefix arg and call appropriate command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1027 (setq value (if (null value) 1 value))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1028 (setq prefix-arg nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1029 (cond ((equal com '(?c . ?c)) (vip-line (cons value ?C)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1030 ((equal com '(?d . ?d)) (vip-line (cons value ?D)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1031 ((equal com '(?d . ?y)) (vip-yank-defun))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1032 ((equal com '(?y . ?y)) (vip-line (cons value ?Y)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1033 ((equal com '(?< . ?<)) (vip-line (cons value ?<)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1034 ((equal com '(?> . ?>)) (vip-line (cons value ?>)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1035 ((equal com '(?! . ?!)) (vip-line (cons value ?!)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1036 ((equal com '(?= . ?=)) (vip-line (cons value ?=)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1037 (t (error "")))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1038
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1039 (if mv-or-digit-cmd
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1040 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1041 (setq last-command-char char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1042 (setq last-command-event
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1043 (vip-copy-event
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1044 (if vip-xemacs-p (character-to-event char) char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1045 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1046 (funcall mv-or-digit-cmd cmd-info)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1047 (error
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1048 (error "")))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1049 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1050
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1051 (defun vip-describe-arg (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1052 (let (val com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1053 (setq val (vip-P-val arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1054 com (vip-getcom arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1055 (if (null val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1056 (if (null com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1057 (message "Value is nil, and command is nil")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1058 (message "Value is nil, and command is `%c'" com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1059 (if (null com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1060 (message "Value is `%d', and command is nil" val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1061 (message "Value is `%d', and command is `%c'" val com)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1062
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1063 (defun vip-digit-argument (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1064 "Begin numeric argument for the next command."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1065 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1066 (vip-leave-region-active)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1067 (vip-prefix-arg-value
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1068 last-command-char (if (consp arg) (cdr arg) nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1069
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1070 (defun vip-command-argument (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1071 "Accept a motion command as an argument."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1072 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1073 (let ((vip-inside-command-argument-action t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1074 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1075 (vip-prefix-arg-com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1076 last-command-char
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1077 (cond ((null arg) nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1078 ((consp arg) (car arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1079 ((integerp arg) arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1080 (t (error vip-InvalidCommandArgument)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1081 (cond ((null arg) nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1082 ((consp arg) (cdr arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1083 ((integerp arg) nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1084 (t (error vip-InvalidCommandArgument))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1085 (quit (setq vip-use-register nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1086 (signal 'quit nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1087 (vip-deactivate-mark)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1088
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1089
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1090 ;; repeat last destructive command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1091
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1092 ;; Append region to text in register REG.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1093 ;; START and END are buffer positions indicating what to append.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1094 (defsubst vip-append-to-register (reg start end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1095 (set-register reg (concat (if (stringp (get-register reg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1096 (get-register reg) "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1097 (buffer-substring start end))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1098
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1099 ;; Saves last inserted text for possible use by vip-repeat command.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1100 (defun vip-save-last-insertion (beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1101 (setq vip-last-insertion (buffer-substring beg end))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1102 (or (< (length vip-d-com) 5)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1103 (setcar (nthcdr 4 vip-d-com) vip-last-insertion))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1104 (or (null vip-command-ring)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1105 (ring-empty-p vip-command-ring)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1106 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1107 (setcar (nthcdr 4 (vip-current-ring-item vip-command-ring))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1108 vip-last-insertion)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1109 ;; del most recent elt, if identical to the second most-recent
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1110 (vip-cleanup-ring vip-command-ring)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1111 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1112
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1113 (defsubst vip-yank-last-insertion ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1114 "Inserts the text saved by the previous vip-save-last-insertion command."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1115 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1116 (insert vip-last-insertion)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1117 (error nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1118
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1119
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1120 ;; define functions to be executed
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1121
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1122 ;; invoked by the `C' command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1123 (defun vip-exec-change (m-com com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1124 (or (and (markerp vip-com-point) (marker-position vip-com-point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1125 (set-marker vip-com-point (point) (current-buffer)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1126 ;; handle C cmd at the eol and at eob.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1127 (if (or (and (eolp) (= vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1128 (= vip-com-point (point-max)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1129 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1130 (insert " ")(backward-char 1)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1131 (if (= vip-com-point (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1132 (vip-forward-char-carefully))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1133 (if (= com ?c)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1134 (vip-change vip-com-point (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1135 (vip-change-subr vip-com-point (point))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1136
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1137 ;; this is invoked by vip-substitute-line
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1138 (defun vip-exec-Change (m-com com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1139 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1140 (set-mark vip-com-point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1141 (vip-enlarge-region (mark t) (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1142 (if vip-use-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1143 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1144 (cond ((vip-valid-register vip-use-register '(letter digit))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1145 ;;(vip-valid-register vip-use-register '(letter)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1146 (copy-to-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1147 vip-use-register (mark t) (point) nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1148 ((vip-valid-register vip-use-register '(Letter))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1149 (vip-append-to-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1150 (downcase vip-use-register) (mark t) (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1151 (t (setq vip-use-register nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1152 (error vip-InvalidRegister vip-use-register)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1153 (setq vip-use-register nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1154 (delete-region (mark t) (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1155 (open-line 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1156 (if (= com ?C) (vip-change-mode-to-insert) (vip-yank-last-insertion)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1157
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1158 (defun vip-exec-delete (m-com com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1159 (or (and (markerp vip-com-point) (marker-position vip-com-point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1160 (set-marker vip-com-point (point) (current-buffer)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1161 (if vip-use-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1162 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1163 (cond ((vip-valid-register vip-use-register '(letter digit))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1164 ;;(vip-valid-register vip-use-register '(letter))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1165 (copy-to-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1166 vip-use-register vip-com-point (point) nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1167 ((vip-valid-register vip-use-register '(Letter))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1168 (vip-append-to-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1169 (downcase vip-use-register) vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1170 (t (setq vip-use-register nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1171 (error vip-InvalidRegister vip-use-register)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1172 (setq vip-use-register nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1173 (setq last-command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1174 (if (eq last-command 'd-command) 'kill-region nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1175 (kill-region vip-com-point (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1176 (setq this-command 'd-command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1177 (if vip-ex-style-motion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1178 (if (and (eolp) (not (bolp))) (backward-char 1))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1179
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1180 (defun vip-exec-Delete (m-com com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1181 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1182 (set-mark vip-com-point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1183 (vip-enlarge-region (mark t) (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1184 (if vip-use-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1185 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1186 (cond ((vip-valid-register vip-use-register '(letter digit))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1187 ;;(vip-valid-register vip-use-register '(letter))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1188 (copy-to-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1189 vip-use-register (mark t) (point) nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1190 ((vip-valid-register vip-use-register '(Letter))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1191 (vip-append-to-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1192 (downcase vip-use-register) (mark t) (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1193 (t (setq vip-use-register nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1194 (error vip-InvalidRegister vip-use-register)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1195 (setq vip-use-register nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1196 (setq last-command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1197 (if (eq last-command 'D-command) 'kill-region nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1198 (kill-region (mark t) (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1199 (if (eq m-com 'vip-line) (setq this-command 'D-command)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1200 (back-to-indentation))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1201
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1202 (defun vip-exec-yank (m-com com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1203 (or (and (markerp vip-com-point) (marker-position vip-com-point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1204 (set-marker vip-com-point (point) (current-buffer)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1205 (if vip-use-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1206 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1207 (cond ((vip-valid-register vip-use-register '(letter digit))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1208 ;; (vip-valid-register vip-use-register '(letter))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1209 (copy-to-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1210 vip-use-register vip-com-point (point) nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1211 ((vip-valid-register vip-use-register '(Letter))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1212 (vip-append-to-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1213 (downcase vip-use-register) vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1214 (t (setq vip-use-register nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1215 (error vip-InvalidRegister vip-use-register)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1216 (setq vip-use-register nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1217 (setq last-command nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1218 (copy-region-as-kill vip-com-point (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1219 (goto-char vip-com-point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1220
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1221 (defun vip-exec-Yank (m-com com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1222 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1223 (set-mark vip-com-point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1224 (vip-enlarge-region (mark t) (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1225 (if vip-use-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1226 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1227 (cond ((vip-valid-register vip-use-register '(letter digit))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1228 (copy-to-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1229 vip-use-register (mark t) (point) nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1230 ((vip-valid-register vip-use-register '(Letter))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1231 (vip-append-to-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1232 (downcase vip-use-register) (mark t) (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1233 (t (setq vip-use-register nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1234 (error vip-InvalidRegister vip-use-register)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1235 (setq vip-use-register nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1236 (setq last-command nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1237 (copy-region-as-kill (mark t) (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1238 (vip-deactivate-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1239 (goto-char vip-com-point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1240
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1241 (defun vip-exec-bang (m-com com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1242 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1243 (set-mark vip-com-point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1244 (vip-enlarge-region (mark t) (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1245 (shell-command-on-region
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1246 (mark t) (point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1247 (if (= com ?!)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1248 (setq vip-last-shell-com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1249 (vip-read-string-with-history
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1250 "!"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1251 nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1252 'vip-shell-history
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1253 (car vip-shell-history)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1254 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1255 vip-last-shell-com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1256 t)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1257
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1258 (defun vip-exec-equals (m-com com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1259 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1260 (set-mark vip-com-point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1261 (vip-enlarge-region (mark t) (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1262 (if (> (mark t) (point)) (exchange-point-and-mark))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1263 (indent-region (mark t) (point) nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1264
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1265 (defun vip-exec-shift (m-com com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1266 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1267 (set-mark vip-com-point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1268 (vip-enlarge-region (mark t) (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1269 (if (> (mark t) (point)) (exchange-point-and-mark))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1270 (indent-rigidly (mark t) (point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1271 (if (= com ?>)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1272 vip-shift-width
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1273 (- vip-shift-width))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1274 ;; return point to where it was before shift
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1275 (goto-char vip-com-point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1276
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1277 ;; this is needed because some commands fake com by setting it to ?r, which
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1278 ;; denotes repeated insert command.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1279 (defsubst vip-exec-dummy (m-com com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1280 nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1281
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1282 (defun vip-exec-buffer-search (m-com com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1283 (setq vip-s-string (buffer-substring (point) vip-com-point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1284 (setq vip-s-forward t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1285 (setq vip-search-history (cons vip-s-string vip-search-history))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1286 (vip-search vip-s-string vip-s-forward 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1287
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1288 (defvar vip-exec-array (make-vector 128 nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1289
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1290 ;; Using a dispatch array allows adding functions like buffer search
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1291 ;; without affecting other functions. Buffer search can now be bound
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1292 ;; to any character.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1293
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1294 (aset vip-exec-array ?c 'vip-exec-change)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1295 (aset vip-exec-array ?C 'vip-exec-Change)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1296 (aset vip-exec-array ?d 'vip-exec-delete)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1297 (aset vip-exec-array ?D 'vip-exec-Delete)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1298 (aset vip-exec-array ?y 'vip-exec-yank)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1299 (aset vip-exec-array ?Y 'vip-exec-Yank)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1300 (aset vip-exec-array ?r 'vip-exec-dummy)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1301 (aset vip-exec-array ?! 'vip-exec-bang)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1302 (aset vip-exec-array ?< 'vip-exec-shift)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1303 (aset vip-exec-array ?> 'vip-exec-shift)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1304 (aset vip-exec-array ?= 'vip-exec-equals)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1305
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1306
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1307
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1308 ;; This function is called by various movement commands to execute a
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1309 ;; destructive command on the region specified by the movement command. For
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1310 ;; instance, if the user types cw, then the command vip-forward-word will
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1311 ;; call vip-execute-com to execute vip-exec-change, which eventually will
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1312 ;; call vip-change to invoke the replace mode on the region.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1313 ;;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1314 ;; The list (M-COM VAL COM REG INSETED-TEXT COMMAND-KEYS) is set to
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1315 ;; vip-d-com for later use by vip-repeat.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1316 (defun vip-execute-com (m-com val com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1317 (let ((reg vip-use-register))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1318 ;; this is the special command `#'
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1319 (if (> com 128)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1320 (vip-special-prefix-com (- com 128))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1321 (let ((fn (aref vip-exec-array (if (< com 0) (- com) com))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1322 (if (null fn)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1323 (error "%c: %s" com vip-InvalidViCommand)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1324 (funcall fn m-com com))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1325 (if (vip-dotable-command-p com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1326 (vip-set-destructive-command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1327 (list m-com val
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1328 (if (memq com (list ?c ?C ?!)) (- com) com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1329 reg nil nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1330 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1331
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1332
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1333 (defun vip-repeat (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1334 "Re-execute last destructive command.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1335 Use the info in vip-d-com, which has the form
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1336 \(com val ch reg inserted-text command-keys\),
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1337 where `com' is the command to be re-executed, `val' is the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1338 argument to `com', `ch' is a flag for repeat, and `reg' is optional;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1339 if it exists, it is the name of the register for `com'.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1340 If the prefix argument, ARG, is non-nil, it is used instead of `val'."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1341 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1342 (let ((save-point (point)) ; save point before repeating prev cmd
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1343 ;; Pass along that we are repeating a destructive command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1344 ;; This tells vip-set-destructive-command not to update
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1345 ;; vip-command-ring
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1346 (vip-intermediate-command 'vip-repeat))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1347 (if (eq last-command 'vip-undo)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1348 ;; if the last command was vip-undo, then undo-more
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1349 (vip-undo-more)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1350 ;; otherwise execute the command stored in vip-d-com. if arg is non-nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1351 ;; its prefix value is used as new prefix value for the command.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1352 (let ((m-com (car vip-d-com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1353 (val (vip-P-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1354 (com (nth 2 vip-d-com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1355 (reg (nth 3 vip-d-com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1356 (if (null val) (setq val (nth 1 vip-d-com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1357 (if (null m-com) (error "No previous command to repeat."))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1358 (setq vip-use-register reg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1359 (if (nth 4 vip-d-com) ; text inserted by command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1360 (setq vip-last-insertion (nth 4 vip-d-com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1361 vip-d-char (nth 4 vip-d-com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1362 (funcall m-com (cons val com))
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1363 (cond ((and (< save-point (point)) vip-keep-point-on-repeat)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1364 (goto-char save-point)) ; go back to before repeat.
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1365 ((and (< save-point (point)) vip-ex-style-editing-in-insert)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1366 (or (bolp) (backward-char 1))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1367 (if (and (eolp) (not (bolp)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1368 (backward-char 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1369 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1370 (if vip-undo-needs-adjustment (vip-adjust-undo)) ; take care of undo
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1371 ;; If the prev cmd was rotating the command ring, this means that `.' has
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1372 ;; just executed a command from that ring. So, push it on the ring again.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1373 ;; If we are just executing previous command , then don't push vip-d-com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1374 ;; because vip-d-com is not fully constructed in this case (its keys and
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1375 ;; the inserted text may be nil). Besides, in this case, the command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1376 ;; executed by `.' is already on the ring.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1377 (if (eq last-command 'vip-display-current-destructive-command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1378 (vip-push-onto-ring vip-d-com 'vip-command-ring))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1379 (vip-deactivate-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1380 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1381
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1382 (defun vip-repeat-from-history ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1383 "Repeat a destructive command from history.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1384 Doesn't change vip-command-ring in any way, so `.' will work as before
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1385 executing this command.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1386 This command is supposed to be bound to a two-character Vi macro where
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1387 the second character is a digit 0 to 9. The digit indicates which
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1388 history command to execute. `<char>0' is equivalent to `.', `<char>1'
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1389 invokes the command before that, etc."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1390 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1391 (let* ((vip-intermediate-command 'repeating-display-destructive-command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1392 (idx (cond (vip-this-kbd-macro
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1393 (string-to-number
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1394 (symbol-name (elt vip-this-kbd-macro 1))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1395 (t 0)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1396 (num idx)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1397 (vip-d-com vip-d-com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1398
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1399 (or (and (numberp num) (<= 0 num) (<= num 9))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1400 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1401 (setq idx 0
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1402 num 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1403 (message
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1404 "`vip-repeat-from-history' must be invoked as a Vi macro bound to `<key><digit>'")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1405 (while (< 0 num)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1406 (setq vip-d-com (vip-special-ring-rotate1 vip-command-ring -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1407 (setq num (1- num)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1408 (vip-repeat nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1409 (while (> idx num)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1410 (vip-special-ring-rotate1 vip-command-ring 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1411 (setq num (1+ num)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1412 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1413
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1414
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1415 ;; The hash-command. It is invoked interactively by the key sequence #<char>.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1416 ;; The chars that can follow `#' are determined by vip-hash-command-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1417 (defun vip-special-prefix-com (char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1418 (cond ((= char ?c)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1419 (downcase-region (min vip-com-point (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1420 (max vip-com-point (point))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1421 ((= char ?C)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1422 (upcase-region (min vip-com-point (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1423 (max vip-com-point (point))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1424 ((= char ?g)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1425 (push-mark vip-com-point t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1426 (vip-global-execute))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1427 ((= char ?q)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1428 (push-mark vip-com-point t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1429 (vip-quote-region))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1430 ((= char ?s) (funcall vip-spell-function vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1431 (t (error "#%c: %s" char vip-InvalidViCommand))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1432
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1433
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1434 ;; undoing
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1435
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1436 (defun vip-undo ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1437 "Undo previous change."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1438 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1439 (message "undo!")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1440 (let ((modified (buffer-modified-p))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1441 (before-undo-pt (point-marker))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1442 (after-change-functions after-change-functions)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1443 undo-beg-posn undo-end-posn)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1444
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1445 ;; no need to remove this hook, since this var has scope inside a let.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1446 (add-hook 'after-change-functions
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1447 '(lambda (beg end len)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1448 (setq undo-beg-posn beg
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1449 undo-end-posn (or end beg))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1450
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1451 (undo-start)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1452 (undo-more 2)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1453 (setq undo-beg-posn (or undo-beg-posn before-undo-pt)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1454 undo-end-posn (or undo-end-posn undo-beg-posn))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1455
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1456 (goto-char undo-beg-posn)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1457 (sit-for 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1458 (if (and vip-keep-point-on-undo
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1459 (pos-visible-in-window-p before-undo-pt))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1460 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1461 (push-mark (point-marker) t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1462 (vip-sit-for-short 300)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1463 (goto-char undo-end-posn)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1464 (vip-sit-for-short 300)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1465 (if (and (> (abs (- undo-beg-posn before-undo-pt)) 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1466 (> (abs (- undo-end-posn before-undo-pt)) 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1467 (goto-char before-undo-pt)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1468 (goto-char undo-beg-posn)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1469 (push-mark before-undo-pt t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1470 (if (and (eolp) (not (bolp))) (backward-char 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1471 (if (not modified) (set-buffer-modified-p t)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1472 (setq this-command 'vip-undo))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1473
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1474 ;; Continue undoing previous changes.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1475 (defun vip-undo-more ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1476 (message "undo more!")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1477 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1478 (undo-more 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1479 (error (beep)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1480 (message "No further undo information in this buffer")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1481 (if (and (eolp) (not (bolp))) (backward-char 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1482 (setq this-command 'vip-undo))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1483
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1484 ;; The following two functions are used to set up undo properly.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1485 ;; In VI, unlike Emacs, if you open a line, say, and add a bunch of lines,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1486 ;; they are undone all at once.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1487 (defun vip-adjust-undo ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1488 (let ((inhibit-quit t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1489 tmp tmp2)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1490 (setq vip-undo-needs-adjustment nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1491 (if (listp buffer-undo-list)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1492 (if (setq tmp (memq vip-buffer-undo-list-mark buffer-undo-list))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1493 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1494 (setq tmp2 (cdr tmp)) ; the part after mark
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1495
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1496 ;; cut tail from buffer-undo-list temporarily by direct
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1497 ;; manipulation with pointers in buffer-undo-list
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1498 (setcdr tmp nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1499
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1500 (setq buffer-undo-list (delq nil buffer-undo-list))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1501 (setq buffer-undo-list
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1502 (delq vip-buffer-undo-list-mark buffer-undo-list))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1503 ;; restore tail of buffer-undo-list
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1504 (setq buffer-undo-list (nconc buffer-undo-list tmp2)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1505 (setq buffer-undo-list (delq nil buffer-undo-list))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1506
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1507
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1508 (defun vip-set-complex-command-for-undo ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1509 (if (listp buffer-undo-list)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1510 (if (not vip-undo-needs-adjustment)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1511 (let ((inhibit-quit t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1512 (setq buffer-undo-list
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1513 (cons vip-buffer-undo-list-mark buffer-undo-list))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1514 (setq vip-undo-needs-adjustment t)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1515
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1516
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1517
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1518
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1519 (defun vip-display-current-destructive-command ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1520 (let ((text (nth 4 vip-d-com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1521 (keys (nth 5 vip-d-com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1522 (max-text-len 30))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1523
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1524 (setq this-command 'vip-display-current-destructive-command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1525
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1526 (message " `.' runs %s%s"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1527 (concat "`" (vip-array-to-string keys) "'")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1528 (vip-abbreviate-string text max-text-len
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1529 " inserting `" "'" " ......."))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1530 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1531
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1532
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1533 ;; don't change vip-d-com if it was vip-repeat command invoked with `.'
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1534 ;; or in some other way (non-interactively).
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1535 (defun vip-set-destructive-command (list)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1536 (or (eq vip-intermediate-command 'vip-repeat)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1537 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1538 (setq vip-d-com list)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1539 (setcar (nthcdr 5 vip-d-com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1540 (vip-array-to-string (this-command-keys)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1541 (vip-push-onto-ring vip-d-com 'vip-command-ring))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1542
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1543 (defun vip-prev-destructive-command (next)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1544 "Find previous destructive command in the history of destructive commands.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1545 With prefix argument, find next destructive command."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1546 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1547 (let (cmd vip-intermediate-command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1548 (if (eq last-command 'vip-display-current-destructive-command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1549 ;; repeated search through command history
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1550 (setq vip-intermediate-command 'repeating-display-destructive-command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1551 ;; first search through command history--set temp ring
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1552 (setq vip-temp-command-ring (copy-list vip-command-ring)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1553 (setq cmd (if next
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1554 (vip-special-ring-rotate1 vip-temp-command-ring 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1555 (vip-special-ring-rotate1 vip-temp-command-ring -1)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1556 (if (null cmd)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1557 ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1558 (setq vip-d-com cmd))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1559 (vip-display-current-destructive-command)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1560
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1561 (defun vip-next-destructive-command ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1562 "Find next destructive command in the history of destructive commands."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1563 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1564 (vip-prev-destructive-command 'next))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1565
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1566 (defun vip-insert-prev-from-insertion-ring (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1567 "Cycle through insertion ring in the direction of older insertions.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1568 Undoes previous insertion and inserts new.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1569 With prefix argument, cycles in the direction of newer elements.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1570 In minibuffer, this command executes whatever the invocation key is bound
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1571 to in the global map, instead of cycling through the insertion ring."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1572 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1573 (let (vip-intermediate-command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1574 (if (eq last-command 'vip-insert-from-insertion-ring)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1575 (progn ; repeated search through insertion history
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1576 (setq vip-intermediate-command 'repeating-insertion-from-ring)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1577 (if (eq vip-current-state 'replace-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1578 (undo 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1579 (if vip-last-inserted-string-from-insertion-ring
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1580 (backward-delete-char
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1581 (length vip-last-inserted-string-from-insertion-ring))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1582 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1583 ;;first search through insertion history
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1584 (setq vip-temp-insertion-ring (copy-list vip-insertion-ring)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1585 (setq this-command 'vip-insert-from-insertion-ring)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1586 ;; so that things will be undone properly
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1587 (setq buffer-undo-list (cons nil buffer-undo-list))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1588 (setq vip-last-inserted-string-from-insertion-ring
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1589 (vip-special-ring-rotate1 vip-temp-insertion-ring (if arg 1 -1)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1590
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1591 ;; this change of vip-intermediate-command must come after
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1592 ;; vip-special-ring-rotate1, so that the ring will rotate, but before the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1593 ;; insertion.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1594 (setq vip-intermediate-command nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1595 (if vip-last-inserted-string-from-insertion-ring
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1596 (insert vip-last-inserted-string-from-insertion-ring))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1597 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1598
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1599 (defun vip-insert-next-from-insertion-ring ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1600 "Cycle through insertion ring in the direction of older insertions.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1601 Undo previous insertion and inserts new."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1602 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1603 (vip-insert-prev-from-insertion-ring 'next))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1604
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1605
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1606 ;; some region utilities
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1607
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1608 ;; If at the last line of buffer, add \\n before eob, if newline is missing.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1609 (defun vip-add-newline-at-eob-if-necessary ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1610 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1611 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1612 ;; make sure all lines end with newline, unless in the minibuffer or
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1613 ;; when requested otherwise (require-final-newline is nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1614 (if (and (eobp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1615 (not (bolp))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1616 require-final-newline
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1617 (not (vip-is-in-minibuffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1618 (not buffer-read-only))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1619 (insert "\n"))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1620
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1621 (defun vip-yank-defun ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1622 (mark-defun)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1623 (copy-region-as-kill (point) (mark t)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1624
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1625 ;; Enlarge region between BEG and END.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1626 (defun vip-enlarge-region (beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1627 (or beg (setq beg end)) ; if beg is nil, set to end
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1628 (or end (setq end beg)) ; if end is nil, set to beg
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1629
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1630 (if (< beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1631 (progn (goto-char beg) (set-mark end))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1632 (goto-char end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1633 (set-mark beg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1634 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1635 (exchange-point-and-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1636 (if (or (not (eobp)) (not (bolp))) (forward-line 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1637 (if (not (eobp)) (beginning-of-line))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1638 (if (> beg end) (exchange-point-and-mark)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1639
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1640
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1641 ;; Quote region by each line with a user supplied string.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1642 (defun vip-quote-region ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1643 (setq vip-quote-string
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1644 (vip-read-string-with-history
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1645 "Quote string: "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1646 nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1647 'vip-quote-region-history
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1648 vip-quote-string))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1649 (vip-enlarge-region (point) (mark t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1650 (if (> (point) (mark t)) (exchange-point-and-mark))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1651 (insert vip-quote-string)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1652 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1653 (forward-line 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1654 (while (and (< (point) (mark t)) (bolp))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1655 (insert vip-quote-string)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1656 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1657 (forward-line 1)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1658
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1659 ;; Tells whether BEG is on the same line as END.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1660 ;; If one of the args is nil, it'll return nil.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1661 (defun vip-same-line (beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1662 (let ((selective-display nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1663 (incr 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1664 temp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1665 (if (and beg end (> beg end))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1666 (setq temp beg
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1667 beg end
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1668 end temp))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1669 (if (and beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1670 (cond ((or (> beg (point-max)) (> end (point-max))) ; out of range
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1671 nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1672 (t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1673 ;; This 'if' is needed because Emacs treats the next empty line
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1674 ;; as part of the previous line.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1675 (if (= (vip-line-pos 'start) end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1676 (setq incr 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1677 (<= (+ incr (count-lines beg end)) 1))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1678 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1679
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1680
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1681 ;; Check if the string ends with a newline.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1682 (defun vip-end-with-a-newline-p (string)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1683 (or (string= string "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1684 (= (vip-seq-last-elt string) ?\n)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1685
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1686 (defun vip-tmp-insert-at-eob (msg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1687 (let ((savemax (point-max)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1688 (goto-char savemax)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1689 (insert msg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1690 (sit-for 2)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1691 (goto-char savemax) (delete-region (point) (point-max))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1692 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1693
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1694
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1695
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1696 ;;; Minibuffer business
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1697
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1698 (defsubst vip-set-minibuffer-style ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1699 (add-hook 'minibuffer-setup-hook 'vip-minibuffer-setup-sentinel))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1700
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1701
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1702 (defun vip-minibuffer-setup-sentinel ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1703 (let ((hook (if vip-vi-style-in-minibuffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1704 'vip-change-state-to-insert
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1705 'vip-change-state-to-emacs)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1706 (funcall hook)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1707 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1708
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1709 ;; Interpret last event in the local map
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1710 (defun vip-exit-minibuffer ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1711 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1712 (let (command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1713 (setq command (local-key-binding (char-to-string last-command-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1714 (if command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1715 (command-execute command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1716 (exit-minibuffer))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1717
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1718
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1719 ;;; Reading string with history
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1720
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1721 (defun vip-read-string-with-history (prompt &optional initial
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1722 history-var default keymap)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1723 ;; Read string, prompting with PROMPT and inserting the INITIAL
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1724 ;; value. Uses HISTORY-VAR. DEFAULT is the default value to accept if the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1725 ;; input is an empty string. Use KEYMAP, if given, or the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1726 ;; minibuffer-local-map.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1727 ;; Default value is displayed until the user types something in the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1728 ;; minibuffer.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1729 (let ((minibuffer-setup-hook
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1730 '(lambda ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1731 (if (stringp initial)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1732 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1733 ;; don't wait if we have unread events or in kbd macro
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1734 (or unread-command-events
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1735 executing-kbd-macro
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1736 (sit-for 840))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1737 (erase-buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1738 (insert initial)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1739 (vip-minibuffer-setup-sentinel)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1740 (val "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1741 (padding "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1742 temp-msg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1743
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1744 (setq keymap (or keymap minibuffer-local-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1745 initial (or initial "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1746 temp-msg (if default
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1747 (format "(default: %s) " default)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1748 ""))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1749
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1750 (setq vip-incomplete-ex-cmd nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1751 (setq val (read-from-minibuffer prompt
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1752 (concat temp-msg initial val padding)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1753 keymap nil history-var))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1754 (setq minibuffer-setup-hook nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1755 padding (vip-array-to-string (this-command-keys))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1756 temp-msg "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1757 ;; the following tries to be smart about what to put in history
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1758 (if (not (string= val (car (eval history-var))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1759 (set history-var (cons val (eval history-var))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1760 (if (or (string= (nth 0 (eval history-var)) (nth 1 (eval history-var)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1761 (string= (nth 0 (eval history-var)) ""))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1762 (set history-var (cdr (eval history-var))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1763 ;; If the user enters nothing but the prev cmd wasn't vip-ex,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1764 ;; vip-command-argument, or `! shell-command', this probably means
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1765 ;; that the user typed something then erased. Return "" in this case, not
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1766 ;; the default---the default is too confusing in this case.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1767 (cond ((and (string= val "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1768 (not (string= prompt "!")) ; was a `! shell-command'
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1769 (not (memq last-command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1770 '(vip-ex
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1771 vip-command-argument
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1772 t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1773 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1774 "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1775 ((string= val "") (or default ""))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1776 (t val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1777 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1778
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1779
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1780
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1781 ;; insertion commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1782
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1783 ;; Called when state changes from Insert Vi command mode.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1784 ;; Repeats the insertion command if Insert state was entered with prefix
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1785 ;; argument > 1.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1786 (defun vip-repeat-insert-command ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1787 (let ((i-com (car vip-d-com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1788 (val (nth 1 vip-d-com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1789 (char (nth 2 vip-d-com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1790 (if (and val (> val 1)) ; first check that val is non-nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1791 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1792 (setq vip-d-com (list i-com (1- val) ?r nil nil nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1793 (vip-repeat nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1794 (setq vip-d-com (list i-com val char nil nil nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1795 ))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1796
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1797 (defun vip-insert (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1798 "Insert before point."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1799 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1800 (vip-set-complex-command-for-undo)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1801 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1802 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1803 (vip-set-destructive-command (list 'vip-insert val ?r nil nil nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1804 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1805 (vip-loop val (vip-yank-last-insertion))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1806 (vip-change-state-to-insert))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1807
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1808 (defun vip-append (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1809 "Append after point."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1810 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1811 (vip-set-complex-command-for-undo)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1812 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1813 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1814 (vip-set-destructive-command (list 'vip-append val ?r nil nil nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1815 (if (not (eolp)) (forward-char))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1816 (if (equal com ?r)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1817 (vip-loop val (vip-yank-last-insertion))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1818 (vip-change-state-to-insert))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1819
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1820 (defun vip-Append (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1821 "Append at end of line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1822 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1823 (vip-set-complex-command-for-undo)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1824 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1825 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1826 (vip-set-destructive-command (list 'vip-Append val ?r nil nil nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1827 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1828 (if (equal com ?r)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1829 (vip-loop val (vip-yank-last-insertion))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1830 (vip-change-state-to-insert))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1831
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1832 (defun vip-Insert (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1833 "Insert before first non-white."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1834 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1835 (vip-set-complex-command-for-undo)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1836 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1837 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1838 (vip-set-destructive-command (list 'vip-Insert val ?r nil nil nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1839 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1840 (if (equal com ?r)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1841 (vip-loop val (vip-yank-last-insertion))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1842 (vip-change-state-to-insert))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1843
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1844 (defun vip-open-line (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1845 "Open line below."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1846 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1847 (vip-set-complex-command-for-undo)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1848 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1849 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1850 (vip-set-destructive-command (list 'vip-open-line val ?r nil nil nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1851 (let ((col (current-indentation)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1852 (if (equal com ?r)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1853 (vip-loop val
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1854 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1855 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1856 (newline 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1857 (if vip-auto-indent
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1858 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1859 (setq vip-cted t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1860 (if vip-electric-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1861 (indent-according-to-mode)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1862 (indent-to col))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1863 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1864 (vip-yank-last-insertion)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1865 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1866 (newline 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1867 (if vip-auto-indent
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1868 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1869 (setq vip-cted t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1870 (if vip-electric-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1871 (indent-according-to-mode)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1872 (indent-to col))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1873 (vip-change-state-to-insert)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1874
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1875 (defun vip-Open-line (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1876 "Open line above."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1877 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1878 (vip-set-complex-command-for-undo)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1879 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1880 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1881 (vip-set-destructive-command (list 'vip-Open-line val ?r nil nil nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1882 (let ((col (current-indentation)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1883 (if (equal com ?r)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1884 (vip-loop val
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1885 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1886 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1887 (open-line 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1888 (if vip-auto-indent
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1889 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1890 (setq vip-cted t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1891 (if vip-electric-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1892 (indent-according-to-mode)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1893 (indent-to col))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1894 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1895 (vip-yank-last-insertion)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1896 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1897 (open-line 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1898 (if vip-auto-indent
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1899 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1900 (setq vip-cted t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1901 (if vip-electric-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1902 (indent-according-to-mode)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1903 (indent-to col))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1904 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1905 (vip-change-state-to-insert)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1906
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1907 (defun vip-open-line-at-point (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1908 "Open line at point."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1909 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1910 (vip-set-complex-command-for-undo)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1911 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1912 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1913 (vip-set-destructive-command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1914 (list 'vip-open-line-at-point val ?r nil nil nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1915 (if (equal com ?r)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1916 (vip-loop val
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1917 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1918 (open-line 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1919 (vip-yank-last-insertion)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1920 (open-line 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1921 (vip-change-state-to-insert))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1922
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1923 (defun vip-substitute (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1924 "Substitute characters."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1925 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1926 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1927 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1928 (push-mark nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1929 (forward-char val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1930 (if (equal com ?r)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1931 (vip-change-subr (mark t) (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1932 (vip-change (mark t) (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1933 (vip-set-destructive-command (list 'vip-substitute val ?r nil nil nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1934 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1935
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1936 (defun vip-substitute-line (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1937 "Substitute lines."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1938 (interactive "p")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1939 (vip-set-complex-command-for-undo)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1940 (vip-line (cons arg ?C)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1941
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1942 ;; Prepare for replace
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1943 (defun vip-start-replace ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1944 (setq vip-began-as-replace t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1945 vip-sitting-in-replace t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1946 vip-replace-chars-to-delete 0
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1947 vip-replace-chars-deleted 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1948 (vip-add-hook 'vip-after-change-functions 'vip-replace-mode-spy-after t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1949 (vip-add-hook 'vip-before-change-functions 'vip-replace-mode-spy-before t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1950 ;; this will get added repeatedly, but no harm
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1951 (add-hook 'after-change-functions 'vip-after-change-sentinel t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1952 (add-hook 'before-change-functions 'vip-before-change-sentinel t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1953 (vip-move-marker-locally 'vip-last-posn-in-replace-region
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1954 (vip-replace-start))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1955 (vip-add-hook
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1956 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1957 (vip-add-hook
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1958 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1959 ;; guard against a smartie who switched from R-replace to normal replace
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1960 (vip-remove-hook
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1961 'vip-post-command-hooks 'vip-R-state-post-command-sentinel)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1962 (if overwrite-mode (overwrite-mode nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1963 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1964
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1965
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1966 ;; checks how many chars were deleted by the last change
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1967 (defun vip-replace-mode-spy-before (beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1968 (setq vip-replace-chars-deleted
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1969 (- end beg
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1970 (max 0 (- end (vip-replace-end)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1971 (max 0 (- (vip-replace-start) beg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1972 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1973
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1974 ;; Invoked as an after-change-function to set up parameters of the last change
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1975 (defun vip-replace-mode-spy-after (beg end length)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1976 (if (memq vip-intermediate-command '(repeating-insertion-from-ring))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1977 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1978 (setq vip-replace-chars-to-delete 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1979 (vip-move-marker-locally
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1980 'vip-last-posn-in-replace-region (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1981
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1982 (let (beg-col end-col real-end chars-to-delete)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1983 (setq real-end (min end (vip-replace-end)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1984 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1985 (goto-char beg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1986 (setq beg-col (current-column))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1987 (goto-char real-end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1988 (setq end-col (current-column)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1989
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1990 ;; If beg of change is outside the replacement region, then don't
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1991 ;; delete anything in the repl region (set chars-to-delete to 0).
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1992 ;;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1993 ;; This works fine except that we have to take special care of
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1994 ;; dabbrev-expand. The problem stems from new-dabbrev.el, which
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1995 ;; sometimes simply shifts the repl region rightwards, without
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1996 ;; deleting an equal amount of characters.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1997 ;;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1998 ;; The reason why new-dabbrev.el causes this are this:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1999 ;; if one dinamically completes a partial word that starts before the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2000 ;; replacement region (but ends inside) then new-dabbrev.el first
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2001 ;; moves cursor backwards, to the beginning of the word to be
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2002 ;; completed (say, pt A). Then it inserts the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2003 ;; completed word and then deletes the old, incomplete part.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2004 ;; Since the complete word is inserted at position before the repl
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2005 ;; region, the next If-statement would have set chars-to-delete to 0
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2006 ;; unless we check for the current command, which must be
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2007 ;; dabbrev-expand.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2008 ;;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2009 ;; In fact, it might be also useful to have overlays for insert
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2010 ;; regions as well, since this will let us capture the situation when
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2011 ;; dabbrev-expand goes back past the insertion point to find the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2012 ;; beginning of the word to be expanded.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2013 (if (or (and (<= (vip-replace-start) beg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2014 (<= beg (vip-replace-end)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2015 (and (= length 0) (eq this-command 'dabbrev-expand)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2016 (setq chars-to-delete
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2017 (max (- end-col beg-col) (- real-end beg) 0))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2018 (setq chars-to-delete 0))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2019
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2020 ;; if beg = last change position, it means that we are within the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2021 ;; same command that does multiple changes. Moreover, it means
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2022 ;; that we have two subsequent changes (insert/delete) that
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2023 ;; complement each other.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2024 (if (= beg (marker-position vip-last-posn-in-replace-region))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2025 (setq vip-replace-chars-to-delete
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2026 (- (+ chars-to-delete vip-replace-chars-to-delete)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2027 vip-replace-chars-deleted))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2028 (setq vip-replace-chars-to-delete chars-to-delete))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2029
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2030 (vip-move-marker-locally
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2031 'vip-last-posn-in-replace-region
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2032 (max (if (> end (vip-replace-end)) (vip-replace-start) end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2033 (or (marker-position vip-last-posn-in-replace-region)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2034 (vip-replace-start))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2035 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2036
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2037 (setq vip-replace-chars-to-delete
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2038 (max 0
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2039 (min vip-replace-chars-to-delete
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2040 (- (vip-replace-end) vip-last-posn-in-replace-region)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2041 (- (vip-line-pos 'end) vip-last-posn-in-replace-region)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2042 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2043 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2044
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2045
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2046 ;; Delete stuff between posn and the end of vip-replace-overlay-marker, if
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2047 ;; posn is within the overlay.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2048 (defun vip-finish-change (posn)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2049 (vip-remove-hook 'vip-after-change-functions 'vip-replace-mode-spy-after)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2050 (vip-remove-hook 'vip-before-change-functions 'vip-replace-mode-spy-before)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2051 (vip-remove-hook 'vip-post-command-hooks
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2052 'vip-replace-state-post-command-sentinel)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2053 (vip-remove-hook
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2054 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2055 (vip-restore-cursor-color-after-replace)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2056 (setq vip-sitting-in-replace nil) ; just in case we'll need to know it
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2057 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2058 (if (and
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2059 vip-replace-overlay
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2060 (>= posn (vip-replace-start))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2061 (< posn (vip-replace-end)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2062 (delete-region posn (vip-replace-end)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2063 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2064
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2065 (if (eq vip-current-state 'replace-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2066 (vip-downgrade-to-insert))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2067 ;; replace mode ended => nullify vip-last-posn-in-replace-region
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2068 (vip-move-marker-locally 'vip-last-posn-in-replace-region nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2069 (vip-hide-replace-overlay)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2070 (vip-refresh-mode-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2071 (vip-put-string-on-kill-ring vip-last-replace-region)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2072 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2073
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2074 ;; Make STRING be the first element of the kill ring.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2075 (defun vip-put-string-on-kill-ring (string)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2076 (setq kill-ring (cons string kill-ring))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2077 (if (> (length kill-ring) kill-ring-max)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2078 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2079 (setq kill-ring-yank-pointer kill-ring))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2080
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2081 (defun vip-finish-R-mode ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2082 (vip-remove-hook 'vip-post-command-hooks 'vip-R-state-post-command-sentinel)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2083 (vip-remove-hook
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2084 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2085 (vip-downgrade-to-insert))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2086
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2087 (defun vip-start-R-mode ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2088 ;; Leave arg as 1, not t: XEmacs insists that it must be a pos number
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2089 (overwrite-mode 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2090 (vip-add-hook
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2091 'vip-post-command-hooks 'vip-R-state-post-command-sentinel t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2092 (vip-add-hook
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2093 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2094 ;; guard against a smartie who switched from R-replace to normal replace
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2095 (vip-remove-hook
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2096 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2097 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2098
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2099
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2100
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2101 (defun vip-replace-state-exit-cmd ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2102 "Binding for keys that cause Replace state to switch to Vi or to Insert.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2103 These keys are ESC, RET, and LineFeed"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2104 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2105 (if overwrite-mode ;; If you are in replace mode invoked via 'R'
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2106 (vip-finish-R-mode)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2107 (vip-finish-change vip-last-posn-in-replace-region))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2108 (let (com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2109 (if (eq this-command 'vip-intercept-ESC-key)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2110 (setq com 'vip-exit-insert-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2111 (vip-set-unread-command-events last-input-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2112 (setq com (key-binding (read-key-sequence nil))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2113
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2114 (condition-case conds
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2115 (command-execute com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2116 (error
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2117 (vip-message-conditions conds)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2118 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2119 (vip-hide-replace-overlay))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2120
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2121 (defun vip-replace-state-carriage-return ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2122 "Implements carriage return in Viper replace state."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2123 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2124 ;; If Emacs start supporting overlay maps, as it currently supports
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2125 ;; text-property maps, we could do away with vip-replace-minor-mode and
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2126 ;; just have keymap attached to replace overlay. Then the "if part" of this
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2127 ;; statement can be deleted.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2128 (if (or (< (point) (vip-replace-start))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2129 (> (point) (vip-replace-end)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2130 (let (vip-replace-minor-mode com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2131 (vip-set-unread-command-events last-input-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2132 (setq com (key-binding (read-key-sequence nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2133 (condition-case conds
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2134 (command-execute com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2135 (error
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2136 (vip-message-conditions conds))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2137 (if (not vip-allow-multiline-replace-regions)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2138 (vip-replace-state-exit-cmd)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2139 (if (vip-same-line (point) (vip-replace-end))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2140 (vip-replace-state-exit-cmd)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2141 (vip-kill-line nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2142 (vip-next-line-at-bol nil)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2143
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2144
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2145 ;; This is the function bound to 'R'---unlimited replace.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2146 ;; Similar to Emacs's own overwrite-mode.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2147 (defun vip-overwrite (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2148 "Begin overwrite mode."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2149 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2150 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2151 (com (vip-getcom arg)) (len))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2152 (vip-set-destructive-command (list 'vip-overwrite val ?r nil nil nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2153 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2154 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2155 ;; Viper saves inserted text in vip-last-insertion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2156 (setq len (length vip-last-insertion))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2157 (delete-char len)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2158 (vip-loop val (vip-yank-last-insertion)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2159 (setq last-command 'vip-overwrite)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2160 (vip-set-complex-command-for-undo)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2161 (vip-set-replace-overlay (point) (vip-line-pos 'end))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2162 (vip-change-state-to-replace)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2163 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2164
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2165
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2166 ;; line commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2167
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2168 (defun vip-line (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2169 (let ((val (car arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2170 (com (cdr arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2171 (vip-move-marker-locally 'vip-com-point (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2172 (if (not (eobp))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2173 (vip-next-line-carefully (1- val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2174 ;; this ensures that dd, cc, D, yy will do the right thing on the last
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2175 ;; line of buffer when this line has no \n.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2176 (vip-add-newline-at-eob-if-necessary)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2177 (vip-execute-com 'vip-line val com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2178 (if (and (eobp) (not (bobp))) (forward-line -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2179 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2180
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2181 (defun vip-yank-line (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2182 "Yank ARG lines (in Vi's sense)."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2183 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2184 (let ((val (vip-p-val arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2185 (vip-line (cons val ?Y))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2186
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2187
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2188 ;; region commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2189
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2190 (defun vip-region (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2191 "Execute command on a region."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2192 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2193 (let ((val (vip-P-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2194 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2195 (vip-move-marker-locally 'vip-com-point (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2196 (exchange-point-and-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2197 (vip-execute-com 'vip-region val com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2198
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2199 (defun vip-Region (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2200 "Execute command on a Region."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2201 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2202 (let ((val (vip-P-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2203 (com (vip-getCom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2204 (vip-move-marker-locally 'vip-com-point (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2205 (exchange-point-and-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2206 (vip-execute-com 'vip-Region val com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2207
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2208 (defun vip-replace-char (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2209 "Replace the following ARG chars by the character read."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2210 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2211 (if (and (eolp) (bolp)) (error "No character to replace here"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2212 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2213 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2214 (vip-replace-char-subr com val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2215 (if (and (eolp) (not (bolp))) (forward-char 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2216 (vip-set-destructive-command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2217 (list 'vip-replace-char val ?r nil vip-d-char nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2218 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2219
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2220 (defun vip-replace-char-subr (com arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2221 (let ((take-care-of-iso-accents
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2222 (and (boundp 'iso-accents-mode) vip-automatic-iso-accents))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2223 char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2224 (setq char (if (equal com ?r)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2225 vip-d-char
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2226 (read-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2227 (if (and take-care-of-iso-accents (memq char '(?' ?\" ?^ ?~)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2228 ;; get European characters
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2229 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2230 (iso-accents-mode 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2231 (vip-set-unread-command-events char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2232 (setq char (aref (read-key-sequence nil) 0))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2233 (iso-accents-mode -1)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2234 (delete-char arg t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2235 (setq vip-d-char char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2236 (vip-loop (if (> arg 0) arg (- arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2237 (if (eq char ?\C-m) (insert "\n") (insert char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2238 (backward-char arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2239
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2240
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2241 ;; basic cursor movement. j, k, l, h commands.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2242
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2243 (defun vip-forward-char (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2244 "Move point right ARG characters (left if ARG negative).
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2245 On reaching end of line, stop and signal error."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2246 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2247 (vip-leave-region-active)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2248 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2249 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2250 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2251 (if vip-ex-style-motion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2252 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2253 ;; the boundary condition check gets weird here because
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2254 ;; forward-char may be the parameter of a delete, and 'dl' works
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2255 ;; just like 'x' for the last char on a line, so we have to allow
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2256 ;; the forward motion before the 'vip-execute-com', but, of
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2257 ;; course, 'dl' doesn't work on an empty line, so we have to
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2258 ;; catch that condition before 'vip-execute-com'
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2259 (if (and (eolp) (bolp)) (error "") (forward-char val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2260 (if com (vip-execute-com 'vip-forward-char val com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2261 (if (eolp) (progn (backward-char 1) (error ""))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2262 (forward-char val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2263 (if com (vip-execute-com 'vip-forward-char val com)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2264
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2265 (defun vip-backward-char (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2266 "Move point left ARG characters (right if ARG negative).
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2267 On reaching beginning of line, stop and signal error."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2268 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2269 (vip-leave-region-active)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2270 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2271 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2272 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2273 (if vip-ex-style-motion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2274 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2275 (if (bolp) (error "") (backward-char val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2276 (if com (vip-execute-com 'vip-backward-char val com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2277 (backward-char val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2278 (if com (vip-execute-com 'vip-backward-char val com)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2279
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2280 ;; Like forward-char, but doesn't move at end of buffer.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2281 (defun vip-forward-char-carefully (&optional arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2282 (setq arg (or arg 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2283 (if (>= (point-max) (+ (point) arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2284 (forward-char arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2285 (goto-char (point-max))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2286
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2287 ;; Like backward-char, but doesn't move at end of buffer.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2288 (defun vip-backward-char-carefully (&optional arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2289 (setq arg (or arg 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2290 (if (<= (point-min) (- (point) arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2291 (backward-char arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2292 (goto-char (point-min))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2293
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2294 (defun vip-next-line-carefully (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2295 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2296 (next-line arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2297 (error nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2298
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2299
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2300
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2301 ;;; Word command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2302
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2303 ;; Words are formed from alpha's and nonalphas - <sp>,\t\n are separators
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2304 ;; for word movement. When executed with a destructive command, \n is
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2305 ;; usually left untouched for the last word.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2306 ;; Viper uses syntax table to determine what is a word and what is a
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2307 ;; separator. However, \n is always a separator. Also, if vip-syntax-preference
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2308 ;; is 'vi, then `_' is part of the word.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2309
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2310 ;; skip only one \n
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2311 (defun vip-skip-separators (forward)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2312 (if forward
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2313 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2314 (vip-skip-all-separators-forward 'within-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2315 (if (looking-at "\n")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2316 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2317 (forward-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2318 (vip-skip-all-separators-forward 'within-line))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2319 (vip-skip-all-separators-backward 'within-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2320 (backward-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2321 (if (looking-at "\n")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2322 (vip-skip-all-separators-backward 'within-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2323 (forward-char))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2324
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2325 (defun vip-forward-word-kernel (val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2326 (while (> val 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2327 (cond ((vip-looking-at-alpha)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2328 (vip-skip-alpha-forward "_")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2329 (vip-skip-separators t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2330 ((vip-looking-at-separator)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2331 (vip-skip-separators t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2332 ((not (vip-looking-at-alphasep))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2333 (vip-skip-nonalphasep-forward)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2334 (vip-skip-separators t)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2335 (setq val (1- val))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2336
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2337 ;; first search backward for pat. Then skip chars backwards using aux-pat
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2338 (defun vip-fwd-skip (pat aux-pat lim)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2339 (if (and (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2340 (re-search-backward pat lim t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2341 (= (point) (match-end 0)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2342 (goto-char (match-beginning 0)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2343 (skip-chars-backward aux-pat lim)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2344 (if (= (point) lim)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2345 (vip-forward-char-carefully))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2346 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2347
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2348
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2349 (defun vip-forward-word (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2350 "Forward word."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2351 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2352 (vip-leave-region-active)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2353 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2354 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2355 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2356 (vip-forward-word-kernel val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2357 (if com (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2358 (cond ((memq com (list ?c (- ?c)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2359 (vip-fwd-skip "\n[ \t]*" " \t" vip-com-point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2360 ;; Yank words including the whitespace, but not newline
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2361 ((memq com (list ?y (- ?y)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2362 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2363 ((vip-dotable-command-p com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2364 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2365 (vip-execute-com 'vip-forward-word val com)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2366
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2367
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2368 (defun vip-forward-Word (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2369 "Forward word delimited by white characters."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2370 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2371 (vip-leave-region-active)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2372 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2373 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2374 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2375 (vip-loop val
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2376 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2377 (vip-skip-nonseparators 'forward)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2378 (vip-skip-separators t)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2379 (if com (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2380 (cond ((memq com (list ?c (- ?c)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2381 (vip-fwd-skip "\n[ \t]*" " \t" vip-com-point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2382 ;; Yank words including the whitespace, but not newline
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2383 ((memq com (list ?y (- ?y)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2384 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2385 ((vip-dotable-command-p com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2386 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2387 (vip-execute-com 'vip-forward-Word val com)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2388
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2389
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2390 ;; this is a bit different from Vi, but Vi's end of word
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2391 ;; makes no sense whatsoever
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2392 (defun vip-end-of-word-kernel ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2393 (if (vip-end-of-word-p) (forward-char))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2394 (if (vip-looking-at-separator)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2395 (vip-skip-all-separators-forward))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2396
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2397 (cond ((vip-looking-at-alpha) (vip-skip-alpha-forward "_"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2398 ((not (vip-looking-at-alphasep)) (vip-skip-nonalphasep-forward)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2399 (vip-backward-char-carefully))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2400
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2401 (defun vip-end-of-word-p ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2402 (or (eobp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2403 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2404 (cond ((vip-looking-at-alpha)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2405 (forward-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2406 (not (vip-looking-at-alpha)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2407 ((not (vip-looking-at-alphasep))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2408 (forward-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2409 (vip-looking-at-alphasep))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2410
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2411
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2412 (defun vip-end-of-word (arg &optional careful)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2413 "Move point to end of current word."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2414 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2415 (vip-leave-region-active)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2416 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2417 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2418 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2419 (vip-loop val (vip-end-of-word-kernel))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2420 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2421 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2422 (forward-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2423 (vip-execute-com 'vip-end-of-word val com)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2424
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2425 (defun vip-end-of-Word (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2426 "Forward to end of word delimited by white character."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2427 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2428 (vip-leave-region-active)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2429 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2430 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2431 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2432 (vip-loop val
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2433 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2434 (vip-end-of-word-kernel)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2435 (vip-skip-nonseparators 'forward)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2436 (backward-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2437 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2438 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2439 (forward-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2440 (vip-execute-com 'vip-end-of-Word val com)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2441
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2442 (defun vip-backward-word-kernel (val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2443 (while (> val 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2444 (backward-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2445 (cond ((vip-looking-at-alpha)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2446 (vip-skip-alpha-backward "_"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2447 ((vip-looking-at-separator)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2448 (forward-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2449 (vip-skip-separators nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2450 (backward-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2451 (cond ((vip-looking-at-alpha)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2452 (vip-skip-alpha-backward "_"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2453 ((not (vip-looking-at-alphasep))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2454 (vip-skip-nonalphasep-backward))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2455 (t (forward-char))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2456 ((not (vip-looking-at-alphasep))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2457 (vip-skip-nonalphasep-backward)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2458 (setq val (1- val))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2459
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2460 (defun vip-backward-word (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2461 "Backward word."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2462 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2463 (vip-leave-region-active)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2464 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2465 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2466 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2467 (let (i)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2468 (if (setq i (save-excursion (backward-char) (looking-at "\n")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2469 (backward-char))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2470 (vip-move-marker-locally 'vip-com-point (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2471 (if i (forward-char))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2472 (vip-backward-word-kernel val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2473 (if com (vip-execute-com 'vip-backward-word val com))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2474
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2475 (defun vip-backward-Word (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2476 "Backward word delimited by white character."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2477 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2478 (vip-leave-region-active)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2479 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2480 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2481 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2482 (let (i)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2483 (if (setq i (save-excursion (backward-char) (looking-at "\n")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2484 (backward-char))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2485 (vip-move-marker-locally 'vip-com-point (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2486 (if i (forward-char))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2487 (vip-loop val
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2488 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2489 (vip-skip-separators nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2490 (vip-skip-nonseparators 'backward)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2491 (if com (vip-execute-com 'vip-backward-Word val com))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2492
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2493
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2494
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2495 ;; line commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2496
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2497 (defun vip-beginning-of-line (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2498 "Go to beginning of line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2499 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2500 (vip-leave-region-active)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2501 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2502 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2503 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2504 (beginning-of-line val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2505 (if com (vip-execute-com 'vip-beginning-of-line val com))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2506
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2507 (defun vip-bol-and-skip-white (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2508 "Beginning of line at first non-white character."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2509 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2510 (vip-leave-region-active)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2511 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2512 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2513 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2514 (forward-to-indentation (1- val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2515 (if com (vip-execute-com 'vip-bol-and-skip-white val com))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2516
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2517 (defun vip-goto-eol (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2518 "Go to end of line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2519 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2520 (vip-leave-region-active)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2521 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2522 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2523 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2524 (end-of-line val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2525 (if com (vip-execute-com 'vip-goto-eol val com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2526 (if vip-ex-style-motion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2527 (if (and (eolp) (not (bolp))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2528 ;; a fix for vip-change-to-eol
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2529 (not (equal vip-current-state 'insert-state)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2530 (backward-char 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2531 ))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2532
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2533
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2534 (defun vip-goto-col (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2535 "Go to ARG's column."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2536 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2537 (vip-leave-region-active)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2538 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2539 (com (vip-getcom arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2540 line-len)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2541 (setq line-len (- (vip-line-pos 'end) (vip-line-pos 'start)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2542 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2543 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2544 (forward-char (1- (min line-len val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2545 (while (> (current-column) (1- val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2546 (backward-char 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2547 (if com (vip-execute-com 'vip-goto-col val com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2548 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2549 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2550 (if (> val (current-column)) (error "")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2551 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2552
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2553
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2554 (defun vip-next-line (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2555 "Go to next line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2556 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2557 (vip-leave-region-active)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2558 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2559 (com (vip-getCom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2560 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2561 (next-line val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2562 (if vip-ex-style-motion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2563 (if (and (eolp) (not (bolp))) (backward-char 1)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2564 (setq this-command 'next-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2565 (if com (vip-execute-com 'vip-next-line val com))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2566
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2567 (defun vip-next-line-at-bol (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2568 "Next line at beginning of line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2569 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2570 (vip-leave-region-active)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2571 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2572 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2573 (if (eobp) (error "Last line in buffer")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2574 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2575 (com (vip-getCom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2576 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2577 (forward-line val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2578 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2579 (if com (vip-execute-com 'vip-next-line-at-bol val com))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2580
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2581 (defun vip-previous-line (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2582 "Go to previous line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2583 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2584 (vip-leave-region-active)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2585 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2586 (com (vip-getCom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2587 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2588 (previous-line val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2589 (if vip-ex-style-motion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2590 (if (and (eolp) (not (bolp))) (backward-char 1)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2591 (setq this-command 'previous-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2592 (if com (vip-execute-com 'vip-previous-line val com))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2593
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2594
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2595 (defun vip-previous-line-at-bol (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2596 "Previous line at beginning of line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2597 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2598 (vip-leave-region-active)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2599 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2600 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2601 (if (bobp) (error "First line in buffer")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2602 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2603 (com (vip-getCom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2604 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2605 (forward-line (- val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2606 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2607 (if com (vip-execute-com 'vip-previous-line val com))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2608
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2609 (defun vip-change-to-eol (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2610 "Change to end of line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2611 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2612 (vip-goto-eol (cons arg ?c)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2613
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2614 (defun vip-kill-line (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2615 "Delete line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2616 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2617 (vip-goto-eol (cons arg ?d)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2618
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2619 (defun vip-erase-line (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2620 "Erase line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2621 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2622 (vip-beginning-of-line (cons arg ?d)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2623
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2624
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2625 ;;; Moving around
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2626
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2627 (defun vip-goto-line (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2628 "Go to ARG's line. Without ARG go to end of buffer."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2629 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2630 (let ((val (vip-P-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2631 (com (vip-getCom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2632 (vip-move-marker-locally 'vip-com-point (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2633 (vip-deactivate-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2634 (push-mark nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2635 (if (null val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2636 (goto-char (point-max))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2637 (goto-char (point-min))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2638 (forward-line (1- val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2639
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2640 ;; positioning is done twice: before and after command execution
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2641 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2642 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2643
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2644 (if com (vip-execute-com 'vip-goto-line val com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2645
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2646 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2647 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2648 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2649
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2650 ;; Find ARG's occurrence of CHAR on the current line.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2651 ;; If FORWARD then search is forward, otherwise backward. OFFSET is used to
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2652 ;; adjust point after search.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2653 (defun vip-find-char (arg char forward offset)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2654 (or (char-or-string-p char) (error ""))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2655 (let ((arg (if forward arg (- arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2656 (cmd (if (eq vip-intermediate-command 'vip-repeat)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2657 (nth 5 vip-d-com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2658 (vip-array-to-string (this-command-keys))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2659 point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2660 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2661 (save-restriction
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2662 (if (> arg 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2663 (narrow-to-region
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2664 ;; forward search begins here
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2665 (if (eolp) (error "Command `%s': At end of line" cmd) (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2666 ;; forward search ends here
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2667 (progn (end-of-line) (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2668 (narrow-to-region
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2669 ;; backward search begins from here
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2670 (if (bolp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2671 (error "Command `%s': At beginning of line" cmd) (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2672 ;; backward search ends here
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2673 (progn (beginning-of-line) (point))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2674 ;; if arg > 0, point is forwarded before search.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2675 (if (> arg 0) (goto-char (1+ (point-min)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2676 (goto-char (point-max)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2677 (if (let ((case-fold-search nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2678 (search-forward (char-to-string char) nil 0 arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2679 (setq point (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2680 (error "Command `%s': `%c' not found" cmd char))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2681 (goto-char (+ point (if (> arg 0) (if offset -2 -1) (if offset 1 0))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2682
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2683 (defun vip-find-char-forward (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2684 "Find char on the line.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2685 If called interactively read the char to find from the terminal, and if
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2686 called from vip-repeat, the char last used is used. This behaviour is
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2687 controlled by the sign of prefix numeric value."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2688 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2689 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2690 (com (vip-getcom arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2691 (cmd-representation (nth 5 vip-d-com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2692 (if (> val 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2693 ;; this means that the function was called interactively
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2694 (setq vip-f-char (read-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2695 vip-f-forward t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2696 vip-f-offset nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2697 ;; vip-repeat --- set vip-F-char from command-keys
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2698 (setq vip-F-char (if (stringp cmd-representation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2699 (vip-seq-last-elt cmd-representation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2700 vip-F-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2701 vip-f-char vip-F-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2702 (setq val (- val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2703 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2704 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2705 (setq val (- val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2706 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2707 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2708 (setq vip-F-char vip-f-char) ; set new vip-F-char
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2709 (forward-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2710 (vip-execute-com 'vip-find-char-forward val com)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2711
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2712 (defun vip-goto-char-forward (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2713 "Go up to char ARG forward on line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2714 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2715 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2716 (com (vip-getcom arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2717 (cmd-representation (nth 5 vip-d-com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2718 (if (> val 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2719 ;; this means that the function was called interactively
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2720 (setq vip-f-char (read-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2721 vip-f-forward t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2722 vip-f-offset t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2723 ;; vip-repeat --- set vip-F-char from command-keys
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2724 (setq vip-F-char (if (stringp cmd-representation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2725 (vip-seq-last-elt cmd-representation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2726 vip-F-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2727 vip-f-char vip-F-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2728 (setq val (- val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2729 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2730 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2731 (setq val (- val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2732 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2733 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2734 (setq vip-F-char vip-f-char) ; set new vip-F-char
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2735 (forward-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2736 (vip-execute-com 'vip-goto-char-forward val com)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2737
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2738 (defun vip-find-char-backward (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2739 "Find char ARG on line backward."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2740 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2741 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2742 (com (vip-getcom arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2743 (cmd-representation (nth 5 vip-d-com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2744 (if (> val 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2745 ;; this means that the function was called interactively
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2746 (setq vip-f-char (read-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2747 vip-f-forward nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2748 vip-f-offset nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2749 ;; vip-repeat --- set vip-F-char from command-keys
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2750 (setq vip-F-char (if (stringp cmd-representation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2751 (vip-seq-last-elt cmd-representation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2752 vip-F-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2753 vip-f-char vip-F-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2754 (setq val (- val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2755 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2756 (vip-find-char
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2757 val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2758 (setq val (- val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2759 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2760 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2761 (setq vip-F-char vip-f-char) ; set new vip-F-char
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2762 (vip-execute-com 'vip-find-char-backward val com)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2763
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2764 (defun vip-goto-char-backward (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2765 "Go up to char ARG backward on line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2766 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2767 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2768 (com (vip-getcom arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2769 (cmd-representation (nth 5 vip-d-com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2770 (if (> val 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2771 ;; this means that the function was called interactively
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2772 (setq vip-f-char (read-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2773 vip-f-forward nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2774 vip-f-offset t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2775 ;; vip-repeat --- set vip-F-char from command-keys
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2776 (setq vip-F-char (if (stringp cmd-representation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2777 (vip-seq-last-elt cmd-representation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2778 vip-F-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2779 vip-f-char vip-F-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2780 (setq val (- val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2781 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2782 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2783 (setq val (- val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2784 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2785 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2786 (setq vip-F-char vip-f-char) ; set new vip-F-char
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2787 (vip-execute-com 'vip-goto-char-backward val com)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2788
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2789 (defun vip-repeat-find (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2790 "Repeat previous find command."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2791 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2792 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2793 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2794 (vip-deactivate-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2795 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2796 (vip-find-char val vip-f-char vip-f-forward vip-f-offset)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2797 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2798 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2799 (if vip-f-forward (forward-char))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2800 (vip-execute-com 'vip-repeat-find val com)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2801
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2802 (defun vip-repeat-find-opposite (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2803 "Repeat previous find command in the opposite direction."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2804 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2805 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2806 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2807 (vip-deactivate-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2808 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2809 (vip-find-char val vip-f-char (not vip-f-forward) vip-f-offset)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2810 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2811 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2812 (if vip-f-forward (forward-char))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2813 (vip-execute-com 'vip-repeat-find-opposite val com)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2814
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2815
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2816 ;; window scrolling etc.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2817
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2818 (defun vip-other-window (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2819 "Switch to other window."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2820 (interactive "p")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2821 (other-window arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2822 (or (not (eq vip-current-state 'emacs-state))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2823 (string= (buffer-name (current-buffer)) " *Minibuf-1*")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2824 (vip-change-state-to-vi)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2825
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2826 (defun vip-window-top (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2827 "Go to home window line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2828 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2829 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2830 (com (vip-getCom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2831 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2832 (push-mark nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2833 (move-to-window-line (1- val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2834
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2835 ;; positioning is done twice: before and after command execution
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2836 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2837 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2838
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2839 (if com (vip-execute-com 'vip-window-top val com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2840
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2841 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2842 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2843 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2844
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2845 (defun vip-window-middle (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2846 "Go to middle window line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2847 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2848 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2849 (com (vip-getCom arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2850 lines)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2851 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2852 (push-mark nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2853 (if (not (pos-visible-in-window-p (point-max)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2854 (move-to-window-line (+ (/ (1- (window-height)) 2) (1- val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2855 (setq lines (count-lines (window-start) (point-max)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2856 (move-to-window-line (+ (/ lines 2) (1- val))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2857
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2858 ;; positioning is done twice: before and after command execution
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2859 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2860 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2861
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2862 (if com (vip-execute-com 'vip-window-middle val com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2863
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2864 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2865 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2866 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2867
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2868 (defun vip-window-bottom (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2869 "Go to last window line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2870 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2871 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2872 (com (vip-getCom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2873 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2874 (push-mark nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2875 (move-to-window-line (- val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2876
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2877 ;; positioning is done twice: before and after command execution
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2878 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2879 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2880
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2881 (if com (vip-execute-com 'vip-window-bottom val com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2882
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2883 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2884 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2885 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2886
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2887 (defun vip-line-to-top (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2888 "Put current line on the home line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2889 (interactive "p")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2890 (recenter (1- arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2891
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2892 (defun vip-line-to-middle (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2893 "Put current line on the middle line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2894 (interactive "p")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2895 (recenter (+ (1- arg) (/ (1- (window-height)) 2))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2896
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2897 (defun vip-line-to-bottom (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2898 "Put current line on the last line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2899 (interactive "p")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2900 (recenter (- (window-height) (1+ arg))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2901
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2902 ;; If point is within vip-search-scroll-threshold of window top or bottom,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2903 ;; scroll up or down 1/7 of window height, depending on whether we are at the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2904 ;; bottom or at the top of the window. This function is called by vip-search
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2905 ;; (which is called from vip-search-forward/backward/next). If the value of
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2906 ;; vip-search-scroll-threshold is negative - don't scroll.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2907 (defun vip-adjust-window ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2908 (let ((win-height (if vip-emacs-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2909 (1- (window-height)) ; adjust for modeline
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2910 (window-displayed-height)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2911 (pt (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2912 at-top-p at-bottom-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2913 min-scroll direction)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2914 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2915 (move-to-window-line 0) ; top
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2916 (setq at-top-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2917 (<= (count-lines pt (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2918 vip-search-scroll-threshold))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2919 (move-to-window-line -1) ; bottom
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2920 (setq at-bottom-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2921 (<= (count-lines pt (point)) vip-search-scroll-threshold))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2922 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2923 (cond (at-top-p (setq min-scroll (1- vip-search-scroll-threshold)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2924 direction 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2925 (at-bottom-p (setq min-scroll (1+ vip-search-scroll-threshold)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2926 direction -1)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2927 (if min-scroll
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2928 (recenter
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2929 (* (max min-scroll (/ win-height 7)) direction)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2930 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2931
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2932
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2933 ;; paren match
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2934 ;; must correct this to only match ( to ) etc. On the other hand
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2935 ;; it is good that paren match gets confused, because that way you
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2936 ;; catch _all_ imbalances.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2937
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2938 (defun vip-paren-match (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2939 "Go to the matching parenthesis."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2940 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2941 (vip-leave-region-active)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2942 (let ((com (vip-getcom arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2943 (parse-sexp-ignore-comments vip-parse-sexp-ignore-comments)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2944 anchor-point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2945 (if (integerp arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2946 (if (or (> arg 99) (< arg 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2947 (error "Prefix must be between 1 and 99")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2948 (goto-char
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2949 (if (> (point-max) 80000)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2950 (* (/ (point-max) 100) arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2951 (/ (* (point-max) arg) 100)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2952 (back-to-indentation))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2953 (let (beg-lim end-lim)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2954 (if (and (eolp) (not (bolp))) (forward-char -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2955 (if (not (looking-at "[][(){}]"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2956 (setq anchor-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2957 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2958 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2959 (setq beg-lim (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2960 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2961 (setq end-lim (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2962 (cond ((re-search-forward "[][(){}]" end-lim t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2963 (backward-char) )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2964 ((re-search-backward "[][(){}]" beg-lim t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2965 (t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2966 (error "No matching character on line"))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2967 (cond ((looking-at "[\(\[{]")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2968 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2969 (forward-sexp 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2970 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2971 (vip-execute-com 'vip-paren-match nil com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2972 (backward-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2973 (anchor-point
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2974 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2975 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2976 (vip-move-marker-locally 'vip-com-point anchor-point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2977 (forward-char 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2978 (vip-execute-com 'vip-paren-match nil com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2979 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2980 ((looking-at "[])}]")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2981 (forward-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2982 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2983 (backward-sexp 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2984 (if com (vip-execute-com 'vip-paren-match nil com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2985 (t (error ""))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2986
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2987 (defun vip-toggle-parse-sexp-ignore-comments ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2988 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2989 (setq vip-parse-sexp-ignore-comments (not vip-parse-sexp-ignore-comments))
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
2990 (princ (format
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
2991 "From now on, `%%' will %signore parentheses inside comment fields"
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
2992 (if vip-parse-sexp-ignore-comments "" "NOT "))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2993
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2994
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2995 ;; sentence ,paragraph and heading
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2996
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2997 (defun vip-forward-sentence (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2998 "Forward sentence."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2999 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3000 (push-mark nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3001 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3002 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3003 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3004 (forward-sentence val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3005 (if com (vip-execute-com 'vip-forward-sentence nil com))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3006
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3007 (defun vip-backward-sentence (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3008 "Backward sentence."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3009 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3010 (push-mark nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3011 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3012 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3013 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3014 (backward-sentence val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3015 (if com (vip-execute-com 'vip-backward-sentence nil com))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3016
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3017 (defun vip-forward-paragraph (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3018 "Forward paragraph."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3019 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3020 (push-mark nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3021 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3022 (com (vip-getCom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3023 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3024 (forward-paragraph val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3025 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3026 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3027 (backward-char 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3028 (vip-execute-com 'vip-forward-paragraph nil com)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3029
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3030 (defun vip-backward-paragraph (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3031 "Backward paragraph."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3032 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3033 (push-mark nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3034 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3035 (com (vip-getCom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3036 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3037 (backward-paragraph val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3038 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3039 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3040 (forward-char 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3041 (vip-execute-com 'vip-backward-paragraph nil com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3042 (backward-char 1)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3043
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3044 ;; should be mode-specific etc.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3045
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3046 (defun vip-prev-heading (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3047 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3048 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3049 (com (vip-getCom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3050 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3051 (re-search-backward vip-heading-start nil t val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3052 (goto-char (match-beginning 0))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3053 (if com (vip-execute-com 'vip-prev-heading nil com))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3054
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3055 (defun vip-heading-end (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3056 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3057 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3058 (com (vip-getCom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3059 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3060 (re-search-forward vip-heading-end nil t val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3061 (goto-char (match-beginning 0))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3062 (if com (vip-execute-com 'vip-heading-end nil com))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3063
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3064 (defun vip-next-heading (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3065 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3066 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3067 (com (vip-getCom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3068 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3069 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3070 (re-search-forward vip-heading-start nil t val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3071 (goto-char (match-beginning 0))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3072 (if com (vip-execute-com 'vip-next-heading nil com))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3073
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3074
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3075 ;; scrolling
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3076
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3077 (defun vip-scroll-screen (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3078 "Scroll to next screen."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3079 (interactive "p")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3080 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3081 (if (> arg 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3082 (while (> arg 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3083 (scroll-up)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3084 (setq arg (1- arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3085 (while (> 0 arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3086 (scroll-down)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3087 (setq arg (1+ arg))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3088 (error (beep 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3089 (if (> arg 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3090 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3091 (message "End of buffer")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3092 (goto-char (point-max)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3093 (message "Beginning of buffer")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3094 (goto-char (point-min))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3095 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3096
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3097 (defun vip-scroll-screen-back (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3098 "Scroll to previous screen."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3099 (interactive "p")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3100 (vip-scroll-screen (- arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3101
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3102 (defun vip-scroll-down (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3103 "Pull down half screen."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3104 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3105 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3106 (if (null arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3107 (scroll-down (/ (window-height) 2))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3108 (scroll-down arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3109 (error (beep 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3110 (message "Beginning of buffer")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3111 (goto-char (point-min)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3112
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3113 (defun vip-scroll-down-one (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3114 "Scroll up one line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3115 (interactive "p")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3116 (scroll-down arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3117
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3118 (defun vip-scroll-up (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3119 "Pull up half screen."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3120 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3121 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3122 (if (null arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3123 (scroll-up (/ (window-height) 2))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3124 (scroll-up arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3125 (error (beep 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3126 (message "End of buffer")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3127 (goto-char (point-max)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3128
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3129 (defun vip-scroll-up-one (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3130 "Scroll down one line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3131 (interactive "p")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3132 (scroll-up arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3133
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3134
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3135 ;; searching
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3136
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3137 (defun vip-if-string (prompt)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3138 (let ((s (vip-read-string-with-history
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3139 prompt
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3140 nil ; no initial
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3141 'vip-search-history
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3142 (car vip-search-history))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3143 (if (not (string= s ""))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3144 (setq vip-s-string s))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3145
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3146
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3147 (defun vip-toggle-search-style (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3148 "Toggle the value of vip-case-fold-search/vip-re-search.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3149 Without prefix argument, will ask which search style to toggle. With prefix
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3150 arg 1,toggles vip-case-fold-search; with arg 2 toggles vip-re-search.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3151
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3152 Although this function is bound to \\[vip-toggle-search-style], the most
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3153 convenient way to use it is to bind `//' to the macro
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3154 `1 M-x vip-toggle-search-style' and `///' to
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3155 `2 M-x vip-toggle-search-style'. In this way, hitting `//' quickly will
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3156 toggle case-fold-search and hitting `/' three times witth toggle regexp
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3157 search. Macros are more convenient in this case because they don't affect
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3158 the Emacs binding of `/'."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3159 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3160 (let (msg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3161 (cond ((or (eq arg 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3162 (and (null arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3163 (y-or-n-p (format "Search style: '%s'. Want '%s'? "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3164 (if vip-case-fold-search
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3165 "case-insensitive" "case-sensitive")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3166 (if vip-case-fold-search
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3167 "case-sensitive"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3168 "case-insensitive")))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3169 (setq vip-case-fold-search (null vip-case-fold-search))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3170 (if vip-case-fold-search
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3171 (setq msg "Search becomes case-insensitive")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3172 (setq msg "Search becomes case-sensitive")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3173 ((or (eq arg 2)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3174 (and (null arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3175 (y-or-n-p (format "Search style: '%s'. Want '%s'? "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3176 (if vip-re-search
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3177 "regexp-search" "vanilla-search")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3178 (if vip-re-search
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3179 "vanilla-search"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3180 "regexp-search")))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3181 (setq vip-re-search (null vip-re-search))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3182 (if vip-re-search
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3183 (setq msg "Search becomes regexp-style")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3184 (setq msg "Search becomes vanilla-style")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3185 (t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3186 (setq msg "Search style remains unchanged")))
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3187 (princ msg t)))
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3188
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3189 (defun vip-set-searchstyle-toggling-macros (unset)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3190 "Set the macros for toggling the search style in Viper's vi-state.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3191 The macro that toggles case sensitivity is bound to `//', and the one that
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3192 toggles regexp search is bound to `///'.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3193 With a prefix argument, this function unsets the macros. "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3194 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3195 (or noninteractive
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3196 (if (not unset)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3197 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3198 ;; toggle case sensitivity in search
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3199 (vip-record-kbd-macro
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3200 "//" 'vi-state
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3201 [1 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return]
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3202 't)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3203 ;; toggle regexp/vanila search
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3204 (vip-record-kbd-macro
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3205 "///" 'vi-state
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3206 [2 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return]
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3207 't)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3208 (if (interactive-p)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3209 (message
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3210 "// and /// now toggle case-sensitivity and regexp search")))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3211 (vip-unrecord-kbd-macro "//" 'vi-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3212 (sit-for 2)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3213 (vip-unrecord-kbd-macro "///" 'vi-state))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3214
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3215
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3216 (defun vip-set-parsing-style-toggling-macro (unset)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3217 "Set `%%%' to be a macro that toggles whether comment fields should be parsed for matching parentheses.
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3218 This is used in conjunction with the `%' command.
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3219
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3220 With a prefix argument, unsets the macro."
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3221 (interactive "P")
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3222 (or noninteractive
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3223 (if (not unset)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3224 (progn
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3225 ;; Make %%% toggle parsing comments for matching parentheses
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3226 (vip-record-kbd-macro
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3227 "%%%" 'vi-state
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3228 [(meta x) v i p - t o g g l e - p a r s e - s e x p - i g n o r e - c o m m e n t s return]
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3229 't)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3230 (if (interactive-p)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3231 (message
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3232 "%%%%%% now toggles whether comments should be parsed for matching parentheses")))
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3233 (vip-unrecord-kbd-macro "%%%" 'vi-state))))
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3234
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3235
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3236 (defun vip-set-emacs-state-searchstyle-macros (unset &optional arg-majormode)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3237 "Set the macros for toggling the search style in Viper's emacs-state.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3238 The macro that toggles case sensitivity is bound to `//', and the one that
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3239 toggles regexp search is bound to `///'.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3240 With a prefix argument, this function unsets the macros.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3241 If the optional prefix argument is non-nil and specifies a valid major mode,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3242 this sets the macros only in the macros in that major mode. Otherwise,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3243 the macros are set in the current major mode.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3244 \(When unsetting the macros, the second argument has no effect.\)"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3245 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3246 (or noninteractive
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3247 (if (not unset)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3248 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3249 ;; toggle case sensitivity in search
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3250 (vip-record-kbd-macro
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3251 "//" 'emacs-state
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3252 [1 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return]
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3253 (or arg-majormode major-mode))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3254 ;; toggle regexp/vanila search
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3255 (vip-record-kbd-macro
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3256 "///" 'emacs-state
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3257 [2 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return]
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3258 (or arg-majormode major-mode))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3259 (if (interactive-p)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3260 (message
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3261 "// and /// now toggle case-sensitivity and regexp search.")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3262 (vip-unrecord-kbd-macro "//" 'emacs-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3263 (sit-for 2)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3264 (vip-unrecord-kbd-macro "///" 'emacs-state))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3265
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3266
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3267 (defun vip-search-forward (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3268 "Search a string forward.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3269 ARG is used to find the ARG's occurrence of the string.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3270 Null string will repeat previous search."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3271 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3272 (let ((val (vip-P-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3273 (com (vip-getcom arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3274 (old-str vip-s-string))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3275 (setq vip-s-forward t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3276 (vip-if-string "/")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3277 ;; this is not used at present, but may be used later
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3278 (if (or (not (equal old-str vip-s-string))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3279 (not (markerp vip-local-search-start-marker))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3280 (not (marker-buffer vip-local-search-start-marker)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3281 (setq vip-local-search-start-marker (point-marker)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3282 (vip-search vip-s-string t val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3283 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3284 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3285 (vip-move-marker-locally 'vip-com-point (mark t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3286 (vip-execute-com 'vip-search-next val com)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3287
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3288 (defun vip-search-backward (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3289 "Search a string backward.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3290 ARG is used to find the ARG's occurrence of the string.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3291 Null string will repeat previous search."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3292 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3293 (let ((val (vip-P-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3294 (com (vip-getcom arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3295 (old-str vip-s-string))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3296 (setq vip-s-forward nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3297 (vip-if-string "?")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3298 ;; this is not used at present, but may be used later
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3299 (if (or (not (equal old-str vip-s-string))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3300 (not (markerp vip-local-search-start-marker))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3301 (not (marker-buffer vip-local-search-start-marker)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3302 (setq vip-local-search-start-marker (point-marker)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3303 (vip-search vip-s-string nil val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3304 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3305 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3306 (vip-move-marker-locally 'vip-com-point (mark t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3307 (vip-execute-com 'vip-search-next val com)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3308
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3309
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3310 ;; Search for COUNT's occurrence of STRING.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3311 ;; Search is forward if FORWARD is non-nil, otherwise backward.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3312 ;; INIT-POINT is the position where search is to start.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3313 ;; Arguments:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3314 ;; (STRING FORW COUNT &optional NO-OFFSET INIT-POINT LIMIT FAIL-IF-NOT-FOUND)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3315 (defun vip-search (string forward arg
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3316 &optional no-offset init-point fail-if-not-found)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3317 (if (not (equal string ""))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3318 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3319 (com (vip-getcom arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3320 (offset (not no-offset))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3321 (case-fold-search vip-case-fold-search)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3322 (start-point (or init-point (point))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3323 (vip-deactivate-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3324 (if forward
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3325 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3326 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3327 (if offset (vip-forward-char-carefully))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3328 (if vip-re-search
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3329 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3330 (re-search-forward string nil nil val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3331 (re-search-backward string))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3332 (search-forward string nil nil val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3333 (search-backward string))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3334 (if (not (equal start-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3335 (push-mark start-point t)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3336 (search-failed
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3337 (if (and (not fail-if-not-found) vip-search-wrap-around-t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3338 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3339 (message "Search wrapped around BOTTOM of buffer")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3340 (goto-char (point-min))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3341 (vip-search string forward (cons 1 com) t start-point 'fail)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3342 ;; don't wait in macros
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3343 (or executing-kbd-macro (sit-for 2))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3344 ;; delete the wrap-around message
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3345 (message "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3346 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3347 (goto-char start-point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3348 (error "`%s': %s not found"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3349 string
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3350 (if vip-re-search "Pattern" "String"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3351 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3352 ;; backward
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3353 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3354 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3355 (if vip-re-search
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3356 (re-search-backward string nil nil val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3357 (search-backward string nil nil val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3358 (if (not (equal start-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3359 (push-mark start-point t)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3360 (search-failed
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3361 (if (and (not fail-if-not-found) vip-search-wrap-around-t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3362 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3363 (message "Search wrapped around TOP of buffer")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3364 (goto-char (point-max))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3365 (vip-search string forward (cons 1 com) t start-point 'fail)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3366 ;; don't wait in macros
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3367 (or executing-kbd-macro (sit-for 2))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3368 ;; delete the wrap-around message
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3369 (message "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3370 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3371 (goto-char start-point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3372 (error "`%s': %s not found"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3373 string
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3374 (if vip-re-search "Pattern" "String"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3375 ))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3376 ;; pull up or down if at top/bottom of window
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3377 (vip-adjust-window)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3378 ;; highlight the result of search
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3379 ;; don't wait and don't highlight in macros
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3380 (or executing-kbd-macro
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3381 vip-inside-command-argument-action
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3382 (vip-flash-search-pattern))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3383 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3384
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3385 (defun vip-search-next (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3386 "Repeat previous search."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3387 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3388 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3389 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3390 (if (null vip-s-string) (error vip-NoPrevSearch))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3391 (vip-search vip-s-string vip-s-forward arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3392 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3393 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3394 (vip-move-marker-locally 'vip-com-point (mark t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3395 (vip-execute-com 'vip-search-next val com)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3396
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3397 (defun vip-search-Next (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3398 "Repeat previous search in the reverse direction."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3399 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3400 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3401 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3402 (if (null vip-s-string) (error vip-NoPrevSearch))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3403 (vip-search vip-s-string (not vip-s-forward) arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3404 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3405 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3406 (vip-move-marker-locally 'vip-com-point (mark t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3407 (vip-execute-com 'vip-search-Next val com)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3408
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3409
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3410 ;; Search contents of buffer defined by one of Viper's motion commands.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3411 ;; Repeatable via `n' and `N'.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3412 (defun vip-buffer-search-enable (&optional c)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3413 (cond (c (setq vip-buffer-search-char c))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3414 ((null vip-buffer-search-char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3415 (setq vip-buffer-search-char ?g)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3416 (define-key vip-vi-basic-map
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3417 (char-to-string vip-buffer-search-char) 'vip-command-argument)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3418 (aset vip-exec-array vip-buffer-search-char 'vip-exec-buffer-search)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3419 (setq vip-prefix-commands (cons vip-buffer-search-char vip-prefix-commands)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3420
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3421 ;; This is a Viper wraper for isearch-forward.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3422 (defun vip-isearch-forward (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3423 "Do incremental search forward."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3424 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3425 ;; emacs bug workaround
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3426 (if (listp arg) (setq arg (car arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3427 (vip-exec-form-in-emacs (list 'isearch-forward arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3428
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3429 ;; This is a Viper wraper for isearch-backward."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3430 (defun vip-isearch-backward (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3431 "Do incremental search backward."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3432 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3433 ;; emacs bug workaround
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3434 (if (listp arg) (setq arg (car arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3435 (vip-exec-form-in-emacs (list 'isearch-backward arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3436
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3437
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3438 ;; visiting and killing files, buffers
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3439
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3440 (defun vip-switch-to-buffer ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3441 "Switch to buffer in the current window."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3442 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3443 (let (buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3444 (setq buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3445 (read-buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3446 (format "Switch to buffer in this window \(%s\): "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3447 (buffer-name (other-buffer (current-buffer))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3448 (switch-to-buffer buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3449 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3450
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3451 (defun vip-switch-to-buffer-other-window ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3452 "Switch to buffer in another window."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3453 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3454 (let (buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3455 (setq buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3456 (read-buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3457 (format "Switch to buffer in another window \(%s\): "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3458 (buffer-name (other-buffer (current-buffer))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3459 (switch-to-buffer-other-window buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3460 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3461
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3462 (defun vip-kill-buffer ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3463 "Kill a buffer."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3464 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3465 (let (buffer buffer-name)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3466 (setq buffer-name
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3467 (read-buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3468 (format "Kill buffer \(%s\): "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3469 (buffer-name (current-buffer)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3470 (setq buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3471 (if (null buffer-name)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3472 (current-buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3473 (get-buffer buffer-name)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3474 (if (null buffer) (error "`%s': No such buffer" buffer-name))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3475 (if (or (not (buffer-modified-p buffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3476 (y-or-n-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3477 (format
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3478 "Buffer `%s' is modified, are you sure you want to kill it? "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3479 buffer-name)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3480 (kill-buffer buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3481 (error "Buffer not killed"))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3482
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3483
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3484 (defcustom vip-smart-suffix-list
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3485 '("" "tex" "c" "cc" "C" "el" "java" "html" "htm" "pl" "P" "p")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3486 "*List of suffixes that Viper automatically tries to append to filenames ending with a `.'.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3487 This is useful when you the current directory contains files with the same
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3488 prefix and many different suffixes. Usually, only one of the suffixes
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3489 represents an editable file. However, file completion will stop at the `.'
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3490 The smart suffix feature lets you hit RET in such a case, and Viper will
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3491 select the appropriate suffix.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3492
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3493 Suffixes are tried in the order given and the first suffix for which a
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3494 corresponding file exists is selected. If no file exists for any of the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3495 suffixes, the user is asked to confirm.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3496
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3497 To turn this feature off, set this variable to nil."
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3498 :type '(set string)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3499 :group 'viper)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3500
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3501 ;; Try to add suffix to files ending with a `.'
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3502 ;; Useful when the user hits RET on a non-completed file name.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3503 (defun vip-file-add-suffix ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3504 (let ((count 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3505 (len (length vip-smart-suffix-list))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3506 (file (buffer-string))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3507 found key cmd suff)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3508 (goto-char (point-max))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3509 (if (and vip-smart-suffix-list (string-match "\\.$" file))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3510 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3511 (while (and (not found) (< count len))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3512 (setq suff (nth count vip-smart-suffix-list)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3513 count (1+ count))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3514 (if (file-exists-p (format "%s%s" file suff))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3515 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3516 (setq found t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3517 (insert suff))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3518
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3519 (if found
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3520 ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3521 (vip-tmp-insert-at-eob " [Please complete file name]")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3522 (unwind-protect
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3523 (while (not (memq cmd '(exit-minibuffer vip-exit-minibuffer)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3524 (setq cmd
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3525 (key-binding (setq key (read-key-sequence nil))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3526 (cond ((eq cmd 'self-insert-command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3527 (if vip-xemacs-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3528 (insert (events-to-keys key))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3529 (insert key)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3530 ((memq cmd '(exit-minibuffer vip-exit-minibuffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3531 nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3532 (t (command-execute cmd)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3533 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3534 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3535 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3536
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3537
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3538
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3539
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3540 ;; yank and pop
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3541
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3542 (defsubst vip-yank (text)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3543 "Yank TEXT silently. This works correctly with Emacs's yank-pop command."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3544 (insert text)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3545 (setq this-command 'yank))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3546
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3547 (defun vip-put-back (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3548 "Put back after point/below line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3549 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3550 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3551 (text (if vip-use-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3552 (cond ((vip-valid-register vip-use-register '(digit))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3553 (current-kill (- vip-use-register ?1) 'do-not-rotate))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3554 ((vip-valid-register vip-use-register)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3555 (get-register (downcase vip-use-register)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3556 (t (error vip-InvalidRegister vip-use-register)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3557 (current-kill 0))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3558 (if (null text)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3559 (if vip-use-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3560 (let ((reg vip-use-register))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3561 (setq vip-use-register nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3562 (error vip-EmptyRegister reg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3563 (error "")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3564 (setq vip-use-register nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3565 (if (vip-end-with-a-newline-p text)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3566 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3567 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3568 (if (eobp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3569 (insert "\n")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3570 (forward-line 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3571 (beginning-of-line))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3572 (if (not (eolp)) (vip-forward-char-carefully)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3573 (set-marker (vip-mark-marker) (point) (current-buffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3574 (vip-set-destructive-command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3575 (list 'vip-put-back val nil vip-use-register nil nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3576 (vip-loop val (vip-yank text)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3577 ;; Vi puts cursor on the last char when the yanked text doesn't contain a
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3578 ;; newline; it leaves the cursor at the beginning when the text contains
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3579 ;; a newline
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3580 (if (vip-same-line (point) (mark))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3581 (or (= (point) (mark)) (vip-backward-char-carefully))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3582 (exchange-point-and-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3583 (if (bolp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3584 (back-to-indentation)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3585 (vip-deactivate-mark))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3586
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3587 (defun vip-Put-back (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3588 "Put back at point/above line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3589 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3590 (let ((val (vip-p-val arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3591 (text (if vip-use-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3592 (cond ((vip-valid-register vip-use-register '(digit))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3593 (current-kill (- vip-use-register ?1) 'do-not-rotate))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3594 ((vip-valid-register vip-use-register)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3595 (get-register (downcase vip-use-register)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3596 (t (error vip-InvalidRegister vip-use-register)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3597 (current-kill 0))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3598 (if (null text)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3599 (if vip-use-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3600 (let ((reg vip-use-register))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3601 (setq vip-use-register nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3602 (error vip-EmptyRegister reg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3603 (error "")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3604 (setq vip-use-register nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3605 (if (vip-end-with-a-newline-p text) (beginning-of-line))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3606 (vip-set-destructive-command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3607 (list 'vip-Put-back val nil vip-use-register nil nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3608 (set-marker (vip-mark-marker) (point) (current-buffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3609 (vip-loop val (vip-yank text)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3610 ;; Vi puts cursor on the last char when the yanked text doesn't contain a
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3611 ;; newline; it leaves the cursor at the beginning when the text contains
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3612 ;; a newline
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3613 (if (vip-same-line (point) (mark))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3614 (or (= (point) (mark)) (vip-backward-char-carefully))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3615 (exchange-point-and-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3616 (if (bolp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3617 (back-to-indentation)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3618 (vip-deactivate-mark))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3619
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3620
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3621 ;; Copy region to kill-ring.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3622 ;; If BEG and END do not belong to the same buffer, copy empty region.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3623 (defun vip-copy-region-as-kill (beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3624 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3625 (copy-region-as-kill beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3626 (error (copy-region-as-kill beg beg))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3627
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3628
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3629 (defun vip-delete-char (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3630 "Delete character."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3631 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3632 (let ((val (vip-p-val arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3633 (vip-set-destructive-command (list 'vip-delete-char val nil nil nil nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3634 (if (> val 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3635 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3636 (let ((here (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3637 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3638 (if (> val (- (point) here))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3639 (setq val (- (point) here))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3640 (if (and (eq val 0) (not vip-ex-style-motion)) (setq val 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3641 (if (and vip-ex-style-motion (eolp))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3642 (if (bolp) (error "") (setq val 0))) ; not bol---simply back 1 ch
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3643 (if vip-use-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3644 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3645 (cond ((vip-valid-register vip-use-register '((Letter)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3646 (vip-append-to-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3647 (downcase vip-use-register) (point) (- (point) val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3648 ((vip-valid-register vip-use-register)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3649 (copy-to-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3650 vip-use-register (point) (- (point) val) nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3651 (t (error vip-InvalidRegister vip-use-register)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3652 (setq vip-use-register nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3653 (if vip-ex-style-motion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3654 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3655 (delete-char val t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3656 (if (and (eolp) (not (bolp))) (backward-char 1)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3657 (if (eolp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3658 (delete-backward-char val t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3659 (delete-char val t)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3660
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3661 (defun vip-delete-backward-char (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3662 "Delete previous character. On reaching beginning of line, stop and beep."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3663 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3664 (let ((val (vip-p-val arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3665 (vip-set-destructive-command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3666 (list 'vip-delete-backward-char val nil nil nil nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3667 (if (> val 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3668 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3669 (let ((here (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3670 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3671 (if (> val (- here (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3672 (setq val (- here (point)))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3673 (if vip-use-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3674 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3675 (cond ((vip-valid-register vip-use-register '(Letter))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3676 (vip-append-to-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3677 (downcase vip-use-register) (point) (+ (point) val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3678 ((vip-valid-register vip-use-register)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3679 (copy-to-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3680 vip-use-register (point) (+ (point) val) nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3681 (t (error vip-InvalidRegister vip-use-register)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3682 (setq vip-use-register nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3683 (if (bolp) (ding)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3684 (delete-backward-char val t))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3685
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3686 (defun vip-del-backward-char-in-insert ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3687 "Delete 1 char backwards while in insert mode."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3688 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3689 (if (and vip-ex-style-editing-in-insert (bolp))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3690 (beep 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3691 (delete-backward-char 1 t)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3692
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3693 (defun vip-del-backward-char-in-replace ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3694 "Delete one character in replace mode.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3695 If `vip-delete-backwards-in-replace' is t, then DEL key actually deletes
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3696 charecters. If it is nil, then the cursor just moves backwards, similarly
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3697 to Vi. The variable `vip-ex-style-editing-in-insert', if t, doesn't let the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3698 cursor move past the beginning of line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3699 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3700 (cond (vip-delete-backwards-in-replace
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3701 (cond ((not (bolp))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3702 (delete-backward-char 1 t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3703 (vip-ex-style-editing-in-insert
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3704 (beep 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3705 ((bobp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3706 (beep 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3707 (t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3708 (delete-backward-char 1 t))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3709 (vip-ex-style-editing-in-insert
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3710 (if (bolp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3711 (beep 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3712 (backward-char 1)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3713 (t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3714 (backward-char 1))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3715
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3716
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3717
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3718 ;; join lines.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3719
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3720 (defun vip-join-lines (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3721 "Join this line to next, if ARG is nil. Otherwise, join ARG lines."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3722 (interactive "*P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3723 (let ((val (vip-P-val arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3724 (vip-set-destructive-command (list 'vip-join-lines val nil nil nil nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3725 (vip-loop (if (null val) 1 (1- val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3726 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3727 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3728 (if (not (eobp))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3729 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3730 (forward-line 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3731 (delete-region (point) (1- (point)))
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3732 (fixup-whitespace)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3733 ;; fixup-whitespace sometimes does not leave space
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3734 ;; between objects, so we insert it as in Vi
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3735 (or (looking-at " ")
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3736 (insert " ")
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3737 (backward-char 1))
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3738 ))))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3739
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3740
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3741 ;; Replace state
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3742
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3743 (defun vip-change (beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3744 (if (markerp beg) (setq beg (marker-position beg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3745 (if (markerp end) (setq end (marker-position end)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3746 ;; beg is sometimes (mark t), which may be nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3747 (or beg (setq beg end))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3748
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3749 (vip-set-complex-command-for-undo)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3750 (if vip-use-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3751 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3752 (copy-to-register vip-use-register beg end nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3753 (setq vip-use-register nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3754 (vip-set-replace-overlay beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3755 (setq last-command nil) ; separate repl text from prev kills
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3756
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3757 (if (= (vip-replace-start) (point-max))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3758 (error "End of buffer"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3759
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3760 (setq vip-last-replace-region
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3761 (buffer-substring (vip-replace-start)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3762 (vip-replace-end)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3763
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3764 ;; protect against error while inserting "@" and other disasters
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3765 ;; (e.g., read-only buff)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3766 (condition-case conds
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3767 (if (or vip-allow-multiline-replace-regions
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3768 (vip-same-line (vip-replace-start)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3769 (vip-replace-end)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3770 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3771 ;; tabs cause problems in replace, so untabify
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3772 (goto-char (vip-replace-end))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3773 (insert-before-markers "@") ; put placeholder after the TAB
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3774 (untabify (vip-replace-start) (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3775 ;; del @, don't put on kill ring
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3776 (delete-backward-char 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3777
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3778 (vip-set-replace-overlay-glyphs
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3779 vip-replace-region-start-delimiter
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3780 vip-replace-region-end-delimiter)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3781 ;; this move takes care of the last posn in the overlay, which
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3782 ;; has to be shifted because of insert. We can't simply insert
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3783 ;; "$" before-markers because then overlay-start will shift the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3784 ;; beginning of the overlay in case we are replacing a single
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3785 ;; character. This fixes the bug with `s' and `cl' commands.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3786 (vip-move-replace-overlay (vip-replace-start) (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3787 (goto-char (vip-replace-start))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3788 (vip-change-state-to-replace t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3789 (kill-region (vip-replace-start)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3790 (vip-replace-end))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3791 (vip-hide-replace-overlay)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3792 (vip-change-state-to-insert))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3793 (error ;; make sure that the overlay doesn't stay.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3794 ;; go back to the original point
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3795 (goto-char (vip-replace-start))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3796 (vip-hide-replace-overlay)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3797 (vip-message-conditions conds))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3798
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3799
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3800 (defun vip-change-subr (beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3801 ;; beg is sometimes (mark t), which may be nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3802 (or beg (setq beg end))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3803
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3804 (if vip-use-register
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3805 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3806 (copy-to-register vip-use-register beg end nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3807 (setq vip-use-register nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3808 (kill-region beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3809 (setq this-command 'vip-change)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3810 (vip-yank-last-insertion))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3811
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3812 (defun vip-toggle-case (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3813 "Toggle character case."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3814 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3815 (let ((val (vip-p-val arg)) (c))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3816 (vip-set-destructive-command (list 'vip-toggle-case val nil nil nil nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3817 (while (> val 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3818 (setq c (following-char))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3819 (delete-char 1 nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3820 (if (eq c (upcase c))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3821 (insert-char (downcase c) 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3822 (insert-char (upcase c) 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3823 (if (eolp) (backward-char 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3824 (setq val (1- val)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3825
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3826
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3827 ;; query replace
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3828
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3829 (defun vip-query-replace ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3830 "Query replace.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3831 If a null string is suplied as the string to be replaced,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3832 the query replace mode will toggle between string replace
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3833 and regexp replace."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3834 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3835 (let (str)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3836 (setq str (vip-read-string-with-history
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3837 (if vip-re-query-replace "Query replace regexp: "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3838 "Query replace: ")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3839 nil ; no initial
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3840 'vip-replace1-history
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3841 (car vip-replace1-history) ; default
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3842 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3843 (if (string= str "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3844 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3845 (setq vip-re-query-replace (not vip-re-query-replace))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3846 (message "Query replace mode changed to %s"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3847 (if vip-re-query-replace "regexp replace"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3848 "string replace")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3849 (if vip-re-query-replace
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3850 (query-replace-regexp
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3851 str
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3852 (vip-read-string-with-history
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3853 (format "Query replace regexp `%s' with: " str)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3854 nil ; no initial
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3855 'vip-replace1-history
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3856 (car vip-replace1-history) ; default
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3857 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3858 (query-replace
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3859 str
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3860 (vip-read-string-with-history
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3861 (format "Query replace `%s' with: " str)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3862 nil ; no initial
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3863 'vip-replace1-history
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3864 (car vip-replace1-history) ; default
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3865 ))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3866
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3867
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3868 ;; marking
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3869
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3870 (defun vip-mark-beginning-of-buffer ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3871 "Mark beginning of buffer."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3872 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3873 (push-mark (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3874 (goto-char (point-min))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3875 (exchange-point-and-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3876 (message "Mark set at the beginning of buffer"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3877
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3878 (defun vip-mark-end-of-buffer ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3879 "Mark end of buffer."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3880 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3881 (push-mark (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3882 (goto-char (point-max))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3883 (exchange-point-and-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3884 (message "Mark set at the end of buffer"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3885
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3886 (defun vip-mark-point ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3887 "Set mark at point of buffer."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3888 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3889 (let ((char (read-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3890 (cond ((and (<= ?a char) (<= char ?z))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3891 (point-to-register (1+ (- char ?a))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3892 ((= char ?<) (vip-mark-beginning-of-buffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3893 ((= char ?>) (vip-mark-end-of-buffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3894 ((= char ?.) (vip-set-mark-if-necessary))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3895 ((= char ?,) (vip-cycle-through-mark-ring))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3896 ((= char ?D) (mark-defun))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3897 (t (error ""))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3898 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3899
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3900 ;; Algorithm: If first invocation of this command save mark on ring, goto
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3901 ;; mark, M0, and pop the most recent elt from the mark ring into mark,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3902 ;; making it into the new mark, M1.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3903 ;; Push this mark back and set mark to the original point position, p1.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3904 ;; So, if you hit '' or `` then you can return to p1.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3905 ;;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3906 ;; If repeated command, pop top elt from the ring into mark and
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3907 ;; jump there. This forgets the position, p1, and puts M1 back into mark.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3908 ;; Then we save the current pos, which is M0, jump to M1 and pop M2 from
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3909 ;; the ring into mark. Push M2 back on the ring and set mark to M0.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3910 ;; etc.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3911 (defun vip-cycle-through-mark-ring ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3912 "Visit previous locations on the mark ring.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3913 One can use `` and '' to temporarily jump 1 step back."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3914 (let* ((sv-pt (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3915 ;; if repeated `m,' command, pop the previously saved mark.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3916 ;; Prev saved mark is actually prev saved point. It is used if the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3917 ;; user types `` or '' and is discarded
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3918 ;; from the mark ring by the next `m,' command.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3919 ;; In any case, go to the previous or previously saved mark.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3920 ;; Then push the current mark (popped off the ring) and set current
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3921 ;; point to be the mark. Current pt as mark is discarded by the next
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3922 ;; m, command.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3923 (if (eq last-command 'vip-cycle-through-mark-ring)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3924 ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3925 ;; save current mark if the first iteration
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3926 (setq mark-ring (delete (vip-mark-marker) mark-ring))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3927 (if (mark t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3928 (push-mark (mark t) t)) )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3929 (pop-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3930 (set-mark-command 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3931 ;; don't duplicate mark on the ring
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3932 (setq mark-ring (delete (vip-mark-marker) mark-ring))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3933 (push-mark sv-pt t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3934 (vip-deactivate-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3935 (setq this-command 'vip-cycle-through-mark-ring)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3936 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3937
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3938
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3939 (defun vip-goto-mark (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3940 "Go to mark."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3941 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3942 (let ((char (read-char))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3943 (com (vip-getcom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3944 (vip-goto-mark-subr char com nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3945
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3946 (defun vip-goto-mark-and-skip-white (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3947 "Go to mark and skip to first non-white character on line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3948 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3949 (let ((char (read-char))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3950 (com (vip-getCom arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3951 (vip-goto-mark-subr char com t)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3952
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3953 (defun vip-goto-mark-subr (char com skip-white)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3954 (if (eobp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3955 (if (bobp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3956 (error "Empty buffer")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3957 (backward-char 1)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3958 (cond ((vip-valid-register char '(letter))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3959 (let* ((buff (current-buffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3960 (reg (1+ (- char ?a)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3961 (text-marker (get-register reg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3962 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3963 (if (not (vip-valid-marker text-marker))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3964 (error vip-EmptyTextmarker char))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3965 (if (and (vip-same-line (point) vip-last-jump)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3966 (= (point) vip-last-jump-ignore))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3967 (push-mark vip-last-jump t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3968 (push-mark nil t)) ; no msg
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3969 (vip-register-to-point reg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3970 (setq vip-last-jump (point-marker))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3971 (cond (skip-white
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3972 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3973 (setq vip-last-jump-ignore (point))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3974 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3975 (if (equal buff (current-buffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3976 (vip-execute-com (if skip-white
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3977 'vip-goto-mark-and-skip-white
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3978 'vip-goto-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3979 nil com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3980 (switch-to-buffer buff)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3981 (goto-char vip-com-point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3982 (vip-change-state-to-vi)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3983 (error "")))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3984 ((and (not skip-white) (= char ?`))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3985 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3986 (if (and (vip-same-line (point) vip-last-jump)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3987 (= (point) vip-last-jump-ignore))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3988 (goto-char vip-last-jump))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3989 (if (null (mark t)) (error "Mark is not set in this buffer"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3990 (if (= (point) (mark t)) (pop-mark))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3991 (exchange-point-and-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3992 (setq vip-last-jump (point-marker)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3993 vip-last-jump-ignore 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3994 (if com (vip-execute-com 'vip-goto-mark nil com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3995 ((and skip-white (= char ?'))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3996 (if com (vip-move-marker-locally 'vip-com-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3997 (if (and (vip-same-line (point) vip-last-jump)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3998 (= (point) vip-last-jump-ignore))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3999 (goto-char vip-last-jump))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4000 (if (= (point) (mark t)) (pop-mark))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4001 (exchange-point-and-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4002 (setq vip-last-jump (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4003 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4004 (setq vip-last-jump-ignore (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4005 (if com (vip-execute-com 'vip-goto-mark-and-skip-white nil com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4006 (t (error vip-InvalidTextmarker char))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4007
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4008 (defun vip-insert-tab ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4009 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4010 (insert-tab))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4011
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4012 (defun vip-exchange-point-and-mark ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4013 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4014 (exchange-point-and-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4015 (back-to-indentation))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4016
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4017 ;; Input Mode Indentation
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4018
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4019 ;; Returns t, if the string before point matches the regexp STR.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4020 (defsubst vip-looking-back (str)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4021 (and (save-excursion (re-search-backward str nil t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4022 (= (point) (match-end 0))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4023
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4024
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4025 (defun vip-forward-indent ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4026 "Indent forward -- `C-t' in Vi."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4027 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4028 (setq vip-cted t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4029 (indent-to (+ (current-column) vip-shift-width)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4030
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4031 (defun vip-backward-indent ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4032 "Backtab, C-d in VI"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4033 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4034 (if vip-cted
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4035 (let ((p (point)) (c (current-column)) bol (indent t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4036 (if (vip-looking-back "[0^]")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4037 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4038 (if (eq ?^ (preceding-char))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4039 (setq vip-preserve-indent t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4040 (delete-backward-char 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4041 (setq p (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4042 (setq indent nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4043 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4044 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4045 (setq bol (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4046 (if (re-search-backward "[^ \t]" bol 1) (forward-char))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4047 (delete-region (point) p)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4048 (if indent
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4049 (indent-to (- c vip-shift-width)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4050 (if (or (bolp) (vip-looking-back "[^ \t]"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4051 (setq vip-cted nil)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4052
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4053 (defun vip-autoindent ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4054 "Auto Indentation, Vi-style."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4055 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4056 (let ((col (current-indentation)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4057 (if abbrev-mode (expand-abbrev))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4058 (if vip-preserve-indent
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4059 (setq vip-preserve-indent nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4060 (setq vip-current-indent col))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4061 ;; don't leave whitespace lines around
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4062 (if (memq last-command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4063 '(vip-autoindent
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4064 vip-open-line vip-Open-line
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4065 vip-replace-state-exit-cmd))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4066 (indent-to-left-margin))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4067 ;; use \n instead of newline, or else <Return> will move the insert point
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4068 ;;(newline 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4069 (insert "\n")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4070 (if vip-auto-indent
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4071 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4072 (setq vip-cted t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4073 (if (and vip-electric-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4074 (not (eq major-mode 'fundamental-mode)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4075 (indent-according-to-mode)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4076 (indent-to vip-current-indent))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4077 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4078 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4079
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4080
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4081 ;; Viewing registers
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4082
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4083 (defun vip-ket-function (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4084 "Function called by \], the ket. View registers and call \]\]."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4085 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4086 (let ((reg (read-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4087 (cond ((vip-valid-register reg '(letter Letter))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4088 (view-register (downcase reg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4089 ((vip-valid-register reg '(digit))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4090 (let ((text (current-kill (- reg ?1) 'do-not-rotate)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4091 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4092 (set-buffer (get-buffer-create "*Output*"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4093 (delete-region (point-min) (point-max))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4094 (insert (format "Register %c contains the string:\n" reg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4095 (insert text)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4096 (goto-char (point-min)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4097 (display-buffer "*Output*")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4098 ((= ?\] reg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4099 (vip-next-heading arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4100 (t (error
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4101 vip-InvalidRegister reg)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4102
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4103 (defun vip-brac-function (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4104 "Function called by \[, the brac. View textmarkers and call \[\["
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4105 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4106 (let ((reg (read-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4107 (cond ((= ?\[ reg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4108 (vip-prev-heading arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4109 ((= ?\] reg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4110 (vip-heading-end arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4111 ((vip-valid-register reg '(letter))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4112 (let* ((val (get-register (1+ (- reg ?a))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4113 (buf (if (not val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4114 (error vip-EmptyTextmarker reg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4115 (marker-buffer val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4116 (pos (marker-position val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4117 line-no text (s pos) (e pos))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4118 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4119 (set-buffer (get-buffer-create "*Output*"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4120 (delete-region (point-min) (point-max))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4121 (if (and buf pos)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4122 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4123 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4124 (set-buffer buf)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4125 (setq line-no (1+ (count-lines (point-min) val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4126 (goto-char pos)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4127 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4128 (if (re-search-backward "[^ \t]" nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4129 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4130 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4131 (setq s (point))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4132 (goto-char pos)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4133 (forward-line 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4134 (if (re-search-forward "[^ \t]" nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4135 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4136 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4137 (setq e (point))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4138 (setq text (buffer-substring s e))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4139 (setq text (format "%s<%c>%s"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4140 (substring text 0 (- pos s))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4141 reg (substring text (- pos s)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4142 (insert
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4143 (format
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4144 "Textmarker `%c' is in buffer `%s' at line %d.\n"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4145 reg (buffer-name buf) line-no))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4146 (insert (format "Here is some text around %c:\n\n %s"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4147 reg text)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4148 (insert (format vip-EmptyTextmarker reg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4149 (goto-char (point-min)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4150 (display-buffer "*Output*")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4151 (t (error vip-InvalidTextmarker reg)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4152
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4153
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4154
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4155 ;; commands in insertion mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4156
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4157 (defun vip-delete-backward-word (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4158 "Delete previous word."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4159 (interactive "p")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4160 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4161 (push-mark nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4162 (backward-word arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4163 (delete-region (point) (mark t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4164 (pop-mark)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4165
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4166
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4167 (defun viper-set-expert-level (&optional dont-change-unless)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4168 "Sets the expert level for a Viper user.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4169 Can be called interactively to change (temporarily or permanently) the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4170 current expert level.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4171
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4172 The optional argument DONT-CHANGE-UNLESS, if not nil, says that
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4173 the level should not be changed, unless its current value is
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4174 meaningless (i.e., not one of 1,2,3,4,5).
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4175
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4176 User level determines the setting of Viper variables that are most
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4177 sensitive for VI-style look-and-feel."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4178
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4179 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4180
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4181 (if (not (natnump viper-expert-level)) (setq viper-expert-level 0))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4182
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4183 (save-window-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4184 (delete-other-windows)
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4185 ;; if 0 < viper-expert-level < viper-max-expert-level
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4186 ;; & dont-change-unless = t -- use it; else ask
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4187 (vip-ask-level dont-change-unless))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4188
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4189 (setq viper-always t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4190 vip-ex-style-motion t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4191 vip-ex-style-editing-in-insert t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4192 vip-want-ctl-h-help nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4193
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4194 (cond ((eq viper-expert-level 1) ; novice or beginner
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4195 (global-set-key ; in emacs-state
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4196 vip-toggle-key
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4197 (if (vip-window-display-p) 'vip-iconify 'suspend-emacs))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4198 (setq vip-no-multiple-ESC t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4199 vip-re-search t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4200 vip-vi-style-in-minibuffer t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4201 vip-search-wrap-around-t t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4202 vip-electric-mode nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4203 vip-want-emacs-keys-in-vi nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4204 vip-want-emacs-keys-in-insert nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4205
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4206 ((and (> viper-expert-level 1) (< viper-expert-level 5))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4207 ;; intermediate to guru
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4208 (setq vip-no-multiple-ESC (if (vip-window-display-p)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4209 t 'twice)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4210 vip-electric-mode t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4211 vip-want-emacs-keys-in-vi t
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4212 vip-want-emacs-keys-in-insert (> viper-expert-level 2))
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4213
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4214 (if (eq viper-expert-level 4) ; respect user's ex-style motion
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4215 ; and vip-no-multiple-ESC
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4216 (progn
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4217 (setq-default
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4218 vip-ex-style-editing-in-insert
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4219 (viper-standard-value 'vip-ex-style-editing-in-insert)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4220 vip-ex-style-motion
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4221 (viper-standard-value 'vip-ex-style-motion))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4222 (setq vip-ex-style-motion
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4223 (viper-standard-value 'vip-ex-style-motion)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4224 vip-ex-style-editing-in-insert
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4225 (viper-standard-value 'vip-ex-style-editing-in-insert)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4226 vip-re-search
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4227 (viper-standard-value 'vip-re-search)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4228 vip-no-multiple-ESC
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4229 (viper-standard-value 'vip-no-multiple-ESC)))))
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4230
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4231 ;; A wizard!!
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4232 ;; Ideally, if 5 is selected, a buffer should pop up to let the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4233 ;; user toggle the values of variables.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4234 (t (setq-default vip-ex-style-editing-in-insert
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4235 (viper-standard-value 'vip-ex-style-editing-in-insert)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4236 vip-ex-style-motion
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4237 (viper-standard-value 'vip-ex-style-motion))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4238 (setq vip-want-ctl-h-help
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4239 (viper-standard-value 'vip-want-ctl-h-help)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4240 viper-always
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4241 (viper-standard-value 'viper-always)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4242 vip-no-multiple-ESC
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4243 (viper-standard-value 'vip-no-multiple-ESC)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4244 vip-ex-style-motion
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4245 (viper-standard-value 'vip-ex-style-motion)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4246 vip-ex-style-editing-in-insert
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4247 (viper-standard-value 'vip-ex-style-editing-in-insert)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4248 vip-re-search
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4249 (viper-standard-value 'vip-re-search)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4250 vip-electric-mode
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4251 (viper-standard-value 'vip-electric-mode)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4252 vip-want-emacs-keys-in-vi
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4253 (viper-standard-value 'vip-want-emacs-keys-in-vi)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4254 vip-want-emacs-keys-in-insert
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4255 (viper-standard-value 'vip-want-emacs-keys-in-insert))))
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4256
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4257 (vip-set-mode-vars-for vip-current-state)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4258 (if (or viper-always
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4259 (and (> viper-expert-level 0) (> 5 viper-expert-level)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4260 (vip-set-hooks)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4261
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4262 ;; Ask user expert level.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4263 (defun vip-ask-level (dont-change-unless)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4264 (let ((ask-buffer " *vip-ask-level*")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4265 level-changed repeated)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4266 (save-window-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4267 (switch-to-buffer ask-buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4268
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4269 (while (or (> viper-expert-level viper-max-expert-level)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4270 (< viper-expert-level 1)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4271 (null dont-change-unless))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4272 (erase-buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4273 (if repeated
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4274 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4275 (message "Invalid user level")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4276 (beep 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4277 (setq repeated t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4278 (setq dont-change-unless t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4279 level-changed t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4280 (insert "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4281 Please specify your level of familiarity with the venomous VI PERil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4282 (and the VI Plan for Emacs Rescue).
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4283 You can change it at any time by typing `M-x viper-set-expert-level RET'
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4284
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4285 1 -- BEGINNER: Almost all Emacs features are suppressed.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4286 Feels almost like straight Vi. File name completion and
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4287 command history in the minibuffer are thrown in as a bonus.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4288 To use Emacs productively, you must reach level 3 or higher.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4289 2 -- MASTER: C-c now has its standard Emacs meaning in Vi command state,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4290 so most Emacs commands can be used when Viper is in Vi state.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4291 Good progress---you are well on the way to level 3!
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4292 3 -- GRAND MASTER: Like 3, but most Emacs commands are available also
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4293 in Viper's insert state.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4294 4 -- GURU: Like 3, but user settings are respected for vip-no-multiple-ESC,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4295 vip-re-search, vip-ex-style-motion, & vip-ex-style-editing-in-insert
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4296 variables. Adjust these settings to your taste.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4297 5 -- WIZARD: Like 4, but user settings are also respected for viper-always,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4298 vip-electric-mode, vip-want-ctl-h-help, vip-want-emacs-keys-in-vi,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4299 and vip-want-emacs-keys-in-insert. Adjust these to your taste.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4300
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4301 Please, specify your level now: ")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4302
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4303 (setq viper-expert-level (- (vip-read-char-exclusive) ?0))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4304 ) ; end while
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4305
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4306 ;; tell the user if level was changed
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4307 (and level-changed
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4308 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4309 (insert
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4310 (format "\n\n\n\n\n\t\tYou have selected user level %d"
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4311 viper-expert-level))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4312 (if (y-or-n-p "Do you wish to make this change permanent? ")
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4313 ;; save the setting for viper-expert-level
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4314 (vip-save-setting
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4315 'viper-expert-level
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4316 (format "Saving user level %d ..." viper-expert-level)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4317 vip-custom-file-name))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4318 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4319 (bury-buffer) ; remove ask-buffer from screen
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4320 (message "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4321 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4322
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4323
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4324 (defun vip-nil ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4325 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4326 (beep 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4327
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4328
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4329 ;; if ENFORCE-BUFFER is not nil, error if CHAR is a marker in another buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4330 (defun vip-register-to-point (char &optional enforce-buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4331 "Like jump-to-register, but switches to another buffer in another window."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4332 (interactive "cViper register to point: ")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4333 (let ((val (get-register char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4334 (cond
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4335 ((and (fboundp 'frame-configuration-p)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4336 (frame-configuration-p val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4337 (set-frame-configuration val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4338 ((window-configuration-p val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4339 (set-window-configuration val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4340 ((vip-valid-marker val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4341 (if (and enforce-buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4342 (not (equal (current-buffer) (marker-buffer val))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4343 (error (concat vip-EmptyTextmarker " in this buffer")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4344 (1- (+ char ?a))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4345 (pop-to-buffer (marker-buffer val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4346 (goto-char val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4347 ((and (consp val) (eq (car val) 'file))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4348 (find-file (cdr val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4349 (t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4350 (error vip-EmptyTextmarker (1- (+ char ?a)))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4351
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4352
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4353 (defun vip-save-kill-buffer ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4354 "Save then kill current buffer. "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4355 (interactive)
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4356 (if (< viper-expert-level 2)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4357 (save-buffers-kill-emacs)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4358 (save-buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4359 (kill-buffer (current-buffer))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4360
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4361
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4362
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4363 ;;; Bug Report
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4364
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4365 (defun vip-submit-report ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4366 "Submit bug report on Viper."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4367 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4368 (let ((reporter-prompt-for-summary-p t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4369 (vip-device-type (vip-device-type))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4370 color-display-p frame-parameters
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4371 minibuffer-emacs-face minibuffer-vi-face minibuffer-insert-face
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4372 varlist salutation window-config)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4373
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4374 ;; If mode info is needed, add variable to `let' and then set it below,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4375 ;; like we did with color-display-p.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4376 (setq color-display-p (if (vip-window-display-p)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4377 (vip-color-display-p)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4378 'non-x)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4379 minibuffer-vi-face (if (vip-has-face-support-p)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4380 (vip-get-face vip-minibuffer-vi-face)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4381 'non-x)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4382 minibuffer-insert-face (if (vip-has-face-support-p)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4383 (vip-get-face vip-minibuffer-insert-face)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4384 'non-x)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4385 minibuffer-emacs-face (if (vip-has-face-support-p)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4386 (vip-get-face vip-minibuffer-emacs-face)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4387 'non-x)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4388 frame-parameters (if (fboundp 'frame-parameters)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4389 (frame-parameters (selected-frame))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4390
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4391 (setq varlist (list 'vip-vi-minibuffer-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4392 'vip-insert-minibuffer-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4393 'vip-vi-intercept-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4394 'vip-vi-local-user-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4395 'vip-vi-kbd-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4396 'vip-vi-global-user-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4397 'vip-vi-state-modifier-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4398 'vip-vi-diehard-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4399 'vip-vi-basic-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4400 'vip-replace-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4401 'vip-insert-intercept-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4402 'vip-insert-local-user-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4403 'vip-insert-kbd-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4404 'vip-insert-global-user-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4405 'vip-insert-state-modifier-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4406 'vip-insert-diehard-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4407 'vip-insert-basic-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4408 'vip-emacs-intercept-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4409 'vip-emacs-local-user-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4410 'vip-emacs-kbd-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4411 'vip-emacs-global-user-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4412 'vip-emacs-state-modifier-minor-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4413 'vip-automatic-iso-accents
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4414 'vip-want-emacs-keys-in-insert
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4415 'vip-want-emacs-keys-in-vi
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4416 'vip-keep-point-on-undo
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4417 'vip-no-multiple-ESC
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4418 'vip-electric-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4419 'vip-ESC-key
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4420 'vip-want-ctl-h-help
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4421 'vip-ex-style-editing-in-insert
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4422 'vip-delete-backwards-in-replace
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4423 'vip-vi-style-in-minibuffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4424 'vip-vi-state-hook
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4425 'vip-insert-state-hook
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4426 'vip-replace-state-hook
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4427 'vip-emacs-state-hook
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4428 'ex-cycle-other-window
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4429 'ex-cycle-through-non-files
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4430 'viper-expert-level
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4431 'major-mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4432 'vip-device-type
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4433 'color-display-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4434 'frame-parameters
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4435 'minibuffer-vi-face
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4436 'minibuffer-insert-face
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4437 'minibuffer-emacs-face
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4438 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4439 (setq salutation "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4440 Congratulations! You may have unearthed a bug in Viper!
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4441 Please mail a concise, accurate summary of the problem to the address above.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4442
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4443 -------------------------------------------------------------------")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4444 (setq window-config (current-window-configuration))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4445 (with-output-to-temp-buffer " *vip-info*"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4446 (switch-to-buffer " *vip-info*")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4447 (delete-other-windows)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4448 (princ "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4449 PLEASE FOLLOW THESE PROCEDURES
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4450 ------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4451
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4452 Before reporting a bug, please verify that it is related to Viper, and is
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4453 not cause by other packages you are using.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4454
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4455 Don't report compilation warnings, unless you are certain that there is a
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4456 problem. These warnings are normal and unavoidable.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4457
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4458 Please note that users should not modify variables and keymaps other than
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4459 those advertised in the manual. Such `customization' is likely to crash
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4460 Viper, as it would any other improperly customized Emacs package.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4461
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4462 If you are reporting an error message received while executing one of the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4463 Viper commands, type:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4464
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4465 M-x set-variable <Return> debug-on-error <Return> t <Return>
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4466
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4467 Then reproduce the error. The above command will cause Emacs to produce a
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4468 back trace of the execution that leads to the error. Please include this
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4469 trace in your bug report.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4470
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4471 If you believe that one of Viper's commands goes into an infinite loop
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4472 \(e.g., Emacs freezes\), type:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4473
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4474 M-x set-variable <Return> debug-on-quit <Return> t <Return>
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4475
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4476 Then reproduce the problem. Wait for a few seconds, then type C-g to abort
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4477 the current command. Include the resulting back trace in the bug report.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4478
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4479 Mail anyway (y or n)? ")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4480 (if (y-or-n-p "Mail anyway? ")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4481 ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4482 (set-window-configuration window-config)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4483 (error "Bug report aborted")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4484
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4485 (require 'reporter)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4486 (set-window-configuration window-config)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4487
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4488 (reporter-submit-bug-report "kifer@cs.sunysb.edu"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4489 (vip-version)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4490 varlist
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4491 nil 'delete-other-windows
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4492 salutation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4493 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4494
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4495
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4496
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4497
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4498 ;; Smoothes out the difference between Emacs' unread-command-events
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4499 ;; and XEmacs unread-command-event. Arg is a character, an event, a list of
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4500 ;; events or a sequence of keys.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4501 ;;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4502 ;; Due to the way unread-command-events in Emacs (not XEmacs), a non-event
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4503 ;; symbol in unread-command-events list may cause Emacs to turn this symbol
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4504 ;; into an event. Below, we delete nil from event lists, since nil is the most
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4505 ;; common symbol that might appear in this wrong context.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4506 (defun vip-set-unread-command-events (arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4507 (if vip-emacs-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4508 (setq
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4509 unread-command-events
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4510 (let ((new-events
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4511 (cond ((eventp arg) (list arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4512 ((listp arg) arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4513 ((sequencep arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4514 (listify-key-sequence arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4515 (t (error
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4516 "vip-set-unread-command-events: Invalid argument, %S"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4517 arg)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4518 (if (not (eventp nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4519 (setq new-events (delq nil new-events)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4520 (append new-events unread-command-events)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4521 ;; XEmacs
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4522 (setq
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4523 unread-command-events
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4524 (append
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4525 (cond ((vip-characterp arg) (list (character-to-event arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4526 ((eventp arg) (list arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4527 ((stringp arg) (mapcar 'character-to-event arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4528 ((vectorp arg) (append arg nil)) ; turn into list
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4529 ((listp arg) (vip-eventify-list-xemacs arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4530 (t (error
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4531 "vip-set-unread-command-events: Invalid argument, %S" arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4532 unread-command-events))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4533
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4534 ;; list is assumed to be a list of events of characters
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4535 (defun vip-eventify-list-xemacs (lis)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4536 (mapcar
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4537 (function (lambda (elt)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4538 (cond ((vip-characterp elt) (character-to-event elt))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4539 ((eventp elt) elt)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4540 (t (error
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4541 "vip-eventify-list-xemacs: can't convert to event, %S"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4542 elt)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4543 lis))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4544
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4545
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4546
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4547 ;;; viper-cmd.el ends here