annotate lisp/emulation/viper-cmd.el @ 18313:083d035f7932

(coding-system-parent): Moved to mule.el.
author Kenichi Handa <handa@m17n.org>
date Wed, 18 Jun 1997 13:22:13 +0000
parents 3a43376db2be
children 1405083241e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1 ;;; viper-cmd.el --- Vi command support for Viper
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2 ;; Copyright (C) 1997 Free Software Foundation, Inc.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
5 ;; Code
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
6
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
7 (provide 'viper-cmd)
18172
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
8 (require 'advice)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
9
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
10 ;; Compiler pacifier
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
11 (defvar vip-minibuffer-current-face)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
12 (defvar vip-minibuffer-insert-face)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
13 (defvar vip-minibuffer-vi-face)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
14 (defvar vip-minibuffer-emacs-face)
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
15 (defvar viper-always)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
16 (defvar vip-mode-string )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
17 (defvar iso-accents-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
18 (defvar zmacs-region-stays)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
19 (defvar mark-even-if-inactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
20
18172
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
21 ;; loading happens only in non-interactive compilation
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
22 ;; in order to spare non-viperized emacs from being viperized
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
23 (if noninteractive
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
24 (eval-when-compile
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
25 (let ((load-path (cons (expand-file-name ".") load-path)))
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
26 (or (featurep 'viper-util)
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
27 (load "viper-util.el" nil nil 'nosuffix))
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
28 (or (featurep 'viper-keym)
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
29 (load "viper-keym.el" nil nil 'nosuffix))
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
30 (or (featurep 'viper-mous)
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
31 (load "viper-mous.el" nil nil 'nosuffix))
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
32 (or (featurep 'viper-macs)
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
33 (load "viper-macs.el" nil nil 'nosuffix))
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
34 (or (featurep 'viper-ex)
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
35 (load "viper-ex.el" nil nil 'nosuffix))
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
36 )))
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
37 ;; end pacifier
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
38
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
39
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
40 (require 'viper-util)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
41 (require 'viper-keym)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
42 (require 'viper-mous)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
43 (require 'viper-macs)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
44 (require 'viper-ex)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
45
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
46
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
47
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
48 ;; Generic predicates
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
49
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
50 ;; These test functions are shamelessly lifted from vip 4.4.2 by Aamod Sane
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
51
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
52 ;; generate test functions
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
53 ;; given symbol foo, foo-p is the test function, foos is the set of
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
54 ;; Viper command keys
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
55 ;; (macroexpand '(vip-test-com-defun foo))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
56 ;; (defun foo-p (com) (consp (memq (if (< com 0) (- com) com) foos)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
57
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
58 (defmacro vip-test-com-defun (name)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
59 (let* ((snm (symbol-name name))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
60 (nm-p (intern (concat snm "-p")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
61 (nms (intern (concat snm "s"))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
62 (` (defun (, nm-p) (com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
63 (consp (memq (if (< com 0) (- com) com) (, nms)))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
64
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
65 ;; Variables for defining VI commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
66
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
67 ;; Modifying commands that can be prefixes to movement commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
68 (defconst vip-prefix-commands '(?c ?d ?y ?! ?= ?# ?< ?> ?\"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
69 ;; define vip-prefix-command-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
70 (vip-test-com-defun vip-prefix-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
71
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
72 ;; Commands that are pairs eg. dd. r and R here are a hack
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
73 (defconst vip-charpair-commands '(?c ?d ?y ?! ?= ?< ?> ?r ?R))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
74 ;; define vip-charpair-command-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
75 (vip-test-com-defun vip-charpair-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
76
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
77 (defconst vip-movement-commands '(?b ?B ?e ?E ?f ?F ?G ?h ?H ?j ?k ?l
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
78 ?H ?M ?L ?n ?t ?T ?w ?W ?$ ?%
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
79 ?^ ?( ?) ?- ?+ ?| ?{ ?} ?[ ?] ?' ?`
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
80 ?; ?, ?0 ?? ?/
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
81 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
82 "Movement commands")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
83 ;; define vip-movement-command-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
84 (vip-test-com-defun vip-movement-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
85
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
86 (defconst vip-digit-commands '(?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
87 "Digit commands")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
88 ;; define vip-digit-command-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
89 (vip-test-com-defun vip-digit-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
90
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
91 ;; Commands that can be repeated by . (dotted)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
92 (defconst vip-dotable-commands '(?c ?d ?C ?s ?S ?D ?> ?<))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
93 ;; define vip-dotable-command-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
94 (vip-test-com-defun vip-dotable-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
95
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
96 ;; Commands that can follow a #
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
97 (defconst vip-hash-commands '(?c ?C ?g ?q ?s))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
98 ;; define vip-hash-command-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
99 (vip-test-com-defun vip-hash-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
100
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
101 ;; Commands that may have registers as prefix
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
102 (defconst vip-regsuffix-commands '(?d ?y ?Y ?D ?p ?P ?x ?X))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
103 ;; define vip-regsuffix-command-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
104 (vip-test-com-defun vip-regsuffix-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
105
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
106 (defconst vip-vi-commands (append vip-movement-commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
107 vip-digit-commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
108 vip-dotable-commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
109 vip-charpair-commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
110 vip-hash-commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
111 vip-prefix-commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
112 vip-regsuffix-commands)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
113 "The list of all commands in Vi-state.")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
114 ;; define vip-vi-command-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
115 (vip-test-com-defun vip-vi-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
116
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
117
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
118 ;;; CODE
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
119
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
120 ;; sentinels
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
121
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
122 ;; Runs vip-after-change-functions inside after-change-functions
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
123 (defun vip-after-change-sentinel (beg end len)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
124 (let ((list vip-after-change-functions))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
125 (while list
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
126 (funcall (car list) beg end len)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
127 (setq list (cdr list)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
128
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
129 ;; Runs vip-before-change-functions inside before-change-functions
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
130 (defun vip-before-change-sentinel (beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
131 (let ((list vip-before-change-functions))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
132 (while list
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
133 (funcall (car list) beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
134 (setq list (cdr list)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
135
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
136 (defsubst vip-post-command-sentinel ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
137 (run-hooks 'vip-post-command-hooks))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
138
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
139 (defsubst vip-pre-command-sentinel ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
140 (run-hooks 'vip-pre-command-hooks))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
141
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
142 ;; Needed so that Viper will be able to figure the last inserted
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
143 ;; chunk of text with reasonable accuracy.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
144 (defsubst vip-insert-state-post-command-sentinel ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
145 (if (and (memq vip-current-state '(insert-state replace-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
146 vip-insert-point
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
147 (>= (point) vip-insert-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
148 (setq vip-last-posn-while-in-insert-state (point-marker)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
149 (if (eq vip-current-state 'insert-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
150 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
151 (or (stringp vip-saved-cursor-color)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
152 (string= (vip-get-cursor-color) vip-insert-state-cursor-color)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
153 (setq vip-saved-cursor-color (vip-get-cursor-color)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
154 (if (stringp vip-saved-cursor-color)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
155 (vip-change-cursor-color vip-insert-state-cursor-color))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
156 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
157 (if (and (eq this-command 'dabbrev-expand)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
158 (integerp vip-pre-command-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
159 (> vip-insert-point vip-pre-command-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
160 (move-marker vip-insert-point vip-pre-command-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
161 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
162
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
163 (defsubst vip-insert-state-pre-command-sentinel ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
164 (or (memq this-command '(self-insert-command))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
165 (memq (vip-event-key last-command-event)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
166 '(up down left right (meta f) (meta b)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
167 (control n) (control p) (control f) (control b)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
168 (vip-restore-cursor-color-after-insert))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
169 (if (and (eq this-command 'dabbrev-expand)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
170 (markerp vip-insert-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
171 (marker-position vip-insert-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
172 (setq vip-pre-command-point (marker-position vip-insert-point))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
173
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
174 (defsubst vip-R-state-post-command-sentinel ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
175 ;; Restoring cursor color is needed despite
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
176 ;; vip-replace-state-pre-command-sentinel: When you jump to another buffer in
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
177 ;; another frame, the pre-command hook won't change cursor color to default
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
178 ;; in that other frame. So, if the second frame cursor was red and we set
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
179 ;; the point outside the replacement region, then the cursor color will
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
180 ;; remain red. Restoring the default, below, prevents this.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
181 (if (and (<= (vip-replace-start) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
182 (<= (point) (vip-replace-end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
183 (vip-change-cursor-color vip-replace-overlay-cursor-color)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
184 (vip-restore-cursor-color-after-replace)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
185 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
186
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
187 ;; to speed up, don't change cursor color before self-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
188 ;; and common move commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
189 (defsubst vip-replace-state-pre-command-sentinel ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
190 (or (memq this-command '(self-insert-command))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
191 (memq (vip-event-key last-command-event)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
192 '(up down left right (meta f) (meta b)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
193 (control n) (control p) (control f) (control b)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
194 (vip-restore-cursor-color-after-replace)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
195
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
196 (defun vip-replace-state-post-command-sentinel ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
197 ;; Restoring cursor color is needed despite
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
198 ;; vip-replace-state-pre-command-sentinel: When one jumps to another buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
199 ;; in another frame, the pre-command hook won't change cursor color to
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
200 ;; default in that other frame. So, if the second frame cursor was red and
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
201 ;; we set the point outside the replacement region, then the cursor color
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
202 ;; will remain red. Restoring the default, below, fixes this problem.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
203 ;;
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
204 ;; We optimize for self-insert-command's here, since they either don't change
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
205 ;; cursor color or, if they terminate replace mode, the color will be changed
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
206 ;; in vip-finish-change
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
207 (or (memq this-command '(self-insert-command))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
208 (vip-restore-cursor-color-after-replace))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
209 (cond
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
210 ((eq vip-current-state 'replace-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
211 ;; delete characters to compensate for inserted chars.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
212 (let ((replace-boundary (vip-replace-end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
213 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
214 (goto-char vip-last-posn-in-replace-region)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
215 (delete-char vip-replace-chars-to-delete)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
216 (setq vip-replace-chars-to-delete 0
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
217 vip-replace-chars-deleted 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
218 ;; terminate replace mode if reached replace limit
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
219 (if (= vip-last-posn-in-replace-region
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
220 (vip-replace-end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
221 (vip-finish-change vip-last-posn-in-replace-region)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
222
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
223 (if (and (<= (vip-replace-start) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
224 (<= (point) replace-boundary))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
225 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
226 ;; the state may have changed in vip-finish-change above
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
227 (if (eq vip-current-state 'replace-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
228 (vip-change-cursor-color vip-replace-overlay-cursor-color))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
229 (setq vip-last-posn-in-replace-region (point-marker))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
230 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
231
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
232 (t ;; terminate replace mode if changed Viper states.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
233 (vip-finish-change vip-last-posn-in-replace-region))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
234
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
235
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
236 ;; changing mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
237
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
238 ;; Change state to NEW-STATE---either emacs-state, vi-state, or insert-state.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
239 (defun vip-change-state (new-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
240 ;; Keep vip-post/pre-command-hooks fresh.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
241 ;; We remove then add vip-post/pre-command-sentinel since it is very
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
242 ;; desirable that vip-pre-command-sentinel is the last hook and
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
243 ;; vip-post-command-sentinel is the first hook.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
244 (remove-hook 'post-command-hook 'vip-post-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
245 (add-hook 'post-command-hook 'vip-post-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
246 (remove-hook 'pre-command-hook 'vip-pre-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
247 (add-hook 'pre-command-hook 'vip-pre-command-sentinel t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
248 ;; These hooks will be added back if switching to insert/replace mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
249 (vip-remove-hook 'vip-post-command-hooks
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
250 'vip-insert-state-post-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
251 (vip-remove-hook 'vip-pre-command-hooks
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
252 'vip-insert-state-pre-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
253 (cond ((eq new-state 'vi-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
254 (cond ((member vip-current-state '(insert-state replace-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
255
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
256 ;; move vip-last-posn-while-in-insert-state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
257 ;; This is a normal hook that is executed in insert/replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
258 ;; states after each command. In Vi/Emacs state, it does
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
259 ;; nothing. We need to execute it here to make sure that
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
260 ;; the last posn was recorded when we hit ESC.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
261 ;; It may be left unrecorded if the last thing done in
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
262 ;; insert/repl state was dabbrev-expansion or abbrev
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
263 ;; expansion caused by hitting ESC
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
264 (vip-insert-state-post-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
265
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
266 (condition-case conds
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
267 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
268 (vip-save-last-insertion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
269 vip-insert-point
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
270 vip-last-posn-while-in-insert-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
271 (if vip-began-as-replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
272 (setq vip-began-as-replace nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
273 ;; repeat insert commands if numerical arg > 1
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
274 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
275 (vip-repeat-insert-command))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
276 (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
277 (vip-message-conditions conds)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
278
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
279 (if (> (length vip-last-insertion) 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
280 (vip-push-onto-ring vip-last-insertion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
281 'vip-insertion-ring))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
282
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
283 (if vip-ex-style-editing-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
284 (or (bolp) (backward-char 1))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
285 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
286
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
287 ;; insert or replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
288 ((memq new-state '(insert-state replace-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
289 (if (memq vip-current-state '(emacs-state vi-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
290 (vip-move-marker-locally 'vip-insert-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
291 (vip-move-marker-locally 'vip-last-posn-while-in-insert-state (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
292 (vip-add-hook 'vip-post-command-hooks
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
293 'vip-insert-state-post-command-sentinel t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
294 (vip-add-hook 'vip-pre-command-hooks
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
295 'vip-insert-state-pre-command-sentinel t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
296 ) ; outermost cond
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
297
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
298 ;; Nothing needs to be done to switch to emacs mode! Just set some
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
299 ;; variables, which is already done in vip-change-state-to-emacs!
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
300
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
301 (setq vip-current-state new-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
302 (vip-normalize-minor-mode-map-alist)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
303 (vip-adjust-keys-for new-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
304 (vip-set-mode-vars-for new-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
305 (vip-refresh-mode-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
306 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
307
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
308
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
309
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
310 (defun vip-adjust-keys-for (state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
311 "Make necessary adjustments to keymaps before entering STATE."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
312 (cond ((memq state '(insert-state replace-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
313 (if vip-auto-indent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
314 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
315 (define-key vip-insert-basic-map "\C-m" 'vip-autoindent)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
316 (if vip-want-emacs-keys-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
317 ;; expert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
318 (define-key vip-insert-basic-map "\C-j" nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
319 ;; novice
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
320 (define-key vip-insert-basic-map "\C-j" 'vip-autoindent)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
321 (define-key vip-insert-basic-map "\C-m" nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
322 (define-key vip-insert-basic-map "\C-j" nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
323
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
324 (setq vip-insert-diehard-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
325 (not vip-want-emacs-keys-in-insert))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
326
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
327 (if vip-want-ctl-h-help
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
328 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
329 (define-key vip-insert-basic-map [(control h)] 'help-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
330 (define-key vip-replace-map [(control h)] 'help-command))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
331 (define-key vip-insert-basic-map
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
332 [(control h)] 'vip-del-backward-char-in-insert)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
333 (define-key vip-replace-map
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
334 [(control h)] 'vip-del-backward-char-in-replace)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
335
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
336 (t ; Vi state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
337 (setq vip-vi-diehard-minor-mode (not vip-want-emacs-keys-in-vi))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
338 (if vip-want-ctl-h-help
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
339 (define-key vip-vi-basic-map [(control h)] 'help-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
340 (define-key vip-vi-basic-map [(control h)] 'vip-backward-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
341 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
342
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
343
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
344 ;; Normalizes minor-mode-map-alist by putting Viper keymaps first.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
345 ;; This ensures that Viper bindings are in effect, regardless of which minor
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
346 ;; modes were turned on by the user or by other packages.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
347 (defun vip-normalize-minor-mode-map-alist ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
348 (setq minor-mode-map-alist
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
349 (vip-append-filter-alist
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
350 (list
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
351 (cons 'vip-vi-intercept-minor-mode vip-vi-intercept-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
352 (cons 'vip-vi-minibuffer-minor-mode vip-minibuffer-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
353 (cons 'vip-vi-local-user-minor-mode vip-vi-local-user-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
354 (cons 'vip-vi-kbd-minor-mode vip-vi-kbd-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
355 (cons 'vip-vi-global-user-minor-mode vip-vi-global-user-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
356 (cons 'vip-vi-state-modifier-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
357 (if (keymapp
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
358 (cdr (assoc major-mode vip-vi-state-modifier-alist)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
359 (cdr (assoc major-mode vip-vi-state-modifier-alist))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
360 vip-empty-keymap))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
361 (cons 'vip-vi-diehard-minor-mode vip-vi-diehard-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
362 (cons 'vip-vi-basic-minor-mode vip-vi-basic-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
363 (cons 'vip-insert-intercept-minor-mode vip-insert-intercept-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
364 (cons 'vip-replace-minor-mode vip-replace-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
365 ;; vip-insert-minibuffer-minor-mode must come after
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
366 ;; vip-replace-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
367 (cons 'vip-insert-minibuffer-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
368 vip-minibuffer-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
369 (cons 'vip-insert-local-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
370 vip-insert-local-user-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
371 (cons 'vip-insert-kbd-minor-mode vip-insert-kbd-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
372 (cons 'vip-insert-global-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
373 vip-insert-global-user-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
374 (cons 'vip-insert-state-modifier-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
375 (if (keymapp
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
376 (cdr
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
377 (assoc major-mode vip-insert-state-modifier-alist)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
378 (cdr
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
379 (assoc major-mode vip-insert-state-modifier-alist))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
380 vip-empty-keymap))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
381 (cons 'vip-insert-diehard-minor-mode vip-insert-diehard-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
382 (cons 'vip-insert-basic-minor-mode vip-insert-basic-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
383 (cons 'vip-emacs-intercept-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
384 vip-emacs-intercept-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
385 (cons 'vip-emacs-local-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
386 vip-emacs-local-user-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
387 (cons 'vip-emacs-kbd-minor-mode vip-emacs-kbd-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
388 (cons 'vip-emacs-global-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
389 vip-emacs-global-user-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
390 (cons 'vip-emacs-state-modifier-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
391 (if (keymapp
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
392 (cdr
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
393 (assoc major-mode vip-emacs-state-modifier-alist)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
394 (cdr
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
395 (assoc major-mode vip-emacs-state-modifier-alist))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
396 vip-empty-keymap))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
397 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
398 minor-mode-map-alist)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
399
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
400
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
401
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
402
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
403
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
404 ;; Viper mode-changing commands and utilities
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
405
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
406 ;; Modifies mode-line-buffer-identification.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
407 (defun vip-refresh-mode-line ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
408 (setq vip-mode-string
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
409 (cond ((eq vip-current-state 'emacs-state) vip-emacs-state-id)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
410 ((eq vip-current-state 'vi-state) vip-vi-state-id)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
411 ((eq vip-current-state 'replace-state) vip-replace-state-id)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
412 ((eq vip-current-state 'insert-state) vip-insert-state-id)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
413
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
414 ;; Sets Viper mode string in global-mode-string
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
415 (force-mode-line-update))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
416
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
417
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
418 ;; Switch from Insert state to Vi state.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
419 (defun vip-exit-insert-state ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
420 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
421 (vip-change-state-to-vi))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
422
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
423 (defun vip-set-mode-vars-for (state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
424 "Sets Viper minor mode variables to put Viper's state STATE in effect."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
425
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
426 ;; Emacs state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
427 (setq vip-vi-minibuffer-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
428 vip-insert-minibuffer-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
429 vip-vi-intercept-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
430 vip-insert-intercept-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
431
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
432 vip-vi-local-user-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
433 vip-vi-kbd-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
434 vip-vi-global-user-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
435 vip-vi-state-modifier-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
436 vip-vi-diehard-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
437 vip-vi-basic-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
438
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
439 vip-replace-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
440
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
441 vip-insert-local-user-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
442 vip-insert-kbd-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
443 vip-insert-global-user-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
444 vip-insert-state-modifier-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
445 vip-insert-diehard-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
446 vip-insert-basic-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
447 vip-emacs-intercept-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
448 vip-emacs-local-user-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
449 vip-emacs-kbd-minor-mode (not (vip-is-in-minibuffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
450 vip-emacs-global-user-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
451 vip-emacs-state-modifier-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
452 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
453
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
454 ;; Vi state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
455 (if (eq state 'vi-state) ; adjust for vi-state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
456 (setq
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
457 vip-vi-intercept-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
458 vip-vi-minibuffer-minor-mode (vip-is-in-minibuffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
459 vip-vi-local-user-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
460 vip-vi-kbd-minor-mode (not (vip-is-in-minibuffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
461 vip-vi-global-user-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
462 vip-vi-state-modifier-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
463 ;; don't let the diehard keymap block command completion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
464 ;; and other things in the minibuffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
465 vip-vi-diehard-minor-mode (not
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
466 (or vip-want-emacs-keys-in-vi
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
467 (vip-is-in-minibuffer)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
468 vip-vi-basic-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
469 vip-emacs-intercept-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
470 vip-emacs-local-user-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
471 vip-emacs-kbd-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
472 vip-emacs-global-user-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
473 vip-emacs-state-modifier-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
474 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
475
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
476 ;; Insert and Replace states
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
477 (if (member state '(insert-state replace-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
478 (setq
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
479 vip-insert-intercept-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
480 vip-replace-minor-mode (eq state 'replace-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
481 vip-insert-minibuffer-minor-mode (vip-is-in-minibuffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
482 vip-insert-local-user-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
483 vip-insert-kbd-minor-mode (not (vip-is-in-minibuffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
484 vip-insert-global-user-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
485 vip-insert-state-modifier-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
486 ;; don't let the diehard keymap block command completion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
487 ;; and other things in the minibuffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
488 vip-insert-diehard-minor-mode (not
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
489 (or vip-want-emacs-keys-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
490 (vip-is-in-minibuffer)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
491 vip-insert-basic-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
492 vip-emacs-intercept-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
493 vip-emacs-local-user-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
494 vip-emacs-kbd-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
495 vip-emacs-global-user-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
496 vip-emacs-state-modifier-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
497 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
498
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
499 ;; minibuffer faces
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
500 (if (vip-has-face-support-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
501 (setq vip-minibuffer-current-face
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
502 (cond ((eq state 'emacs-state) vip-minibuffer-emacs-face)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
503 ((eq state 'vi-state) vip-minibuffer-vi-face)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
504 ((memq state '(insert-state replace-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
505 vip-minibuffer-insert-face))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
506
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
507 (if (vip-is-in-minibuffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
508 (vip-set-minibuffer-overlay))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
509 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
510
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
511 ;; This also takes care of the annoying incomplete lines in files.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
512 ;; Also, this fixes `undo' to work vi-style for complex commands.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
513 (defun vip-change-state-to-vi ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
514 "Change Viper state to Vi."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
515 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
516 (if (and vip-first-time (not (vip-is-in-minibuffer)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
517 (viper-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
518 (if overwrite-mode (overwrite-mode nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
519 (if abbrev-mode (expand-abbrev))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
520 (if (and auto-fill-function (> (current-column) fill-column))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
521 (funcall auto-fill-function))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
522 ;; don't leave whitespace lines around
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
523 (if (and (memq last-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
524 '(vip-autoindent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
525 vip-open-line vip-Open-line
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
526 vip-replace-state-exit-cmd))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
527 (vip-over-whitespace-line))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
528 (indent-to-left-margin))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
529 (vip-add-newline-at-eob-if-necessary)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
530 (if vip-undo-needs-adjustment (vip-adjust-undo))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
531 (vip-change-state 'vi-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
532
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
533 ;; always turn off iso-accents-mode, or else we won't be able to use the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
534 ;; keys `,',^ in Vi state, as they will do accents instead of Vi actions.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
535 (if (and (boundp 'iso-accents-mode) iso-accents-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
536 (iso-accents-mode -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
537
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
538 (vip-restore-cursor-color-after-insert)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
539
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
540 ;; Protection against user errors in hooks
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
541 (condition-case conds
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
542 (run-hooks 'vip-vi-state-hook)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
543 (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
544 (vip-message-conditions conds)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
545
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
546 (defun vip-change-state-to-insert ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
547 "Change Viper state to Insert."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
548 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
549 (vip-change-state 'insert-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
550 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
551 (iso-accents-mode 1)) ; turn iso accents on
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
552
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
553 (or (stringp vip-saved-cursor-color)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
554 (string= (vip-get-cursor-color) vip-insert-state-cursor-color)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
555 (setq vip-saved-cursor-color (vip-get-cursor-color)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
556 ;; Commented out, because if vip-change-state-to-insert is executed
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
557 ;; non-interactively then the old cursor color may get lost. Same old Emacs
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
558 ;; bug related to local variables?
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
559 ;;;(if (stringp vip-saved-cursor-color)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
560 ;;; (vip-change-cursor-color vip-insert-state-cursor-color))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
561 ;; Protection against user errors in hooks
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
562 (condition-case conds
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
563 (run-hooks 'vip-insert-state-hook)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
564 (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
565 (vip-message-conditions conds))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
566
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
567 (defsubst vip-downgrade-to-insert ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
568 (setq vip-current-state 'insert-state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
569 vip-replace-minor-mode nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
570 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
571
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
572
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
573
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
574 ;; Change to replace state. When the end of replacement region is reached,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
575 ;; replace state changes to insert state.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
576 (defun vip-change-state-to-replace (&optional non-R-cmd)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
577 (vip-change-state 'replace-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
578 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
579 (iso-accents-mode 1)) ; turn iso accents on
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
580 ;; Run insert-state-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
581 (condition-case conds
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
582 (run-hooks 'vip-insert-state-hook 'vip-replace-state-hook)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
583 (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
584 (vip-message-conditions conds)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
585
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
586 (if non-R-cmd
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
587 (vip-start-replace)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
588 ;; 'R' is implemented using Emacs's overwrite-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
589 (vip-start-R-mode))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
590 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
591
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
592
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
593 (defun vip-change-state-to-emacs ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
594 "Change Viper state to Emacs."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
595 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
596 (vip-change-state 'emacs-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
597 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
598 (iso-accents-mode 1)) ; turn iso accents on
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
599
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
600 ;; Protection agains user errors in hooks
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
601 (condition-case conds
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
602 (run-hooks 'vip-emacs-state-hook)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
603 (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
604 (vip-message-conditions conds))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
605
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
606 ;; escape to emacs mode termporarily
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
607 (defun vip-escape-to-emacs (arg &optional events)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
608 "Escape to Emacs state from Vi state for one Emacs command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
609 ARG is used as the prefix value for the executed command. If
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
610 EVENTS is a list of events, which become the beginning of the command."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
611 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
612 (if (= last-command-char ?\\)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
613 (message "Switched to EMACS state for the next command..."))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
614 (vip-escape-to-state arg events 'emacs-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
615
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
616 ;; escape to Vi mode termporarily
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
617 (defun vip-escape-to-vi (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
618 "Escape from Emacs state to Vi state for one Vi 1-character command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
619 If the Vi command that the user types has a prefix argument, e.g., `d2w', then
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
620 Vi's prefix argument will be used. Otherwise, the prefix argument passed to
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
621 `vip-escape-to-vi' is used."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
622 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
623 (message "Switched to VI state for the next command...")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
624 (vip-escape-to-state arg nil 'vi-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
625
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
626 ;; Escape to STATE mode for one Emacs command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
627 (defun vip-escape-to-state (arg events state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
628 ;;(let (com key prefix-arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
629 (let (com key)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
630 ;; this temporarily turns off Viper's minor mode keymaps
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
631 (vip-set-mode-vars-for state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
632 (vip-normalize-minor-mode-map-alist)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
633 (if events (vip-set-unread-command-events events))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
634
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
635 ;; protect against keyboard quit and other errors
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
636 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
637 (let (vip-vi-kbd-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
638 vip-insert-kbd-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
639 vip-emacs-kbd-minor-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
640 (unwind-protect
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
641 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
642 (setq com (key-binding (setq key
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
643 (if vip-xemacs-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
644 (read-key-sequence nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
645 (read-key-sequence nil t)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
646 ;; In case of binding indirection--chase definitions.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
647 ;; Have to do it here because we execute this command under
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
648 ;; different keymaps, so command-execute may not do the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
649 ;; right thing there
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
650 (while (vectorp com) (setq com (key-binding com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
651 nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
652 ;; Execute command com in the original Viper state, not in state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
653 ;; `state'. Otherwise, if we switch buffers while executing the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
654 ;; escaped to command, Viper's mode vars will remain those of
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
655 ;; `state'. When we return to the orig buffer, the bindings will be
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
656 ;; screwed up.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
657 (vip-set-mode-vars-for vip-current-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
658
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
659 ;; this-command, last-command-char, last-command-event
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
660 (setq this-command com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
661 (if vip-xemacs-p ; XEmacs represents key sequences as vectors
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
662 (setq last-command-event (vip-copy-event (vip-seq-last-elt key))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
663 last-command-char (event-to-character last-command-event))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
664 ;; Emacs represents them as sequences (str or vec)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
665 (setq last-command-event (vip-copy-event (vip-seq-last-elt key))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
666 last-command-char last-command-event))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
667
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
668 (if (commandp com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
669 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
670 (setq prefix-arg (or prefix-arg arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
671 (command-execute com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
672 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
673 (quit (ding))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
674 (error (beep 1))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
675 ;; set state in the new buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
676 (vip-set-mode-vars-for vip-current-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
677
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
678 (defun vip-exec-form-in-vi (form)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
679 "Execute FORM in Vi state, regardless of the Ccurrent Vi state."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
680 (let ((buff (current-buffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
681 result)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
682 (vip-set-mode-vars-for 'vi-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
683
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
684 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
685 (setq result (eval form))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
686 (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
687 (signal 'quit nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
688
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
689 (if (not (equal buff (current-buffer))) ; cmd switched buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
690 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
691 (set-buffer buff)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
692 (vip-set-mode-vars-for vip-current-state)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
693 (vip-set-mode-vars-for vip-current-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
694 result))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
695
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
696 (defun vip-exec-form-in-emacs (form)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
697 "Execute FORM in Emacs, temporarily disabling Viper's minor modes.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
698 Similar to vip-escape-to-emacs, but accepts forms rather than keystrokes."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
699 (let ((buff (current-buffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
700 result)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
701 (vip-set-mode-vars-for 'emacs-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
702 (setq result (eval form))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
703 (if (not (equal buff (current-buffer))) ; cmd switched buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
704 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
705 (set-buffer buff)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
706 (vip-set-mode-vars-for vip-current-state)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
707 (vip-set-mode-vars-for vip-current-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
708 result))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
709
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
710
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
711 ;; This is needed because minor modes sometimes override essential Viper
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
712 ;; bindings. By letting Viper know which files these modes are in, it will
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
713 ;; arrange to reorganize minor-mode-map-alist so that things will work right.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
714 (defun vip-harness-minor-mode (load-file)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
715 "Familiarize Viper with a minor mode defined in LOAD_FILE.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
716 Minor modes that have their own keymaps may overshadow Viper keymaps.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
717 This function is designed to make Viper aware of the packages that define
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
718 such minor modes.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
719 Usage:
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
720 (vip-harness-minor-mode load-file)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
721
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
722 LOAD-FILE is a name of the file where the specific minor mode is defined.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
723 Suffixes such as .el or .elc should be stripped."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
724
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
725 (interactive "sEnter name of the load file: ")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
726
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
727 (vip-eval-after-load load-file '(vip-normalize-minor-mode-map-alist))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
728
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
729 ;; Change the default for minor-mode-map-alist each time a harnessed minor
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
730 ;; mode adds its own keymap to the a-list.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
731 (vip-eval-after-load
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
732 load-file '(setq-default minor-mode-map-alist minor-mode-map-alist))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
733 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
734
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
735
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
736 (defun vip-ESC (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
737 "Emulate ESC key in Emacs.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
738 Prevents multiple escape keystrokes if vip-no-multiple-ESC is true.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
739 If vip-no-multiple-ESC is 'twice double ESC would ding in vi-state.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
740 Other ESC sequences are emulated via the current Emacs's major mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
741 keymap. This is more convenient on TTYs, since this won't block
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
742 function keys such as up,down, etc. ESC will also will also work as
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
743 a Meta key in this case. When vip-no-multiple-ESC is nil, ESC functions
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
744 as a Meta key and any number of multiple escapes is allowed."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
745 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
746 (let (char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
747 (cond ((and (not vip-no-multiple-ESC) (eq vip-current-state 'vi-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
748 (setq char (vip-read-char-exclusive))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
749 (vip-escape-to-emacs arg (list ?\e char) ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
750 ((and (eq vip-no-multiple-ESC 'twice)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
751 (eq vip-current-state 'vi-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
752 (setq char (vip-read-char-exclusive))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
753 (if (= char (string-to-char vip-ESC-key))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
754 (ding)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
755 (vip-escape-to-emacs arg (list ?\e char) )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
756 (t (ding)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
757 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
758
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
759 (defun vip-alternate-Meta-key (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
760 "Simulate Emacs Meta key."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
761 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
762 (sit-for 1) (message "ESC-")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
763 (vip-escape-to-emacs arg '(?\e)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
764
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
765 (defun vip-toggle-key-action ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
766 "Action bound to `vip-toggle-key'."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
767 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
768 (if (and (< vip-expert-level 2) (equal vip-toggle-key "\C-z"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
769 (if (vip-window-display-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
770 (vip-iconify)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
771 (suspend-emacs))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
772 (vip-change-state-to-emacs)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
773
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
774
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
775 ;; Intercept ESC sequences on dumb terminals.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
776 ;; Based on the idea contributed by Marcelino Veiga Tuimil <mveiga@dit.upm.es>
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
777
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
778 ;; Check if last key was ESC and if so try to reread it as a function key.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
779 ;; But only if there are characters to read during a very short time.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
780 ;; Returns the last event, if any.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
781 (defun vip-envelop-ESC-key ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
782 (let ((event last-input-event)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
783 (keyseq [nil])
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
784 inhibit-quit)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
785 (if (vip-ESC-event-p event)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
786 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
787 (if (vip-fast-keysequence-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
788 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
789 (let (minor-mode-map-alist)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
790 (vip-set-unread-command-events event)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
791 (setq keyseq
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
792 (funcall
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
793 (ad-get-orig-definition 'read-key-sequence) nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
794 ) ; let
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
795 ;; If keyseq translates into something that still has ESC
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
796 ;; at the beginning, separate ESC from the rest of the seq.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
797 ;; In XEmacs we check for events that are keypress meta-key
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
798 ;; and convert them into [escape key]
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
799 ;;
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
800 ;; This is needed for the following reason:
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
801 ;; If ESC is the first symbol, we interpret it as if the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
802 ;; user typed ESC and then quickly some other symbols.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
803 ;; If ESC is not the first one, then the key sequence
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
804 ;; entered was apparently translated into a function key or
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
805 ;; something (e.g., one may have
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
806 ;; (define-key function-key-map "\e[192z" [f11])
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
807 ;; which would translate the escape-sequence generated by
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
808 ;; f11 in an xterm window into the symbolic key f11.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
809 ;;
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
810 ;; If `first-key' is not an ESC event, we make it into the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
811 ;; last-command-event in order to pretend that this key was
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
812 ;; pressed. This is needed to allow arrow keys to be bound to
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
813 ;; macros. Otherwise, vip-exec-mapped-kbd-macro will think that
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
814 ;; the last event was ESC and so it'll execute whatever is
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
815 ;; bound to ESC. (Viper macros can't be bound to
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
816 ;; ESC-sequences).
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
817 (let* ((first-key (elt keyseq 0))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
818 (key-mod (event-modifiers first-key)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
819 (cond ((vip-ESC-event-p first-key)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
820 ;; put keys following ESC on the unread list
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
821 ;; and return ESC as the key-sequence
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
822 (vip-set-unread-command-events (subseq keyseq 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
823 (setq last-input-event event
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
824 keyseq (if vip-emacs-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
825 "\e"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
826 (vector (character-to-event ?\e)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
827 ((and vip-xemacs-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
828 (key-press-event-p first-key)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
829 (equal '(meta) key-mod))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
830 (vip-set-unread-command-events
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
831 (vconcat (vector
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
832 (character-to-event (event-key first-key)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
833 (subseq keyseq 1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
834 (setq last-input-event event
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
835 keyseq (vector (character-to-event ?\e))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
836 ((eventp first-key)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
837 (setq last-command-event (vip-copy-event first-key)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
838 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
839 ) ; end progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
840
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
841 ;; this is escape event with nothing after it
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
842 ;; put in unread-command-event and then re-read
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
843 (vip-set-unread-command-events event)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
844 (setq keyseq
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
845 (funcall (ad-get-orig-definition 'read-key-sequence) nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
846 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
847 ;; not an escape event
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
848 (setq keyseq (vector event)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
849 keyseq))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
850
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
851
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
852
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
853 ;; Listen to ESC key.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
854 ;; If a sequence of keys starting with ESC is issued with very short delays,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
855 ;; interpret these keys in Emacs mode, so ESC won't be interpreted as a Vi key.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
856 (defun vip-intercept-ESC-key ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
857 "Function that implements ESC key in Viper emulation of Vi."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
858 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
859 (let ((cmd (or (key-binding (vip-envelop-ESC-key))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
860 '(lambda () (interactive) (error "")))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
861
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
862 ;; call the actual function to execute ESC (if no other symbols followed)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
863 ;; or the key bound to the ESC sequence (if the sequence was issued
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
864 ;; with very short delay between characters.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
865 (if (eq cmd 'vip-intercept-ESC-key)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
866 (setq cmd
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
867 (cond ((eq vip-current-state 'vi-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
868 'vip-ESC)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
869 ((eq vip-current-state 'insert-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
870 'vip-exit-insert-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
871 ((eq vip-current-state 'replace-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
872 'vip-replace-state-exit-cmd)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
873 (t 'vip-change-state-to-vi)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
874 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
875 (call-interactively cmd)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
876
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
877
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
878
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
879
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
880 ;; prefix argument for Vi mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
881
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
882 ;; In Vi mode, prefix argument is a dotted pair (NUM . COM) where NUM
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
883 ;; represents the numeric value of the prefix argument and COM represents
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
884 ;; command prefix such as "c", "d", "m" and "y".
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
885
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
886 ;; Get value part of prefix-argument ARG.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
887 (defsubst vip-p-val (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
888 (cond ((null arg) 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
889 ((consp arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
890 (if (or (null (car arg)) (equal (car arg) '(nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
891 1 (car arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
892 (t arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
893
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
894 ;; Get raw value part of prefix-argument ARG.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
895 (defsubst vip-P-val (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
896 (cond ((consp arg) (car arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
897 (t arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
898
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
899 ;; Get com part of prefix-argument ARG.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
900 (defsubst vip-getcom (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
901 (cond ((null arg) nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
902 ((consp arg) (cdr arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
903 (t nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
904
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
905 ;; Get com part of prefix-argument ARG and modify it.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
906 (defun vip-getCom (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
907 (let ((com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
908 (cond ((equal com ?c) ?C)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
909 ((equal com ?d) ?D)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
910 ((equal com ?y) ?Y)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
911 (t com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
912
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
913
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
914 ;; Compute numeric prefix arg value.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
915 ;; Invoked by EVENT. COM is the command part obtained so far.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
916 (defun vip-prefix-arg-value (event com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
917 (let (value func)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
918 ;; read while number
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
919 (while (and (vip-characterp event) (>= event ?0) (<= event ?9))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
920 (setq value (+ (* (if (integerp value) value 0) 10) (- event ?0)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
921 (setq event (vip-read-event-convert-to-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
922
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
923 (setq prefix-arg value)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
924 (if com (setq prefix-arg (cons prefix-arg com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
925 (while (eq event ?U)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
926 (vip-describe-arg prefix-arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
927 (setq event (vip-read-event-convert-to-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
928
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
929 (if (or com (and (not (eq vip-current-state 'vi-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
930 ;; make sure it is a Vi command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
931 (vip-characterp event) (vip-vi-command-p event)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
932 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
933 ;; If appears to be one of the vi commands,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
934 ;; then execute it with funcall and clear prefix-arg in order to not
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
935 ;; confuse subsequent commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
936 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
937 ;; last-command-char is the char we want emacs to think was typed
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
938 ;; last. If com is not nil, the vip-digit-argument command was called
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
939 ;; from within vip-prefix-arg command, such as `d', `w', etc., i.e.,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
940 ;; the user typed, say, d2. In this case, `com' would be `d', `w',
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
941 ;; etc.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
942 ;; If vip-digit-argument was invoked by vip-escape-to-vi (which is
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
943 ;; indicated by the fact that the current state is not vi-state),
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
944 ;; then `event' represents the vi command to be executed (e.g., `d',
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
945 ;; `w', etc). Again, last-command-char must make emacs believe that
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
946 ;; this is the command we typed.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
947 (setq last-command-char (or com event))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
948 (setq func (vip-exec-form-in-vi
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
949 (` (key-binding (char-to-string (, event))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
950 (funcall func prefix-arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
951 (setq prefix-arg nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
952 ;; some other command -- let emacs do it in its own way
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
953 (vip-set-unread-command-events event))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
954 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
955
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
956
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
957 ;; Vi operator as prefix argument."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
958 (defun vip-prefix-arg-com (char value com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
959 (let ((cont t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
960 cmd-info mv-or-digit-cmd)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
961 (while (and cont
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
962 (memq char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
963 (list ?c ?d ?y ?! ?< ?> ?= ?# ?r ?R ?\"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
964 vip-buffer-search-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
965 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
966 ;; this means that we already have a command character, so we
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
967 ;; construct a com list and exit while. however, if char is "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
968 ;; it is an error.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
969 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
970 ;; new com is (CHAR . OLDCOM)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
971 (if (memq char '(?# ?\")) (error ""))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
972 (setq com (cons char com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
973 (setq cont nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
974 ;; If com is nil we set com as char, and read more. Again, if char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
975 ;; is ", we read the name of register and store it in vip-use-register.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
976 ;; if char is !, =, or #, a complete com is formed so we exit the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
977 ;; while loop.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
978 (cond ((memq char '(?! ?=))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
979 (setq com char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
980 (setq char (read-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
981 (setq cont nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
982 ((= char ?#)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
983 ;; read a char and encode it as com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
984 (setq com (+ 128 (read-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
985 (setq char (read-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
986 ((= char ?\")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
987 (let ((reg (read-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
988 (if (vip-valid-register reg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
989 (setq vip-use-register reg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
990 (error ""))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
991 (setq char (read-char))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
992 (t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
993 (setq com char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
994 (setq char (read-char))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
995
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
996 (if (atom com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
997 ;; `com' is a single char, so we construct the command argument
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
998 ;; and if `char' is `?', we describe the arg; otherwise
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
999 ;; we prepare the command that will be executed at the end.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1000 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1001 (setq cmd-info (cons value com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1002 (while (= char ?U)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1003 (vip-describe-arg cmd-info)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1004 (setq char (read-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1005 ;; `char' is a movement cmd, a digit arg cmd, or a register cmd---so we
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1006 ;; execute it at the very end
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1007 (or (vip-movement-command-p char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1008 (vip-digit-command-p char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1009 (vip-regsuffix-command-p char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1010 (error ""))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1011 (setq mv-or-digit-cmd
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1012 (vip-exec-form-in-vi
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1013 (` (key-binding (char-to-string (, char)))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1014
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1015 ;; as com is non-nil, this means that we have a command to execute
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1016 (if (memq (car com) '(?r ?R))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1017 ;; execute apropriate region command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1018 (let ((char (car com)) (com (cdr com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1019 (setq prefix-arg (cons value com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1020 (if (= char ?r) (vip-region prefix-arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1021 (vip-Region prefix-arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1022 ;; reset prefix-arg
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1023 (setq prefix-arg nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1024 ;; otherwise, reset prefix arg and call appropriate command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1025 (setq value (if (null value) 1 value))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1026 (setq prefix-arg nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1027 (cond ((equal com '(?c . ?c)) (vip-line (cons value ?C)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1028 ((equal com '(?d . ?d)) (vip-line (cons value ?D)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1029 ((equal com '(?d . ?y)) (vip-yank-defun))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1030 ((equal com '(?y . ?y)) (vip-line (cons value ?Y)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1031 ((equal com '(?< . ?<)) (vip-line (cons value ?<)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1032 ((equal com '(?> . ?>)) (vip-line (cons value ?>)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1033 ((equal com '(?! . ?!)) (vip-line (cons value ?!)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1034 ((equal com '(?= . ?=)) (vip-line (cons value ?=)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1035 (t (error "")))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1036
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1037 (if mv-or-digit-cmd
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1038 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1039 (setq last-command-char char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1040 (setq last-command-event
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1041 (vip-copy-event
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1042 (if vip-xemacs-p (character-to-event char) char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1043 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1044 (funcall mv-or-digit-cmd cmd-info)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1045 (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1046 (error "")))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1047 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1048
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1049 (defun vip-describe-arg (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1050 (let (val com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1051 (setq val (vip-P-val arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1052 com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1053 (if (null val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1054 (if (null com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1055 (message "Value is nil, and command is nil")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1056 (message "Value is nil, and command is `%c'" com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1057 (if (null com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1058 (message "Value is `%d', and command is nil" val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1059 (message "Value is `%d', and command is `%c'" val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1060
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1061 (defun vip-digit-argument (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1062 "Begin numeric argument for the next command."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1063 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1064 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1065 (vip-prefix-arg-value
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1066 last-command-char (if (consp arg) (cdr arg) nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1067
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1068 (defun vip-command-argument (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1069 "Accept a motion command as an argument."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1070 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1071 (let ((vip-inside-command-argument-action t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1072 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1073 (vip-prefix-arg-com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1074 last-command-char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1075 (cond ((null arg) nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1076 ((consp arg) (car arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1077 ((integerp arg) arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1078 (t (error vip-InvalidCommandArgument)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1079 (cond ((null arg) nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1080 ((consp arg) (cdr arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1081 ((integerp arg) nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1082 (t (error vip-InvalidCommandArgument))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1083 (quit (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1084 (signal 'quit nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1085 (vip-deactivate-mark)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1086
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1087
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1088 ;; repeat last destructive command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1089
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1090 ;; Append region to text in register REG.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1091 ;; START and END are buffer positions indicating what to append.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1092 (defsubst vip-append-to-register (reg start end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1093 (set-register reg (concat (if (stringp (get-register reg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1094 (get-register reg) "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1095 (buffer-substring start end))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1096
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1097 ;; Saves last inserted text for possible use by vip-repeat command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1098 (defun vip-save-last-insertion (beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1099 (setq vip-last-insertion (buffer-substring beg end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1100 (or (< (length vip-d-com) 5)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1101 (setcar (nthcdr 4 vip-d-com) vip-last-insertion))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1102 (or (null vip-command-ring)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1103 (ring-empty-p vip-command-ring)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1104 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1105 (setcar (nthcdr 4 (vip-current-ring-item vip-command-ring))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1106 vip-last-insertion)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1107 ;; del most recent elt, if identical to the second most-recent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1108 (vip-cleanup-ring vip-command-ring)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1109 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1110
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1111 (defsubst vip-yank-last-insertion ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1112 "Inserts the text saved by the previous vip-save-last-insertion command."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1113 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1114 (insert vip-last-insertion)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1115 (error nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1116
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1117
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1118 ;; define functions to be executed
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1119
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1120 ;; invoked by the `C' command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1121 (defun vip-exec-change (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1122 (or (and (markerp vip-com-point) (marker-position vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1123 (set-marker vip-com-point (point) (current-buffer)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1124 ;; handle C cmd at the eol and at eob.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1125 (if (or (and (eolp) (= vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1126 (= vip-com-point (point-max)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1127 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1128 (insert " ")(backward-char 1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1129 (if (= vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1130 (vip-forward-char-carefully))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1131 (if (= com ?c)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1132 (vip-change vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1133 (vip-change-subr vip-com-point (point))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1134
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1135 ;; this is invoked by vip-substitute-line
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1136 (defun vip-exec-Change (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1137 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1138 (set-mark vip-com-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1139 (vip-enlarge-region (mark t) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1140 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1141 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1142 (cond ((vip-valid-register vip-use-register '(letter digit))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1143 ;;(vip-valid-register vip-use-register '(letter)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1144 (copy-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1145 vip-use-register (mark t) (point) nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1146 ((vip-valid-register vip-use-register '(Letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1147 (vip-append-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1148 (downcase vip-use-register) (mark t) (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1149 (t (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1150 (error vip-InvalidRegister vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1151 (setq vip-use-register nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1152 (delete-region (mark t) (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1153 (open-line 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1154 (if (= com ?C) (vip-change-mode-to-insert) (vip-yank-last-insertion)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1155
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1156 (defun vip-exec-delete (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1157 (or (and (markerp vip-com-point) (marker-position vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1158 (set-marker vip-com-point (point) (current-buffer)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1159 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1160 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1161 (cond ((vip-valid-register vip-use-register '(letter digit))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1162 ;;(vip-valid-register vip-use-register '(letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1163 (copy-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1164 vip-use-register vip-com-point (point) nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1165 ((vip-valid-register vip-use-register '(Letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1166 (vip-append-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1167 (downcase vip-use-register) vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1168 (t (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1169 (error vip-InvalidRegister vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1170 (setq vip-use-register nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1171 (setq last-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1172 (if (eq last-command 'd-command) 'kill-region nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1173 (kill-region vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1174 (setq this-command 'd-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1175 (if vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1176 (if (and (eolp) (not (bolp))) (backward-char 1))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1177
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1178 (defun vip-exec-Delete (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1179 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1180 (set-mark vip-com-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1181 (vip-enlarge-region (mark t) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1182 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1183 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1184 (cond ((vip-valid-register vip-use-register '(letter digit))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1185 ;;(vip-valid-register vip-use-register '(letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1186 (copy-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1187 vip-use-register (mark t) (point) nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1188 ((vip-valid-register vip-use-register '(Letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1189 (vip-append-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1190 (downcase vip-use-register) (mark t) (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1191 (t (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1192 (error vip-InvalidRegister vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1193 (setq vip-use-register nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1194 (setq last-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1195 (if (eq last-command 'D-command) 'kill-region nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1196 (kill-region (mark t) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1197 (if (eq m-com 'vip-line) (setq this-command 'D-command)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1198 (back-to-indentation))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1199
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1200 (defun vip-exec-yank (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1201 (or (and (markerp vip-com-point) (marker-position vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1202 (set-marker vip-com-point (point) (current-buffer)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1203 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1204 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1205 (cond ((vip-valid-register vip-use-register '(letter digit))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1206 ;; (vip-valid-register vip-use-register '(letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1207 (copy-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1208 vip-use-register vip-com-point (point) nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1209 ((vip-valid-register vip-use-register '(Letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1210 (vip-append-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1211 (downcase vip-use-register) vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1212 (t (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1213 (error vip-InvalidRegister vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1214 (setq vip-use-register nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1215 (setq last-command nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1216 (copy-region-as-kill vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1217 (goto-char vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1218
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1219 (defun vip-exec-Yank (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1220 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1221 (set-mark vip-com-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1222 (vip-enlarge-region (mark t) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1223 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1224 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1225 (cond ((vip-valid-register vip-use-register '(letter digit))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1226 (copy-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1227 vip-use-register (mark t) (point) nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1228 ((vip-valid-register vip-use-register '(Letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1229 (vip-append-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1230 (downcase vip-use-register) (mark t) (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1231 (t (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1232 (error vip-InvalidRegister vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1233 (setq vip-use-register nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1234 (setq last-command nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1235 (copy-region-as-kill (mark t) (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1236 (vip-deactivate-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1237 (goto-char vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1238
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1239 (defun vip-exec-bang (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1240 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1241 (set-mark vip-com-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1242 (vip-enlarge-region (mark t) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1243 (shell-command-on-region
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1244 (mark t) (point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1245 (if (= com ?!)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1246 (setq vip-last-shell-com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1247 (vip-read-string-with-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1248 "!"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1249 nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1250 'vip-shell-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1251 (car vip-shell-history)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1252 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1253 vip-last-shell-com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1254 t)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1255
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1256 (defun vip-exec-equals (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1257 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1258 (set-mark vip-com-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1259 (vip-enlarge-region (mark t) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1260 (if (> (mark t) (point)) (exchange-point-and-mark))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1261 (indent-region (mark t) (point) nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1262
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1263 (defun vip-exec-shift (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1264 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1265 (set-mark vip-com-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1266 (vip-enlarge-region (mark t) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1267 (if (> (mark t) (point)) (exchange-point-and-mark))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1268 (indent-rigidly (mark t) (point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1269 (if (= com ?>)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1270 vip-shift-width
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1271 (- vip-shift-width))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1272 ;; return point to where it was before shift
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1273 (goto-char vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1274
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1275 ;; this is needed because some commands fake com by setting it to ?r, which
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1276 ;; denotes repeated insert command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1277 (defsubst vip-exec-dummy (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1278 nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1279
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1280 (defun vip-exec-buffer-search (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1281 (setq vip-s-string (buffer-substring (point) vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1282 (setq vip-s-forward t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1283 (setq vip-search-history (cons vip-s-string vip-search-history))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1284 (vip-search vip-s-string vip-s-forward 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1285
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1286 (defvar vip-exec-array (make-vector 128 nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1287
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1288 ;; Using a dispatch array allows adding functions like buffer search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1289 ;; without affecting other functions. Buffer search can now be bound
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1290 ;; to any character.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1291
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1292 (aset vip-exec-array ?c 'vip-exec-change)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1293 (aset vip-exec-array ?C 'vip-exec-Change)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1294 (aset vip-exec-array ?d 'vip-exec-delete)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1295 (aset vip-exec-array ?D 'vip-exec-Delete)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1296 (aset vip-exec-array ?y 'vip-exec-yank)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1297 (aset vip-exec-array ?Y 'vip-exec-Yank)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1298 (aset vip-exec-array ?r 'vip-exec-dummy)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1299 (aset vip-exec-array ?! 'vip-exec-bang)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1300 (aset vip-exec-array ?< 'vip-exec-shift)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1301 (aset vip-exec-array ?> 'vip-exec-shift)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1302 (aset vip-exec-array ?= 'vip-exec-equals)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1303
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1304
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1305
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1306 ;; This function is called by various movement commands to execute a
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1307 ;; destructive command on the region specified by the movement command. For
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1308 ;; instance, if the user types cw, then the command vip-forward-word will
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1309 ;; call vip-execute-com to execute vip-exec-change, which eventually will
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1310 ;; call vip-change to invoke the replace mode on the region.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1311 ;;
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1312 ;; The list (M-COM VAL COM REG INSETED-TEXT COMMAND-KEYS) is set to
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1313 ;; vip-d-com for later use by vip-repeat.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1314 (defun vip-execute-com (m-com val com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1315 (let ((reg vip-use-register))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1316 ;; this is the special command `#'
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1317 (if (> com 128)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1318 (vip-special-prefix-com (- com 128))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1319 (let ((fn (aref vip-exec-array (if (< com 0) (- com) com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1320 (if (null fn)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1321 (error "%c: %s" com vip-InvalidViCommand)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1322 (funcall fn m-com com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1323 (if (vip-dotable-command-p com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1324 (vip-set-destructive-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1325 (list m-com val
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1326 (if (memq com (list ?c ?C ?!)) (- com) com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1327 reg nil nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1328 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1329
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1330
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1331 (defun vip-repeat (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1332 "Re-execute last destructive command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1333 Use the info in vip-d-com, which has the form
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1334 \(com val ch reg inserted-text command-keys\),
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1335 where `com' is the command to be re-executed, `val' is the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1336 argument to `com', `ch' is a flag for repeat, and `reg' is optional;
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1337 if it exists, it is the name of the register for `com'.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1338 If the prefix argument, ARG, is non-nil, it is used instead of `val'."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1339 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1340 (let ((save-point (point)) ; save point before repeating prev cmd
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1341 ;; Pass along that we are repeating a destructive command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1342 ;; This tells vip-set-destructive-command not to update
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1343 ;; vip-command-ring
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1344 (vip-intermediate-command 'vip-repeat))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1345 (if (eq last-command 'vip-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1346 ;; if the last command was vip-undo, then undo-more
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1347 (vip-undo-more)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1348 ;; otherwise execute the command stored in vip-d-com. if arg is non-nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1349 ;; its prefix value is used as new prefix value for the command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1350 (let ((m-com (car vip-d-com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1351 (val (vip-P-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1352 (com (nth 2 vip-d-com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1353 (reg (nth 3 vip-d-com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1354 (if (null val) (setq val (nth 1 vip-d-com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1355 (if (null m-com) (error "No previous command to repeat."))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1356 (setq vip-use-register reg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1357 (if (nth 4 vip-d-com) ; text inserted by command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1358 (setq vip-last-insertion (nth 4 vip-d-com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1359 vip-d-char (nth 4 vip-d-com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1360 (funcall m-com (cons val com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1361 (if (and vip-keep-point-on-repeat (< save-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1362 (goto-char save-point)) ; go back to before repeat.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1363 (if (and (eolp) (not (bolp)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1364 (backward-char 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1365 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1366 (if vip-undo-needs-adjustment (vip-adjust-undo)) ; take care of undo
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1367 ;; If the prev cmd was rotating the command ring, this means that `.' has
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1368 ;; just executed a command from that ring. So, push it on the ring again.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1369 ;; If we are just executing previous command , then don't push vip-d-com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1370 ;; because vip-d-com is not fully constructed in this case (its keys and
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1371 ;; the inserted text may be nil). Besides, in this case, the command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1372 ;; executed by `.' is already on the ring.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1373 (if (eq last-command 'vip-display-current-destructive-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1374 (vip-push-onto-ring vip-d-com 'vip-command-ring))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1375 (vip-deactivate-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1376 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1377
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1378 (defun vip-repeat-from-history ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1379 "Repeat a destructive command from history.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1380 Doesn't change vip-command-ring in any way, so `.' will work as before
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1381 executing this command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1382 This command is supposed to be bound to a two-character Vi macro where
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1383 the second character is a digit 0 to 9. The digit indicates which
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1384 history command to execute. `<char>0' is equivalent to `.', `<char>1'
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1385 invokes the command before that, etc."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1386 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1387 (let* ((vip-intermediate-command 'repeating-display-destructive-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1388 (idx (cond (vip-this-kbd-macro
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1389 (string-to-number
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1390 (symbol-name (elt vip-this-kbd-macro 1))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1391 (t 0)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1392 (num idx)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1393 (vip-d-com vip-d-com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1394
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1395 (or (and (numberp num) (<= 0 num) (<= num 9))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1396 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1397 (setq idx 0
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1398 num 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1399 (message
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1400 "`vip-repeat-from-history' must be invoked as a Vi macro bound to `<key><digit>'")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1401 (while (< 0 num)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1402 (setq vip-d-com (vip-special-ring-rotate1 vip-command-ring -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1403 (setq num (1- num)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1404 (vip-repeat nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1405 (while (> idx num)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1406 (vip-special-ring-rotate1 vip-command-ring 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1407 (setq num (1+ num)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1408 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1409
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1410
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1411 ;; The hash-command. It is invoked interactively by the key sequence #<char>.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1412 ;; The chars that can follow `#' are determined by vip-hash-command-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1413 (defun vip-special-prefix-com (char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1414 (cond ((= char ?c)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1415 (downcase-region (min vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1416 (max vip-com-point (point))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1417 ((= char ?C)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1418 (upcase-region (min vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1419 (max vip-com-point (point))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1420 ((= char ?g)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1421 (push-mark vip-com-point t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1422 (vip-global-execute))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1423 ((= char ?q)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1424 (push-mark vip-com-point t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1425 (vip-quote-region))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1426 ((= char ?s) (funcall vip-spell-function vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1427 (t (error "#%c: %s" char vip-InvalidViCommand))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1428
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1429
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1430 ;; undoing
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1431
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1432 (defun vip-undo ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1433 "Undo previous change."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1434 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1435 (message "undo!")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1436 (let ((modified (buffer-modified-p))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1437 (before-undo-pt (point-marker))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1438 (after-change-functions after-change-functions)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1439 undo-beg-posn undo-end-posn)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1440
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1441 ;; no need to remove this hook, since this var has scope inside a let.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1442 (add-hook 'after-change-functions
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1443 '(lambda (beg end len)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1444 (setq undo-beg-posn beg
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1445 undo-end-posn (or end beg))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1446
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1447 (undo-start)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1448 (undo-more 2)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1449 (setq undo-beg-posn (or undo-beg-posn before-undo-pt)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1450 undo-end-posn (or undo-end-posn undo-beg-posn))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1451
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1452 (goto-char undo-beg-posn)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1453 (sit-for 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1454 (if (and vip-keep-point-on-undo
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1455 (pos-visible-in-window-p before-undo-pt))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1456 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1457 (push-mark (point-marker) t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1458 (vip-sit-for-short 300)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1459 (goto-char undo-end-posn)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1460 (vip-sit-for-short 300)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1461 (if (and (> (abs (- undo-beg-posn before-undo-pt)) 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1462 (> (abs (- undo-end-posn before-undo-pt)) 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1463 (goto-char before-undo-pt)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1464 (goto-char undo-beg-posn)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1465 (push-mark before-undo-pt t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1466 (if (and (eolp) (not (bolp))) (backward-char 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1467 (if (not modified) (set-buffer-modified-p t)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1468 (setq this-command 'vip-undo))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1469
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1470 ;; Continue undoing previous changes.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1471 (defun vip-undo-more ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1472 (message "undo more!")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1473 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1474 (undo-more 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1475 (error (beep)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1476 (message "No further undo information in this buffer")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1477 (if (and (eolp) (not (bolp))) (backward-char 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1478 (setq this-command 'vip-undo))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1479
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1480 ;; The following two functions are used to set up undo properly.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1481 ;; In VI, unlike Emacs, if you open a line, say, and add a bunch of lines,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1482 ;; they are undone all at once.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1483 (defun vip-adjust-undo ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1484 (let ((inhibit-quit t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1485 tmp tmp2)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1486 (setq vip-undo-needs-adjustment nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1487 (if (listp buffer-undo-list)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1488 (if (setq tmp (memq vip-buffer-undo-list-mark buffer-undo-list))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1489 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1490 (setq tmp2 (cdr tmp)) ; the part after mark
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1491
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1492 ;; cut tail from buffer-undo-list temporarily by direct
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1493 ;; manipulation with pointers in buffer-undo-list
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1494 (setcdr tmp nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1495
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1496 (setq buffer-undo-list (delq nil buffer-undo-list))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1497 (setq buffer-undo-list
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1498 (delq vip-buffer-undo-list-mark buffer-undo-list))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1499 ;; restore tail of buffer-undo-list
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1500 (setq buffer-undo-list (nconc buffer-undo-list tmp2)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1501 (setq buffer-undo-list (delq nil buffer-undo-list))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1502
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1503
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1504 (defun vip-set-complex-command-for-undo ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1505 (if (listp buffer-undo-list)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1506 (if (not vip-undo-needs-adjustment)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1507 (let ((inhibit-quit t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1508 (setq buffer-undo-list
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1509 (cons vip-buffer-undo-list-mark buffer-undo-list))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1510 (setq vip-undo-needs-adjustment t)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1511
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1512
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1513
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1514
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1515 (defun vip-display-current-destructive-command ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1516 (let ((text (nth 4 vip-d-com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1517 (keys (nth 5 vip-d-com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1518 (max-text-len 30))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1519
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1520 (setq this-command 'vip-display-current-destructive-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1521
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1522 (message " `.' runs %s%s"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1523 (concat "`" (vip-array-to-string keys) "'")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1524 (vip-abbreviate-string text max-text-len
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1525 " inserting `" "'" " ......."))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1526 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1527
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1528
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1529 ;; don't change vip-d-com if it was vip-repeat command invoked with `.'
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1530 ;; or in some other way (non-interactively).
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1531 (defun vip-set-destructive-command (list)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1532 (or (eq vip-intermediate-command 'vip-repeat)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1533 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1534 (setq vip-d-com list)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1535 (setcar (nthcdr 5 vip-d-com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1536 (vip-array-to-string (this-command-keys)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1537 (vip-push-onto-ring vip-d-com 'vip-command-ring))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1538
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1539 (defun vip-prev-destructive-command (next)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1540 "Find previous destructive command in the history of destructive commands.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1541 With prefix argument, find next destructive command."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1542 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1543 (let (cmd vip-intermediate-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1544 (if (eq last-command 'vip-display-current-destructive-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1545 ;; repeated search through command history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1546 (setq vip-intermediate-command 'repeating-display-destructive-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1547 ;; first search through command history--set temp ring
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1548 (setq vip-temp-command-ring (copy-list vip-command-ring)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1549 (setq cmd (if next
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1550 (vip-special-ring-rotate1 vip-temp-command-ring 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1551 (vip-special-ring-rotate1 vip-temp-command-ring -1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1552 (if (null cmd)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1553 ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1554 (setq vip-d-com cmd))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1555 (vip-display-current-destructive-command)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1556
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1557 (defun vip-next-destructive-command ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1558 "Find next destructive command in the history of destructive commands."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1559 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1560 (vip-prev-destructive-command 'next))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1561
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1562 (defun vip-insert-prev-from-insertion-ring (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1563 "Cycle through insertion ring in the direction of older insertions.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1564 Undoes previous insertion and inserts new.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1565 With prefix argument, cycles in the direction of newer elements.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1566 In minibuffer, this command executes whatever the invocation key is bound
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1567 to in the global map, instead of cycling through the insertion ring."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1568 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1569 (let (vip-intermediate-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1570 (if (eq last-command 'vip-insert-from-insertion-ring)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1571 (progn ; repeated search through insertion history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1572 (setq vip-intermediate-command 'repeating-insertion-from-ring)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1573 (if (eq vip-current-state 'replace-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1574 (undo 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1575 (if vip-last-inserted-string-from-insertion-ring
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1576 (backward-delete-char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1577 (length vip-last-inserted-string-from-insertion-ring))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1578 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1579 ;;first search through insertion history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1580 (setq vip-temp-insertion-ring (copy-list vip-insertion-ring)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1581 (setq this-command 'vip-insert-from-insertion-ring)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1582 ;; so that things will be undone properly
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1583 (setq buffer-undo-list (cons nil buffer-undo-list))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1584 (setq vip-last-inserted-string-from-insertion-ring
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1585 (vip-special-ring-rotate1 vip-temp-insertion-ring (if arg 1 -1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1586
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1587 ;; this change of vip-intermediate-command must come after
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1588 ;; vip-special-ring-rotate1, so that the ring will rotate, but before the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1589 ;; insertion.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1590 (setq vip-intermediate-command nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1591 (if vip-last-inserted-string-from-insertion-ring
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1592 (insert vip-last-inserted-string-from-insertion-ring))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1593 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1594
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1595 (defun vip-insert-next-from-insertion-ring ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1596 "Cycle through insertion ring in the direction of older insertions.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1597 Undo previous insertion and inserts new."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1598 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1599 (vip-insert-prev-from-insertion-ring 'next))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1600
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1601
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1602 ;; some region utilities
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1603
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1604 ;; If at the last line of buffer, add \\n before eob, if newline is missing.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1605 (defun vip-add-newline-at-eob-if-necessary ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1606 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1607 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1608 ;; make sure all lines end with newline, unless in the minibuffer or
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1609 ;; when requested otherwise (require-final-newline is nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1610 (if (and (eobp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1611 (not (bolp))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1612 require-final-newline
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1613 (not (vip-is-in-minibuffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1614 (not buffer-read-only))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1615 (insert "\n"))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1616
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1617 (defun vip-yank-defun ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1618 (mark-defun)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1619 (copy-region-as-kill (point) (mark t)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1620
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1621 ;; Enlarge region between BEG and END.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1622 (defun vip-enlarge-region (beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1623 (or beg (setq beg end)) ; if beg is nil, set to end
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1624 (or end (setq end beg)) ; if end is nil, set to beg
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1625
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1626 (if (< beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1627 (progn (goto-char beg) (set-mark end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1628 (goto-char end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1629 (set-mark beg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1630 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1631 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1632 (if (or (not (eobp)) (not (bolp))) (forward-line 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1633 (if (not (eobp)) (beginning-of-line))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1634 (if (> beg end) (exchange-point-and-mark)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1635
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1636
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1637 ;; Quote region by each line with a user supplied string.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1638 (defun vip-quote-region ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1639 (setq vip-quote-string
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1640 (vip-read-string-with-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1641 "Quote string: "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1642 nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1643 'vip-quote-region-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1644 vip-quote-string))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1645 (vip-enlarge-region (point) (mark t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1646 (if (> (point) (mark t)) (exchange-point-and-mark))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1647 (insert vip-quote-string)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1648 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1649 (forward-line 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1650 (while (and (< (point) (mark t)) (bolp))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1651 (insert vip-quote-string)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1652 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1653 (forward-line 1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1654
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1655 ;; Tells whether BEG is on the same line as END.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1656 ;; If one of the args is nil, it'll return nil.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1657 (defun vip-same-line (beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1658 (let ((selective-display nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1659 (incr 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1660 temp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1661 (if (and beg end (> beg end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1662 (setq temp beg
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1663 beg end
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1664 end temp))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1665 (if (and beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1666 (cond ((or (> beg (point-max)) (> end (point-max))) ; out of range
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1667 nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1668 (t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1669 ;; This 'if' is needed because Emacs treats the next empty line
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1670 ;; as part of the previous line.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1671 (if (= (vip-line-pos 'start) end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1672 (setq incr 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1673 (<= (+ incr (count-lines beg end)) 1))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1674 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1675
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1676
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1677 ;; Check if the string ends with a newline.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1678 (defun vip-end-with-a-newline-p (string)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1679 (or (string= string "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1680 (= (vip-seq-last-elt string) ?\n)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1681
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1682 (defun vip-tmp-insert-at-eob (msg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1683 (let ((savemax (point-max)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1684 (goto-char savemax)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1685 (insert msg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1686 (sit-for 2)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1687 (goto-char savemax) (delete-region (point) (point-max))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1688 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1689
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1690
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1691
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1692 ;;; Minibuffer business
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1693
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1694 (defsubst vip-set-minibuffer-style ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1695 (add-hook 'minibuffer-setup-hook 'vip-minibuffer-setup-sentinel))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1696
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1697
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1698 (defun vip-minibuffer-setup-sentinel ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1699 (let ((hook (if vip-vi-style-in-minibuffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1700 'vip-change-state-to-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1701 'vip-change-state-to-emacs)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1702 (funcall hook)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1703 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1704
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1705 ;; Interpret last event in the local map
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1706 (defun vip-exit-minibuffer ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1707 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1708 (let (command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1709 (setq command (local-key-binding (char-to-string last-command-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1710 (if command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1711 (command-execute command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1712 (exit-minibuffer))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1713
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1714
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1715 ;;; Reading string with history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1716
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1717 (defun vip-read-string-with-history (prompt &optional initial
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1718 history-var default keymap)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1719 ;; Read string, prompting with PROMPT and inserting the INITIAL
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1720 ;; value. Uses HISTORY-VAR. DEFAULT is the default value to accept if the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1721 ;; input is an empty string. Use KEYMAP, if given, or the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1722 ;; minibuffer-local-map.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1723 ;; Default value is displayed until the user types something in the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1724 ;; minibuffer.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1725 (let ((minibuffer-setup-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1726 '(lambda ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1727 (if (stringp initial)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1728 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1729 ;; don't wait if we have unread events or in kbd macro
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1730 (or unread-command-events
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1731 executing-kbd-macro
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1732 (sit-for 840))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1733 (erase-buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1734 (insert initial)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1735 (vip-minibuffer-setup-sentinel)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1736 (val "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1737 (padding "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1738 temp-msg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1739
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1740 (setq keymap (or keymap minibuffer-local-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1741 initial (or initial "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1742 temp-msg (if default
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1743 (format "(default: %s) " default)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1744 ""))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1745
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1746 (setq vip-incomplete-ex-cmd nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1747 (setq val (read-from-minibuffer prompt
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1748 (concat temp-msg initial val padding)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1749 keymap nil history-var))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1750 (setq minibuffer-setup-hook nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1751 padding (vip-array-to-string (this-command-keys))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1752 temp-msg "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1753 ;; the following tries to be smart about what to put in history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1754 (if (not (string= val (car (eval history-var))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1755 (set history-var (cons val (eval history-var))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1756 (if (or (string= (nth 0 (eval history-var)) (nth 1 (eval history-var)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1757 (string= (nth 0 (eval history-var)) ""))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1758 (set history-var (cdr (eval history-var))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1759 ;; If the user enters nothing but the prev cmd wasn't vip-ex,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1760 ;; vip-command-argument, or `! shell-command', this probably means
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1761 ;; that the user typed something then erased. Return "" in this case, not
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1762 ;; the default---the default is too confusing in this case.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1763 (cond ((and (string= val "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1764 (not (string= prompt "!")) ; was a `! shell-command'
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1765 (not (memq last-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1766 '(vip-ex
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1767 vip-command-argument
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1768 t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1769 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1770 "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1771 ((string= val "") (or default ""))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1772 (t val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1773 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1774
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1775
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1776
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1777 ;; insertion commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1778
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1779 ;; Called when state changes from Insert Vi command mode.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1780 ;; Repeats the insertion command if Insert state was entered with prefix
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1781 ;; argument > 1.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1782 (defun vip-repeat-insert-command ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1783 (let ((i-com (car vip-d-com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1784 (val (nth 1 vip-d-com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1785 (char (nth 2 vip-d-com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1786 (if (and val (> val 1)) ; first check that val is non-nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1787 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1788 (setq vip-d-com (list i-com (1- val) ?r nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1789 (vip-repeat nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1790 (setq vip-d-com (list i-com val char nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1791 ))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1792
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1793 (defun vip-insert (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1794 "Insert before point."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1795 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1796 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1797 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1798 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1799 (vip-set-destructive-command (list 'vip-insert val ?r nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1800 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1801 (vip-loop val (vip-yank-last-insertion))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1802 (vip-change-state-to-insert))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1803
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1804 (defun vip-append (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1805 "Append after point."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1806 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1807 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1808 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1809 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1810 (vip-set-destructive-command (list 'vip-append val ?r nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1811 (if (not (eolp)) (forward-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1812 (if (equal com ?r)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1813 (vip-loop val (vip-yank-last-insertion))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1814 (vip-change-state-to-insert))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1815
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1816 (defun vip-Append (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1817 "Append at end of line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1818 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1819 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1820 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1821 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1822 (vip-set-destructive-command (list 'vip-Append val ?r nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1823 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1824 (if (equal com ?r)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1825 (vip-loop val (vip-yank-last-insertion))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1826 (vip-change-state-to-insert))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1827
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1828 (defun vip-Insert (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1829 "Insert before first non-white."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1830 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1831 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1832 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1833 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1834 (vip-set-destructive-command (list 'vip-Insert val ?r nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1835 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1836 (if (equal com ?r)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1837 (vip-loop val (vip-yank-last-insertion))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1838 (vip-change-state-to-insert))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1839
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1840 (defun vip-open-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1841 "Open line below."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1842 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1843 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1844 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1845 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1846 (vip-set-destructive-command (list 'vip-open-line val ?r nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1847 (let ((col (current-indentation)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1848 (if (equal com ?r)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1849 (vip-loop val
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1850 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1851 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1852 (newline 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1853 (if vip-auto-indent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1854 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1855 (setq vip-cted t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1856 (if vip-electric-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1857 (indent-according-to-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1858 (indent-to col))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1859 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1860 (vip-yank-last-insertion)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1861 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1862 (newline 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1863 (if vip-auto-indent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1864 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1865 (setq vip-cted t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1866 (if vip-electric-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1867 (indent-according-to-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1868 (indent-to col))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1869 (vip-change-state-to-insert)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1870
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1871 (defun vip-Open-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1872 "Open line above."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1873 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1874 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1875 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1876 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1877 (vip-set-destructive-command (list 'vip-Open-line val ?r nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1878 (let ((col (current-indentation)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1879 (if (equal com ?r)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1880 (vip-loop val
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1881 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1882 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1883 (open-line 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1884 (if vip-auto-indent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1885 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1886 (setq vip-cted t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1887 (if vip-electric-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1888 (indent-according-to-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1889 (indent-to col))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1890 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1891 (vip-yank-last-insertion)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1892 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1893 (open-line 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1894 (if vip-auto-indent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1895 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1896 (setq vip-cted t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1897 (if vip-electric-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1898 (indent-according-to-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1899 (indent-to col))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1900 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1901 (vip-change-state-to-insert)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1902
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1903 (defun vip-open-line-at-point (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1904 "Open line at point."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1905 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1906 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1907 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1908 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1909 (vip-set-destructive-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1910 (list 'vip-open-line-at-point val ?r nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1911 (if (equal com ?r)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1912 (vip-loop val
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1913 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1914 (open-line 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1915 (vip-yank-last-insertion)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1916 (open-line 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1917 (vip-change-state-to-insert))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1918
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1919 (defun vip-substitute (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1920 "Substitute characters."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1921 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1922 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1923 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1924 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1925 (forward-char val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1926 (if (equal com ?r)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1927 (vip-change-subr (mark t) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1928 (vip-change (mark t) (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1929 (vip-set-destructive-command (list 'vip-substitute val ?r nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1930 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1931
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1932 (defun vip-substitute-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1933 "Substitute lines."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1934 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1935 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1936 (vip-line (cons arg ?C)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1937
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1938 ;; Prepare for replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1939 (defun vip-start-replace ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1940 (setq vip-began-as-replace t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1941 vip-sitting-in-replace t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1942 vip-replace-chars-to-delete 0
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1943 vip-replace-chars-deleted 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1944 (vip-add-hook 'vip-after-change-functions 'vip-replace-mode-spy-after t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1945 (vip-add-hook 'vip-before-change-functions 'vip-replace-mode-spy-before t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1946 ;; this will get added repeatedly, but no harm
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1947 (add-hook 'after-change-functions 'vip-after-change-sentinel t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1948 (add-hook 'before-change-functions 'vip-before-change-sentinel t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1949 (vip-move-marker-locally 'vip-last-posn-in-replace-region
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1950 (vip-replace-start))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1951 (vip-add-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1952 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1953 (vip-add-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1954 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1955 ;; guard against a smartie who switched from R-replace to normal replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1956 (vip-remove-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1957 'vip-post-command-hooks 'vip-R-state-post-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1958 (if overwrite-mode (overwrite-mode nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1959 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1960
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1961
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1962 ;; checks how many chars were deleted by the last change
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1963 (defun vip-replace-mode-spy-before (beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1964 (setq vip-replace-chars-deleted
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1965 (- end beg
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1966 (max 0 (- end (vip-replace-end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1967 (max 0 (- (vip-replace-start) beg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1968 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1969
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1970 ;; Invoked as an after-change-function to set up parameters of the last change
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1971 (defun vip-replace-mode-spy-after (beg end length)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1972 (if (memq vip-intermediate-command '(repeating-insertion-from-ring))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1973 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1974 (setq vip-replace-chars-to-delete 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1975 (vip-move-marker-locally
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1976 'vip-last-posn-in-replace-region (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1977
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1978 (let (beg-col end-col real-end chars-to-delete)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1979 (setq real-end (min end (vip-replace-end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1980 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1981 (goto-char beg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1982 (setq beg-col (current-column))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1983 (goto-char real-end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1984 (setq end-col (current-column)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1985
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1986 ;; If beg of change is outside the replacement region, then don't
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1987 ;; delete anything in the repl region (set chars-to-delete to 0).
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1988 ;;
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1989 ;; This works fine except that we have to take special care of
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1990 ;; dabbrev-expand. The problem stems from new-dabbrev.el, which
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1991 ;; sometimes simply shifts the repl region rightwards, without
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1992 ;; deleting an equal amount of characters.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1993 ;;
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1994 ;; The reason why new-dabbrev.el causes this are this:
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1995 ;; if one dinamically completes a partial word that starts before the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1996 ;; replacement region (but ends inside) then new-dabbrev.el first
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1997 ;; moves cursor backwards, to the beginning of the word to be
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1998 ;; completed (say, pt A). Then it inserts the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1999 ;; completed word and then deletes the old, incomplete part.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2000 ;; Since the complete word is inserted at position before the repl
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2001 ;; region, the next If-statement would have set chars-to-delete to 0
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2002 ;; unless we check for the current command, which must be
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2003 ;; dabbrev-expand.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2004 ;;
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2005 ;; In fact, it might be also useful to have overlays for insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2006 ;; regions as well, since this will let us capture the situation when
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2007 ;; dabbrev-expand goes back past the insertion point to find the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2008 ;; beginning of the word to be expanded.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2009 (if (or (and (<= (vip-replace-start) beg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2010 (<= beg (vip-replace-end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2011 (and (= length 0) (eq this-command 'dabbrev-expand)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2012 (setq chars-to-delete
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2013 (max (- end-col beg-col) (- real-end beg) 0))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2014 (setq chars-to-delete 0))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2015
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2016 ;; if beg = last change position, it means that we are within the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2017 ;; same command that does multiple changes. Moreover, it means
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2018 ;; that we have two subsequent changes (insert/delete) that
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2019 ;; complement each other.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2020 (if (= beg (marker-position vip-last-posn-in-replace-region))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2021 (setq vip-replace-chars-to-delete
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2022 (- (+ chars-to-delete vip-replace-chars-to-delete)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2023 vip-replace-chars-deleted))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2024 (setq vip-replace-chars-to-delete chars-to-delete))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2025
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2026 (vip-move-marker-locally
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2027 'vip-last-posn-in-replace-region
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2028 (max (if (> end (vip-replace-end)) (vip-replace-start) end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2029 (or (marker-position vip-last-posn-in-replace-region)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2030 (vip-replace-start))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2031 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2032
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2033 (setq vip-replace-chars-to-delete
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2034 (max 0
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2035 (min vip-replace-chars-to-delete
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2036 (- (vip-replace-end) vip-last-posn-in-replace-region)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2037 (- (vip-line-pos 'end) vip-last-posn-in-replace-region)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2038 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2039 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2040
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2041
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2042 ;; Delete stuff between posn and the end of vip-replace-overlay-marker, if
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2043 ;; posn is within the overlay.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2044 (defun vip-finish-change (posn)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2045 (vip-remove-hook 'vip-after-change-functions 'vip-replace-mode-spy-after)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2046 (vip-remove-hook 'vip-before-change-functions 'vip-replace-mode-spy-before)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2047 (vip-remove-hook 'vip-post-command-hooks
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2048 'vip-replace-state-post-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2049 (vip-remove-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2050 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2051 (vip-restore-cursor-color-after-replace)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2052 (setq vip-sitting-in-replace nil) ; just in case we'll need to know it
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2053 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2054 (if (and
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2055 vip-replace-overlay
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2056 (>= posn (vip-replace-start))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2057 (< posn (vip-replace-end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2058 (delete-region posn (vip-replace-end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2059 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2060
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2061 (if (eq vip-current-state 'replace-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2062 (vip-downgrade-to-insert))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2063 ;; replace mode ended => nullify vip-last-posn-in-replace-region
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2064 (vip-move-marker-locally 'vip-last-posn-in-replace-region nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2065 (vip-hide-replace-overlay)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2066 (vip-refresh-mode-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2067 (vip-put-string-on-kill-ring vip-last-replace-region)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2068 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2069
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2070 ;; Make STRING be the first element of the kill ring.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2071 (defun vip-put-string-on-kill-ring (string)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2072 (setq kill-ring (cons string kill-ring))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2073 (if (> (length kill-ring) kill-ring-max)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2074 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2075 (setq kill-ring-yank-pointer kill-ring))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2076
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2077 (defun vip-finish-R-mode ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2078 (vip-remove-hook 'vip-post-command-hooks 'vip-R-state-post-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2079 (vip-remove-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2080 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2081 (vip-downgrade-to-insert))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2082
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2083 (defun vip-start-R-mode ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2084 ;; Leave arg as 1, not t: XEmacs insists that it must be a pos number
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2085 (overwrite-mode 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2086 (vip-add-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2087 'vip-post-command-hooks 'vip-R-state-post-command-sentinel t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2088 (vip-add-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2089 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2090 ;; guard against a smartie who switched from R-replace to normal replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2091 (vip-remove-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2092 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2093 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2094
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2095
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2096
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2097 (defun vip-replace-state-exit-cmd ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2098 "Binding for keys that cause Replace state to switch to Vi or to Insert.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2099 These keys are ESC, RET, and LineFeed"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2100 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2101 (if overwrite-mode ;; If you are in replace mode invoked via 'R'
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2102 (vip-finish-R-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2103 (vip-finish-change vip-last-posn-in-replace-region))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2104 (let (com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2105 (if (eq this-command 'vip-intercept-ESC-key)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2106 (setq com 'vip-exit-insert-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2107 (vip-set-unread-command-events last-input-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2108 (setq com (key-binding (read-key-sequence nil))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2109
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2110 (condition-case conds
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2111 (command-execute com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2112 (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2113 (vip-message-conditions conds)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2114 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2115 (vip-hide-replace-overlay))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2116
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2117 (defun vip-replace-state-carriage-return ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2118 "Implements carriage return in Viper replace state."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2119 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2120 ;; If Emacs start supporting overlay maps, as it currently supports
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2121 ;; text-property maps, we could do away with vip-replace-minor-mode and
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2122 ;; just have keymap attached to replace overlay. Then the "if part" of this
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2123 ;; statement can be deleted.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2124 (if (or (< (point) (vip-replace-start))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2125 (> (point) (vip-replace-end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2126 (let (vip-replace-minor-mode com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2127 (vip-set-unread-command-events last-input-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2128 (setq com (key-binding (read-key-sequence nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2129 (condition-case conds
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2130 (command-execute com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2131 (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2132 (vip-message-conditions conds))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2133 (if (not vip-allow-multiline-replace-regions)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2134 (vip-replace-state-exit-cmd)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2135 (if (vip-same-line (point) (vip-replace-end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2136 (vip-replace-state-exit-cmd)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2137 (vip-kill-line nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2138 (vip-next-line-at-bol nil)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2139
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2140
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2141 ;; This is the function bound to 'R'---unlimited replace.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2142 ;; Similar to Emacs's own overwrite-mode.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2143 (defun vip-overwrite (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2144 "Begin overwrite mode."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2145 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2146 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2147 (com (vip-getcom arg)) (len))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2148 (vip-set-destructive-command (list 'vip-overwrite val ?r nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2149 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2150 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2151 ;; Viper saves inserted text in vip-last-insertion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2152 (setq len (length vip-last-insertion))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2153 (delete-char len)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2154 (vip-loop val (vip-yank-last-insertion)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2155 (setq last-command 'vip-overwrite)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2156 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2157 (vip-set-replace-overlay (point) (vip-line-pos 'end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2158 (vip-change-state-to-replace)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2159 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2160
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2161
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2162 ;; line commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2163
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2164 (defun vip-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2165 (let ((val (car arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2166 (com (cdr arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2167 (vip-move-marker-locally 'vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2168 (if (not (eobp))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2169 (vip-next-line-carefully (1- val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2170 ;; this ensures that dd, cc, D, yy will do the right thing on the last
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2171 ;; line of buffer when this line has no \n.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2172 (vip-add-newline-at-eob-if-necessary)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2173 (vip-execute-com 'vip-line val com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2174 (if (and (eobp) (not (bobp))) (forward-line -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2175 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2176
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2177 (defun vip-yank-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2178 "Yank ARG lines (in Vi's sense)."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2179 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2180 (let ((val (vip-p-val arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2181 (vip-line (cons val ?Y))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2182
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2183
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2184 ;; region commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2185
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2186 (defun vip-region (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2187 "Execute command on a region."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2188 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2189 (let ((val (vip-P-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2190 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2191 (vip-move-marker-locally 'vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2192 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2193 (vip-execute-com 'vip-region val com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2194
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2195 (defun vip-Region (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2196 "Execute command on a Region."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2197 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2198 (let ((val (vip-P-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2199 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2200 (vip-move-marker-locally 'vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2201 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2202 (vip-execute-com 'vip-Region val com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2203
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2204 (defun vip-replace-char (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2205 "Replace the following ARG chars by the character read."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2206 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2207 (if (and (eolp) (bolp)) (error "No character to replace here"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2208 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2209 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2210 (vip-replace-char-subr com val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2211 (if (and (eolp) (not (bolp))) (forward-char 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2212 (vip-set-destructive-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2213 (list 'vip-replace-char val ?r nil vip-d-char nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2214 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2215
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2216 (defun vip-replace-char-subr (com arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2217 (let ((take-care-of-iso-accents
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2218 (and (boundp 'iso-accents-mode) vip-automatic-iso-accents))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2219 char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2220 (setq char (if (equal com ?r)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2221 vip-d-char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2222 (read-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2223 (if (and take-care-of-iso-accents (memq char '(?' ?\" ?^ ?~)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2224 ;; get European characters
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2225 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2226 (iso-accents-mode 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2227 (vip-set-unread-command-events char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2228 (setq char (aref (read-key-sequence nil) 0))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2229 (iso-accents-mode -1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2230 (delete-char arg t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2231 (setq vip-d-char char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2232 (vip-loop (if (> arg 0) arg (- arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2233 (if (eq char ?\C-m) (insert "\n") (insert char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2234 (backward-char arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2235
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2236
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2237 ;; basic cursor movement. j, k, l, h commands.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2238
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2239 (defun vip-forward-char (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2240 "Move point right ARG characters (left if ARG negative).
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2241 On reaching end of line, stop and signal error."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2242 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2243 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2244 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2245 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2246 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2247 (if vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2248 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2249 ;; the boundary condition check gets weird here because
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2250 ;; forward-char may be the parameter of a delete, and 'dl' works
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2251 ;; just like 'x' for the last char on a line, so we have to allow
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2252 ;; the forward motion before the 'vip-execute-com', but, of
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2253 ;; course, 'dl' doesn't work on an empty line, so we have to
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2254 ;; catch that condition before 'vip-execute-com'
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2255 (if (and (eolp) (bolp)) (error "") (forward-char val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2256 (if com (vip-execute-com 'vip-forward-char val com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2257 (if (eolp) (progn (backward-char 1) (error ""))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2258 (forward-char val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2259 (if com (vip-execute-com 'vip-forward-char val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2260
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2261 (defun vip-backward-char (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2262 "Move point left ARG characters (right if ARG negative).
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2263 On reaching beginning of line, stop and signal error."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2264 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2265 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2266 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2267 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2268 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2269 (if vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2270 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2271 (if (bolp) (error "") (backward-char val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2272 (if com (vip-execute-com 'vip-backward-char val com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2273 (backward-char val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2274 (if com (vip-execute-com 'vip-backward-char val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2275
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2276 ;; Like forward-char, but doesn't move at end of buffer.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2277 (defun vip-forward-char-carefully (&optional arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2278 (setq arg (or arg 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2279 (if (>= (point-max) (+ (point) arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2280 (forward-char arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2281 (goto-char (point-max))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2282
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2283 ;; Like backward-char, but doesn't move at end of buffer.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2284 (defun vip-backward-char-carefully (&optional arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2285 (setq arg (or arg 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2286 (if (<= (point-min) (- (point) arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2287 (backward-char arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2288 (goto-char (point-min))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2289
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2290 (defun vip-next-line-carefully (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2291 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2292 (next-line arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2293 (error nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2294
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2295
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2296
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2297 ;;; Word command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2298
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2299 ;; Words are formed from alpha's and nonalphas - <sp>,\t\n are separators
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2300 ;; for word movement. When executed with a destructive command, \n is
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2301 ;; usually left untouched for the last word.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2302 ;; Viper uses syntax table to determine what is a word and what is a
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2303 ;; separator. However, \n is always a separator. Also, if vip-syntax-preference
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2304 ;; is 'vi, then `_' is part of the word.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2305
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2306 ;; skip only one \n
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2307 (defun vip-skip-separators (forward)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2308 (if forward
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2309 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2310 (vip-skip-all-separators-forward 'within-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2311 (if (looking-at "\n")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2312 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2313 (forward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2314 (vip-skip-all-separators-forward 'within-line))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2315 (vip-skip-all-separators-backward 'within-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2316 (backward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2317 (if (looking-at "\n")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2318 (vip-skip-all-separators-backward 'within-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2319 (forward-char))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2320
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2321 (defun vip-forward-word-kernel (val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2322 (while (> val 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2323 (cond ((vip-looking-at-alpha)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2324 (vip-skip-alpha-forward "_")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2325 (vip-skip-separators t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2326 ((vip-looking-at-separator)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2327 (vip-skip-separators t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2328 ((not (vip-looking-at-alphasep))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2329 (vip-skip-nonalphasep-forward)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2330 (vip-skip-separators t)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2331 (setq val (1- val))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2332
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2333 ;; first search backward for pat. Then skip chars backwards using aux-pat
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2334 (defun vip-fwd-skip (pat aux-pat lim)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2335 (if (and (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2336 (re-search-backward pat lim t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2337 (= (point) (match-end 0)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2338 (goto-char (match-beginning 0)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2339 (skip-chars-backward aux-pat lim)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2340 (if (= (point) lim)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2341 (vip-forward-char-carefully))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2342 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2343
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2344
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2345 (defun vip-forward-word (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2346 "Forward word."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2347 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2348 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2349 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2350 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2351 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2352 (vip-forward-word-kernel val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2353 (if com (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2354 (cond ((memq com (list ?c (- ?c)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2355 (vip-fwd-skip "\n[ \t]*" " \t" vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2356 ;; Yank words including the whitespace, but not newline
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2357 ((memq com (list ?y (- ?y)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2358 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2359 ((vip-dotable-command-p com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2360 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2361 (vip-execute-com 'vip-forward-word val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2362
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2363
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2364 (defun vip-forward-Word (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2365 "Forward word delimited by white characters."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2366 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2367 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2368 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2369 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2370 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2371 (vip-loop val
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2372 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2373 (vip-skip-nonseparators 'forward)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2374 (vip-skip-separators t)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2375 (if com (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2376 (cond ((memq com (list ?c (- ?c)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2377 (vip-fwd-skip "\n[ \t]*" " \t" vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2378 ;; Yank words including the whitespace, but not newline
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2379 ((memq com (list ?y (- ?y)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2380 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2381 ((vip-dotable-command-p com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2382 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2383 (vip-execute-com 'vip-forward-Word val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2384
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2385
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2386 ;; this is a bit different from Vi, but Vi's end of word
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2387 ;; makes no sense whatsoever
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2388 (defun vip-end-of-word-kernel ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2389 (if (vip-end-of-word-p) (forward-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2390 (if (vip-looking-at-separator)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2391 (vip-skip-all-separators-forward))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2392
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2393 (cond ((vip-looking-at-alpha) (vip-skip-alpha-forward "_"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2394 ((not (vip-looking-at-alphasep)) (vip-skip-nonalphasep-forward)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2395 (vip-backward-char-carefully))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2396
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2397 (defun vip-end-of-word-p ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2398 (or (eobp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2399 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2400 (cond ((vip-looking-at-alpha)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2401 (forward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2402 (not (vip-looking-at-alpha)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2403 ((not (vip-looking-at-alphasep))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2404 (forward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2405 (vip-looking-at-alphasep))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2406
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2407
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2408 (defun vip-end-of-word (arg &optional careful)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2409 "Move point to end of current word."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2410 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2411 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2412 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2413 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2414 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2415 (vip-loop val (vip-end-of-word-kernel))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2416 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2417 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2418 (forward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2419 (vip-execute-com 'vip-end-of-word val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2420
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2421 (defun vip-end-of-Word (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2422 "Forward to end of word delimited by white character."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2423 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2424 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2425 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2426 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2427 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2428 (vip-loop val
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2429 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2430 (vip-end-of-word-kernel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2431 (vip-skip-nonseparators 'forward)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2432 (backward-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2433 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2434 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2435 (forward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2436 (vip-execute-com 'vip-end-of-Word val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2437
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2438 (defun vip-backward-word-kernel (val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2439 (while (> val 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2440 (backward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2441 (cond ((vip-looking-at-alpha)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2442 (vip-skip-alpha-backward "_"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2443 ((vip-looking-at-separator)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2444 (forward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2445 (vip-skip-separators nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2446 (backward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2447 (cond ((vip-looking-at-alpha)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2448 (vip-skip-alpha-backward "_"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2449 ((not (vip-looking-at-alphasep))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2450 (vip-skip-nonalphasep-backward))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2451 (t (forward-char))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2452 ((not (vip-looking-at-alphasep))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2453 (vip-skip-nonalphasep-backward)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2454 (setq val (1- val))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2455
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2456 (defun vip-backward-word (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2457 "Backward word."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2458 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2459 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2460 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2461 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2462 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2463 (let (i)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2464 (if (setq i (save-excursion (backward-char) (looking-at "\n")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2465 (backward-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2466 (vip-move-marker-locally 'vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2467 (if i (forward-char))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2468 (vip-backward-word-kernel val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2469 (if com (vip-execute-com 'vip-backward-word val com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2470
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2471 (defun vip-backward-Word (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2472 "Backward word delimited by white character."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2473 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2474 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2475 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2476 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2477 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2478 (let (i)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2479 (if (setq i (save-excursion (backward-char) (looking-at "\n")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2480 (backward-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2481 (vip-move-marker-locally 'vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2482 (if i (forward-char))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2483 (vip-loop val
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2484 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2485 (vip-skip-separators nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2486 (vip-skip-nonseparators 'backward)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2487 (if com (vip-execute-com 'vip-backward-Word val com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2488
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2489
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2490
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2491 ;; line commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2492
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2493 (defun vip-beginning-of-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2494 "Go to beginning of line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2495 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2496 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2497 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2498 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2499 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2500 (beginning-of-line val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2501 (if com (vip-execute-com 'vip-beginning-of-line val com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2502
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2503 (defun vip-bol-and-skip-white (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2504 "Beginning of line at first non-white character."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2505 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2506 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2507 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2508 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2509 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2510 (forward-to-indentation (1- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2511 (if com (vip-execute-com 'vip-bol-and-skip-white val com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2512
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2513 (defun vip-goto-eol (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2514 "Go to end of line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2515 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2516 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2517 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2518 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2519 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2520 (end-of-line val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2521 (if com (vip-execute-com 'vip-goto-eol val com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2522 (if vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2523 (if (and (eolp) (not (bolp))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2524 ;; a fix for vip-change-to-eol
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2525 (not (equal vip-current-state 'insert-state)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2526 (backward-char 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2527 ))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2528
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2529
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2530 (defun vip-goto-col (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2531 "Go to ARG's column."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2532 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2533 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2534 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2535 (com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2536 line-len)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2537 (setq line-len (- (vip-line-pos 'end) (vip-line-pos 'start)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2538 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2539 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2540 (forward-char (1- (min line-len val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2541 (while (> (current-column) (1- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2542 (backward-char 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2543 (if com (vip-execute-com 'vip-goto-col val com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2544 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2545 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2546 (if (> val (current-column)) (error "")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2547 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2548
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2549
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2550 (defun vip-next-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2551 "Go to next line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2552 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2553 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2554 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2555 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2556 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2557 (next-line val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2558 (if vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2559 (if (and (eolp) (not (bolp))) (backward-char 1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2560 (setq this-command 'next-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2561 (if com (vip-execute-com 'vip-next-line val com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2562
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2563 (defun vip-next-line-at-bol (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2564 "Next line at beginning of line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2565 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2566 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2567 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2568 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2569 (if (eobp) (error "Last line in buffer")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2570 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2571 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2572 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2573 (forward-line val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2574 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2575 (if com (vip-execute-com 'vip-next-line-at-bol val com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2576
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2577 (defun vip-previous-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2578 "Go to previous line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2579 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2580 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2581 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2582 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2583 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2584 (previous-line val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2585 (if vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2586 (if (and (eolp) (not (bolp))) (backward-char 1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2587 (setq this-command 'previous-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2588 (if com (vip-execute-com 'vip-previous-line val com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2589
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2590
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2591 (defun vip-previous-line-at-bol (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2592 "Previous line at beginning of line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2593 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2594 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2595 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2596 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2597 (if (bobp) (error "First line in buffer")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2598 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2599 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2600 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2601 (forward-line (- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2602 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2603 (if com (vip-execute-com 'vip-previous-line val com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2604
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2605 (defun vip-change-to-eol (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2606 "Change to end of line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2607 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2608 (vip-goto-eol (cons arg ?c)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2609
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2610 (defun vip-kill-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2611 "Delete line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2612 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2613 (vip-goto-eol (cons arg ?d)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2614
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2615 (defun vip-erase-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2616 "Erase line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2617 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2618 (vip-beginning-of-line (cons arg ?d)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2619
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2620
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2621 ;;; Moving around
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2622
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2623 (defun vip-goto-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2624 "Go to ARG's line. Without ARG go to end of buffer."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2625 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2626 (let ((val (vip-P-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2627 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2628 (vip-move-marker-locally 'vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2629 (vip-deactivate-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2630 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2631 (if (null val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2632 (goto-char (point-max))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2633 (goto-char (point-min))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2634 (forward-line (1- val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2635
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2636 ;; positioning is done twice: before and after command execution
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2637 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2638 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2639
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2640 (if com (vip-execute-com 'vip-goto-line val com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2641
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2642 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2643 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2644 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2645
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2646 ;; Find ARG's occurrence of CHAR on the current line.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2647 ;; If FORWARD then search is forward, otherwise backward. OFFSET is used to
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2648 ;; adjust point after search.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2649 (defun vip-find-char (arg char forward offset)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2650 (or (char-or-string-p char) (error ""))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2651 (let ((arg (if forward arg (- arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2652 (cmd (if (eq vip-intermediate-command 'vip-repeat)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2653 (nth 5 vip-d-com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2654 (vip-array-to-string (this-command-keys))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2655 point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2656 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2657 (save-restriction
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2658 (if (> arg 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2659 (narrow-to-region
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2660 ;; forward search begins here
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2661 (if (eolp) (error "Command `%s': At end of line" cmd) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2662 ;; forward search ends here
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2663 (progn (end-of-line) (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2664 (narrow-to-region
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2665 ;; backward search begins from here
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2666 (if (bolp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2667 (error "Command `%s': At beginning of line" cmd) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2668 ;; backward search ends here
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2669 (progn (beginning-of-line) (point))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2670 ;; if arg > 0, point is forwarded before search.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2671 (if (> arg 0) (goto-char (1+ (point-min)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2672 (goto-char (point-max)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2673 (if (let ((case-fold-search nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2674 (search-forward (char-to-string char) nil 0 arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2675 (setq point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2676 (error "Command `%s': `%c' not found" cmd char))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2677 (goto-char (+ point (if (> arg 0) (if offset -2 -1) (if offset 1 0))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2678
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2679 (defun vip-find-char-forward (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2680 "Find char on the line.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2681 If called interactively read the char to find from the terminal, and if
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2682 called from vip-repeat, the char last used is used. This behaviour is
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2683 controlled by the sign of prefix numeric value."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2684 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2685 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2686 (com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2687 (cmd-representation (nth 5 vip-d-com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2688 (if (> val 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2689 ;; this means that the function was called interactively
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2690 (setq vip-f-char (read-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2691 vip-f-forward t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2692 vip-f-offset nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2693 ;; vip-repeat --- set vip-F-char from command-keys
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2694 (setq vip-F-char (if (stringp cmd-representation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2695 (vip-seq-last-elt cmd-representation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2696 vip-F-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2697 vip-f-char vip-F-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2698 (setq val (- val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2699 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2700 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2701 (setq val (- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2702 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2703 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2704 (setq vip-F-char vip-f-char) ; set new vip-F-char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2705 (forward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2706 (vip-execute-com 'vip-find-char-forward val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2707
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2708 (defun vip-goto-char-forward (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2709 "Go up to char ARG forward on line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2710 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2711 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2712 (com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2713 (cmd-representation (nth 5 vip-d-com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2714 (if (> val 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2715 ;; this means that the function was called interactively
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2716 (setq vip-f-char (read-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2717 vip-f-forward t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2718 vip-f-offset t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2719 ;; vip-repeat --- set vip-F-char from command-keys
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2720 (setq vip-F-char (if (stringp cmd-representation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2721 (vip-seq-last-elt cmd-representation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2722 vip-F-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2723 vip-f-char vip-F-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2724 (setq val (- val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2725 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2726 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2727 (setq val (- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2728 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2729 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2730 (setq vip-F-char vip-f-char) ; set new vip-F-char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2731 (forward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2732 (vip-execute-com 'vip-goto-char-forward val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2733
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2734 (defun vip-find-char-backward (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2735 "Find char ARG on line backward."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2736 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2737 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2738 (com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2739 (cmd-representation (nth 5 vip-d-com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2740 (if (> val 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2741 ;; this means that the function was called interactively
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2742 (setq vip-f-char (read-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2743 vip-f-forward nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2744 vip-f-offset nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2745 ;; vip-repeat --- set vip-F-char from command-keys
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2746 (setq vip-F-char (if (stringp cmd-representation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2747 (vip-seq-last-elt cmd-representation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2748 vip-F-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2749 vip-f-char vip-F-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2750 (setq val (- val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2751 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2752 (vip-find-char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2753 val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2754 (setq val (- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2755 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2756 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2757 (setq vip-F-char vip-f-char) ; set new vip-F-char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2758 (vip-execute-com 'vip-find-char-backward val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2759
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2760 (defun vip-goto-char-backward (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2761 "Go up to char ARG backward on line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2762 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2763 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2764 (com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2765 (cmd-representation (nth 5 vip-d-com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2766 (if (> val 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2767 ;; this means that the function was called interactively
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2768 (setq vip-f-char (read-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2769 vip-f-forward nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2770 vip-f-offset t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2771 ;; vip-repeat --- set vip-F-char from command-keys
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2772 (setq vip-F-char (if (stringp cmd-representation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2773 (vip-seq-last-elt cmd-representation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2774 vip-F-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2775 vip-f-char vip-F-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2776 (setq val (- val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2777 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2778 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2779 (setq val (- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2780 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2781 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2782 (setq vip-F-char vip-f-char) ; set new vip-F-char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2783 (vip-execute-com 'vip-goto-char-backward val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2784
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2785 (defun vip-repeat-find (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2786 "Repeat previous find command."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2787 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2788 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2789 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2790 (vip-deactivate-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2791 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2792 (vip-find-char val vip-f-char vip-f-forward vip-f-offset)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2793 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2794 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2795 (if vip-f-forward (forward-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2796 (vip-execute-com 'vip-repeat-find val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2797
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2798 (defun vip-repeat-find-opposite (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2799 "Repeat previous find command in the opposite direction."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2800 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2801 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2802 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2803 (vip-deactivate-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2804 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2805 (vip-find-char val vip-f-char (not vip-f-forward) vip-f-offset)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2806 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2807 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2808 (if vip-f-forward (forward-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2809 (vip-execute-com 'vip-repeat-find-opposite val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2810
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2811
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2812 ;; window scrolling etc.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2813
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2814 (defun vip-other-window (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2815 "Switch to other window."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2816 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2817 (other-window arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2818 (or (not (eq vip-current-state 'emacs-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2819 (string= (buffer-name (current-buffer)) " *Minibuf-1*")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2820 (vip-change-state-to-vi)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2821
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2822 (defun vip-window-top (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2823 "Go to home window line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2824 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2825 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2826 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2827 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2828 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2829 (move-to-window-line (1- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2830
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2831 ;; positioning is done twice: before and after command execution
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2832 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2833 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2834
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2835 (if com (vip-execute-com 'vip-window-top val com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2836
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2837 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2838 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2839 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2840
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2841 (defun vip-window-middle (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2842 "Go to middle window line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2843 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2844 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2845 (com (vip-getCom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2846 lines)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2847 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2848 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2849 (if (not (pos-visible-in-window-p (point-max)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2850 (move-to-window-line (+ (/ (1- (window-height)) 2) (1- val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2851 (setq lines (count-lines (window-start) (point-max)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2852 (move-to-window-line (+ (/ lines 2) (1- val))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2853
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2854 ;; positioning is done twice: before and after command execution
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2855 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2856 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2857
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2858 (if com (vip-execute-com 'vip-window-middle val com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2859
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2860 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2861 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2862 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2863
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2864 (defun vip-window-bottom (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2865 "Go to last window line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2866 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2867 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2868 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2869 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2870 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2871 (move-to-window-line (- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2872
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2873 ;; positioning is done twice: before and after command execution
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2874 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2875 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2876
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2877 (if com (vip-execute-com 'vip-window-bottom val com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2878
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2879 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2880 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2881 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2882
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2883 (defun vip-line-to-top (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2884 "Put current line on the home line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2885 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2886 (recenter (1- arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2887
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2888 (defun vip-line-to-middle (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2889 "Put current line on the middle line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2890 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2891 (recenter (+ (1- arg) (/ (1- (window-height)) 2))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2892
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2893 (defun vip-line-to-bottom (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2894 "Put current line on the last line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2895 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2896 (recenter (- (window-height) (1+ arg))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2897
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2898 ;; If point is within vip-search-scroll-threshold of window top or bottom,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2899 ;; scroll up or down 1/7 of window height, depending on whether we are at the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2900 ;; bottom or at the top of the window. This function is called by vip-search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2901 ;; (which is called from vip-search-forward/backward/next). If the value of
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2902 ;; vip-search-scroll-threshold is negative - don't scroll.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2903 (defun vip-adjust-window ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2904 (let ((win-height (if vip-emacs-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2905 (1- (window-height)) ; adjust for modeline
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2906 (window-displayed-height)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2907 (pt (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2908 at-top-p at-bottom-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2909 min-scroll direction)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2910 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2911 (move-to-window-line 0) ; top
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2912 (setq at-top-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2913 (<= (count-lines pt (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2914 vip-search-scroll-threshold))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2915 (move-to-window-line -1) ; bottom
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2916 (setq at-bottom-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2917 (<= (count-lines pt (point)) vip-search-scroll-threshold))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2918 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2919 (cond (at-top-p (setq min-scroll (1- vip-search-scroll-threshold)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2920 direction 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2921 (at-bottom-p (setq min-scroll (1+ vip-search-scroll-threshold)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2922 direction -1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2923 (if min-scroll
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2924 (recenter
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2925 (* (max min-scroll (/ win-height 7)) direction)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2926 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2927
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2928
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2929 ;; paren match
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2930 ;; must correct this to only match ( to ) etc. On the other hand
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2931 ;; it is good that paren match gets confused, because that way you
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2932 ;; catch _all_ imbalances.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2933
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2934 (defun vip-paren-match (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2935 "Go to the matching parenthesis."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2936 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2937 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2938 (let ((com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2939 (parse-sexp-ignore-comments vip-parse-sexp-ignore-comments)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2940 anchor-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2941 (if (integerp arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2942 (if (or (> arg 99) (< arg 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2943 (error "Prefix must be between 1 and 99")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2944 (goto-char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2945 (if (> (point-max) 80000)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2946 (* (/ (point-max) 100) arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2947 (/ (* (point-max) arg) 100)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2948 (back-to-indentation))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2949 (let (beg-lim end-lim)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2950 (if (and (eolp) (not (bolp))) (forward-char -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2951 (if (not (looking-at "[][(){}]"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2952 (setq anchor-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2953 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2954 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2955 (setq beg-lim (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2956 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2957 (setq end-lim (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2958 (cond ((re-search-forward "[][(){}]" end-lim t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2959 (backward-char) )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2960 ((re-search-backward "[][(){}]" beg-lim t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2961 (t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2962 (error "No matching character on line"))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2963 (cond ((looking-at "[\(\[{]")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2964 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2965 (forward-sexp 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2966 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2967 (vip-execute-com 'vip-paren-match nil com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2968 (backward-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2969 (anchor-point
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2970 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2971 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2972 (vip-move-marker-locally 'vip-com-point anchor-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2973 (forward-char 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2974 (vip-execute-com 'vip-paren-match nil com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2975 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2976 ((looking-at "[])}]")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2977 (forward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2978 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2979 (backward-sexp 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2980 (if com (vip-execute-com 'vip-paren-match nil com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2981 (t (error ""))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2982
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2983 (defun vip-toggle-parse-sexp-ignore-comments ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2984 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2985 (setq vip-parse-sexp-ignore-comments (not vip-parse-sexp-ignore-comments))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2986 (prin1 (format "`%%' will %signore parentheses inside the comments"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2987 (if vip-parse-sexp-ignore-comments "" "NOT ")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2988 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2989
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2990
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2991 ;; sentence ,paragraph and heading
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2992
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2993 (defun vip-forward-sentence (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2994 "Forward sentence."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2995 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2996 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2997 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2998 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2999 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3000 (forward-sentence val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3001 (if com (vip-execute-com 'vip-forward-sentence nil com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3002
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3003 (defun vip-backward-sentence (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3004 "Backward sentence."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3005 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3006 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3007 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3008 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3009 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3010 (backward-sentence val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3011 (if com (vip-execute-com 'vip-backward-sentence nil com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3012
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3013 (defun vip-forward-paragraph (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3014 "Forward paragraph."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3015 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3016 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3017 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3018 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3019 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3020 (forward-paragraph val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3021 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3022 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3023 (backward-char 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3024 (vip-execute-com 'vip-forward-paragraph nil com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3025
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3026 (defun vip-backward-paragraph (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3027 "Backward paragraph."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3028 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3029 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3030 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3031 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3032 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3033 (backward-paragraph val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3034 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3035 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3036 (forward-char 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3037 (vip-execute-com 'vip-backward-paragraph nil com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3038 (backward-char 1)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3039
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3040 ;; should be mode-specific etc.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3041
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3042 (defun vip-prev-heading (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3043 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3044 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3045 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3046 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3047 (re-search-backward vip-heading-start nil t val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3048 (goto-char (match-beginning 0))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3049 (if com (vip-execute-com 'vip-prev-heading nil com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3050
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3051 (defun vip-heading-end (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3052 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3053 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3054 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3055 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3056 (re-search-forward vip-heading-end nil t val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3057 (goto-char (match-beginning 0))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3058 (if com (vip-execute-com 'vip-heading-end nil com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3059
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3060 (defun vip-next-heading (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3061 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3062 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3063 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3064 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3065 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3066 (re-search-forward vip-heading-start nil t val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3067 (goto-char (match-beginning 0))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3068 (if com (vip-execute-com 'vip-next-heading nil com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3069
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3070
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3071 ;; scrolling
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3072
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3073 (defun vip-scroll-screen (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3074 "Scroll to next screen."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3075 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3076 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3077 (if (> arg 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3078 (while (> arg 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3079 (scroll-up)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3080 (setq arg (1- arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3081 (while (> 0 arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3082 (scroll-down)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3083 (setq arg (1+ arg))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3084 (error (beep 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3085 (if (> arg 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3086 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3087 (message "End of buffer")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3088 (goto-char (point-max)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3089 (message "Beginning of buffer")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3090 (goto-char (point-min))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3091 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3092
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3093 (defun vip-scroll-screen-back (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3094 "Scroll to previous screen."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3095 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3096 (vip-scroll-screen (- arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3097
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3098 (defun vip-scroll-down (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3099 "Pull down half screen."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3100 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3101 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3102 (if (null arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3103 (scroll-down (/ (window-height) 2))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3104 (scroll-down arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3105 (error (beep 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3106 (message "Beginning of buffer")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3107 (goto-char (point-min)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3108
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3109 (defun vip-scroll-down-one (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3110 "Scroll up one line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3111 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3112 (scroll-down arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3113
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3114 (defun vip-scroll-up (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3115 "Pull up half screen."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3116 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3117 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3118 (if (null arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3119 (scroll-up (/ (window-height) 2))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3120 (scroll-up arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3121 (error (beep 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3122 (message "End of buffer")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3123 (goto-char (point-max)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3124
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3125 (defun vip-scroll-up-one (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3126 "Scroll down one line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3127 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3128 (scroll-up arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3130
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3131 ;; searching
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3132
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3133 (defun vip-if-string (prompt)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3134 (let ((s (vip-read-string-with-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3135 prompt
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3136 nil ; no initial
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3137 'vip-search-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3138 (car vip-search-history))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3139 (if (not (string= s ""))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3140 (setq vip-s-string s))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3141
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3142
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3143 (defun vip-toggle-search-style (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3144 "Toggle the value of vip-case-fold-search/vip-re-search.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3145 Without prefix argument, will ask which search style to toggle. With prefix
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3146 arg 1,toggles vip-case-fold-search; with arg 2 toggles vip-re-search.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3147
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3148 Although this function is bound to \\[vip-toggle-search-style], the most
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3149 convenient way to use it is to bind `//' to the macro
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3150 `1 M-x vip-toggle-search-style' and `///' to
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3151 `2 M-x vip-toggle-search-style'. In this way, hitting `//' quickly will
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3152 toggle case-fold-search and hitting `/' three times witth toggle regexp
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3153 search. Macros are more convenient in this case because they don't affect
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3154 the Emacs binding of `/'."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3155 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3156 (let (msg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3157 (cond ((or (eq arg 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3158 (and (null arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3159 (y-or-n-p (format "Search style: '%s'. Want '%s'? "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3160 (if vip-case-fold-search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3161 "case-insensitive" "case-sensitive")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3162 (if vip-case-fold-search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3163 "case-sensitive"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3164 "case-insensitive")))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3165 (setq vip-case-fold-search (null vip-case-fold-search))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3166 (if vip-case-fold-search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3167 (setq msg "Search becomes case-insensitive")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3168 (setq msg "Search becomes case-sensitive")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3169 ((or (eq arg 2)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3170 (and (null arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3171 (y-or-n-p (format "Search style: '%s'. Want '%s'? "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3172 (if vip-re-search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3173 "regexp-search" "vanilla-search")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3174 (if vip-re-search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3175 "vanilla-search"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3176 "regexp-search")))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3177 (setq vip-re-search (null vip-re-search))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3178 (if vip-re-search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3179 (setq msg "Search becomes regexp-style")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3180 (setq msg "Search becomes vanilla-style")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3181 (t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3182 (setq msg "Search style remains unchanged")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3183 (prin1 msg t)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3184
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3185 (defun vip-set-vi-search-style-macros (unset)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3186 "Set the macros for toggling the search style in Viper's vi-state.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3187 The macro that toggles case sensitivity is bound to `//', and the one that
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3188 toggles regexp search is bound to `///'.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3189 With a prefix argument, this function unsets the macros. "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3190 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3191 (or noninteractive
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3192 (if (not unset)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3193 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3194 ;; toggle case sensitivity in search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3195 (vip-record-kbd-macro
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3196 "//" 'vi-state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3197 [1 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return]
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3198 't)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3199 ;; toggle regexp/vanila search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3200 (vip-record-kbd-macro
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3201 "///" 'vi-state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3202 [2 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return]
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3203 't)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3204 (if (interactive-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3205 (message
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3206 "// and /// now toggle case-sensitivity and regexp search.")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3207 (vip-unrecord-kbd-macro "//" 'vi-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3208 (sit-for 2)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3209 (vip-unrecord-kbd-macro "///" 'vi-state))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3210
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3211 (defun vip-set-emacs-search-style-macros (unset &optional arg-majormode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3212 "Set the macros for toggling the search style in Viper's emacs-state.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3213 The macro that toggles case sensitivity is bound to `//', and the one that
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3214 toggles regexp search is bound to `///'.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3215 With a prefix argument, this function unsets the macros.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3216 If the optional prefix argument is non-nil and specifies a valid major mode,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3217 this sets the macros only in the macros in that major mode. Otherwise,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3218 the macros are set in the current major mode.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3219 \(When unsetting the macros, the second argument has no effect.\)"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3220 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3221 (or noninteractive
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3222 (if (not unset)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3223 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3224 ;; toggle case sensitivity in search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3225 (vip-record-kbd-macro
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3226 "//" 'emacs-state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3227 [1 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return]
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3228 (or arg-majormode major-mode))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3229 ;; toggle regexp/vanila search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3230 (vip-record-kbd-macro
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3231 "///" 'emacs-state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3232 [2 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return]
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3233 (or arg-majormode major-mode))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3234 (if (interactive-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3235 (message
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3236 "// and /// now toggle case-sensitivity and regexp search.")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3237 (vip-unrecord-kbd-macro "//" 'emacs-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3238 (sit-for 2)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3239 (vip-unrecord-kbd-macro "///" 'emacs-state))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3240
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3241
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3242 (defun vip-search-forward (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3243 "Search a string forward.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3244 ARG is used to find the ARG's occurrence of the string.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3245 Null string will repeat previous search."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3246 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3247 (let ((val (vip-P-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3248 (com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3249 (old-str vip-s-string))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3250 (setq vip-s-forward t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3251 (vip-if-string "/")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3252 ;; this is not used at present, but may be used later
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3253 (if (or (not (equal old-str vip-s-string))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3254 (not (markerp vip-local-search-start-marker))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3255 (not (marker-buffer vip-local-search-start-marker)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3256 (setq vip-local-search-start-marker (point-marker)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3257 (vip-search vip-s-string t val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3258 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3259 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3260 (vip-move-marker-locally 'vip-com-point (mark t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3261 (vip-execute-com 'vip-search-next val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3262
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3263 (defun vip-search-backward (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3264 "Search a string backward.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3265 ARG is used to find the ARG's occurrence of the string.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3266 Null string will repeat previous search."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3267 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3268 (let ((val (vip-P-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3269 (com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3270 (old-str vip-s-string))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3271 (setq vip-s-forward nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3272 (vip-if-string "?")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3273 ;; this is not used at present, but may be used later
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3274 (if (or (not (equal old-str vip-s-string))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3275 (not (markerp vip-local-search-start-marker))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3276 (not (marker-buffer vip-local-search-start-marker)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3277 (setq vip-local-search-start-marker (point-marker)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3278 (vip-search vip-s-string nil val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3279 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3280 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3281 (vip-move-marker-locally 'vip-com-point (mark t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3282 (vip-execute-com 'vip-search-next val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3283
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3284
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3285 ;; Search for COUNT's occurrence of STRING.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3286 ;; Search is forward if FORWARD is non-nil, otherwise backward.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3287 ;; INIT-POINT is the position where search is to start.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3288 ;; Arguments:
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3289 ;; (STRING FORW COUNT &optional NO-OFFSET INIT-POINT LIMIT FAIL-IF-NOT-FOUND)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3290 (defun vip-search (string forward arg
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3291 &optional no-offset init-point fail-if-not-found)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3292 (if (not (equal string ""))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3293 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3294 (com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3295 (offset (not no-offset))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3296 (case-fold-search vip-case-fold-search)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3297 (start-point (or init-point (point))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3298 (vip-deactivate-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3299 (if forward
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3300 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3301 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3302 (if offset (vip-forward-char-carefully))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3303 (if vip-re-search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3304 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3305 (re-search-forward string nil nil val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3306 (re-search-backward string))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3307 (search-forward string nil nil val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3308 (search-backward string))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3309 (if (not (equal start-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3310 (push-mark start-point t)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3311 (search-failed
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3312 (if (and (not fail-if-not-found) vip-search-wrap-around-t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3313 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3314 (message "Search wrapped around BOTTOM of buffer")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3315 (goto-char (point-min))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3316 (vip-search string forward (cons 1 com) t start-point 'fail)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3317 ;; don't wait in macros
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3318 (or executing-kbd-macro (sit-for 2))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3319 ;; delete the wrap-around message
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3320 (message "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3321 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3322 (goto-char start-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3323 (error "`%s': %s not found"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3324 string
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3325 (if vip-re-search "Pattern" "String"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3326 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3327 ;; backward
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3328 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3329 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3330 (if vip-re-search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3331 (re-search-backward string nil nil val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3332 (search-backward string nil nil val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3333 (if (not (equal start-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3334 (push-mark start-point t)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3335 (search-failed
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3336 (if (and (not fail-if-not-found) vip-search-wrap-around-t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3337 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3338 (message "Search wrapped around TOP of buffer")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3339 (goto-char (point-max))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3340 (vip-search string forward (cons 1 com) t start-point 'fail)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3341 ;; don't wait in macros
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3342 (or executing-kbd-macro (sit-for 2))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3343 ;; delete the wrap-around message
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3344 (message "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3345 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3346 (goto-char start-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3347 (error "`%s': %s not found"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3348 string
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3349 (if vip-re-search "Pattern" "String"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3350 ))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3351 ;; pull up or down if at top/bottom of window
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3352 (vip-adjust-window)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3353 ;; highlight the result of search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3354 ;; don't wait and don't highlight in macros
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3355 (or executing-kbd-macro
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3356 vip-inside-command-argument-action
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3357 (vip-flash-search-pattern))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3358 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3359
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3360 (defun vip-search-next (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3361 "Repeat previous search."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3362 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3363 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3364 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3365 (if (null vip-s-string) (error vip-NoPrevSearch))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3366 (vip-search vip-s-string vip-s-forward arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3367 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3368 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3369 (vip-move-marker-locally 'vip-com-point (mark t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3370 (vip-execute-com 'vip-search-next val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3371
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3372 (defun vip-search-Next (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3373 "Repeat previous search in the reverse direction."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3374 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3375 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3376 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3377 (if (null vip-s-string) (error vip-NoPrevSearch))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3378 (vip-search vip-s-string (not vip-s-forward) arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3379 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3380 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3381 (vip-move-marker-locally 'vip-com-point (mark t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3382 (vip-execute-com 'vip-search-Next val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3383
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3384
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3385 ;; Search contents of buffer defined by one of Viper's motion commands.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3386 ;; Repeatable via `n' and `N'.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3387 (defun vip-buffer-search-enable (&optional c)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3388 (cond (c (setq vip-buffer-search-char c))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3389 ((null vip-buffer-search-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3390 (setq vip-buffer-search-char ?g)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3391 (define-key vip-vi-basic-map
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3392 (char-to-string vip-buffer-search-char) 'vip-command-argument)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3393 (aset vip-exec-array vip-buffer-search-char 'vip-exec-buffer-search)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3394 (setq vip-prefix-commands (cons vip-buffer-search-char vip-prefix-commands)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3395
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3396 ;; This is a Viper wraper for isearch-forward.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3397 (defun vip-isearch-forward (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3398 "Do incremental search forward."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3399 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3400 ;; emacs bug workaround
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3401 (if (listp arg) (setq arg (car arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3402 (vip-exec-form-in-emacs (list 'isearch-forward arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3403
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3404 ;; This is a Viper wraper for isearch-backward."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3405 (defun vip-isearch-backward (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3406 "Do incremental search backward."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3407 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3408 ;; emacs bug workaround
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3409 (if (listp arg) (setq arg (car arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3410 (vip-exec-form-in-emacs (list 'isearch-backward arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3411
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3412
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3413 ;; visiting and killing files, buffers
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3414
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3415 (defun vip-switch-to-buffer ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3416 "Switch to buffer in the current window."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3417 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3418 (let (buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3419 (setq buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3420 (read-buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3421 (format "Switch to buffer in this window \(%s\): "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3422 (buffer-name (other-buffer (current-buffer))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3423 (switch-to-buffer buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3424 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3425
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3426 (defun vip-switch-to-buffer-other-window ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3427 "Switch to buffer in another window."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3428 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3429 (let (buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3430 (setq buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3431 (read-buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3432 (format "Switch to buffer in another window \(%s\): "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3433 (buffer-name (other-buffer (current-buffer))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3434 (switch-to-buffer-other-window buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3435 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3436
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3437 (defun vip-kill-buffer ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3438 "Kill a buffer."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3439 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3440 (let (buffer buffer-name)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3441 (setq buffer-name
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3442 (read-buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3443 (format "Kill buffer \(%s\): "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3444 (buffer-name (current-buffer)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3445 (setq buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3446 (if (null buffer-name)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3447 (current-buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3448 (get-buffer buffer-name)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3449 (if (null buffer) (error "`%s': No such buffer" buffer-name))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3450 (if (or (not (buffer-modified-p buffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3451 (y-or-n-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3452 (format
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3453 "Buffer `%s' is modified, are you sure you want to kill it? "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3454 buffer-name)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3455 (kill-buffer buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3456 (error "Buffer not killed"))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3457
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3458
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3459 (defvar vip-smart-suffix-list
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3460 '("" "tex" "c" "cc" "C" "el" "java" "html" "htm" "pl" "P" "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3461 "*List of suffixes that Viper automatically tries to append to filenames ending with a `.'.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3462 This is useful when you the current directory contains files with the same
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3463 prefix and many different suffixes. Usually, only one of the suffixes
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3464 represents an editable file. However, file completion will stop at the `.'
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3465 The smart suffix feature lets you hit RET in such a case, and Viper will
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3466 select the appropriate suffix.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3467
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3468 Suffixes are tried in the order given and the first suffix for which a
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3469 corresponding file exists is selected. If no file exists for any of the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3470 suffixes, the user is asked to confirm.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3471
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3472 To turn this feature off, set this variable to nil.")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3473
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3474 ;; Try to add suffix to files ending with a `.'
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3475 ;; Useful when the user hits RET on a non-completed file name.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3476 (defun vip-file-add-suffix ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3477 (let ((count 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3478 (len (length vip-smart-suffix-list))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3479 (file (buffer-string))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3480 found key cmd suff)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3481 (goto-char (point-max))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3482 (if (and vip-smart-suffix-list (string-match "\\.$" file))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3483 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3484 (while (and (not found) (< count len))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3485 (setq suff (nth count vip-smart-suffix-list)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3486 count (1+ count))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3487 (if (file-exists-p (format "%s%s" file suff))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3488 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3489 (setq found t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3490 (insert suff))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3491
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3492 (if found
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3493 ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3494 (vip-tmp-insert-at-eob " [Please complete file name]")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3495 (unwind-protect
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3496 (while (not (memq cmd '(exit-minibuffer vip-exit-minibuffer)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3497 (setq cmd
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3498 (key-binding (setq key (read-key-sequence nil))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3499 (cond ((eq cmd 'self-insert-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3500 (if vip-xemacs-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3501 (insert (events-to-keys key))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3502 (insert key)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3503 ((memq cmd '(exit-minibuffer vip-exit-minibuffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3504 nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3505 (t (command-execute cmd)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3506 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3507 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3508 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3509
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3510
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3511
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3512
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3513 ;; yank and pop
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3514
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3515 (defsubst vip-yank (text)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3516 "Yank TEXT silently. This works correctly with Emacs's yank-pop command."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3517 (insert text)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3518 (setq this-command 'yank))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3519
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3520 (defun vip-put-back (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3521 "Put back after point/below line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3522 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3523 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3524 (text (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3525 (cond ((vip-valid-register vip-use-register '(digit))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3526 (current-kill (- vip-use-register ?1) 'do-not-rotate))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3527 ((vip-valid-register vip-use-register)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3528 (get-register (downcase vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3529 (t (error vip-InvalidRegister vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3530 (current-kill 0))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3531 (if (null text)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3532 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3533 (let ((reg vip-use-register))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3534 (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3535 (error vip-EmptyRegister reg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3536 (error "")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3537 (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3538 (if (vip-end-with-a-newline-p text)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3539 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3540 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3541 (if (eobp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3542 (insert "\n")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3543 (forward-line 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3544 (beginning-of-line))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3545 (if (not (eolp)) (vip-forward-char-carefully)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3546 (set-marker (vip-mark-marker) (point) (current-buffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3547 (vip-set-destructive-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3548 (list 'vip-put-back val nil vip-use-register nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3549 (vip-loop val (vip-yank text)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3550 ;; Vi puts cursor on the last char when the yanked text doesn't contain a
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3551 ;; newline; it leaves the cursor at the beginning when the text contains
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3552 ;; a newline
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3553 (if (vip-same-line (point) (mark))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3554 (or (= (point) (mark)) (vip-backward-char-carefully))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3555 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3556 (if (bolp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3557 (back-to-indentation)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3558 (vip-deactivate-mark))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3559
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3560 (defun vip-Put-back (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3561 "Put back at point/above line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3562 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3563 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3564 (text (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3565 (cond ((vip-valid-register vip-use-register '(digit))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3566 (current-kill (- vip-use-register ?1) 'do-not-rotate))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3567 ((vip-valid-register vip-use-register)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3568 (get-register (downcase vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3569 (t (error vip-InvalidRegister vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3570 (current-kill 0))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3571 (if (null text)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3572 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3573 (let ((reg vip-use-register))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3574 (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3575 (error vip-EmptyRegister reg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3576 (error "")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3577 (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3578 (if (vip-end-with-a-newline-p text) (beginning-of-line))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3579 (vip-set-destructive-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3580 (list 'vip-Put-back val nil vip-use-register nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3581 (set-marker (vip-mark-marker) (point) (current-buffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3582 (vip-loop val (vip-yank text)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3583 ;; Vi puts cursor on the last char when the yanked text doesn't contain a
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3584 ;; newline; it leaves the cursor at the beginning when the text contains
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3585 ;; a newline
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3586 (if (vip-same-line (point) (mark))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3587 (or (= (point) (mark)) (vip-backward-char-carefully))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3588 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3589 (if (bolp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3590 (back-to-indentation)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3591 (vip-deactivate-mark))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3592
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3593
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3594 ;; Copy region to kill-ring.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3595 ;; If BEG and END do not belong to the same buffer, copy empty region.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3596 (defun vip-copy-region-as-kill (beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3597 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3598 (copy-region-as-kill beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3599 (error (copy-region-as-kill beg beg))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3600
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3601
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3602 (defun vip-delete-char (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3603 "Delete character."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3604 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3605 (let ((val (vip-p-val arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3606 (vip-set-destructive-command (list 'vip-delete-char val nil nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3607 (if (> val 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3608 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3609 (let ((here (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3610 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3611 (if (> val (- (point) here))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3612 (setq val (- (point) here))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3613 (if (and (eq val 0) (not vip-ex-style-motion)) (setq val 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3614 (if (and vip-ex-style-motion (eolp))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3615 (if (bolp) (error "") (setq val 0))) ; not bol---simply back 1 ch
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3616 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3617 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3618 (cond ((vip-valid-register vip-use-register '((Letter)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3619 (vip-append-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3620 (downcase vip-use-register) (point) (- (point) val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3621 ((vip-valid-register vip-use-register)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3622 (copy-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3623 vip-use-register (point) (- (point) val) nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3624 (t (error vip-InvalidRegister vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3625 (setq vip-use-register nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3626 (if vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3627 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3628 (delete-char val t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3629 (if (and (eolp) (not (bolp))) (backward-char 1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3630 (if (eolp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3631 (delete-backward-char val t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3632 (delete-char val t)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3633
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3634 (defun vip-delete-backward-char (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3635 "Delete previous character. On reaching beginning of line, stop and beep."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3636 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3637 (let ((val (vip-p-val arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3638 (vip-set-destructive-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3639 (list 'vip-delete-backward-char val nil nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3640 (if (> val 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3641 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3642 (let ((here (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3643 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3644 (if (> val (- here (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3645 (setq val (- here (point)))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3646 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3647 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3648 (cond ((vip-valid-register vip-use-register '(Letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3649 (vip-append-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3650 (downcase vip-use-register) (point) (+ (point) val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3651 ((vip-valid-register vip-use-register)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3652 (copy-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3653 vip-use-register (point) (+ (point) val) nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3654 (t (error vip-InvalidRegister vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3655 (setq vip-use-register nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3656 (if (bolp) (ding)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3657 (delete-backward-char val t))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3658
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3659 (defun vip-del-backward-char-in-insert ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3660 "Delete 1 char backwards while in insert mode."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3661 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3662 (if (and vip-ex-style-editing-in-insert (bolp))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3663 (beep 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3664 (delete-backward-char 1 t)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3665
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3666 (defun vip-del-backward-char-in-replace ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3667 "Delete one character in replace mode.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3668 If `vip-delete-backwards-in-replace' is t, then DEL key actually deletes
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3669 charecters. If it is nil, then the cursor just moves backwards, similarly
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3670 to Vi. The variable `vip-ex-style-editing-in-insert', if t, doesn't let the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3671 cursor move past the beginning of line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3672 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3673 (cond (vip-delete-backwards-in-replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3674 (cond ((not (bolp))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3675 (delete-backward-char 1 t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3676 (vip-ex-style-editing-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3677 (beep 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3678 ((bobp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3679 (beep 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3680 (t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3681 (delete-backward-char 1 t))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3682 (vip-ex-style-editing-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3683 (if (bolp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3684 (beep 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3685 (backward-char 1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3686 (t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3687 (backward-char 1))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3688
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3689
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3690
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3691 ;; join lines.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3692
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3693 (defun vip-join-lines (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3694 "Join this line to next, if ARG is nil. Otherwise, join ARG lines."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3695 (interactive "*P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3696 (let ((val (vip-P-val arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3697 (vip-set-destructive-command (list 'vip-join-lines val nil nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3698 (vip-loop (if (null val) 1 (1- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3699 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3700 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3701 (if (not (eobp))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3702 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3703 (forward-line 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3704 (delete-region (point) (1- (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3705 (fixup-whitespace)))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3706
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3707
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3708 ;; Replace state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3709
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3710 (defun vip-change (beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3711 (if (markerp beg) (setq beg (marker-position beg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3712 (if (markerp end) (setq end (marker-position end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3713 ;; beg is sometimes (mark t), which may be nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3714 (or beg (setq beg end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3715
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3716 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3717 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3718 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3719 (copy-to-register vip-use-register beg end nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3720 (setq vip-use-register nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3721 (vip-set-replace-overlay beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3722 (setq last-command nil) ; separate repl text from prev kills
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3723
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3724 (if (= (vip-replace-start) (point-max))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3725 (error "End of buffer"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3726
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3727 (setq vip-last-replace-region
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3728 (buffer-substring (vip-replace-start)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3729 (vip-replace-end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3730
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3731 ;; protect against error while inserting "@" and other disasters
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3732 ;; (e.g., read-only buff)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3733 (condition-case conds
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3734 (if (or vip-allow-multiline-replace-regions
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3735 (vip-same-line (vip-replace-start)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3736 (vip-replace-end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3737 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3738 ;; tabs cause problems in replace, so untabify
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3739 (goto-char (vip-replace-end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3740 (insert-before-markers "@") ; put placeholder after the TAB
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3741 (untabify (vip-replace-start) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3742 ;; del @, don't put on kill ring
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3743 (delete-backward-char 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3744
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3745 (vip-set-replace-overlay-glyphs
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3746 vip-replace-region-start-delimiter
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3747 vip-replace-region-end-delimiter)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3748 ;; this move takes care of the last posn in the overlay, which
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3749 ;; has to be shifted because of insert. We can't simply insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3750 ;; "$" before-markers because then overlay-start will shift the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3751 ;; beginning of the overlay in case we are replacing a single
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3752 ;; character. This fixes the bug with `s' and `cl' commands.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3753 (vip-move-replace-overlay (vip-replace-start) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3754 (goto-char (vip-replace-start))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3755 (vip-change-state-to-replace t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3756 (kill-region (vip-replace-start)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3757 (vip-replace-end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3758 (vip-hide-replace-overlay)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3759 (vip-change-state-to-insert))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3760 (error ;; make sure that the overlay doesn't stay.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3761 ;; go back to the original point
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3762 (goto-char (vip-replace-start))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3763 (vip-hide-replace-overlay)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3764 (vip-message-conditions conds))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3765
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3766
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3767 (defun vip-change-subr (beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3768 ;; beg is sometimes (mark t), which may be nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3769 (or beg (setq beg end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3770
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3771 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3772 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3773 (copy-to-register vip-use-register beg end nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3774 (setq vip-use-register nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3775 (kill-region beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3776 (setq this-command 'vip-change)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3777 (vip-yank-last-insertion))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3778
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3779 (defun vip-toggle-case (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3780 "Toggle character case."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3781 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3782 (let ((val (vip-p-val arg)) (c))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3783 (vip-set-destructive-command (list 'vip-toggle-case val nil nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3784 (while (> val 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3785 (setq c (following-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3786 (delete-char 1 nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3787 (if (eq c (upcase c))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3788 (insert-char (downcase c) 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3789 (insert-char (upcase c) 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3790 (if (eolp) (backward-char 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3791 (setq val (1- val)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3792
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3793
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3794 ;; query replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3795
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3796 (defun vip-query-replace ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3797 "Query replace.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3798 If a null string is suplied as the string to be replaced,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3799 the query replace mode will toggle between string replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3800 and regexp replace."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3801 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3802 (let (str)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3803 (setq str (vip-read-string-with-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3804 (if vip-re-query-replace "Query replace regexp: "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3805 "Query replace: ")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3806 nil ; no initial
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3807 'vip-replace1-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3808 (car vip-replace1-history) ; default
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3809 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3810 (if (string= str "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3811 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3812 (setq vip-re-query-replace (not vip-re-query-replace))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3813 (message "Query replace mode changed to %s"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3814 (if vip-re-query-replace "regexp replace"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3815 "string replace")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3816 (if vip-re-query-replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3817 (query-replace-regexp
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3818 str
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3819 (vip-read-string-with-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3820 (format "Query replace regexp `%s' with: " str)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3821 nil ; no initial
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3822 'vip-replace1-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3823 (car vip-replace1-history) ; default
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3824 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3825 (query-replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3826 str
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3827 (vip-read-string-with-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3828 (format "Query replace `%s' with: " str)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3829 nil ; no initial
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3830 'vip-replace1-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3831 (car vip-replace1-history) ; default
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3832 ))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3833
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3834
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3835 ;; marking
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3836
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3837 (defun vip-mark-beginning-of-buffer ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3838 "Mark beginning of buffer."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3839 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3840 (push-mark (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3841 (goto-char (point-min))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3842 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3843 (message "Mark set at the beginning of buffer"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3844
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3845 (defun vip-mark-end-of-buffer ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3846 "Mark end of buffer."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3847 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3848 (push-mark (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3849 (goto-char (point-max))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3850 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3851 (message "Mark set at the end of buffer"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3852
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3853 (defun vip-mark-point ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3854 "Set mark at point of buffer."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3855 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3856 (let ((char (read-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3857 (cond ((and (<= ?a char) (<= char ?z))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3858 (point-to-register (1+ (- char ?a))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3859 ((= char ?<) (vip-mark-beginning-of-buffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3860 ((= char ?>) (vip-mark-end-of-buffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3861 ((= char ?.) (vip-set-mark-if-necessary))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3862 ((= char ?,) (vip-cycle-through-mark-ring))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3863 ((= char ?D) (mark-defun))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3864 (t (error ""))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3865 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3866
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3867 ;; Algorithm: If first invocation of this command save mark on ring, goto
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3868 ;; mark, M0, and pop the most recent elt from the mark ring into mark,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3869 ;; making it into the new mark, M1.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3870 ;; Push this mark back and set mark to the original point position, p1.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3871 ;; So, if you hit '' or `` then you can return to p1.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3872 ;;
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3873 ;; If repeated command, pop top elt from the ring into mark and
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3874 ;; jump there. This forgets the position, p1, and puts M1 back into mark.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3875 ;; Then we save the current pos, which is M0, jump to M1 and pop M2 from
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3876 ;; the ring into mark. Push M2 back on the ring and set mark to M0.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3877 ;; etc.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3878 (defun vip-cycle-through-mark-ring ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3879 "Visit previous locations on the mark ring.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3880 One can use `` and '' to temporarily jump 1 step back."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3881 (let* ((sv-pt (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3882 ;; if repeated `m,' command, pop the previously saved mark.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3883 ;; Prev saved mark is actually prev saved point. It is used if the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3884 ;; user types `` or '' and is discarded
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3885 ;; from the mark ring by the next `m,' command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3886 ;; In any case, go to the previous or previously saved mark.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3887 ;; Then push the current mark (popped off the ring) and set current
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3888 ;; point to be the mark. Current pt as mark is discarded by the next
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3889 ;; m, command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3890 (if (eq last-command 'vip-cycle-through-mark-ring)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3891 ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3892 ;; save current mark if the first iteration
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3893 (setq mark-ring (delete (vip-mark-marker) mark-ring))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3894 (if (mark t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3895 (push-mark (mark t) t)) )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3896 (pop-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3897 (set-mark-command 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3898 ;; don't duplicate mark on the ring
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3899 (setq mark-ring (delete (vip-mark-marker) mark-ring))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3900 (push-mark sv-pt t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3901 (vip-deactivate-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3902 (setq this-command 'vip-cycle-through-mark-ring)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3903 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3904
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3905
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3906 (defun vip-goto-mark (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3907 "Go to mark."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3908 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3909 (let ((char (read-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3910 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3911 (vip-goto-mark-subr char com nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3912
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3913 (defun vip-goto-mark-and-skip-white (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3914 "Go to mark and skip to first non-white character on line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3915 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3916 (let ((char (read-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3917 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3918 (vip-goto-mark-subr char com t)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3919
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3920 (defun vip-goto-mark-subr (char com skip-white)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3921 (if (eobp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3922 (if (bobp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3923 (error "Empty buffer")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3924 (backward-char 1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3925 (cond ((vip-valid-register char '(letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3926 (let* ((buff (current-buffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3927 (reg (1+ (- char ?a)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3928 (text-marker (get-register reg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3929 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3930 (if (not (vip-valid-marker text-marker))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3931 (error vip-EmptyTextmarker char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3932 (if (and (vip-same-line (point) vip-last-jump)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3933 (= (point) vip-last-jump-ignore))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3934 (push-mark vip-last-jump t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3935 (push-mark nil t)) ; no msg
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3936 (vip-register-to-point reg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3937 (setq vip-last-jump (point-marker))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3938 (cond (skip-white
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3939 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3940 (setq vip-last-jump-ignore (point))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3941 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3942 (if (equal buff (current-buffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3943 (vip-execute-com (if skip-white
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3944 'vip-goto-mark-and-skip-white
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3945 'vip-goto-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3946 nil com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3947 (switch-to-buffer buff)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3948 (goto-char vip-com-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3949 (vip-change-state-to-vi)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3950 (error "")))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3951 ((and (not skip-white) (= char ?`))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3952 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3953 (if (and (vip-same-line (point) vip-last-jump)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3954 (= (point) vip-last-jump-ignore))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3955 (goto-char vip-last-jump))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3956 (if (null (mark t)) (error "Mark is not set in this buffer"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3957 (if (= (point) (mark t)) (pop-mark))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3958 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3959 (setq vip-last-jump (point-marker)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3960 vip-last-jump-ignore 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3961 (if com (vip-execute-com 'vip-goto-mark nil com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3962 ((and skip-white (= char ?'))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3963 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3964 (if (and (vip-same-line (point) vip-last-jump)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3965 (= (point) vip-last-jump-ignore))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3966 (goto-char vip-last-jump))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3967 (if (= (point) (mark t)) (pop-mark))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3968 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3969 (setq vip-last-jump (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3970 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3971 (setq vip-last-jump-ignore (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3972 (if com (vip-execute-com 'vip-goto-mark-and-skip-white nil com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3973 (t (error vip-InvalidTextmarker char))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3974
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3975 (defun vip-insert-tab ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3976 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3977 (insert-tab))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3978
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3979 (defun vip-exchange-point-and-mark ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3980 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3981 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3982 (back-to-indentation))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3983
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3984 ;; Input Mode Indentation
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3985
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3986 ;; Returns t, if the string before point matches the regexp STR.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3987 (defsubst vip-looking-back (str)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3988 (and (save-excursion (re-search-backward str nil t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3989 (= (point) (match-end 0))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3990
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3991
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3992 (defun vip-forward-indent ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3993 "Indent forward -- `C-t' in Vi."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3994 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3995 (setq vip-cted t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3996 (indent-to (+ (current-column) vip-shift-width)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3997
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3998 (defun vip-backward-indent ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3999 "Backtab, C-d in VI"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4000 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4001 (if vip-cted
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4002 (let ((p (point)) (c (current-column)) bol (indent t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4003 (if (vip-looking-back "[0^]")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4004 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4005 (if (eq ?^ (preceding-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4006 (setq vip-preserve-indent t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4007 (delete-backward-char 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4008 (setq p (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4009 (setq indent nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4010 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4011 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4012 (setq bol (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4013 (if (re-search-backward "[^ \t]" bol 1) (forward-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4014 (delete-region (point) p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4015 (if indent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4016 (indent-to (- c vip-shift-width)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4017 (if (or (bolp) (vip-looking-back "[^ \t]"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4018 (setq vip-cted nil)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4019
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4020 (defun vip-autoindent ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4021 "Auto Indentation, Vi-style."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4022 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4023 (let ((col (current-indentation)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4024 (if abbrev-mode (expand-abbrev))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4025 (if vip-preserve-indent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4026 (setq vip-preserve-indent nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4027 (setq vip-current-indent col))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4028 ;; don't leave whitespace lines around
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4029 (if (memq last-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4030 '(vip-autoindent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4031 vip-open-line vip-Open-line
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4032 vip-replace-state-exit-cmd))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4033 (indent-to-left-margin))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4034 ;; use \n instead of newline, or else <Return> will move the insert point
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4035 ;;(newline 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4036 (insert "\n")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4037 (if vip-auto-indent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4038 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4039 (setq vip-cted t)
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4040 (if (and vip-electric-mode
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4041 (not (eq major-mode 'fundamental-mode)))
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4042 (indent-according-to-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4043 (indent-to vip-current-indent))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4044 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4045 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4046
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4047
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4048 ;; Viewing registers
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4049
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4050 (defun vip-ket-function (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4051 "Function called by \], the ket. View registers and call \]\]."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4052 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4053 (let ((reg (read-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4054 (cond ((vip-valid-register reg '(letter Letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4055 (view-register (downcase reg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4056 ((vip-valid-register reg '(digit))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4057 (let ((text (current-kill (- reg ?1) 'do-not-rotate)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4058 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4059 (set-buffer (get-buffer-create "*Output*"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4060 (delete-region (point-min) (point-max))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4061 (insert (format "Register %c contains the string:\n" reg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4062 (insert text)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4063 (goto-char (point-min)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4064 (display-buffer "*Output*")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4065 ((= ?\] reg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4066 (vip-next-heading arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4067 (t (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4068 vip-InvalidRegister reg)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4069
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4070 (defun vip-brac-function (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4071 "Function called by \[, the brac. View textmarkers and call \[\["
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4072 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4073 (let ((reg (read-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4074 (cond ((= ?\[ reg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4075 (vip-prev-heading arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4076 ((= ?\] reg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4077 (vip-heading-end arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4078 ((vip-valid-register reg '(letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4079 (let* ((val (get-register (1+ (- reg ?a))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4080 (buf (if (not val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4081 (error vip-EmptyTextmarker reg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4082 (marker-buffer val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4083 (pos (marker-position val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4084 line-no text (s pos) (e pos))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4085 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4086 (set-buffer (get-buffer-create "*Output*"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4087 (delete-region (point-min) (point-max))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4088 (if (and buf pos)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4089 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4090 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4091 (set-buffer buf)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4092 (setq line-no (1+ (count-lines (point-min) val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4093 (goto-char pos)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4094 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4095 (if (re-search-backward "[^ \t]" nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4096 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4097 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4098 (setq s (point))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4099 (goto-char pos)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4100 (forward-line 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4101 (if (re-search-forward "[^ \t]" nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4102 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4103 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4104 (setq e (point))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4105 (setq text (buffer-substring s e))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4106 (setq text (format "%s<%c>%s"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4107 (substring text 0 (- pos s))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4108 reg (substring text (- pos s)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4109 (insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4110 (format
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4111 "Textmarker `%c' is in buffer `%s' at line %d.\n"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4112 reg (buffer-name buf) line-no))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4113 (insert (format "Here is some text around %c:\n\n %s"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4114 reg text)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4115 (insert (format vip-EmptyTextmarker reg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4116 (goto-char (point-min)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4117 (display-buffer "*Output*")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4118 (t (error vip-InvalidTextmarker reg)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4119
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4120
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4121
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4122 ;; commands in insertion mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4123
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4124 (defun vip-delete-backward-word (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4125 "Delete previous word."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4126 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4127 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4128 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4129 (backward-word arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4130 (delete-region (point) (mark t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4131 (pop-mark)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4132
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4133
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4134 (defun vip-set-expert-level (&optional dont-change-unless)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4135 "Sets the expert level for a Viper user.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4136 Can be called interactively to change (temporarily or permanently) the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4137 current expert level.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4138
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4139 The optional argument DONT-CHANGE-UNLESS, if not nil, says that
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4140 the level should not be changed, unless its current value is
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4141 meaningless (i.e., not one of 1,2,3,4,5).
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4142
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4143 User level determines the setting of Viper variables that are most
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4144 sensitive for VI-style look-and-feel."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4145
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4146 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4147
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4148 (if (not (natnump vip-expert-level)) (setq vip-expert-level 0))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4149
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4150 (save-window-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4151 (delete-other-windows)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4152 ;; if 0 < vip-expert-level < vip-max-expert-level
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4153 ;; & dont-change-unless = t -- use it; else ask
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4154 (vip-ask-level dont-change-unless))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4155
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4156 (setq viper-always t
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4157 vip-ex-style-motion t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4158 vip-ex-style-editing-in-insert t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4159 vip-want-ctl-h-help nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4160
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4161 (cond ((eq vip-expert-level 1) ; novice or beginner
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4162 (global-set-key ; in emacs-state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4163 vip-toggle-key
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4164 (if (vip-window-display-p) 'vip-iconify 'suspend-emacs))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4165 (setq vip-no-multiple-ESC t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4166 vip-re-search t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4167 vip-vi-style-in-minibuffer t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4168 vip-search-wrap-around-t t
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4169 vip-electric-mode nil
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4170 vip-want-emacs-keys-in-vi nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4171 vip-want-emacs-keys-in-insert nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4172
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4173 ((and (> vip-expert-level 1) (< vip-expert-level 5))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4174 ;; intermediate to guru
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4175 (setq vip-no-multiple-ESC (if (vip-window-display-p)
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4176 t 'twice)
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4177 vip-electric-mode t
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4178 vip-want-emacs-keys-in-vi t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4179 vip-want-emacs-keys-in-insert (> vip-expert-level 2))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4180
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4181 (if (eq vip-expert-level 4) ; respect user's ex-style motion
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4182 ; and vip-no-multiple-ESC
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4183 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4184 (setq-default vip-ex-style-editing-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4185 (cdr (assoc 'vip-ex-style-editing-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4186 vip-saved-user-settings))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4187 vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4188 (cdr (assoc 'vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4189 vip-saved-user-settings)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4190 (setq vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4191 (cdr (assoc 'vip-ex-style-motion vip-saved-user-settings))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4192 vip-ex-style-editing-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4193 (cdr (assoc 'vip-ex-style-editing-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4194 vip-saved-user-settings))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4195 vip-re-search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4196 (cdr (assoc 'vip-re-search vip-saved-user-settings))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4197 vip-no-multiple-ESC
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4198 (cdr (assoc 'vip-no-multiple-ESC
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4199 vip-saved-user-settings))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4200
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4201 ;; A wizard!!
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4202 ;; Ideally, if 5 is selected, a buffer should pop up to let the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4203 ;; user toggle the values of variables.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4204 (t (setq-default vip-ex-style-editing-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4205 (cdr (assoc 'vip-ex-style-editing-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4206 vip-saved-user-settings))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4207 vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4208 (cdr (assoc 'vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4209 vip-saved-user-settings)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4210 (setq vip-want-ctl-h-help
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4211 (cdr (assoc 'vip-want-ctl-h-help vip-saved-user-settings))
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4212 viper-always
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4213 (cdr (assoc 'viper-always vip-saved-user-settings))
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4214 vip-no-multiple-ESC
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4215 (cdr (assoc 'vip-no-multiple-ESC vip-saved-user-settings))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4216 vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4217 (cdr (assoc 'vip-ex-style-motion vip-saved-user-settings))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4218 vip-ex-style-editing-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4219 (cdr (assoc 'vip-ex-style-editing-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4220 vip-saved-user-settings))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4221 vip-re-search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4222 (cdr (assoc 'vip-re-search vip-saved-user-settings))
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4223 vip-electric-mode
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4224 (cdr (assoc 'vip-electric-mode
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4225 vip-saved-user-settings))
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4226 vip-want-emacs-keys-in-vi
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4227 (cdr (assoc 'vip-want-emacs-keys-in-vi
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4228 vip-saved-user-settings))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4229 vip-want-emacs-keys-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4230 (cdr (assoc 'vip-want-emacs-keys-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4231 vip-saved-user-settings)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4232 (vip-set-mode-vars-for vip-current-state)
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4233 (if (or viper-always
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4234 (and (> vip-expert-level 0) (> 5 vip-expert-level)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4235 (vip-set-hooks)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4236
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4237 ;; Ask user expert level.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4238 (defun vip-ask-level (dont-change-unless)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4239 (let ((ask-buffer " *vip-ask-level*")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4240 level-changed repeated)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4241 (save-window-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4242 (switch-to-buffer ask-buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4243
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4244 (or (eq this-command 'vip-set-expert-level)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4245 (and
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4246 (<= vip-expert-level vip-max-expert-level)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4247 (>= vip-expert-level 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4248 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4249 (insert "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4250
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4251 *** Important Notice for VIP users***
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4252
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4253 This is VIPER
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4254
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4255 @joke
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4256 Viper Is a Package for Emacs Rebels,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4257 a VI Plan for Emacs Rescue,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4258 and a venomous VI PERil.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4259 @end joke
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4260
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4261 Technically speaking, Viper is a new Vi emulator that replaces
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4262 the old VIP package.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4263
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4264 Viper emulates Vi much better than VIP. It also significantly
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4265 extends and improves upon Vi in many useful ways.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4266
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4267 Although many VIP settings in your ~/.vip are compatible with Viper,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4268 you may have to change some of them. Please refer to the documentation,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4269 which can be obtained by executing
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4270
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4271 :help
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4272
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4273 when Viper is in Vi state.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4274
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4275 If you will be so lucky as to find a bug, report it via the command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4276
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4277 :submitReport
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4278
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4279 Type any key to continue... ")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4280
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4281 (read-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4282 (erase-buffer)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4283
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4284 (while (or (> vip-expert-level vip-max-expert-level)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4285 (< vip-expert-level 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4286 (null dont-change-unless))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4287 (erase-buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4288 (if repeated
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4289 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4290 (message "Invalid user level")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4291 (beep 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4292 (setq repeated t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4293 (setq dont-change-unless t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4294 level-changed t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4295 (insert "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4296 Please specify your level of familiarity with the venomous VI PERil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4297 (and the VI Plan for Emacs Rescue).
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4298 You can change it at any time by typing `M-x vip-set-expert-level RET'
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4299
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4300 1 -- BEGINNER: Almost all Emacs features are suppressed.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4301 Feels almost like straight Vi. File name completion and
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4302 command history in the minibuffer are thrown in as a bonus.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4303 To use Emacs productively, you must reach level 3 or higher.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4304 2 -- MASTER: C-c now has its standard Emacs meaning in Vi command state,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4305 so most Emacs commands can be used when Viper is in Vi state.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4306 Good progress---you are well on the way to level 3!
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4307 3 -- GRAND MASTER: Like 3, but most Emacs commands are available also
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4308 in Viper's insert state.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4309 4 -- GURU: Like 3, but user settings are respected for vip-no-multiple-ESC,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4310 vip-re-search, vip-ex-style-motion, & vip-ex-style-editing-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4311 variables. Adjust these settings to your taste.
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4312 5 -- WIZARD: Like 4, but user settings are also respected for viper-always,
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4313 vip-electric-mode, vip-want-ctl-h-help, vip-want-emacs-keys-in-vi,
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4314 and vip-want-emacs-keys-in-insert. Adjust these to your taste.
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4315
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4316 Please, specify your level now: ")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4317
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4318 (setq vip-expert-level (- (vip-read-char-exclusive) ?0))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4319 ) ; end while
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4320
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4321 ;; tell the user if level was changed
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4322 (and level-changed
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4323 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4324 (insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4325 (format "\n\n\n\n\n\t\tYou have selected user level %d"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4326 vip-expert-level))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4327 (if (y-or-n-p "Do you wish to make this change permanent? ")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4328 ;; save the setting for vip-expert-level
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4329 (vip-save-setting
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4330 'vip-expert-level
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4331 (format "Saving user level %d ..." vip-expert-level)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4332 vip-custom-file-name))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4333 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4334 (bury-buffer) ; remove ask-buffer from screen
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4335 (message "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4336 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4337
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4338
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4339 (defun vip-nil ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4340 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4341 (beep 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4342
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4343
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4344 ;; if ENFORCE-BUFFER is not nil, error if CHAR is a marker in another buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4345 (defun vip-register-to-point (char &optional enforce-buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4346 "Like jump-to-register, but switches to another buffer in another window."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4347 (interactive "cViper register to point: ")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4348 (let ((val (get-register char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4349 (cond
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4350 ((and (fboundp 'frame-configuration-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4351 (frame-configuration-p val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4352 (set-frame-configuration val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4353 ((window-configuration-p val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4354 (set-window-configuration val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4355 ((vip-valid-marker val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4356 (if (and enforce-buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4357 (not (equal (current-buffer) (marker-buffer val))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4358 (error (concat vip-EmptyTextmarker " in this buffer")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4359 (1- (+ char ?a))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4360 (pop-to-buffer (marker-buffer val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4361 (goto-char val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4362 ((and (consp val) (eq (car val) 'file))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4363 (find-file (cdr val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4364 (t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4365 (error vip-EmptyTextmarker (1- (+ char ?a)))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4366
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4367
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4368 (defun vip-save-kill-buffer ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4369 "Save then kill current buffer. "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4370 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4371 (if (< vip-expert-level 2)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4372 (save-buffers-kill-emacs)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4373 (save-buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4374 (kill-buffer (current-buffer))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4375
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4376
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4377
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4378 ;;; Bug Report
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4379
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4380 (defun vip-submit-report ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4381 "Submit bug report on Viper."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4382 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4383 (let ((reporter-prompt-for-summary-p t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4384 (vip-device-type (vip-device-type))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4385 color-display-p frame-parameters
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4386 minibuffer-emacs-face minibuffer-vi-face minibuffer-insert-face
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4387 varlist salutation window-config)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4388
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4389 ;; If mode info is needed, add variable to `let' and then set it below,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4390 ;; like we did with color-display-p.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4391 (setq color-display-p (if (vip-window-display-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4392 (vip-color-display-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4393 'non-x)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4394 minibuffer-vi-face (if (vip-has-face-support-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4395 (vip-get-face vip-minibuffer-vi-face)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4396 'non-x)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4397 minibuffer-insert-face (if (vip-has-face-support-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4398 (vip-get-face vip-minibuffer-insert-face)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4399 'non-x)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4400 minibuffer-emacs-face (if (vip-has-face-support-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4401 (vip-get-face vip-minibuffer-emacs-face)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4402 'non-x)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4403 frame-parameters (if (fboundp 'frame-parameters)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4404 (frame-parameters (selected-frame))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4405
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4406 (setq varlist (list 'vip-vi-minibuffer-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4407 'vip-insert-minibuffer-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4408 'vip-vi-intercept-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4409 'vip-vi-local-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4410 'vip-vi-kbd-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4411 'vip-vi-global-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4412 'vip-vi-state-modifier-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4413 'vip-vi-diehard-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4414 'vip-vi-basic-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4415 'vip-replace-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4416 'vip-insert-intercept-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4417 'vip-insert-local-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4418 'vip-insert-kbd-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4419 'vip-insert-global-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4420 'vip-insert-state-modifier-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4421 'vip-insert-diehard-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4422 'vip-insert-basic-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4423 'vip-emacs-intercept-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4424 'vip-emacs-local-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4425 'vip-emacs-kbd-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4426 'vip-emacs-global-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4427 'vip-emacs-state-modifier-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4428 'vip-automatic-iso-accents
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4429 'vip-want-emacs-keys-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4430 'vip-want-emacs-keys-in-vi
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4431 'vip-keep-point-on-undo
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4432 'vip-no-multiple-ESC
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4433 'vip-electric-mode
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4434 'vip-ESC-key
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4435 'vip-want-ctl-h-help
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4436 'vip-ex-style-editing-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4437 'vip-delete-backwards-in-replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4438 'vip-vi-style-in-minibuffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4439 'vip-vi-state-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4440 'vip-insert-state-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4441 'vip-replace-state-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4442 'vip-emacs-state-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4443 'ex-cycle-other-window
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4444 'ex-cycle-through-non-files
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4445 'vip-expert-level
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4446 'major-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4447 'vip-device-type
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4448 'color-display-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4449 'frame-parameters
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4450 'minibuffer-vi-face
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4451 'minibuffer-insert-face
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4452 'minibuffer-emacs-face
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4453 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4454 (setq salutation "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4455 Congratulations! You may have unearthed a bug in Viper!
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4456 Please mail a concise, accurate summary of the problem to the address above.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4457
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4458 -------------------------------------------------------------------")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4459 (setq window-config (current-window-configuration))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4460 (with-output-to-temp-buffer " *vip-info*"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4461 (switch-to-buffer " *vip-info*")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4462 (delete-other-windows)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4463 (princ "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4464 PLEASE FOLLOW THESE PROCEDURES
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4465 ------------------------------
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4466
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4467 Before reporting a bug, please verify that it is related to Viper, and is
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4468 not cause by other packages you are using.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4469
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4470 Don't report compilation warnings, unless you are certain that there is a
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4471 problem. These warnings are normal and unavoidable.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4472
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4473 Please note that users should not modify variables and keymaps other than
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4474 those advertised in the manual. Such `customization' is likely to crash
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4475 Viper, as it would any other improperly customized Emacs package.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4476
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4477 If you are reporting an error message received while executing one of the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4478 Viper commands, type:
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4479
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4480 M-x set-variable <Return> debug-on-error <Return> t <Return>
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4481
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4482 Then reproduce the error. The above command will cause Emacs to produce a
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4483 back trace of the execution that leads to the error. Please include this
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4484 trace in your bug report.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4485
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4486 If you believe that one of Viper's commands goes into an infinite loop
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4487 \(e.g., Emacs freezes\), type:
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4488
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4489 M-x set-variable <Return> debug-on-quit <Return> t <Return>
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4490
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4491 Then reproduce the problem. Wait for a few seconds, then type C-g to abort
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4492 the current command. Include the resulting back trace in the bug report.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4493
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4494 Mail anyway (y or n)? ")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4495 (if (y-or-n-p "Mail anyway? ")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4496 ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4497 (set-window-configuration window-config)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4498 (error "Bug report aborted")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4499
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4500 (require 'reporter)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4501 (set-window-configuration window-config)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4502
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4503 (reporter-submit-bug-report "kifer@cs.sunysb.edu"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4504 (vip-version)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4505 varlist
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4506 nil 'delete-other-windows
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4507 salutation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4508 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4509
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4510
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4511
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4512
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4513 ;; Smoothes out the difference between Emacs' unread-command-events
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4514 ;; and XEmacs unread-command-event. Arg is a character, an event, a list of
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4515 ;; events or a sequence of keys.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4516 ;;
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4517 ;; Due to the way unread-command-events in Emacs (not XEmacs), a non-event
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4518 ;; symbol in unread-command-events list may cause Emacs to turn this symbol
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4519 ;; into an event. Below, we delete nil from event lists, since nil is the most
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4520 ;; common symbol that might appear in this wrong context.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4521 (defun vip-set-unread-command-events (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4522 (if vip-emacs-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4523 (setq
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4524 unread-command-events
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4525 (let ((new-events
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4526 (cond ((eventp arg) (list arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4527 ((listp arg) arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4528 ((sequencep arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4529 (listify-key-sequence arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4530 (t (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4531 "vip-set-unread-command-events: Invalid argument, %S"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4532 arg)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4533 (if (not (eventp nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4534 (setq new-events (delq nil new-events)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4535 (append new-events unread-command-events)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4536 ;; XEmacs
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4537 (setq
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4538 unread-command-events
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4539 (append
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4540 (cond ((vip-characterp arg) (list (character-to-event arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4541 ((eventp arg) (list arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4542 ((stringp arg) (mapcar 'character-to-event arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4543 ((vectorp arg) (append arg nil)) ; turn into list
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4544 ((listp arg) (vip-eventify-list-xemacs arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4545 (t (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4546 "vip-set-unread-command-events: Invalid argument, %S" arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4547 unread-command-events))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4548
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4549 ;; list is assumed to be a list of events of characters
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4550 (defun vip-eventify-list-xemacs (lis)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4551 (mapcar
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4552 (function (lambda (elt)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4553 (cond ((vip-characterp elt) (character-to-event elt))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4554 ((eventp elt) elt)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4555 (t (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4556 "vip-eventify-list-xemacs: can't convert to event, %S"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4557 elt)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4558 lis))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4559
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4560
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4561
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4562 ;;; viper-cmd.el ends here