annotate lisp/emulation/viper-cmd.el @ 18999:4d5237dec736 libc-970727 libc-970728

Recognize SunOS 3.x.
author Per Bothner <bothner@cygnus.com>
date Sat, 26 Jul 1997 19:01:01 +0000
parents 506ec0258d63
children 46326a66c27c
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)
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
16 (defvar vip-mode-string)
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
17 (defvar vip-custom-file-name)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
18 (defvar iso-accents-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
19 (defvar zmacs-region-stays)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
20 (defvar mark-even-if-inactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
21
18172
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
22 ;; loading happens only in non-interactive compilation
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
23 ;; in order to spare non-viperized emacs from being viperized
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
24 (if noninteractive
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
25 (eval-when-compile
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
26 (let ((load-path (cons (expand-file-name ".") load-path)))
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
27 (or (featurep 'viper-util)
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
28 (load "viper-util.el" nil nil 'nosuffix))
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
29 (or (featurep 'viper-keym)
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
30 (load "viper-keym.el" nil nil 'nosuffix))
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
31 (or (featurep 'viper-mous)
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
32 (load "viper-mous.el" nil nil 'nosuffix))
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
33 (or (featurep 'viper-macs)
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
34 (load "viper-macs.el" nil nil 'nosuffix))
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
35 (or (featurep 'viper-ex)
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
36 (load "viper-ex.el" nil nil 'nosuffix))
e145ccc61a22 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18151
diff changeset
37 )))
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
38 ;; end pacifier
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
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
41 (require 'viper-util)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
42 (require 'viper-keym)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
43 (require 'viper-mous)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
44 (require 'viper-macs)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
45 (require 'viper-ex)
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
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
49 ;; Generic predicates
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
50
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
51 ;; 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
52
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
53 ;; generate test functions
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
54 ;; 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
55 ;; Viper command keys
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
56 ;; (macroexpand '(vip-test-com-defun foo))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
57 ;; (defun foo-p (com) (consp (memq (if (< com 0) (- com) com) foos)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
58
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
59 (defmacro vip-test-com-defun (name)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
60 (let* ((snm (symbol-name name))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
61 (nm-p (intern (concat snm "-p")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
62 (nms (intern (concat snm "s"))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
63 (` (defun (, nm-p) (com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
64 (consp (memq (if (< com 0) (- com) com) (, nms)))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
65
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
66 ;; Variables for defining VI commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
67
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
68 ;; Modifying commands that can be prefixes to movement commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
69 (defconst vip-prefix-commands '(?c ?d ?y ?! ?= ?# ?< ?> ?\"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
70 ;; define vip-prefix-command-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
71 (vip-test-com-defun vip-prefix-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
72
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
73 ;; 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
74 (defconst vip-charpair-commands '(?c ?d ?y ?! ?= ?< ?> ?r ?R))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
75 ;; define vip-charpair-command-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
76 (vip-test-com-defun vip-charpair-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
77
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
78 (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
79 ?H ?M ?L ?n ?t ?T ?w ?W ?$ ?%
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
80 ?^ ?( ?) ?- ?+ ?| ?{ ?} ?[ ?] ?' ?`
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
81 ?; ?, ?0 ?? ?/ ?\C-m ?\
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
82 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
83 "Movement commands")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
84 ;; define vip-movement-command-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
85 (vip-test-com-defun vip-movement-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
86
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
87 ;; Vi digit commands
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
88 (defconst vip-digit-commands '(?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
89
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
90 ;; define vip-digit-command-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
91 (vip-test-com-defun vip-digit-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
92
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
93 ;; Commands that can be repeated by . (dotted)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
94 (defconst vip-dotable-commands '(?c ?d ?C ?s ?S ?D ?> ?<))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
95 ;; define vip-dotable-command-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
96 (vip-test-com-defun vip-dotable-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
97
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
98 ;; Commands that can follow a #
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
99 (defconst vip-hash-commands '(?c ?C ?g ?q ?s))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
100 ;; define vip-hash-command-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
101 (vip-test-com-defun vip-hash-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
102
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
103 ;; Commands that may have registers as prefix
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
104 (defconst vip-regsuffix-commands '(?d ?y ?Y ?D ?p ?P ?x ?X))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
105 ;; define vip-regsuffix-command-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
106 (vip-test-com-defun vip-regsuffix-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
107
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
108 (defconst vip-vi-commands (append vip-movement-commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
109 vip-digit-commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
110 vip-dotable-commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
111 vip-charpair-commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
112 vip-hash-commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
113 vip-prefix-commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
114 vip-regsuffix-commands)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
115 "The list of all commands in Vi-state.")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
116 ;; define vip-vi-command-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
117 (vip-test-com-defun vip-vi-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
118
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 ;;; CODE
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 ;; sentinels
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
123
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
124 ;; Runs vip-after-change-functions inside after-change-functions
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
125 (defun vip-after-change-sentinel (beg end len)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
126 (let ((list vip-after-change-functions))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
127 (while list
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
128 (funcall (car list) beg end len)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
129 (setq list (cdr list)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
130
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
131 ;; Runs vip-before-change-functions inside before-change-functions
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
132 (defun vip-before-change-sentinel (beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
133 (let ((list vip-before-change-functions))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
134 (while list
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
135 (funcall (car list) beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
136 (setq list (cdr list)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
137
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
138 (defsubst vip-post-command-sentinel ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
139 (run-hooks 'vip-post-command-hooks))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
140
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
141 (defsubst vip-pre-command-sentinel ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
142 (run-hooks 'vip-pre-command-hooks))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
143
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
144 ;; Needed so that Viper will be able to figure the last inserted
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
145 ;; chunk of text with reasonable accuracy.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
146 (defsubst vip-insert-state-post-command-sentinel ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
147 (if (and (memq vip-current-state '(insert-state replace-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
148 vip-insert-point
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
149 (>= (point) vip-insert-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
150 (setq vip-last-posn-while-in-insert-state (point-marker)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
151 (if (eq vip-current-state 'insert-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
152 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
153 (or (stringp vip-saved-cursor-color)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
154 (string= (vip-get-cursor-color) vip-insert-state-cursor-color)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
155 (setq vip-saved-cursor-color (vip-get-cursor-color)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
156 (if (stringp vip-saved-cursor-color)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
157 (vip-change-cursor-color vip-insert-state-cursor-color))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
158 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
159 (if (and (eq this-command 'dabbrev-expand)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
160 (integerp vip-pre-command-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
161 (> vip-insert-point vip-pre-command-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
162 (move-marker vip-insert-point vip-pre-command-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
163 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
164
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
165 (defsubst vip-insert-state-pre-command-sentinel ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
166 (or (memq this-command '(self-insert-command))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
167 (memq (vip-event-key last-command-event)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
168 '(up down left right (meta f) (meta b)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
169 (control n) (control p) (control f) (control b)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
170 (vip-restore-cursor-color-after-insert))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
171 (if (and (eq this-command 'dabbrev-expand)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
172 (markerp vip-insert-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
173 (marker-position vip-insert-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
174 (setq vip-pre-command-point (marker-position vip-insert-point))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
175
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
176 (defsubst vip-R-state-post-command-sentinel ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
177 ;; Restoring cursor color is needed despite
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
178 ;; 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
179 ;; 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
180 ;; 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
181 ;; the point outside the replacement region, then the cursor color will
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
182 ;; remain red. Restoring the default, below, prevents this.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
183 (if (and (<= (vip-replace-start) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
184 (<= (point) (vip-replace-end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
185 (vip-change-cursor-color vip-replace-overlay-cursor-color)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
186 (vip-restore-cursor-color-after-replace)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
187 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
188
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
189 ;; to speed up, don't change cursor color before self-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
190 ;; and common move commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
191 (defsubst vip-replace-state-pre-command-sentinel ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
192 (or (memq this-command '(self-insert-command))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
193 (memq (vip-event-key last-command-event)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
194 '(up down left right (meta f) (meta b)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
195 (control n) (control p) (control f) (control b)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
196 (vip-restore-cursor-color-after-replace)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
197
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
198 (defun vip-replace-state-post-command-sentinel ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
199 ;; Restoring cursor color is needed despite
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
200 ;; vip-replace-state-pre-command-sentinel: When one jumps to another buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
201 ;; 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
202 ;; 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
203 ;; we set the point outside the replacement region, then the cursor color
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
204 ;; will remain red. Restoring the default, below, fixes this problem.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
205 ;;
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
206 ;; 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
207 ;; 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
208 ;; in vip-finish-change
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
209 (or (memq this-command '(self-insert-command))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
210 (vip-restore-cursor-color-after-replace))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
211 (cond
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
212 ((eq vip-current-state 'replace-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
213 ;; delete characters to compensate for inserted chars.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
214 (let ((replace-boundary (vip-replace-end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
215 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
216 (goto-char vip-last-posn-in-replace-region)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
217 (delete-char vip-replace-chars-to-delete)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
218 (setq vip-replace-chars-to-delete 0
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
219 vip-replace-chars-deleted 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
220 ;; terminate replace mode if reached replace limit
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
221 (if (= vip-last-posn-in-replace-region
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
222 (vip-replace-end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
223 (vip-finish-change vip-last-posn-in-replace-region)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
224
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
225 (if (and (<= (vip-replace-start) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
226 (<= (point) replace-boundary))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
227 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
228 ;; the state may have changed in vip-finish-change above
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
229 (if (eq vip-current-state 'replace-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
230 (vip-change-cursor-color vip-replace-overlay-cursor-color))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
231 (setq vip-last-posn-in-replace-region (point-marker))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
232 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
233
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
234 (t ;; terminate replace mode if changed Viper states.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
235 (vip-finish-change vip-last-posn-in-replace-region))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
236
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 ;; changing mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
239
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
240 ;; 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
241 (defun vip-change-state (new-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
242 ;; Keep vip-post/pre-command-hooks fresh.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
243 ;; 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
244 ;; desirable that vip-pre-command-sentinel is the last hook and
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
245 ;; vip-post-command-sentinel is the first hook.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
246 (remove-hook 'post-command-hook 'vip-post-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
247 (add-hook 'post-command-hook 'vip-post-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
248 (remove-hook 'pre-command-hook 'vip-pre-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
249 (add-hook 'pre-command-hook 'vip-pre-command-sentinel t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
250 ;; These hooks will be added back if switching to insert/replace mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
251 (vip-remove-hook 'vip-post-command-hooks
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
252 'vip-insert-state-post-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
253 (vip-remove-hook 'vip-pre-command-hooks
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
254 'vip-insert-state-pre-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
255 (cond ((eq new-state 'vi-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
256 (cond ((member vip-current-state '(insert-state replace-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
257
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
258 ;; move vip-last-posn-while-in-insert-state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
259 ;; This is a normal hook that is executed in insert/replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
260 ;; states after each command. In Vi/Emacs state, it does
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
261 ;; nothing. We need to execute it here to make sure that
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
262 ;; the last posn was recorded when we hit ESC.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
263 ;; It may be left unrecorded if the last thing done in
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
264 ;; insert/repl state was dabbrev-expansion or abbrev
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
265 ;; expansion caused by hitting ESC
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
266 (vip-insert-state-post-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
267
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
268 (condition-case conds
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
269 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
270 (vip-save-last-insertion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
271 vip-insert-point
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
272 vip-last-posn-while-in-insert-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
273 (if vip-began-as-replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
274 (setq vip-began-as-replace nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
275 ;; repeat insert commands if numerical arg > 1
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
276 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
277 (vip-repeat-insert-command))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
278 (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
279 (vip-message-conditions conds)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
280
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
281 (if (> (length vip-last-insertion) 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
282 (vip-push-onto-ring vip-last-insertion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
283 'vip-insertion-ring))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
284
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
285 (if vip-ex-style-editing-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
286 (or (bolp) (backward-char 1))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
287 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
288
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
289 ;; insert or replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
290 ((memq new-state '(insert-state replace-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
291 (if (memq vip-current-state '(emacs-state vi-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
292 (vip-move-marker-locally 'vip-insert-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
293 (vip-move-marker-locally 'vip-last-posn-while-in-insert-state (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
294 (vip-add-hook 'vip-post-command-hooks
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
295 'vip-insert-state-post-command-sentinel t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
296 (vip-add-hook 'vip-pre-command-hooks
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
297 'vip-insert-state-pre-command-sentinel t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
298 ) ; outermost cond
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
299
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
300 ;; 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
301 ;; variables, which is already done in vip-change-state-to-emacs!
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
302
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
303 (setq vip-current-state new-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
304 (vip-normalize-minor-mode-map-alist)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
305 (vip-adjust-keys-for new-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
306 (vip-set-mode-vars-for new-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
307 (vip-refresh-mode-line)
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
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
311
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
312 (defun vip-adjust-keys-for (state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
313 "Make necessary adjustments to keymaps before entering STATE."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
314 (cond ((memq state '(insert-state replace-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
315 (if vip-auto-indent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
316 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
317 (define-key vip-insert-basic-map "\C-m" 'vip-autoindent)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
318 (if vip-want-emacs-keys-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
319 ;; expert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
320 (define-key vip-insert-basic-map "\C-j" nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
321 ;; novice
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
322 (define-key vip-insert-basic-map "\C-j" 'vip-autoindent)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
323 (define-key vip-insert-basic-map "\C-m" nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
324 (define-key vip-insert-basic-map "\C-j" nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
325
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
326 (setq vip-insert-diehard-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
327 (not vip-want-emacs-keys-in-insert))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
328
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
329 (if vip-want-ctl-h-help
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
330 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
331 (define-key vip-insert-basic-map [(control h)] 'help-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
332 (define-key vip-replace-map [(control h)] 'help-command))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
333 (define-key vip-insert-basic-map
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
334 [(control h)] 'vip-del-backward-char-in-insert)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
335 (define-key vip-replace-map
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
336 [(control h)] 'vip-del-backward-char-in-replace)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
337
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
338 (t ; Vi state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
339 (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
340 (if vip-want-ctl-h-help
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
341 (define-key vip-vi-basic-map [(control h)] 'help-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
342 (define-key vip-vi-basic-map [(control h)] 'vip-backward-char)))
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
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
345
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
346 ;; Normalizes minor-mode-map-alist by putting Viper keymaps first.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
347 ;; This ensures that Viper bindings are in effect, regardless of which minor
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
348 ;; modes were turned on by the user or by other packages.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
349 (defun vip-normalize-minor-mode-map-alist ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
350 (setq minor-mode-map-alist
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
351 (vip-append-filter-alist
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
352 (list
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
353 (cons 'vip-vi-intercept-minor-mode vip-vi-intercept-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
354 (cons 'vip-vi-minibuffer-minor-mode vip-minibuffer-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
355 (cons 'vip-vi-local-user-minor-mode vip-vi-local-user-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
356 (cons 'vip-vi-kbd-minor-mode vip-vi-kbd-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
357 (cons 'vip-vi-global-user-minor-mode vip-vi-global-user-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
358 (cons 'vip-vi-state-modifier-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
359 (if (keymapp
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
360 (cdr (assoc major-mode vip-vi-state-modifier-alist)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
361 (cdr (assoc major-mode vip-vi-state-modifier-alist))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
362 vip-empty-keymap))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
363 (cons 'vip-vi-diehard-minor-mode vip-vi-diehard-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
364 (cons 'vip-vi-basic-minor-mode vip-vi-basic-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
365 (cons 'vip-insert-intercept-minor-mode vip-insert-intercept-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
366 (cons 'vip-replace-minor-mode vip-replace-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
367 ;; vip-insert-minibuffer-minor-mode must come after
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
368 ;; vip-replace-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
369 (cons 'vip-insert-minibuffer-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
370 vip-minibuffer-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
371 (cons 'vip-insert-local-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
372 vip-insert-local-user-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
373 (cons 'vip-insert-kbd-minor-mode vip-insert-kbd-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
374 (cons 'vip-insert-global-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
375 vip-insert-global-user-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
376 (cons 'vip-insert-state-modifier-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
377 (if (keymapp
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 (cdr
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
381 (assoc major-mode vip-insert-state-modifier-alist))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
382 vip-empty-keymap))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
383 (cons 'vip-insert-diehard-minor-mode vip-insert-diehard-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
384 (cons 'vip-insert-basic-minor-mode vip-insert-basic-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
385 (cons 'vip-emacs-intercept-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
386 vip-emacs-intercept-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
387 (cons 'vip-emacs-local-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
388 vip-emacs-local-user-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
389 (cons 'vip-emacs-kbd-minor-mode vip-emacs-kbd-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
390 (cons 'vip-emacs-global-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
391 vip-emacs-global-user-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
392 (cons 'vip-emacs-state-modifier-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
393 (if (keymapp
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 (cdr
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
397 (assoc major-mode vip-emacs-state-modifier-alist))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
398 vip-empty-keymap))
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 minor-mode-map-alist)))
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
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 ;; Viper mode-changing commands and utilities
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
407
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
408 ;; Modifies mode-line-buffer-identification.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
409 (defun vip-refresh-mode-line ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
410 (setq vip-mode-string
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
411 (cond ((eq vip-current-state 'emacs-state) vip-emacs-state-id)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
412 ((eq vip-current-state 'vi-state) vip-vi-state-id)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
413 ((eq vip-current-state 'replace-state) vip-replace-state-id)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
414 ((eq vip-current-state 'insert-state) vip-insert-state-id)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
415
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
416 ;; Sets Viper mode string in global-mode-string
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
417 (force-mode-line-update))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
418
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
419
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
420 ;; Switch from Insert state to Vi state.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
421 (defun vip-exit-insert-state ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
422 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
423 (vip-change-state-to-vi))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
424
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
425 (defun vip-set-mode-vars-for (state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
426 "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
427
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
428 ;; Emacs state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
429 (setq vip-vi-minibuffer-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
430 vip-insert-minibuffer-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
431 vip-vi-intercept-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
432 vip-insert-intercept-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
433
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
434 vip-vi-local-user-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
435 vip-vi-kbd-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
436 vip-vi-global-user-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
437 vip-vi-state-modifier-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
438 vip-vi-diehard-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
439 vip-vi-basic-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-replace-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
442
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
443 vip-insert-local-user-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
444 vip-insert-kbd-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
445 vip-insert-global-user-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
446 vip-insert-state-modifier-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
447 vip-insert-diehard-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
448 vip-insert-basic-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
449 vip-emacs-intercept-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
450 vip-emacs-local-user-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
451 vip-emacs-kbd-minor-mode (not (vip-is-in-minibuffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
452 vip-emacs-global-user-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
453 vip-emacs-state-modifier-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
454 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
455
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
456 ;; Vi state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
457 (if (eq state 'vi-state) ; adjust for vi-state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
458 (setq
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
459 vip-vi-intercept-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
460 vip-vi-minibuffer-minor-mode (vip-is-in-minibuffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
461 vip-vi-local-user-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
462 vip-vi-kbd-minor-mode (not (vip-is-in-minibuffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
463 vip-vi-global-user-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
464 vip-vi-state-modifier-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
465 ;; don't let the diehard keymap block command completion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
466 ;; and other things in the minibuffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
467 vip-vi-diehard-minor-mode (not
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
468 (or vip-want-emacs-keys-in-vi
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
469 (vip-is-in-minibuffer)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
470 vip-vi-basic-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
471 vip-emacs-intercept-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
472 vip-emacs-local-user-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
473 vip-emacs-kbd-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
474 vip-emacs-global-user-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
475 vip-emacs-state-modifier-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
476 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
477
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
478 ;; Insert and Replace states
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
479 (if (member state '(insert-state replace-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
480 (setq
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
481 vip-insert-intercept-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
482 vip-replace-minor-mode (eq state 'replace-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
483 vip-insert-minibuffer-minor-mode (vip-is-in-minibuffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
484 vip-insert-local-user-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
485 vip-insert-kbd-minor-mode (not (vip-is-in-minibuffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
486 vip-insert-global-user-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
487 vip-insert-state-modifier-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
488 ;; don't let the diehard keymap block command completion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
489 ;; and other things in the minibuffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
490 vip-insert-diehard-minor-mode (not
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
491 (or vip-want-emacs-keys-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
492 (vip-is-in-minibuffer)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
493 vip-insert-basic-minor-mode t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
494 vip-emacs-intercept-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
495 vip-emacs-local-user-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
496 vip-emacs-kbd-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
497 vip-emacs-global-user-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
498 vip-emacs-state-modifier-minor-mode nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
499 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
500
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
501 ;; minibuffer faces
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
502 (if (vip-has-face-support-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
503 (setq vip-minibuffer-current-face
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
504 (cond ((eq state 'emacs-state) vip-minibuffer-emacs-face)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
505 ((eq state 'vi-state) vip-minibuffer-vi-face)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
506 ((memq state '(insert-state replace-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
507 vip-minibuffer-insert-face))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
508
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
509 (if (vip-is-in-minibuffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
510 (vip-set-minibuffer-overlay))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
511 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
512
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
513 ;; This also takes care of the annoying incomplete lines in files.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
514 ;; Also, this fixes `undo' to work vi-style for complex commands.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
515 (defun vip-change-state-to-vi ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
516 "Change Viper state to Vi."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
517 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
518 (if (and vip-first-time (not (vip-is-in-minibuffer)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
519 (viper-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
520 (if overwrite-mode (overwrite-mode nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
521 (if abbrev-mode (expand-abbrev))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
522 (if (and auto-fill-function (> (current-column) fill-column))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
523 (funcall auto-fill-function))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
524 ;; don't leave whitespace lines around
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
525 (if (and (memq last-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
526 '(vip-autoindent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
527 vip-open-line vip-Open-line
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
528 vip-replace-state-exit-cmd))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
529 (vip-over-whitespace-line))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
530 (indent-to-left-margin))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
531 (vip-add-newline-at-eob-if-necessary)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
532 (if vip-undo-needs-adjustment (vip-adjust-undo))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
533 (vip-change-state 'vi-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
534
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
535 ;; 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
536 ;; 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
537 (if (and (boundp 'iso-accents-mode) iso-accents-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
538 (iso-accents-mode -1))
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 (vip-restore-cursor-color-after-insert)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
541
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
542 ;; Protection against user errors in hooks
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
543 (condition-case conds
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
544 (run-hooks 'vip-vi-state-hook)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
545 (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
546 (vip-message-conditions conds)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
547
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
548 (defun vip-change-state-to-insert ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
549 "Change Viper state to Insert."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
550 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
551 (vip-change-state 'insert-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
552 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
553 (iso-accents-mode 1)) ; turn iso accents on
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
554
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
555 (or (stringp vip-saved-cursor-color)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
556 (string= (vip-get-cursor-color) vip-insert-state-cursor-color)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
557 (setq vip-saved-cursor-color (vip-get-cursor-color)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
558 ;; Commented out, because if vip-change-state-to-insert is executed
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
559 ;; 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
560 ;; bug related to local variables?
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
561 ;;;(if (stringp vip-saved-cursor-color)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
562 ;;; (vip-change-cursor-color vip-insert-state-cursor-color))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
563 ;; Protection against user errors in hooks
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
564 (condition-case conds
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
565 (run-hooks 'vip-insert-state-hook)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
566 (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
567 (vip-message-conditions conds))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
568
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
569 (defsubst vip-downgrade-to-insert ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
570 (setq vip-current-state 'insert-state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
571 vip-replace-minor-mode nil)
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
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
575
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
576 ;; Change to replace state. When the end of replacement region is reached,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
577 ;; replace state changes to insert state.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
578 (defun vip-change-state-to-replace (&optional non-R-cmd)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
579 (vip-change-state 'replace-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
580 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
581 (iso-accents-mode 1)) ; turn iso accents on
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
582 ;; Run insert-state-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
583 (condition-case conds
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
584 (run-hooks 'vip-insert-state-hook 'vip-replace-state-hook)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
585 (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
586 (vip-message-conditions conds)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
587
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
588 (if non-R-cmd
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
589 (vip-start-replace)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
590 ;; 'R' is implemented using Emacs's overwrite-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
591 (vip-start-R-mode))
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
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
594
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
595 (defun vip-change-state-to-emacs ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
596 "Change Viper state to Emacs."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
597 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
598 (vip-change-state 'emacs-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
599 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
600 (iso-accents-mode 1)) ; turn iso accents on
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
601
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
602 ;; Protection agains user errors in hooks
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
603 (condition-case conds
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
604 (run-hooks 'vip-emacs-state-hook)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
605 (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
606 (vip-message-conditions conds))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
607
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
608 ;; escape to emacs mode termporarily
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
609 (defun vip-escape-to-emacs (arg &optional events)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
610 "Escape to Emacs state from Vi state for one Emacs command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
611 ARG is used as the prefix value for the executed command. If
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
612 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
613 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
614 (if (= last-command-char ?\\)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
615 (message "Switched to EMACS state for the next command..."))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
616 (vip-escape-to-state arg events 'emacs-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
617
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
618 ;; escape to Vi mode termporarily
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
619 (defun vip-escape-to-vi (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
620 "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
621 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
622 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
623 `vip-escape-to-vi' is used."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
624 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
625 (message "Switched to VI state for the next command...")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
626 (vip-escape-to-state arg nil 'vi-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
627
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
628 ;; Escape to STATE mode for one Emacs command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
629 (defun vip-escape-to-state (arg events state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
630 ;;(let (com key prefix-arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
631 (let (com key)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
632 ;; this temporarily turns off Viper's minor mode keymaps
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
633 (vip-set-mode-vars-for state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
634 (vip-normalize-minor-mode-map-alist)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
635 (if events (vip-set-unread-command-events events))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
636
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
637 ;; protect against keyboard quit and other errors
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
638 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
639 (let (vip-vi-kbd-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
640 vip-insert-kbd-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
641 vip-emacs-kbd-minor-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
642 (unwind-protect
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
643 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
644 (setq com (key-binding (setq key
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
645 (if vip-xemacs-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
646 (read-key-sequence nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
647 (read-key-sequence nil t)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
648 ;; In case of binding indirection--chase definitions.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
649 ;; Have to do it here because we execute this command under
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
650 ;; different keymaps, so command-execute may not do the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
651 ;; right thing there
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
652 (while (vectorp com) (setq com (key-binding com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
653 nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
654 ;; Execute command com in the original Viper state, not in state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
655 ;; `state'. Otherwise, if we switch buffers while executing the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
656 ;; escaped to command, Viper's mode vars will remain those of
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
657 ;; `state'. When we return to the orig buffer, the bindings will be
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
658 ;; screwed up.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
659 (vip-set-mode-vars-for vip-current-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
660
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
661 ;; this-command, last-command-char, last-command-event
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
662 (setq this-command com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
663 (if vip-xemacs-p ; XEmacs represents key sequences as vectors
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
664 (setq last-command-event (vip-copy-event (vip-seq-last-elt key))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
665 last-command-char (event-to-character last-command-event))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
666 ;; Emacs represents them as sequences (str or vec)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
667 (setq last-command-event (vip-copy-event (vip-seq-last-elt key))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
668 last-command-char last-command-event))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
669
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
670 (if (commandp com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
671 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
672 (setq prefix-arg (or prefix-arg arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
673 (command-execute com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
674 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
675 (quit (ding))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
676 (error (beep 1))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
677 ;; set state in the new buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
678 (vip-set-mode-vars-for vip-current-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
679
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
680 (defun vip-exec-form-in-vi (form)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
681 "Execute FORM in Vi state, regardless of the Ccurrent Vi state."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
682 (let ((buff (current-buffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
683 result)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
684 (vip-set-mode-vars-for 'vi-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
685
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
686 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
687 (setq result (eval form))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
688 (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
689 (signal 'quit nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
690
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
691 (if (not (equal buff (current-buffer))) ; cmd switched buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
692 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
693 (set-buffer buff)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
694 (vip-set-mode-vars-for vip-current-state)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
695 (vip-set-mode-vars-for vip-current-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
696 result))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
697
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
698 (defun vip-exec-form-in-emacs (form)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
699 "Execute FORM in Emacs, temporarily disabling Viper's minor modes.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
700 Similar to vip-escape-to-emacs, but accepts forms rather than keystrokes."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
701 (let ((buff (current-buffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
702 result)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
703 (vip-set-mode-vars-for 'emacs-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
704 (setq result (eval form))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
705 (if (not (equal buff (current-buffer))) ; cmd switched buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
706 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
707 (set-buffer buff)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
708 (vip-set-mode-vars-for vip-current-state)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
709 (vip-set-mode-vars-for vip-current-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
710 result))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
711
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
712
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
713 ;; This is needed because minor modes sometimes override essential Viper
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
714 ;; 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
715 ;; 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
716 (defun vip-harness-minor-mode (load-file)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
717 "Familiarize Viper with a minor mode defined in LOAD_FILE.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
718 Minor modes that have their own keymaps may overshadow Viper keymaps.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
719 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
720 such minor modes.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
721 Usage:
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
722 (vip-harness-minor-mode load-file)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
723
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
724 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
725 Suffixes such as .el or .elc should be stripped."
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 (interactive "sEnter name of the load file: ")
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 (vip-eval-after-load load-file '(vip-normalize-minor-mode-map-alist))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
730
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
731 ;; 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
732 ;; mode adds its own keymap to the a-list.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
733 (vip-eval-after-load
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
734 load-file '(setq-default minor-mode-map-alist minor-mode-map-alist))
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
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
737
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
738 (defun vip-ESC (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
739 "Emulate ESC key in Emacs.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
740 Prevents multiple escape keystrokes if vip-no-multiple-ESC is true.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
741 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
742 Other ESC sequences are emulated via the current Emacs's major mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
743 keymap. This is more convenient on TTYs, since this won't block
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
744 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
745 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
746 as a Meta key and any number of multiple escapes is allowed."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
747 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
748 (let (char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
749 (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
750 (setq char (vip-read-char-exclusive))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
751 (vip-escape-to-emacs arg (list ?\e char) ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
752 ((and (eq vip-no-multiple-ESC 'twice)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
753 (eq vip-current-state 'vi-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
754 (setq char (vip-read-char-exclusive))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
755 (if (= char (string-to-char vip-ESC-key))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
756 (ding)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
757 (vip-escape-to-emacs arg (list ?\e char) )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
758 (t (ding)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
759 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
760
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
761 (defun vip-alternate-Meta-key (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
762 "Simulate Emacs Meta key."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
763 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
764 (sit-for 1) (message "ESC-")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
765 (vip-escape-to-emacs arg '(?\e)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
766
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
767 (defun vip-toggle-key-action ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
768 "Action bound to `vip-toggle-key'."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
769 (interactive)
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
770 (if (and (< viper-expert-level 2) (equal vip-toggle-key "\C-z"))
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
771 (if (vip-window-display-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
772 (vip-iconify)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
773 (suspend-emacs))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
774 (vip-change-state-to-emacs)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
775
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
776
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
777 ;; Intercept ESC sequences on dumb terminals.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
778 ;; 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
779
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
780 ;; 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
781 ;; 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
782 ;; Returns the last event, if any.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
783 (defun vip-envelop-ESC-key ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
784 (let ((event last-input-event)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
785 (keyseq [nil])
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
786 inhibit-quit)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
787 (if (vip-ESC-event-p event)
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 (if (vip-fast-keysequence-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
790 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
791 (let (minor-mode-map-alist)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
792 (vip-set-unread-command-events event)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
793 (setq keyseq
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
794 (funcall
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
795 (ad-get-orig-definition 'read-key-sequence) nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
796 ) ; let
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
797 ;; If keyseq translates into something that still has ESC
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
798 ;; at the beginning, separate ESC from the rest of the seq.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
799 ;; In XEmacs we check for events that are keypress meta-key
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
800 ;; and convert them into [escape key]
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
801 ;;
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
802 ;; This is needed for the following reason:
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
803 ;; If ESC is the first symbol, we interpret it as if the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
804 ;; user typed ESC and then quickly some other symbols.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
805 ;; If ESC is not the first one, then the key sequence
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
806 ;; entered was apparently translated into a function key or
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
807 ;; something (e.g., one may have
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
808 ;; (define-key function-key-map "\e[192z" [f11])
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
809 ;; which would translate the escape-sequence generated by
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
810 ;; f11 in an xterm window into the symbolic key f11.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
811 ;;
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
812 ;; 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
813 ;; last-command-event in order to pretend that this key was
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
814 ;; pressed. This is needed to allow arrow keys to be bound to
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
815 ;; macros. Otherwise, vip-exec-mapped-kbd-macro will think that
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
816 ;; the last event was ESC and so it'll execute whatever is
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
817 ;; bound to ESC. (Viper macros can't be bound to
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
818 ;; ESC-sequences).
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
819 (let* ((first-key (elt keyseq 0))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
820 (key-mod (event-modifiers first-key)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
821 (cond ((vip-ESC-event-p first-key)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
822 ;; put keys following ESC on the unread list
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
823 ;; and return ESC as the key-sequence
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
824 (vip-set-unread-command-events (subseq keyseq 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
825 (setq last-input-event event
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
826 keyseq (if vip-emacs-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
827 "\e"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
828 (vector (character-to-event ?\e)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
829 ((and vip-xemacs-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
830 (key-press-event-p first-key)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
831 (equal '(meta) key-mod))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
832 (vip-set-unread-command-events
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
833 (vconcat (vector
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
834 (character-to-event (event-key first-key)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
835 (subseq keyseq 1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
836 (setq last-input-event event
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
837 keyseq (vector (character-to-event ?\e))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
838 ((eventp first-key)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
839 (setq last-command-event (vip-copy-event first-key)))
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 ) ; end progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
842
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
843 ;; this is escape event with nothing after it
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
844 ;; put in unread-command-event and then re-read
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
845 (vip-set-unread-command-events event)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
846 (setq keyseq
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
847 (funcall (ad-get-orig-definition 'read-key-sequence) nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
848 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
849 ;; not an escape event
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
850 (setq keyseq (vector event)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
851 keyseq))
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
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
854
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
855 ;; Listen to ESC key.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
856 ;; 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
857 ;; 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
858 (defun vip-intercept-ESC-key ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
859 "Function that implements ESC key in Viper emulation of Vi."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
860 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
861 (let ((cmd (or (key-binding (vip-envelop-ESC-key))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
862 '(lambda () (interactive) (error "")))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
863
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
864 ;; call the actual function to execute ESC (if no other symbols followed)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
865 ;; 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
866 ;; with very short delay between characters.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
867 (if (eq cmd 'vip-intercept-ESC-key)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
868 (setq cmd
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
869 (cond ((eq vip-current-state 'vi-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
870 'vip-ESC)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
871 ((eq vip-current-state 'insert-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
872 'vip-exit-insert-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
873 ((eq vip-current-state 'replace-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
874 'vip-replace-state-exit-cmd)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
875 (t 'vip-change-state-to-vi)
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 (call-interactively cmd)))
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
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 ;; prefix argument for Vi mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
883
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
884 ;; 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
885 ;; represents the numeric value of the prefix argument and COM represents
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
886 ;; command prefix such as "c", "d", "m" and "y".
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
887
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
888 ;; Get value part of prefix-argument ARG.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
889 (defsubst vip-p-val (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
890 (cond ((null arg) 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
891 ((consp arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
892 (if (or (null (car arg)) (equal (car arg) '(nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
893 1 (car arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
894 (t arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
895
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
896 ;; Get raw value part of prefix-argument ARG.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
897 (defsubst vip-P-val (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
898 (cond ((consp arg) (car arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
899 (t arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
900
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
901 ;; Get com part of prefix-argument ARG.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
902 (defsubst vip-getcom (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
903 (cond ((null arg) nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
904 ((consp arg) (cdr arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
905 (t nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
906
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
907 ;; Get com part of prefix-argument ARG and modify it.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
908 (defun vip-getCom (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
909 (let ((com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
910 (cond ((equal com ?c) ?C)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
911 ((equal com ?d) ?D)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
912 ((equal com ?y) ?Y)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
913 (t com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
914
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
915
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
916 ;; Compute numeric prefix arg value.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
917 ;; Invoked by EVENT. COM is the command part obtained so far.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
918 (defun vip-prefix-arg-value (event com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
919 (let (value func)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
920 ;; read while number
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
921 (while (and (vip-characterp event) (>= event ?0) (<= event ?9))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
922 (setq value (+ (* (if (integerp value) value 0) 10) (- event ?0)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
923 (setq event (vip-read-event-convert-to-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
924
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
925 (setq prefix-arg value)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
926 (if com (setq prefix-arg (cons prefix-arg com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
927 (while (eq event ?U)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
928 (vip-describe-arg prefix-arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
929 (setq event (vip-read-event-convert-to-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
930
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
931 (if (or com (and (not (eq vip-current-state 'vi-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
932 ;; make sure it is a Vi command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
933 (vip-characterp event) (vip-vi-command-p event)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
934 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
935 ;; If appears to be one of the vi commands,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
936 ;; 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
937 ;; confuse subsequent commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
938 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
939 ;; 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
940 ;; 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
941 ;; 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
942 ;; 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
943 ;; etc.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
944 ;; 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
945 ;; indicated by the fact that the current state is not vi-state),
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
946 ;; then `event' represents the vi command to be executed (e.g., `d',
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
947 ;; `w', etc). Again, last-command-char must make emacs believe that
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
948 ;; this is the command we typed.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
949 (setq last-command-char (or com event))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
950 (setq func (vip-exec-form-in-vi
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
951 (` (key-binding (char-to-string (, event))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
952 (funcall func prefix-arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
953 (setq prefix-arg nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
954 ;; some other command -- let emacs do it in its own way
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
955 (vip-set-unread-command-events event))
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
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
958
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
959 ;; Vi operator as prefix argument."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
960 (defun vip-prefix-arg-com (char value com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
961 (let ((cont t)
18958
506ec0258d63 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18855
diff changeset
962 cmd-info
506ec0258d63 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18855
diff changeset
963 cmd-to-exec-at-end)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
964 (while (and cont
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
965 (memq char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
966 (list ?c ?d ?y ?! ?< ?> ?= ?# ?r ?R ?\"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
967 vip-buffer-search-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
968 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
969 ;; this means that we already have a command character, so we
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
970 ;; construct a com list and exit while. however, if char is "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
971 ;; it is an error.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
972 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
973 ;; new com is (CHAR . OLDCOM)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
974 (if (memq char '(?# ?\")) (error ""))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
975 (setq com (cons char com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
976 (setq cont nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
977 ;; 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
978 ;; 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
979 ;; 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
980 ;; while loop.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
981 (cond ((memq char '(?! ?=))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
982 (setq com char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
983 (setq char (read-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
984 (setq cont nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
985 ((= char ?#)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
986 ;; read a char and encode it as com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
987 (setq com (+ 128 (read-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
988 (setq char (read-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
989 ((= char ?\")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
990 (let ((reg (read-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
991 (if (vip-valid-register reg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
992 (setq vip-use-register reg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
993 (error ""))
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 (t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
996 (setq com char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
997 (setq char (read-char))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
998
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
999 (if (atom com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1000 ;; `com' is a single char, so we construct the command argument
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1001 ;; and if `char' is `?', we describe the arg; otherwise
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1002 ;; we prepare the command that will be executed at the end.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1003 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1004 (setq cmd-info (cons value com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1005 (while (= char ?U)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1006 (vip-describe-arg cmd-info)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1007 (setq char (read-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1008 ;; `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
1009 ;; execute it at the very end
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1010 (or (vip-movement-command-p char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1011 (vip-digit-command-p char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1012 (vip-regsuffix-command-p char)
18958
506ec0258d63 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18855
diff changeset
1013 (= char ?!) ; bang command
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1014 (error ""))
18958
506ec0258d63 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18855
diff changeset
1015 (setq cmd-to-exec-at-end
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1016 (vip-exec-form-in-vi
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1017 (` (key-binding (char-to-string (, char)))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1018
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1019 ;; 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
1020 (if (memq (car com) '(?r ?R))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1021 ;; execute apropriate region command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1022 (let ((char (car com)) (com (cdr com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1023 (setq prefix-arg (cons value com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1024 (if (= char ?r) (vip-region prefix-arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1025 (vip-Region prefix-arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1026 ;; reset prefix-arg
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1027 (setq prefix-arg nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1028 ;; otherwise, reset prefix arg and call appropriate command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1029 (setq value (if (null value) 1 value))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1030 (setq prefix-arg nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1031 (cond ((equal com '(?c . ?c)) (vip-line (cons value ?C)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1032 ((equal com '(?d . ?d)) (vip-line (cons value ?D)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1033 ((equal com '(?d . ?y)) (vip-yank-defun))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1034 ((equal com '(?y . ?y)) (vip-line (cons value ?Y)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1035 ((equal com '(?< . ?<)) (vip-line (cons value ?<)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1036 ((equal com '(?> . ?>)) (vip-line (cons value ?>)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1037 ((equal com '(?! . ?!)) (vip-line (cons value ?!)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1038 ((equal com '(?= . ?=)) (vip-line (cons value ?=)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1039 (t (error "")))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1040
18958
506ec0258d63 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18855
diff changeset
1041 (if cmd-to-exec-at-end
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1042 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1043 (setq last-command-char char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1044 (setq last-command-event
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1045 (vip-copy-event
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1046 (if vip-xemacs-p (character-to-event char) char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1047 (condition-case nil
18958
506ec0258d63 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18855
diff changeset
1048 (funcall cmd-to-exec-at-end cmd-info)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1049 (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1050 (error "")))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1051 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1052
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1053 (defun vip-describe-arg (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1054 (let (val com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1055 (setq val (vip-P-val arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1056 com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1057 (if (null val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1058 (if (null com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1059 (message "Value is nil, and command is nil")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1060 (message "Value is nil, and command is `%c'" com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1061 (if (null com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1062 (message "Value is `%d', and command is nil" val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1063 (message "Value is `%d', and command is `%c'" val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1064
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1065 (defun vip-digit-argument (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1066 "Begin numeric argument for the next command."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1067 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1068 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1069 (vip-prefix-arg-value
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1070 last-command-char (if (consp arg) (cdr arg) nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1071
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1072 (defun vip-command-argument (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1073 "Accept a motion command as an argument."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1074 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1075 (let ((vip-inside-command-argument-action t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1076 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1077 (vip-prefix-arg-com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1078 last-command-char
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) (car arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1081 ((integerp arg) arg)
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 (cond ((null arg) nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1084 ((consp arg) (cdr arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1085 ((integerp arg) nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1086 (t (error vip-InvalidCommandArgument))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1087 (quit (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1088 (signal 'quit nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1089 (vip-deactivate-mark)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1090
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1091
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1092 ;; repeat last destructive command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1093
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1094 ;; Append region to text in register REG.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1095 ;; START and END are buffer positions indicating what to append.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1096 (defsubst vip-append-to-register (reg start end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1097 (set-register reg (concat (if (stringp (get-register reg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1098 (get-register reg) "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1099 (buffer-substring start end))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1100
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1101 ;; Saves last inserted text for possible use by vip-repeat command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1102 (defun vip-save-last-insertion (beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1103 (setq vip-last-insertion (buffer-substring beg end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1104 (or (< (length vip-d-com) 5)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1105 (setcar (nthcdr 4 vip-d-com) vip-last-insertion))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1106 (or (null vip-command-ring)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1107 (ring-empty-p vip-command-ring)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1108 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1109 (setcar (nthcdr 4 (vip-current-ring-item vip-command-ring))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1110 vip-last-insertion)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1111 ;; del most recent elt, if identical to the second most-recent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1112 (vip-cleanup-ring vip-command-ring)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1113 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1114
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1115 (defsubst vip-yank-last-insertion ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1116 "Inserts the text saved by the previous vip-save-last-insertion command."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1117 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1118 (insert vip-last-insertion)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1119 (error nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1120
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1121
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1122 ;; define functions to be executed
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1123
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1124 ;; invoked by the `C' command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1125 (defun vip-exec-change (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1126 (or (and (markerp vip-com-point) (marker-position vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1127 (set-marker vip-com-point (point) (current-buffer)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1128 ;; handle C cmd at the eol and at eob.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1129 (if (or (and (eolp) (= vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1130 (= vip-com-point (point-max)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1131 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1132 (insert " ")(backward-char 1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1133 (if (= vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1134 (vip-forward-char-carefully))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1135 (if (= com ?c)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1136 (vip-change vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1137 (vip-change-subr vip-com-point (point))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1138
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1139 ;; this is invoked by vip-substitute-line
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1140 (defun vip-exec-Change (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1141 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1142 (set-mark vip-com-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1143 (vip-enlarge-region (mark t) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1144 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1145 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1146 (cond ((vip-valid-register vip-use-register '(letter digit))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1147 ;;(vip-valid-register vip-use-register '(letter)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1148 (copy-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1149 vip-use-register (mark t) (point) nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1150 ((vip-valid-register vip-use-register '(Letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1151 (vip-append-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1152 (downcase vip-use-register) (mark t) (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1153 (t (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1154 (error vip-InvalidRegister vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1155 (setq vip-use-register nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1156 (delete-region (mark t) (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1157 (open-line 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1158 (if (= com ?C) (vip-change-mode-to-insert) (vip-yank-last-insertion)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1159
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1160 (defun vip-exec-delete (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1161 (or (and (markerp vip-com-point) (marker-position vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1162 (set-marker vip-com-point (point) (current-buffer)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1163 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1164 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1165 (cond ((vip-valid-register vip-use-register '(letter digit))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1166 ;;(vip-valid-register vip-use-register '(letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1167 (copy-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1168 vip-use-register vip-com-point (point) nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1169 ((vip-valid-register vip-use-register '(Letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1170 (vip-append-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1171 (downcase vip-use-register) vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1172 (t (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1173 (error vip-InvalidRegister vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1174 (setq vip-use-register nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1175 (setq last-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1176 (if (eq last-command 'd-command) 'kill-region nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1177 (kill-region vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1178 (setq this-command 'd-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1179 (if vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1180 (if (and (eolp) (not (bolp))) (backward-char 1))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1181
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1182 (defun vip-exec-Delete (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1183 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1184 (set-mark vip-com-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1185 (vip-enlarge-region (mark t) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1186 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1187 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1188 (cond ((vip-valid-register vip-use-register '(letter digit))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1189 ;;(vip-valid-register vip-use-register '(letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1190 (copy-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1191 vip-use-register (mark t) (point) nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1192 ((vip-valid-register vip-use-register '(Letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1193 (vip-append-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1194 (downcase vip-use-register) (mark t) (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1195 (t (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1196 (error vip-InvalidRegister vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1197 (setq vip-use-register nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1198 (setq last-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1199 (if (eq last-command 'D-command) 'kill-region nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1200 (kill-region (mark t) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1201 (if (eq m-com 'vip-line) (setq this-command 'D-command)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1202 (back-to-indentation))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1203
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1204 (defun vip-exec-yank (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1205 (or (and (markerp vip-com-point) (marker-position vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1206 (set-marker vip-com-point (point) (current-buffer)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1207 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1208 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1209 (cond ((vip-valid-register vip-use-register '(letter digit))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1210 ;; (vip-valid-register vip-use-register '(letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1211 (copy-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1212 vip-use-register vip-com-point (point) nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1213 ((vip-valid-register vip-use-register '(Letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1214 (vip-append-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1215 (downcase vip-use-register) vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1216 (t (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1217 (error vip-InvalidRegister vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1218 (setq vip-use-register nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1219 (setq last-command nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1220 (copy-region-as-kill vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1221 (goto-char vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1222
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1223 (defun vip-exec-Yank (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1224 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1225 (set-mark vip-com-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1226 (vip-enlarge-region (mark t) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1227 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1228 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1229 (cond ((vip-valid-register vip-use-register '(letter digit))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1230 (copy-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1231 vip-use-register (mark t) (point) nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1232 ((vip-valid-register vip-use-register '(Letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1233 (vip-append-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1234 (downcase vip-use-register) (mark t) (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1235 (t (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1236 (error vip-InvalidRegister vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1237 (setq vip-use-register nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1238 (setq last-command nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1239 (copy-region-as-kill (mark t) (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1240 (vip-deactivate-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1241 (goto-char vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1242
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1243 (defun vip-exec-bang (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1244 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1245 (set-mark vip-com-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1246 (vip-enlarge-region (mark t) (point))
18958
506ec0258d63 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18855
diff changeset
1247 (exchange-point-and-mark)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1248 (shell-command-on-region
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1249 (mark t) (point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1250 (if (= com ?!)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1251 (setq vip-last-shell-com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1252 (vip-read-string-with-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1253 "!"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1254 nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1255 'vip-shell-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1256 (car vip-shell-history)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1257 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1258 vip-last-shell-com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1259 t)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1260
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1261 (defun vip-exec-equals (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1262 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1263 (set-mark vip-com-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1264 (vip-enlarge-region (mark t) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1265 (if (> (mark t) (point)) (exchange-point-and-mark))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1266 (indent-region (mark t) (point) nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1267
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1268 (defun vip-exec-shift (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1269 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1270 (set-mark vip-com-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1271 (vip-enlarge-region (mark t) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1272 (if (> (mark t) (point)) (exchange-point-and-mark))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1273 (indent-rigidly (mark t) (point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1274 (if (= com ?>)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1275 vip-shift-width
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1276 (- vip-shift-width))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1277 ;; return point to where it was before shift
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1278 (goto-char vip-com-point))
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 ;; 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
1281 ;; denotes repeated insert command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1282 (defsubst vip-exec-dummy (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1283 nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1284
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1285 (defun vip-exec-buffer-search (m-com com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1286 (setq vip-s-string (buffer-substring (point) vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1287 (setq vip-s-forward t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1288 (setq vip-search-history (cons vip-s-string vip-search-history))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1289 (vip-search vip-s-string vip-s-forward 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1290
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1291 (defvar vip-exec-array (make-vector 128 nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1292
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1293 ;; Using a dispatch array allows adding functions like buffer search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1294 ;; without affecting other functions. Buffer search can now be bound
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1295 ;; to any character.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1296
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1297 (aset vip-exec-array ?c 'vip-exec-change)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1298 (aset vip-exec-array ?C 'vip-exec-Change)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1299 (aset vip-exec-array ?d 'vip-exec-delete)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1300 (aset vip-exec-array ?D 'vip-exec-Delete)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1301 (aset vip-exec-array ?y 'vip-exec-yank)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1302 (aset vip-exec-array ?Y 'vip-exec-Yank)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1303 (aset vip-exec-array ?r 'vip-exec-dummy)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1304 (aset vip-exec-array ?! 'vip-exec-bang)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1305 (aset vip-exec-array ?< 'vip-exec-shift)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1306 (aset vip-exec-array ?> 'vip-exec-shift)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1307 (aset vip-exec-array ?= 'vip-exec-equals)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1308
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1309
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1310
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1311 ;; This function is called by various movement commands to execute a
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1312 ;; destructive command on the region specified by the movement command. For
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1313 ;; 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
1314 ;; call vip-execute-com to execute vip-exec-change, which eventually will
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1315 ;; call vip-change to invoke the replace mode on the region.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1316 ;;
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1317 ;; 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
1318 ;; vip-d-com for later use by vip-repeat.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1319 (defun vip-execute-com (m-com val com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1320 (let ((reg vip-use-register))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1321 ;; this is the special command `#'
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1322 (if (> com 128)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1323 (vip-special-prefix-com (- com 128))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1324 (let ((fn (aref vip-exec-array (if (< com 0) (- com) com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1325 (if (null fn)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1326 (error "%c: %s" com vip-InvalidViCommand)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1327 (funcall fn m-com com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1328 (if (vip-dotable-command-p com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1329 (vip-set-destructive-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1330 (list m-com val
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1331 (if (memq com (list ?c ?C ?!)) (- com) com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1332 reg nil nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1333 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1334
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1335
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1336 (defun vip-repeat (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1337 "Re-execute last destructive command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1338 Use the info in vip-d-com, which has the form
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1339 \(com val ch reg inserted-text command-keys\),
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1340 where `com' is the command to be re-executed, `val' is the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1341 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
1342 if it exists, it is the name of the register for `com'.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1343 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
1344 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1345 (let ((save-point (point)) ; save point before repeating prev cmd
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1346 ;; Pass along that we are repeating a destructive command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1347 ;; This tells vip-set-destructive-command not to update
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1348 ;; vip-command-ring
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1349 (vip-intermediate-command 'vip-repeat))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1350 (if (eq last-command 'vip-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1351 ;; if the last command was vip-undo, then undo-more
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1352 (vip-undo-more)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1353 ;; 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
1354 ;; its prefix value is used as new prefix value for the command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1355 (let ((m-com (car vip-d-com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1356 (val (vip-P-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1357 (com (nth 2 vip-d-com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1358 (reg (nth 3 vip-d-com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1359 (if (null val) (setq val (nth 1 vip-d-com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1360 (if (null m-com) (error "No previous command to repeat."))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1361 (setq vip-use-register reg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1362 (if (nth 4 vip-d-com) ; text inserted by command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1363 (setq vip-last-insertion (nth 4 vip-d-com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1364 vip-d-char (nth 4 vip-d-com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1365 (funcall m-com (cons val com))
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
1366 (cond ((and (< save-point (point)) vip-keep-point-on-repeat)
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
1367 (goto-char save-point)) ; go back to before repeat.
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
1368 ((and (< save-point (point)) vip-ex-style-editing-in-insert)
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
1369 (or (bolp) (backward-char 1))))
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1370 (if (and (eolp) (not (bolp)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1371 (backward-char 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1372 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1373 (if vip-undo-needs-adjustment (vip-adjust-undo)) ; take care of undo
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1374 ;; 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
1375 ;; 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
1376 ;; 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
1377 ;; 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
1378 ;; the inserted text may be nil). Besides, in this case, the command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1379 ;; executed by `.' is already on the ring.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1380 (if (eq last-command 'vip-display-current-destructive-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1381 (vip-push-onto-ring vip-d-com 'vip-command-ring))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1382 (vip-deactivate-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1383 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1384
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1385 (defun vip-repeat-from-history ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1386 "Repeat a destructive command from history.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1387 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
1388 executing this command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1389 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
1390 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
1391 history command to execute. `<char>0' is equivalent to `.', `<char>1'
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1392 invokes the command before that, etc."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1393 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1394 (let* ((vip-intermediate-command 'repeating-display-destructive-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1395 (idx (cond (vip-this-kbd-macro
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1396 (string-to-number
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1397 (symbol-name (elt vip-this-kbd-macro 1))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1398 (t 0)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1399 (num idx)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1400 (vip-d-com vip-d-com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1401
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1402 (or (and (numberp num) (<= 0 num) (<= num 9))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1403 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1404 (setq idx 0
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1405 num 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1406 (message
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1407 "`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
1408 (while (< 0 num)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1409 (setq vip-d-com (vip-special-ring-rotate1 vip-command-ring -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1410 (setq num (1- num)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1411 (vip-repeat nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1412 (while (> idx num)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1413 (vip-special-ring-rotate1 vip-command-ring 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1414 (setq num (1+ num)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1415 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1416
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1417
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1418 ;; The hash-command. It is invoked interactively by the key sequence #<char>.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1419 ;; The chars that can follow `#' are determined by vip-hash-command-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1420 (defun vip-special-prefix-com (char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1421 (cond ((= char ?c)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1422 (downcase-region (min vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1423 (max vip-com-point (point))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1424 ((= char ?C)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1425 (upcase-region (min vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1426 (max vip-com-point (point))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1427 ((= char ?g)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1428 (push-mark vip-com-point t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1429 (vip-global-execute))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1430 ((= char ?q)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1431 (push-mark vip-com-point t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1432 (vip-quote-region))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1433 ((= char ?s) (funcall vip-spell-function vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1434 (t (error "#%c: %s" char vip-InvalidViCommand))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1435
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1436
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1437 ;; undoing
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1438
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1439 (defun vip-undo ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1440 "Undo previous change."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1441 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1442 (message "undo!")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1443 (let ((modified (buffer-modified-p))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1444 (before-undo-pt (point-marker))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1445 (after-change-functions after-change-functions)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1446 undo-beg-posn undo-end-posn)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1447
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1448 ;; 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
1449 (add-hook 'after-change-functions
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1450 '(lambda (beg end len)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1451 (setq undo-beg-posn beg
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1452 undo-end-posn (or end beg))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1453
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1454 (undo-start)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1455 (undo-more 2)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1456 (setq undo-beg-posn (or undo-beg-posn before-undo-pt)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1457 undo-end-posn (or undo-end-posn undo-beg-posn))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1458
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1459 (goto-char undo-beg-posn)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1460 (sit-for 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1461 (if (and vip-keep-point-on-undo
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1462 (pos-visible-in-window-p before-undo-pt))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1463 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1464 (push-mark (point-marker) t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1465 (vip-sit-for-short 300)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1466 (goto-char undo-end-posn)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1467 (vip-sit-for-short 300)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1468 (if (and (> (abs (- undo-beg-posn before-undo-pt)) 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1469 (> (abs (- undo-end-posn before-undo-pt)) 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1470 (goto-char before-undo-pt)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1471 (goto-char undo-beg-posn)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1472 (push-mark before-undo-pt t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1473 (if (and (eolp) (not (bolp))) (backward-char 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1474 (if (not modified) (set-buffer-modified-p t)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1475 (setq this-command 'vip-undo))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1476
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1477 ;; Continue undoing previous changes.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1478 (defun vip-undo-more ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1479 (message "undo more!")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1480 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1481 (undo-more 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1482 (error (beep)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1483 (message "No further undo information in this buffer")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1484 (if (and (eolp) (not (bolp))) (backward-char 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1485 (setq this-command 'vip-undo))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1486
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1487 ;; The following two functions are used to set up undo properly.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1488 ;; 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
1489 ;; they are undone all at once.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1490 (defun vip-adjust-undo ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1491 (let ((inhibit-quit t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1492 tmp tmp2)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1493 (setq vip-undo-needs-adjustment nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1494 (if (listp buffer-undo-list)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1495 (if (setq tmp (memq vip-buffer-undo-list-mark buffer-undo-list))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1496 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1497 (setq tmp2 (cdr tmp)) ; the part after mark
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1498
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1499 ;; cut tail from buffer-undo-list temporarily by direct
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1500 ;; manipulation with pointers in buffer-undo-list
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1501 (setcdr tmp nil)
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 (setq buffer-undo-list (delq nil buffer-undo-list))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1504 (setq buffer-undo-list
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1505 (delq vip-buffer-undo-list-mark buffer-undo-list))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1506 ;; restore tail of buffer-undo-list
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1507 (setq buffer-undo-list (nconc buffer-undo-list tmp2)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1508 (setq buffer-undo-list (delq nil buffer-undo-list))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1509
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1510
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1511 (defun vip-set-complex-command-for-undo ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1512 (if (listp buffer-undo-list)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1513 (if (not vip-undo-needs-adjustment)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1514 (let ((inhibit-quit t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1515 (setq buffer-undo-list
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1516 (cons vip-buffer-undo-list-mark buffer-undo-list))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1517 (setq vip-undo-needs-adjustment t)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1518
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
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 (defun vip-display-current-destructive-command ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1523 (let ((text (nth 4 vip-d-com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1524 (keys (nth 5 vip-d-com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1525 (max-text-len 30))
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 (setq this-command 'vip-display-current-destructive-command)
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 (message " `.' runs %s%s"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1530 (concat "`" (vip-array-to-string keys) "'")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1531 (vip-abbreviate-string text max-text-len
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1532 " inserting `" "'" " ......."))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1533 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1534
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1535
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1536 ;; 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
1537 ;; or in some other way (non-interactively).
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1538 (defun vip-set-destructive-command (list)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1539 (or (eq vip-intermediate-command 'vip-repeat)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1540 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1541 (setq vip-d-com list)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1542 (setcar (nthcdr 5 vip-d-com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1543 (vip-array-to-string (this-command-keys)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1544 (vip-push-onto-ring vip-d-com 'vip-command-ring))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1545
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1546 (defun vip-prev-destructive-command (next)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1547 "Find previous destructive command in the history of destructive commands.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1548 With prefix argument, find next destructive command."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1549 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1550 (let (cmd vip-intermediate-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1551 (if (eq last-command 'vip-display-current-destructive-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1552 ;; repeated search through command history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1553 (setq vip-intermediate-command 'repeating-display-destructive-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1554 ;; first search through command history--set temp ring
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1555 (setq vip-temp-command-ring (copy-list vip-command-ring)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1556 (setq cmd (if next
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1557 (vip-special-ring-rotate1 vip-temp-command-ring 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1558 (vip-special-ring-rotate1 vip-temp-command-ring -1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1559 (if (null cmd)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1560 ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1561 (setq vip-d-com cmd))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1562 (vip-display-current-destructive-command)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1563
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1564 (defun vip-next-destructive-command ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1565 "Find next destructive command in the history of destructive commands."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1566 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1567 (vip-prev-destructive-command 'next))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1568
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1569 (defun vip-insert-prev-from-insertion-ring (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1570 "Cycle through insertion ring in the direction of older insertions.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1571 Undoes previous insertion and inserts new.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1572 With prefix argument, cycles in the direction of newer elements.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1573 In minibuffer, this command executes whatever the invocation key is bound
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1574 to in the global map, instead of cycling through the insertion ring."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1575 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1576 (let (vip-intermediate-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1577 (if (eq last-command 'vip-insert-from-insertion-ring)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1578 (progn ; repeated search through insertion history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1579 (setq vip-intermediate-command 'repeating-insertion-from-ring)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1580 (if (eq vip-current-state 'replace-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1581 (undo 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1582 (if vip-last-inserted-string-from-insertion-ring
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1583 (backward-delete-char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1584 (length vip-last-inserted-string-from-insertion-ring))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1585 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1586 ;;first search through insertion history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1587 (setq vip-temp-insertion-ring (copy-list vip-insertion-ring)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1588 (setq this-command 'vip-insert-from-insertion-ring)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1589 ;; so that things will be undone properly
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1590 (setq buffer-undo-list (cons nil buffer-undo-list))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1591 (setq vip-last-inserted-string-from-insertion-ring
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1592 (vip-special-ring-rotate1 vip-temp-insertion-ring (if arg 1 -1)))
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 ;; this change of vip-intermediate-command must come after
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1595 ;; 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
1596 ;; insertion.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1597 (setq vip-intermediate-command nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1598 (if vip-last-inserted-string-from-insertion-ring
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1599 (insert vip-last-inserted-string-from-insertion-ring))
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 (defun vip-insert-next-from-insertion-ring ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1603 "Cycle through insertion ring in the direction of older insertions.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1604 Undo previous insertion and inserts new."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1605 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1606 (vip-insert-prev-from-insertion-ring 'next))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1607
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1608
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1609 ;; some region utilities
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1610
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1611 ;; 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
1612 (defun vip-add-newline-at-eob-if-necessary ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1613 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1614 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1615 ;; make sure all lines end with newline, unless in the minibuffer or
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1616 ;; when requested otherwise (require-final-newline is nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1617 (if (and (eobp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1618 (not (bolp))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1619 require-final-newline
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1620 (not (vip-is-in-minibuffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1621 (not buffer-read-only))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1622 (insert "\n"))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1623
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1624 (defun vip-yank-defun ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1625 (mark-defun)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1626 (copy-region-as-kill (point) (mark t)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1627
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1628 ;; Enlarge region between BEG and END.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1629 (defun vip-enlarge-region (beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1630 (or beg (setq beg end)) ; if beg is nil, set to end
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1631 (or end (setq end beg)) ; if end is nil, set to beg
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1632
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1633 (if (< beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1634 (progn (goto-char beg) (set-mark end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1635 (goto-char end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1636 (set-mark beg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1637 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1638 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1639 (if (or (not (eobp)) (not (bolp))) (forward-line 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1640 (if (not (eobp)) (beginning-of-line))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1641 (if (> beg end) (exchange-point-and-mark)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1642
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1643
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1644 ;; Quote region by each line with a user supplied string.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1645 (defun vip-quote-region ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1646 (setq vip-quote-string
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1647 (vip-read-string-with-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1648 "Quote string: "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1649 nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1650 'vip-quote-region-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1651 vip-quote-string))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1652 (vip-enlarge-region (point) (mark t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1653 (if (> (point) (mark t)) (exchange-point-and-mark))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1654 (insert vip-quote-string)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1655 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1656 (forward-line 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1657 (while (and (< (point) (mark t)) (bolp))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1658 (insert vip-quote-string)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1659 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1660 (forward-line 1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1661
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1662 ;; Tells whether BEG is on the same line as END.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1663 ;; If one of the args is nil, it'll return nil.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1664 (defun vip-same-line (beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1665 (let ((selective-display nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1666 (incr 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1667 temp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1668 (if (and beg end (> beg end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1669 (setq temp beg
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1670 beg end
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1671 end temp))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1672 (if (and beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1673 (cond ((or (> beg (point-max)) (> end (point-max))) ; out of range
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1674 nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1675 (t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1676 ;; This 'if' is needed because Emacs treats the next empty line
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1677 ;; as part of the previous line.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1678 (if (= (vip-line-pos 'start) end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1679 (setq incr 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1680 (<= (+ incr (count-lines beg end)) 1))))
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
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1683
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1684 ;; Check if the string ends with a newline.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1685 (defun vip-end-with-a-newline-p (string)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1686 (or (string= string "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1687 (= (vip-seq-last-elt string) ?\n)))
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 (defun vip-tmp-insert-at-eob (msg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1690 (let ((savemax (point-max)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1691 (goto-char savemax)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1692 (insert msg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1693 (sit-for 2)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1694 (goto-char savemax) (delete-region (point) (point-max))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1695 ))
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
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1699 ;;; Minibuffer business
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1700
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1701 (defsubst vip-set-minibuffer-style ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1702 (add-hook 'minibuffer-setup-hook 'vip-minibuffer-setup-sentinel))
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 (defun vip-minibuffer-setup-sentinel ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1706 (let ((hook (if vip-vi-style-in-minibuffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1707 'vip-change-state-to-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1708 'vip-change-state-to-emacs)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1709 (funcall hook)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1710 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1711
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1712 ;; Interpret last event in the local map
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1713 (defun vip-exit-minibuffer ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1714 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1715 (let (command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1716 (setq command (local-key-binding (char-to-string last-command-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1717 (if command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1718 (command-execute command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1719 (exit-minibuffer))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1720
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1721
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1722 ;;; Reading string with history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1723
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1724 (defun vip-read-string-with-history (prompt &optional initial
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1725 history-var default keymap)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1726 ;; Read string, prompting with PROMPT and inserting the INITIAL
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1727 ;; 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
1728 ;; input is an empty string. Use KEYMAP, if given, or the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1729 ;; minibuffer-local-map.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1730 ;; Default value is displayed until the user types something in the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1731 ;; minibuffer.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1732 (let ((minibuffer-setup-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1733 '(lambda ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1734 (if (stringp initial)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1735 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1736 ;; don't wait if we have unread events or in kbd macro
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1737 (or unread-command-events
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1738 executing-kbd-macro
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1739 (sit-for 840))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1740 (erase-buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1741 (insert initial)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1742 (vip-minibuffer-setup-sentinel)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1743 (val "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1744 (padding "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1745 temp-msg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1746
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1747 (setq keymap (or keymap minibuffer-local-map)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1748 initial (or initial "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1749 temp-msg (if default
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1750 (format "(default: %s) " default)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1751 ""))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1752
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1753 (setq vip-incomplete-ex-cmd nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1754 (setq val (read-from-minibuffer prompt
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1755 (concat temp-msg initial val padding)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1756 keymap nil history-var))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1757 (setq minibuffer-setup-hook nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1758 padding (vip-array-to-string (this-command-keys))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1759 temp-msg "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1760 ;; the following tries to be smart about what to put in history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1761 (if (not (string= val (car (eval history-var))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1762 (set history-var (cons val (eval history-var))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1763 (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
1764 (string= (nth 0 (eval history-var)) ""))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1765 (set history-var (cdr (eval history-var))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1766 ;; 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
1767 ;; vip-command-argument, or `! shell-command', this probably means
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1768 ;; that the user typed something then erased. Return "" in this case, not
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1769 ;; the default---the default is too confusing in this case.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1770 (cond ((and (string= val "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1771 (not (string= prompt "!")) ; was a `! shell-command'
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1772 (not (memq last-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1773 '(vip-ex
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1774 vip-command-argument
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1775 t)
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 "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1778 ((string= val "") (or default ""))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1779 (t val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1780 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1781
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1782
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1783
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1784 ;; insertion commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1785
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1786 ;; Called when state changes from Insert Vi command mode.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1787 ;; Repeats the insertion command if Insert state was entered with prefix
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1788 ;; argument > 1.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1789 (defun vip-repeat-insert-command ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1790 (let ((i-com (car vip-d-com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1791 (val (nth 1 vip-d-com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1792 (char (nth 2 vip-d-com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1793 (if (and val (> val 1)) ; first check that val is non-nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1794 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1795 (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
1796 (vip-repeat nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1797 (setq vip-d-com (list i-com val char nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1798 ))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1799
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1800 (defun vip-insert (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1801 "Insert before point."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1802 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1803 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1804 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1805 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1806 (vip-set-destructive-command (list 'vip-insert val ?r nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1807 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1808 (vip-loop val (vip-yank-last-insertion))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1809 (vip-change-state-to-insert))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1810
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1811 (defun vip-append (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1812 "Append after point."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1813 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1814 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1815 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1816 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1817 (vip-set-destructive-command (list 'vip-append val ?r nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1818 (if (not (eolp)) (forward-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1819 (if (equal com ?r)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1820 (vip-loop val (vip-yank-last-insertion))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1821 (vip-change-state-to-insert))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1822
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1823 (defun vip-Append (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1824 "Append at end of line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1825 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1826 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1827 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1828 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1829 (vip-set-destructive-command (list 'vip-Append val ?r nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1830 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1831 (if (equal com ?r)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1832 (vip-loop val (vip-yank-last-insertion))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1833 (vip-change-state-to-insert))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1834
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1835 (defun vip-Insert (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1836 "Insert before first non-white."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1837 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1838 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1839 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1840 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1841 (vip-set-destructive-command (list 'vip-Insert val ?r nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1842 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1843 (if (equal com ?r)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1844 (vip-loop val (vip-yank-last-insertion))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1845 (vip-change-state-to-insert))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1846
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1847 (defun vip-open-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1848 "Open line below."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1849 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1850 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1851 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1852 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1853 (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
1854 (let ((col (current-indentation)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1855 (if (equal com ?r)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1856 (vip-loop val
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1857 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1858 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1859 (newline 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1860 (if vip-auto-indent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1861 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1862 (setq vip-cted t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1863 (if vip-electric-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1864 (indent-according-to-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1865 (indent-to col))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1866 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1867 (vip-yank-last-insertion)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1868 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1869 (newline 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1870 (if vip-auto-indent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1871 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1872 (setq vip-cted t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1873 (if vip-electric-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1874 (indent-according-to-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1875 (indent-to col))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1876 (vip-change-state-to-insert)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1877
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1878 (defun vip-Open-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1879 "Open line above."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1880 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1881 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1882 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1883 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1884 (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
1885 (let ((col (current-indentation)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1886 (if (equal com ?r)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1887 (vip-loop val
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1888 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1889 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1890 (open-line 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1891 (if vip-auto-indent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1892 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1893 (setq vip-cted t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1894 (if vip-electric-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1895 (indent-according-to-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1896 (indent-to col))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1897 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1898 (vip-yank-last-insertion)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1899 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1900 (open-line 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1901 (if vip-auto-indent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1902 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1903 (setq vip-cted t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1904 (if vip-electric-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1905 (indent-according-to-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1906 (indent-to col))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1907 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1908 (vip-change-state-to-insert)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1909
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1910 (defun vip-open-line-at-point (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1911 "Open line at point."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1912 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1913 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1914 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1915 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1916 (vip-set-destructive-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1917 (list 'vip-open-line-at-point val ?r nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1918 (if (equal com ?r)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1919 (vip-loop val
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1920 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1921 (open-line 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1922 (vip-yank-last-insertion)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1923 (open-line 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1924 (vip-change-state-to-insert))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1925
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1926 (defun vip-substitute (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1927 "Substitute characters."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1928 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1929 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1930 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1931 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1932 (forward-char val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1933 (if (equal com ?r)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1934 (vip-change-subr (mark t) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1935 (vip-change (mark t) (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1936 (vip-set-destructive-command (list 'vip-substitute val ?r nil nil nil))
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
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1939 (defun vip-substitute-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1940 "Substitute lines."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1941 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1942 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1943 (vip-line (cons arg ?C)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1944
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1945 ;; Prepare for replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1946 (defun vip-start-replace ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1947 (setq vip-began-as-replace t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1948 vip-sitting-in-replace t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1949 vip-replace-chars-to-delete 0
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1950 vip-replace-chars-deleted 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1951 (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
1952 (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
1953 ;; this will get added repeatedly, but no harm
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1954 (add-hook 'after-change-functions 'vip-after-change-sentinel t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1955 (add-hook 'before-change-functions 'vip-before-change-sentinel t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1956 (vip-move-marker-locally 'vip-last-posn-in-replace-region
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1957 (vip-replace-start))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1958 (vip-add-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1959 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1960 (vip-add-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1961 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1962 ;; guard against a smartie who switched from R-replace to normal replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1963 (vip-remove-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1964 'vip-post-command-hooks 'vip-R-state-post-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1965 (if overwrite-mode (overwrite-mode nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1966 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1967
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 ;; checks how many chars were deleted by the last change
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1970 (defun vip-replace-mode-spy-before (beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1971 (setq vip-replace-chars-deleted
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1972 (- end beg
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1973 (max 0 (- end (vip-replace-end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1974 (max 0 (- (vip-replace-start) beg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1975 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1976
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1977 ;; 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
1978 (defun vip-replace-mode-spy-after (beg end length)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1979 (if (memq vip-intermediate-command '(repeating-insertion-from-ring))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1980 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1981 (setq vip-replace-chars-to-delete 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1982 (vip-move-marker-locally
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1983 'vip-last-posn-in-replace-region (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1984
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1985 (let (beg-col end-col real-end chars-to-delete)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1986 (setq real-end (min end (vip-replace-end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1987 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1988 (goto-char beg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1989 (setq beg-col (current-column))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1990 (goto-char real-end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1991 (setq end-col (current-column)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1992
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1993 ;; If beg of change is outside the replacement region, then don't
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1994 ;; delete anything in the repl region (set chars-to-delete to 0).
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1995 ;;
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1996 ;; This works fine except that we have to take special care of
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1997 ;; dabbrev-expand. The problem stems from new-dabbrev.el, which
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1998 ;; sometimes simply shifts the repl region rightwards, without
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
1999 ;; deleting an equal amount of characters.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2000 ;;
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2001 ;; The reason why new-dabbrev.el causes this are this:
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2002 ;; if one dinamically completes a partial word that starts before the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2003 ;; replacement region (but ends inside) then new-dabbrev.el first
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2004 ;; moves cursor backwards, to the beginning of the word to be
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2005 ;; completed (say, pt A). Then it inserts the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2006 ;; completed word and then deletes the old, incomplete part.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2007 ;; Since the complete word is inserted at position before the repl
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2008 ;; 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
2009 ;; unless we check for the current command, which must be
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2010 ;; dabbrev-expand.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2011 ;;
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2012 ;; In fact, it might be also useful to have overlays for insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2013 ;; regions as well, since this will let us capture the situation when
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2014 ;; dabbrev-expand goes back past the insertion point to find the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2015 ;; beginning of the word to be expanded.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2016 (if (or (and (<= (vip-replace-start) beg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2017 (<= beg (vip-replace-end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2018 (and (= length 0) (eq this-command 'dabbrev-expand)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2019 (setq chars-to-delete
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2020 (max (- end-col beg-col) (- real-end beg) 0))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2021 (setq chars-to-delete 0))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2022
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2023 ;; if beg = last change position, it means that we are within the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2024 ;; same command that does multiple changes. Moreover, it means
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2025 ;; that we have two subsequent changes (insert/delete) that
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2026 ;; complement each other.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2027 (if (= beg (marker-position vip-last-posn-in-replace-region))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2028 (setq vip-replace-chars-to-delete
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2029 (- (+ chars-to-delete vip-replace-chars-to-delete)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2030 vip-replace-chars-deleted))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2031 (setq vip-replace-chars-to-delete chars-to-delete))
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 (vip-move-marker-locally
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2034 'vip-last-posn-in-replace-region
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2035 (max (if (> end (vip-replace-end)) (vip-replace-start) end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2036 (or (marker-position vip-last-posn-in-replace-region)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2037 (vip-replace-start))
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 (setq vip-replace-chars-to-delete
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2041 (max 0
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2042 (min vip-replace-chars-to-delete
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2043 (- (vip-replace-end) vip-last-posn-in-replace-region)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2044 (- (vip-line-pos 'end) vip-last-posn-in-replace-region)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2045 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2046 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2047
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2048
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2049 ;; 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
2050 ;; posn is within the overlay.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2051 (defun vip-finish-change (posn)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2052 (vip-remove-hook 'vip-after-change-functions 'vip-replace-mode-spy-after)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2053 (vip-remove-hook 'vip-before-change-functions 'vip-replace-mode-spy-before)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2054 (vip-remove-hook 'vip-post-command-hooks
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2055 'vip-replace-state-post-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2056 (vip-remove-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2057 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2058 (vip-restore-cursor-color-after-replace)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2059 (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
2060 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2061 (if (and
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2062 vip-replace-overlay
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2063 (>= posn (vip-replace-start))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2064 (< posn (vip-replace-end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2065 (delete-region posn (vip-replace-end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2066 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2067
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2068 (if (eq vip-current-state 'replace-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2069 (vip-downgrade-to-insert))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2070 ;; replace mode ended => nullify vip-last-posn-in-replace-region
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2071 (vip-move-marker-locally 'vip-last-posn-in-replace-region nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2072 (vip-hide-replace-overlay)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2073 (vip-refresh-mode-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2074 (vip-put-string-on-kill-ring vip-last-replace-region)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2075 )
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 ;; Make STRING be the first element of the kill ring.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2078 (defun vip-put-string-on-kill-ring (string)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2079 (setq kill-ring (cons string kill-ring))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2080 (if (> (length kill-ring) kill-ring-max)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2081 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2082 (setq kill-ring-yank-pointer kill-ring))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2083
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2084 (defun vip-finish-R-mode ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2085 (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
2086 (vip-remove-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2087 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2088 (vip-downgrade-to-insert))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2089
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2090 (defun vip-start-R-mode ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2091 ;; 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
2092 (overwrite-mode 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2093 (vip-add-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2094 'vip-post-command-hooks 'vip-R-state-post-command-sentinel t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2095 (vip-add-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2096 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2097 ;; guard against a smartie who switched from R-replace to normal replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2098 (vip-remove-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2099 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2100 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2101
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2102
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2103
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2104 (defun vip-replace-state-exit-cmd ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2105 "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
2106 These keys are ESC, RET, and LineFeed"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2107 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2108 (if overwrite-mode ;; If you are in replace mode invoked via 'R'
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2109 (vip-finish-R-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2110 (vip-finish-change vip-last-posn-in-replace-region))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2111 (let (com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2112 (if (eq this-command 'vip-intercept-ESC-key)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2113 (setq com 'vip-exit-insert-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2114 (vip-set-unread-command-events last-input-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2115 (setq com (key-binding (read-key-sequence nil))))
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 (condition-case conds
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2118 (command-execute com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2119 (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2120 (vip-message-conditions conds)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2121 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2122 (vip-hide-replace-overlay))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2123
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2124 (defun vip-replace-state-carriage-return ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2125 "Implements carriage return in Viper replace state."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2126 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2127 ;; If Emacs start supporting overlay maps, as it currently supports
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2128 ;; 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
2129 ;; 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
2130 ;; statement can be deleted.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2131 (if (or (< (point) (vip-replace-start))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2132 (> (point) (vip-replace-end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2133 (let (vip-replace-minor-mode com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2134 (vip-set-unread-command-events last-input-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2135 (setq com (key-binding (read-key-sequence nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2136 (condition-case conds
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2137 (command-execute com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2138 (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2139 (vip-message-conditions conds))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2140 (if (not vip-allow-multiline-replace-regions)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2141 (vip-replace-state-exit-cmd)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2142 (if (vip-same-line (point) (vip-replace-end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2143 (vip-replace-state-exit-cmd)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2144 (vip-kill-line nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2145 (vip-next-line-at-bol nil)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2146
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2147
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2148 ;; This is the function bound to 'R'---unlimited replace.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2149 ;; Similar to Emacs's own overwrite-mode.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2150 (defun vip-overwrite (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2151 "Begin overwrite mode."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2152 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2153 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2154 (com (vip-getcom arg)) (len))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2155 (vip-set-destructive-command (list 'vip-overwrite val ?r nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2156 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2157 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2158 ;; Viper saves inserted text in vip-last-insertion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2159 (setq len (length vip-last-insertion))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2160 (delete-char len)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2161 (vip-loop val (vip-yank-last-insertion)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2162 (setq last-command 'vip-overwrite)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2163 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2164 (vip-set-replace-overlay (point) (vip-line-pos 'end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2165 (vip-change-state-to-replace)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2166 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2167
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2168
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2169 ;; line commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2170
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2171 (defun vip-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2172 (let ((val (car arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2173 (com (cdr arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2174 (vip-move-marker-locally 'vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2175 (if (not (eobp))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2176 (vip-next-line-carefully (1- val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2177 ;; 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
2178 ;; line of buffer when this line has no \n.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2179 (vip-add-newline-at-eob-if-necessary)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2180 (vip-execute-com 'vip-line val com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2181 (if (and (eobp) (not (bobp))) (forward-line -1))
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 (defun vip-yank-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2185 "Yank ARG lines (in Vi's sense)."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2186 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2187 (let ((val (vip-p-val arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2188 (vip-line (cons val ?Y))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2189
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2190
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2191 ;; region commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2192
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2193 (defun vip-region (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2194 "Execute command on a region."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2195 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2196 (let ((val (vip-P-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2197 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2198 (vip-move-marker-locally 'vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2199 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2200 (vip-execute-com 'vip-region val com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2201
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2202 (defun vip-Region (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2203 "Execute command on a Region."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2204 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2205 (let ((val (vip-P-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2206 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2207 (vip-move-marker-locally 'vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2208 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2209 (vip-execute-com 'vip-Region val com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2210
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2211 (defun vip-replace-char (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2212 "Replace the following ARG chars by the character read."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2213 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2214 (if (and (eolp) (bolp)) (error "No character to replace here"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2215 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2216 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2217 (vip-replace-char-subr com val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2218 (if (and (eolp) (not (bolp))) (forward-char 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2219 (vip-set-destructive-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2220 (list 'vip-replace-char val ?r nil vip-d-char nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2221 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2222
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2223 (defun vip-replace-char-subr (com arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2224 (let ((take-care-of-iso-accents
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2225 (and (boundp 'iso-accents-mode) vip-automatic-iso-accents))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2226 char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2227 (setq char (if (equal com ?r)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2228 vip-d-char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2229 (read-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2230 (if (and take-care-of-iso-accents (memq char '(?' ?\" ?^ ?~)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2231 ;; get European characters
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2232 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2233 (iso-accents-mode 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2234 (vip-set-unread-command-events char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2235 (setq char (aref (read-key-sequence nil) 0))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2236 (iso-accents-mode -1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2237 (delete-char arg t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2238 (setq vip-d-char char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2239 (vip-loop (if (> arg 0) arg (- arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2240 (if (eq char ?\C-m) (insert "\n") (insert char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2241 (backward-char arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2242
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2243
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2244 ;; basic cursor movement. j, k, l, h commands.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2245
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2246 (defun vip-forward-char (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2247 "Move point right ARG characters (left if ARG negative).
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2248 On reaching end of line, stop and signal error."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2249 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2250 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2251 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2252 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2253 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2254 (if vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2255 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2256 ;; the boundary condition check gets weird here because
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2257 ;; forward-char may be the parameter of a delete, and 'dl' works
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2258 ;; 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
2259 ;; the forward motion before the 'vip-execute-com', but, of
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2260 ;; 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
2261 ;; catch that condition before 'vip-execute-com'
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2262 (if (and (eolp) (bolp)) (error "") (forward-char val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2263 (if com (vip-execute-com 'vip-forward-char val com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2264 (if (eolp) (progn (backward-char 1) (error ""))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2265 (forward-char val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2266 (if com (vip-execute-com 'vip-forward-char val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2267
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2268 (defun vip-backward-char (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2269 "Move point left ARG characters (right if ARG negative).
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2270 On reaching beginning of line, stop and signal error."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2271 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2272 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2273 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2274 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2275 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2276 (if vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2277 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2278 (if (bolp) (error "") (backward-char val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2279 (if com (vip-execute-com 'vip-backward-char val com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2280 (backward-char val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2281 (if com (vip-execute-com 'vip-backward-char val com)))))
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 forward-char, but doesn't move at end of buffer.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2284 (defun vip-forward-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-max) (+ (point) arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2287 (forward-char arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2288 (goto-char (point-max))))
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 ;; Like backward-char, but doesn't move at end of buffer.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2291 (defun vip-backward-char-carefully (&optional arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2292 (setq arg (or arg 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2293 (if (<= (point-min) (- (point) arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2294 (backward-char arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2295 (goto-char (point-min))))
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 (defun vip-next-line-carefully (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2298 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2299 (next-line arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2300 (error nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2301
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2302
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2303
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2304 ;;; Word command
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 ;; 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
2307 ;; for word movement. When executed with a destructive command, \n is
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2308 ;; usually left untouched for the last word.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2309 ;; 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
2310 ;; separator. However, \n is always a separator. Also, if vip-syntax-preference
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2311 ;; is 'vi, then `_' is part of the word.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2312
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2313 ;; skip only one \n
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2314 (defun vip-skip-separators (forward)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2315 (if forward
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2316 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2317 (vip-skip-all-separators-forward 'within-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2318 (if (looking-at "\n")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2319 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2320 (forward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2321 (vip-skip-all-separators-forward 'within-line))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2322 (vip-skip-all-separators-backward 'within-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2323 (backward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2324 (if (looking-at "\n")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2325 (vip-skip-all-separators-backward 'within-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2326 (forward-char))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2327
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2328 (defun vip-forward-word-kernel (val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2329 (while (> val 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2330 (cond ((vip-looking-at-alpha)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2331 (vip-skip-alpha-forward "_")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2332 (vip-skip-separators t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2333 ((vip-looking-at-separator)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2334 (vip-skip-separators t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2335 ((not (vip-looking-at-alphasep))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2336 (vip-skip-nonalphasep-forward)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2337 (vip-skip-separators t)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2338 (setq val (1- val))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2339
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2340 ;; first search backward for pat. Then skip chars backwards using aux-pat
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2341 (defun vip-fwd-skip (pat aux-pat lim)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2342 (if (and (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2343 (re-search-backward pat lim t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2344 (= (point) (match-end 0)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2345 (goto-char (match-beginning 0)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2346 (skip-chars-backward aux-pat lim)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2347 (if (= (point) lim)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2348 (vip-forward-char-carefully))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2349 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2350
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2351
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2352 (defun vip-forward-word (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2353 "Forward word."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2354 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2355 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2356 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2357 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2358 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2359 (vip-forward-word-kernel val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2360 (if com (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2361 (cond ((memq com (list ?c (- ?c)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2362 (vip-fwd-skip "\n[ \t]*" " \t" vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2363 ;; Yank words including the whitespace, but not newline
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2364 ((memq com (list ?y (- ?y)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2365 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2366 ((vip-dotable-command-p com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2367 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2368 (vip-execute-com 'vip-forward-word val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2369
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2370
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2371 (defun vip-forward-Word (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2372 "Forward word delimited by white characters."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2373 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2374 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2375 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2376 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2377 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2378 (vip-loop val
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2379 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2380 (vip-skip-nonseparators 'forward)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2381 (vip-skip-separators t)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2382 (if com (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2383 (cond ((memq com (list ?c (- ?c)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2384 (vip-fwd-skip "\n[ \t]*" " \t" vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2385 ;; Yank words including the whitespace, but not newline
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2386 ((memq com (list ?y (- ?y)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2387 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2388 ((vip-dotable-command-p com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2389 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2390 (vip-execute-com 'vip-forward-Word val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2391
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 ;; 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
2394 ;; makes no sense whatsoever
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2395 (defun vip-end-of-word-kernel ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2396 (if (vip-end-of-word-p) (forward-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2397 (if (vip-looking-at-separator)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2398 (vip-skip-all-separators-forward))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2399
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2400 (cond ((vip-looking-at-alpha) (vip-skip-alpha-forward "_"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2401 ((not (vip-looking-at-alphasep)) (vip-skip-nonalphasep-forward)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2402 (vip-backward-char-carefully))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2403
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2404 (defun vip-end-of-word-p ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2405 (or (eobp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2406 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2407 (cond ((vip-looking-at-alpha)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2408 (forward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2409 (not (vip-looking-at-alpha)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2410 ((not (vip-looking-at-alphasep))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2411 (forward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2412 (vip-looking-at-alphasep))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2413
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2414
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2415 (defun vip-end-of-word (arg &optional careful)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2416 "Move point to end of current word."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2417 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2418 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2419 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2420 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2421 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2422 (vip-loop val (vip-end-of-word-kernel))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2423 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2424 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2425 (forward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2426 (vip-execute-com 'vip-end-of-word val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2427
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2428 (defun vip-end-of-Word (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2429 "Forward to end of word delimited by white character."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2430 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2431 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2432 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2433 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2434 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2435 (vip-loop val
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2436 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2437 (vip-end-of-word-kernel)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2438 (vip-skip-nonseparators 'forward)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2439 (backward-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2440 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2441 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2442 (forward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2443 (vip-execute-com 'vip-end-of-Word val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2444
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2445 (defun vip-backward-word-kernel (val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2446 (while (> val 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2447 (backward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2448 (cond ((vip-looking-at-alpha)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2449 (vip-skip-alpha-backward "_"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2450 ((vip-looking-at-separator)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2451 (forward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2452 (vip-skip-separators nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2453 (backward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2454 (cond ((vip-looking-at-alpha)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2455 (vip-skip-alpha-backward "_"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2456 ((not (vip-looking-at-alphasep))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2457 (vip-skip-nonalphasep-backward))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2458 (t (forward-char))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2459 ((not (vip-looking-at-alphasep))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2460 (vip-skip-nonalphasep-backward)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2461 (setq val (1- val))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2462
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2463 (defun vip-backward-word (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2464 "Backward word."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2465 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2466 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2467 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2468 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2469 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2470 (let (i)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2471 (if (setq i (save-excursion (backward-char) (looking-at "\n")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2472 (backward-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2473 (vip-move-marker-locally 'vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2474 (if i (forward-char))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2475 (vip-backward-word-kernel val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2476 (if com (vip-execute-com 'vip-backward-word val com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2477
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2478 (defun vip-backward-Word (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2479 "Backward word delimited by white character."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2480 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2481 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2482 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2483 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2484 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2485 (let (i)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2486 (if (setq i (save-excursion (backward-char) (looking-at "\n")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2487 (backward-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2488 (vip-move-marker-locally 'vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2489 (if i (forward-char))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2490 (vip-loop val
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2491 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2492 (vip-skip-separators nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2493 (vip-skip-nonseparators 'backward)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2494 (if com (vip-execute-com 'vip-backward-Word val com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2495
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2496
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2497
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2498 ;; line commands
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2499
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2500 (defun vip-beginning-of-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2501 "Go to beginning of line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2502 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2503 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2504 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2505 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2506 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2507 (beginning-of-line val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2508 (if com (vip-execute-com 'vip-beginning-of-line val com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2509
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2510 (defun vip-bol-and-skip-white (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2511 "Beginning of line at first non-white character."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2512 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2513 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2514 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2515 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2516 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2517 (forward-to-indentation (1- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2518 (if com (vip-execute-com 'vip-bol-and-skip-white val com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2519
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2520 (defun vip-goto-eol (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2521 "Go to end of line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2522 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2523 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2524 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2525 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2526 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2527 (end-of-line val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2528 (if com (vip-execute-com 'vip-goto-eol val com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2529 (if vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2530 (if (and (eolp) (not (bolp))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2531 ;; a fix for vip-change-to-eol
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2532 (not (equal vip-current-state 'insert-state)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2533 (backward-char 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2534 ))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2535
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2536
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2537 (defun vip-goto-col (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2538 "Go to ARG's column."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2539 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2540 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2541 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2542 (com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2543 line-len)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2544 (setq line-len (- (vip-line-pos 'end) (vip-line-pos 'start)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2545 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2546 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2547 (forward-char (1- (min line-len val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2548 (while (> (current-column) (1- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2549 (backward-char 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2550 (if com (vip-execute-com 'vip-goto-col val com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2551 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2552 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2553 (if (> val (current-column)) (error "")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2554 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2555
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2556
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2557 (defun vip-next-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2558 "Go to next line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2559 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2560 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2561 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2562 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2563 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2564 (next-line val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2565 (if vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2566 (if (and (eolp) (not (bolp))) (backward-char 1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2567 (setq this-command 'next-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2568 (if com (vip-execute-com 'vip-next-line val com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2569
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2570 (defun vip-next-line-at-bol (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2571 "Next line at beginning of line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2572 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2573 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2574 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2575 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2576 (if (eobp) (error "Last line in buffer")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2577 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2578 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2579 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2580 (forward-line val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2581 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2582 (if com (vip-execute-com 'vip-next-line-at-bol val com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2583
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2584 (defun vip-previous-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2585 "Go to previous line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2586 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2587 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2588 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2589 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2590 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2591 (previous-line val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2592 (if vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2593 (if (and (eolp) (not (bolp))) (backward-char 1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2594 (setq this-command 'previous-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2595 (if com (vip-execute-com 'vip-previous-line val com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2596
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2597
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2598 (defun vip-previous-line-at-bol (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2599 "Previous line at beginning of line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2600 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2601 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2602 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2603 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2604 (if (bobp) (error "First line in buffer")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2605 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2606 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2607 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2608 (forward-line (- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2609 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2610 (if com (vip-execute-com 'vip-previous-line val com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2611
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2612 (defun vip-change-to-eol (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2613 "Change to end of line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2614 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2615 (vip-goto-eol (cons arg ?c)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2616
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2617 (defun vip-kill-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2618 "Delete line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2619 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2620 (vip-goto-eol (cons arg ?d)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2621
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2622 (defun vip-erase-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2623 "Erase line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2624 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2625 (vip-beginning-of-line (cons arg ?d)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2626
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2627
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2628 ;;; Moving around
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2629
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2630 (defun vip-goto-line (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2631 "Go to ARG's line. Without ARG go to end of buffer."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2632 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2633 (let ((val (vip-P-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2634 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2635 (vip-move-marker-locally 'vip-com-point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2636 (vip-deactivate-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2637 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2638 (if (null val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2639 (goto-char (point-max))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2640 (goto-char (point-min))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2641 (forward-line (1- val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2642
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2643 ;; positioning is done twice: before and after command execution
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2644 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2645 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2646
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2647 (if com (vip-execute-com 'vip-goto-line val com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2648
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2649 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2650 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2651 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2652
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2653 ;; Find ARG's occurrence of CHAR on the current line.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2654 ;; If FORWARD then search is forward, otherwise backward. OFFSET is used to
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2655 ;; adjust point after search.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2656 (defun vip-find-char (arg char forward offset)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2657 (or (char-or-string-p char) (error ""))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2658 (let ((arg (if forward arg (- arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2659 (cmd (if (eq vip-intermediate-command 'vip-repeat)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2660 (nth 5 vip-d-com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2661 (vip-array-to-string (this-command-keys))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2662 point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2663 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2664 (save-restriction
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2665 (if (> arg 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2666 (narrow-to-region
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2667 ;; forward search begins here
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2668 (if (eolp) (error "Command `%s': At end of line" cmd) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2669 ;; forward search ends here
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2670 (progn (end-of-line) (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2671 (narrow-to-region
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2672 ;; backward search begins from here
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2673 (if (bolp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2674 (error "Command `%s': At beginning of line" cmd) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2675 ;; backward search ends here
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2676 (progn (beginning-of-line) (point))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2677 ;; if arg > 0, point is forwarded before search.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2678 (if (> arg 0) (goto-char (1+ (point-min)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2679 (goto-char (point-max)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2680 (if (let ((case-fold-search nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2681 (search-forward (char-to-string char) nil 0 arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2682 (setq point (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2683 (error "Command `%s': `%c' not found" cmd char))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2684 (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
2685
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2686 (defun vip-find-char-forward (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2687 "Find char on the line.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2688 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
2689 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
2690 controlled by the sign of prefix numeric value."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2691 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2692 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2693 (com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2694 (cmd-representation (nth 5 vip-d-com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2695 (if (> val 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2696 ;; this means that the function was called interactively
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2697 (setq vip-f-char (read-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2698 vip-f-forward t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2699 vip-f-offset nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2700 ;; vip-repeat --- set vip-F-char from command-keys
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2701 (setq vip-F-char (if (stringp cmd-representation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2702 (vip-seq-last-elt cmd-representation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2703 vip-F-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2704 vip-f-char vip-F-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2705 (setq val (- val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2706 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2707 (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
2708 (setq val (- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2709 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2710 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2711 (setq vip-F-char vip-f-char) ; set new vip-F-char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2712 (forward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2713 (vip-execute-com 'vip-find-char-forward val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2714
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2715 (defun vip-goto-char-forward (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2716 "Go up to char ARG forward on line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2717 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2718 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2719 (com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2720 (cmd-representation (nth 5 vip-d-com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2721 (if (> val 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2722 ;; this means that the function was called interactively
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2723 (setq vip-f-char (read-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2724 vip-f-forward t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2725 vip-f-offset t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2726 ;; vip-repeat --- set vip-F-char from command-keys
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2727 (setq vip-F-char (if (stringp cmd-representation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2728 (vip-seq-last-elt cmd-representation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2729 vip-F-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2730 vip-f-char vip-F-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2731 (setq val (- val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2732 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2733 (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
2734 (setq val (- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2735 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2736 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2737 (setq vip-F-char vip-f-char) ; set new vip-F-char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2738 (forward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2739 (vip-execute-com 'vip-goto-char-forward val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2740
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2741 (defun vip-find-char-backward (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2742 "Find char ARG on line backward."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2743 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2744 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2745 (com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2746 (cmd-representation (nth 5 vip-d-com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2747 (if (> val 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2748 ;; this means that the function was called interactively
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2749 (setq vip-f-char (read-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2750 vip-f-forward nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2751 vip-f-offset nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2752 ;; vip-repeat --- set vip-F-char from command-keys
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2753 (setq vip-F-char (if (stringp cmd-representation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2754 (vip-seq-last-elt cmd-representation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2755 vip-F-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2756 vip-f-char vip-F-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2757 (setq val (- val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2758 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2759 (vip-find-char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2760 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
2761 (setq val (- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2762 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2763 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2764 (setq vip-F-char vip-f-char) ; set new vip-F-char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2765 (vip-execute-com 'vip-find-char-backward val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2766
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2767 (defun vip-goto-char-backward (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2768 "Go up to char ARG backward on line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2769 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2770 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2771 (com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2772 (cmd-representation (nth 5 vip-d-com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2773 (if (> val 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2774 ;; this means that the function was called interactively
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2775 (setq vip-f-char (read-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2776 vip-f-forward nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2777 vip-f-offset t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2778 ;; vip-repeat --- set vip-F-char from command-keys
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2779 (setq vip-F-char (if (stringp cmd-representation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2780 (vip-seq-last-elt cmd-representation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2781 vip-F-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2782 vip-f-char vip-F-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2783 (setq val (- val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2784 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2785 (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
2786 (setq val (- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2787 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2788 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2789 (setq vip-F-char vip-f-char) ; set new vip-F-char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2790 (vip-execute-com 'vip-goto-char-backward val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2791
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2792 (defun vip-repeat-find (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2793 "Repeat previous find command."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2794 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2795 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2796 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2797 (vip-deactivate-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2798 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2799 (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
2800 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2801 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2802 (if vip-f-forward (forward-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2803 (vip-execute-com 'vip-repeat-find val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2804
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2805 (defun vip-repeat-find-opposite (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2806 "Repeat previous find command in the opposite direction."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2807 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2808 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2809 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2810 (vip-deactivate-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2811 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2812 (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
2813 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2814 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2815 (if vip-f-forward (forward-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2816 (vip-execute-com 'vip-repeat-find-opposite val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2817
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2818
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2819 ;; window scrolling etc.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2820
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2821 (defun vip-other-window (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2822 "Switch to other window."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2823 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2824 (other-window arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2825 (or (not (eq vip-current-state 'emacs-state))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2826 (string= (buffer-name (current-buffer)) " *Minibuf-1*")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2827 (vip-change-state-to-vi)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2828
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2829 (defun vip-window-top (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2830 "Go to home window line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2831 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2832 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2833 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2834 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2835 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2836 (move-to-window-line (1- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2837
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2838 ;; positioning is done twice: before and after command execution
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2839 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2840 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2841
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2842 (if com (vip-execute-com 'vip-window-top val com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2843
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2844 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2845 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2846 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2847
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2848 (defun vip-window-middle (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2849 "Go to middle window line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2850 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2851 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2852 (com (vip-getCom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2853 lines)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2854 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2855 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2856 (if (not (pos-visible-in-window-p (point-max)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2857 (move-to-window-line (+ (/ (1- (window-height)) 2) (1- val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2858 (setq lines (count-lines (window-start) (point-max)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2859 (move-to-window-line (+ (/ lines 2) (1- val))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2860
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2861 ;; positioning is done twice: before and after command execution
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2862 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2863 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2864
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2865 (if com (vip-execute-com 'vip-window-middle val com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2866
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2867 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2868 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2869 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2870
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2871 (defun vip-window-bottom (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2872 "Go to last window line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2873 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2874 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2875 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2876 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2877 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2878 (move-to-window-line (- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2879
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2880 ;; positioning is done twice: before and after command execution
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2881 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2882 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2883
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2884 (if com (vip-execute-com 'vip-window-bottom val com))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2885
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2886 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2887 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2888 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2889
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2890 (defun vip-line-to-top (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2891 "Put current line on the home line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2892 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2893 (recenter (1- arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2894
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2895 (defun vip-line-to-middle (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2896 "Put current line on the middle line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2897 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2898 (recenter (+ (1- arg) (/ (1- (window-height)) 2))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2899
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2900 (defun vip-line-to-bottom (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2901 "Put current line on the last line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2902 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2903 (recenter (- (window-height) (1+ arg))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2904
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2905 ;; 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
2906 ;; 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
2907 ;; 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
2908 ;; (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
2909 ;; vip-search-scroll-threshold is negative - don't scroll.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2910 (defun vip-adjust-window ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2911 (let ((win-height (if vip-emacs-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2912 (1- (window-height)) ; adjust for modeline
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2913 (window-displayed-height)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2914 (pt (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2915 at-top-p at-bottom-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2916 min-scroll direction)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2917 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2918 (move-to-window-line 0) ; top
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2919 (setq at-top-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2920 (<= (count-lines pt (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2921 vip-search-scroll-threshold))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2922 (move-to-window-line -1) ; bottom
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2923 (setq at-bottom-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2924 (<= (count-lines pt (point)) vip-search-scroll-threshold))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2925 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2926 (cond (at-top-p (setq min-scroll (1- vip-search-scroll-threshold)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2927 direction 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2928 (at-bottom-p (setq min-scroll (1+ vip-search-scroll-threshold)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2929 direction -1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2930 (if min-scroll
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2931 (recenter
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2932 (* (max min-scroll (/ win-height 7)) direction)))
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
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2935
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2936 ;; paren match
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2937 ;; must correct this to only match ( to ) etc. On the other hand
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2938 ;; it is good that paren match gets confused, because that way you
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2939 ;; catch _all_ imbalances.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2940
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2941 (defun vip-paren-match (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2942 "Go to the matching parenthesis."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2943 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2944 (vip-leave-region-active)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2945 (let ((com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2946 (parse-sexp-ignore-comments vip-parse-sexp-ignore-comments)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2947 anchor-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2948 (if (integerp arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2949 (if (or (> arg 99) (< arg 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2950 (error "Prefix must be between 1 and 99")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2951 (goto-char
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2952 (if (> (point-max) 80000)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2953 (* (/ (point-max) 100) arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2954 (/ (* (point-max) arg) 100)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2955 (back-to-indentation))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2956 (let (beg-lim end-lim)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2957 (if (and (eolp) (not (bolp))) (forward-char -1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2958 (if (not (looking-at "[][(){}]"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2959 (setq anchor-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2960 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2961 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2962 (setq beg-lim (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2963 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2964 (setq end-lim (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2965 (cond ((re-search-forward "[][(){}]" end-lim t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2966 (backward-char) )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2967 ((re-search-backward "[][(){}]" beg-lim t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2968 (t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2969 (error "No matching character on line"))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2970 (cond ((looking-at "[\(\[{]")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2971 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2972 (forward-sexp 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2973 (if com
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 (backward-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2976 (anchor-point
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2977 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2978 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2979 (vip-move-marker-locally 'vip-com-point anchor-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2980 (forward-char 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2981 (vip-execute-com 'vip-paren-match nil com)
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 ((looking-at "[])}]")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2984 (forward-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2985 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2986 (backward-sexp 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2987 (if com (vip-execute-com 'vip-paren-match nil com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2988 (t (error ""))))))
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 (defun vip-toggle-parse-sexp-ignore-comments ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2991 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2992 (setq vip-parse-sexp-ignore-comments (not vip-parse-sexp-ignore-comments))
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
2993 (princ (format
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
2994 "From now on, `%%' will %signore parentheses inside comment fields"
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
2995 (if vip-parse-sexp-ignore-comments "" "NOT "))))
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2996
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2997
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2998 ;; sentence ,paragraph and heading
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
2999
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3000 (defun vip-forward-sentence (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3001 "Forward sentence."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3002 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3003 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3004 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3005 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3006 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3007 (forward-sentence val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3008 (if com (vip-execute-com 'vip-forward-sentence nil com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3009
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3010 (defun vip-backward-sentence (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3011 "Backward sentence."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3012 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3013 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3014 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3015 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3016 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3017 (backward-sentence val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3018 (if com (vip-execute-com 'vip-backward-sentence nil com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3019
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3020 (defun vip-forward-paragraph (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3021 "Forward paragraph."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3022 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3023 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3024 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3025 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3026 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3027 (forward-paragraph val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3028 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3029 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3030 (backward-char 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3031 (vip-execute-com 'vip-forward-paragraph nil com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3032
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3033 (defun vip-backward-paragraph (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3034 "Backward paragraph."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3035 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3036 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3037 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3038 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3039 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3040 (backward-paragraph val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3041 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3042 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3043 (forward-char 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3044 (vip-execute-com 'vip-backward-paragraph nil com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3045 (backward-char 1)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3046
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3047 ;; should be mode-specific etc.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3048
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3049 (defun vip-prev-heading (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3050 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3051 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3052 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3053 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3054 (re-search-backward vip-heading-start nil t val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3055 (goto-char (match-beginning 0))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3056 (if com (vip-execute-com 'vip-prev-heading nil com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3057
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3058 (defun vip-heading-end (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3059 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3060 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3061 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3062 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3063 (re-search-forward vip-heading-end nil t val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3064 (goto-char (match-beginning 0))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3065 (if com (vip-execute-com 'vip-heading-end nil com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3066
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3067 (defun vip-next-heading (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3068 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3069 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3070 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3071 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3072 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3073 (re-search-forward vip-heading-start nil t val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3074 (goto-char (match-beginning 0))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3075 (if com (vip-execute-com 'vip-next-heading nil com))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3076
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3077
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3078 ;; scrolling
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3079
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3080 (defun vip-scroll-screen (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3081 "Scroll to next screen."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3082 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3083 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3084 (if (> arg 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3085 (while (> arg 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3086 (scroll-up)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3087 (setq arg (1- arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3088 (while (> 0 arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3089 (scroll-down)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3090 (setq arg (1+ arg))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3091 (error (beep 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3092 (if (> arg 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3093 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3094 (message "End of buffer")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3095 (goto-char (point-max)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3096 (message "Beginning of buffer")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3097 (goto-char (point-min))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3098 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3099
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3100 (defun vip-scroll-screen-back (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3101 "Scroll to previous screen."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3102 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3103 (vip-scroll-screen (- arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3104
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3105 (defun vip-scroll-down (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3106 "Pull down half screen."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3107 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3108 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3109 (if (null arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3110 (scroll-down (/ (window-height) 2))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3111 (scroll-down arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3112 (error (beep 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3113 (message "Beginning of buffer")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3114 (goto-char (point-min)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3115
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3116 (defun vip-scroll-down-one (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3117 "Scroll up one line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3118 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3119 (scroll-down arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3120
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3121 (defun vip-scroll-up (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3122 "Pull up half screen."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3123 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3124 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3125 (if (null arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3126 (scroll-up (/ (window-height) 2))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3127 (scroll-up arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3128 (error (beep 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3129 (message "End of buffer")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3130 (goto-char (point-max)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3131
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3132 (defun vip-scroll-up-one (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3133 "Scroll down one line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3134 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3135 (scroll-up arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3136
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3137
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3138 ;; searching
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3139
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3140 (defun vip-if-string (prompt)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3141 (let ((s (vip-read-string-with-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3142 prompt
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3143 nil ; no initial
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3144 'vip-search-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3145 (car vip-search-history))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3146 (if (not (string= s ""))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3147 (setq vip-s-string s))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3148
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3149
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3150 (defun vip-toggle-search-style (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3151 "Toggle the value of vip-case-fold-search/vip-re-search.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3152 Without prefix argument, will ask which search style to toggle. With prefix
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3153 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
3154
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3155 Although this function is bound to \\[vip-toggle-search-style], the most
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3156 convenient way to use it is to bind `//' to the macro
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3157 `1 M-x vip-toggle-search-style' and `///' to
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3158 `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
3159 toggle case-fold-search and hitting `/' three times witth toggle regexp
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3160 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
3161 the Emacs binding of `/'."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3162 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3163 (let (msg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3164 (cond ((or (eq arg 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3165 (and (null arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3166 (y-or-n-p (format "Search style: '%s'. Want '%s'? "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3167 (if vip-case-fold-search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3168 "case-insensitive" "case-sensitive")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3169 (if vip-case-fold-search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3170 "case-sensitive"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3171 "case-insensitive")))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3172 (setq vip-case-fold-search (null vip-case-fold-search))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3173 (if vip-case-fold-search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3174 (setq msg "Search becomes case-insensitive")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3175 (setq msg "Search becomes case-sensitive")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3176 ((or (eq arg 2)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3177 (and (null arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3178 (y-or-n-p (format "Search style: '%s'. Want '%s'? "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3179 (if vip-re-search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3180 "regexp-search" "vanilla-search")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3181 (if vip-re-search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3182 "vanilla-search"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3183 "regexp-search")))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3184 (setq vip-re-search (null vip-re-search))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3185 (if vip-re-search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3186 (setq msg "Search becomes regexp-style")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3187 (setq msg "Search becomes vanilla-style")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3188 (t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3189 (setq msg "Search style remains unchanged")))
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3190 (princ msg t)))
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3191
18855
915f558fc1ce new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
3192 (defun vip-set-searchstyle-toggling-macros (unset)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3193 "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
3194 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
3195 toggles regexp search is bound to `///'.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3196 With a prefix argument, this function unsets the macros. "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3197 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3198 (or noninteractive
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3199 (if (not unset)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3200 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3201 ;; toggle case sensitivity in search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3202 (vip-record-kbd-macro
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3203 "//" 'vi-state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3204 [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
3205 't)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3206 ;; toggle regexp/vanila search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3207 (vip-record-kbd-macro
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3208 "///" 'vi-state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3209 [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
3210 't)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3211 (if (interactive-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3212 (message
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3213 "// and /// now toggle case-sensitivity and regexp search")))
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3214 (vip-unrecord-kbd-macro "//" 'vi-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3215 (sit-for 2)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3216 (vip-unrecord-kbd-macro "///" 'vi-state))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3217
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3218
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3219 (defun vip-set-parsing-style-toggling-macro (unset)
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3220 "Set `%%%' to be a macro that toggles whether comment fields should be parsed for matching parentheses.
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3221 This is used in conjunction with the `%' command.
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3222
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3223 With a prefix argument, unsets the macro."
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3224 (interactive "P")
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3225 (or noninteractive
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3226 (if (not unset)
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3227 (progn
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3228 ;; Make %%% toggle parsing comments for matching parentheses
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3229 (vip-record-kbd-macro
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3230 "%%%" 'vi-state
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3231 [(meta x) v i p - t o g g l e - p a r s e - s e x p - i g n o r e - c o m m e n t s return]
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3232 't)
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3233 (if (interactive-p)
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3234 (message
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3235 "%%%%%% now toggles whether comments should be parsed for matching parentheses")))
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3236 (vip-unrecord-kbd-macro "%%%" 'vi-state))))
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3237
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3238
18855
915f558fc1ce new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18839
diff changeset
3239 (defun vip-set-emacs-state-searchstyle-macros (unset &optional arg-majormode)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3240 "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
3241 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
3242 toggles regexp search is bound to `///'.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3243 With a prefix argument, this function unsets the macros.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3244 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
3245 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
3246 the macros are set in the current major mode.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3247 \(When unsetting the macros, the second argument has no effect.\)"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3248 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3249 (or noninteractive
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3250 (if (not unset)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3251 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3252 ;; toggle case sensitivity in search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3253 (vip-record-kbd-macro
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3254 "//" 'emacs-state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3255 [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
3256 (or arg-majormode major-mode))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3257 ;; toggle regexp/vanila search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3258 (vip-record-kbd-macro
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3259 "///" 'emacs-state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3260 [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
3261 (or arg-majormode major-mode))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3262 (if (interactive-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3263 (message
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3264 "// and /// now toggle case-sensitivity and regexp search.")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3265 (vip-unrecord-kbd-macro "//" 'emacs-state)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3266 (sit-for 2)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3267 (vip-unrecord-kbd-macro "///" 'emacs-state))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3268
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3269
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3270 (defun vip-search-forward (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3271 "Search a string forward.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3272 ARG is used to find the ARG's occurrence of the string.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3273 Null string will repeat previous search."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3274 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3275 (let ((val (vip-P-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3276 (com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3277 (old-str vip-s-string))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3278 (setq vip-s-forward t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3279 (vip-if-string "/")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3280 ;; this is not used at present, but may be used later
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3281 (if (or (not (equal old-str vip-s-string))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3282 (not (markerp vip-local-search-start-marker))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3283 (not (marker-buffer vip-local-search-start-marker)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3284 (setq vip-local-search-start-marker (point-marker)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3285 (vip-search vip-s-string t val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3286 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3287 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3288 (vip-move-marker-locally 'vip-com-point (mark t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3289 (vip-execute-com 'vip-search-next val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3290
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3291 (defun vip-search-backward (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3292 "Search a string backward.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3293 ARG is used to find the ARG's occurrence of the string.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3294 Null string will repeat previous search."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3295 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3296 (let ((val (vip-P-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3297 (com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3298 (old-str vip-s-string))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3299 (setq vip-s-forward nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3300 (vip-if-string "?")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3301 ;; this is not used at present, but may be used later
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3302 (if (or (not (equal old-str vip-s-string))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3303 (not (markerp vip-local-search-start-marker))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3304 (not (marker-buffer vip-local-search-start-marker)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3305 (setq vip-local-search-start-marker (point-marker)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3306 (vip-search vip-s-string nil val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3307 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3308 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3309 (vip-move-marker-locally 'vip-com-point (mark t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3310 (vip-execute-com 'vip-search-next val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3311
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3312
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3313 ;; Search for COUNT's occurrence of STRING.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3314 ;; Search is forward if FORWARD is non-nil, otherwise backward.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3315 ;; INIT-POINT is the position where search is to start.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3316 ;; Arguments:
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3317 ;; (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
3318 (defun vip-search (string forward arg
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3319 &optional no-offset init-point fail-if-not-found)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3320 (if (not (equal string ""))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3321 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3322 (com (vip-getcom arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3323 (offset (not no-offset))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3324 (case-fold-search vip-case-fold-search)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3325 (start-point (or init-point (point))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3326 (vip-deactivate-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3327 (if forward
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 offset (vip-forward-char-carefully))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3331 (if vip-re-search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3332 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3333 (re-search-forward string nil nil val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3334 (re-search-backward string))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3335 (search-forward string nil nil val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3336 (search-backward string))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3337 (if (not (equal start-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3338 (push-mark start-point t)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3339 (search-failed
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3340 (if (and (not fail-if-not-found) vip-search-wrap-around-t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3341 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3342 (message "Search wrapped around BOTTOM of buffer")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3343 (goto-char (point-min))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3344 (vip-search string forward (cons 1 com) t start-point 'fail)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3345 ;; don't wait in macros
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3346 (or executing-kbd-macro (sit-for 2))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3347 ;; delete the wrap-around message
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3348 (message "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3349 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3350 (goto-char start-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3351 (error "`%s': %s not found"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3352 string
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3353 (if vip-re-search "Pattern" "String"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3354 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3355 ;; backward
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3356 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3357 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3358 (if vip-re-search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3359 (re-search-backward string nil nil val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3360 (search-backward string nil nil val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3361 (if (not (equal start-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3362 (push-mark start-point t)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3363 (search-failed
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3364 (if (and (not fail-if-not-found) vip-search-wrap-around-t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3365 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3366 (message "Search wrapped around TOP of buffer")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3367 (goto-char (point-max))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3368 (vip-search string forward (cons 1 com) t start-point 'fail)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3369 ;; don't wait in macros
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3370 (or executing-kbd-macro (sit-for 2))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3371 ;; delete the wrap-around message
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3372 (message "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3373 )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3374 (goto-char start-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3375 (error "`%s': %s not found"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3376 string
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3377 (if vip-re-search "Pattern" "String"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3378 ))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3379 ;; pull up or down if at top/bottom of window
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3380 (vip-adjust-window)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3381 ;; highlight the result of search
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3382 ;; don't wait and don't highlight in macros
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3383 (or executing-kbd-macro
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3384 vip-inside-command-argument-action
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3385 (vip-flash-search-pattern))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3386 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3387
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3388 (defun vip-search-next (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3389 "Repeat previous search."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3390 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3391 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3392 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3393 (if (null vip-s-string) (error vip-NoPrevSearch))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3394 (vip-search vip-s-string vip-s-forward arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3395 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3396 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3397 (vip-move-marker-locally 'vip-com-point (mark t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3398 (vip-execute-com 'vip-search-next val com)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3399
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3400 (defun vip-search-Next (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3401 "Repeat previous search in the reverse direction."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3402 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3403 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3404 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3405 (if (null vip-s-string) (error vip-NoPrevSearch))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3406 (vip-search vip-s-string (not vip-s-forward) arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3407 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3408 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3409 (vip-move-marker-locally 'vip-com-point (mark t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3410 (vip-execute-com 'vip-search-Next val com)))))
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 ;; Search contents of buffer defined by one of Viper's motion commands.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3414 ;; Repeatable via `n' and `N'.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3415 (defun vip-buffer-search-enable (&optional c)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3416 (cond (c (setq vip-buffer-search-char c))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3417 ((null vip-buffer-search-char)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3418 (setq vip-buffer-search-char ?g)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3419 (define-key vip-vi-basic-map
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3420 (char-to-string vip-buffer-search-char) 'vip-command-argument)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3421 (aset vip-exec-array vip-buffer-search-char 'vip-exec-buffer-search)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3422 (setq vip-prefix-commands (cons vip-buffer-search-char vip-prefix-commands)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3423
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3424 ;; This is a Viper wraper for isearch-forward.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3425 (defun vip-isearch-forward (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3426 "Do incremental search forward."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3427 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3428 ;; emacs bug workaround
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3429 (if (listp arg) (setq arg (car arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3430 (vip-exec-form-in-emacs (list 'isearch-forward arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3431
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3432 ;; This is a Viper wraper for isearch-backward."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3433 (defun vip-isearch-backward (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3434 "Do incremental search backward."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3435 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3436 ;; emacs bug workaround
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3437 (if (listp arg) (setq arg (car arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3438 (vip-exec-form-in-emacs (list 'isearch-backward arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3439
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3440
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3441 ;; visiting and killing files, buffers
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3442
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3443 (defun vip-switch-to-buffer ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3444 "Switch to buffer in the current window."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3445 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3446 (let (buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3447 (setq buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3448 (read-buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3449 (format "Switch to buffer in this window \(%s\): "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3450 (buffer-name (other-buffer (current-buffer))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3451 (switch-to-buffer buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3452 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3453
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3454 (defun vip-switch-to-buffer-other-window ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3455 "Switch to buffer in another window."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3456 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3457 (let (buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3458 (setq buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3459 (read-buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3460 (format "Switch to buffer in another window \(%s\): "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3461 (buffer-name (other-buffer (current-buffer))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3462 (switch-to-buffer-other-window buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3463 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3464
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3465 (defun vip-kill-buffer ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3466 "Kill a buffer."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3467 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3468 (let (buffer buffer-name)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3469 (setq buffer-name
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3470 (read-buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3471 (format "Kill buffer \(%s\): "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3472 (buffer-name (current-buffer)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3473 (setq buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3474 (if (null buffer-name)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3475 (current-buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3476 (get-buffer buffer-name)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3477 (if (null buffer) (error "`%s': No such buffer" buffer-name))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3478 (if (or (not (buffer-modified-p buffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3479 (y-or-n-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3480 (format
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3481 "Buffer `%s' is modified, are you sure you want to kill it? "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3482 buffer-name)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3483 (kill-buffer buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3484 (error "Buffer not killed"))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3485
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3486
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3487 (defcustom vip-smart-suffix-list
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3488 '("" "tex" "c" "cc" "C" "el" "java" "html" "htm" "pl" "P" "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3489 "*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
3490 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
3491 prefix and many different suffixes. Usually, only one of the suffixes
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3492 represents an editable file. However, file completion will stop at the `.'
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3493 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
3494 select the appropriate suffix.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3495
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3496 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
3497 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
3498 suffixes, the user is asked to confirm.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3499
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3500 To turn this feature off, set this variable to nil."
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3501 :type '(set string)
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3502 :group 'viper)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3503
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3504 ;; Try to add suffix to files ending with a `.'
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3505 ;; Useful when the user hits RET on a non-completed file name.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3506 (defun vip-file-add-suffix ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3507 (let ((count 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3508 (len (length vip-smart-suffix-list))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3509 (file (buffer-string))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3510 found key cmd suff)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3511 (goto-char (point-max))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3512 (if (and vip-smart-suffix-list (string-match "\\.$" file))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3513 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3514 (while (and (not found) (< count len))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3515 (setq suff (nth count vip-smart-suffix-list)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3516 count (1+ count))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3517 (if (file-exists-p (format "%s%s" file suff))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3518 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3519 (setq found t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3520 (insert suff))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3521
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3522 (if found
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3523 ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3524 (vip-tmp-insert-at-eob " [Please complete file name]")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3525 (unwind-protect
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3526 (while (not (memq cmd '(exit-minibuffer vip-exit-minibuffer)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3527 (setq cmd
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3528 (key-binding (setq key (read-key-sequence nil))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3529 (cond ((eq cmd 'self-insert-command)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3530 (if vip-xemacs-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3531 (insert (events-to-keys key))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3532 (insert key)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3533 ((memq cmd '(exit-minibuffer vip-exit-minibuffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3534 nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3535 (t (command-execute cmd)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3536 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3537 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3538 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3539
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3540
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3541
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3542
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3543 ;; yank and pop
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3544
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3545 (defsubst vip-yank (text)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3546 "Yank TEXT silently. This works correctly with Emacs's yank-pop command."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3547 (insert text)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3548 (setq this-command 'yank))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3549
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3550 (defun vip-put-back (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3551 "Put back after point/below line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3552 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3553 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3554 (text (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3555 (cond ((vip-valid-register vip-use-register '(digit))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3556 (current-kill (- vip-use-register ?1) 'do-not-rotate))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3557 ((vip-valid-register vip-use-register)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3558 (get-register (downcase vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3559 (t (error vip-InvalidRegister vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3560 (current-kill 0))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3561 (if (null text)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3562 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3563 (let ((reg vip-use-register))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3564 (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3565 (error vip-EmptyRegister reg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3566 (error "")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3567 (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3568 (if (vip-end-with-a-newline-p text)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3569 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3570 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3571 (if (eobp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3572 (insert "\n")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3573 (forward-line 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3574 (beginning-of-line))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3575 (if (not (eolp)) (vip-forward-char-carefully)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3576 (set-marker (vip-mark-marker) (point) (current-buffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3577 (vip-set-destructive-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3578 (list 'vip-put-back val nil vip-use-register nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3579 (vip-loop val (vip-yank text)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3580 ;; 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
3581 ;; newline; it leaves the cursor at the beginning when the text contains
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3582 ;; a newline
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3583 (if (vip-same-line (point) (mark))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3584 (or (= (point) (mark)) (vip-backward-char-carefully))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3585 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3586 (if (bolp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3587 (back-to-indentation)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3588 (vip-deactivate-mark))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3589
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3590 (defun vip-Put-back (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3591 "Put back at point/above line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3592 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3593 (let ((val (vip-p-val arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3594 (text (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3595 (cond ((vip-valid-register vip-use-register '(digit))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3596 (current-kill (- vip-use-register ?1) 'do-not-rotate))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3597 ((vip-valid-register vip-use-register)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3598 (get-register (downcase vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3599 (t (error vip-InvalidRegister vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3600 (current-kill 0))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3601 (if (null text)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3602 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3603 (let ((reg vip-use-register))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3604 (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3605 (error vip-EmptyRegister reg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3606 (error "")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3607 (setq vip-use-register nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3608 (if (vip-end-with-a-newline-p text) (beginning-of-line))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3609 (vip-set-destructive-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3610 (list 'vip-Put-back val nil vip-use-register nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3611 (set-marker (vip-mark-marker) (point) (current-buffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3612 (vip-loop val (vip-yank text)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3613 ;; 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
3614 ;; newline; it leaves the cursor at the beginning when the text contains
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3615 ;; a newline
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3616 (if (vip-same-line (point) (mark))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3617 (or (= (point) (mark)) (vip-backward-char-carefully))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3618 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3619 (if (bolp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3620 (back-to-indentation)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3621 (vip-deactivate-mark))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3622
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3623
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3624 ;; Copy region to kill-ring.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3625 ;; 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
3626 (defun vip-copy-region-as-kill (beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3627 (condition-case nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3628 (copy-region-as-kill beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3629 (error (copy-region-as-kill beg beg))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3630
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3631
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3632 (defun vip-delete-char (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3633 "Delete character."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3634 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3635 (let ((val (vip-p-val arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3636 (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
3637 (if (> val 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3638 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3639 (let ((here (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3640 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3641 (if (> val (- (point) here))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3642 (setq val (- (point) here))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3643 (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
3644 (if (and vip-ex-style-motion (eolp))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3645 (if (bolp) (error "") (setq val 0))) ; not bol---simply back 1 ch
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 vip-ex-style-motion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3657 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3658 (delete-char val t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3659 (if (and (eolp) (not (bolp))) (backward-char 1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3660 (if (eolp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3661 (delete-backward-char val t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3662 (delete-char val t)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3663
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3664 (defun vip-delete-backward-char (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3665 "Delete previous character. On reaching beginning of line, stop and beep."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3666 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3667 (let ((val (vip-p-val arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3668 (vip-set-destructive-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3669 (list 'vip-delete-backward-char val nil nil nil nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3670 (if (> val 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3671 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3672 (let ((here (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3673 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3674 (if (> val (- here (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3675 (setq val (- here (point)))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3676 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3677 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3678 (cond ((vip-valid-register vip-use-register '(Letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3679 (vip-append-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3680 (downcase vip-use-register) (point) (+ (point) val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3681 ((vip-valid-register vip-use-register)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3682 (copy-to-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3683 vip-use-register (point) (+ (point) val) nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3684 (t (error vip-InvalidRegister vip-use-register)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3685 (setq vip-use-register nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3686 (if (bolp) (ding)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3687 (delete-backward-char val t))))
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 (defun vip-del-backward-char-in-insert ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3690 "Delete 1 char backwards while in insert mode."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3691 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3692 (if (and vip-ex-style-editing-in-insert (bolp))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3693 (beep 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3694 (delete-backward-char 1 t)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3695
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3696 (defun vip-del-backward-char-in-replace ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3697 "Delete one character in replace mode.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3698 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
3699 charecters. If it is nil, then the cursor just moves backwards, similarly
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3700 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
3701 cursor move past the beginning of line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3702 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3703 (cond (vip-delete-backwards-in-replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3704 (cond ((not (bolp))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3705 (delete-backward-char 1 t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3706 (vip-ex-style-editing-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3707 (beep 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3708 ((bobp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3709 (beep 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3710 (t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3711 (delete-backward-char 1 t))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3712 (vip-ex-style-editing-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3713 (if (bolp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3714 (beep 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3715 (backward-char 1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3716 (t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3717 (backward-char 1))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3718
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3719
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3720
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3721 ;; join lines.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3722
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3723 (defun vip-join-lines (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3724 "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
3725 (interactive "*P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3726 (let ((val (vip-P-val arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3727 (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
3728 (vip-loop (if (null val) 1 (1- val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3729 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3730 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3731 (if (not (eobp))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3732 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3733 (forward-line 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3734 (delete-region (point) (1- (point)))
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3735 (fixup-whitespace)
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3736 ;; fixup-whitespace sometimes does not leave space
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3737 ;; between objects, so we insert it as in Vi
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3738 (or (looking-at " ")
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3739 (insert " ")
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3740 (backward-char 1))
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
3741 ))))))
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3742
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3743
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3744 ;; Replace state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3745
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3746 (defun vip-change (beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3747 (if (markerp beg) (setq beg (marker-position beg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3748 (if (markerp end) (setq end (marker-position end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3749 ;; beg is sometimes (mark t), which may be nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3750 (or beg (setq beg end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3751
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3752 (vip-set-complex-command-for-undo)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3753 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3754 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3755 (copy-to-register vip-use-register beg end nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3756 (setq vip-use-register nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3757 (vip-set-replace-overlay beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3758 (setq last-command nil) ; separate repl text from prev kills
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3759
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3760 (if (= (vip-replace-start) (point-max))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3761 (error "End of buffer"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3762
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3763 (setq vip-last-replace-region
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3764 (buffer-substring (vip-replace-start)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3765 (vip-replace-end)))
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 ;; protect against error while inserting "@" and other disasters
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3768 ;; (e.g., read-only buff)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3769 (condition-case conds
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3770 (if (or vip-allow-multiline-replace-regions
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3771 (vip-same-line (vip-replace-start)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3772 (vip-replace-end)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3773 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3774 ;; tabs cause problems in replace, so untabify
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3775 (goto-char (vip-replace-end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3776 (insert-before-markers "@") ; put placeholder after the TAB
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3777 (untabify (vip-replace-start) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3778 ;; del @, don't put on kill ring
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3779 (delete-backward-char 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3780
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3781 (vip-set-replace-overlay-glyphs
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3782 vip-replace-region-start-delimiter
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3783 vip-replace-region-end-delimiter)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3784 ;; this move takes care of the last posn in the overlay, which
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3785 ;; has to be shifted because of insert. We can't simply insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3786 ;; "$" before-markers because then overlay-start will shift the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3787 ;; beginning of the overlay in case we are replacing a single
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3788 ;; character. This fixes the bug with `s' and `cl' commands.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3789 (vip-move-replace-overlay (vip-replace-start) (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3790 (goto-char (vip-replace-start))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3791 (vip-change-state-to-replace t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3792 (kill-region (vip-replace-start)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3793 (vip-replace-end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3794 (vip-hide-replace-overlay)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3795 (vip-change-state-to-insert))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3796 (error ;; make sure that the overlay doesn't stay.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3797 ;; go back to the original point
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3798 (goto-char (vip-replace-start))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3799 (vip-hide-replace-overlay)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3800 (vip-message-conditions conds))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3801
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3802
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3803 (defun vip-change-subr (beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3804 ;; beg is sometimes (mark t), which may be nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3805 (or beg (setq beg end))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3806
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3807 (if vip-use-register
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3808 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3809 (copy-to-register vip-use-register beg end nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3810 (setq vip-use-register nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3811 (kill-region beg end)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3812 (setq this-command 'vip-change)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3813 (vip-yank-last-insertion))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3814
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3815 (defun vip-toggle-case (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3816 "Toggle character case."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3817 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3818 (let ((val (vip-p-val arg)) (c))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3819 (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
3820 (while (> val 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3821 (setq c (following-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3822 (delete-char 1 nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3823 (if (eq c (upcase c))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3824 (insert-char (downcase c) 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3825 (insert-char (upcase c) 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3826 (if (eolp) (backward-char 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3827 (setq val (1- val)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3828
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3829
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3830 ;; query replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3831
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3832 (defun vip-query-replace ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3833 "Query replace.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3834 If a null string is suplied as the string to be replaced,
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3835 the query replace mode will toggle between string replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3836 and regexp replace."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3837 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3838 (let (str)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3839 (setq str (vip-read-string-with-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3840 (if vip-re-query-replace "Query replace regexp: "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3841 "Query replace: ")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3842 nil ; no initial
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3843 'vip-replace1-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3844 (car vip-replace1-history) ; default
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3845 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3846 (if (string= str "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3847 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3848 (setq vip-re-query-replace (not vip-re-query-replace))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3849 (message "Query replace mode changed to %s"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3850 (if vip-re-query-replace "regexp replace"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3851 "string replace")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3852 (if vip-re-query-replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3853 (query-replace-regexp
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3854 str
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3855 (vip-read-string-with-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3856 (format "Query replace regexp `%s' with: " str)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3857 nil ; no initial
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3858 'vip-replace1-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3859 (car vip-replace1-history) ; default
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3860 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3861 (query-replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3862 str
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3863 (vip-read-string-with-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3864 (format "Query replace `%s' with: " str)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3865 nil ; no initial
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3866 'vip-replace1-history
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3867 (car vip-replace1-history) ; default
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3868 ))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3869
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3870
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3871 ;; marking
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 (defun vip-mark-beginning-of-buffer ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3874 "Mark beginning of buffer."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3875 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3876 (push-mark (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3877 (goto-char (point-min))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3878 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3879 (message "Mark set at the beginning of buffer"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3880
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3881 (defun vip-mark-end-of-buffer ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3882 "Mark end of buffer."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3883 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3884 (push-mark (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3885 (goto-char (point-max))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3886 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3887 (message "Mark set at the end of buffer"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3888
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3889 (defun vip-mark-point ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3890 "Set mark at point of buffer."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3891 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3892 (let ((char (read-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3893 (cond ((and (<= ?a char) (<= char ?z))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3894 (point-to-register (1+ (- char ?a))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3895 ((= char ?<) (vip-mark-beginning-of-buffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3896 ((= char ?>) (vip-mark-end-of-buffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3897 ((= char ?.) (vip-set-mark-if-necessary))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3898 ((= char ?,) (vip-cycle-through-mark-ring))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3899 ((= char ?D) (mark-defun))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3900 (t (error ""))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3901 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3902
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3903 ;; Algorithm: If first invocation of this command save mark on ring, goto
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3904 ;; 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
3905 ;; making it into the new mark, M1.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3906 ;; 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
3907 ;; So, if you hit '' or `` then you can return to p1.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3908 ;;
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3909 ;; If repeated command, pop top elt from the ring into mark and
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3910 ;; 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
3911 ;; 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
3912 ;; 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
3913 ;; etc.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3914 (defun vip-cycle-through-mark-ring ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3915 "Visit previous locations on the mark ring.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3916 One can use `` and '' to temporarily jump 1 step back."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3917 (let* ((sv-pt (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3918 ;; if repeated `m,' command, pop the previously saved mark.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3919 ;; 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
3920 ;; user types `` or '' and is discarded
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3921 ;; from the mark ring by the next `m,' command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3922 ;; In any case, go to the previous or previously saved mark.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3923 ;; Then push the current mark (popped off the ring) and set current
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3924 ;; 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
3925 ;; m, command.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3926 (if (eq last-command 'vip-cycle-through-mark-ring)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3927 ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3928 ;; save current mark if the first iteration
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3929 (setq mark-ring (delete (vip-mark-marker) mark-ring))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3930 (if (mark t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3931 (push-mark (mark t) t)) )
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3932 (pop-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3933 (set-mark-command 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3934 ;; don't duplicate mark on the ring
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3935 (setq mark-ring (delete (vip-mark-marker) mark-ring))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3936 (push-mark sv-pt t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3937 (vip-deactivate-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3938 (setq this-command 'vip-cycle-through-mark-ring)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3939 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3940
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3941
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3942 (defun vip-goto-mark (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3943 "Go to mark."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3944 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3945 (let ((char (read-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3946 (com (vip-getcom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3947 (vip-goto-mark-subr char com nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3948
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3949 (defun vip-goto-mark-and-skip-white (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3950 "Go to mark and skip to first non-white character on line."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3951 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3952 (let ((char (read-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3953 (com (vip-getCom arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3954 (vip-goto-mark-subr char com t)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3955
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3956 (defun vip-goto-mark-subr (char com skip-white)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3957 (if (eobp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3958 (if (bobp)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3959 (error "Empty buffer")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3960 (backward-char 1)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3961 (cond ((vip-valid-register char '(letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3962 (let* ((buff (current-buffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3963 (reg (1+ (- char ?a)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3964 (text-marker (get-register reg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3965 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3966 (if (not (vip-valid-marker text-marker))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3967 (error vip-EmptyTextmarker char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3968 (if (and (vip-same-line (point) vip-last-jump)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3969 (= (point) vip-last-jump-ignore))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3970 (push-mark vip-last-jump t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3971 (push-mark nil t)) ; no msg
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3972 (vip-register-to-point reg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3973 (setq vip-last-jump (point-marker))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3974 (cond (skip-white
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3975 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3976 (setq vip-last-jump-ignore (point))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3977 (if com
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3978 (if (equal buff (current-buffer))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3979 (vip-execute-com (if skip-white
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3980 'vip-goto-mark-and-skip-white
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3981 'vip-goto-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3982 nil com)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3983 (switch-to-buffer buff)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3984 (goto-char vip-com-point)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3985 (vip-change-state-to-vi)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3986 (error "")))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3987 ((and (not skip-white) (= char ?`))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3988 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3989 (if (and (vip-same-line (point) vip-last-jump)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3990 (= (point) vip-last-jump-ignore))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3991 (goto-char vip-last-jump))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3992 (if (null (mark t)) (error "Mark is not set in this buffer"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3993 (if (= (point) (mark t)) (pop-mark))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3994 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3995 (setq vip-last-jump (point-marker)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3996 vip-last-jump-ignore 0)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3997 (if com (vip-execute-com 'vip-goto-mark nil com)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3998 ((and skip-white (= char ?'))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
3999 (if com (vip-move-marker-locally 'vip-com-point (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4000 (if (and (vip-same-line (point) vip-last-jump)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4001 (= (point) vip-last-jump-ignore))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4002 (goto-char vip-last-jump))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4003 (if (= (point) (mark t)) (pop-mark))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4004 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4005 (setq vip-last-jump (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4006 (back-to-indentation)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4007 (setq vip-last-jump-ignore (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4008 (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
4009 (t (error vip-InvalidTextmarker char))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4010
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4011 (defun vip-insert-tab ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4012 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4013 (insert-tab))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4014
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4015 (defun vip-exchange-point-and-mark ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4016 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4017 (exchange-point-and-mark)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4018 (back-to-indentation))
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 ;; Input Mode Indentation
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4021
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4022 ;; Returns t, if the string before point matches the regexp STR.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4023 (defsubst vip-looking-back (str)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4024 (and (save-excursion (re-search-backward str nil t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4025 (= (point) (match-end 0))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4026
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4027
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4028 (defun vip-forward-indent ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4029 "Indent forward -- `C-t' in Vi."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4030 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4031 (setq vip-cted t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4032 (indent-to (+ (current-column) vip-shift-width)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4033
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4034 (defun vip-backward-indent ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4035 "Backtab, C-d in VI"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4036 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4037 (if vip-cted
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4038 (let ((p (point)) (c (current-column)) bol (indent t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4039 (if (vip-looking-back "[0^]")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4040 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4041 (if (eq ?^ (preceding-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4042 (setq vip-preserve-indent t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4043 (delete-backward-char 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4044 (setq p (point))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4045 (setq indent nil)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4046 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4047 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4048 (setq bol (point)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4049 (if (re-search-backward "[^ \t]" bol 1) (forward-char))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4050 (delete-region (point) p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4051 (if indent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4052 (indent-to (- c vip-shift-width)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4053 (if (or (bolp) (vip-looking-back "[^ \t]"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4054 (setq vip-cted nil)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4055
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4056 (defun vip-autoindent ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4057 "Auto Indentation, Vi-style."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4058 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4059 (let ((col (current-indentation)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4060 (if abbrev-mode (expand-abbrev))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4061 (if vip-preserve-indent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4062 (setq vip-preserve-indent nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4063 (setq vip-current-indent col))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4064 ;; don't leave whitespace lines around
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4065 (if (memq last-command
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4066 '(vip-autoindent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4067 vip-open-line vip-Open-line
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4068 vip-replace-state-exit-cmd))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4069 (indent-to-left-margin))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4070 ;; 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
4071 ;;(newline 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4072 (insert "\n")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4073 (if vip-auto-indent
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4074 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4075 (setq vip-cted t)
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4076 (if (and vip-electric-mode
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4077 (not (eq major-mode 'fundamental-mode)))
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4078 (indent-according-to-mode)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4079 (indent-to vip-current-indent))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4080 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4081 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4082
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4083
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4084 ;; Viewing registers
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4085
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4086 (defun vip-ket-function (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4087 "Function called by \], the ket. View registers and call \]\]."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4088 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4089 (let ((reg (read-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4090 (cond ((vip-valid-register reg '(letter Letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4091 (view-register (downcase reg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4092 ((vip-valid-register reg '(digit))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4093 (let ((text (current-kill (- reg ?1) 'do-not-rotate)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4094 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4095 (set-buffer (get-buffer-create "*Output*"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4096 (delete-region (point-min) (point-max))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4097 (insert (format "Register %c contains the string:\n" reg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4098 (insert text)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4099 (goto-char (point-min)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4100 (display-buffer "*Output*")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4101 ((= ?\] reg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4102 (vip-next-heading arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4103 (t (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4104 vip-InvalidRegister reg)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4105
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4106 (defun vip-brac-function (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4107 "Function called by \[, the brac. View textmarkers and call \[\["
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4108 (interactive "P")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4109 (let ((reg (read-char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4110 (cond ((= ?\[ reg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4111 (vip-prev-heading arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4112 ((= ?\] reg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4113 (vip-heading-end arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4114 ((vip-valid-register reg '(letter))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4115 (let* ((val (get-register (1+ (- reg ?a))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4116 (buf (if (not val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4117 (error vip-EmptyTextmarker reg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4118 (marker-buffer val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4119 (pos (marker-position val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4120 line-no text (s pos) (e pos))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4121 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4122 (set-buffer (get-buffer-create "*Output*"))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4123 (delete-region (point-min) (point-max))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4124 (if (and buf pos)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4125 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4126 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4127 (set-buffer buf)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4128 (setq line-no (1+ (count-lines (point-min) val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4129 (goto-char pos)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4130 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4131 (if (re-search-backward "[^ \t]" nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4132 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4133 (beginning-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4134 (setq s (point))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4135 (goto-char pos)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4136 (forward-line 1)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4137 (if (re-search-forward "[^ \t]" nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4138 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4139 (end-of-line)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4140 (setq e (point))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4141 (setq text (buffer-substring s e))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4142 (setq text (format "%s<%c>%s"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4143 (substring text 0 (- pos s))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4144 reg (substring text (- pos s)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4145 (insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4146 (format
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4147 "Textmarker `%c' is in buffer `%s' at line %d.\n"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4148 reg (buffer-name buf) line-no))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4149 (insert (format "Here is some text around %c:\n\n %s"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4150 reg text)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4151 (insert (format vip-EmptyTextmarker reg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4152 (goto-char (point-min)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4153 (display-buffer "*Output*")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4154 (t (error vip-InvalidTextmarker reg)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4155
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4156
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4157
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4158 ;; commands in insertion mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4159
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4160 (defun vip-delete-backward-word (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4161 "Delete previous word."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4162 (interactive "p")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4163 (save-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4164 (push-mark nil t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4165 (backward-word arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4166 (delete-region (point) (mark t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4167 (pop-mark)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4168
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4169
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4170 (defun viper-set-expert-level (&optional dont-change-unless)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4171 "Sets the expert level for a Viper user.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4172 Can be called interactively to change (temporarily or permanently) the
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4173 current expert level.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4174
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4175 The optional argument DONT-CHANGE-UNLESS, if not nil, says that
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4176 the level should not be changed, unless its current value is
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4177 meaningless (i.e., not one of 1,2,3,4,5).
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4178
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4179 User level determines the setting of Viper variables that are most
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4180 sensitive for VI-style look-and-feel."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4181
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4182 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4183
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4184 (if (not (natnump viper-expert-level)) (setq viper-expert-level 0))
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4185
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4186 (save-window-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4187 (delete-other-windows)
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4188 ;; if 0 < viper-expert-level < viper-max-expert-level
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4189 ;; & dont-change-unless = t -- use it; else ask
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4190 (vip-ask-level dont-change-unless))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4191
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4192 (setq viper-always t
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4193 vip-ex-style-motion t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4194 vip-ex-style-editing-in-insert t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4195 vip-want-ctl-h-help nil)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4196
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4197 (cond ((eq viper-expert-level 1) ; novice or beginner
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4198 (global-set-key ; in emacs-state
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4199 vip-toggle-key
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4200 (if (vip-window-display-p) 'vip-iconify 'suspend-emacs))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4201 (setq vip-no-multiple-ESC t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4202 vip-re-search t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4203 vip-vi-style-in-minibuffer t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4204 vip-search-wrap-around-t t
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4205 vip-electric-mode nil
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4206 vip-want-emacs-keys-in-vi nil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4207 vip-want-emacs-keys-in-insert nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4208
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4209 ((and (> viper-expert-level 1) (< viper-expert-level 5))
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4210 ;; intermediate to guru
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4211 (setq vip-no-multiple-ESC (if (vip-window-display-p)
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4212 t 'twice)
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4213 vip-electric-mode t
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4214 vip-want-emacs-keys-in-vi t
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4215 vip-want-emacs-keys-in-insert (> viper-expert-level 2))
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4216
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4217 (if (eq viper-expert-level 4) ; respect user's ex-style motion
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4218 ; and vip-no-multiple-ESC
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4219 (progn
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4220 (setq-default
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4221 vip-ex-style-editing-in-insert
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4222 (viper-standard-value 'vip-ex-style-editing-in-insert)
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4223 vip-ex-style-motion
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4224 (viper-standard-value 'vip-ex-style-motion))
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4225 (setq vip-ex-style-motion
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4226 (viper-standard-value 'vip-ex-style-motion)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4227 vip-ex-style-editing-in-insert
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4228 (viper-standard-value 'vip-ex-style-editing-in-insert)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4229 vip-re-search
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4230 (viper-standard-value 'vip-re-search)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4231 vip-no-multiple-ESC
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4232 (viper-standard-value 'vip-no-multiple-ESC)))))
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4233
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4234 ;; A wizard!!
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4235 ;; 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
4236 ;; user toggle the values of variables.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4237 (t (setq-default vip-ex-style-editing-in-insert
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4238 (viper-standard-value 'vip-ex-style-editing-in-insert)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4239 vip-ex-style-motion
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4240 (viper-standard-value 'vip-ex-style-motion))
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4241 (setq vip-want-ctl-h-help
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4242 (viper-standard-value 'vip-want-ctl-h-help)
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4243 viper-always
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4244 (viper-standard-value 'viper-always)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4245 vip-no-multiple-ESC
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4246 (viper-standard-value 'vip-no-multiple-ESC)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4247 vip-ex-style-motion
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4248 (viper-standard-value 'vip-ex-style-motion)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4249 vip-ex-style-editing-in-insert
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4250 (viper-standard-value 'vip-ex-style-editing-in-insert)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4251 vip-re-search
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4252 (viper-standard-value 'vip-re-search)
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4253 vip-electric-mode
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4254 (viper-standard-value 'vip-electric-mode)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4255 vip-want-emacs-keys-in-vi
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4256 (viper-standard-value 'vip-want-emacs-keys-in-vi)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4257 vip-want-emacs-keys-in-insert
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4258 (viper-standard-value 'vip-want-emacs-keys-in-insert))))
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4259
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4260 (vip-set-mode-vars-for vip-current-state)
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4261 (if (or viper-always
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4262 (and (> viper-expert-level 0) (> 5 viper-expert-level)))
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4263 (vip-set-hooks)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4264
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4265 ;; Ask user expert level.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4266 (defun vip-ask-level (dont-change-unless)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4267 (let ((ask-buffer " *vip-ask-level*")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4268 level-changed repeated)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4269 (save-window-excursion
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4270 (switch-to-buffer ask-buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4271
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4272 (while (or (> viper-expert-level viper-max-expert-level)
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4273 (< viper-expert-level 1)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4274 (null dont-change-unless))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4275 (erase-buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4276 (if repeated
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4277 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4278 (message "Invalid user level")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4279 (beep 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4280 (setq repeated t))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4281 (setq dont-change-unless t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4282 level-changed t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4283 (insert "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4284 Please specify your level of familiarity with the venomous VI PERil
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4285 (and the VI Plan for Emacs Rescue).
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4286 You can change it at any time by typing `M-x viper-set-expert-level RET'
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4287
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4288 1 -- BEGINNER: Almost all Emacs features are suppressed.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4289 Feels almost like straight Vi. File name completion and
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4290 command history in the minibuffer are thrown in as a bonus.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4291 To use Emacs productively, you must reach level 3 or higher.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4292 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
4293 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
4294 Good progress---you are well on the way to level 3!
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4295 3 -- GRAND MASTER: Like 3, but most Emacs commands are available also
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4296 in Viper's insert state.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4297 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
4298 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
4299 variables. Adjust these settings to your taste.
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4300 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
4301 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
4302 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
4303
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4304 Please, specify your level now: ")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4305
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4306 (setq viper-expert-level (- (vip-read-char-exclusive) ?0))
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4307 ) ; end while
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4308
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4309 ;; tell the user if level was changed
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4310 (and level-changed
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4311 (progn
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4312 (insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4313 (format "\n\n\n\n\n\t\tYou have selected user level %d"
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4314 viper-expert-level))
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4315 (if (y-or-n-p "Do you wish to make this change permanent? ")
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4316 ;; save the setting for viper-expert-level
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4317 (vip-save-setting
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4318 'viper-expert-level
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4319 (format "Saving user level %d ..." viper-expert-level)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4320 vip-custom-file-name))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4321 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4322 (bury-buffer) ; remove ask-buffer from screen
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4323 (message "")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4324 )))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4325
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4326
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4327 (defun vip-nil ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4328 (interactive)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4329 (beep 1))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4330
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4331
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4332 ;; 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
4333 (defun vip-register-to-point (char &optional enforce-buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4334 "Like jump-to-register, but switches to another buffer in another window."
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4335 (interactive "cViper register to point: ")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4336 (let ((val (get-register char)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4337 (cond
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4338 ((and (fboundp 'frame-configuration-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4339 (frame-configuration-p val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4340 (set-frame-configuration val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4341 ((window-configuration-p val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4342 (set-window-configuration val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4343 ((vip-valid-marker val)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4344 (if (and enforce-buffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4345 (not (equal (current-buffer) (marker-buffer val))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4346 (error (concat vip-EmptyTextmarker " in this buffer")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4347 (1- (+ char ?a))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4348 (pop-to-buffer (marker-buffer val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4349 (goto-char val))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4350 ((and (consp val) (eq (car val) 'file))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4351 (find-file (cdr val)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4352 (t
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4353 (error vip-EmptyTextmarker (1- (+ char ?a)))))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4354
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4355
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4356 (defun vip-save-kill-buffer ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4357 "Save then kill current buffer. "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4358 (interactive)
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4359 (if (< viper-expert-level 2)
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4360 (save-buffers-kill-emacs)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4361 (save-buffer)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4362 (kill-buffer (current-buffer))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4363
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4364
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4365
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4366 ;;; Bug Report
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-submit-report ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4369 "Submit bug report on Viper."
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 (let ((reporter-prompt-for-summary-p t)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4372 (vip-device-type (vip-device-type))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4373 color-display-p frame-parameters
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4374 minibuffer-emacs-face minibuffer-vi-face minibuffer-insert-face
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4375 varlist salutation window-config)
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 ;; 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
4378 ;; like we did with color-display-p.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4379 (setq color-display-p (if (vip-window-display-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4380 (vip-color-display-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4381 'non-x)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4382 minibuffer-vi-face (if (vip-has-face-support-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4383 (vip-get-face vip-minibuffer-vi-face)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4384 'non-x)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4385 minibuffer-insert-face (if (vip-has-face-support-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4386 (vip-get-face vip-minibuffer-insert-face)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4387 'non-x)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4388 minibuffer-emacs-face (if (vip-has-face-support-p)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4389 (vip-get-face vip-minibuffer-emacs-face)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4390 'non-x)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4391 frame-parameters (if (fboundp 'frame-parameters)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4392 (frame-parameters (selected-frame))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4393
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4394 (setq varlist (list 'vip-vi-minibuffer-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4395 'vip-insert-minibuffer-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4396 'vip-vi-intercept-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4397 'vip-vi-local-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4398 'vip-vi-kbd-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4399 'vip-vi-global-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4400 'vip-vi-state-modifier-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4401 'vip-vi-diehard-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4402 'vip-vi-basic-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4403 'vip-replace-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4404 'vip-insert-intercept-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4405 'vip-insert-local-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4406 'vip-insert-kbd-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4407 'vip-insert-global-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4408 'vip-insert-state-modifier-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4409 'vip-insert-diehard-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4410 'vip-insert-basic-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4411 'vip-emacs-intercept-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4412 'vip-emacs-local-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4413 'vip-emacs-kbd-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4414 'vip-emacs-global-user-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4415 'vip-emacs-state-modifier-minor-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4416 'vip-automatic-iso-accents
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4417 'vip-want-emacs-keys-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4418 'vip-want-emacs-keys-in-vi
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4419 'vip-keep-point-on-undo
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4420 'vip-no-multiple-ESC
18289
3a43376db2be new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18172
diff changeset
4421 'vip-electric-mode
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4422 'vip-ESC-key
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4423 'vip-want-ctl-h-help
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4424 'vip-ex-style-editing-in-insert
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4425 'vip-delete-backwards-in-replace
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4426 'vip-vi-style-in-minibuffer
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4427 'vip-vi-state-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4428 'vip-insert-state-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4429 'vip-replace-state-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4430 'vip-emacs-state-hook
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4431 'ex-cycle-other-window
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4432 'ex-cycle-through-non-files
18839
1405083241e8 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 18289
diff changeset
4433 'viper-expert-level
18129
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4434 'major-mode
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4435 'vip-device-type
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4436 'color-display-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4437 'frame-parameters
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4438 'minibuffer-vi-face
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4439 'minibuffer-insert-face
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4440 'minibuffer-emacs-face
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4441 ))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4442 (setq salutation "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4443 Congratulations! You may have unearthed a bug in Viper!
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4444 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
4445
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4446 -------------------------------------------------------------------")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4447 (setq window-config (current-window-configuration))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4448 (with-output-to-temp-buffer " *vip-info*"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4449 (switch-to-buffer " *vip-info*")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4450 (delete-other-windows)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4451 (princ "
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4452 PLEASE FOLLOW THESE PROCEDURES
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
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4455 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
4456 not cause by other packages you are using.
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 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
4459 problem. These warnings are normal and unavoidable.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4460
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4461 Please note that users should not modify variables and keymaps other than
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4462 those advertised in the manual. Such `customization' is likely to crash
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4463 Viper, as it would any other improperly customized Emacs package.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4464
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4465 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
4466 Viper commands, type:
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4467
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4468 M-x set-variable <Return> debug-on-error <Return> t <Return>
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 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
4471 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
4472 trace in your bug report.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4473
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4474 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
4475 \(e.g., Emacs freezes\), type:
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 M-x set-variable <Return> debug-on-quit <Return> t <Return>
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4478
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4479 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
4480 the current command. Include the resulting back trace in the bug report.
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 Mail anyway (y or n)? ")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4483 (if (y-or-n-p "Mail anyway? ")
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4484 ()
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4485 (set-window-configuration window-config)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4486 (error "Bug report aborted")))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4487
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4488 (require 'reporter)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4489 (set-window-configuration window-config)
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 (reporter-submit-bug-report "kifer@cs.sunysb.edu"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4492 (vip-version)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4493 varlist
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4494 nil 'delete-other-windows
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4495 salutation)
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
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4498
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
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4501 ;; Smoothes out the difference between Emacs' unread-command-events
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4502 ;; 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
4503 ;; events or a sequence of keys.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4504 ;;
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4505 ;; 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
4506 ;; 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
4507 ;; 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
4508 ;; common symbol that might appear in this wrong context.
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4509 (defun vip-set-unread-command-events (arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4510 (if vip-emacs-p
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4511 (setq
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4512 unread-command-events
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4513 (let ((new-events
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4514 (cond ((eventp arg) (list arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4515 ((listp arg) arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4516 ((sequencep arg)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4517 (listify-key-sequence arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4518 (t (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4519 "vip-set-unread-command-events: Invalid argument, %S"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4520 arg)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4521 (if (not (eventp nil))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4522 (setq new-events (delq nil new-events)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4523 (append new-events unread-command-events)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4524 ;; XEmacs
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4525 (setq
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4526 unread-command-events
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4527 (append
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4528 (cond ((vip-characterp arg) (list (character-to-event arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4529 ((eventp arg) (list arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4530 ((stringp arg) (mapcar 'character-to-event arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4531 ((vectorp arg) (append arg nil)) ; turn into list
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4532 ((listp arg) (vip-eventify-list-xemacs arg))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4533 (t (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4534 "vip-set-unread-command-events: Invalid argument, %S" arg)))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4535 unread-command-events))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4536
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4537 ;; list is assumed to be a list of events of characters
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4538 (defun vip-eventify-list-xemacs (lis)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4539 (mapcar
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4540 (function (lambda (elt)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4541 (cond ((vip-characterp elt) (character-to-event elt))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4542 ((eventp elt) elt)
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4543 (t (error
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4544 "vip-eventify-list-xemacs: can't convert to event, %S"
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4545 elt)))))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4546 lis))
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4547
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
e92598964ee6 new version
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
diff changeset
4550 ;;; viper-cmd.el ends here