annotate lisp/viper/viper-cmd.el @ 200:f0deb0c0e6be

Added tag r20-3b26 for changeset 169c0442b401
author cvs
date Mon, 13 Aug 2007 10:00:35 +0200
parents acd284d43ca1
children
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
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
4 ;; This file is part of GNU Emacs.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
5
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
6 ;; GNU Emacs is free software; you can redistribute it and/or modify
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
7 ;; it under the terms of the GNU General Public License as published by
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
8 ;; the Free Software Foundation; either version 2, or (at your option)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
9 ;; any later version.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
10
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
11 ;; GNU Emacs is distributed in the hope that it will be useful,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
14 ;; GNU General Public License for more details.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
15
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
16 ;; You should have received a copy of the GNU General Public License
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
17 ;; along with GNU Emacs; see the file COPYING. If not, write to the
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
18 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
19 ;; Boston, MA 02111-1307, USA.
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
20
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
21 ;; Code
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
22
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
23 (provide 'viper-cmd)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
24 (require 'advice)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
25
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
26 ;; Compiler pacifier
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
27 (defvar viper-minibuffer-current-face)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
28 (defvar viper-minibuffer-insert-face)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
29 (defvar viper-minibuffer-vi-face)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
30 (defvar viper-minibuffer-emacs-face)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
31 (defvar viper-always)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
32 (defvar viper-mode-string)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
33 (defvar viper-custom-file-name)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
34 (defvar iso-accents-mode)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
35 (defvar quail-mode)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
36 (defvar quail-current-str)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
37 (defvar zmacs-region-stays)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
38 (defvar mark-even-if-inactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
39
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
40 ;; loading happens only in non-interactive compilation
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
41 ;; in order to spare non-viperized emacs from being viperized
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
42 (if noninteractive
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
43 (eval-when-compile
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
44 (let ((load-path (cons (expand-file-name ".") load-path)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
45 (or (featurep 'viper-util)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
46 (load "viper-util.el" nil nil 'nosuffix))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
47 (or (featurep 'viper-keym)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
48 (load "viper-keym.el" nil nil 'nosuffix))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
49 (or (featurep 'viper-mous)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
50 (load "viper-mous.el" nil nil 'nosuffix))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
51 (or (featurep 'viper-macs)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
52 (load "viper-macs.el" nil nil 'nosuffix))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
53 (or (featurep 'viper-ex)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
54 (load "viper-ex.el" nil nil 'nosuffix))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
55 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
56 ;; end pacifier
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
57
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
58
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
59 (require 'viper-util)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
60 (require 'viper-keym)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
61 (require 'viper-mous)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
62 (require 'viper-macs)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
63 (require 'viper-ex)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
64
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
65
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
66
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
67 ;; Generic predicates
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
68
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
69 ;; 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
70
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
71 ;; generate test functions
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
72 ;; 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
73 ;; Viper command keys
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
74 ;; (macroexpand '(viper-test-com-defun foo))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
75 ;; (defun foo-p (com) (consp (memq (if (< com 0) (- com) com) foos)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
76
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
77 (defmacro viper-test-com-defun (name)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
78 (let* ((snm (symbol-name name))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
79 (nm-p (intern (concat snm "-p")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
80 (nms (intern (concat snm "s"))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
81 (` (defun (, nm-p) (com)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
82 (consp (memq (if (and (viper-characterp com) (< com 0))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
83 (- com) com) (, nms)))))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
84
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
85 ;; Variables for defining VI commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
86
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
87 ;; Modifying commands that can be prefixes to movement commands
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
88 (defconst viper-prefix-commands '(?c ?d ?y ?! ?= ?# ?< ?> ?\"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
89 ;; define viper-prefix-command-p
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
90 (viper-test-com-defun viper-prefix-command)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
91
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
92 ;; Commands that are pairs eg. dd. r and R here are a hack
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
93 (defconst viper-charpair-commands '(?c ?d ?y ?! ?= ?< ?> ?r ?R))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
94 ;; define viper-charpair-command-p
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
95 (viper-test-com-defun viper-charpair-command)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
96
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
97 (defconst viper-movement-commands '(?b ?B ?e ?E ?f ?F ?G ?h ?H ?j ?k ?l
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
98 ?H ?M ?L ?n ?t ?T ?w ?W ?$ ?%
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
99 ?^ ?( ?) ?- ?+ ?| ?{ ?} ?[ ?] ?' ?`
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
100 ?; ?, ?0 ?? ?/ ?\C-m ?\
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
101 space return
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
102 delete backspace
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
103 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
104 "Movement commands")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
105 ;; define viper-movement-command-p
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
106 (viper-test-com-defun viper-movement-command)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
107
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
108 ;; Vi digit commands
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
109 (defconst viper-digit-commands '(?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
110
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
111 ;; define viper-digit-command-p
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
112 (viper-test-com-defun viper-digit-command)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
113
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
114 ;; Commands that can be repeated by . (dotted)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
115 (defconst viper-dotable-commands '(?c ?d ?C ?s ?S ?D ?> ?<))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
116 ;; define viper-dotable-command-p
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
117 (viper-test-com-defun viper-dotable-command)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
118
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
119 ;; Commands that can follow a #
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
120 (defconst viper-hash-commands '(?c ?C ?g ?q ?s))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
121 ;; define viper-hash-command-p
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
122 (viper-test-com-defun viper-hash-command)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
123
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
124 ;; Commands that may have registers as prefix
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
125 (defconst viper-regsuffix-commands '(?d ?y ?Y ?D ?p ?P ?x ?X))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
126 ;; define viper-regsuffix-command-p
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
127 (viper-test-com-defun viper-regsuffix-command)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
128
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
129 (defconst viper-vi-commands (append viper-movement-commands
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
130 viper-digit-commands
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
131 viper-dotable-commands
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
132 viper-charpair-commands
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
133 viper-hash-commands
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
134 viper-prefix-commands
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
135 viper-regsuffix-commands)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
136 "The list of all commands in Vi-state.")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
137 ;; define viper-vi-command-p
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
138 (viper-test-com-defun viper-vi-command)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
139
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
140
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
141 ;;; CODE
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
142
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
143 ;; sentinels
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
144
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
145 ;; Runs viper-after-change-functions inside after-change-functions
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
146 (defun viper-after-change-sentinel (beg end len)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
147 (let ((list viper-after-change-functions))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
148 (while list
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
149 (funcall (car list) beg end len)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
150 (setq list (cdr list)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
151
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
152 ;; Runs viper-before-change-functions inside before-change-functions
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
153 (defun viper-before-change-sentinel (beg end)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
154 (let ((list viper-before-change-functions))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
155 (while list
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
156 (funcall (car list) beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
157 (setq list (cdr list)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
158
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
159 (defsubst viper-post-command-sentinel ()
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
160 (run-hooks 'viper-post-command-hooks))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
161
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
162 (defsubst viper-pre-command-sentinel ()
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
163 (run-hooks 'viper-pre-command-hooks))
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 ;; Needed so that Viper will be able to figure the last inserted
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
166 ;; chunk of text with reasonable accuracy.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
167 (defsubst viper-insert-state-post-command-sentinel ()
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
168 (if (and (memq viper-current-state '(insert-state replace-state))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
169 viper-insert-point
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
170 (>= (point) viper-insert-point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
171 (setq viper-last-posn-while-in-insert-state (point-marker)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
172 (if (eq viper-current-state 'insert-state)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
173 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
174 (or (stringp viper-saved-cursor-color)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
175 (string= (viper-get-cursor-color) viper-insert-state-cursor-color)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
176 (setq viper-saved-cursor-color (viper-get-cursor-color)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
177 (if (stringp viper-saved-cursor-color)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
178 (viper-change-cursor-color viper-insert-state-cursor-color))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
179 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
180 (if (and (eq this-command 'dabbrev-expand)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
181 (integerp viper-pre-command-point)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
182 (markerp viper-insert-point)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
183 (marker-position viper-insert-point)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
184 (> viper-insert-point viper-pre-command-point))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
185 (viper-move-marker-locally viper-insert-point viper-pre-command-point))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
186 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
187
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
188 (defsubst viper-insert-state-pre-command-sentinel ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
189 (or (memq this-command '(self-insert-command))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
190 (memq (viper-event-key last-command-event)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
191 '(up down left right (meta f) (meta b)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
192 (control n) (control p) (control f) (control b)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
193 (viper-restore-cursor-color-after-insert))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
194 (if (and (eq this-command 'dabbrev-expand)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
195 (markerp viper-insert-point)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
196 (marker-position viper-insert-point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
197 (setq viper-pre-command-point (marker-position viper-insert-point))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
198
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
199 (defsubst viper-R-state-post-command-sentinel ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
200 ;; Restoring cursor color is needed despite
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
201 ;; viper-replace-state-pre-command-sentinel: When you jump to another buffer
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
202 ;; in another frame, the pre-command hook won't change cursor color to
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
203 ;; default in that other frame. So, if the second frame cursor was red and
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
204 ;; we set the point outside the replacement region, then the cursor color
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
205 ;; will remain red. Restoring the default, below, prevents this.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
206 (if (and (<= (viper-replace-start) (point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
207 (<= (point) (viper-replace-end)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
208 (viper-change-cursor-color viper-replace-overlay-cursor-color)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
209 (viper-restore-cursor-color-after-replace)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
210 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
211
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
212 ;; to speed up, don't change cursor color before self-insert
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
213 ;; and common move commands
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
214 (defsubst viper-replace-state-pre-command-sentinel ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
215 (or (memq this-command '(self-insert-command))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
216 (memq (viper-event-key last-command-event)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
217 '(up down left right (meta f) (meta b)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
218 (control n) (control p) (control f) (control b)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
219 (viper-restore-cursor-color-after-replace)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
220
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
221 (defun viper-replace-state-post-command-sentinel ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
222 ;; Restoring cursor color is needed despite
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
223 ;; viper-replace-state-pre-command-sentinel: When one jumps to another buffer
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
224 ;; in another frame, the pre-command hook won't change cursor color to
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
225 ;; 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
226 ;; we set the point outside the replacement region, then the cursor color
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
227 ;; will remain red. Restoring the default, below, fixes this problem.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
228 ;;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
229 ;; 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
230 ;; cursor color or, if they terminate replace mode, the color will be changed
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
231 ;; in viper-finish-change
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
232 (or (memq this-command '(self-insert-command))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
233 (viper-restore-cursor-color-after-replace))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
234 (cond
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
235 ((eq viper-current-state 'replace-state)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
236 ;; delete characters to compensate for inserted chars.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
237 (let ((replace-boundary (viper-replace-end)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
238 (save-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
239 (goto-char viper-last-posn-in-replace-region)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
240 (viper-trim-replace-chars-to-delete-if-necessary)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
241 (delete-char viper-replace-chars-to-delete)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
242 (setq viper-replace-chars-to-delete 0)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
243 ;; terminate replace mode if reached replace limit
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
244 (if (= viper-last-posn-in-replace-region (viper-replace-end))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
245 (viper-finish-change)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
246
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
247 (if (viper-pos-within-region
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
248 (point) (viper-replace-start) replace-boundary)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
249 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
250 ;; the state may have changed in viper-finish-change above
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
251 (if (eq viper-current-state 'replace-state)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
252 (viper-change-cursor-color viper-replace-overlay-cursor-color))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
253 (setq viper-last-posn-in-replace-region (point-marker))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
254 ))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
255 ;; terminate replace mode if changed Viper states.
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
256 (t (viper-finish-change))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
257
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
258
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
259 ;; changing mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
260
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
261 ;; Change state to NEW-STATE---either emacs-state, vi-state, or insert-state.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
262 (defun viper-change-state (new-state)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
263 ;; Keep viper-post/pre-command-hooks fresh.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
264 ;; We remove then add viper-post/pre-command-sentinel since it is very
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
265 ;; desirable that viper-pre-command-sentinel is the last hook and
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
266 ;; viper-post-command-sentinel is the first hook.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
267 (remove-hook 'post-command-hook 'viper-post-command-sentinel)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
268 (add-hook 'post-command-hook 'viper-post-command-sentinel)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
269 (remove-hook 'pre-command-hook 'viper-pre-command-sentinel)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
270 (add-hook 'pre-command-hook 'viper-pre-command-sentinel t)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
271 ;; These hooks will be added back if switching to insert/replace mode
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
272 (viper-remove-hook 'viper-post-command-hooks
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
273 'viper-insert-state-post-command-sentinel)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
274 (viper-remove-hook 'viper-pre-command-hooks
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
275 'viper-insert-state-pre-command-sentinel)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
276 (setq viper-intermediate-command nil)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
277 (cond ((eq new-state 'vi-state)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
278 (cond ((member viper-current-state '(insert-state replace-state))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
279
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
280 ;; move viper-last-posn-while-in-insert-state
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
281 ;; This is a normal hook that is executed in insert/replace
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
282 ;; states after each command. In Vi/Emacs state, it does
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
283 ;; nothing. We need to execute it here to make sure that
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
284 ;; the last posn was recorded when we hit ESC.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
285 ;; It may be left unrecorded if the last thing done in
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
286 ;; insert/repl state was dabbrev-expansion or abbrev
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
287 ;; expansion caused by hitting ESC
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
288 (viper-insert-state-post-command-sentinel)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
289
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
290 (condition-case conds
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
291 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
292 (viper-save-last-insertion
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
293 viper-insert-point
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
294 viper-last-posn-while-in-insert-state)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
295 (if viper-began-as-replace
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
296 (setq viper-began-as-replace nil)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
297 ;; repeat insert commands if numerical arg > 1
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
298 (save-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
299 (viper-repeat-insert-command))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
300 (error
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
301 (viper-message-conditions conds)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
302
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
303 (if (> (length viper-last-insertion) 0)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
304 (viper-push-onto-ring viper-last-insertion
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
305 'viper-insertion-ring))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
306
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
307 (if viper-ex-style-editing
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
308 (or (bolp) (backward-char 1))))
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 ;; insert or replace
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
312 ((memq new-state '(insert-state replace-state))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
313 (if (memq viper-current-state '(emacs-state vi-state))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
314 (viper-move-marker-locally 'viper-insert-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
315 (viper-move-marker-locally
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
316 'viper-last-posn-while-in-insert-state (point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
317 (viper-add-hook 'viper-post-command-hooks
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
318 'viper-insert-state-post-command-sentinel t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
319 (viper-add-hook 'viper-pre-command-hooks
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
320 'viper-insert-state-pre-command-sentinel t))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
321 ) ; outermost cond
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
322
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
323 ;; Nothing needs to be done to switch to emacs mode! Just set some
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
324 ;; variables, which is already done in viper-change-state-to-emacs!
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
325
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
326 ;; ISO accents
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
327 ;; always turn off iso-accents-mode in vi-state, or else we won't be able to
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
328 ;; use the keys `,',^ , as they will do accents instead of Vi actions.
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
329 (cond ((eq new-state 'vi-state) (viper-set-iso-accents-mode nil));accents off
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
330 (viper-automatic-iso-accents (viper-set-iso-accents-mode t));accents on
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
331 (t (viper-set-iso-accents-mode nil)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
332 ;; Always turn off quail mode in vi state
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
333 (cond ((eq new-state 'vi-state) (viper-set-input-method nil)) ;intl input off
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
334 (viper-special-input-method (viper-set-input-method t)) ;intl input on
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
335 (t (viper-set-input-method nil)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
336
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
337 (setq viper-current-state new-state)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
338
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
339 (viper-update-syntax-classes)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
340 (viper-normalize-minor-mode-map-alist)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
341 (viper-adjust-keys-for new-state)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
342 (viper-set-mode-vars-for new-state)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
343 (viper-refresh-mode-line)
163
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
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
347
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
348 (defun viper-adjust-keys-for (state)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
349 "Make necessary adjustments to keymaps before entering STATE."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
350 (cond ((memq state '(insert-state replace-state))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
351 (if viper-auto-indent
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
352 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
353 (define-key viper-insert-basic-map "\C-m" 'viper-autoindent)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
354 (if viper-want-emacs-keys-in-insert
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
355 ;; expert
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
356 (define-key viper-insert-basic-map "\C-j" nil)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
357 ;; novice
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
358 (define-key viper-insert-basic-map "\C-j" 'viper-autoindent)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
359 (define-key viper-insert-basic-map "\C-m" nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
360 (define-key viper-insert-basic-map "\C-j" nil))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
361
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
362 (setq viper-insert-diehard-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
363 (not viper-want-emacs-keys-in-insert))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
364
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
365 (if viper-want-ctl-h-help
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
366 (progn
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
367 (define-key viper-insert-basic-map "\C-h" 'help-command)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
368 (define-key viper-replace-map "\C-h" 'help-command))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
369 (define-key viper-insert-basic-map
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
370 "\C-h" 'viper-del-backward-char-in-insert)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
371 (define-key viper-replace-map
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
372 "\C-h" 'viper-del-backward-char-in-replace))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
373 ;; In XEmacs, C-h overrides backspace, so we make sure it doesn't.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
374 (define-key viper-insert-basic-map
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
375 [backspace] 'viper-del-backward-char-in-insert)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
376 (define-key viper-replace-map
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
377 [backspace] 'viper-del-backward-char-in-replace)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
378 ) ; end insert/replace case
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
379 (t ; Vi state
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
380 (setq viper-vi-diehard-minor-mode (not viper-want-emacs-keys-in-vi))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
381 (if viper-want-ctl-h-help
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
382 (define-key viper-vi-basic-map "\C-h" 'help-command)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
383 (define-key viper-vi-basic-map "\C-h" 'viper-backward-char))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
384 ;; In XEmacs, C-h overrides backspace, so we make sure it doesn't.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
385 (define-key viper-vi-basic-map [backspace] 'viper-backward-char))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
386 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
387
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
388
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
389 ;; Normalizes minor-mode-map-alist by putting Viper keymaps first.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
390 ;; This ensures that Viper bindings are in effect, regardless of which minor
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
391 ;; modes were turned on by the user or by other packages.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
392 (defun viper-normalize-minor-mode-map-alist ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
393 (setq minor-mode-map-alist
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
394 (viper-append-filter-alist
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
395 (list
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
396 (cons 'viper-vi-intercept-minor-mode viper-vi-intercept-map)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
397 (cons 'viper-vi-minibuffer-minor-mode viper-minibuffer-map)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
398 (cons 'viper-vi-local-user-minor-mode viper-vi-local-user-map)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
399 (cons 'viper-vi-kbd-minor-mode viper-vi-kbd-map)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
400 (cons 'viper-vi-global-user-minor-mode viper-vi-global-user-map)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
401 (cons 'viper-vi-state-modifier-minor-mode
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
402 (if (keymapp
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
403 (cdr (assoc major-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
404 viper-vi-state-modifier-alist)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
405 (cdr (assoc major-mode viper-vi-state-modifier-alist))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
406 viper-empty-keymap))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
407 (cons 'viper-vi-diehard-minor-mode viper-vi-diehard-map)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
408 (cons 'viper-vi-basic-minor-mode viper-vi-basic-map)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
409 (cons 'viper-insert-intercept-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
410 viper-insert-intercept-map)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
411 (cons 'viper-replace-minor-mode viper-replace-map)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
412 ;; viper-insert-minibuffer-minor-mode must come after
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
413 ;; viper-replace-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
414 (cons 'viper-insert-minibuffer-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
415 viper-minibuffer-map)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
416 (cons 'viper-insert-local-user-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
417 viper-insert-local-user-map)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
418 (cons 'viper-insert-kbd-minor-mode viper-insert-kbd-map)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
419 (cons 'viper-insert-global-user-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
420 viper-insert-global-user-map)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
421 (cons 'viper-insert-state-modifier-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
422 (if (keymapp
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
423 (cdr (assoc major-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
424 viper-insert-state-modifier-alist)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
425 (cdr (assoc major-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
426 viper-insert-state-modifier-alist))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
427 viper-empty-keymap))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
428 (cons 'viper-insert-diehard-minor-mode viper-insert-diehard-map)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
429 (cons 'viper-insert-basic-minor-mode viper-insert-basic-map)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
430 (cons 'viper-emacs-intercept-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
431 viper-emacs-intercept-map)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
432 (cons 'viper-emacs-local-user-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
433 viper-emacs-local-user-map)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
434 (cons 'viper-emacs-kbd-minor-mode viper-emacs-kbd-map)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
435 (cons 'viper-emacs-global-user-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
436 viper-emacs-global-user-map)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
437 (cons 'viper-emacs-state-modifier-minor-mode
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
438 (if (keymapp
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
439 (cdr
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
440 (assoc major-mode viper-emacs-state-modifier-alist)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
441 (cdr
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
442 (assoc major-mode viper-emacs-state-modifier-alist))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
443 viper-empty-keymap))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
444 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
445 minor-mode-map-alist)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
446
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
447
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
448
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
449
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
450
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
451 ;; Viper mode-changing commands and utilities
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
452
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
453 ;; Modifies mode-line-buffer-identification.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
454 (defun viper-refresh-mode-line ()
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
455 (setq viper-mode-string
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
456 (cond ((eq viper-current-state 'emacs-state) viper-emacs-state-id)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
457 ((eq viper-current-state 'vi-state) viper-vi-state-id)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
458 ((eq viper-current-state 'replace-state) viper-replace-state-id)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
459 ((eq viper-current-state 'insert-state) viper-insert-state-id)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
460
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
461 ;; Sets Viper mode string in global-mode-string
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
462 (force-mode-line-update))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
463
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
464
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
465 ;; Switch from Insert state to Vi state.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
466 (defun viper-exit-insert-state ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
467 (interactive)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
468 (viper-change-state-to-vi))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
469
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
470 (defun viper-set-mode-vars-for (state)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
471 "Sets Viper minor mode variables to put Viper's state STATE in effect."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
472
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
473 ;; Emacs state
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
474 (setq viper-vi-minibuffer-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
475 viper-insert-minibuffer-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
476 viper-vi-intercept-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
477 viper-insert-intercept-minor-mode nil
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
478
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
479 viper-vi-local-user-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
480 viper-vi-kbd-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
481 viper-vi-global-user-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
482 viper-vi-state-modifier-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
483 viper-vi-diehard-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
484 viper-vi-basic-minor-mode nil
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
485
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
486 viper-replace-minor-mode nil
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
487
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
488 viper-insert-local-user-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
489 viper-insert-kbd-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
490 viper-insert-global-user-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
491 viper-insert-state-modifier-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
492 viper-insert-diehard-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
493 viper-insert-basic-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
494 viper-emacs-intercept-minor-mode t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
495 viper-emacs-local-user-minor-mode t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
496 viper-emacs-kbd-minor-mode (not (viper-is-in-minibuffer))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
497 viper-emacs-global-user-minor-mode t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
498 viper-emacs-state-modifier-minor-mode t
163
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 ;; Vi state
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
502 (if (eq state 'vi-state) ; adjust for vi-state
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
503 (setq
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
504 viper-vi-intercept-minor-mode t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
505 viper-vi-minibuffer-minor-mode (viper-is-in-minibuffer)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
506 viper-vi-local-user-minor-mode t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
507 viper-vi-kbd-minor-mode (not (viper-is-in-minibuffer))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
508 viper-vi-global-user-minor-mode t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
509 viper-vi-state-modifier-minor-mode t
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
510 ;; don't let the diehard keymap block command completion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
511 ;; and other things in the minibuffer
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
512 viper-vi-diehard-minor-mode (not
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
513 (or viper-want-emacs-keys-in-vi
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
514 (viper-is-in-minibuffer)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
515 viper-vi-basic-minor-mode t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
516 viper-emacs-intercept-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
517 viper-emacs-local-user-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
518 viper-emacs-kbd-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
519 viper-emacs-global-user-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
520 viper-emacs-state-modifier-minor-mode nil
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
521 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
522
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
523 ;; Insert and Replace states
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
524 (if (member state '(insert-state replace-state))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
525 (setq
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
526 viper-insert-intercept-minor-mode t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
527 viper-replace-minor-mode (eq state 'replace-state)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
528 viper-insert-minibuffer-minor-mode (viper-is-in-minibuffer)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
529 viper-insert-local-user-minor-mode t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
530 viper-insert-kbd-minor-mode (not (viper-is-in-minibuffer))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
531 viper-insert-global-user-minor-mode t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
532 viper-insert-state-modifier-minor-mode t
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
533 ;; don't let the diehard keymap block command completion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
534 ;; and other things in the minibuffer
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
535 viper-insert-diehard-minor-mode (not
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
536 (or
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
537 viper-want-emacs-keys-in-insert
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
538 (viper-is-in-minibuffer)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
539 viper-insert-basic-minor-mode t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
540 viper-emacs-intercept-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
541 viper-emacs-local-user-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
542 viper-emacs-kbd-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
543 viper-emacs-global-user-minor-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
544 viper-emacs-state-modifier-minor-mode nil
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
545 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
546
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
547 ;; minibuffer faces
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
548 (if (viper-has-face-support-p)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
549 (setq viper-minibuffer-current-face
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
550 (cond ((eq state 'emacs-state) viper-minibuffer-emacs-face)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
551 ((eq state 'vi-state) viper-minibuffer-vi-face)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
552 ((memq state '(insert-state replace-state))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
553 viper-minibuffer-insert-face))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
554
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
555 (if (viper-is-in-minibuffer)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
556 (viper-set-minibuffer-overlay))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
557 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
558
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
559 ;; This also takes care of the annoying incomplete lines in files.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
560 ;; Also, this fixes `undo' to work vi-style for complex commands.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
561 (defun viper-change-state-to-vi ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
562 "Change Viper state to Vi."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
563 (interactive)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
564 (if (and viper-first-time (not (viper-is-in-minibuffer)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
565 (viper-mode)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
566 (if overwrite-mode (overwrite-mode nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
567 (if abbrev-mode (expand-abbrev))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
568 (if (and auto-fill-function (> (current-column) fill-column))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
569 (funcall auto-fill-function))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
570 ;; don't leave whitespace lines around
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
571 (if (and (memq last-command
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
572 '(viper-autoindent
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
573 viper-open-line viper-Open-line
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
574 viper-replace-state-exit-cmd))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
575 (viper-over-whitespace-line))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
576 (indent-to-left-margin))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
577 (viper-add-newline-at-eob-if-necessary)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
578 (viper-adjust-undo)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
579 (viper-change-state 'vi-state)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
580
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
581 (viper-restore-cursor-color-after-insert)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
582
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
583 ;; Protect against user errors in hooks
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
584 (condition-case conds
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
585 (run-hooks 'viper-vi-state-hook)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
586 (error
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
587 (viper-message-conditions conds)))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
588
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
589 (defun viper-change-state-to-insert ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
590 "Change Viper state to Insert."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
591 (interactive)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
592 (viper-change-state 'insert-state)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
593
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
594 (or (stringp viper-saved-cursor-color)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
595 (string= (viper-get-cursor-color) viper-insert-state-cursor-color)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
596 (setq viper-saved-cursor-color (viper-get-cursor-color)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
597 ;; Commented out, because if viper-change-state-to-insert is executed
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
598 ;; non-interactively then the old cursor color may get lost. Same old Emacs
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
599 ;; bug related to local variables?
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
600 ;;;(if (stringp viper-saved-cursor-color)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
601 ;;; (viper-change-cursor-color viper-insert-state-cursor-color))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
602
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
603 ;; Protect against user errors in hooks
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
604 (condition-case conds
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
605 (run-hooks 'viper-insert-state-hook)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
606 (error
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
607 (viper-message-conditions conds))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
608
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
609 (defsubst viper-downgrade-to-insert ()
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
610 (setq viper-current-state 'insert-state
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
611 viper-replace-minor-mode nil))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
612
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
613
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
614
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
615 ;; Change to replace state. When the end of replacement region is reached,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
616 ;; replace state changes to insert state.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
617 (defun viper-change-state-to-replace (&optional non-R-cmd)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
618 (viper-change-state 'replace-state)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
619 ;; Run insert-state-hook
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
620 (condition-case conds
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
621 (run-hooks 'viper-insert-state-hook 'viper-replace-state-hook)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
622 (error
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
623 (viper-message-conditions conds)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
624
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
625 (if non-R-cmd
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
626 (viper-start-replace)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
627 ;; 'R' is implemented using Emacs's overwrite-mode
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
628 (viper-start-R-mode))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
629 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
630
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
631
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
632 (defun viper-change-state-to-emacs ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
633 "Change Viper state to Emacs."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
634 (interactive)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
635 (viper-change-state 'emacs-state)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
636
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
637 ;; Protect agains user errors in hooks
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
638 (condition-case conds
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
639 (run-hooks 'viper-emacs-state-hook)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
640 (error
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
641 (viper-message-conditions conds))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
642
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
643 ;; escape to emacs mode termporarily
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
644 (defun viper-escape-to-emacs (arg &optional events)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
645 "Escape to Emacs state from Vi state for one Emacs command.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
646 ARG is used as the prefix value for the executed command. If
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
647 EVENTS is a list of events, which become the beginning of the command."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
648 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
649 (if (= last-command-char ?\\)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
650 (message "Switched to EMACS state for the next command..."))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
651 (viper-escape-to-state arg events 'emacs-state))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
652
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
653 ;; escape to Vi mode termporarily
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
654 (defun viper-escape-to-vi (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
655 "Escape from Emacs state to Vi state for one Vi 1-character command.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
656 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
657 Vi's prefix argument will be used. Otherwise, the prefix argument passed to
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
658 `viper-escape-to-vi' is used."
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
659 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
660 (message "Switched to VI state for the next command...")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
661 (viper-escape-to-state arg nil 'vi-state))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
662
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
663 ;; Escape to STATE mode for one Emacs command.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
664 (defun viper-escape-to-state (arg events state)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
665 ;;(let (com key prefix-arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
666 (let (com key)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
667 ;; this temporarily turns off Viper's minor mode keymaps
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
668 (viper-set-mode-vars-for state)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
669 (viper-normalize-minor-mode-map-alist)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
670 (if events (viper-set-unread-command-events events))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
671
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
672 ;; protect against keyboard quit and other errors
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
673 (condition-case nil
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
674 (let (viper-vi-kbd-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
675 viper-insert-kbd-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
676 viper-emacs-kbd-minor-mode)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
677 (unwind-protect
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
678 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
679 (setq com (key-binding (setq key
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
680 (if viper-xemacs-p
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
681 (read-key-sequence nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
682 (read-key-sequence nil t)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
683 ;; In case of binding indirection--chase definitions.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
684 ;; Have to do it here because we execute this command under
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
685 ;; different keymaps, so command-execute may not do the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
686 ;; right thing there
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
687 (while (vectorp com) (setq com (key-binding com))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
688 nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
689 ;; Execute command com in the original Viper state, not in state
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
690 ;; `state'. Otherwise, if we switch buffers while executing the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
691 ;; escaped to command, Viper's mode vars will remain those of
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
692 ;; `state'. When we return to the orig buffer, the bindings will be
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
693 ;; screwed up.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
694 (viper-set-mode-vars-for viper-current-state)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
695
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
696 ;; this-command, last-command-char, last-command-event
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
697 (setq this-command com)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
698 (if viper-xemacs-p ; XEmacs represents key sequences as vectors
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
699 (setq last-command-event
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
700 (viper-copy-event (viper-seq-last-elt key))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
701 last-command-char (event-to-character last-command-event))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
702 ;; Emacs represents them as sequences (str or vec)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
703 (setq last-command-event
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
704 (viper-copy-event (viper-seq-last-elt key))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
705 last-command-char last-command-event))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
706
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
707 (if (commandp com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
708 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
709 (setq prefix-arg (or prefix-arg arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
710 (command-execute com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
711 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
712 (quit (ding))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
713 (error (beep 1))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
714 ;; set state in the new buffer
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
715 (viper-set-mode-vars-for viper-current-state))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
716
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
717 (defun viper-exec-form-in-vi (form)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
718 "Execute FORM in Vi state, regardless of the Ccurrent Vi state."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
719 (let ((buff (current-buffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
720 result)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
721 (viper-set-mode-vars-for 'vi-state)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
722
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
723 (condition-case nil
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
724 (let (viper-vi-kbd-minor-mode) ; execute without kbd macros
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
725 (setq result (eval form))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
726 )
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
727 (error
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
728 (signal 'quit nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
729
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
730 (if (not (equal buff (current-buffer))) ; cmd switched buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
731 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
732 (set-buffer buff)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
733 (viper-set-mode-vars-for viper-current-state)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
734 (viper-set-mode-vars-for viper-current-state)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
735 result))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
736
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
737 (defun viper-exec-form-in-emacs (form)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
738 "Execute FORM in Emacs, temporarily disabling Viper's minor modes.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
739 Similar to viper-escape-to-emacs, but accepts forms rather than keystrokes."
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
740 (let ((buff (current-buffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
741 result)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
742 (viper-set-mode-vars-for 'emacs-state)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
743 (setq result (eval form))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
744 (if (not (equal buff (current-buffer))) ; cmd switched buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
745 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
746 (set-buffer buff)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
747 (viper-set-mode-vars-for viper-current-state)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
748 (viper-set-mode-vars-for viper-current-state)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
749 result))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
750
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
751
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
752 ;; This is needed because minor modes sometimes override essential Viper
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
753 ;; bindings. By letting Viper know which files these modes are in, it will
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
754 ;; arrange to reorganize minor-mode-map-alist so that things will work right.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
755 (defun viper-harness-minor-mode (load-file)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
756 "Familiarize Viper with a minor mode defined in LOAD_FILE.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
757 Minor modes that have their own keymaps may overshadow Viper keymaps.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
758 This function is designed to make Viper aware of the packages that define
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
759 such minor modes.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
760 Usage:
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
761 (viper-harness-minor-mode load-file)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
762
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
763 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
764 Suffixes such as .el or .elc should be stripped."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
765
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
766 (interactive "sEnter name of the load file: ")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
767
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
768 (eval-after-load load-file '(viper-normalize-minor-mode-map-alist))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
769
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
770 ;; Change the default for minor-mode-map-alist each time a harnessed minor
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
771 ;; mode adds its own keymap to the a-list.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
772 (eval-after-load
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
773 load-file '(setq-default minor-mode-map-alist minor-mode-map-alist))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
774 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
775
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
776
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
777 (defun viper-ESC (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
778 "Emulate ESC key in Emacs.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
779 Prevents multiple escape keystrokes if viper-no-multiple-ESC is true.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
780 If viper-no-multiple-ESC is 'twice double ESC would ding in vi-state.
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
781 Other ESC sequences are emulated via the current Emacs's major mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
782 keymap. This is more convenient on TTYs, since this won't block
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
783 function keys such as up,down, etc. ESC will also will also work as
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
784 a Meta key in this case. When viper-no-multiple-ESC is nil, ESC functions
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
785 as a Meta key and any number of multiple escapes is allowed."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
786 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
787 (let (char)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
788 (cond ((and (not viper-no-multiple-ESC) (eq viper-current-state 'vi-state))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
789 (setq char (viper-read-char-exclusive))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
790 (viper-escape-to-emacs arg (list ?\e char) ))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
791 ((and (eq viper-no-multiple-ESC 'twice)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
792 (eq viper-current-state 'vi-state))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
793 (setq char (viper-read-char-exclusive))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
794 (if (= char (string-to-char viper-ESC-key))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
795 (ding)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
796 (viper-escape-to-emacs arg (list ?\e char) )))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
797 (t (ding)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
798 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
799
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
800 (defun viper-alternate-Meta-key (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
801 "Simulate Emacs Meta key."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
802 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
803 (sit-for 1) (message "ESC-")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
804 (viper-escape-to-emacs arg '(?\e)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
805
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
806 (defun viper-toggle-key-action ()
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
807 "Action bound to `viper-toggle-key'."
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
808 (interactive)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
809 (if (and (< viper-expert-level 2) (equal viper-toggle-key "\C-z"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
810 (if (viper-window-display-p)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
811 (viper-iconify)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
812 (suspend-emacs))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
813 (viper-change-state-to-emacs)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
814
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
815
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
816 ;; Intercept ESC sequences on dumb terminals.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
817 ;; Based on the idea contributed by Marcelino Veiga Tuimil <mveiga@dit.upm.es>
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
818
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
819 ;; 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
820 ;; But only if there are characters to read during a very short time.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
821 ;; Returns the last event, if any.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
822 (defun viper-envelop-ESC-key ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
823 (let ((event last-input-event)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
824 (keyseq [nil])
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
825 inhibit-quit)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
826 (if (viper-ESC-event-p event)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
827 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
828 (if (viper-fast-keysequence-p)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
829 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
830 (let (minor-mode-map-alist)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
831 (viper-set-unread-command-events event)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
832 (setq keyseq
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
833 (funcall
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
834 (ad-get-orig-definition 'read-key-sequence) nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
835 ) ; let
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
836 ;; If keyseq translates into something that still has ESC
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
837 ;; at the beginning, separate ESC from the rest of the seq.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
838 ;; In XEmacs we check for events that are keypress meta-key
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
839 ;; and convert them into [escape 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 ;; This is needed for the following reason:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
842 ;; If ESC is the first symbol, we interpret it as if the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
843 ;; user typed ESC and then quickly some other symbols.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
844 ;; If ESC is not the first one, then the key sequence
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
845 ;; entered was apparently translated into a function key or
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
846 ;; something (e.g., one may have
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
847 ;; (define-key function-key-map "\e[192z" [f11])
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
848 ;; which would translate the escape-sequence generated by
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
849 ;; f11 in an xterm window into the symbolic key f11.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
850 ;;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
851 ;; If `first-key' is not an ESC event, we make it into the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
852 ;; last-command-event in order to pretend that this key was
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
853 ;; pressed. This is needed to allow arrow keys to be bound to
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
854 ;; macros. Otherwise, viper-exec-mapped-kbd-macro will think
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
855 ;; that the last event was ESC and so it'll execute whatever is
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
856 ;; bound to ESC. (Viper macros can't be bound to
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
857 ;; ESC-sequences).
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
858 (let* ((first-key (elt keyseq 0))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
859 (key-mod (event-modifiers first-key)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
860 (cond ((viper-ESC-event-p first-key)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
861 ;; put keys following ESC on the unread list
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
862 ;; and return ESC as the key-sequence
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
863 (viper-set-unread-command-events (subseq keyseq 1))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
864 (setq last-input-event event
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
865 keyseq (if viper-emacs-p
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
866 "\e"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
867 (vector (character-to-event ?\e)))))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
868 ((and viper-xemacs-p
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
869 (key-press-event-p first-key)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
870 (equal '(meta) key-mod))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
871 (viper-set-unread-command-events
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
872 (vconcat (vector
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
873 (character-to-event (event-key first-key)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
874 (subseq keyseq 1)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
875 (setq last-input-event event
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
876 keyseq (vector (character-to-event ?\e))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
877 ((eventp first-key)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
878 (setq last-command-event
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
879 (viper-copy-event first-key)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
880 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
881 ) ; end progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
882
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
883 ;; this is escape event with nothing after it
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
884 ;; put in unread-command-event and then re-read
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
885 (viper-set-unread-command-events event)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
886 (setq keyseq
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
887 (funcall (ad-get-orig-definition 'read-key-sequence) nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
888 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
889 ;; not an escape event
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
890 (setq keyseq (vector event)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
891 keyseq))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
892
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
893
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
894
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
895 ;; Listen to ESC key.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
896 ;; 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
897 ;; interpret these keys in Emacs mode, so ESC won't be interpreted as a Vi key.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
898 (defun viper-intercept-ESC-key ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
899 "Function that implements ESC key in Viper emulation of Vi."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
900 (interactive)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
901 (let ((cmd (or (key-binding (viper-envelop-ESC-key))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
902 '(lambda () (interactive) (error "")))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
903
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
904 ;; call the actual function to execute ESC (if no other symbols followed)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
905 ;; or the key bound to the ESC sequence (if the sequence was issued
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
906 ;; with very short delay between characters.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
907 (if (eq cmd 'viper-intercept-ESC-key)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
908 (setq cmd
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
909 (cond ((eq viper-current-state 'vi-state)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
910 'viper-ESC)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
911 ((eq viper-current-state 'insert-state)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
912 'viper-exit-insert-state)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
913 ((eq viper-current-state 'replace-state)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
914 'viper-replace-state-exit-cmd)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
915 (t 'viper-change-state-to-vi)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
916 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
917 (call-interactively cmd)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
918
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
919
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
920
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
921
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
922 ;; prefix argument for Vi mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
923
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
924 ;; In Vi mode, prefix argument is a dotted pair (NUM . COM) where NUM
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
925 ;; represents the numeric value of the prefix argument and COM represents
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
926 ;; command prefix such as "c", "d", "m" and "y".
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
927
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
928 ;; Get value part of prefix-argument ARG.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
929 (defsubst viper-p-val (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
930 (cond ((null arg) 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
931 ((consp arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
932 (if (or (null (car arg)) (equal (car arg) '(nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
933 1 (car arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
934 (t arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
935
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
936 ;; Get raw value part of prefix-argument ARG.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
937 (defsubst viper-P-val (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
938 (cond ((consp arg) (car arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
939 (t arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
940
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
941 ;; Get com part of prefix-argument ARG.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
942 (defsubst viper-getcom (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
943 (cond ((null arg) nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
944 ((consp arg) (cdr arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
945 (t nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
946
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
947 ;; Get com part of prefix-argument ARG and modify it.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
948 (defun viper-getCom (arg)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
949 (let ((com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
950 (cond ((equal com ?c) ?c)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
951 ;; Previously, ?c was being converted to ?C, but this prevented
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
952 ;; multiline replace regions.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
953 ;;((equal com ?c) ?C)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
954 ((equal com ?d) ?D)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
955 ((equal com ?y) ?Y)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
956 (t com))))
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 ;; Compute numeric prefix arg value.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
960 ;; Invoked by EVENT. COM is the command part obtained so far.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
961 (defun viper-prefix-arg-value (event com)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
962 (let ((viper-intermediate-command 'viper-digit-argument)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
963 value func)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
964 ;; read while number
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
965 (while (and (viper-characterp event) (>= event ?0) (<= event ?9))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
966 (setq value (+ (* (if (integerp value) value 0) 10) (- event ?0)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
967 (setq event (viper-read-event-convert-to-char)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
968
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
969 (setq prefix-arg value)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
970 (if com (setq prefix-arg (cons prefix-arg com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
971 (while (eq event ?U)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
972 (viper-describe-arg prefix-arg)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
973 (setq event (viper-read-event-convert-to-char)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
974
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
975 (if (or com (and (not (eq viper-current-state 'vi-state))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
976 ;; make sure it is a Vi command
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
977 (viper-characterp event) (viper-vi-command-p event)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
978 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
979 ;; If appears to be one of the vi commands,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
980 ;; then execute it with funcall and clear prefix-arg in order to not
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
981 ;; confuse subsequent commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
982 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
983 ;; last-command-char is the char we want emacs to think was typed
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
984 ;; last. If com is not nil, the viper-digit-argument command was
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
985 ;; called from within viper-prefix-arg command, such as `d', `w',
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
986 ;; etc., i.e., the user typed, say, d2. In this case, `com' would be
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
987 ;; `d', `w', etc. If viper-digit-argument was invoked by
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
988 ;; viper-escape-to-vi (which is indicated by the fact that the
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
989 ;; current state is not vi-state), then `event' represents the vi
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
990 ;; command to be executed (e.g., `d', `w', etc). Again,
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
991 ;; last-command-char must make emacs believe that this is the command
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
992 ;; we typed.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
993 (cond ((eq event 'return) (setq event ?\C-m))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
994 ((eq event 'delete) (setq event ?\C-?))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
995 ((eq event 'backspace) (setq event ?\C-h))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
996 ((eq event 'space) (setq event ?\ )))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
997 (setq last-command-char (or com event))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
998 (setq func (viper-exec-form-in-vi
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
999 (` (key-binding (char-to-string (, event))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1000 (funcall func prefix-arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1001 (setq prefix-arg nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1002 ;; some other command -- let emacs do it in its own way
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1003 (viper-set-unread-command-events event))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1004 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1005
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1006
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1007 ;; Vi operator as prefix argument."
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1008 (defun viper-prefix-arg-com (char value com)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1009 (let ((cont t)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1010 cmd-info
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1011 cmd-to-exec-at-end)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1012 (while (and cont
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1013 (memq char
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1014 (list ?c ?d ?y ?! ?< ?> ?= ?# ?r ?R ?\"
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1015 viper-buffer-search-char)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1016 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1017 ;; this means that we already have a command character, so we
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1018 ;; construct a com list and exit while. however, if char is "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1019 ;; it is an error.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1020 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1021 ;; new com is (CHAR . OLDCOM)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1022 (if (memq char '(?# ?\")) (error ""))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1023 (setq com (cons char com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1024 (setq cont nil))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1025 ;; If com is nil we set com as char, and read more. Again, if char is
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1026 ;; ", we read the name of register and store it in viper-use-register.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1027 ;; if char is !, =, or #, a complete com is formed so we exit the while
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1028 ;; loop.
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1029 (cond ((memq char '(?! ?=))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1030 (setq com char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1031 (setq char (read-char))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1032 (setq cont nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1033 ((= char ?#)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1034 ;; read a char and encode it as com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1035 (setq com (+ 128 (read-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1036 (setq char (read-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1037 ((= char ?\")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1038 (let ((reg (read-char)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1039 (if (viper-valid-register reg)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1040 (setq viper-use-register reg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1041 (error ""))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1042 (setq char (read-char))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1043 (t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1044 (setq com char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1045 (setq char (read-char))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1046
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1047 (if (atom com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1048 ;; `com' is a single char, so we construct the command argument
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1049 ;; and if `char' is `?', we describe the arg; otherwise
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1050 ;; we prepare the command that will be executed at the end.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1051 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1052 (setq cmd-info (cons value com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1053 (while (= char ?U)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1054 (viper-describe-arg cmd-info)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1055 (setq char (read-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1056 ;; `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
1057 ;; execute it at the very end
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1058 (or (viper-movement-command-p char)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1059 (viper-digit-command-p char)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1060 (viper-regsuffix-command-p char)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1061 (= char ?!) ; bang command
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1062 (error ""))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1063 (setq cmd-to-exec-at-end
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1064 (viper-exec-form-in-vi
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1065 (` (key-binding (char-to-string (, char)))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1066
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1067 ;; 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
1068 (if (memq (car com) '(?r ?R))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1069 ;; execute apropriate region command.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1070 (let ((char (car com)) (com (cdr com)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1071 (setq prefix-arg (cons value com))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1072 (if (= char ?r) (viper-region prefix-arg)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1073 (viper-Region prefix-arg))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1074 ;; reset prefix-arg
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1075 (setq prefix-arg nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1076 ;; otherwise, reset prefix arg and call appropriate command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1077 (setq value (if (null value) 1 value))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1078 (setq prefix-arg nil)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1079 (cond
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1080 ;; If we change ?C to ?c here, then cc will enter replacement mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1081 ;; rather than deleting lines. However, it will affect 1 less line than
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1082 ;; normal. We decided to not use replacement mode here and follow Vi,
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1083 ;; since replacement mode on n full lines can be achieved with nC.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1084 ((equal com '(?c . ?c)) (viper-line (cons value ?C)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1085 ((equal com '(?d . ?d)) (viper-line (cons value ?D)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1086 ((equal com '(?d . ?y)) (viper-yank-defun))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1087 ((equal com '(?y . ?y)) (viper-line (cons value ?Y)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1088 ((equal com '(?< . ?<)) (viper-line (cons value ?<)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1089 ((equal com '(?> . ?>)) (viper-line (cons value ?>)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1090 ((equal com '(?! . ?!)) (viper-line (cons value ?!)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1091 ((equal com '(?= . ?=)) (viper-line (cons value ?=)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1092 (t (error "")))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1093
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1094 (if cmd-to-exec-at-end
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1095 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1096 (setq last-command-char char)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1097 (setq last-command-event
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1098 (viper-copy-event
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1099 (if viper-xemacs-p (character-to-event char) char)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1100 (condition-case nil
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1101 (funcall cmd-to-exec-at-end cmd-info)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1102 (error
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1103 (error "")))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1104 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1105
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1106 (defun viper-describe-arg (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1107 (let (val com)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1108 (setq val (viper-P-val arg)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1109 com (viper-getcom arg))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1110 (if (null val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1111 (if (null com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1112 (message "Value is nil, and command is nil")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1113 (message "Value is nil, and command is `%c'" com))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1114 (if (null com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1115 (message "Value is `%d', and command is nil" val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1116 (message "Value is `%d', and command is `%c'" val com)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1117
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1118 (defun viper-digit-argument (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1119 "Begin numeric argument for the next command."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1120 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1121 (viper-leave-region-active)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1122 (viper-prefix-arg-value
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1123 last-command-char (if (consp arg) (cdr arg) nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1124
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1125 (defun viper-command-argument (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1126 "Accept a motion command as an argument."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1127 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1128 (let ((viper-intermediate-command 'viper-command-argument))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1129 (condition-case nil
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1130 (viper-prefix-arg-com
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1131 last-command-char
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1132 (cond ((null arg) nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1133 ((consp arg) (car arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1134 ((integerp arg) arg)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1135 (t (error viper-InvalidCommandArgument)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1136 (cond ((null arg) nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1137 ((consp arg) (cdr arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1138 ((integerp arg) nil)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1139 (t (error viper-InvalidCommandArgument))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1140 (quit (setq viper-use-register nil)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1141 (signal 'quit nil)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1142 (viper-deactivate-mark)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1143
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1144
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1145 ;; repeat last destructive command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1146
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1147 ;; Append region to text in register REG.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1148 ;; START and END are buffer positions indicating what to append.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1149 (defsubst viper-append-to-register (reg start end)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1150 (set-register reg (concat (if (stringp (get-register reg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1151 (get-register reg) "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1152 (buffer-substring start end))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1153
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1154 ;; Saves last inserted text for possible use by viper-repeat command.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1155 (defun viper-save-last-insertion (beg end)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1156 (condition-case nil
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1157 (setq viper-last-insertion (buffer-substring beg end))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1158 (error
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1159 ;; beg or end marker are somehow screwed up
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1160 (setq viper-last-insertion nil)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1161 (setq viper-last-insertion (buffer-substring beg end))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1162 (or (< (length viper-d-com) 5)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1163 (setcar (nthcdr 4 viper-d-com) viper-last-insertion))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1164 (or (null viper-command-ring)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1165 (ring-empty-p viper-command-ring)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1166 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1167 (setcar (nthcdr 4 (viper-current-ring-item viper-command-ring))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1168 viper-last-insertion)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1169 ;; del most recent elt, if identical to the second most-recent
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1170 (viper-cleanup-ring viper-command-ring)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1171 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1172
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1173 (defsubst viper-yank-last-insertion ()
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1174 "Inserts the text saved by the previous viper-save-last-insertion command."
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1175 (condition-case nil
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1176 (insert viper-last-insertion)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1177 (error nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1178
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1179
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1180 ;; define functions to be executed
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1181
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1182 ;; invoked by the `C' command
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1183 (defun viper-exec-change (m-com com)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1184 (or (and (markerp viper-com-point) (marker-position viper-com-point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1185 (set-marker viper-com-point (point) (current-buffer)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1186 ;; handle C cmd at the eol and at eob.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1187 (if (or (and (eolp) (= viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1188 (= viper-com-point (point-max)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1189 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1190 (insert " ")(backward-char 1)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1191 (if (= viper-com-point (point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1192 (viper-forward-char-carefully))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1193 (set-mark viper-com-point)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1194 (if (eq m-com 'viper-next-line-at-bol)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1195 (viper-enlarge-region (mark t) (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1196 (if (< (point) (mark t))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1197 (exchange-point-and-mark))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1198 (if (eq (preceding-char) ?\n)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1199 (viper-backward-char-carefully)) ; give back the newline
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1200 (if (= com ?c)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1201 (viper-change (mark t) (point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1202 (viper-change-subr (mark t) (point))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1203
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1204 ;; this is invoked by viper-substitute-line
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1205 (defun viper-exec-Change (m-com com)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1206 (save-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1207 (set-mark viper-com-point)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1208 (viper-enlarge-region (mark t) (point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1209 (if viper-use-register
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1210 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1211 (cond ((viper-valid-register viper-use-register '(letter digit))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1212 (copy-to-register
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1213 viper-use-register (mark t) (point) nil))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1214 ((viper-valid-register viper-use-register '(Letter))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1215 (viper-append-to-register
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1216 (downcase viper-use-register) (mark t) (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1217 (t (setq viper-use-register nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1218 (error viper-InvalidRegister viper-use-register)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1219 (setq viper-use-register nil)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1220 (delete-region (mark t) (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1221 (open-line 1)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1222 (if (= com ?C)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1223 (viper-change-state-to-insert)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1224 (viper-yank-last-insertion)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1225
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1226 (defun viper-exec-delete (m-com com)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1227 (or (and (markerp viper-com-point) (marker-position viper-com-point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1228 (set-marker viper-com-point (point) (current-buffer)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1229 (if viper-use-register
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1230 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1231 (cond ((viper-valid-register viper-use-register '(letter digit))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1232 (copy-to-register
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1233 viper-use-register viper-com-point (point) nil))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1234 ((viper-valid-register viper-use-register '(Letter))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1235 (viper-append-to-register
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1236 (downcase viper-use-register) viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1237 (t (setq viper-use-register nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1238 (error viper-InvalidRegister viper-use-register)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1239 (setq viper-use-register nil)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1240 (setq last-command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1241 (if (eq last-command 'd-command) 'kill-region nil))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1242 (kill-region viper-com-point (point))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1243 (setq this-command 'd-command)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1244 (if viper-ex-style-motion
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1245 (if (and (eolp) (not (bolp))) (backward-char 1))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1246
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1247 (defun viper-exec-Delete (m-com com)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1248 (save-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1249 (set-mark viper-com-point)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1250 (viper-enlarge-region (mark t) (point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1251 (if viper-use-register
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1252 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1253 (cond ((viper-valid-register viper-use-register '(letter digit))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1254 (copy-to-register
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1255 viper-use-register (mark t) (point) nil))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1256 ((viper-valid-register viper-use-register '(Letter))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1257 (viper-append-to-register
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1258 (downcase viper-use-register) (mark t) (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1259 (t (setq viper-use-register nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1260 (error viper-InvalidRegister viper-use-register)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1261 (setq viper-use-register nil)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1262 (setq last-command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1263 (if (eq last-command 'D-command) 'kill-region nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1264 (kill-region (mark t) (point))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1265 (if (eq m-com 'viper-line) (setq this-command 'D-command)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1266 (back-to-indentation))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1267
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1268 (defun viper-exec-yank (m-com com)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1269 (or (and (markerp viper-com-point) (marker-position viper-com-point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1270 (set-marker viper-com-point (point) (current-buffer)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1271 (if viper-use-register
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1272 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1273 (cond ((viper-valid-register viper-use-register '(letter digit))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1274 (copy-to-register
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1275 viper-use-register viper-com-point (point) nil))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1276 ((viper-valid-register viper-use-register '(Letter))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1277 (viper-append-to-register
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1278 (downcase viper-use-register) viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1279 (t (setq viper-use-register nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1280 (error viper-InvalidRegister viper-use-register)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1281 (setq viper-use-register nil)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1282 (setq last-command nil)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1283 (copy-region-as-kill viper-com-point (point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1284 (goto-char viper-com-point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1285
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1286 (defun viper-exec-Yank (m-com com)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1287 (save-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1288 (set-mark viper-com-point)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1289 (viper-enlarge-region (mark t) (point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1290 (if viper-use-register
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1291 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1292 (cond ((viper-valid-register viper-use-register '(letter digit))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1293 (copy-to-register
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1294 viper-use-register (mark t) (point) nil))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1295 ((viper-valid-register viper-use-register '(Letter))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1296 (viper-append-to-register
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1297 (downcase viper-use-register) (mark t) (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1298 (t (setq viper-use-register nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1299 (error viper-InvalidRegister viper-use-register)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1300 (setq viper-use-register nil)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1301 (setq last-command nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1302 (copy-region-as-kill (mark t) (point)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1303 (viper-deactivate-mark)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1304 (goto-char viper-com-point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1305
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1306 (defun viper-exec-bang (m-com com)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1307 (save-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1308 (set-mark viper-com-point)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1309 (viper-enlarge-region (mark t) (point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1310 (exchange-point-and-mark)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1311 (shell-command-on-region
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1312 (mark t) (point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1313 (if (= com ?!)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1314 (setq viper-last-shell-com
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1315 (viper-read-string-with-history
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1316 "!"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1317 nil
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1318 'viper-shell-history
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1319 (car viper-shell-history)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1320 ))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1321 viper-last-shell-com)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1322 t)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1323
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1324 (defun viper-exec-equals (m-com com)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1325 (save-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1326 (set-mark viper-com-point)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1327 (viper-enlarge-region (mark t) (point))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1328 (if (> (mark t) (point)) (exchange-point-and-mark))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1329 (indent-region (mark t) (point) nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1330
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1331 (defun viper-exec-shift (m-com com)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1332 (save-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1333 (set-mark viper-com-point)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1334 (viper-enlarge-region (mark t) (point))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1335 (if (> (mark t) (point)) (exchange-point-and-mark))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1336 (indent-rigidly (mark t) (point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1337 (if (= com ?>)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1338 viper-shift-width
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1339 (- viper-shift-width))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1340 ;; return point to where it was before shift
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1341 (goto-char viper-com-point))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1342
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1343 ;; 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
1344 ;; denotes repeated insert command.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1345 (defsubst viper-exec-dummy (m-com com)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1346 nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1347
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1348 (defun viper-exec-buffer-search (m-com com)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1349 (setq viper-s-string (buffer-substring (point) viper-com-point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1350 (setq viper-s-forward t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1351 (setq viper-search-history (cons viper-s-string viper-search-history))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1352 (viper-search viper-s-string viper-s-forward 1))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1353
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1354 (defvar viper-exec-array (make-vector 128 nil))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1355
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1356 ;; Using a dispatch array allows adding functions like buffer search
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1357 ;; without affecting other functions. Buffer search can now be bound
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1358 ;; to any character.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1359
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1360 (aset viper-exec-array ?c 'viper-exec-change)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1361 (aset viper-exec-array ?C 'viper-exec-Change)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1362 (aset viper-exec-array ?d 'viper-exec-delete)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1363 (aset viper-exec-array ?D 'viper-exec-Delete)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1364 (aset viper-exec-array ?y 'viper-exec-yank)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1365 (aset viper-exec-array ?Y 'viper-exec-Yank)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1366 (aset viper-exec-array ?r 'viper-exec-dummy)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1367 (aset viper-exec-array ?! 'viper-exec-bang)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1368 (aset viper-exec-array ?< 'viper-exec-shift)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1369 (aset viper-exec-array ?> 'viper-exec-shift)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1370 (aset viper-exec-array ?= 'viper-exec-equals)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1371
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1372
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1373
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1374 ;; This function is called by various movement commands to execute a
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1375 ;; destructive command on the region specified by the movement command. For
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1376 ;; instance, if the user types cw, then the command viper-forward-word will
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1377 ;; call viper-execute-com to execute viper-exec-change, which eventually will
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1378 ;; call viper-change to invoke the replace mode on the region.
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1379 ;;
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1380 ;; The var viper-d-com is set to (M-COM VAL COM REG INSETED-TEXT COMMAND-KEYS)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1381 ;; via a call to viper-set-destructive-command, for later use by viper-repeat.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1382 (defun viper-execute-com (m-com val com)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1383 (let ((reg viper-use-register))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1384 ;; this is the special command `#'
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1385 (if (> com 128)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1386 (viper-special-prefix-com (- com 128))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1387 (let ((fn (aref viper-exec-array (if (< com 0) (- com) com))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1388 (if (null fn)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1389 (error "%c: %s" com viper-InvalidViCommand)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1390 (funcall fn m-com com))))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1391 (if (viper-dotable-command-p com)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1392 (viper-set-destructive-command
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1393 (list m-com val
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1394 (if (memq com (list ?c ?C ?!)) (- com) com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1395 reg nil nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1396 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1397
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1398
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1399 (defun viper-repeat (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1400 "Re-execute last destructive command.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1401 Use the info in viper-d-com, which has the form
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1402 \(com val ch reg inserted-text command-keys\),
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1403 where `com' is the command to be re-executed, `val' is the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1404 argument to `com', `ch' is a flag for repeat, and `reg' is optional;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1405 if it exists, it is the name of the register for `com'.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1406 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
1407 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1408 (let ((save-point (point)) ; save point before repeating prev cmd
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1409 ;; Pass along that we are repeating a destructive command
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1410 ;; This tells viper-set-destructive-command not to update
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1411 ;; viper-command-ring
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1412 (viper-intermediate-command 'viper-repeat))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1413 (if (eq last-command 'viper-undo)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1414 ;; if the last command was viper-undo, then undo-more
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1415 (viper-undo-more)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1416 ;; otherwise execute the command stored in viper-d-com. if arg is
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1417 ;; non-nil its prefix value is used as new prefix value for the command.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1418 (let ((m-com (car viper-d-com))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1419 (val (viper-P-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1420 (com (nth 2 viper-d-com))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1421 (reg (nth 3 viper-d-com)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1422 (if (null val) (setq val (nth 1 viper-d-com)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1423 (if (null m-com) (error "No previous command to repeat."))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1424 (setq viper-use-register reg)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1425 (if (nth 4 viper-d-com) ; text inserted by command
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1426 (setq viper-last-insertion (nth 4 viper-d-com)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1427 viper-d-char (nth 4 viper-d-com)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1428 (funcall m-com (cons val com))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1429 (cond ((and (< save-point (point)) viper-keep-point-on-repeat)
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1430 (goto-char save-point)) ; go back to before repeat.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1431 ((and (< save-point (point)) viper-ex-style-editing)
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
1432 (or (bolp) (backward-char 1))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1433 (if (and (eolp) (not (bolp)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1434 (backward-char 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1435 ))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1436 (viper-adjust-undo) ; take care of undo
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1437 ;; If the prev cmd was rotating the command ring, this means that `.' has
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1438 ;; just executed a command from that ring. So, push it on the ring again.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1439 ;; If we are just executing previous command , then don't push viper-d-com
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1440 ;; because viper-d-com is not fully constructed in this case (its keys and
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1441 ;; the inserted text may be nil). Besides, in this case, the command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1442 ;; executed by `.' is already on the ring.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1443 (if (eq last-command 'viper-display-current-destructive-command)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1444 (viper-push-onto-ring viper-d-com 'viper-command-ring))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1445 (viper-deactivate-mark)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1446 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1447
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1448 (defun viper-repeat-from-history ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1449 "Repeat a destructive command from history.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1450 Doesn't change viper-command-ring in any way, so `.' will work as before
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1451 executing this command.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1452 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
1453 the second character is a digit 0 to 9. The digit indicates which
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1454 history command to execute. `<char>0' is equivalent to `.', `<char>1'
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1455 invokes the command before that, etc."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1456 (interactive)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1457 (let* ((viper-intermediate-command 'repeating-display-destructive-command)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1458 (idx (cond (viper-this-kbd-macro
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1459 (string-to-number
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1460 (symbol-name (elt viper-this-kbd-macro 1))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1461 (t 0)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1462 (num idx)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1463 (viper-d-com viper-d-com))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1464
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1465 (or (and (numberp num) (<= 0 num) (<= num 9))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1466 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1467 (setq idx 0
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1468 num 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1469 (message
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1470 "`viper-repeat-from-history' must be invoked as a Vi macro bound to `<key><digit>'")))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1471 (while (< 0 num)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1472 (setq viper-d-com (viper-special-ring-rotate1 viper-command-ring -1))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1473 (setq num (1- num)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1474 (viper-repeat nil)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1475 (while (> idx num)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1476 (viper-special-ring-rotate1 viper-command-ring 1)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1477 (setq num (1+ num)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1478 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1479
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1480
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1481 ;; The hash-command. It is invoked interactively by the key sequence #<char>.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1482 ;; The chars that can follow `#' are determined by viper-hash-command-p
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1483 (defun viper-special-prefix-com (char)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1484 (cond ((= char ?c)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1485 (downcase-region (min viper-com-point (point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1486 (max viper-com-point (point))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1487 ((= char ?C)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1488 (upcase-region (min viper-com-point (point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1489 (max viper-com-point (point))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1490 ((= char ?g)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1491 (push-mark viper-com-point t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1492 (viper-global-execute))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1493 ((= char ?q)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1494 (push-mark viper-com-point t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1495 (viper-quote-region))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1496 ((= char ?s) (funcall viper-spell-function viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1497 (t (error "#%c: %s" char viper-InvalidViCommand))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1498
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1499
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1500 ;; undoing
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1501
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1502 (defun viper-undo ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1503 "Undo previous change."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1504 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1505 (message "undo!")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1506 (let ((modified (buffer-modified-p))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1507 (before-undo-pt (point-marker))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1508 (after-change-functions after-change-functions)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1509 undo-beg-posn undo-end-posn)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1510
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1511 ;; 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
1512 (add-hook 'after-change-functions
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1513 '(lambda (beg end len)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1514 (setq undo-beg-posn beg
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1515 undo-end-posn (or end beg))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1516
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1517 (undo-start)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1518 (undo-more 2)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1519 (setq undo-beg-posn (or undo-beg-posn before-undo-pt)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1520 undo-end-posn (or undo-end-posn undo-beg-posn))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1521
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1522 (goto-char undo-beg-posn)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1523 (sit-for 0)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1524 (if (and viper-keep-point-on-undo
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1525 (pos-visible-in-window-p before-undo-pt))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1526 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1527 (push-mark (point-marker) t)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1528 (viper-sit-for-short 300)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1529 (goto-char undo-end-posn)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1530 (viper-sit-for-short 300)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1531 (if (and (> (viper-chars-in-region undo-beg-posn before-undo-pt) 1)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1532 (> (viper-chars-in-region undo-end-posn before-undo-pt) 1))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1533 (goto-char before-undo-pt)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1534 (goto-char undo-beg-posn)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1535 (push-mark before-undo-pt t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1536 (if (and (eolp) (not (bolp))) (backward-char 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1537 (if (not modified) (set-buffer-modified-p t)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1538 (setq this-command 'viper-undo))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1539
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1540 ;; Continue undoing previous changes.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1541 (defun viper-undo-more ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1542 (message "undo more!")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1543 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1544 (undo-more 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1545 (error (beep)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1546 (message "No further undo information in this buffer")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1547 (if (and (eolp) (not (bolp))) (backward-char 1))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1548 (setq this-command 'viper-undo))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1549
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1550 ;; The following two functions are used to set up undo properly.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1551 ;; 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
1552 ;; they are undone all at once.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1553 (defun viper-adjust-undo ()
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1554 (if viper-undo-needs-adjustment
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1555 (let ((inhibit-quit t)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1556 tmp tmp2)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1557 (setq viper-undo-needs-adjustment nil)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1558 (if (listp buffer-undo-list)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1559 (if (setq tmp (memq viper-buffer-undo-list-mark buffer-undo-list))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1560 (progn
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1561 (setq tmp2 (cdr tmp)) ; the part after mark
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1562
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1563 ;; cut tail from buffer-undo-list temporarily by direct
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1564 ;; manipulation with pointers in buffer-undo-list
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1565 (setcdr tmp nil)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1566
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1567 (setq buffer-undo-list (delq nil buffer-undo-list))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1568 (setq buffer-undo-list
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1569 (delq viper-buffer-undo-list-mark buffer-undo-list))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1570 ;; restore tail of buffer-undo-list
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1571 (setq buffer-undo-list (nconc buffer-undo-list tmp2)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1572 (setq buffer-undo-list (delq nil buffer-undo-list)))))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1573 ))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1574
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1575
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1576 (defun viper-set-complex-command-for-undo ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1577 (if (listp buffer-undo-list)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1578 (if (not viper-undo-needs-adjustment)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1579 (let ((inhibit-quit t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1580 (setq buffer-undo-list
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1581 (cons viper-buffer-undo-list-mark buffer-undo-list))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1582 (setq viper-undo-needs-adjustment t)))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1583
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1584
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1585
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1586
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1587 (defun viper-display-current-destructive-command ()
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1588 (let ((text (nth 4 viper-d-com))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1589 (keys (nth 5 viper-d-com))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1590 (max-text-len 30))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1591
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1592 (setq this-command 'viper-display-current-destructive-command)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1593
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1594 (message " `.' runs %s%s"
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1595 (concat "`" (viper-array-to-string keys) "'")
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1596 (viper-abbreviate-string
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1597 (if viper-xemacs-p
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1598 (replace-in-string
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1599 (cond ((characterp text) (char-to-string text))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1600 ((stringp text) text)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1601 (t ""))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1602 "\n" "^J")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1603 text)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1604 max-text-len
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1605 " inserting `" "'" " ......."))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1606 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1607
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1608
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1609 ;; don't change viper-d-com if it was viper-repeat command invoked with `.'
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1610 ;; or in some other way (non-interactively).
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1611 (defun viper-set-destructive-command (list)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1612 (or (eq viper-intermediate-command 'viper-repeat)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1613 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1614 (setq viper-d-com list)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1615 (setcar (nthcdr 5 viper-d-com)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1616 (viper-array-to-string (if (arrayp viper-this-command-keys)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1617 viper-this-command-keys
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1618 (this-command-keys))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1619 (viper-push-onto-ring viper-d-com 'viper-command-ring)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1620 (setq viper-this-command-keys nil))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1621
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1622 (defun viper-prev-destructive-command (next)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1623 "Find previous destructive command in the history of destructive commands.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1624 With prefix argument, find next destructive command."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1625 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1626 (let (cmd viper-intermediate-command)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1627 (if (eq last-command 'viper-display-current-destructive-command)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1628 ;; repeated search through command history
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1629 (setq viper-intermediate-command
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1630 'repeating-display-destructive-command)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1631 ;; first search through command history--set temp ring
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1632 (setq viper-temp-command-ring (copy-list viper-command-ring)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1633 (setq cmd (if next
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1634 (viper-special-ring-rotate1 viper-temp-command-ring 1)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1635 (viper-special-ring-rotate1 viper-temp-command-ring -1)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1636 (if (null cmd)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1637 ()
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1638 (setq viper-d-com cmd))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1639 (viper-display-current-destructive-command)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1640
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1641 (defun viper-next-destructive-command ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1642 "Find next destructive command in the history of destructive commands."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1643 (interactive)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1644 (viper-prev-destructive-command 'next))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1645
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1646 (defun viper-insert-prev-from-insertion-ring (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1647 "Cycle through insertion ring in the direction of older insertions.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1648 Undoes previous insertion and inserts new.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1649 With prefix argument, cycles in the direction of newer elements.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1650 In minibuffer, this command executes whatever the invocation key is bound
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1651 to in the global map, instead of cycling through the insertion ring."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1652 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1653 (let (viper-intermediate-command)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1654 (if (eq last-command 'viper-insert-from-insertion-ring)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1655 (progn ; repeated search through insertion history
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1656 (setq viper-intermediate-command 'repeating-insertion-from-ring)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1657 (if (eq viper-current-state 'replace-state)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1658 (undo 1)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1659 (if viper-last-inserted-string-from-insertion-ring
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1660 (backward-delete-char
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1661 (length viper-last-inserted-string-from-insertion-ring))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1662 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1663 ;;first search through insertion history
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1664 (setq viper-temp-insertion-ring (copy-list viper-insertion-ring)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1665 (setq this-command 'viper-insert-from-insertion-ring)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1666 ;; so that things will be undone properly
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1667 (setq buffer-undo-list (cons nil buffer-undo-list))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1668 (setq viper-last-inserted-string-from-insertion-ring
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1669 (viper-special-ring-rotate1 viper-temp-insertion-ring (if arg 1 -1)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1670
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1671 ;; this change of viper-intermediate-command must come after
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1672 ;; viper-special-ring-rotate1, so that the ring will rotate, but before the
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1673 ;; insertion.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1674 (setq viper-intermediate-command nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1675 (if viper-last-inserted-string-from-insertion-ring
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1676 (insert viper-last-inserted-string-from-insertion-ring))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1677 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1678
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1679 (defun viper-insert-next-from-insertion-ring ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1680 "Cycle through insertion ring in the direction of older insertions.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1681 Undo previous insertion and inserts new."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1682 (interactive)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1683 (viper-insert-prev-from-insertion-ring 'next))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1684
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1685
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1686 ;; some region utilities
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1687
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1688 ;; If at the last line of buffer, add \\n before eob, if newline is missing.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1689 (defun viper-add-newline-at-eob-if-necessary ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1690 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1691 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1692 ;; make sure all lines end with newline, unless in the minibuffer or
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1693 ;; when requested otherwise (require-final-newline is nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1694 (if (and (eobp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1695 (not (bolp))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1696 require-final-newline
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1697 (not (viper-is-in-minibuffer))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1698 (not buffer-read-only))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1699 (insert "\n"))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1700
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1701 (defun viper-yank-defun ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1702 (mark-defun)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1703 (copy-region-as-kill (point) (mark t)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1704
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1705 ;; Enlarge region between BEG and END.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1706 (defun viper-enlarge-region (beg end)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1707 (or beg (setq beg end)) ; if beg is nil, set to end
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1708 (or end (setq end beg)) ; if end is nil, set to beg
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1709
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1710 (if (< beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1711 (progn (goto-char beg) (set-mark end))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1712 (goto-char end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1713 (set-mark beg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1714 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1715 (exchange-point-and-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1716 (if (or (not (eobp)) (not (bolp))) (forward-line 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1717 (if (not (eobp)) (beginning-of-line))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1718 (if (> beg end) (exchange-point-and-mark)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1719
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1720
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1721 ;; Quote region by each line with a user supplied string.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1722 (defun viper-quote-region ()
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1723 (setq viper-quote-string
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1724 (viper-read-string-with-history
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1725 "Quote string: "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1726 nil
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1727 'viper-quote-region-history
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1728 viper-quote-string))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1729 (viper-enlarge-region (point) (mark t))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1730 (if (> (point) (mark t)) (exchange-point-and-mark))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1731 (insert viper-quote-string)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1732 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1733 (forward-line 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1734 (while (and (< (point) (mark t)) (bolp))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1735 (insert viper-quote-string)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1736 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1737 (forward-line 1)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1738
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1739 ;; Tells whether BEG is on the same line as END.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1740 ;; If one of the args is nil, it'll return nil.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1741 (defun viper-same-line (beg end)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1742 (let ((selective-display nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1743 (incr 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1744 temp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1745 (if (and beg end (> beg end))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1746 (setq temp beg
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1747 beg end
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1748 end temp))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1749 (if (and beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1750 (cond ((or (> beg (point-max)) (> end (point-max))) ; out of range
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1751 nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1752 (t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1753 ;; This 'if' is needed because Emacs treats the next empty line
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1754 ;; as part of the previous line.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1755 (if (= (viper-line-pos 'start) end)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1756 (setq incr 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1757 (<= (+ incr (count-lines beg end)) 1))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1758 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1759
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1760
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1761 ;; Check if the string ends with a newline.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1762 (defun viper-end-with-a-newline-p (string)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1763 (or (string= string "")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1764 (= (viper-seq-last-elt string) ?\n)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1765
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1766 (defun viper-tmp-insert-at-eob (msg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1767 (let ((savemax (point-max)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1768 (goto-char savemax)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1769 (insert msg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1770 (sit-for 2)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1771 (goto-char savemax) (delete-region (point) (point-max))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1772 ))
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
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1776 ;;; Minibuffer business
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1777
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1778 (defsubst viper-set-minibuffer-style ()
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1779 (add-hook 'minibuffer-setup-hook 'viper-minibuffer-setup-sentinel))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1780
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1781
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1782 (defun viper-minibuffer-setup-sentinel ()
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1783 (let ((hook (if viper-vi-style-in-minibuffer
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1784 'viper-change-state-to-insert
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1785 'viper-change-state-to-emacs)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1786 (funcall hook)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1787 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1788
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1789 ;; Interpret last event in the local map first; if fails, use exit-minibuffer.
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1790 ;; Run viper-minibuffer-exit-hook before exiting.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1791 (defun viper-exit-minibuffer ()
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1792 "Exit minibuffer Viper way."
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1793 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1794 (let (command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1795 (setq command (local-key-binding (char-to-string last-command-char)))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1796 (run-hooks 'viper-minibuffer-exit-hook)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1797 (if command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1798 (command-execute command)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1799 (exit-minibuffer))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1800
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1801
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1802 (defcustom viper-smart-suffix-list
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1803 '("" "tex" "c" "cc" "C" "el" "java" "html" "htm" "pl" "P" "p")
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
1804 "*List of suffixes that Viper tries to append to filenames ending with a `.'.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1805 This is useful when you the current directory contains files with the same
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1806 prefix and many different suffixes. Usually, only one of the suffixes
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1807 represents an editable file. However, file completion will stop at the `.'
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1808 The smart suffix feature lets you hit RET in such a case, and Viper will
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1809 select the appropriate suffix.
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1810
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1811 Suffixes are tried in the order given and the first suffix for which a
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1812 corresponding file exists is selected. If no file exists for any of the
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1813 suffixes, the user is asked to confirm.
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1814
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1815 To turn this feature off, set this variable to nil."
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
1816 :type '(repeat string)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
1817 :group 'viper-misc)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1818
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1819
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1820 ;; Try to add a suitable suffix to files whose name ends with a `.'
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1821 ;; Useful when the user hits RET on a non-completed file name.
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1822 ;; Used as a minibuffer exit hook in read-file-name
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1823 (defun viper-file-add-suffix ()
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1824 (let ((count 0)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1825 (len (length viper-smart-suffix-list))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1826 (file (buffer-string))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1827 found key cmd suff)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1828 (goto-char (point-max))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1829 (if (and viper-smart-suffix-list (string-match "\\.$" file))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1830 (progn
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1831 (while (and (not found) (< count len))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1832 (setq suff (nth count viper-smart-suffix-list)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1833 count (1+ count))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1834 (if (file-exists-p
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1835 (format "%s%s" (substitute-in-file-name file) suff))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1836 (progn
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1837 (setq found t)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1838 (insert suff))))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1839
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1840 (if found
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1841 ()
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1842 (viper-tmp-insert-at-eob " [Please complete file name]")
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1843 (unwind-protect
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1844 (while (not (memq cmd
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1845 '(exit-minibuffer viper-exit-minibuffer)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1846 (setq cmd
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1847 (key-binding (setq key (read-key-sequence nil))))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1848 (cond ((eq cmd 'self-insert-command)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1849 (if viper-xemacs-p
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1850 (insert (events-to-keys key))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1851 (insert key)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1852 ((memq cmd '(exit-minibuffer viper-exit-minibuffer))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1853 nil)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1854 (t (command-execute cmd)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1855 )))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1856 ))))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1857
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1858
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1859 (defun viper-minibuffer-trim-tail ()
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1860 "Delete junk at the end of the first line of the minibuffer input.
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1861 Remove this function from `viper-minibuffer-exit-hook', if this causes
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1862 problems."
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1863 (if (viper-is-in-minibuffer)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1864 (progn
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1865 (goto-char (point-min))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1866 (end-of-line)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1867 (delete-region (point) (point-max)))))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
1868
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1869
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1870 ;;; Reading string with history
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1871
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1872 (defun viper-read-string-with-history (prompt &optional initial
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1873 history-var default keymap)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1874 ;; Read string, prompting with PROMPT and inserting the INITIAL
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1875 ;; value. Uses HISTORY-VAR. DEFAULT is the default value to accept if the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1876 ;; input is an empty string. Use KEYMAP, if given, or the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1877 ;; minibuffer-local-map.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1878 ;; Default value is displayed until the user types something in the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1879 ;; minibuffer.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1880 (let ((minibuffer-setup-hook
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1881 '(lambda ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1882 (if (stringp initial)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1883 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1884 ;; don't wait if we have unread events or in kbd macro
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1885 (or unread-command-events
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1886 executing-kbd-macro
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1887 (sit-for 840))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1888 (erase-buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1889 (insert initial)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1890 (viper-minibuffer-setup-sentinel)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1891 (val "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1892 (padding "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1893 temp-msg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1894
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1895 (setq keymap (or keymap minibuffer-local-map)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1896 initial (or initial "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1897 temp-msg (if default
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1898 (format "(default: %s) " default)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1899 ""))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1900
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1901 (setq viper-incomplete-ex-cmd nil)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1902 (setq val (read-from-minibuffer prompt
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1903 (concat temp-msg initial val padding)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1904 keymap nil history-var))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1905 (setq minibuffer-setup-hook nil
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1906 padding (viper-array-to-string (this-command-keys))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1907 temp-msg "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1908 ;; the following tries to be smart about what to put in history
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1909 (if (not (string= val (car (eval history-var))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1910 (set history-var (cons val (eval history-var))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1911 (if (or (string= (nth 0 (eval history-var)) (nth 1 (eval history-var)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1912 (string= (nth 0 (eval history-var)) ""))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1913 (set history-var (cdr (eval history-var))))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1914 ;; If the user enters nothing but the prev cmd wasn't viper-ex,
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1915 ;; viper-command-argument, or `! shell-command', this probably means
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1916 ;; that the user typed something then erased. Return "" in this case, not
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1917 ;; the default---the default is too confusing in this case.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1918 (cond ((and (string= val "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1919 (not (string= prompt "!")) ; was a `! shell-command'
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1920 (not (memq last-command
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1921 '(viper-ex
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1922 viper-command-argument
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1923 t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1924 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1925 "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1926 ((string= val "") (or default ""))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1927 (t val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1928 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1929
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1930
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1931
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1932 ;; insertion commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1933
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1934 ;; Called when state changes from Insert Vi command mode.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1935 ;; Repeats the insertion command if Insert state was entered with prefix
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1936 ;; argument > 1.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1937 (defun viper-repeat-insert-command ()
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1938 (let ((i-com (car viper-d-com))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1939 (val (nth 1 viper-d-com))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1940 (char (nth 2 viper-d-com)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1941 (if (and val (> val 1)) ; first check that val is non-nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1942 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1943 (setq viper-d-com (list i-com (1- val) ?r nil nil nil))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1944 (viper-repeat nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1945 (setq viper-d-com (list i-com val char nil nil nil))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1946 ))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1947
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1948 (defun viper-insert (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1949 "Insert before point."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1950 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1951 (viper-set-complex-command-for-undo)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1952 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1953 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1954 (viper-set-destructive-command (list 'viper-insert val ?r nil nil nil))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1955 (if com
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1956 (viper-loop val (viper-yank-last-insertion))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1957 (viper-change-state-to-insert))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1958
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1959 (defun viper-append (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1960 "Append after point."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1961 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1962 (viper-set-complex-command-for-undo)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1963 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1964 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1965 (viper-set-destructive-command (list 'viper-append val ?r nil nil nil))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1966 (if (not (eolp)) (forward-char))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1967 (if (equal com ?r)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1968 (viper-loop val (viper-yank-last-insertion))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1969 (viper-change-state-to-insert))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1970
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1971 (defun viper-Append (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1972 "Append at end of line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1973 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1974 (viper-set-complex-command-for-undo)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1975 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1976 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1977 (viper-set-destructive-command (list 'viper-Append val ?r nil nil nil))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1978 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1979 (if (equal com ?r)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1980 (viper-loop val (viper-yank-last-insertion))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1981 (viper-change-state-to-insert))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1982
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1983 (defun viper-Insert (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1984 "Insert before first non-white."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1985 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1986 (viper-set-complex-command-for-undo)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1987 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1988 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1989 (viper-set-destructive-command (list 'viper-Insert val ?r nil nil nil))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1990 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1991 (if (equal com ?r)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1992 (viper-loop val (viper-yank-last-insertion))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1993 (viper-change-state-to-insert))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1994
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1995 (defun viper-open-line (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1996 "Open line below."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1997 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1998 (viper-set-complex-command-for-undo)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
1999 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2000 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2001 (viper-set-destructive-command (list 'viper-open-line val ?r nil nil nil))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2002 (let ((col (current-indentation)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2003 (if (equal com ?r)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2004 (viper-loop val
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2005 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2006 (newline 1)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2007 (if viper-auto-indent
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2008 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2009 (setq viper-cted t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2010 (if viper-electric-mode
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2011 (indent-according-to-mode)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2012 (indent-to col))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2013 ))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2014 (viper-yank-last-insertion))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2015 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2016 (newline 1)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2017 (if viper-auto-indent
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2018 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2019 (setq viper-cted t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2020 (if viper-electric-mode
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2021 (indent-according-to-mode)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2022 (indent-to col))))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2023 (viper-change-state-to-insert)))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2024
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2025 (defun viper-Open-line (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2026 "Open line above."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2027 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2028 (viper-set-complex-command-for-undo)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2029 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2030 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2031 (viper-set-destructive-command (list 'viper-Open-line val ?r nil nil nil))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2032 (let ((col (current-indentation)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2033 (if (equal com ?r)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2034 (viper-loop val
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2035 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2036 (open-line 1)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2037 (if viper-auto-indent
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2038 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2039 (setq viper-cted t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2040 (if viper-electric-mode
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2041 (indent-according-to-mode)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2042 (indent-to col))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2043 ))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2044 (viper-yank-last-insertion))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2045 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2046 (open-line 1)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2047 (if viper-auto-indent
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2048 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2049 (setq viper-cted t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2050 (if viper-electric-mode
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2051 (indent-according-to-mode)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2052 (indent-to col))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2053 ))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2054 (viper-change-state-to-insert)))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2055
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2056 (defun viper-open-line-at-point (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2057 "Open line at point."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2058 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2059 (viper-set-complex-command-for-undo)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2060 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2061 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2062 (viper-set-destructive-command
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2063 (list 'viper-open-line-at-point val ?r nil nil nil))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2064 (if (equal com ?r)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2065 (viper-loop val
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2066 (open-line 1)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2067 (viper-yank-last-insertion))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2068 (open-line 1)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2069 (viper-change-state-to-insert))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2070
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2071 (defun viper-substitute (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2072 "Substitute characters."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2073 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2074 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2075 (com (viper-getcom arg)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2076 (push-mark nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2077 (forward-char val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2078 (if (equal com ?r)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2079 (viper-change-subr (mark t) (point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2080 (viper-change (mark t) (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2081 (viper-set-destructive-command (list 'viper-substitute val ?r nil nil nil))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2082 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2083
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2084 ;; Command bound to S
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2085 (defun viper-substitute-line (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2086 "Substitute lines."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2087 (interactive "p")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2088 (viper-set-complex-command-for-undo)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2089 (viper-line (cons arg ?C)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2090
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2091 ;; Prepare for replace
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2092 (defun viper-start-replace ()
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2093 (setq viper-began-as-replace t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2094 viper-sitting-in-replace t
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2095 viper-replace-chars-to-delete 0)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2096 (viper-add-hook
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2097 'viper-after-change-functions 'viper-replace-mode-spy-after t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2098 (viper-add-hook
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2099 'viper-before-change-functions 'viper-replace-mode-spy-before t)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2100 ;; this will get added repeatedly, but no harm
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2101 (add-hook 'after-change-functions 'viper-after-change-sentinel t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2102 (add-hook 'before-change-functions 'viper-before-change-sentinel t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2103 (viper-move-marker-locally 'viper-last-posn-in-replace-region
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2104 (viper-replace-start))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2105 (viper-add-hook
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2106 'viper-post-command-hooks 'viper-replace-state-post-command-sentinel t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2107 (viper-add-hook
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2108 'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel t)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2109 ;; guard against a smartie who switched from R-replace to normal replace
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2110 (viper-remove-hook
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2111 'viper-post-command-hooks 'viper-R-state-post-command-sentinel)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2112 (if overwrite-mode (overwrite-mode 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
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2115
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2116 (defun viper-replace-mode-spy-before (beg end)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2117 (setq viper-replace-region-chars-deleted (viper-chars-in-region beg end))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2118 )
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2119
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2120 ;; Invoked as an after-change-function to calculate how many chars have to be
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2121 ;; deleted. This function may be called several times within a single command,
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2122 ;; if this command performs several separate buffer changes. Therefore, if adds
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2123 ;; up the number of chars inserted and subtracts the number of chars deleted.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2124 (defun viper-replace-mode-spy-after (beg end length)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2125 (if (memq viper-intermediate-command
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2126 '(dabbrev-expand repeating-insertion-from-ring))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2127 ;; Take special care of text insertion from insertion ring inside
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2128 ;; replacement overlays.
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2129 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2130 (setq viper-replace-chars-to-delete 0)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2131 (viper-move-marker-locally
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2132 'viper-last-posn-in-replace-region (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2133
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2134 (let* ((real-end (min end (viper-replace-end)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2135 (column-shift (- (save-excursion (goto-char real-end)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2136 (current-column))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2137 (save-excursion (goto-char beg)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2138 (current-column))))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2139 (chars-deleted 0))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2140
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2141 (if (> length 0)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2142 (setq chars-deleted viper-replace-region-chars-deleted))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2143 (setq viper-replace-region-chars-deleted 0)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2144 (setq viper-replace-chars-to-delete
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2145 (+ viper-replace-chars-to-delete
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2146 (-
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2147 ;; if column shift is bigger, due to a TAB insertion, take
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2148 ;; column-shift instead of the number of inserted chars
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2149 (max (viper-chars-in-region beg real-end)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2150 ;; This test accounts for Chinese/Japanese/... chars,
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2151 ;; which occupy 2 columns instead of one. If we use
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2152 ;; column-shift here, we may delete two chars instead of
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2153 ;; one when the user types one Chinese character. Deleting
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2154 ;; two would be OK, if they were European chars, but it is
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2155 ;; not OK if they are Chinese chars. Since it is hard to
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2156 ;; figure out which characters are being deleted in any
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2157 ;; given region, we decided to treat Eastern and European
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2158 ;; characters equally, even though Eastern chars may
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2159 ;; occupy more columns.
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2160 (if (memq this-command '(self-insert-command
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2161 quoted-insert viper-insert-tab))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2162 column-shift
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2163 0))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2164 ;; the number of deleted chars
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2165 chars-deleted)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2166
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2167 (viper-move-marker-locally
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2168 'viper-last-posn-in-replace-region
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2169 (max (if (> end (viper-replace-end)) (viper-replace-end) end)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2170 (or (marker-position viper-last-posn-in-replace-region)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2171 (viper-replace-start))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2172 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2173
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2174 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2175
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2176 ;; Make sure we don't delete more than needed.
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2177 ;; This is executed at viper-last-posn-in-replace-region
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2178 (defsubst viper-trim-replace-chars-to-delete-if-necessary ()
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2179 (setq viper-replace-chars-to-delete
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2180 (max 0
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2181 (min viper-replace-chars-to-delete
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2182 ;; Don't delete more than to the end of repl overlay
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2183 (viper-chars-in-region
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2184 (viper-replace-end) viper-last-posn-in-replace-region)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2185 ;; point is viper-last-posn-in-replace-region now
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2186 ;; So, this limits deletion to the end of line
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2187 (viper-chars-in-region (point) (viper-line-pos 'end))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2188 ))))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2189
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2190
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2191 ;; Delete stuff between viper-last-posn-in-replace-region and the end of
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2192 ;; viper-replace-overlay-marker, if viper-last-posn-in-replace-region is within
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2193 ;; the overlay and current point is before the end of the overlay.
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2194 ;; Don't delete anything if current point is past the end of the overlay.
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2195 (defun viper-finish-change ()
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2196 (viper-remove-hook
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2197 'viper-after-change-functions 'viper-replace-mode-spy-after)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2198 (viper-remove-hook
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2199 'viper-before-change-functions 'viper-replace-mode-spy-before)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2200 (viper-remove-hook
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2201 'viper-post-command-hooks 'viper-replace-state-post-command-sentinel)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2202 (viper-remove-hook
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2203 'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2204 (viper-restore-cursor-color-after-replace)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2205 (setq viper-sitting-in-replace nil) ; just in case we'll need to know it
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2206 (save-excursion
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2207 (if (and viper-replace-overlay
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2208 (viper-pos-within-region viper-last-posn-in-replace-region
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2209 (viper-replace-start)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2210 (viper-replace-end))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2211 (< (point) (viper-replace-end)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2212 (delete-region
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2213 viper-last-posn-in-replace-region (viper-replace-end))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2214
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2215 (if (eq viper-current-state 'replace-state)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2216 (viper-downgrade-to-insert))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2217 ;; replace mode ended => nullify viper-last-posn-in-replace-region
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2218 (viper-move-marker-locally 'viper-last-posn-in-replace-region nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2219 (viper-hide-replace-overlay)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2220 (viper-refresh-mode-line)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2221 (viper-put-string-on-kill-ring viper-last-replace-region)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2222 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2223
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2224 ;; Make STRING be the first element of the kill ring.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2225 (defun viper-put-string-on-kill-ring (string)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2226 (setq kill-ring (cons string kill-ring))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2227 (if (> (length kill-ring) kill-ring-max)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2228 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2229 (setq kill-ring-yank-pointer kill-ring))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2230
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2231 (defun viper-finish-R-mode ()
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2232 (viper-remove-hook
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2233 'viper-post-command-hooks 'viper-R-state-post-command-sentinel)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2234 (viper-remove-hook
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2235 'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2236 (viper-downgrade-to-insert))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2237
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2238 (defun viper-start-R-mode ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2239 ;; 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
2240 (overwrite-mode 1)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2241 (viper-add-hook
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2242 'viper-post-command-hooks 'viper-R-state-post-command-sentinel t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2243 (viper-add-hook
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2244 'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel t)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2245 ;; guard against a smartie who switched from R-replace to normal replace
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2246 (viper-remove-hook
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2247 'viper-post-command-hooks 'viper-replace-state-post-command-sentinel)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2248 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2249
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2250
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2251
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2252 (defun viper-replace-state-exit-cmd ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2253 "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
2254 These keys are ESC, RET, and LineFeed"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2255 (interactive)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2256 (if overwrite-mode ; if in replace mode invoked via 'R'
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2257 (viper-finish-R-mode)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2258 (viper-finish-change))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2259 (let (com)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2260 (if (eq this-command 'viper-intercept-ESC-key)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2261 (setq com 'viper-exit-insert-state)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2262 (viper-set-unread-command-events last-input-char)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2263 (setq com (key-binding (read-key-sequence nil))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2264
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2265 (condition-case conds
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2266 (command-execute com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2267 (error
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2268 (viper-message-conditions conds)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2269 )
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2270 (viper-hide-replace-overlay))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2271
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2272
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2273 (defun viper-replace-state-carriage-return ()
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2274 "Carriage return in Viper replace state."
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2275 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2276 ;; If Emacs start supporting overlay maps, as it currently supports
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2277 ;; text-property maps, we could do away with viper-replace-minor-mode and
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2278 ;; just have keymap attached to replace overlay. Then the "if part" of this
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2279 ;; statement can be deleted.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2280 (if (or (< (point) (viper-replace-start))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2281 (> (point) (viper-replace-end)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2282 (let (viper-replace-minor-mode com)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2283 (viper-set-unread-command-events last-input-char)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2284 (setq com (key-binding (read-key-sequence nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2285 (condition-case conds
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2286 (command-execute com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2287 (error
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2288 (viper-message-conditions conds))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2289 (if (not viper-allow-multiline-replace-regions)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2290 (viper-replace-state-exit-cmd)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2291 (if (viper-same-line (point) (viper-replace-end))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2292 (viper-replace-state-exit-cmd)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2293 ;; delete the rest of line
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2294 (delete-region (point) (viper-line-pos 'end))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2295 (save-excursion
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2296 (end-of-line)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2297 (if (eobp) (error "Last line in buffer")))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2298 ;; skip to the next line
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2299 (forward-line 1)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2300 (back-to-indentation)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2301 ))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2302
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2303
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2304 ;; This is the function bound to 'R'---unlimited replace.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2305 ;; Similar to Emacs's own overwrite-mode.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2306 (defun viper-overwrite (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2307 "Begin overwrite mode."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2308 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2309 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2310 (com (viper-getcom arg)) (len))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2311 (viper-set-destructive-command (list 'viper-overwrite val ?r nil nil nil))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2312 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2313 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2314 ;; Viper saves inserted text in viper-last-insertion
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2315 (setq len (length viper-last-insertion))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2316 (delete-char len)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2317 (viper-loop val (viper-yank-last-insertion)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2318 (setq last-command 'viper-overwrite)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2319 (viper-set-complex-command-for-undo)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2320 (viper-set-replace-overlay (point) (viper-line-pos 'end))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2321 (viper-change-state-to-replace)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2322 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2323
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2324
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2325 ;; line commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2326
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2327 (defun viper-line (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2328 (let ((val (car arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2329 (com (cdr arg)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2330 (viper-move-marker-locally 'viper-com-point (point))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2331 (if (not (eobp))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2332 (viper-next-line-carefully (1- val)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2333 ;; 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
2334 ;; line of buffer when this line has no \n.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2335 (viper-add-newline-at-eob-if-necessary)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2336 (viper-execute-com 'viper-line val com))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2337 (if (and (eobp) (not (bobp))) (forward-line -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2338 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2339
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2340 (defun viper-yank-line (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2341 "Yank ARG lines (in Vi's sense)."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2342 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2343 (let ((val (viper-p-val arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2344 (viper-line (cons val ?Y))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2345
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2346
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2347 ;; region commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2348
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2349 (defun viper-region (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2350 "Execute command on a region."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2351 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2352 (let ((val (viper-P-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2353 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2354 (viper-move-marker-locally 'viper-com-point (point))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2355 (exchange-point-and-mark)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2356 (viper-execute-com 'viper-region val com)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2357
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2358 (defun viper-Region (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2359 "Execute command on a Region."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2360 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2361 (let ((val (viper-P-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2362 (com (viper-getCom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2363 (viper-move-marker-locally 'viper-com-point (point))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2364 (exchange-point-and-mark)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2365 (viper-execute-com 'viper-Region val com)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2366
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2367 (defun viper-replace-char (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2368 "Replace the following ARG chars by the character read."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2369 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2370 (if (and (eolp) (bolp)) (error "No character to replace here"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2371 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2372 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2373 (viper-replace-char-subr com val)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2374 (if (and (eolp) (not (bolp))) (forward-char 1))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2375 (setq viper-this-command-keys
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2376 (format "%sr" (if (integerp arg) arg "")))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2377 (viper-set-destructive-command
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2378 (list 'viper-replace-char val ?r nil viper-d-char nil))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2379 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2380
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2381 (defun viper-replace-char-subr (com arg)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2382 (let (char)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2383 (setq char (if (equal com ?r)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2384 viper-d-char
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2385 (read-char)))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2386 (let (inhibit-quit) ; preserve consistency of undo-list and iso-accents
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2387 (if (and viper-automatic-iso-accents (memq char '(?' ?\" ?^ ?~)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2388 ;; get European characters
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2389 (progn
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2390 (viper-set-iso-accents-mode t)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2391 (viper-set-unread-command-events char)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2392 (setq char (aref (read-key-sequence nil) 0))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2393 (viper-set-iso-accents-mode nil)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2394 (viper-set-complex-command-for-undo)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2395 (if (eq char ?\C-m) (setq char ?\n))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2396 (if (and viper-special-input-method (fboundp 'quail-start-translation))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2397 ;; get Intl. characters
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2398 (progn
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2399 (viper-set-input-method t)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2400 (setq last-command-event
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2401 (viper-copy-event
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2402 (if viper-xemacs-p (character-to-event char) char)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2403 (delete-char 1 t)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2404 (condition-case nil
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2405 (if com
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2406 (insert char)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2407 (if viper-emacs-p
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2408 (quail-start-translation 1)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2409 (quail-start-translation)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2410 (error))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2411 ;; quail translation failed
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2412 (if (and (not (stringp quail-current-str))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2413 (not (viper-characterp quail-current-str)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2414 (progn
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2415 (viper-adjust-undo)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2416 (undo-start)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2417 (undo-more 1)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2418 (viper-set-input-method nil)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2419 (error "Composing character failed, changes undone")))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2420 ;; quail translation seems ok
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2421 (or com
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2422 ;;(setq char quail-current-str))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2423 (setq char (viper-char-at-pos 'backward)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2424 (setq viper-d-char char)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2425 (viper-loop (1- (if (> arg 0) arg (- arg)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2426 (delete-char 1 t)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2427 (insert char))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2428 (viper-set-input-method nil))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2429 (delete-char arg t)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2430 (setq viper-d-char char)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2431 (viper-loop (if (> arg 0) arg (- arg))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2432 (insert char)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2433 (viper-adjust-undo)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2434 (backward-char arg))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2435
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2436
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2437 ;; basic cursor movement. j, k, l, h commands.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2438
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2439 (defun viper-forward-char (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2440 "Move point right ARG characters (left if ARG negative).
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2441 On reaching end of line, stop and signal error."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2442 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2443 (viper-leave-region-active)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2444 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2445 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2446 (if com (viper-move-marker-locally 'viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2447 (if viper-ex-style-motion
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2448 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2449 ;; the boundary condition check gets weird here because
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2450 ;; forward-char may be the parameter of a delete, and 'dl' works
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2451 ;; just like 'x' for the last char on a line, so we have to allow
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2452 ;; the forward motion before the 'viper-execute-com', but, of
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2453 ;; course, 'dl' doesn't work on an empty line, so we have to
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2454 ;; catch that condition before 'viper-execute-com'
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2455 (if (and (eolp) (bolp)) (error "") (forward-char val))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2456 (if com (viper-execute-com 'viper-forward-char val com))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2457 (if (eolp) (progn (backward-char 1) (error ""))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2458 (forward-char val)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2459 (if com (viper-execute-com 'viper-forward-char val com)))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2460
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2461 (defun viper-backward-char (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2462 "Move point left ARG characters (right if ARG negative).
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2463 On reaching beginning of line, stop and signal error."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2464 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2465 (viper-leave-region-active)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2466 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2467 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2468 (if com (viper-move-marker-locally 'viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2469 (if viper-ex-style-motion
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2470 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2471 (if (bolp) (error "") (backward-char val))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2472 (if com (viper-execute-com 'viper-backward-char val com)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2473 (backward-char val)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2474 (if com (viper-execute-com 'viper-backward-char val com)))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2475
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2476 ;; Like forward-char, but doesn't move at end of buffer.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2477 ;; Returns distance traveled
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2478 ;; (positive or 0, if arg positive; negative if arg negative).
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2479 (defun viper-forward-char-carefully (&optional arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2480 (setq arg (or arg 1))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2481 (let ((pt (point)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2482 (condition-case nil
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2483 (forward-char arg)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2484 (error))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2485 (if (< (point) pt) ; arg was negative
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2486 (- (viper-chars-in-region pt (point)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2487 (viper-chars-in-region pt (point)))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2488
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2489 ;; Like backward-char, but doesn't move at beg of buffer.
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2490 ;; Returns distance traveled
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2491 ;; (negative or 0, if arg positive; positive if arg negative).
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2492 (defun viper-backward-char-carefully (&optional arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2493 (setq arg (or arg 1))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2494 (let ((pt (point)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2495 (condition-case nil
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2496 (backward-char arg)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2497 (error))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2498 (if (> (point) pt) ; arg was negative
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2499 (viper-chars-in-region pt (point))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2500 (- (viper-chars-in-region pt (point))))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2501
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2502 (defun viper-next-line-carefully (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2503 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2504 (next-line arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2505 (error nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2506
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2507
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2508
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2509 ;;; Word command
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2510
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2511 ;; Words are formed from alpha's and nonalphas - <sp>,\t\n are separators for
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2512 ;; word movement. When executed with a destructive command, \n is usually left
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2513 ;; untouched for the last word. Viper uses syntax table to determine what is a
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2514 ;; word and what is a separator. However, \n is always a separator. Also, if
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2515 ;; viper-syntax-preference is 'vi, then `_' is part of the word.
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2516
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2517 ;; skip only one \n
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2518 (defun viper-skip-separators (forward)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2519 (if forward
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2520 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2521 (viper-skip-all-separators-forward 'within-line)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2522 (if (looking-at "\n")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2523 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2524 (forward-char)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2525 (viper-skip-all-separators-forward 'within-line))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2526 (viper-skip-all-separators-backward 'within-line)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2527 (viper-backward-char-carefully)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2528 (if (looking-at "\n")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2529 (viper-skip-all-separators-backward 'within-line)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2530 (forward-char))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2531
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2532 (defun viper-forward-word-kernel (val)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2533 (while (> val 0)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2534 (cond ((viper-looking-at-alpha)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2535 (viper-skip-alpha-forward "_")
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2536 (viper-skip-separators t))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2537 ((viper-looking-at-separator)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2538 (viper-skip-separators t))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2539 ((not (viper-looking-at-alphasep))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2540 (viper-skip-nonalphasep-forward)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2541 (viper-skip-separators t)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2542 (setq val (1- val))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2543
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2544 ;; first skip non-newline separators backward, then skip \n. Then, if TWICE is
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2545 ;; non-nil, skip non-\n back again, but don't overshoot the limit LIM.
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2546 (defun viper-separator-skipback-special (twice lim)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2547 (let ((prev-char (viper-char-at-pos 'backward))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2548 (saved-point (point)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2549 ;; skip non-newline separators backward
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2550 (while (and (not (memq prev-char '(nil \n)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2551 (< lim (point))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2552 ;; must be non-newline separator
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2553 (if (eq viper-syntax-preference 'strict-vi)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2554 (memq prev-char '(?\ ?\t))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2555 (memq (char-syntax prev-char) '(?\ ?-))))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2556 (viper-backward-char-carefully)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2557 (setq prev-char (viper-char-at-pos 'backward)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2558
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2559 (if (and (< lim (point)) (eq prev-char ?\n))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2560 (backward-char)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2561 ;; If we skipped to the next word and the prefix of this line doesn't
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2562 ;; consist of separators preceded by a newline, then don't skip backwards
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2563 ;; at all.
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2564 (goto-char saved-point))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2565 (setq prev-char (viper-char-at-pos 'backward))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2566
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2567 ;; skip again, but make sure we don't overshoot the limit
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2568 (if twice
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2569 (while (and (not (memq prev-char '(nil \n)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2570 (< lim (point))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2571 ;; must be non-newline separator
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2572 (if (eq viper-syntax-preference 'strict-vi)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2573 (memq prev-char '(?\ ?\t))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2574 (memq (char-syntax prev-char) '(?\ ?-))))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2575 (viper-backward-char-carefully)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2576 (setq prev-char (viper-char-at-pos 'backward))))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2577
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2578 (if (= (point) lim)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2579 (viper-forward-char-carefully))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2580 ))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2581
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2582
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2583 (defun viper-forward-word (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2584 "Forward word."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2585 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2586 (viper-leave-region-active)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2587 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2588 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2589 (if com (viper-move-marker-locally 'viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2590 (viper-forward-word-kernel val)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2591 (if com (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2592 (cond ((memq com (list ?c (- ?c)))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2593 (viper-separator-skipback-special 'twice viper-com-point))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2594 ;; Yank words including the whitespace, but not newline
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2595 ((memq com (list ?y (- ?y)))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2596 (viper-separator-skipback-special nil viper-com-point))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2597 ((viper-dotable-command-p com)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2598 (viper-separator-skipback-special nil viper-com-point)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2599 (viper-execute-com 'viper-forward-word val com)))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2600
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2601
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2602 (defun viper-forward-Word (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2603 "Forward word delimited by white characters."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2604 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2605 (viper-leave-region-active)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2606 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2607 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2608 (if com (viper-move-marker-locally 'viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2609 (viper-loop val
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2610 (viper-skip-nonseparators 'forward)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2611 (viper-skip-separators t))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2612 (if com (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2613 (cond ((memq com (list ?c (- ?c)))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2614 (viper-separator-skipback-special 'twice viper-com-point))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2615 ;; Yank words including the whitespace, but not newline
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2616 ((memq com (list ?y (- ?y)))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2617 (viper-separator-skipback-special nil viper-com-point))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2618 ((viper-dotable-command-p com)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2619 (viper-separator-skipback-special nil viper-com-point)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2620 (viper-execute-com 'viper-forward-Word val com)))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2621
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2622
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2623 ;; this is a bit different from Vi, but Vi's end of word
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2624 ;; makes no sense whatsoever
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2625 (defun viper-end-of-word-kernel ()
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2626 (if (viper-end-of-word-p) (forward-char))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2627 (if (viper-looking-at-separator)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2628 (viper-skip-all-separators-forward))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2629
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2630 (cond ((viper-looking-at-alpha) (viper-skip-alpha-forward "_"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2631 ((not (viper-looking-at-alphasep)) (viper-skip-nonalphasep-forward)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2632 (viper-backward-char-carefully))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2633
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2634 (defun viper-end-of-word-p ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2635 (or (eobp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2636 (save-excursion
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2637 (cond ((viper-looking-at-alpha)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2638 (forward-char)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2639 (not (viper-looking-at-alpha)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2640 ((not (viper-looking-at-alphasep))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2641 (forward-char)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2642 (viper-looking-at-alphasep))))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2643
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2644
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2645 (defun viper-end-of-word (arg &optional careful)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2646 "Move point to end of current word."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2647 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2648 (viper-leave-region-active)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2649 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2650 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2651 (if com (viper-move-marker-locally 'viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2652 (viper-loop val (viper-end-of-word-kernel))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2653 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2654 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2655 (forward-char)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2656 (viper-execute-com 'viper-end-of-word val com)))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2657
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2658 (defun viper-end-of-Word (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2659 "Forward to end of word delimited by white character."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2660 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2661 (viper-leave-region-active)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2662 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2663 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2664 (if com (viper-move-marker-locally 'viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2665 (viper-loop val
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2666 (viper-end-of-word-kernel)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2667 (viper-skip-nonseparators 'forward)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2668 (backward-char))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2669 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2670 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2671 (forward-char)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2672 (viper-execute-com 'viper-end-of-Word val com)))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2673
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2674 (defun viper-backward-word-kernel (val)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2675 (while (> val 0)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2676 (viper-backward-char-carefully)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2677 (cond ((viper-looking-at-alpha)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2678 (viper-skip-alpha-backward "_"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2679 ((viper-looking-at-separator)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2680 (forward-char)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2681 (viper-skip-separators nil)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2682 (viper-backward-char-carefully)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2683 (cond ((viper-looking-at-alpha)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2684 (viper-skip-alpha-backward "_"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2685 ((not (viper-looking-at-alphasep))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2686 (viper-skip-nonalphasep-backward))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2687 ((bobp)) ; could still be at separator, but at beg of buffer
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2688 (t (forward-char))))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2689 ((not (viper-looking-at-alphasep))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2690 (viper-skip-nonalphasep-backward)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2691 (setq val (1- val))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2692
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2693 (defun viper-backward-word (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2694 "Backward word."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2695 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2696 (viper-leave-region-active)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2697 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2698 (com (viper-getcom arg)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2699 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2700 (let (i)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2701 (if (setq i (save-excursion (backward-char) (looking-at "\n")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2702 (backward-char))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2703 (viper-move-marker-locally 'viper-com-point (point))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2704 (if i (forward-char))))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2705 (viper-backward-word-kernel val)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2706 (if com (viper-execute-com 'viper-backward-word val com))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2707
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2708 (defun viper-backward-Word (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2709 "Backward word delimited by white character."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2710 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2711 (viper-leave-region-active)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2712 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2713 (com (viper-getcom arg)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2714 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2715 (let (i)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2716 (if (setq i (save-excursion (backward-char) (looking-at "\n")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2717 (backward-char))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2718 (viper-move-marker-locally 'viper-com-point (point))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2719 (if i (forward-char))))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2720 (viper-loop val
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2721 (viper-skip-separators nil) ; nil means backward here
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2722 (viper-skip-nonseparators 'backward))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2723 (if com (viper-execute-com 'viper-backward-Word val com))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2724
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2725
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2726
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2727 ;; line commands
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2728
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2729 (defun viper-beginning-of-line (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2730 "Go to beginning of line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2731 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2732 (viper-leave-region-active)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2733 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2734 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2735 (if com (viper-move-marker-locally 'viper-com-point (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2736 (beginning-of-line val)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2737 (if com (viper-execute-com 'viper-beginning-of-line val com))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2738
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2739 (defun viper-bol-and-skip-white (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2740 "Beginning of line at first non-white character."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2741 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2742 (viper-leave-region-active)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2743 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2744 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2745 (if com (viper-move-marker-locally 'viper-com-point (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2746 (forward-to-indentation (1- val))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2747 (if com (viper-execute-com 'viper-bol-and-skip-white val com))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2748
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2749 (defun viper-goto-eol (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2750 "Go to end of line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2751 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2752 (viper-leave-region-active)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2753 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2754 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2755 (if com (viper-move-marker-locally 'viper-com-point (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2756 (end-of-line val)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2757 (if com (viper-execute-com 'viper-goto-eol val com))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2758 (if viper-ex-style-motion
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2759 (if (and (eolp) (not (bolp))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2760 ;; a fix for viper-change-to-eol
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2761 (not (equal viper-current-state 'insert-state)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2762 (backward-char 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2763 ))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2764
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2765
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2766 (defun viper-goto-col (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2767 "Go to ARG's column."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2768 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2769 (viper-leave-region-active)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2770 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2771 (com (viper-getcom arg))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2772 line-len)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2773 (setq line-len
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2774 (viper-chars-in-region
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2775 (viper-line-pos 'start) (viper-line-pos 'end)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2776 (if com (viper-move-marker-locally 'viper-com-point (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2777 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2778 (forward-char (1- (min line-len val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2779 (while (> (current-column) (1- val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2780 (backward-char 1))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2781 (if com (viper-execute-com 'viper-goto-col val com))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2782 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2783 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2784 (if (> val (current-column)) (error "")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2785 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2786
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2787
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2788 (defun viper-next-line (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2789 "Go to next line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2790 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2791 (viper-leave-region-active)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2792 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2793 (com (viper-getCom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2794 (if com (viper-move-marker-locally 'viper-com-point (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2795 (next-line val)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2796 (if viper-ex-style-motion
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2797 (if (and (eolp) (not (bolp))) (backward-char 1)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2798 (setq this-command 'next-line)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2799 (if com (viper-execute-com 'viper-next-line val com))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2800
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2801 (defun viper-next-line-at-bol (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2802 "Next line at beginning of line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2803 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2804 (viper-leave-region-active)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2805 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2806 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2807 (if (eobp) (error "Last line in buffer")))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2808 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2809 (com (viper-getCom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2810 (if com (viper-move-marker-locally 'viper-com-point (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2811 (forward-line val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2812 (back-to-indentation)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2813 (if com (viper-execute-com 'viper-next-line-at-bol val com))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2814
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2815 (defun viper-previous-line (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2816 "Go to previous line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2817 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2818 (viper-leave-region-active)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2819 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2820 (com (viper-getCom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2821 (if com (viper-move-marker-locally 'viper-com-point (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2822 (previous-line val)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2823 (if viper-ex-style-motion
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2824 (if (and (eolp) (not (bolp))) (backward-char 1)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2825 (setq this-command 'previous-line)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2826 (if com (viper-execute-com 'viper-previous-line val com))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2827
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2828
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2829 (defun viper-previous-line-at-bol (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2830 "Previous line at beginning of line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2831 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2832 (viper-leave-region-active)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2833 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2834 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2835 (if (bobp) (error "First line in buffer")))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2836 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2837 (com (viper-getCom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2838 (if com (viper-move-marker-locally 'viper-com-point (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2839 (forward-line (- val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2840 (back-to-indentation)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2841 (if com (viper-execute-com 'viper-previous-line val com))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2842
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2843 (defun viper-change-to-eol (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2844 "Change to end of line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2845 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2846 (viper-goto-eol (cons arg ?c)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2847
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2848 (defun viper-kill-line (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2849 "Delete line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2850 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2851 (viper-goto-eol (cons arg ?d)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2852
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2853 (defun viper-erase-line (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2854 "Erase line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2855 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2856 (viper-beginning-of-line (cons arg ?d)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2857
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2858
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2859 ;;; Moving around
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2860
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2861 (defun viper-goto-line (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2862 "Go to ARG's line. Without ARG go to end of buffer."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2863 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2864 (let ((val (viper-P-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2865 (com (viper-getCom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2866 (viper-move-marker-locally 'viper-com-point (point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2867 (viper-deactivate-mark)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2868 (push-mark nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2869 (if (null val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2870 (goto-char (point-max))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2871 (goto-char (point-min))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2872 (forward-line (1- val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2873
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2874 ;; positioning is done twice: before and after command execution
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2875 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2876 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2877
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2878 (if com (viper-execute-com 'viper-goto-line val com))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2879
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2880 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2881 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2882 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2883
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2884 ;; Find ARG's occurrence of CHAR on the current line.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2885 ;; If FORWARD then search is forward, otherwise backward. OFFSET is used to
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2886 ;; adjust point after search.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2887 (defun viper-find-char (arg char forward offset)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2888 (or (char-or-string-p char) (error ""))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2889 (let ((arg (if forward arg (- arg)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2890 (cmd (if (eq viper-intermediate-command 'viper-repeat)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2891 (nth 5 viper-d-com)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2892 (viper-array-to-string (this-command-keys))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2893 point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2894 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2895 (save-restriction
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2896 (if (> arg 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2897 (narrow-to-region
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2898 ;; forward search begins here
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2899 (if (eolp) (error "Command `%s': At end of line" cmd) (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2900 ;; forward search ends here
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2901 (progn (end-of-line) (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2902 (narrow-to-region
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2903 ;; backward search begins from here
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2904 (if (bolp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2905 (error "Command `%s': At beginning of line" cmd) (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2906 ;; backward search ends here
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2907 (progn (beginning-of-line) (point))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2908 ;; if arg > 0, point is forwarded before search.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2909 (if (> arg 0) (goto-char (1+ (point-min)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2910 (goto-char (point-max)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2911 (if (let ((case-fold-search nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2912 (search-forward (char-to-string char) nil 0 arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2913 (setq point (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2914 (error "Command `%s': `%c' not found" cmd char))))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2915 (goto-char point)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2916 (if (> arg 0)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2917 (backward-char (if offset 2 1))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
2918 (forward-char (if offset 1 0)))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2919
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2920 (defun viper-find-char-forward (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2921 "Find char on the line.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2922 If called interactively read the char to find from the terminal, and if
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2923 called from viper-repeat, the char last used is used. This behaviour is
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2924 controlled by the sign of prefix numeric value."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2925 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2926 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2927 (com (viper-getcom arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2928 (cmd-representation (nth 5 viper-d-com)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2929 (if (> val 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2930 ;; this means that the function was called interactively
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2931 (setq viper-f-char (read-char)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2932 viper-f-forward t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2933 viper-f-offset nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2934 ;; viper-repeat --- set viper-F-char from command-keys
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2935 (setq viper-F-char (if (stringp cmd-representation)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2936 (viper-seq-last-elt cmd-representation)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2937 viper-F-char)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2938 viper-f-char viper-F-char)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2939 (setq val (- val)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2940 (if com (viper-move-marker-locally 'viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2941 (viper-find-char
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2942 val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) t nil)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2943 (setq val (- val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2944 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2945 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2946 (setq viper-F-char viper-f-char) ; set new viper-F-char
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2947 (forward-char)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2948 (viper-execute-com 'viper-find-char-forward val com)))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2949
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2950 (defun viper-goto-char-forward (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2951 "Go up to char ARG forward on line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2952 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2953 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2954 (com (viper-getcom arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2955 (cmd-representation (nth 5 viper-d-com)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2956 (if (> val 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2957 ;; this means that the function was called interactively
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2958 (setq viper-f-char (read-char)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2959 viper-f-forward t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2960 viper-f-offset t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2961 ;; viper-repeat --- set viper-F-char from command-keys
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2962 (setq viper-F-char (if (stringp cmd-representation)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2963 (viper-seq-last-elt cmd-representation)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2964 viper-F-char)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2965 viper-f-char viper-F-char)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2966 (setq val (- val)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2967 (if com (viper-move-marker-locally 'viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2968 (viper-find-char
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2969 val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) t t)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2970 (setq val (- val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2971 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2972 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2973 (setq viper-F-char viper-f-char) ; set new viper-F-char
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2974 (forward-char)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2975 (viper-execute-com 'viper-goto-char-forward val com)))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2976
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2977 (defun viper-find-char-backward (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2978 "Find char ARG on line backward."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2979 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2980 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2981 (com (viper-getcom arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2982 (cmd-representation (nth 5 viper-d-com)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2983 (if (> val 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2984 ;; this means that the function was called interactively
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2985 (setq viper-f-char (read-char)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2986 viper-f-forward nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2987 viper-f-offset nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2988 ;; viper-repeat --- set viper-F-char from command-keys
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2989 (setq viper-F-char (if (stringp cmd-representation)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2990 (viper-seq-last-elt cmd-representation)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2991 viper-F-char)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2992 viper-f-char viper-F-char)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2993 (setq val (- val)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2994 (if com (viper-move-marker-locally 'viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2995 (viper-find-char
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
2996 val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) nil nil)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2997 (setq val (- val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2998 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2999 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3000 (setq viper-F-char viper-f-char) ; set new viper-F-char
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3001 (viper-execute-com 'viper-find-char-backward val com)))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3002
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3003 (defun viper-goto-char-backward (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3004 "Go up to char ARG backward on line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3005 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3006 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3007 (com (viper-getcom arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3008 (cmd-representation (nth 5 viper-d-com)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3009 (if (> val 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3010 ;; this means that the function was called interactively
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3011 (setq viper-f-char (read-char)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3012 viper-f-forward nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3013 viper-f-offset t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3014 ;; viper-repeat --- set viper-F-char from command-keys
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3015 (setq viper-F-char (if (stringp cmd-representation)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3016 (viper-seq-last-elt cmd-representation)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3017 viper-F-char)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3018 viper-f-char viper-F-char)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3019 (setq val (- val)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3020 (if com (viper-move-marker-locally 'viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3021 (viper-find-char
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3022 val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) nil t)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3023 (setq val (- val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3024 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3025 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3026 (setq viper-F-char viper-f-char) ; set new viper-F-char
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3027 (viper-execute-com 'viper-goto-char-backward val com)))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3028
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3029 (defun viper-repeat-find (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3030 "Repeat previous find command."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3031 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3032 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3033 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3034 (viper-deactivate-mark)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3035 (if com (viper-move-marker-locally 'viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3036 (viper-find-char val viper-f-char viper-f-forward viper-f-offset)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3037 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3038 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3039 (if viper-f-forward (forward-char))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3040 (viper-execute-com 'viper-repeat-find val com)))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3041
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3042 (defun viper-repeat-find-opposite (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3043 "Repeat previous find command in the opposite direction."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3044 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3045 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3046 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3047 (viper-deactivate-mark)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3048 (if com (viper-move-marker-locally 'viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3049 (viper-find-char val viper-f-char (not viper-f-forward) viper-f-offset)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3050 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3051 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3052 (if viper-f-forward (forward-char))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3053 (viper-execute-com 'viper-repeat-find-opposite val com)))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3054
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3055
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3056 ;; window scrolling etc.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3057
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3058 (defun viper-window-top (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3059 "Go to home window line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3060 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3061 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3062 (com (viper-getCom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3063 (if com (viper-move-marker-locally 'viper-com-point (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3064 (push-mark nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3065 (move-to-window-line (1- val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3066
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3067 ;; positioning is done twice: before and after command execution
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3068 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3069 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3070
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3071 (if com (viper-execute-com 'viper-window-top val com))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3072
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3073 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3074 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3075 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3076
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3077 (defun viper-window-middle (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3078 "Go to middle window line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3079 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3080 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3081 (com (viper-getCom arg))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3082 lines)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3083 (if com (viper-move-marker-locally 'viper-com-point (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3084 (push-mark nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3085 (if (not (pos-visible-in-window-p (point-max)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3086 (move-to-window-line (+ (/ (1- (window-height)) 2) (1- val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3087 (setq lines (count-lines (window-start) (point-max)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3088 (move-to-window-line (+ (/ lines 2) (1- val))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3089
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3090 ;; positioning is done twice: before and after command execution
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3091 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3092 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3093
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3094 (if com (viper-execute-com 'viper-window-middle val com))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3095
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3096 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3097 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3098 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3099
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3100 (defun viper-window-bottom (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3101 "Go to last window line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3102 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3103 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3104 (com (viper-getCom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3105 (if com (viper-move-marker-locally 'viper-com-point (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3106 (push-mark nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3107 (move-to-window-line (- val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3108
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3109 ;; positioning is done twice: before and after command execution
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3110 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3111 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3112
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3113 (if com (viper-execute-com 'viper-window-bottom val com))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3114
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3115 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3116 (back-to-indentation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3117 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3118
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3119 (defun viper-line-to-top (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3120 "Put current line on the home line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3121 (interactive "p")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3122 (recenter (1- arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3123
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3124 (defun viper-line-to-middle (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3125 "Put current line on the middle line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3126 (interactive "p")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3127 (recenter (+ (1- arg) (/ (1- (window-height)) 2))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3128
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3129 (defun viper-line-to-bottom (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3130 "Put current line on the last 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 (recenter (- (window-height) (1+ arg))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3133
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3134 ;; If point is within viper-search-scroll-threshold of window top or bottom,
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3135 ;; scroll up or down 1/7 of window height, depending on whether we are at the
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3136 ;; bottom or at the top of the window. This function is called by viper-search
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3137 ;; (which is called from viper-search-forward/backward/next). If the value of
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3138 ;; viper-search-scroll-threshold is negative - don't scroll.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3139 (defun viper-adjust-window ()
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3140 (let ((win-height (if viper-emacs-p
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3141 (1- (window-height)) ; adjust for modeline
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3142 (window-displayed-height)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3143 (pt (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3144 at-top-p at-bottom-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3145 min-scroll direction)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3146 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3147 (move-to-window-line 0) ; top
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3148 (setq at-top-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3149 (<= (count-lines pt (point))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3150 viper-search-scroll-threshold))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3151 (move-to-window-line -1) ; bottom
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3152 (setq at-bottom-p
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3153 (<= (count-lines pt (point)) viper-search-scroll-threshold))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3154 )
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3155 (cond (at-top-p (setq min-scroll (1- viper-search-scroll-threshold)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3156 direction 1))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3157 (at-bottom-p (setq min-scroll (1+ viper-search-scroll-threshold)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3158 direction -1)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3159 (if min-scroll
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3160 (recenter
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3161 (* (max min-scroll (/ win-height 7)) direction)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3162 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3164
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3165 ;; paren match
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3166 ;; must correct this to only match ( to ) etc. On the other hand
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3167 ;; it is good that paren match gets confused, because that way you
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3168 ;; catch _all_ imbalances.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3169
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3170 (defun viper-paren-match (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3171 "Go to the matching parenthesis."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3172 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3173 (viper-leave-region-active)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3174 (let ((com (viper-getcom arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3175 (parse-sexp-ignore-comments viper-parse-sexp-ignore-comments)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3176 anchor-point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3177 (if (integerp arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3178 (if (or (> arg 99) (< arg 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3179 (error "Prefix must be between 1 and 99")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3180 (goto-char
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3181 (if (> (point-max) 80000)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3182 (* (/ (point-max) 100) arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3183 (/ (* (point-max) arg) 100)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3184 (back-to-indentation))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3185 (let (beg-lim end-lim)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3186 (if (and (eolp) (not (bolp))) (forward-char -1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3187 (if (not (looking-at "[][(){}]"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3188 (setq anchor-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3189 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3190 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3191 (setq beg-lim (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3192 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3193 (setq end-lim (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3194 (cond ((re-search-forward "[][(){}]" end-lim t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3195 (backward-char) )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3196 ((re-search-backward "[][(){}]" beg-lim t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3197 (t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3198 (error "No matching character on line"))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3199 (cond ((looking-at "[\(\[{]")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3200 (if com (viper-move-marker-locally 'viper-com-point (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3201 (forward-sexp 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3202 (if com
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3203 (viper-execute-com 'viper-paren-match nil com)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3204 (backward-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3205 (anchor-point
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3206 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3207 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3208 (viper-move-marker-locally 'viper-com-point anchor-point)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3209 (forward-char 1)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3210 (viper-execute-com 'viper-paren-match nil com)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3211 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3212 ((looking-at "[])}]")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3213 (forward-char)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3214 (if com (viper-move-marker-locally 'viper-com-point (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3215 (backward-sexp 1)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3216 (if com (viper-execute-com 'viper-paren-match nil com)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3217 (t (error ""))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3218
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3219 (defun viper-toggle-parse-sexp-ignore-comments ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3220 (interactive)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3221 (setq viper-parse-sexp-ignore-comments
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3222 (not viper-parse-sexp-ignore-comments))
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3223 (princ (format
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3224 "From now on, `%%' will %signore parentheses inside comment fields"
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3225 (if viper-parse-sexp-ignore-comments "" "NOT "))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3226
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3227
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3228 ;; sentence ,paragraph and heading
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3229
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3230 (defun viper-forward-sentence (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3231 "Forward sentence."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3232 (interactive "P")
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
3233 (or (eq last-command this-command)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
3234 (push-mark nil t))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3235 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3236 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3237 (if com (viper-move-marker-locally 'viper-com-point (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3238 (forward-sentence val)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3239 (if com (viper-execute-com 'viper-forward-sentence nil com))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3240
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3241 (defun viper-backward-sentence (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3242 "Backward sentence."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3243 (interactive "P")
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
3244 (or (eq last-command this-command)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
3245 (push-mark nil t))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3246 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3247 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3248 (if com (viper-move-marker-locally 'viper-com-point (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3249 (backward-sentence val)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3250 (if com (viper-execute-com 'viper-backward-sentence nil com))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3251
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3252 (defun viper-forward-paragraph (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3253 "Forward paragraph."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3254 (interactive "P")
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
3255 (or (eq last-command this-command)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
3256 (push-mark nil t))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3257 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3258 (com (viper-getCom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3259 (if com (viper-move-marker-locally 'viper-com-point (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3260 (forward-paragraph val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3261 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3262 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3263 (backward-char 1)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3264 (viper-execute-com 'viper-forward-paragraph nil com)))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3265
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3266 (defun viper-backward-paragraph (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3267 "Backward paragraph."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3268 (interactive "P")
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
3269 (or (eq last-command this-command)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
3270 (push-mark nil t))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3271 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3272 (com (viper-getCom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3273 (if com (viper-move-marker-locally 'viper-com-point (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3274 (backward-paragraph val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3275 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3276 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3277 (forward-char 1)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3278 (viper-execute-com 'viper-backward-paragraph nil com)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3279 (backward-char 1)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3280
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
3281 ;; should be mode-specific
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3282 (defun viper-prev-heading (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3283 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3284 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3285 (com (viper-getCom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3286 (if com (viper-move-marker-locally 'viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3287 (re-search-backward viper-heading-start nil t val)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3288 (goto-char (match-beginning 0))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3289 (if com (viper-execute-com 'viper-prev-heading nil com))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3290
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3291 (defun viper-heading-end (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3292 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3293 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3294 (com (viper-getCom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3295 (if com (viper-move-marker-locally 'viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3296 (re-search-forward viper-heading-end nil t val)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3297 (goto-char (match-beginning 0))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3298 (if com (viper-execute-com 'viper-heading-end nil com))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3299
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3300 (defun viper-next-heading (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3301 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3302 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3303 (com (viper-getCom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3304 (if com (viper-move-marker-locally 'viper-com-point (point)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3305 (end-of-line)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3306 (re-search-forward viper-heading-start nil t val)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3307 (goto-char (match-beginning 0))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3308 (if com (viper-execute-com 'viper-next-heading nil com))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3309
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3310
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3311 ;; scrolling
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3312
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3313 (defun viper-scroll-screen (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3314 "Scroll to next screen."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3315 (interactive "p")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3316 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3317 (if (> arg 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3318 (while (> arg 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3319 (scroll-up)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3320 (setq arg (1- arg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3321 (while (> 0 arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3322 (scroll-down)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3323 (setq arg (1+ arg))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3324 (error (beep 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3325 (if (> arg 0)
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 (message "End of buffer")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3328 (goto-char (point-max)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3329 (message "Beginning of buffer")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3330 (goto-char (point-min))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3331 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3332
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3333 (defun viper-scroll-screen-back (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3334 "Scroll to previous screen."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3335 (interactive "p")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3336 (viper-scroll-screen (- arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3337
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3338 (defun viper-scroll-down (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3339 "Pull down half screen."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3340 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3341 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3342 (if (null arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3343 (scroll-down (/ (window-height) 2))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3344 (scroll-down arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3345 (error (beep 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3346 (message "Beginning of buffer")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3347 (goto-char (point-min)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3348
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3349 (defun viper-scroll-down-one (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3350 "Scroll up one line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3351 (interactive "p")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3352 (scroll-down arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3353
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3354 (defun viper-scroll-up (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3355 "Pull up half screen."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3356 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3357 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3358 (if (null arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3359 (scroll-up (/ (window-height) 2))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3360 (scroll-up arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3361 (error (beep 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3362 (message "End of buffer")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3363 (goto-char (point-max)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3364
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3365 (defun viper-scroll-up-one (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3366 "Scroll down one line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3367 (interactive "p")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3368 (scroll-up arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3369
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3370
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3371 ;; searching
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3372
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3373 (defun viper-if-string (prompt)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3374 (if (memq viper-intermediate-command
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3375 '(viper-command-argument viper-digit-argument viper-repeat))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3376 (setq viper-this-command-keys (this-command-keys)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3377 (let ((s (viper-read-string-with-history
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3378 prompt
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3379 nil ; no initial
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3380 'viper-search-history
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3381 (car viper-search-history))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3382 (if (not (string= s ""))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3383 (setq viper-s-string s))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3384
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3385
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3386 (defun viper-toggle-search-style (arg)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3387 "Toggle the value of viper-case-fold-search/viper-re-search.
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3388 Without prefix argument, will ask which search style to toggle. With prefix
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3389 arg 1,toggles viper-case-fold-search; with arg 2 toggles viper-re-search.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3390
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3391 Although this function is bound to \\[viper-toggle-search-style], the most
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3392 convenient way to use it is to bind `//' to the macro
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3393 `1 M-x viper-toggle-search-style' and `///' to
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3394 `2 M-x viper-toggle-search-style'. In this way, hitting `//' quickly will
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3395 toggle case-fold-search and hitting `/' three times witth toggle regexp
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3396 search. Macros are more convenient in this case because they don't affect
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3397 the Emacs binding of `/'."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3398 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3399 (let (msg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3400 (cond ((or (eq arg 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3401 (and (null arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3402 (y-or-n-p (format "Search style: '%s'. Want '%s'? "
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3403 (if viper-case-fold-search
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3404 "case-insensitive" "case-sensitive")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3405 (if viper-case-fold-search
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3406 "case-sensitive"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3407 "case-insensitive")))))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3408 (setq viper-case-fold-search (null viper-case-fold-search))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3409 (if viper-case-fold-search
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3410 (setq msg "Search becomes case-insensitive")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3411 (setq msg "Search becomes case-sensitive")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3412 ((or (eq arg 2)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3413 (and (null arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3414 (y-or-n-p (format "Search style: '%s'. Want '%s'? "
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3415 (if viper-re-search
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3416 "regexp-search" "vanilla-search")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3417 (if viper-re-search
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3418 "vanilla-search"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3419 "regexp-search")))))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3420 (setq viper-re-search (null viper-re-search))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3421 (if viper-re-search
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3422 (setq msg "Search becomes regexp-style")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3423 (setq msg "Search becomes vanilla-style")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3424 (t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3425 (setq msg "Search style remains unchanged")))
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3426 (princ msg t)))
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3427
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3428 (defun viper-set-searchstyle-toggling-macros (unset)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3429 "Set the macros for toggling the search style in Viper's vi-state.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3430 The macro that toggles case sensitivity is bound to `//', and the one that
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3431 toggles regexp search is bound to `///'.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3432 With a prefix argument, this function unsets the macros. "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3433 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3434 (or noninteractive
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3435 (if (not unset)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3436 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3437 ;; toggle case sensitivity in search
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3438 (viper-record-kbd-macro
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3439 "//" 'vi-state
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3440 [1 (meta x) v i p e r - t o g g l e - s e a r c h - s t y l e return]
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3441 't)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3442 ;; toggle regexp/vanila search
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3443 (viper-record-kbd-macro
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3444 "///" 'vi-state
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3445 [2 (meta x) v i p e r - t o g g l e - s e a r c h - s t y l e return]
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3446 't)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3447 (if (interactive-p)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3448 (message
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3449 "// and /// now toggle case-sensitivity and regexp search")))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3450 (viper-unrecord-kbd-macro "//" 'vi-state)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3451 (sit-for 2)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3452 (viper-unrecord-kbd-macro "///" 'vi-state))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3453
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3454
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3455 (defun viper-set-parsing-style-toggling-macro (unset)
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3456 "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
3457 This is used in conjunction with the `%' command.
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3458
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3459 With a prefix argument, unsets the macro."
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3460 (interactive "P")
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3461 (or noninteractive
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3462 (if (not unset)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3463 (progn
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3464 ;; Make %%% toggle parsing comments for matching parentheses
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3465 (viper-record-kbd-macro
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3466 "%%%" 'vi-state
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3467 [(meta x) v i p e r - 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]
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3468 't)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3469 (if (interactive-p)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3470 (message
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3471 "%%%%%% now toggles whether comments should be parsed for matching parentheses")))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3472 (viper-unrecord-kbd-macro "%%%" 'vi-state))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3473
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3474
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3475 (defun viper-set-emacs-state-searchstyle-macros (unset &optional arg-majormode)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3476 "Set the macros for toggling the search style in Viper's emacs-state.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3477 The macro that toggles case sensitivity is bound to `//', and the one that
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3478 toggles regexp search is bound to `///'.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3479 With a prefix argument, this function unsets the macros.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3480 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
3481 this sets the macros only in the macros in that major mode. Otherwise,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3482 the macros are set in the current major mode.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3483 \(When unsetting the macros, the second argument has no effect.\)"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3484 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3485 (or noninteractive
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3486 (if (not unset)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3487 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3488 ;; toggle case sensitivity in search
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3489 (viper-record-kbd-macro
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3490 "//" 'emacs-state
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3491 [1 (meta x) v i p e r - t o g g l e - s e a r c h - s t y l e return]
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3492 (or arg-majormode major-mode))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3493 ;; toggle regexp/vanila search
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3494 (viper-record-kbd-macro
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3495 "///" 'emacs-state
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3496 [2 (meta x) v i p e r - t o g g l e - s e a r c h - s t y l e return]
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3497 (or arg-majormode major-mode))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3498 (if (interactive-p)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3499 (message
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3500 "// and /// now toggle case-sensitivity and regexp search.")))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3501 (viper-unrecord-kbd-macro "//" 'emacs-state)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3502 (sit-for 2)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3503 (viper-unrecord-kbd-macro "///" 'emacs-state))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3504
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3505
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3506 (defun viper-search-forward (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3507 "Search a string forward.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3508 ARG is used to find the ARG's occurrence of the string.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3509 Null string will repeat previous search."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3510 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3511 (let ((val (viper-P-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3512 (com (viper-getcom arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3513 (old-str viper-s-string))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3514 (setq viper-s-forward t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3515 (viper-if-string "/")
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3516 ;; this is not used at present, but may be used later
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3517 (if (or (not (equal old-str viper-s-string))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3518 (not (markerp viper-local-search-start-marker))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3519 (not (marker-buffer viper-local-search-start-marker)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3520 (setq viper-local-search-start-marker (point-marker)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3521 (viper-search viper-s-string t val)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3522 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3523 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3524 (viper-move-marker-locally 'viper-com-point (mark t))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3525 (viper-execute-com 'viper-search-next val com)))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3526
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3527 (defun viper-search-backward (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3528 "Search a string backward.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3529 ARG is used to find the ARG's occurrence of the string.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3530 Null string will repeat previous search."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3531 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3532 (let ((val (viper-P-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3533 (com (viper-getcom arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3534 (old-str viper-s-string))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3535 (setq viper-s-forward nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3536 (viper-if-string "?")
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3537 ;; this is not used at present, but may be used later
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3538 (if (or (not (equal old-str viper-s-string))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3539 (not (markerp viper-local-search-start-marker))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3540 (not (marker-buffer viper-local-search-start-marker)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3541 (setq viper-local-search-start-marker (point-marker)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3542 (viper-search viper-s-string nil val)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3543 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3544 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3545 (viper-move-marker-locally 'viper-com-point (mark t))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3546 (viper-execute-com 'viper-search-next val com)))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3547
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3548
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3549 ;; Search for COUNT's occurrence of STRING.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3550 ;; Search is forward if FORWARD is non-nil, otherwise backward.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3551 ;; INIT-POINT is the position where search is to start.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3552 ;; Arguments:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3553 ;; (STRING FORW COUNT &optional NO-OFFSET INIT-POINT LIMIT FAIL-IF-NOT-FOUND)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3554 (defun viper-search (string forward arg
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3555 &optional no-offset init-point fail-if-not-found)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3556 (if (not (equal string ""))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3557 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3558 (com (viper-getcom arg))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3559 (offset (not no-offset))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3560 (case-fold-search viper-case-fold-search)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3561 (start-point (or init-point (point))))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3562 (viper-deactivate-mark)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3563 (if forward
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3564 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3565 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3566 (if offset (viper-forward-char-carefully))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3567 (if viper-re-search
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3568 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3569 (re-search-forward string nil nil val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3570 (re-search-backward string))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3571 (search-forward string nil nil val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3572 (search-backward string))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3573 (if (not (equal start-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3574 (push-mark start-point t)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3575 (search-failed
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3576 (if (and (not fail-if-not-found) viper-search-wrap-around-t)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3577 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3578 (message "Search wrapped around BOTTOM of buffer")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3579 (goto-char (point-min))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3580 (viper-search string forward (cons 1 com) t start-point 'fail)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3581 ;; don't wait in macros
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3582 (or executing-kbd-macro
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3583 (memq viper-intermediate-command
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3584 '(viper-repeat
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3585 viper-digit-argument
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3586 viper-command-argument))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3587 (sit-for 2))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3588 ;; delete the wrap-around message
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3589 (message "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3590 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3591 (goto-char start-point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3592 (error "`%s': %s not found"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3593 string
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3594 (if viper-re-search "Pattern" "String"))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3595 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3596 ;; backward
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3597 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3598 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3599 (if viper-re-search
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3600 (re-search-backward string nil nil val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3601 (search-backward string nil nil val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3602 (if (not (equal start-point (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3603 (push-mark start-point t)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3604 (search-failed
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3605 (if (and (not fail-if-not-found) viper-search-wrap-around-t)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3606 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3607 (message "Search wrapped around TOP of buffer")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3608 (goto-char (point-max))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3609 (viper-search string forward (cons 1 com) t start-point 'fail)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3610 ;; don't wait in macros
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3611 (or executing-kbd-macro
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3612 (memq viper-intermediate-command
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3613 '(viper-repeat
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3614 viper-digit-argument
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3615 viper-command-argument))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3616 (sit-for 2))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3617 ;; delete the wrap-around message
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3618 (message "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3619 )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3620 (goto-char start-point)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3621 (error "`%s': %s not found"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3622 string
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3623 (if viper-re-search "Pattern" "String"))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3624 ))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3625 ;; pull up or down if at top/bottom of window
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3626 (viper-adjust-window)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3627 ;; highlight the result of search
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3628 ;; don't wait and don't highlight in macros
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3629 (or executing-kbd-macro
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3630 (memq viper-intermediate-command
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3631 '(viper-repeat viper-digit-argument viper-command-argument))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3632 (viper-flash-search-pattern))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3633 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3634
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3635 (defun viper-search-next (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3636 "Repeat previous search."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3637 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3638 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3639 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3640 (if (null viper-s-string) (error viper-NoPrevSearch))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3641 (viper-search viper-s-string viper-s-forward arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3642 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3643 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3644 (viper-move-marker-locally 'viper-com-point (mark t))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3645 (viper-execute-com 'viper-search-next val com)))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3646
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3647 (defun viper-search-Next (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3648 "Repeat previous search in the reverse direction."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3649 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3650 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3651 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3652 (if (null viper-s-string) (error viper-NoPrevSearch))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3653 (viper-search viper-s-string (not viper-s-forward) arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3654 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3655 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3656 (viper-move-marker-locally 'viper-com-point (mark t))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3657 (viper-execute-com 'viper-search-Next val com)))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3658
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3659
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3660 ;; Search contents of buffer defined by one of Viper's motion commands.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3661 ;; Repeatable via `n' and `N'.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3662 (defun viper-buffer-search-enable (&optional c)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3663 (cond (c (setq viper-buffer-search-char c))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3664 ((null viper-buffer-search-char)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3665 (setq viper-buffer-search-char ?g)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3666 (define-key viper-vi-basic-map
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3667 (char-to-string viper-buffer-search-char) 'viper-command-argument)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3668 (aset viper-exec-array viper-buffer-search-char 'viper-exec-buffer-search)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3669 (setq viper-prefix-commands
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3670 (cons viper-buffer-search-char viper-prefix-commands)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3671
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3672 ;; This is a Viper wraper for isearch-forward.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3673 (defun viper-isearch-forward (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3674 "Do incremental search forward."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3675 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3676 ;; emacs bug workaround
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3677 (if (listp arg) (setq arg (car arg)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3678 (viper-exec-form-in-emacs (list 'isearch-forward arg)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3679
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3680 ;; This is a Viper wraper for isearch-backward."
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3681 (defun viper-isearch-backward (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3682 "Do incremental search backward."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3683 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3684 ;; emacs bug workaround
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3685 (if (listp arg) (setq arg (car arg)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3686 (viper-exec-form-in-emacs (list 'isearch-backward arg)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3687
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3688
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3689 ;; visiting and killing files, buffers
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3690
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3691 (defun viper-switch-to-buffer ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3692 "Switch to buffer in the current window."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3693 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3694 (let (buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3695 (setq buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3696 (read-buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3697 (format "Switch to buffer in this window \(%s\): "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3698 (buffer-name (other-buffer (current-buffer))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3699 (switch-to-buffer buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3700 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3701
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3702 (defun viper-switch-to-buffer-other-window ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3703 "Switch to buffer in another window."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3704 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3705 (let (buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3706 (setq buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3707 (read-buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3708 (format "Switch to buffer in another window \(%s\): "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3709 (buffer-name (other-buffer (current-buffer))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3710 (switch-to-buffer-other-window buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3711 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3712
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3713 (defun viper-kill-buffer ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3714 "Kill a buffer."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3715 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3716 (let (buffer buffer-name)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3717 (setq buffer-name
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3718 (read-buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3719 (format "Kill buffer \(%s\): "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3720 (buffer-name (current-buffer)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3721 (setq buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3722 (if (null buffer-name)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3723 (current-buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3724 (get-buffer buffer-name)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3725 (if (null buffer) (error "`%s': No such buffer" buffer-name))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3726 (if (or (not (buffer-modified-p buffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3727 (y-or-n-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3728 (format
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3729 "Buffer `%s' is modified, are you sure you want to kill it? "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3730 buffer-name)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3731 (kill-buffer buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3732 (error "Buffer not killed"))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3733
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3734
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3735
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3736 ;; yank and pop
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3737
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3738 (defsubst viper-yank (text)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3739 "Yank TEXT silently. This works correctly with Emacs's yank-pop command."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3740 (insert text)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3741 (setq this-command 'yank))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3742
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3743 (defun viper-put-back (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3744 "Put back after point/below line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3745 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3746 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3747 (text (if viper-use-register
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3748 (cond ((viper-valid-register viper-use-register '(digit))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3749 (current-kill
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3750 (- viper-use-register ?1) 'do-not-rotate))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3751 ((viper-valid-register viper-use-register)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3752 (get-register (downcase viper-use-register)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3753 (t (error viper-InvalidRegister viper-use-register)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3754 (current-kill 0))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3755 (if (null text)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3756 (if viper-use-register
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3757 (let ((reg viper-use-register))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3758 (setq viper-use-register nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3759 (error viper-EmptyRegister reg))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3760 (error "")))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3761 (setq viper-use-register nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3762 (if (viper-end-with-a-newline-p text)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3763 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3764 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3765 (if (eobp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3766 (insert "\n")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3767 (forward-line 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3768 (beginning-of-line))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3769 (if (not (eolp)) (viper-forward-char-carefully)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3770 (set-marker (viper-mark-marker) (point) (current-buffer))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3771 (viper-set-destructive-command
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3772 (list 'viper-put-back val nil viper-use-register nil nil))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3773 (viper-loop val (viper-yank text)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3774 ;; 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
3775 ;; newline; it leaves the cursor at the beginning when the text contains
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3776 ;; a newline
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3777 (if (viper-same-line (point) (mark))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3778 (or (= (point) (mark)) (viper-backward-char-carefully))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3779 (exchange-point-and-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3780 (if (bolp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3781 (back-to-indentation)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3782 (viper-deactivate-mark))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3783
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3784 (defun viper-Put-back (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3785 "Put back at point/above line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3786 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3787 (let ((val (viper-p-val arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3788 (text (if viper-use-register
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3789 (cond ((viper-valid-register viper-use-register '(digit))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3790 (current-kill
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3791 (- viper-use-register ?1) 'do-not-rotate))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3792 ((viper-valid-register viper-use-register)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3793 (get-register (downcase viper-use-register)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3794 (t (error viper-InvalidRegister viper-use-register)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3795 (current-kill 0))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3796 (if (null text)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3797 (if viper-use-register
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3798 (let ((reg viper-use-register))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3799 (setq viper-use-register nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3800 (error viper-EmptyRegister reg))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3801 (error "")))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3802 (setq viper-use-register nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3803 (if (viper-end-with-a-newline-p text) (beginning-of-line))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3804 (viper-set-destructive-command
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3805 (list 'viper-Put-back val nil viper-use-register nil nil))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3806 (set-marker (viper-mark-marker) (point) (current-buffer))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3807 (viper-loop val (viper-yank text)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3808 ;; 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
3809 ;; newline; it leaves the cursor at the beginning when the text contains
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3810 ;; a newline
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3811 (if (viper-same-line (point) (mark))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3812 (or (= (point) (mark)) (viper-backward-char-carefully))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3813 (exchange-point-and-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3814 (if (bolp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3815 (back-to-indentation)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3816 (viper-deactivate-mark))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3817
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3818
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3819 ;; Copy region to kill-ring.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3820 ;; If BEG and END do not belong to the same buffer, copy empty region.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3821 (defun viper-copy-region-as-kill (beg end)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3822 (condition-case nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3823 (copy-region-as-kill beg end)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3824 (error (copy-region-as-kill beg beg))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3825
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3826
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3827 (defun viper-delete-char (arg)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3828 "Delete next character."
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3829 (interactive "P")
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3830 (let ((val (viper-p-val arg))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3831 end-del-pos)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3832 (viper-set-destructive-command
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3833 (list 'viper-delete-char val nil nil nil nil))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3834 (if (and viper-ex-style-editing
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3835 (> val (viper-chars-in-region (point) (viper-line-pos 'end))))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3836 (setq val (viper-chars-in-region (point) (viper-line-pos 'end))))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3837 (if (and viper-ex-style-motion (eolp))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3838 (if (bolp) (error "") (setq val 0))) ; not bol---simply back 1 ch
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3839 (save-excursion
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3840 (viper-forward-char-carefully val)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3841 (setq end-del-pos (point)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3842 (if viper-use-register
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3843 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3844 (cond ((viper-valid-register viper-use-register '((Letter)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3845 (viper-append-to-register
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3846 (downcase viper-use-register) (point) end-del-pos))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3847 ((viper-valid-register viper-use-register)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3848 (copy-to-register
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3849 viper-use-register (point) end-del-pos nil))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3850 (t (error viper-InvalidRegister viper-use-register)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3851 (setq viper-use-register nil)))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3852
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3853 (delete-char val t)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3854 (if viper-ex-style-motion
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3855 (if (and (eolp) (not (bolp))) (backward-char 1)))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3856 ))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3857
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3858 (defun viper-delete-backward-char (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3859 "Delete previous character. On reaching beginning of line, stop and beep."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3860 (interactive "P")
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3861 (let ((val (viper-p-val arg))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3862 end-del-pos)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3863 (viper-set-destructive-command
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3864 (list 'viper-delete-backward-char val nil nil nil nil))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3865 (if (and
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3866 viper-ex-style-editing
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3867 (> val (viper-chars-in-region (viper-line-pos 'start) (point))))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3868 (setq val (viper-chars-in-region (viper-line-pos 'start) (point))))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3869 (save-excursion
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3870 (viper-backward-char-carefully val)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3871 (setq end-del-pos (point)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3872 (if viper-use-register
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3873 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3874 (cond ((viper-valid-register viper-use-register '(Letter))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3875 (viper-append-to-register
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3876 (downcase viper-use-register) end-del-pos (point)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3877 ((viper-valid-register viper-use-register)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3878 (copy-to-register
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3879 viper-use-register end-del-pos (point) nil))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3880 (t (error viper-InvalidRegister viper-use-register)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3881 (setq viper-use-register nil)))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3882 (if (and (bolp) viper-ex-style-editing)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3883 (ding))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3884 (delete-backward-char val t)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3885
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3886 (defun viper-del-backward-char-in-insert ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3887 "Delete 1 char backwards while in insert mode."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3888 (interactive)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3889 (if (and viper-ex-style-editing (bolp))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3890 (beep 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3891 (delete-backward-char 1 t)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3892
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3893 (defun viper-del-backward-char-in-replace ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3894 "Delete one character in replace mode.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3895 If `viper-delete-backwards-in-replace' is t, then DEL key actually deletes
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3896 charecters. If it is nil, then the cursor just moves backwards, similarly
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3897 to Vi. The variable `viper-ex-style-editing', if t, doesn't let the
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3898 cursor move past the beginning of line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3899 (interactive)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3900 (cond (viper-delete-backwards-in-replace
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3901 (cond ((not (bolp))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3902 (delete-backward-char 1 t))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3903 (viper-ex-style-editing
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3904 (beep 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3905 ((bobp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3906 (beep 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3907 (t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3908 (delete-backward-char 1 t))))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3909 (viper-ex-style-editing
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3910 (if (bolp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3911 (beep 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3912 (backward-char 1)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3913 (t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3914 (backward-char 1))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3915
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3916
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3917
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3918 ;; join lines.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3919
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3920 (defun viper-join-lines (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3921 "Join this line to next, if ARG is nil. Otherwise, join ARG lines."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3922 (interactive "*P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3923 (let ((val (viper-P-val arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3924 (viper-set-destructive-command
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3925 (list 'viper-join-lines val nil nil nil nil))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3926 (viper-loop (if (null val) 1 (1- val))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3927 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3928 (if (not (eobp))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3929 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3930 (forward-line 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3931 (delete-region (point) (1- (point)))
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3932 (fixup-whitespace)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3933 ;; fixup-whitespace sometimes does not leave space
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3934 ;; between objects, so we insert it as in Vi
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3935 (or (looking-at " ")
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3936 (insert " ")
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
3937 (backward-char 1))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
3938 )))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3939
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3940
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3941 ;; Replace state
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3942
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3943 (defun viper-change (beg end)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3944 (if (markerp beg) (setq beg (marker-position beg)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3945 (if (markerp end) (setq end (marker-position end)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3946 ;; beg is sometimes (mark t), which may be nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3947 (or beg (setq beg end))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3948
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3949 (viper-set-complex-command-for-undo)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3950 (if viper-use-register
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3951 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3952 (copy-to-register viper-use-register beg end nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3953 (setq viper-use-register nil)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3954 (viper-set-replace-overlay beg end)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3955 (setq last-command nil) ; separate repl text from prev kills
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3956
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3957 (if (= (viper-replace-start) (point-max))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3958 (error "End of buffer"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3959
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3960 (setq viper-last-replace-region
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3961 (buffer-substring (viper-replace-start)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3962 (viper-replace-end)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3963
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3964 ;; protect against error while inserting "@" and other disasters
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3965 ;; (e.g., read-only buff)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3966 (condition-case conds
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3967 (if (or viper-allow-multiline-replace-regions
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3968 (viper-same-line (viper-replace-start)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3969 (viper-replace-end)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3970 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3971 ;; tabs cause problems in replace, so untabify
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3972 (goto-char (viper-replace-end))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3973 (insert-before-markers "@") ; put placeholder after the TAB
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3974 (untabify (viper-replace-start) (point))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3975 ;; del @, don't put on kill ring
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3976 (delete-backward-char 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3977
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3978 (viper-set-replace-overlay-glyphs
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3979 viper-replace-region-start-delimiter
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3980 viper-replace-region-end-delimiter)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3981 ;; this move takes care of the last posn in the overlay, which
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3982 ;; has to be shifted because of insert. We can't simply insert
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3983 ;; "$" before-markers because then overlay-start will shift the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3984 ;; beginning of the overlay in case we are replacing a single
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3985 ;; character. This fixes the bug with `s' and `cl' commands.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3986 (viper-move-replace-overlay (viper-replace-start) (point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3987 (goto-char (viper-replace-start))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3988 (viper-change-state-to-replace t))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3989 (kill-region (viper-replace-start)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3990 (viper-replace-end))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3991 (viper-hide-replace-overlay)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3992 (viper-change-state-to-insert))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3993 (error ;; make sure that the overlay doesn't stay.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3994 ;; go back to the original point
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3995 (goto-char (viper-replace-start))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3996 (viper-hide-replace-overlay)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3997 (viper-message-conditions conds))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3998
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
3999
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4000 (defun viper-change-subr (beg end)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4001 ;; beg is sometimes (mark t), which may be nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4002 (or beg (setq beg end))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4003 (if viper-use-register
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4004 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4005 (copy-to-register viper-use-register beg end nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4006 (setq viper-use-register nil)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4007 (kill-region beg end)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4008 (setq this-command 'viper-change)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4009 (viper-yank-last-insertion))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4010
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4011 (defun viper-toggle-case (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4012 "Toggle character case."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4013 (interactive "P")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4014 (let ((val (viper-p-val arg)) (c))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4015 (viper-set-destructive-command
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4016 (list 'viper-toggle-case val nil nil nil nil))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4017 (while (> val 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4018 (setq c (following-char))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4019 (delete-char 1 nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4020 (if (eq c (upcase c))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4021 (insert-char (downcase c) 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4022 (insert-char (upcase c) 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4023 (if (eolp) (backward-char 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4024 (setq val (1- val)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4025
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4026
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4027 ;; query replace
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4028
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4029 (defun viper-query-replace ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4030 "Query replace.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4031 If a null string is suplied as the string to be replaced,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4032 the query replace mode will toggle between string replace
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4033 and regexp replace."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4034 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4035 (let (str)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4036 (setq str (viper-read-string-with-history
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4037 (if viper-re-query-replace "Query replace regexp: "
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4038 "Query replace: ")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4039 nil ; no initial
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4040 'viper-replace1-history
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4041 (car viper-replace1-history) ; default
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4042 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4043 (if (string= str "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4044 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4045 (setq viper-re-query-replace (not viper-re-query-replace))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4046 (message "Query replace mode changed to %s"
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4047 (if viper-re-query-replace "regexp replace"
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4048 "string replace")))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4049 (if viper-re-query-replace
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4050 (query-replace-regexp
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4051 str
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4052 (viper-read-string-with-history
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4053 (format "Query replace regexp `%s' with: " str)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4054 nil ; no initial
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4055 'viper-replace1-history
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4056 (car viper-replace1-history) ; default
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4057 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4058 (query-replace
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4059 str
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4060 (viper-read-string-with-history
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4061 (format "Query replace `%s' with: " str)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4062 nil ; no initial
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4063 'viper-replace1-history
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4064 (car viper-replace1-history) ; default
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4065 ))))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4066
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4067
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4068 ;; marking
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4069
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4070 (defun viper-mark-beginning-of-buffer ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4071 "Mark beginning of buffer."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4072 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4073 (push-mark (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4074 (goto-char (point-min))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4075 (exchange-point-and-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4076 (message "Mark set at the beginning of buffer"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4077
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4078 (defun viper-mark-end-of-buffer ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4079 "Mark end of buffer."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4080 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4081 (push-mark (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4082 (goto-char (point-max))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4083 (exchange-point-and-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4084 (message "Mark set at the end of buffer"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4085
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4086 (defun viper-mark-point ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4087 "Set mark at point of buffer."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4088 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4089 (let ((char (read-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4090 (cond ((and (<= ?a char) (<= char ?z))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4091 (point-to-register (1+ (- char ?a))))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4092 ((= char ?<) (viper-mark-beginning-of-buffer))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4093 ((= char ?>) (viper-mark-end-of-buffer))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4094 ((= char ?.) (viper-set-mark-if-necessary))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4095 ((= char ?,) (viper-cycle-through-mark-ring))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4096 ((= char ?D) (mark-defun))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4097 (t (error ""))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4098 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4099
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4100 ;; Algorithm: If first invocation of this command save mark on ring, goto
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4101 ;; 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
4102 ;; making it into the new mark, M1.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4103 ;; Push this mark back and set mark to the original point position, p1.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4104 ;; So, if you hit '' or `` then you can return to p1.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4105 ;;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4106 ;; If repeated command, pop top elt from the ring into mark and
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4107 ;; jump there. This forgets the position, p1, and puts M1 back into mark.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4108 ;; 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
4109 ;; 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
4110 ;; etc.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4111 (defun viper-cycle-through-mark-ring ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4112 "Visit previous locations on the mark ring.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4113 One can use `` and '' to temporarily jump 1 step back."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4114 (let* ((sv-pt (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4115 ;; if repeated `m,' command, pop the previously saved mark.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4116 ;; Prev saved mark is actually prev saved point. It is used if the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4117 ;; user types `` or '' and is discarded
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4118 ;; from the mark ring by the next `m,' command.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4119 ;; In any case, go to the previous or previously saved mark.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4120 ;; Then push the current mark (popped off the ring) and set current
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4121 ;; 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
4122 ;; m, command.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4123 (if (eq last-command 'viper-cycle-through-mark-ring)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4124 ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4125 ;; save current mark if the first iteration
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4126 (setq mark-ring (delete (viper-mark-marker) mark-ring))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4127 (if (mark t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4128 (push-mark (mark t) t)) )
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4129 (pop-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4130 (set-mark-command 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4131 ;; don't duplicate mark on the ring
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4132 (setq mark-ring (delete (viper-mark-marker) mark-ring))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4133 (push-mark sv-pt t)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4134 (viper-deactivate-mark)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4135 (setq this-command 'viper-cycle-through-mark-ring)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4136 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4137
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4138
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4139 (defun viper-goto-mark (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4140 "Go to mark."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4141 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4142 (let ((char (read-char))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4143 (com (viper-getcom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4144 (viper-goto-mark-subr char com nil)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4145
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4146 (defun viper-goto-mark-and-skip-white (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4147 "Go to mark and skip to first non-white character on line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4148 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4149 (let ((char (read-char))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4150 (com (viper-getCom arg)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4151 (viper-goto-mark-subr char com t)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4152
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4153 (defun viper-goto-mark-subr (char com skip-white)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4154 (if (eobp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4155 (if (bobp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4156 (error "Empty buffer")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4157 (backward-char 1)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4158 (cond ((viper-valid-register char '(letter))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4159 (let* ((buff (current-buffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4160 (reg (1+ (- char ?a)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4161 (text-marker (get-register reg)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4162 (if com (viper-move-marker-locally 'viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4163 (if (not (viper-valid-marker text-marker))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4164 (error viper-EmptyTextmarker char))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4165 (if (and (viper-same-line (point) viper-last-jump)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4166 (= (point) viper-last-jump-ignore))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4167 (push-mark viper-last-jump t)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4168 (push-mark nil t)) ; no msg
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4169 (viper-register-to-point reg)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4170 (setq viper-last-jump (point-marker))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4171 (cond (skip-white
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4172 (back-to-indentation)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4173 (setq viper-last-jump-ignore (point))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4174 (if com
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4175 (if (equal buff (current-buffer))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4176 (viper-execute-com (if skip-white
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4177 'viper-goto-mark-and-skip-white
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4178 'viper-goto-mark)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4179 nil com)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4180 (switch-to-buffer buff)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4181 (goto-char viper-com-point)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4182 (viper-change-state-to-vi)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4183 (error "")))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4184 ((and (not skip-white) (= char ?`))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4185 (if com (viper-move-marker-locally 'viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4186 (if (and (viper-same-line (point) viper-last-jump)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4187 (= (point) viper-last-jump-ignore))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4188 (goto-char viper-last-jump))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4189 (if (null (mark t)) (error "Mark is not set in this buffer"))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4190 (if (= (point) (mark t)) (pop-mark))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4191 (exchange-point-and-mark)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4192 (setq viper-last-jump (point-marker)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4193 viper-last-jump-ignore 0)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4194 (if com (viper-execute-com 'viper-goto-mark nil com)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4195 ((and skip-white (= char ?'))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4196 (if com (viper-move-marker-locally 'viper-com-point (point)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4197 (if (and (viper-same-line (point) viper-last-jump)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4198 (= (point) viper-last-jump-ignore))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4199 (goto-char viper-last-jump))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4200 (if (= (point) (mark t)) (pop-mark))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4201 (exchange-point-and-mark)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4202 (setq viper-last-jump (point))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4203 (back-to-indentation)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4204 (setq viper-last-jump-ignore (point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4205 (if com (viper-execute-com 'viper-goto-mark-and-skip-white nil com)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4206 (t (error viper-InvalidTextmarker char))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4207
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4208 (defun viper-insert-tab ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4209 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4210 (insert-tab))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4211
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4212 (defun viper-exchange-point-and-mark ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4213 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4214 (exchange-point-and-mark)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4215 (back-to-indentation))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4216
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4217 ;; Input Mode Indentation
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4218
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4219 ;; Returns t, if the string before point matches the regexp STR.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4220 (defsubst viper-looking-back (str)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4221 (and (save-excursion (re-search-backward str nil t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4222 (= (point) (match-end 0))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4223
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4224
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4225 (defun viper-forward-indent ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4226 "Indent forward -- `C-t' in Vi."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4227 (interactive)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4228 (setq viper-cted t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4229 (indent-to (+ (current-column) viper-shift-width)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4230
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4231 (defun viper-backward-indent ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4232 "Backtab, C-d in VI"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4233 (interactive)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4234 (if viper-cted
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4235 (let ((p (point)) (c (current-column)) bol (indent t))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4236 (if (viper-looking-back "[0^]")
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4237 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4238 (if (eq ?^ (preceding-char))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4239 (setq viper-preserve-indent t))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4240 (delete-backward-char 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4241 (setq p (point))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4242 (setq indent nil)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4243 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4244 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4245 (setq bol (point)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4246 (if (re-search-backward "[^ \t]" bol 1) (forward-char))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4247 (delete-region (point) p)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4248 (if indent
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4249 (indent-to (- c viper-shift-width)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4250 (if (or (bolp) (viper-looking-back "[^ \t]"))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4251 (setq viper-cted nil)))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4252
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4253 (defun viper-autoindent ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4254 "Auto Indentation, Vi-style."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4255 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4256 (let ((col (current-indentation)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4257 (if abbrev-mode (expand-abbrev))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4258 (if viper-preserve-indent
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4259 (setq viper-preserve-indent nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4260 (setq viper-current-indent col))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4261 ;; don't leave whitespace lines around
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4262 (if (memq last-command
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4263 '(viper-autoindent
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4264 viper-open-line viper-Open-line
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4265 viper-replace-state-exit-cmd))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4266 (indent-to-left-margin))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4267 ;; use \n instead of newline, or else <Return> will move the insert point
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4268 ;;(newline 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4269 (insert "\n")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4270 (if viper-auto-indent
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4271 (progn
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4272 (setq viper-cted t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4273 (if (and viper-electric-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4274 (not
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4275 (memq major-mode '(fundamental-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4276 text-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4277 paragraph-indent-text-mode ))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4278 (indent-according-to-mode)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4279 (indent-to viper-current-indent))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4280 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4281 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4282
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4283
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4284 ;; Viewing registers
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4285
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4286 (defun viper-ket-function (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4287 "Function called by \], the ket. View registers and call \]\]."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4288 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4289 (let ((reg (read-char)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4290 (cond ((viper-valid-register reg '(letter Letter))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4291 (view-register (downcase reg)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4292 ((viper-valid-register reg '(digit))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4293 (let ((text (current-kill (- reg ?1) 'do-not-rotate)))
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
4294 (with-output-to-temp-buffer " *viper-info*"
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
4295 (princ (format "Register %c contains the string:\n" reg))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
4296 (princ text))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
4297 ))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4298 ((= ?\] reg)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4299 (viper-next-heading arg))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4300 (t (error
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4301 viper-InvalidRegister reg)))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4302
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4303 (defun viper-brac-function (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4304 "Function called by \[, the brac. View textmarkers and call \[\["
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4305 (interactive "P")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4306 (let ((reg (read-char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4307 (cond ((= ?\[ reg)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4308 (viper-prev-heading arg))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4309 ((= ?\] reg)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4310 (viper-heading-end arg))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4311 ((viper-valid-register reg '(letter))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4312 (let* ((val (get-register (1+ (- reg ?a))))
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
4313 (buf (if (not (markerp val))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4314 (error viper-EmptyTextmarker reg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4315 (marker-buffer val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4316 (pos (marker-position val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4317 line-no text (s pos) (e pos))
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
4318 (with-output-to-temp-buffer " *viper-info*"
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4319 (if (and buf pos)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4320 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4321 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4322 (set-buffer buf)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4323 (setq line-no (1+ (count-lines (point-min) val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4324 (goto-char pos)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4325 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4326 (if (re-search-backward "[^ \t]" nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4327 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4328 (beginning-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4329 (setq s (point))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4330 (goto-char pos)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4331 (forward-line 1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4332 (if (re-search-forward "[^ \t]" nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4333 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4334 (end-of-line)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4335 (setq e (point))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4336 (setq text (buffer-substring s e))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4337 (setq text (format "%s<%c>%s"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4338 (substring text 0 (- pos s))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4339 reg (substring text (- pos s)))))
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
4340 (princ
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4341 (format
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4342 "Textmarker `%c' is in buffer `%s' at line %d.\n"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4343 reg (buffer-name buf) line-no))
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
4344 (princ (format "Here is some text around %c:\n\n %s"
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4345 reg text)))
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
4346 (princ (format viper-EmptyTextmarker reg))))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
4347 ))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4348 (t (error viper-InvalidTextmarker reg)))))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4349
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4350
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4351
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4352 ;; commands in insertion mode
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4353
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4354 (defun viper-delete-backward-word (arg)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4355 "Delete previous word."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4356 (interactive "p")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4357 (save-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4358 (push-mark nil t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4359 (backward-word arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4360 (delete-region (point) (mark t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4361 (pop-mark)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4362
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4363
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4364 (defun viper-set-expert-level (&optional dont-change-unless)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4365 "Sets the expert level for a Viper user.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4366 Can be called interactively to change (temporarily or permanently) the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4367 current expert level.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4368
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4369 The optional argument DONT-CHANGE-UNLESS, if not nil, says that
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4370 the level should not be changed, unless its current value is
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4371 meaningless (i.e., not one of 1,2,3,4,5).
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4372
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4373 User level determines the setting of Viper variables that are most
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4374 sensitive for VI-style look-and-feel."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4375
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4376 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4377
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4378 (if (not (natnump viper-expert-level)) (setq viper-expert-level 0))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4379
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4380 (save-window-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4381 (delete-other-windows)
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4382 ;; if 0 < viper-expert-level < viper-max-expert-level
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4383 ;; & dont-change-unless = t -- use it; else ask
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4384 (viper-ask-level dont-change-unless))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4385
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4386 (setq viper-always t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4387 viper-ex-style-motion t
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
4388 viper-ex-style-editing t
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4389 viper-want-ctl-h-help nil)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4390
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4391 (cond ((eq viper-expert-level 1) ; novice or beginner
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4392 (global-set-key ; in emacs-state
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4393 viper-toggle-key
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4394 (if (viper-window-display-p) 'viper-iconify 'suspend-emacs))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4395 (setq viper-no-multiple-ESC t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4396 viper-re-search t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4397 viper-vi-style-in-minibuffer t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4398 viper-search-wrap-around-t t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4399 viper-electric-mode nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4400 viper-want-emacs-keys-in-vi nil
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4401 viper-want-emacs-keys-in-insert nil))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4402
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4403 ((and (> viper-expert-level 1) (< viper-expert-level 5))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4404 ;; intermediate to guru
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4405 (setq viper-no-multiple-ESC (if (viper-window-display-p)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4406 t 'twice)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4407 viper-electric-mode t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4408 viper-want-emacs-keys-in-vi t
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4409 viper-want-emacs-keys-in-insert (> viper-expert-level 2))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4410
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4411 (if (eq viper-expert-level 4) ; respect user's ex-style motion
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4412 ; and viper-no-multiple-ESC
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4413 (progn
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4414 (setq-default
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
4415 viper-ex-style-editing
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
4416 (viper-standard-value 'viper-ex-style-editing)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4417 viper-ex-style-motion
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4418 (viper-standard-value 'viper-ex-style-motion))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4419 (setq viper-ex-style-motion
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4420 (viper-standard-value 'viper-ex-style-motion)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
4421 viper-ex-style-editing
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
4422 (viper-standard-value 'viper-ex-style-editing)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4423 viper-re-search
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4424 (viper-standard-value 'viper-re-search)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4425 viper-no-multiple-ESC
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4426 (viper-standard-value 'viper-no-multiple-ESC)))))
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4427
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4428 ;; A wizard!!
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4429 ;; Ideally, if 5 is selected, a buffer should pop up to let the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4430 ;; user toggle the values of variables.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
4431 (t (setq-default viper-ex-style-editing
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
4432 (viper-standard-value 'viper-ex-style-editing)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4433 viper-ex-style-motion
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4434 (viper-standard-value 'viper-ex-style-motion))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4435 (setq viper-want-ctl-h-help
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4436 (viper-standard-value 'viper-want-ctl-h-help)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4437 viper-always
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4438 (viper-standard-value 'viper-always)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4439 viper-no-multiple-ESC
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4440 (viper-standard-value 'viper-no-multiple-ESC)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4441 viper-ex-style-motion
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4442 (viper-standard-value 'viper-ex-style-motion)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
4443 viper-ex-style-editing
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
4444 (viper-standard-value 'viper-ex-style-editing)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4445 viper-re-search
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4446 (viper-standard-value 'viper-re-search)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4447 viper-electric-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4448 (viper-standard-value 'viper-electric-mode)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4449 viper-want-emacs-keys-in-vi
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4450 (viper-standard-value 'viper-want-emacs-keys-in-vi)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4451 viper-want-emacs-keys-in-insert
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4452 (viper-standard-value 'viper-want-emacs-keys-in-insert))))
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4453
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4454 (viper-set-mode-vars-for viper-current-state)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4455 (if (or viper-always
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4456 (and (> viper-expert-level 0) (> 5 viper-expert-level)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4457 (viper-set-hooks)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4458
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4459 ;; Ask user expert level.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4460 (defun viper-ask-level (dont-change-unless)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4461 (let ((ask-buffer " *viper-ask-level*")
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4462 level-changed repeated)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4463 (save-window-excursion
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4464 (switch-to-buffer ask-buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4465
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4466 (while (or (> viper-expert-level viper-max-expert-level)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4467 (< viper-expert-level 1)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4468 (null dont-change-unless))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4469 (erase-buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4470 (if repeated
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4471 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4472 (message "Invalid user level")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4473 (beep 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4474 (setq repeated t))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4475 (setq dont-change-unless t
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4476 level-changed t)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4477 (insert "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4478 Please specify your level of familiarity with the venomous VI PERil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4479 (and the VI Plan for Emacs Rescue).
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4480 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
4481
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4482 1 -- BEGINNER: Almost all Emacs features are suppressed.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4483 Feels almost like straight Vi. File name completion and
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4484 command history in the minibuffer are thrown in as a bonus.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4485 To use Emacs productively, you must reach level 3 or higher.
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4486 2 -- MASTER: C-c now has its standard Emacs meaning in Vi command state,
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4487 so most Emacs commands can be used when Viper is in Vi state.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4488 Good progress---you are well on the way to level 3!
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4489 3 -- GRAND MASTER: Like 3, but most Emacs commands are available also
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4490 in Viper's insert state.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4491 4 -- GURU: Like 3, but user settings are respected for viper-no-multiple-ESC,
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
4492 viper-ex-style-motion, viper-ex-style-editing, and
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4493 viper-re-search variables. Adjust these settings to your taste.
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4494 5 -- WIZARD: Like 4, but user settings are also respected for viper-always,
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4495 viper-electric-mode, viper-want-ctl-h-help, viper-want-emacs-keys-in-vi,
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4496 and viper-want-emacs-keys-in-insert. Adjust these to your taste.
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4497
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4498 Please, specify your level now: ")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4499
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4500 (setq viper-expert-level (- (viper-read-char-exclusive) ?0))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4501 ) ; end while
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4502
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4503 ;; tell the user if level was changed
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4504 (and level-changed
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4505 (progn
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4506 (insert
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4507 (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
4508 viper-expert-level))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4509 (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
4510 ;; save the setting for viper-expert-level
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4511 (viper-save-setting
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4512 'viper-expert-level
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4513 (format "Saving user level %d ..." viper-expert-level)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4514 viper-custom-file-name))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4515 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4516 (bury-buffer) ; remove ask-buffer from screen
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4517 (message "")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4518 )))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4519
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4520
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4521 (defun viper-nil ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4522 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4523 (beep 1))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4524
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4525
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4526 ;; if ENFORCE-BUFFER is not nil, error if CHAR is a marker in another buffer
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4527 (defun viper-register-to-point (char &optional enforce-buffer)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4528 "Like jump-to-register, but switches to another buffer in another window."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4529 (interactive "cViper register to point: ")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4530 (let ((val (get-register char)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4531 (cond
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4532 ((and (fboundp 'frame-configuration-p)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4533 (frame-configuration-p val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4534 (set-frame-configuration val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4535 ((window-configuration-p val)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4536 (set-window-configuration val))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4537 ((viper-valid-marker val)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4538 (if (and enforce-buffer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4539 (not (equal (current-buffer) (marker-buffer val))))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4540 (error (concat viper-EmptyTextmarker " in this buffer")
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4541 (1- (+ char ?a))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4542 (pop-to-buffer (marker-buffer val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4543 (goto-char val))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4544 ((and (consp val) (eq (car val) 'file))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4545 (find-file (cdr val)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4546 (t
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4547 (error viper-EmptyTextmarker (1- (+ char ?a)))))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4548
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4549
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4550 (defun viper-save-kill-buffer ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4551 "Save then kill current buffer. "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4552 (interactive)
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4553 (if (< viper-expert-level 2)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4554 (save-buffers-kill-emacs)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4555 (save-buffer)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4556 (kill-buffer (current-buffer))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4557
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4558
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4559
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4560 ;;; Bug Report
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4561
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4562 (defun viper-submit-report ()
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4563 "Submit bug report on Viper."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4564 (interactive)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4565 (let ((reporter-prompt-for-summary-p t)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4566 (viper-device-type (viper-device-type))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4567 color-display-p frame-parameters
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4568 minibuffer-emacs-face minibuffer-vi-face minibuffer-insert-face
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4569 varlist salutation window-config)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4570
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4571 ;; 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
4572 ;; like we did with color-display-p.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4573 (setq color-display-p (if (viper-window-display-p)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4574 (viper-color-display-p)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4575 'non-x)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4576 minibuffer-vi-face (if (viper-has-face-support-p)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4577 (viper-get-face viper-minibuffer-vi-face)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4578 'non-x)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4579 minibuffer-insert-face (if (viper-has-face-support-p)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4580 (viper-get-face
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4581 viper-minibuffer-insert-face)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4582 'non-x)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4583 minibuffer-emacs-face (if (viper-has-face-support-p)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4584 (viper-get-face
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4585 viper-minibuffer-emacs-face)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4586 'non-x)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4587 frame-parameters (if (fboundp 'frame-parameters)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4588 (frame-parameters (selected-frame))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4589
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4590 (setq varlist (list 'viper-vi-minibuffer-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4591 'viper-insert-minibuffer-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4592 'viper-vi-intercept-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4593 'viper-vi-local-user-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4594 'viper-vi-kbd-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4595 'viper-vi-global-user-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4596 'viper-vi-state-modifier-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4597 'viper-vi-diehard-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4598 'viper-vi-basic-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4599 'viper-replace-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4600 'viper-insert-intercept-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4601 'viper-insert-local-user-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4602 'viper-insert-kbd-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4603 'viper-insert-global-user-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4604 'viper-insert-state-modifier-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4605 'viper-insert-diehard-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4606 'viper-insert-basic-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4607 'viper-emacs-intercept-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4608 'viper-emacs-local-user-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4609 'viper-emacs-kbd-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4610 'viper-emacs-global-user-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4611 'viper-emacs-state-modifier-minor-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4612 'viper-automatic-iso-accents
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
4613 'viper-special-input-method
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4614 'viper-want-emacs-keys-in-insert
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4615 'viper-want-emacs-keys-in-vi
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4616 'viper-keep-point-on-undo
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4617 'viper-no-multiple-ESC
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4618 'viper-electric-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4619 'viper-ESC-key
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4620 'viper-want-ctl-h-help
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 181
diff changeset
4621 'viper-ex-style-editing
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4622 'viper-delete-backwards-in-replace
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4623 'viper-vi-style-in-minibuffer
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4624 'viper-vi-state-hook
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4625 'viper-insert-state-hook
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4626 'viper-replace-state-hook
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4627 'viper-emacs-state-hook
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4628 'ex-cycle-other-window
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4629 'ex-cycle-through-non-files
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
4630 'viper-expert-level
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4631 'major-mode
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4632 'viper-device-type
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4633 'color-display-p
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4634 'frame-parameters
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4635 'minibuffer-vi-face
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4636 'minibuffer-insert-face
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4637 'minibuffer-emacs-face
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4638 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4639 (setq salutation "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4640 Congratulations! You may have unearthed a bug in Viper!
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4641 Please mail a concise, accurate summary of the problem to the address above.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4642
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4643 -------------------------------------------------------------------")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4644 (setq window-config (current-window-configuration))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4645 (with-output-to-temp-buffer " *viper-info*"
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4646 (switch-to-buffer " *viper-info*")
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4647 (delete-other-windows)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4648 (princ "
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4649 PLEASE FOLLOW THESE PROCEDURES
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4650 ------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4651
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4652 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
4653 not cause by other packages you are using.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4654
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4655 Don't report compilation warnings, unless you are certain that there is a
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4656 problem. These warnings are normal and unavoidable.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4657
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4658 Please note that users should not modify variables and keymaps other than
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4659 those advertised in the manual. Such `customization' is likely to crash
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4660 Viper, as it would any other improperly customized Emacs package.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4661
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4662 If you are reporting an error message received while executing one of the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4663 Viper commands, type:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4664
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4665 M-x set-variable <Return> debug-on-error <Return> t <Return>
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4666
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4667 Then reproduce the error. The above command will cause Emacs to produce a
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4668 back trace of the execution that leads to the error. Please include this
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4669 trace in your bug report.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4670
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4671 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
4672 \(e.g., Emacs freezes\), type:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4673
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4674 M-x set-variable <Return> debug-on-quit <Return> t <Return>
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4675
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4676 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
4677 the current command. Include the resulting back trace in the bug report.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4678
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4679 Mail anyway (y or n)? ")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4680 (if (y-or-n-p "Mail anyway? ")
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4681 ()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4682 (set-window-configuration window-config)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4683 (error "Bug report aborted")))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4684
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4685 (require 'reporter)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4686 (set-window-configuration window-config)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4687
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4688 (reporter-submit-bug-report "kifer@cs.sunysb.edu"
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4689 (viper-version)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4690 varlist
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4691 nil 'delete-other-windows
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4692 salutation)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4693 ))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4694
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4695
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4696
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4697
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4698 ;; Smoothes out the difference between Emacs' unread-command-events
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4699 ;; 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
4700 ;; events or a sequence of keys.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4701 ;;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4702 ;; 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
4703 ;; symbol in unread-command-events list may cause Emacs to turn this symbol
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4704 ;; 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
4705 ;; common symbol that might appear in this wrong context.
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4706 (defun viper-set-unread-command-events (arg)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4707 (if viper-emacs-p
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4708 (setq
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4709 unread-command-events
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4710 (let ((new-events
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4711 (cond ((eventp arg) (list arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4712 ((listp arg) arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4713 ((sequencep arg)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4714 (listify-key-sequence arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4715 (t (error
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4716 "viper-set-unread-command-events: Invalid argument, %S"
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4717 arg)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4718 (if (not (eventp nil))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4719 (setq new-events (delq nil new-events)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4720 (append new-events unread-command-events)))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4721 ;; XEmacs
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4722 (setq
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4723 unread-command-events
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4724 (append
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4725 (cond ((viper-characterp arg) (list (character-to-event arg)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4726 ((eventp arg) (list arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4727 ((stringp arg) (mapcar 'character-to-event arg))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4728 ((vectorp arg) (append arg nil)) ; turn into list
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4729 ((listp arg) (viper-eventify-list-xemacs arg))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4730 (t (error
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4731 "viper-set-unread-command-events: Invalid argument, %S" arg)))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4732 unread-command-events))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4733
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4734 ;; list is assumed to be a list of events of characters
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4735 (defun viper-eventify-list-xemacs (lis)
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4736 (mapcar
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4737 (function (lambda (elt)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4738 (cond ((viper-characterp elt) (character-to-event elt))
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4739 ((eventp elt) elt)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4740 (t (error
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 175
diff changeset
4741 "viper-eventify-list-xemacs: can't convert to event, %S"
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4742 elt)))))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4743 lis))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4744
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4745
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4746
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4747 ;;; viper-cmd.el ends here