annotate lisp/emulation/viper.el @ 13177:439506fa922e

Check that DJGPP v. 1 is used. Define __DJGPP__ to 1. Simplified INTERNAL_TERMINAL termcap definition. Removed #define fflush internal_flush.
author Kim F. Storm <storm@cua.dk>
date Wed, 11 Oct 1995 14:55:17 +0000
parents 7a7b8d42bdec
children bc4eeb585ff1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1 ;;; viper.el --- A full-featured Vi emulator for GNU Emacs 19 and XEmacs 19,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2 ;; a VI Plan for Emacs Rescue,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3 ;; and a venomous VI PERil.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4 ;; Viper Is also a Package for Emacs Rebels.
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5 ;;
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
6 ;; Keywords: emulations
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
7 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
8
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
9 (defconst viper-version "2.81 of August 7, 1995"
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
10 "The current version of Viper")
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
11
11255
e79aca68f09c Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10792
diff changeset
12 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc.
e79aca68f09c Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10792
diff changeset
13
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
14 ;; This file is part of GNU Emacs.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
15
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
17 ;; it under the terms of the GNU General Public License as published by
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
18 ;; the Free Software Foundation; either version 2, or (at your option)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
19 ;; any later version.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
20
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
21 ;; GNU Emacs is distributed in the hope that it will be useful,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
24 ;; GNU General Public License for more details.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
25
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
26 ;; You should have received a copy of the GNU General Public License
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
27 ;; along with GNU Emacs; see the file COPYING. If not, write to
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
28 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
29
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
30 ;;; Commentary:
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
31
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
32 ;; Viper is a full-featured Vi emulator for Emacs 19. It emulates and
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
33 ;; improves upon the standard features of Vi and, at the same time, allows
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
34 ;; full access to all Emacs facilities. Viper supports multiple undo,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
35 ;; file name completion, command, file, and search history and it extends
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
36 ;; Vi in many other ways. Viper is highly customizable through the various
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
37 ;; hooks, user variables, and keymaps. It is implemented as a collection
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
38 ;; of minor modes and it is designed to provide full access to all Emacs
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
39 ;; major and minor modes.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
40 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
41 ;;; History
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
42 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
43 ;; Viper is a new name for a package formerly known as VIP-19,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
44 ;; which was a successor of VIP version 3.5 by Masahiko Sato
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
45 ;; <ms@sail.stanford.edu> and VIP version 4.2 by Aamod Sane
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
46 ;; <sane@cs.uiuc.edu>. Some ideas from vip 4.4.2 by Aamod Sane
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
47 ;; were also shamelessly plagiarized.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
48 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
49 ;; Viper maintains some degree of compatibility with these older
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
50 ;; packages. See the documentation for customization.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
51 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
52 ;; The main difference between Viper and these older packages are:
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
53 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
54 ;; 1. Viper emulates Vi at several levels, from almost complete conformity
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
55 ;; to a rather loose Vi-compliance.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
56 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
57 ;; 2. Viper provides full access to all major and minor modes of Emacs
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
58 ;; without the need to type extra keys.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
59 ;; The older versions of VIP (and other Vi emulators) do not work with
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
60 ;; some major and minor modes.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
61 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
62 ;; 3. Viper supports vi-style undo.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
63 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
64 ;; 4. Viper fully emulates (and improves upon) vi's replacement mode.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
65 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
66 ;; 5. Viper has a better interface to ex, including command, variable, and
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
67 ;; file name completion.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
68 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
69 ;; 6. Viper uses native Emacs history and completion features; it doesn't
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
70 ;; rely on other packages (such as gmhist.el and completer.el) to provide
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
71 ;; these features.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
72 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
73 ;; 7. Viper supports Vi-style editing in the minibuffer, by allowing the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
74 ;; user to switch from Insert state to Vi state to Replace state, etc.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
75 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
76 ;; 8. Viper keeps history of recently inserted pieces of text and recently
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
77 ;; executed Vi-style destructive commands, such as `i', `d', etc.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
78 ;; These pieces of text can be inserted in later insertion commands;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
79 ;; the previous destructive commands can be re-executed.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
80 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
81 ;; 9. Viper has Vi-style keyboard macros, which enhances the similar
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
82 ;; facility in the original Vi.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
83 ;; First, one can execute any Emacs command while defining a
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
84 ;; macro, not just the Vi commands. Second, macros are defined in a
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
85 ;; WYSYWYG mode, using an interface to Emacs' WYSIWYG style of defining
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
86 ;; macros. Third, in Viper, one can define macros that are specific to
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
87 ;; a given buffer, a given major mode, or macros defined for all buffers.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
88 ;; The same macro name can have several different definitions:
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
89 ;; one global, several definitions for various major modes, and
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
90 ;; definitions for specific buffers.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
91 ;; Bffer-specific definitions override mode-specific
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
92 ;; definitions, which, in turn, override global definitions.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
93 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
94 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
95 ;;; Installation:
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
96 ;; -------------
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
97 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
98 ;; (require 'viper)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
99 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
100
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
101 ;;; Acknowledgements:
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
102 ;; -----------------
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
103 ;; Bug reports and ideas contributed by the following users
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
104 ;; have helped improve Viper and the various versions of VIP.
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
105 ;; See the on-line manual for a complete list of contributors.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
106 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
107 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
108 ;;; Notes:
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
109 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
110 ;; 1. Major modes.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
111 ;; In most cases, Viper handles major modes correctly, i.e., they come up
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
112 ;; in the right state (either vi-state or emacs-state). For instance, text
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
113 ;; files come up in vi-state, while, say, Dired appears in emacs-state by
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
114 ;; default.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
115 ;; However, some modes do not appear in the right mode in the beginning,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
116 ;; usually because they neglect to follow Emacs conventions (e.g., they don't
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
117 ;; use kill-all-local-variables when they start). Some major modes
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
118 ;; may fail to come up in emacs-state if they call hooks, such as
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
119 ;; text-hook, for no good reason.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
120 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
121 ;; As an immediate solution, you can hit C-z to bring about the right mode.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
122 ;; An interim solution is to add an appropriate hook to the mode like this:
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
123 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
124 ;; (add-hook 'your-favorite-mode 'viper-mode)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
125 ;; or
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
126 ;; (add-hook 'your-favorite-mode 'vip-change-state-to-emacs)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
127 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
128 ;; whichever applies. The right thing to do, however, is to complain to the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
129 ;; author of the respective package. (Sometimes they also neglect to equip
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
130 ;; their modes with hooks, which is one more reason for complaining.)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
131 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
132 ;; 2. Keymap handling
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
133 ;; Because Emacs 19 has an elegant mechanism for turning minor mode keymaps
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
134 ;; on and off, implementation of Viper has been greatly simplified. Viper
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
135 ;; has several minor modes.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
136 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
137 ;; Viper's Vi state consists of seven minor modes:
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
138 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
139 ;; vip-vi-intercept-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
140 ;; vip-vi-local-user-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
141 ;; vip-vi-global-user-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
142 ;; vip-vi-kbd-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
143 ;; vip-vi-state-modifier-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
144 ;; vip-vi-diehard-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
145 ;; vip-vi-basic-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
146 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
147 ;; Bindings done to the keymap of the first mode overshadow those done to
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
148 ;; the second, which, in turn, overshadows those done to the third, etc.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
149 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
150 ;; The last vip-vi-basic-minor-mode contains most of the usual Vi bindings
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
151 ;; in its edit mode. This mode provides access to all Emacs facilities.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
152 ;; Novice users, however, may want to set their vip-expert-level to 1
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
153 ;; in their .vip file. This will enable vip-vi-diehard-minor-mode. This
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
154 ;; minor mode's bindings make Viper simulate the usual Vi very closely.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
155 ;; For instance, C-c will not have its standard Emacs binding
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
156 ;; and so many of the goodies of Emacs are not available.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
157 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
158 ;; An skilled user, should set vip-expert-level to at least 3. This will
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
159 ;; enable ;; C-c and many Emacs facilities will become available.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
160 ;; In this case, vip-vi-diehard-minor-mode is inactive.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
161 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
162 ;; Viper gurus should have at least
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
163 ;; (setq vip-expert-level 4)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
164 ;; in their ~/.vip files. This will unsuppress all Emacs keys that are not
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
165 ;; essential for VI-style editing.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
166 ;; Pick-and-choose users may want to put
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
167 ;; (setq vip-expert-level 5)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
168 ;; in ~/.vip. Viper will then leave it up to the user to set the variables
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
169 ;; vip-want-* See vip-set-expert-level for details.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
170 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
171 ;; The very first minor mode, vip-vi-intercept-minor-mode, is of no
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
172 ;; concern for the user. It is needed to bind Viper's vital keys, such as
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
173 ;; ESC and C-z.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
174 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
175 ;; The second mode, vip-vi-local-user-minor-mode, usually has an
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
176 ;; empty keymap. However, the user can set bindings in this keymap, which
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
177 ;; will overshadow the corresponding bindings in the other two minor
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
178 ;; modes. This is useful, for example, for setting up ZZ in gnus,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
179 ;; rmail, mh-e, etc., to send message instead of saving it in a file.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
180 ;; Likewise, in Dired mode, you may want to bind ZN and ZP to commands
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
181 ;; that would visit the next or the previous file in the Dired buffer.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
182 ;; Setting local keys is tricky, so don't do it directly. Instead, use
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
183 ;; vip-add-local-keys function (see its doc).
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
184 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
185 ;; The third minor mode, vip-vi-global-user-minor-mode, is also intended
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
186 ;; for the users but, unlike vip-vi-local-user-minor-mode, its key
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
187 ;; bindings are seen in all Viper buffers. This mode keys can be done
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
188 ;; with define-key command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
189 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
190 ;; The fourth minor mode, vip-vi-kbd-minor-mode, is used by keyboard
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
191 ;; macros. Users are NOT supposed to modify this keymap directly.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
192 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
193 ;; The fifth mode, vip-vi-state-modifier-minor-mode, can be used to set
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
194 ;; key bindings that are visible in some major modes but not in others.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
195 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
196 ;; Users are allowed to modify keymaps that belong to
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
197 ;; vip-vi-local-user-minor-mode, vip-vi-global-user-minor-mode,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
198 ;; and vip-vi-state-modifier-minor-mode only.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
199 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
200 ;; Viper's Insert state also has seven minor modes:
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
201 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
202 ;; vip-insert-intercept-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
203 ;; vip-insert-local-user-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
204 ;; vip-insert-global-user-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
205 ;; vip-insert-kbd-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
206 ;; vip-insert-state-modifier-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
207 ;; vip-insert-diehard-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
208 ;; vip-insert-basic-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
209 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
210 ;; As with VI's editing modes, the first mode, vip-insert-intercept-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
211 ;; is used to bind vital keys that are not to be changed by the user.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
212 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
213 ;; The next mode, vip-insert-local-user-minor-mode, is used to customize
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
214 ;; bindings in the insert state of Viper. The third mode,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
215 ;; vip-insert-global-user-minor-mode is like
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
216 ;; vip-insert-local-user-minor-mode, except that its bindings are seen in
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
217 ;; all Viper buffers. As with vip-vi-local-user-minor-mode, its bindings
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
218 ;; should be done via the function vip-add-local-keys. Bindings for
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
219 ;; vip-insert-global-user-minor-mode can be set with the define-key command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
220 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
221 ;; The next minor mode, vip-insert-kbd-minor-mode,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
222 ;; is used for keyboard VI-style macros defined with :map!.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
223 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
224 ;; The fifth minor mode, vip-insert-state-modifier-minor-mode, is like
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
225 ;; vip-vi-state-modifier-minor-mode, except that it is used in the Insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
226 ;; state; it can be used to modify keys in a mode-specific fashion.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
227 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
228 ;; The minor mode vip-insert-diehard-minor-mode is in effect when
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
229 ;; the user wants a high degree of Vi compatibility (a bad idea, really!).
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
230 ;; The last minor mode, vip-insert-basic-minor-mode, is always in effect
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
231 ;; when Viper is in insert state. It binds a small number of keys needed for
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
232 ;; Viper's operation.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
233 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
234 ;; Finally, Viper provides minor modes for overriding bindings set by Emacs
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
235 ;; modes when Viper is in Emacs state:
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
236 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
237 ;; vip-emacs-local-user-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
238 ;; vip-emacs-global-user-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
239 ;; vip-emacs-kbd-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
240 ;; vip-emacs-state-modifier-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
241 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
242 ;; These minor modes are in effect when Viper is in Emacs state. The keymap
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
243 ;; associated with vip-emacs-global-user-minor-mode,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
244 ;; vip-emacs-global-user-map, overrides the global and local keymaps as
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
245 ;; well as the minor mode keymaps set by other modes. The keymap of
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
246 ;; vip-emacs-local-user-minor-mode, vip-emacs-local-user-map, overrides
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
247 ;; everything, but it is used on a per buffer basis.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
248 ;; The keymap associated with vip-emacs-state-modifier-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
249 ;; overrides keys on a per-major-mode basis. The mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
250 ;; vip-emacs-kbd-minor-mode is used to define Vi-style macros in Emacs
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
251 ;; state.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
252 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
253 ;; 3. There is also one minor mode that is used when Viper is in its
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
254 ;; replace-state (used for commands like cw, C, etc.). This mode is
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
255 ;; called
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
256 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
257 ;; vip-replace-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
258 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
259 ;; and its keymap is vip-replace-map. Replace minor mode is always
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
260 ;; used in conjunction with the minor modes for insert-state, and its
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
261 ;; keymap overshadows the keymaps for insert minor modes.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
262 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
263 ;; 4. Defining buffer-local bindings in Vi and Insert modes.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
264 ;; As mentioned before, sometimes, it is convenient to have
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
265 ;; buffer-specific of mode-specific key bindings in Vi and insert modes.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
266 ;; Viper provides a special function, vip-add-local-keys, to do precisely
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
267 ;; this. For instance, is you need to add couple of mode-specific bindings
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
268 ;; to Insert mode, you can put
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
269 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
270 ;; (vip-add-local-keys 'insert-state '((key1 . func1) (key2 .func2)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
271 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
272 ;; somewhere in a hook of this major mode. If you put something like this
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
273 ;; in your own elisp function, this will define bindings specific to the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
274 ;; buffer that was current at the time of the call to vip-add-local-keys.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
275 ;; The only thing to make sure here is that the major mode of this buffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
276 ;; is written according to Emacs conventions, which includes a call to
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
277 ;; (kill-all-local-variables). See vip-add-local-keys for more details.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
278 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
279 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
280 ;; TO DO (volunteers?):
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
281 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
282 ;; 1. Some of the code that is inherited from VIP-3.5 is rather
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
283 ;; convoluted. Instead of vip-command-argument, keymaps should bind the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
284 ;; actual commands. E.g., "dw" should be bound to a generic command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
285 ;; vip-delete that will delete things based on the value of
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
286 ;; last-command-char. This would greatly simplify the logic and the code.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
287 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
288 ;; 2. Somebody should venture to write a customization package a la
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
289 ;; options.el that would allow the user to change values of variables
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
290 ;; that meet certain specs (e.g., match a regexp) and whose doc string
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
291 ;; starts with a '*'. Then, the user should be offered to save
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
292 ;; variables that were changed. This will make user's customization job
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
293 ;; much easier.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
294 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
295
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
296
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
297 (require 'advice)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
298 (require 'cl)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
299 (require 'ring)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
300
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
301 (require 'viper-util)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
302
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
303
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
304 ;;; Variables
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
305
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
306 ;; Is t until viper-mode executes for the very first time.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
307 ;; Prevents recursive descend into startup messages.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
308 (defvar vip-first-time t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
309
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
310 (defvar vip-expert-level 0
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
311 "User's expert level.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
312 The minor mode vip-vi-diehard-minor-mode is in effect when
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
313 vip-expert-level is 1 or 2 or when vip-want-emacs-keys-in-vi is t.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
314 The minor mode vip-insert-diehard-minor-mode is in effect when
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
315 vip-expert-level is 1 or 2 or if vip-want-emacs-keys-in-insert is t.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
316 Use `M-x vip-set-expert-level' to change this.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
317
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
318 ;; Max expert level supported by Viper. This is NOT a user option.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
319 ;; It is here to make it hard for the user from resetting it.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
320 (defconst vip-max-expert-level 5)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
321
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
322 ;; Contains user settings for vars affected by vip-set-expert-level function.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
323 ;; Not a user option.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
324 (defvar vip-saved-user-settings nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
325
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
326
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
327 ;;; Viper minor modes
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
328
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
329 ;; This is not local in Emacs, so we make it local.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
330 (make-variable-buffer-local 'minor-mode-map-alist)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
331
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
332 ;; Mode for vital things like \e, C-z.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
333 (vip-deflocalvar vip-vi-intercept-minor-mode nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
334
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
335 (vip-deflocalvar vip-vi-basic-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
336 "Viper's minor mode for Vi bindings.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
337
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
338 (vip-deflocalvar vip-vi-local-user-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
339 "Auxiliary minor mode for user-defined local bindings in Vi state.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
340
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
341 (vip-deflocalvar vip-vi-global-user-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
342 "Auxiliary minor mode for user-defined global bindings in Vi state.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
343
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
344 (vip-deflocalvar vip-vi-state-modifier-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
345 "Minor mode used to make major-mode-specific modification to Vi state.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
346
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
347 (vip-deflocalvar vip-vi-diehard-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
348 "This minor mode is in effect when the user wants Viper to be Vi.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
349
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
350 (vip-deflocalvar vip-vi-kbd-minor-mode nil
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
351 "Minor mode for Ex command macros in Vi state.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
352 The corresponding keymap stores key bindings of Vi macros defined with
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
353 the Ex command :map.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
354
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
355 ;; Mode for vital things like \e, C-z.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
356 (vip-deflocalvar vip-insert-intercept-minor-mode nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
357
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
358 (vip-deflocalvar vip-insert-basic-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
359 "Viper's minor mode for bindings in Insert mode.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
360
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
361 (vip-deflocalvar vip-insert-local-user-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
362 "Auxiliary minor mode for buffer-local user-defined bindings in Insert state.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
363 This is a way to overshadow normal Insert mode bindings locally to certain
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
364 designated buffers.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
365
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
366 (vip-deflocalvar vip-insert-global-user-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
367 "Auxiliary minor mode for global user-defined bindings in Insert state.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
368
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
369 (vip-deflocalvar vip-insert-state-modifier-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
370 "Minor mode used to make major-mode-specific modification to Insert state.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
371
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
372 (vip-deflocalvar vip-insert-diehard-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
373 "Minor mode that simulates Vi very closely.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
374 Not recommened, except for the novice user.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
375
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
376 (vip-deflocalvar vip-insert-kbd-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
377 "Minor mode for Ex command macros Insert state.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
378 The corresponding keymap stores key bindings of Vi macros defined with
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
379 the Ex command :map!.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
380
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
381 (vip-deflocalvar vip-replace-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
382 "Minor mode in effect in replace state (cw, C, and the like commands).")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
383
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
384 ;; Mode for vital things like \C-z and \C-x)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
385 ;; This is t, by default. So, any new buffer will have C-z defined as
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
386 ;; switch to Vi, unless we switched states in this buffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
387 (vip-deflocalvar vip-emacs-intercept-minor-mode t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
388
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
389 (vip-deflocalvar vip-emacs-local-user-minor-mode t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
390 "Minor mode for local user bindings effective in Emacs state.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
391 Users can use it to override Emacs bindings when Viper is in its Emacs
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
392 state.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
393
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
394 (vip-deflocalvar vip-emacs-global-user-minor-mode t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
395 "Minor mode for global user bindings in effect in Emacs state.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
396 Users can use it to override Emacs bindings when Viper is in its Emacs
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
397 state.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
398
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
399 (vip-deflocalvar vip-emacs-kbd-minor-mode t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
400 "Minor mode for Vi style macros in Emacs state.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
401 The corresponding keymap stores key bindings of Vi macros defined with
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
402 `vip-record-kbd-macro' command. There is no Ex-level command to do this
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
403 interactively.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
404
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
405 (vip-deflocalvar vip-emacs-state-modifier-minor-mode t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
406 "Minor mode used to make major-mode-specific modification to Emacs state.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
407 For instance, a Vi purist may want to bind `dd' in Dired mode to a function
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
408 that deletes a file.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
409
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
410
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
411
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
412 ;;; ISO characters
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
413
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
414 (defvar vip-automatic-iso-accents nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
415 "*If non-nil, ISO accents will be turned on in insert/replace emacs states and turned off in vi-state.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
416 For some users, this behavior may be too primitive. In this case, use
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
417 insert/emacs/vi state hooks.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
418
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
419
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
420 ;;; Emacs keys in other states.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
421
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
422 (defvar vip-want-emacs-keys-in-insert t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
423 "*Set to nil if you want complete Vi compatibility in insert mode.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
424 Complete compatibility with Vi is not recommended for power use of Viper.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
425
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
426 (defvar vip-want-emacs-keys-in-vi t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
427 "*Set to nil if you want complete Vi compatibility in Vi mode.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
428 Full Vi compatibility is not recommended for power use of Viper.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
429
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
430
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
431
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
432 ;; VI-style Undo
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
433
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
434 ;; Used to 'undo' complex commands, such as replace and insert commands.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
435 (vip-deflocalvar vip-undo-needs-adjustment nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
436 (put 'vip-undo-needs-adjustment 'permanent-local t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
437
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
438 ;; A mark that Viper puts on buffer-undo-list. Marks the beginning of a
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
439 ;; complex command that must be undone atomically. If inserted, it is
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
440 ;; erased by vip-change-state-to-vi and vip-repeat.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
441 (defconst vip-buffer-undo-list-mark 'viper)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
442
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
443 (defvar vip-keep-point-on-undo nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
444 "*Non-nil means not to move point while undoing commands.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
445 This style is different from Emacs and Vi. Try it to see if
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
446 it better fits your working style.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
447
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
448 ;; Replace mode and changing text
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
449
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
450 ;; Viper's own after/before change functions, which get vip-add-hook'ed to
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
451 ;; Emacs's
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
452 (vip-deflocalvar vip-after-change-functions nil "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
453 (vip-deflocalvar vip-before-change-functions nil "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
454 (vip-deflocalvar vip-post-command-hooks nil "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
455 (vip-deflocalvar vip-pre-command-hooks nil "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
456
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
457 ;; Can be used to pass global states around for short period of time
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
458 (vip-deflocalvar vip-intermediate-command nil "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
459
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
460 ;; Indicates that the current destructive command has started in replace mode.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
461 (vip-deflocalvar vip-began-as-replace nil "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
462
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
463 (defvar vip-replace-overlay-cursor-color "Red"
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
464 "*Cursor color to use in Replace state")
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
465
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
466
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
467 (vip-deflocalvar vip-replace-overlay nil "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
468 (put 'vip-replace-overlay 'permanent-local t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
469
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
470 (if (vip-window-display-p)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
471 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
472 (make-face 'vip-replace-overlay-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
473 (or (face-differs-from-default-p 'vip-replace-overlay-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
474 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
475 (if (vip-can-use-colors "darkseagreen2" "Black")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
476 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
477 (set-face-background
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
478 'vip-replace-overlay-face "darkseagreen2")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
479 (set-face-foreground 'vip-replace-overlay-face "Black")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
480 (set-face-underline-p 'vip-replace-overlay-face t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
481 )))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
482
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
483 (defvar vip-replace-overlay-face 'vip-replace-overlay-face
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
484 "*Face for highlighting replace regions on a window display.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
485
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
486 (defvar vip-replace-region-end-delimiter "$"
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
487 "A string marking the end of replacement regions.
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
488 It is used only with TTYs or if `vip-use-replace-region-delimiters'
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
489 is non-nil.")
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
490 (defvar vip-replace-region-start-delimiter ""
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
491 "A string marking the beginning of replacement regions.
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
492 It is used only with TTYs or if `vip-use-replace-region-delimiters'
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
493 is non-nil.")
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
494 (defvar vip-use-replace-region-delimiters
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
495 (or (not (vip-window-display-p)) (not (vip-color-display-p)))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
496 "*If non-nil, Viper will always use `vip-replace-region-end-delimiter' and
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
497 `vip-replace-region-start-delimiter' to delimit replacement regions, even on
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
498 color displays. By default, the delimiters are used only on TTYs or
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
499 monochrome displays.")
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
500
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
501 ;; XEmacs requires glyphs
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
502 (if vip-xemacs-p
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
503 (progn
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
504 (or (glyphp vip-replace-region-end-delimiter)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
505 (setq vip-replace-region-end-delimiter
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
506 (make-glyph vip-replace-region-end-delimiter)))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
507 (or (glyphp vip-replace-region-start-delimiter)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
508 (setq vip-replace-region-start-delimiter
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
509 (make-glyph vip-replace-region-start-delimiter)))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
510 ))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
511
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
512
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
513 ;; These are local marker that must be initialized to nil and moved with
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
514 ;; `vip-move-marker-locally'
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
515 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
516 ;; Remember the last position inside the replace region.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
517 (vip-deflocalvar vip-last-posn-in-replace-region nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
518 ;; Remember the last position while inserting
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
519 (vip-deflocalvar vip-last-posn-while-in-insert-state nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
520 (put 'vip-last-posn-in-replace-region 'permanent-local t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
521 (put 'vip-last-posn-while-in-insert-state 'permanent-local t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
522
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
523 (vip-deflocalvar vip-sitting-in-replace nil "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
524 (put 'vip-sitting-in-replace 'permanent-local t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
525
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
526 ;; Remember the number of characters that have to be deleted in replace
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
527 ;; mode to compensate for the inserted characters.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
528 (vip-deflocalvar vip-replace-chars-to-delete 0 "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
529 (vip-deflocalvar vip-replace-chars-deleted 0 "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
530
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
531 ;; Insertion ring and command ring
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
532 (defvar vip-insertion-ring-size 14
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
533 "The size of the insertion ring.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
534 ;; The insertion ring.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
535 (defvar vip-insertion-ring nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
536 ;; This is temp insertion ring. Used to do rotation for display purposes.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
537 ;; When rotation just started, it is initialized to vip-insertion-ring.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
538 (defvar vip-temp-insertion-ring nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
539 (defvar vip-last-inserted-string-from-insertion-ring "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
540
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
541 (defvar vip-command-ring-size 14
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
542 "The size of the command ring.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
543 ;; The command ring.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
544 (defvar vip-command-ring nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
545 ;; This is temp command ring. Used to do rotation for display purposes.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
546 ;; When rotation just started, it is initialized to vip-command-ring.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
547 (defvar vip-temp-command-ring nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
548
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
549 ;; Modes and related variables
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
550
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
551 ;; Current mode. One of: `emacs-state', `vi-state', `insert-state'
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
552 (vip-deflocalvar vip-current-state 'emacs-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
553
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
554
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
555 (defvar vip-toggle-key "\C-z"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
556 "The key used to change states from emacs to Vi and back.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
557 In insert mode, this key also functions as Meta.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
558 Must be set in .vip file or prior to loading Viper.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
559 This setting cannot be changed interactively.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
560
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
561 (defvar vip-ESC-key "\e"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
562 "Key used to ESC.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
563 Must be set in .vip file or prior to loading Viper.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
564 This setting cannot be changed interactively.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
565
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
566 (defvar vip-no-multiple-ESC t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
567 "*If true, multiple ESC in Vi mode will cause bell to ring.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
568 \_ is then mapped to Meta.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
569 This is set to t on a windowing terminal and to 'twice on a dumb
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
570 terminal (unless the user level is 1, 2, or 5). On a dumb terminal, this
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
571 enables cursor keys and is generally more convenient, as terminals usually
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
572 don't have a convenient Meta key.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
573 Setting vip-no-multiple-ESC to nil will allow as many multiple ESC,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
574 as is allowed by the major mode in effect.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
575
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
576
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
577 (defvar vip-want-ctl-h-help nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
578 "*If t then C-h is bound to help-command in insert mode, if nil then it is
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
579 bound to delete-backward-char.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
580
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
581 ;; Autoindent in insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
582
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
583 ;; Variable that keeps track of whether C-t has been pressed.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
584 (vip-deflocalvar vip-cted nil "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
585
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
586 ;; Preserve the indent value, used by C-d in insert mode.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
587 (vip-deflocalvar vip-current-indent 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
588
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
589 ;; Whether to preserve the indent, used by C-d in insert mode.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
590 (vip-deflocalvar vip-preserve-indent nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
591
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
592 (defconst vip-auto-indent nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
593 "*Autoindent if t.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
594
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
595 (defconst vip-shift-width 8
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
596 "*The shiftwidth variable.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
597
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
598 ;; Variables for repeating destructive commands
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
599
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
600 (defconst vip-keep-point-on-repeat t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
601 "*If t, don't move point when repeating previous command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
602 This is useful for doing repeated changes with the '.' key.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
603 The user can change this to nil, if she likes when the cursor moves
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
604 to a new place after repeating previous Vi command.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
605
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
606 ;; Remember insert point as a marker. This is a local marker that must be
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
607 ;; initialized to nil and moved with `vip-move-marker-locally'.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
608 (vip-deflocalvar vip-insert-point nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
609 (put 'vip-insert-point 'permanent-local t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
610
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
611 ;; This remembers the point before dabbrev-expand was called.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
612 ;; If vip-insert-point turns out to be bigger than that, it is reset
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
613 ;; back to vip-pre-command-point.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
614 ;; The reason this is needed is because dabbrev-expand (and possibly
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
615 ;; others) may jump to before the insertion point, delete something and
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
616 ;; then reinsert a bigger piece. For instance: bla^blo
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
617 ;; If dabbrev-expand is called after `blo' and ^ undicates vip-insert-point,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
618 ;; then point jumps to the beginning of `blo'. If expansion is found, `blablo'
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
619 ;; is deleted, and we have |^, where | denotes point. Next, dabbrev-expand
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
620 ;; will insert the expansion, and we get: blablo^
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
621 ;; Whatever we insert next goes before the ^, i.e., before the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
622 ;; vip-insert-point marker. So, Viper will think that nothing was
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
623 ;; inserted. Remembering the orig position of the marker circumvents the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
624 ;; problem.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
625 ;; We don't know of any command, except dabbrev-expand, that has the same
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
626 ;; problem. However, the same trick can be used if such a command is
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
627 ;; discovered later.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
628 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
629 (vip-deflocalvar vip-pre-command-point nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
630 (put 'vip-pre-command-point 'permanent-local t) ; this is probably an overkill
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
631
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
632 ;; This is used for saving inserted text.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
633 (defvar vip-last-insertion nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
634
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
635 ;; Remembers the last replaced region.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
636 (defvar vip-last-replace-region "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
637
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
638 ;; Remember com point as a marker.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
639 ;; This is a local marker. Should be moved with `vip-move-marker-locally'
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
640 (vip-deflocalvar vip-com-point nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
641
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
642 ;; If non-nil, the value is a list (M-COM VAL COM REG inserted-text cmd-keys)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
643 ;; It is used to re-execute last destructive command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
644 ;; M-COM is a Lisp symbol representing the function to be executed.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
645 ;; VAL is the prefix argument that was used with that command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
646 ;; COM is an internal descriptor, such as ?r, ?c, ?C, which contains
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
647 ;; additional information on how the function in M-COM is to be handled.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
648 ;; REG is the register used by command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
649 ;; INSERTED-TEXT is text inserted by that command (in case of o, c, C, i, r
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
650 ;; commands).
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
651 ;; COMMAND-KEYS are the keys that were typed to invoke the command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
652 (defvar vip-d-com nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
653
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
654 ;; The character remembered by the Vi `r' command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
655 (defvar vip-d-char nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
656
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
657 ;; Name of register to store deleted or yanked strings
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
658 (defvar vip-use-register nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
659
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
660
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
661
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
662 ;; Variables for Moves and Searches
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
663
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
664 ;; For use by `;' command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
665 (defvar vip-f-char nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
666
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
667 ;; For use by `.' command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
668 (defvar vip-F-char nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
669
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
670 ;; For use by `;' command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
671 (defvar vip-f-forward nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
672
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
673 ;; For use by `;' command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
674 (defvar vip-f-offset nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
675
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
676 ;; Last search string
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
677 (defvar vip-s-string "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
678
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
679 (defvar vip-quote-string "> "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
680 "String inserted at the beginning of quoted region.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
681
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
682 ;; If t, search is forward.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
683 (defvar vip-s-forward nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
684
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
685 (defconst vip-case-fold-search nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
686 "*If t, search ignores cases.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
687
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
688 (defconst vip-re-search t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
689 "*If t, search is reg-exp search, otherwise vanilla search.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
690
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
691 (defconst vip-re-query-replace t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
692 "*If t then do regexp replace, if nil then do string replace.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
693
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
694 (defconst vip-re-replace t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
695 "*If t, do regexp replace. nil means do string replace.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
696
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
697 (vip-deflocalvar vip-ex-style-motion t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
698 "*Ex-style: the commands l,h do not cross lines, etc.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
699
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
700 (vip-deflocalvar vip-ex-style-editing-in-insert t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
701 "*The keys ^H, ^? don't jump lines in insert, ESC moves cursor back, etc.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
702 Note: this doesn't preclude ^H and ^? from deleting characters by moving
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
703 past the insertion point. This is a feature, not a bug. ")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
704
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
705 (vip-deflocalvar vip-delete-backwards-in-replace nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
706 "*If t, DEL key will delete characters while moving the cursor backwards.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
707 If nil, the cursor will move backwards without deleting anything.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
708
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
709 (defconst vip-buffer-search-char nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
710 "*Key bound for buffer-searching.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
711
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
712 (defconst vip-search-wrap-around-t t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
713 "*If t, search wraps around.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
714
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
715 (vip-deflocalvar vip-related-files-and-buffers-ring nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
716 "*Ring of file and buffer names that are considered to be related to the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
717 current buffer.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
718 These buffers can be cycled through via :R and :P commands.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
719 (put 'vip-related-files-and-buffers-ring 'permanent-local t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
720
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
721 ;; Used to find out if we are done with searching the current buffer.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
722 (vip-deflocalvar vip-local-search-start-marker nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
723 ;; As above, but global
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
724 (defvar vip-search-start-marker (make-marker))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
725
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
726 ;; the search overlay
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
727 (vip-deflocalvar vip-search-overlay nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
728
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
729
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
730 (defvar vip-heading-start
10792
70977216c215 Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents: 10789
diff changeset
731 (concat "^\\s-*(\\s-*defun\\s-\\|" ; lisp
70977216c215 Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents: 10789
diff changeset
732 "^{\\s-*$\\|^[_a-zA-Z][^()]*[()].*{\\s-*$\\|" ; C/C++
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
733 "^\\s-*class.*{\\|^\\s-*struct.*{\\|^\\s-*enum.*{\\|"
10792
70977216c215 Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents: 10789
diff changeset
734 "^\\\\[sb][a-z]*{.*}\\s-*$\\|" ; latex
70977216c215 Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents: 10789
diff changeset
735 "^@node\\|@table\\|^@m?enu\\|^@itemize\\|^@if\\|" ; texinfo
70977216c215 Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents: 10789
diff changeset
736 "^.+:-") ; prolog
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
737 "*Regexps for Headings. Used by \[\[ and \]\].")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
738
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
739 (defvar vip-heading-end
10792
70977216c215 Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents: 10789
diff changeset
740 (concat "^}\\|" ; C/C++
70977216c215 Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents: 10789
diff changeset
741 "^\\\\end{\\|" ; latex
70977216c215 Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents: 10789
diff changeset
742 "^@end \\|" ; texinfo
70977216c215 Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents: 10789
diff changeset
743 ")\n\n[ \t\n]*\\|" ; lisp
70977216c215 Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents: 10789
diff changeset
744 "\\.\\s-*$") ; prolog
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
745 "*Regexps to end Headings/Sections. Used by \[\].")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
746
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
747
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
748 ;; These two vars control the interaction of jumps performed by ' and `.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
749 ;; In this new version, '' doesn't erase the marks set by ``, so one can
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
750 ;; use both kinds of jumps interchangeably and without loosing positions
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
751 ;; inside the lines.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
752
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
753 ;; Remembers position of the last jump done using ``'.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
754 (vip-deflocalvar vip-last-jump nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
755 ;; Remembers position of the last jump done using `''.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
756 (vip-deflocalvar vip-last-jump-ignore 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
757
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
758 ;; Some common error messages
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
759
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
760 (defconst vip-SpuriousText "Spurious text after command" "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
761 (defconst vip-BadExCommand "Not an editor command" "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
762 (defconst vip-InvalidCommandArgument "Invalid command argument" "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
763 (defconst vip-NoPrevSearch "No previous search string" "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
764 (defconst vip-EmptyRegister "`%c': Nothing in this register" "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
765 (defconst vip-InvalidRegister "`%c': Invalid register" "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
766 (defconst vip-EmptyTextmarker "`%c': Text marker doesn't point anywhere" "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
767 (defconst vip-InvalidTextmarker "`%c': Invalid text marker" "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
768 (defconst vip-InvalidViCommand "Invalid command" "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
769 (defconst vip-BadAddress "Ill-formed address" "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
770 (defconst vip-FirstAddrExceedsSecond "First address exceeds second" "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
771 (defconst vip-NoFileSpecified "No file specified" "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
772
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
773
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
774 ;; History variables
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
775
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
776 ;; History of search strings.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
777 (defvar vip-search-history (list ""))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
778 ;; History of query-replace strings used as a source.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
779 (defvar vip-replace1-history nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
780 ;; History of query-replace strings used as replacement.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
781 (defvar vip-replace2-history nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
782 ;; History of region quoting strings.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
783 (defvar vip-quote-region-history (list vip-quote-string))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
784 ;; History of Ex-style commands.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
785 (defvar vip-ex-history nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
786 ;; History of shell commands.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
787 (defvar vip-shell-history nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
788
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
790 ;; Last shell command. There are two of these, one for Ex (in viper-ex)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
791 ;; and one for Vi.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
792
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
793 ;; Last shell command executed with ! command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
794 (defvar vip-last-shell-com nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
795
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
796
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
797
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
798 ;;; Miscellaneous
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
799
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
800 ;; setup emacs-supported vi-style feel
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
801 (setq mark-even-if-inactive t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
802 next-line-add-newlines nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
803 require-final-newline t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
804
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
805 (defvar vip-inhibit-startup-message nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
806 "Whether Viper startup message should be inhibited.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
807
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
808 (defvar vip-always t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
809 "t means, arrange that vi-state will be a default.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
810
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
811 (defvar vip-custom-file-name "~/.vip"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
812 "Viper customisation file.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
813 This variable must be set _before_ loading Viper.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
814
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
815 (defvar vip-spell-function 'ispell-region
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
816 "Spell function used by #s<move> command to spell.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
817
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
818 (defvar vip-tags-file-name "TAGS"
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
819 "The tags file used by Viper.")
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
820
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
821 ;; Minibuffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
822
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
823 (defvar vip-vi-style-in-minibuffer t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
824 "If t, use vi-style editing in minibuffer.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
825 Should be set in `~/.vip' file.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
826
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
827 ;; overlay used in the minibuffer to indicate which state it is in
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
828 (vip-deflocalvar vip-minibuffer-overlay nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
829
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
830 ;; Hook, specific to Viper, which is run just *before* exiting the minibuffer.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
831 ;; Beginning with Emacs 19.26, the standard `minibuffer-exit-hook' is run
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
832 ;; *after* exiting the minibuffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
833 (defvar vip-minibuffer-exit-hook nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
834
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
835 (vip-deflocalvar vip-vi-minibuffer-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
836 "Minor mode that forces Vi-style when the Minibuffer is in Vi state.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
837 (vip-deflocalvar vip-insert-minibuffer-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
838 "Minor mode that forces Vi-style when the Minibuffer is in Insert state.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
839
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
840 (vip-deflocalvar vip-add-newline-at-eob t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
841 "If t, always add a newline at the end of buffer.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
842 Usually, Viper adds a newline character at the end of the last
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
843 line in a buffer, if it's missing. In some major modes, however, like
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
844 shell-mode, this is undesirable and must be set to nil. See vip-set-hooks.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
845
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
846
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
847 ;; Mode line
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
848 (defconst vip-vi-state-id "<V> "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
849 "Mode line tag identifying the Vi mode of Viper.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
850 (defconst vip-emacs-state-id "<E> "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
851 "Mode line tag identifying the Emacs mode of Viper.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
852 (defconst vip-insert-state-id "<I> "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
853 "Mode line tag identifying the Insert mode of Viper.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
854 (defconst vip-replace-state-id "<R> "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
855 "Mode line tag identifying the Replace mode of Viper.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
856
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
857 ;; Viper changes the default mode-line-buffer-identification
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
858 (setq-default mode-line-buffer-identification '(" %b"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
859
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
860 ;; Variable displaying the current Viper state in the mode line.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
861 (vip-deflocalvar vip-mode-string vip-emacs-state-id)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
862 (or (memq 'vip-mode-string global-mode-string)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
863 (setq global-mode-string
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
864 (append '("" vip-mode-string) (cdr global-mode-string))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
865
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
866
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
867 (defvar vip-vi-state-hooks nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
868 "*Hooks run just before the switch to Vi mode is completed.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
869 (defvar vip-insert-state-hooks nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
870 "*Hooks run just before the switch to Insert mode is completed.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
871 (defvar vip-replace-state-hooks nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
872 "*Hooks run just before the switch to Replace mode is completed.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
873 (defvar vip-emacs-state-hooks nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
874 "*Hooks run just before the switch to Emacs mode is completed.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
875
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
876 (defvar vip-load-hooks nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
877 "Hooks run just after loading Viper.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
878
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
879
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
880 ;; Generic predicates
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
881
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
882 ;; These test functions are shamelessly lifted from vip 4.4.2 by Aamod Sane
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
883
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
884 ;; generate test functions
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
885 ;; given symbol foo, foo-p is the test function, foos is the set of
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
886 ;; Viper command keys
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
887 ;; (macroexpand '(vip-test-com-defun foo))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
888 ;; (defun foo-p (com) (consp (memq (if (< com 0) (- com) com) foos)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
889
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
890 (defmacro vip-test-com-defun (name)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
891 (let* ((snm (symbol-name name))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
892 (nm-p (intern (concat snm "-p")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
893 (nms (intern (concat snm "s"))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
894 (` (defun (, nm-p) (com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
895 (consp (memq (if (< com 0) (- com) com) (, nms)))))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
896
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
897 ;; Variables for defining VI commands
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
898
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
899 ;; Modifying commands that can be prefixes to movement commands
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
900 (defconst vip-prefix-commands '(?c ?d ?y ?! ?= ?# ?< ?> ?\"))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
901 (vip-test-com-defun vip-prefix-command)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
902
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
903 ;; Commands that are pairs eg. dd. r and R here are a hack
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
904 (defconst vip-charpair-commands '(?c ?d ?y ?! ?= ?< ?> ?r ?R))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
905 (vip-test-com-defun vip-charpair-command)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
906
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
907 (defconst vip-movement-commands '(?b ?B ?e ?E ?f ?F ?G ?h ?H ?j ?k ?l
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
908 ?H ?M ?n ?t ?T ?w ?W ?$ ?%
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
909 ?^ ?( ?) ?- ?+ ?| ?{ ?} ?[ ?] ?' ?`
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
910 ?; ?, ?0 ?? ?/
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
911 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
912 "Movement commands")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
913 (vip-test-com-defun vip-movement-command)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
914
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
915 ;; Commands that can be repeated by .(dotted)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
916 (defconst vip-dotable-commands '(?c ?d ?C ?D ?> ?<))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
917 (vip-test-com-defun vip-dotable-command)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
918
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
919 ;; Commands that can follow a #
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
920 (defconst vip-hash-cmds '(?c ?C ?g ?q ?S))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
921 (vip-test-com-defun vip-hash-cmd)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
922
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
923 ;; Commands that may have registers as prefix
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
924 (defconst vip-regsuffix-commands '(?d ?y ?Y ?D ?p ?P ?x ?X))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
925 (vip-test-com-defun vip-regsuffix-command)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
926
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
927
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
928
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
929 ;;; Arrange the keymaps
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
930 (require 'viper-keym)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
931
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
932
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
933 ;;;; CODE
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
934
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
935 ;; changing mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
936
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
937 ;; Change state to NEW-STATE---either emacs-state, vi-state, or insert-state.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
938 (defun vip-change-state (new-state)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
939 ;; Keep vip-post/pre-command-hooks fresh.
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
940 ;; We remove then add vip-post/pre-command-sentinel since it is very
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
941 ;; desirable that noone gets in-between
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
942 (remove-hook 'post-command-hook 'vip-post-command-sentinel)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
943 (add-hook 'post-command-hook 'vip-post-command-sentinel)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
944 (remove-hook 'pre-command-hook 'vip-pre-command-sentinel)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
945 (add-hook 'pre-command-hook 'vip-pre-command-sentinel t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
946 ;; These hooks will be added back if switching to insert/replace mode
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
947 (vip-remove-hook 'vip-post-command-hooks
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
948 'vip-insert-state-post-command-sentinel)
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
949 (vip-remove-hook 'vip-pre-command-hooks
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
950 'vip-insert-state-pre-command-sentinel)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
951 (cond ((eq new-state 'vi-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
952 (cond ((member vip-current-state '(insert-state replace-state))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
953
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
954 ;; move vip-last-posn-while-in-insert-state
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
955 ;; This is a normal hook that is executed in insert/replace
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
956 ;; states after each command. In Vi/Emacs state, it does
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
957 ;; nothing. We need to execute it here to make sure that
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
958 ;; the last posn was recorded when we hit ESC.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
959 ;; It may be left unrecorded if the last thing done in
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
960 ;; insert/repl state was dabbrev-expansion or abbrev
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
961 ;; expansion caused by hitting ESC
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
962 (vip-insert-state-post-command-sentinel)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
963
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
964 (condition-case conds
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
965 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
966 (vip-save-last-insertion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
967 vip-insert-point
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
968 vip-last-posn-while-in-insert-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
969 (if vip-began-as-replace
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
970 (setq vip-began-as-replace nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
971 ;; repeat insert commands if numerical arg > 1
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
972 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
973 (vip-repeat-insert-command))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
974 (error
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
975 (vip-message-conditions conds)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
976
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
977 (if (> (length vip-last-insertion) 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
978 (vip-push-onto-ring vip-last-insertion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
979 'vip-insertion-ring))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
980
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
981 (if vip-ex-style-editing-in-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
982 (or (bolp) (backward-char 1))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
983 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
984
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
985 ;; insert or replace
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
986 ((memq new-state '(insert-state replace-state))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
987 (if (memq vip-current-state '(emacs-state vi-state))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
988 (vip-move-marker-locally 'vip-insert-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
989 (vip-move-marker-locally 'vip-last-posn-while-in-insert-state (point))
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
990 (vip-add-hook 'vip-post-command-hooks
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
991 'vip-insert-state-post-command-sentinel t)
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
992 (vip-add-hook 'vip-pre-command-hooks
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
993 'vip-insert-state-pre-command-sentinel t))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
994 ) ; outermost cond
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
995
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
996 ;; Nothing needs to be done to switch to emacs mode! Just set some
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
997 ;; variables, which is already done in vip-change-state-to-emacs!
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
998
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
999 (setq vip-current-state new-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1000 (vip-normalize-minor-mode-map-alist)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1001 (vip-adjust-keys-for new-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1002 (vip-set-mode-vars-for new-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1003 (vip-refresh-mode-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1004 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1005
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1006
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1007
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1008 (defun vip-adjust-keys-for (state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1009 "Make necessary adjustments to keymaps before entering STATE."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1010 (cond ((memq state '(insert-state replace-state))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1011 (if vip-auto-indent
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1012 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1013 (define-key vip-insert-basic-map "\C-m" 'vip-autoindent)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1014 (if vip-want-emacs-keys-in-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1015 ;; expert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1016 (define-key vip-insert-basic-map "\C-j" nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1017 ;; novice
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1018 (define-key vip-insert-basic-map "\C-j" 'vip-autoindent))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1019
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1020 (setq vip-insert-diehard-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1021 (not vip-want-emacs-keys-in-insert))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1022
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1023 (if vip-want-ctl-h-help
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1024 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1025 (define-key vip-insert-basic-map "\C-h" 'help-command)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1026 (define-key vip-replace-map "\C-h" 'help-command))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1027 (define-key vip-insert-basic-map
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1028 "\C-h" 'vip-del-backward-char-in-insert)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1029 (define-key vip-replace-map
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1030 "\C-h" 'vip-del-backward-char-in-replace)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1031
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1032 (t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1033 (setq vip-vi-diehard-minor-mode (not vip-want-emacs-keys-in-vi))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1034 (if vip-want-ctl-h-help
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1035 (define-key vip-vi-basic-map "\C-h" 'help-command)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1036 (define-key vip-vi-basic-map "\C-h" 'vip-backward-char)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1037 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1038
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1039
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1040 ;; Normalizes minor-mode-map-alist by putting Viper keymaps first.
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1041 ;; This ensures that Viper bindings are in effect, regardless of which minor
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1042 ;; modes were turned on by the user or by other packages.
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
1043 (defun vip-normalize-minor-mode-map-alist ()
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1044 (setq minor-mode-map-alist
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1045 (vip-append-filter-alist
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1046 (list
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1047 (cons 'vip-vi-intercept-minor-mode vip-vi-intercept-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1048 (cons 'vip-vi-minibuffer-minor-mode vip-minibuffer-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1049 (cons 'vip-vi-local-user-minor-mode vip-vi-local-user-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1050 (cons 'vip-vi-kbd-minor-mode vip-vi-kbd-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1051 (cons 'vip-vi-global-user-minor-mode vip-vi-global-user-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1052 (cons 'vip-vi-state-modifier-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1053 (if (keymapp
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1054 (cdr (assoc major-mode vip-vi-state-modifier-alist)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1055 (cdr (assoc major-mode vip-vi-state-modifier-alist))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1056 vip-empty-keymap))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1057 (cons 'vip-vi-diehard-minor-mode vip-vi-diehard-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1058 (cons 'vip-vi-basic-minor-mode vip-vi-basic-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1059 (cons 'vip-insert-intercept-minor-mode vip-insert-intercept-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1060 (cons 'vip-replace-minor-mode vip-replace-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1061 ;; vip-insert-minibuffer-minor-mode must come after
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1062 ;; vip-replace-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1063 (cons 'vip-insert-minibuffer-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1064 vip-minibuffer-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1065 (cons 'vip-insert-local-user-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1066 vip-insert-local-user-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1067 (cons 'vip-insert-kbd-minor-mode vip-insert-kbd-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1068 (cons 'vip-insert-global-user-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1069 vip-insert-global-user-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1070 (cons 'vip-insert-state-modifier-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1071 (if (keymapp
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1072 (cdr
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1073 (assoc major-mode vip-insert-state-modifier-alist)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1074 (cdr
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1075 (assoc major-mode vip-insert-state-modifier-alist))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1076 vip-empty-keymap))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1077 (cons 'vip-insert-diehard-minor-mode vip-insert-diehard-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1078 (cons 'vip-insert-basic-minor-mode vip-insert-basic-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1079 (cons 'vip-emacs-intercept-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1080 vip-emacs-intercept-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1081 (cons 'vip-emacs-local-user-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1082 vip-emacs-local-user-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1083 (cons 'vip-emacs-kbd-minor-mode vip-emacs-kbd-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1084 (cons 'vip-emacs-global-user-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1085 vip-emacs-global-user-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1086 (cons 'vip-emacs-state-modifier-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1087 (if (keymapp
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1088 (cdr
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1089 (assoc major-mode vip-emacs-state-modifier-alist)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1090 (cdr
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1091 (assoc major-mode vip-emacs-state-modifier-alist))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1092 vip-empty-keymap))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1093 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1094 minor-mode-map-alist)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1095
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1096
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1097
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1098
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1099
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1100 ;; Viper mode-changing commands and utilities
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1101
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1102 ;; Modifies mode-line-buffer-identification.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1103 (defun vip-refresh-mode-line ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1104 (setq vip-mode-string
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1105 (cond ((eq vip-current-state 'emacs-state) vip-emacs-state-id)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1106 ((eq vip-current-state 'vi-state) vip-vi-state-id)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1107 ((eq vip-current-state 'replace-state) vip-replace-state-id)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1108 ((eq vip-current-state 'insert-state) vip-insert-state-id)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1109
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1110 ;; Sets Viper mode string in global-mode-string
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1111 (force-mode-line-update))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1112
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1113 ;;;###autoload
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1114 (defun viper-mode ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1115 "Turn on Viper emulation of Vi."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1116 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1117 (if (not noninteractive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1118 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1119 (if vip-first-time ; This check is important. Without it, startup and
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1120 (progn ; expert-level msgs mix up when viper-mode recurses
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1121 (setq vip-first-time nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1122 (if (not vip-inhibit-startup-message)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1123 (save-window-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1124 (setq vip-inhibit-startup-message t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1125 (delete-other-windows)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1126 (switch-to-buffer "Viper Startup Message")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1127 (erase-buffer)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1128 (insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1129 (substitute-command-keys
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1130 "Viper Is a Package for Emacs Rebels.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1131 It is also a VI Plan for Emacs Rescue and a venomous VI PERil.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1132
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1133 Technically speaking, Viper is a Vi emulation package for GNU Emacs 19 and
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1134 XEmacs 19. It supports virtually all of Vi and Ex functionality, extending
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1135 and improving upon much of it.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1136
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1137 1. Viper supports Vi at several levels. Level 1 is the closest to
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1138 Vi, level 5 provides the most flexibility to depart from many Vi
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1139 conventions.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1140
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1141 You will be asked to specify your user level in a following screen.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1142
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1143 If you select user level 1 then the keys ^X, ^C, ^Z, and ^G will
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1144 behave as in VI, to smooth transition to Viper for the beginners.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1145 However, to use Emacs productively, you are advised to reach user
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1146 level 3 or higher.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1147
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1148 If your user level is 2 or higher, ^X and ^C will invoke Emacs
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1149 functions,as usual in Emacs; ^Z will toggle vi/emacs modes, and
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1150 ^G will be the usual Emacs's keyboard-quit (something like ^C in VI).
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1151
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1152 2. Vi exit functions (e.g., :wq, ZZ) work on INDIVIDUAL files -- they
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1153 do not cause Emacs to quit, except at user level 1 (a novice).
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1154 3. ^X^C EXITS EMACS.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1155 4. Viper supports multiple undo: `u' will undo. Typing `.' will repeat
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1156 undo. Another `u' changes direction.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1157
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1158 6. Emacs Meta functions are invoked by typing `_' or `\\ ESC'.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1159 On a window system, the best way is to use the Meta-key.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1160 7. Try \\[keyboard-quit] and \\[abort-recursive-edit] repeatedly,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1161 if something funny happens. This would abort the current editing
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1162 command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1163
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1164 You can get more information on Viper by:
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1165
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1166 a. Typing `:help' in Vi state
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1167 b. Printing Viper manual, found in ./etc/viper.dvi
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1168 c. Printing ViperCard, the Quick Reference, found in ./etc/viperCard.dvi
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1169
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1170 This startup message appears whenever you load Viper, unless you type `y' now."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1171 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1172 (goto-char (point-min))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1173 (if (y-or-n-p "Inhibit Viper startup message? ")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1174 (vip-save-setting
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1175 'vip-inhibit-startup-message
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1176 "Viper startup message inhibited"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1177 vip-custom-file-name t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1178 (kill-buffer (current-buffer))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1179 (message " ")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1180 (vip-set-expert-level 'dont-change-unless)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1181 (vip-change-state-to-vi))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1182
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1183 ;;;###autoload
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1184 (defalias 'vip-mode 'viper-mode)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1185
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1186
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1187 ;; Switch from Insert state to Vi state.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1188 (defun vip-exit-insert-state ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1189 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1190 (vip-change-state-to-vi))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1191
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1192 (defun vip-set-mode-vars-for (state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1193 "Sets Viper minor mode variables to put Viper's state STATE in effect."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1194
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1195 ;; Emacs state
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1196 (setq vip-vi-minibuffer-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1197 vip-insert-minibuffer-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1198 vip-vi-intercept-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1199 vip-insert-intercept-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1200
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1201 vip-vi-local-user-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1202 vip-vi-kbd-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1203 vip-vi-global-user-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1204 vip-vi-state-modifier-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1205 vip-vi-diehard-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1206 vip-vi-basic-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1207
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1208 vip-replace-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1209
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1210 vip-insert-local-user-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1211 vip-insert-kbd-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1212 vip-insert-global-user-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1213 vip-insert-state-modifier-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1214 vip-insert-diehard-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1215 vip-insert-basic-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1216 vip-emacs-intercept-minor-mode t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1217 vip-emacs-local-user-minor-mode t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1218 vip-emacs-kbd-minor-mode (not (vip-is-in-minibuffer))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1219 vip-emacs-global-user-minor-mode t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1220 vip-emacs-state-modifier-minor-mode t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1221 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1222
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1223 ;; Vi state
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1224 (if (eq state 'vi-state) ; adjust for vi-state
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1225 (setq
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1226 vip-vi-intercept-minor-mode t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1227 vip-vi-minibuffer-minor-mode (vip-is-in-minibuffer)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1228 vip-vi-local-user-minor-mode t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1229 vip-vi-kbd-minor-mode (not (vip-is-in-minibuffer))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1230 vip-vi-global-user-minor-mode t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1231 vip-vi-state-modifier-minor-mode t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1232 ;; don't let the diehard keymap block command completion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1233 ;; and other things in the minibuffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1234 vip-vi-diehard-minor-mode (not
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1235 (or vip-want-emacs-keys-in-vi
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1236 (vip-is-in-minibuffer)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1237 vip-vi-basic-minor-mode t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1238 vip-emacs-intercept-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1239 vip-emacs-local-user-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1240 vip-emacs-kbd-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1241 vip-emacs-global-user-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1242 vip-emacs-state-modifier-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1243 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1244
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1245 ;; Insert and Replace states
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1246 (if (member state '(insert-state replace-state))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1247 (setq
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1248 vip-insert-intercept-minor-mode t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1249 vip-replace-minor-mode (eq state 'replace-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1250 vip-insert-minibuffer-minor-mode (vip-is-in-minibuffer)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1251 vip-insert-local-user-minor-mode t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1252 vip-insert-kbd-minor-mode (not (vip-is-in-minibuffer))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1253 vip-insert-global-user-minor-mode t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1254 vip-insert-state-modifier-minor-mode t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1255 ;; don't let the diehard keymap block command completion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1256 ;; and other things in the minibuffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1257 vip-insert-diehard-minor-mode (not
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1258 (or vip-want-emacs-keys-in-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1259 (vip-is-in-minibuffer)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1260 vip-insert-basic-minor-mode t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1261 vip-emacs-intercept-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1262 vip-emacs-local-user-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1263 vip-emacs-kbd-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1264 vip-emacs-global-user-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1265 vip-emacs-state-modifier-minor-mode nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1266 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1267
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1268 ;; minibuffer faces
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1269 (if (vip-window-display-p)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1270 (setq vip-minibuffer-current-face
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1271 (cond ((eq state 'emacs-state) vip-minibuffer-emacs-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1272 ((eq state 'vi-state) vip-minibuffer-vi-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1273 ((memq state '(insert-state replace-state))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1274 vip-minibuffer-insert-face))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1275
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1276 (if (vip-is-in-minibuffer)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1277 (vip-set-minibuffer-overlay))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1278 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1279
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1280 ;; This also takes care of the annoying incomplete lines in files.
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
1281 ;; Also, this fixes `undo' to work vi-style for complex commands.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1282 (defun vip-change-state-to-vi ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1283 "Change Viper state to Vi."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1284 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1285 (if (and vip-first-time (not (vip-is-in-minibuffer)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1286 (viper-mode)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1287 (if overwrite-mode (overwrite-mode nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1288 (if abbrev-mode (expand-abbrev))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1289 (if (and auto-fill-function (> (current-column) fill-column))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1290 (funcall auto-fill-function))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1291 ;; don't leave whitespace lines around
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
1292 (if (and (memq last-command
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
1293 '(vip-autoindent
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
1294 vip-open-line vip-Open-line
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
1295 vip-replace-state-exit-cmd))
12203
0078571e5330 (vip-change-state-to-vi): bug fix.
Karl Heuer <kwzh@gnu.org>
parents: 12137
diff changeset
1296 (vip-over-whitespace-line))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1297 (indent-to-left-margin))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1298 (vip-add-newline-at-eob-if-necessary)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1299 (if vip-undo-needs-adjustment (vip-adjust-undo))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1300 (vip-change-state 'vi-state)
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
1301
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
1302 ;; always turn off iso-accents-mode, or else we won't be able to use the
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
1303 ;; keys `,',^ in Vi state, as they will do accents instead of Vi actions.
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
1304 (if (and (boundp 'iso-accents-mode) iso-accents-mode)
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
1305 (iso-accents-mode -1))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1306
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1307 ;; Protection against user errors in hooks
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1308 (condition-case conds
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1309 (run-hooks 'vip-vi-state-hooks)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1310 (error
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1311 (vip-message-conditions conds)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1312
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1313 (defun vip-change-state-to-insert ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1314 "Change Viper state to Insert."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1315 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1316 (vip-change-state 'insert-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1317 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1318 (iso-accents-mode 1)) ; turn iso accents on
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1319
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1320 ;; Protection against user errors in hooks
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1321 (condition-case conds
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1322 (run-hooks 'vip-insert-state-hooks)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1323 (error
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1324 (vip-message-conditions conds))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1325
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1326 (defsubst vip-downgrade-to-insert ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1327 (setq vip-current-state 'insert-state
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1328 vip-replace-minor-mode nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1329 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1330
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1331
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1332
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1333 ;; Change to replace state. When the end of replacement region is reached,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1334 ;; replace state changes to insert state.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1335 (defun vip-change-state-to-replace (&optional non-R-cmd)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1336 (vip-change-state 'replace-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1337 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1338 (iso-accents-mode 1)) ; turn iso accents on
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1339 ;; Run insert-state-hook
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1340 (condition-case conds
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1341 (run-hooks 'vip-insert-state-hooks 'vip-replace-state-hooks)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1342 (error
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1343 (vip-message-conditions conds)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1344
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1345 (if non-R-cmd
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1346 (vip-start-replace)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1347 ;; 'R' is implemented using Emacs's overwrite-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1348 (vip-start-R-mode))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1349 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1350
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1351
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1352 (defun vip-change-state-to-emacs ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1353 "Change Viper state to Emacs."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1354 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1355 (vip-change-state 'emacs-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1356 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1357 (iso-accents-mode 1)) ; turn iso accents on
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1358
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1359 ;; Protection agains user errors in hooks
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1360 (condition-case conds
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1361 (run-hooks 'vip-emacs-state-hooks)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1362 (error
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1363 (vip-message-conditions conds))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1364
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1365 ;; escape to emacs mode termporarily
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1366 (defun vip-escape-to-emacs (arg &optional events)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1367 "Escape to Emacs state from Vi state for one Emacs command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1368 ARG is used as the prefix value for the executed command. If
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1369 EVENTS is a list of events, which become the beginning of the command."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1370 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1371 (vip-escape-to-state arg events 'emacs-state))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1372
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1373 ;; escape to Vi mode termporarily
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1374 (defun vip-escape-to-vi ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1375 "Escape from Emacs state to Vi state for one Vi 1-character command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1376 This doesn't work with prefix arguments or most complex commands like
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1377 cw, dw, etc. But it does work with some 2-character commands,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1378 like dd or dr."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1379 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1380 (vip-escape-to-state nil nil 'vi-state))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1381
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1382 ;; Escape to STATE mode for one Emacs command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1383 (defun vip-escape-to-state (arg events state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1384 (let (com key prefix-arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1385 ;; this temporarily turns off Viper's minor mode keymaps
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1386 (vip-set-mode-vars-for state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1387 (vip-normalize-minor-mode-map-alist)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1388 (if events (vip-set-unread-command-events events))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1389
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1390 ;; protect against keyboard quit and other errors
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1391 (condition-case nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1392 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1393 (unwind-protect
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1394 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1395 (setq com (key-binding (setq key
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1396 (if vip-xemacs-p
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1397 (read-key-sequence nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1398 (read-key-sequence nil t)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1399 ;; In case of indirection--chase definitions.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1400 ;; Have to do it here because we execute this command under
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1401 ;; different keymaps, so command-execute may not do the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1402 ;; right thing there
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1403 (while (vectorp com) (setq com (key-binding com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1404 nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1405 ;; exec command in the right Viper state
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1406 ;; otherwise, if we switch buffers in the escaped command,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1407 ;; Viper's mode vars will remain those of `state'. When we return
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1408 ;; to the orig buffer, the bindings will be screwed up.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1409 (vip-set-mode-vars-for vip-current-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1410
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1411 ;; this-command, last-command-char, last-command-event
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1412 (setq this-command com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1413 (if vip-xemacs-p ; XEmacs represents key sequences as vectors
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1414 (setq last-command-event (vip-seq-last-elt key)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1415 last-command-char (event-to-character last-command-event))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1416 ;; Emacs represents them as sequences (str or vec)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1417 (setq last-command-event (vip-seq-last-elt key)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1418 last-command-char last-command-event))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1419
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1420 (if (commandp com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1421 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1422 (setq prefix-arg arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1423 (command-execute com)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1424 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1425 (quit (ding))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1426 (error (beep 1))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1427 (vip-set-mode-vars-for vip-current-state)) ; set state in new buffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1428
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1429 (defun vip-exec-form-in-emacs (form)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1430 "Execute FORM in Emacs, temporarily disabling Viper's minor modes.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1431 Similar to vip-escape-to-emacs, but accepts forms rather than keystrokes."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1432 (let ((buff (current-buffer))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1433 result)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1434 (vip-set-mode-vars-for 'emacs-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1435 (setq result (eval form))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1436 (if (not (equal buff (current-buffer))) ; cmd switched buffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1437 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1438 (set-buffer buff)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1439 (vip-set-mode-vars-for vip-current-state)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1440 (vip-set-mode-vars-for vip-current-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1441 result))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1442
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1443
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1444 ;; This is needed because minor modes sometimes override essential Viper
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1445 ;; bindings. By letting Viper know which files these modes are in, it will
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1446 ;; arrange to reorganize minor-mode-map-alist so that things will work right.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1447 (defun vip-harness-minor-mode (load-file)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1448 "Familiarize Viper with a minor mode defined in LOAD_FILE.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1449 Minor modes that have their own keymaps may overshadow Viper keymaps.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1450 This function is designed to make Viper aware of the packages that define
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1451 such minor modes.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1452 Usage:
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1453 (vip-harness-minor-mode load-file)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1454
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1455 LOAD-FILE is a name of the file where the specific minor mode is defined.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1456 Suffixes such as .el or .elc should be stripped."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1457
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1458 (interactive "sEnter name of the load file: ")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1459
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1460 (vip-eval-after-load load-file '(vip-normalize-minor-mode-map-alist))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1461
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1462 ;; Change the default for minor-mode-map-alist each time a harnessed minor
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1463 ;; mode adds its own keymap to the a-list.
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1464 (vip-eval-after-load
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1465 load-file '(setq-default minor-mode-map-alist minor-mode-map-alist))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1466 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1467
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1468
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1469 (defun vip-ESC (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1470 "Emulate ESC key in Emacs.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1471 Prevents multiple escape keystrokes if vip-no-multiple-ESC is true. In that
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1472 case \@ will be bound to ESC. If vip-no-multiple-ESC is 'twice double ESC
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1473 would dings in vi-state. Other ESC sequences are emulated via the current
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1474 Emacs's major mode keymap. This is more convenient on dumb terminals and in
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1475 Emacs -nw, since this won't block functional keys such as up,down,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1476 etc. Meta key also will work. When vip-no-multiple-ESC is nil, ESC key
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1477 behaves as in Emacs, any number of multiple escapes is allowed."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1478 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1479 (let (char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1480 (cond ((and (not vip-no-multiple-ESC) (eq vip-current-state 'vi-state))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1481 (setq char (vip-read-char-exclusive))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1482 (vip-escape-to-emacs arg (list ?\e char) ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1483 ((and (eq vip-no-multiple-ESC 'twice)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1484 (eq vip-current-state 'vi-state))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1485 (setq char (vip-read-char-exclusive))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1486 (if (= char (string-to-char vip-ESC-key))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1487 (ding)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1488 (vip-escape-to-emacs arg (list ?\e char) )))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1489 (t (ding)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1490 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1491
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1492 (defun vip-alternate-ESC (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1493 "ESC key without checking for multiple keystrokes."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1494 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1495 (vip-escape-to-emacs arg '(?\e)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1496
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1497
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1498 ;; Intercept ESC sequences on dumb terminals.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1499 ;; Based on the idea contributed by Marcelino Veiga Tuimil <mveiga@dit.upm.es>
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1500
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1501 ;; Check if last key was ESC and if so try to reread it as a function key.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1502 ;; But only if there are characters to read during a very short time.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1503 ;; Returns the last event, if any.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1504 (defun vip-envelop-ESC-key ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1505 (let ((event last-input-event)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1506 (keyseq [nil])
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1507 inhibit-quit)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1508 (if (vip-ESC-event-p event)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1509 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1510 (if (vip-fast-keysequence-p)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1511 (progn
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
1512 (let (minor-mode-map-alist)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1513 (vip-set-unread-command-events event)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1514 (setq keyseq
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1515 (funcall
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1516 (ad-get-orig-definition 'read-key-sequence) nil))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1517 ) ; let
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1518 ;; If keyseq translates into something that still has ESC
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
1519 ;; at the beginning, separate ESC from the rest of the seq.
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1520 ;; In XEmacs we check for events that are keypress meta-key
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1521 ;; and convert them into [escape key]
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1522 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1523 ;; This is needed for the following reason:
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1524 ;; If ESC is the first symbol, we interpret it as if the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1525 ;; user typed ESC and then quickly some other symbols.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1526 ;; If ESC is not the first one, then the key sequence
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1527 ;; entered was apparently translated into a function key or
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1528 ;; something (e.g., one may have
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1529 ;; (define-key function-key-map "\e[192z" [f11])
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1530 ;; which would translate the escape-sequence generated by
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1531 ;; f11 in an xterm window into the symbolic key f11.
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1532 ;;
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
1533 ;; If `first-key' is not an ESC event, we make it into the
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1534 ;; last-command-event in order to pretend that this key was
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1535 ;; pressed. This is needed to allow arrow keys to be bound to
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1536 ;; macros. Otherwise, vip-exec-mapped-kbd-macro will think that
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1537 ;; the last event was ESC and so it'll execute whatever is
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1538 ;; bound to ESC. (Viper macros can't be bound to
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1539 ;; ESC-sequences).
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1540 (let* ((first-key (elt keyseq 0))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1541 (key-mod (event-modifiers first-key)))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1542 (cond ((vip-ESC-event-p first-key)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1543 ;; put keys following ESC on the unread list
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1544 ;; and return ESC as the key-sequence
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1545 (vip-set-unread-command-events (subseq keyseq 1))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1546 (setq last-input-event event
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1547 keyseq (if vip-emacs-p
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1548 "\e"
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1549 (vector (character-to-event ?\e)))))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1550 ((and vip-xemacs-p
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1551 (key-press-event-p first-key)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1552 (equal '(meta) key-mod))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1553 (vip-set-unread-command-events
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1554 (vconcat (vector
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1555 (character-to-event (event-key first-key)))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1556 (subseq keyseq 1)))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1557 (setq last-input-event event
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1558 keyseq (vector (character-to-event ?\e))))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1559 ((eventp first-key)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1560 (setq last-command-event first-key))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1561 ))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1562 ) ; end progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1563
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1564 ;; this is escape event with nothing after it
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1565 ;; put in unread-command-event and then re-read
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1566 (vip-set-unread-command-events event)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1567 (setq keyseq
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1568 (funcall (ad-get-orig-definition 'read-key-sequence) nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1569 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1570 ;; not an escape event
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1571 (setq keyseq (vector event)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1572 keyseq))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1573
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1574
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1575
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1576 (defadvice read-key-sequence (around vip-read-keyseq-ad activate)
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
1577 "Harness to work for Viper. This advice is harmless---don't worry!"
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1578 (let (inhibit-quit event keyseq)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1579 (setq keyseq ad-do-it)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1580 (setq event (if vip-xemacs-p
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1581 (elt keyseq 0) ; XEmacs returns vector of events
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1582 (elt (listify-key-sequence keyseq) 0)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1583 (if (vip-ESC-event-p event)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1584 (let (unread-command-events)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1585 (vip-set-unread-command-events keyseq)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1586 (if (vip-fast-keysequence-p)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1587 (let ((vip-vi-global-user-minor-mode nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1588 (vip-vi-local-user-minor-mode nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1589 (vip-replace-minor-mode nil) ; actually unnecessary
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1590 (vip-insert-global-user-minor-mode nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1591 (vip-insert-local-user-minor-mode nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1592 (setq keyseq ad-do-it))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1593 (setq keyseq ad-do-it))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1594 keyseq))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1595
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1596 (defadvice describe-key (before vip-read-keyseq-ad protect activate)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1597 "Force to read key via `read-key-sequence'."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1598 (interactive (list (vip-events-to-keys
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1599 (read-key-sequence "Describe key: ")))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1600
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1601 (defadvice describe-key-briefly (before vip-read-keyseq-ad protect activate)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1602 "Force to read key via `read-key-sequence'."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1603 (interactive (list (vip-events-to-keys
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1604 (read-key-sequence "Describe key briefly: ")))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1605
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1606 ;; Listen to ESC key.
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1607 ;; If a sequence of keys starting with ESC is issued with very short delays,
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1608 ;; interpret these keys in Emacs mode, so ESC won't be interpreted as a Vi key.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1609 (defun vip-intercept-ESC-key ()
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1610 "Function that implements ESC key in Viper emulation of Vi."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1611 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1612 (let ((cmd (or (key-binding (vip-envelop-ESC-key))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1613 '(lambda () (interactive) (error "")))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1614
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1615 ;; call the actual function to execute ESC (if no other symbols followed)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1616 ;; or the key bound to the ESC sequence (if the sequence was issued
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1617 ;; with very short delay between characters.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1618 (if (eq cmd 'vip-intercept-ESC-key)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1619 (setq cmd
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1620 (cond ((eq vip-current-state 'vi-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1621 'vip-ESC)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1622 ((eq vip-current-state 'insert-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1623 'vip-exit-insert-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1624 ((eq vip-current-state 'replace-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1625 'vip-replace-state-exit-cmd)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1626 (t 'vip-change-state-to-vi)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1627 )))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1628 (call-interactively cmd)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1629
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1630
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1631
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1632 ;; prefix argument for Vi mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1633
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1634 ;; In Vi mode, prefix argument is a dotted pair (NUM . COM) where NUM
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1635 ;; represents the numeric value of the prefix argument and COM represents
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1636 ;; command prefix such as "c", "d", "m" and "y".
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1637
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1638 ;; Compute numeric prefix arg value.
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1639 ;; Invoked by CHAR. COM is the command part obtained so far.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1640 (defun vip-prefix-arg-value (event com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1641 (let (value)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1642 ;; read while number
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1643 (while (and (numberp event) (>= event ?0) (<= event ?9))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1644 (setq value (+ (* (if (numberp value) value 0) 10) (- event ?0)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1645 (setq event (vip-read-event-convert-to-char)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1646
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1647 (setq prefix-arg value)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1648 (if com (setq prefix-arg (cons prefix-arg com)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1649 (while (eq event ?U)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1650 (vip-describe-arg prefix-arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1651 (setq event (vip-read-event-convert-to-char)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1652 (vip-set-unread-command-events event)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1653
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1654 ;; Vi operator as prefix argument."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1655 (defun vip-prefix-arg-com (char value com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1656 (let ((cont t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1657 (while (and cont
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1658 (memq char
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1659 (list ?c ?d ?y ?! ?< ?> ?= ?# ?r ?R ?\"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1660 vip-buffer-search-char)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1661 (if com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1662 ;; this means that we already have a command character, so we
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1663 ;; construct a com list and exit while. however, if char is "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1664 ;; it is an error.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1665 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1666 ;; new com is (CHAR . OLDCOM)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1667 (if (memq char '(?# ?\")) (error ""))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1668 (setq com (cons char com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1669 (setq cont nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1670 ;; If com is nil we set com as char, and read more. Again, if char
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1671 ;; is ", we read the name of register and store it in vip-use-register.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1672 ;; if char is !, =, or #, a complete com is formed so we exit the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1673 ;; while loop.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1674 (cond ((memq char '(?! ?=))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1675 (setq com char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1676 (setq char (read-char))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1677 (setq cont nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1678 ((= char ?#)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1679 ;; read a char and encode it as com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1680 (setq com (+ 128 (read-char)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1681 (setq char (read-char)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1682 ((= char ?\")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1683 (let ((reg (read-char)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1684 (if (vip-valid-register reg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1685 (setq vip-use-register reg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1686 (error ""))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1687 (setq char (read-char))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1688 (t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1689 (setq com char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1690 (setq char (vip-read-char-exclusive)))))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1691 (if (atom com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1692 ;; com is a single char, so we construct prefix-arg
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1693 ;; and if char is ?, describe prefix arg, otherwise exit by
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1694 ;; pushing the char back
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1695 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1696 (setq prefix-arg (cons value com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1697 (while (= char ?U)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1698 (vip-describe-arg prefix-arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1699 (setq char (read-char)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1700 (vip-set-unread-command-events char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1701 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1702 ;; as com is non-nil, this means that we have a command to execute
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1703 (if (memq (car com) '(?r ?R))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1704 ;; execute apropriate region command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1705 (let ((char (car com)) (com (cdr com)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1706 (setq prefix-arg (cons value com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1707 (if (= char ?r) (vip-region prefix-arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1708 (vip-Region prefix-arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1709 ;; reset prefix-arg
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1710 (setq prefix-arg nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1711 ;; otherwise, reset prefix arg and call appropriate command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1712 (setq value (if (null value) 1 value))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1713 (setq prefix-arg nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1714 (cond ((equal com '(?c . ?c)) (vip-line (cons value ?C)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1715 ((equal com '(?d . ?d)) (vip-line (cons value ?D)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1716 ((equal com '(?d . ?y)) (vip-yank-defun))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1717 ((equal com '(?y . ?y)) (vip-line (cons value ?Y)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1718 ((equal com '(?< . ?<)) (vip-line (cons value ?<)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1719 ((equal com '(?> . ?>)) (vip-line (cons value ?>)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1720 ((equal com '(?! . ?!)) (vip-line (cons value ?!)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1721 ((equal com '(?= . ?=)) (vip-line (cons value ?=)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1722 (t (error ""))))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1723
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1724 (defun vip-describe-arg (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1725 (let (val com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1726 (setq val (vip-P-val arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1727 com (vip-getcom arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1728 (if (null val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1729 (if (null com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1730 (message "Value is nil, and command is nil")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1731 (message "Value is nil, and command is `%c'" com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1732 (if (null com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1733 (message "Value is `%d', and command is nil" val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1734 (message "Value is `%d', and command is `%c'" val com)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1735
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1736 (defun vip-digit-argument (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1737 "Begin numeric argument for the next command."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1738 (interactive "P")
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
1739 (vip-leave-region-active)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1740 (vip-prefix-arg-value last-command-char
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1741 (if (consp arg) (cdr arg) nil)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1742
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1743 (defun vip-command-argument (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1744 "Accept a motion command as an argument."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1745 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1746 (condition-case nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1747 (vip-prefix-arg-com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1748 last-command-char
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1749 (cond ((null arg) nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1750 ((consp arg) (car arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1751 ((numberp arg) arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1752 (t (error vip-InvalidCommandArgument)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1753 (cond ((null arg) nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1754 ((consp arg) (cdr arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1755 ((numberp arg) nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1756 (t (error vip-InvalidCommandArgument))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1757 (quit (setq vip-use-register nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1758 (signal 'quit nil)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1759 (vip-deactivate-mark))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1760
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1761 ;; Get value part of prefix-argument ARG.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1762 (defsubst vip-p-val (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1763 (cond ((null arg) 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1764 ((consp arg) (if (null (car arg)) 1 (car arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1765 (t arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1766
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1767 ;; Get raw value part of prefix-argument ARG.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1768 (defsubst vip-P-val (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1769 (cond ((consp arg) (car arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1770 (t arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1771
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1772 ;; Get com part of prefix-argument ARG.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1773 (defsubst vip-getcom (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1774 (cond ((null arg) nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1775 ((consp arg) (cdr arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1776 (t nil)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1777
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1778 ;; Get com part of prefix-argument ARG and modify it.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1779 (defun vip-getCom (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1780 (let ((com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1781 (cond ((equal com ?c) ?C)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1782 ((equal com ?d) ?D)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1783 ((equal com ?y) ?Y)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1784 (t com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1785
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1786
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1787 ;; repeat last destructive command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1788
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1789 ;; Append region to text in register REG.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1790 ;; START and END are buffer positions indicating what to append.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1791 (defsubst vip-append-to-register (reg start end)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1792 (set-register reg (concat (if (stringp (get-register reg))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1793 (get-register reg) "")
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1794 (buffer-substring start end))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1795
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1796 ;; define functions to be executed
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1797
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1798 ;; invoked by C command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1799 (defun vip-exec-change (m-com com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1800 ;; handle C cmd at the eol and at eob.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1801 (if (or (and (eolp) (= vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1802 (= vip-com-point (point-max)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1803 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1804 (insert " ")(backward-char 1)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1805 (if (= vip-com-point (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1806 (vip-forward-char-carefully))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1807 (if (= com ?c)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1808 (vip-change vip-com-point (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1809 (vip-change-subr vip-com-point (point))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1810
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1811 ;; this is invoked by vip-substitute-line
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1812 (defun vip-exec-Change (m-com com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1813 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1814 (set-mark vip-com-point)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1815 (vip-enlarge-region (mark t) (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1816 (if vip-use-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1817 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1818 (cond ((vip-valid-register vip-use-register '(letter digit))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1819 ;;(vip-valid-register vip-use-register '(letter)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1820 (copy-to-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1821 vip-use-register (mark t) (point) nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1822 ((vip-valid-register vip-use-register '(Letter))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1823 (vip-append-to-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1824 (downcase vip-use-register) (mark t) (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1825 (t (setq vip-use-register nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1826 (error vip-InvalidRegister vip-use-register)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1827 (setq vip-use-register nil)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1828 (delete-region (mark t) (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1829 (open-line 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1830 (if (= com ?C) (vip-change-mode-to-insert) (vip-yank-last-insertion)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1831
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1832 (defun vip-exec-delete (m-com com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1833 (if vip-use-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1834 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1835 (cond ((vip-valid-register vip-use-register '(letter digit))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1836 ;;(vip-valid-register vip-use-register '(letter))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1837 (copy-to-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1838 vip-use-register vip-com-point (point) nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1839 ((vip-valid-register vip-use-register '(Letter))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1840 (vip-append-to-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1841 (downcase vip-use-register) vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1842 (t (setq vip-use-register nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1843 (error vip-InvalidRegister vip-use-register)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1844 (setq vip-use-register nil)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1845 (setq last-command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1846 (if (eq last-command 'd-command) 'kill-region nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1847 (kill-region vip-com-point (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1848 (setq this-command 'd-command)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1849 (if vip-ex-style-motion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1850 (if (and (eolp) (not (bolp))) (backward-char 1))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1851
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1852 (defun vip-exec-Delete (m-com com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1853 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1854 (set-mark vip-com-point)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1855 (vip-enlarge-region (mark t) (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1856 (if vip-use-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1857 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1858 (cond ((vip-valid-register vip-use-register '(letter digit))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1859 ;;(vip-valid-register vip-use-register '(letter))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1860 (copy-to-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1861 vip-use-register (mark t) (point) nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1862 ((vip-valid-register vip-use-register '(Letter))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1863 (vip-append-to-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1864 (downcase vip-use-register) (mark t) (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1865 (t (setq vip-use-register nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1866 (error vip-InvalidRegister vip-use-register)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1867 (setq vip-use-register nil)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1868 (setq last-command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1869 (if (eq last-command 'D-command) 'kill-region nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1870 (kill-region (mark t) (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1871 (if (eq m-com 'vip-line) (setq this-command 'D-command)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1872 (back-to-indentation))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1873
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1874 (defun vip-exec-yank (m-com com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1875 (if vip-use-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1876 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1877 (cond ((vip-valid-register vip-use-register '(letter digit))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1878 ;; (vip-valid-register vip-use-register '(letter))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1879 (copy-to-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1880 vip-use-register vip-com-point (point) nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1881 ((vip-valid-register vip-use-register '(Letter))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1882 (vip-append-to-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1883 (downcase vip-use-register) vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1884 (t (setq vip-use-register nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1885 (error vip-InvalidRegister vip-use-register)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1886 (setq vip-use-register nil)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1887 (setq last-command nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1888 (copy-region-as-kill vip-com-point (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1889 (goto-char vip-com-point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1890
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1891 (defun vip-exec-Yank (m-com com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1892 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1893 (set-mark vip-com-point)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1894 (vip-enlarge-region (mark t) (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1895 (if vip-use-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1896 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1897 (cond ((vip-valid-register vip-use-register '(letter digit))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1898 ;;(vip-valid-register vip-use-register '(letter))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1899 (copy-to-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1900 vip-use-register (mark t) (point) nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1901 ((vip-valid-register vip-use-register '(Letter))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1902 (vip-append-to-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1903 (downcase vip-use-register) (mark t) (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1904 (t (setq vip-use-register nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1905 (error vip-InvalidRegister vip-use-register)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1906 (setq vip-use-register nil)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1907 (setq last-command nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1908 (copy-region-as-kill (mark t) (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1909 (goto-char vip-com-point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1910
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1911 (defun vip-exec-bang (m-com com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1912 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1913 (set-mark vip-com-point)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1914 (vip-enlarge-region (mark t) (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1915 (shell-command-on-region
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1916 (mark t) (point)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1917 (if (= com ?!)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1918 (setq vip-last-shell-com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1919 (vip-read-string-with-history
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1920 "!"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1921 nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1922 'vip-shell-history
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1923 (car vip-shell-history)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1924 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1925 vip-last-shell-com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1926 t)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1927
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1928 (defun vip-exec-equals (m-com com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1929 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1930 (set-mark vip-com-point)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1931 (vip-enlarge-region (mark t) (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1932 (if (> (mark t) (point)) (exchange-point-and-mark))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1933 (indent-region (mark t) (point) nil)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1934
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1935 (defun vip-exec-shift (m-com com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1936 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1937 (set-mark vip-com-point)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1938 (vip-enlarge-region (mark t) (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1939 (if (> (mark t) (point)) (exchange-point-and-mark))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1940 (indent-rigidly (mark t) (point)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1941 (if (= com ?>)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1942 vip-shift-width
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1943 (- vip-shift-width))))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1944 ;; return point to where it was before shift
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
1945 (goto-char vip-com-point))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1946
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1947 ;; this is needed because some commands fake com by setting it to ?r, which
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1948 ;; denotes repeated insert command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1949 (defsubst vip-exec-dummy (m-com com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1950 nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1951
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1952 (defun vip-exec-buffer-search (m-com com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1953 (setq vip-s-string (buffer-substring (point) vip-com-point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1954 (setq vip-s-forward t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1955 (setq vip-search-history (cons vip-s-string vip-search-history))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1956 (vip-search vip-s-string vip-s-forward 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1957
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1958 (defvar vip-exec-array (make-vector 128 nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1959
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1960 ;; Using a dispatch array allows adding functions like buffer search
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1961 ;; without affecting other functions. Buffer search can now be bound
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1962 ;; to any character.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1963
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1964 (aset vip-exec-array ?c 'vip-exec-change)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1965 (aset vip-exec-array ?C 'vip-exec-Change)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1966 (aset vip-exec-array ?d 'vip-exec-delete)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1967 (aset vip-exec-array ?D 'vip-exec-Delete)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1968 (aset vip-exec-array ?y 'vip-exec-yank)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1969 (aset vip-exec-array ?Y 'vip-exec-Yank)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1970 (aset vip-exec-array ?r 'vip-exec-dummy)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1971 (aset vip-exec-array ?! 'vip-exec-bang)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1972 (aset vip-exec-array ?< 'vip-exec-shift)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1973 (aset vip-exec-array ?> 'vip-exec-shift)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1974 (aset vip-exec-array ?= 'vip-exec-equals)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1975
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1976
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1977
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1978 ;; This function is called by various movement commands to execute a
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1979 ;; destructive command on the region specified by the movement command. For
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1980 ;; instance, if the user types cw, then the command vip-forward-word will
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1981 ;; call vip-execute-com to execute vip-exec-change, which eventually will
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1982 ;; call vip-change to invoke the replace mode on the region.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1983 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1984 ;; The list (M-COM VAL COM REG INSETED-TEXT COMMAND-KEYS) is set to
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1985 ;; vip-d-com for later use by vip-repeat.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1986 (defun vip-execute-com (m-com val com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1987 (let ((reg vip-use-register))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1988 ;; this is the special command `#'
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1989 (if (> com 128)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1990 (vip-special-prefix-com (- com 128))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1991 (let ((fn (aref vip-exec-array (if (< com 0) (- com) com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1992 (if (null fn)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1993 (error "%c: %s" com vip-InvalidViCommand)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1994 (funcall fn m-com com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1995 (if (vip-dotable-command-p com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1996 (vip-set-destructive-command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1997 (list m-com val
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1998 (if (memq com (list ?c ?C ?!)) (- com) com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1999 reg nil nil)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2000 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2001
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2002
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2003 (defun vip-repeat (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2004 "Re-execute last destructive command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2005 Use the info in vip-d-com, which has the form
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2006 \(com val ch reg inserted-text command-keys\),
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2007 where `com' is the command to be re-executed, `val' is the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2008 argument to `com', `ch' is a flag for repeat, and `reg' is optional;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2009 if it exists, it is the name of the register for `com'.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2010 If the prefix argument, ARG, is non-nil, it is used instead of `val'."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2011 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2012 (let ((save-point (point)) ; save point before repeating prev cmd
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2013 ;; Pass along that we are repeating a destructive command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2014 ;; This tells vip-set-destructive-command not to update
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2015 ;; vip-command-ring
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2016 (vip-intermediate-command 'vip-repeat))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2017 (if (eq last-command 'vip-undo)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2018 ;; if the last command was vip-undo, then undo-more
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2019 (vip-undo-more)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2020 ;; otherwise execute the command stored in vip-d-com. if arg is non-nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2021 ;; its prefix value is used as new prefix value for the command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2022 (let ((m-com (car vip-d-com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2023 (val (vip-P-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2024 (com (nth 2 vip-d-com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2025 (reg (nth 3 vip-d-com)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2026 (if (null val) (setq val (nth 1 vip-d-com)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2027 (if (null m-com) (error "No previous command to repeat."))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2028 (setq vip-use-register reg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2029 (if (nth 4 vip-d-com) ; text inserted by command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2030 (setq vip-last-insertion (nth 4 vip-d-com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2031 vip-d-char (nth 4 vip-d-com)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2032 (funcall m-com (cons val com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2033 (if (and vip-keep-point-on-repeat (< save-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2034 (goto-char save-point)) ; go back to before repeat.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2035 (if (and (eolp) (not (bolp)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2036 (backward-char 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2037 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2038 (if vip-undo-needs-adjustment (vip-adjust-undo)) ; take care of undo
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2039 ;; If the prev cmd was rotating the command ring, this means that `.' has
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2040 ;; just executed a command from that ring. So, push it on the ring again.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2041 ;; If we are just executing previous command , then don't push vip-d-com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2042 ;; because vip-d-com is not fully constructed in this case (its keys and
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2043 ;; the inserted text may be nil). Besides, in this case, the command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2044 ;; executed by `.' is already on the ring.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2045 (if (eq last-command 'vip-display-current-destructive-command)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2046 (vip-push-onto-ring vip-d-com 'vip-command-ring))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2047 (vip-deactivate-mark)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2048 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2049
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2050 (defun vip-repeat-from-history ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2051 "Repeat a destructive command from history.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2052 Doesn't change vip-command-ring in any way, so `.' will work as before
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2053 executing this command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2054 This command is supposed to be bound to a two-character Vi macro where
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2055 the second character is a digit 0 to 9. The digit indicates which
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2056 history command to execute. `<char>0' is equivalent to `.', `<char>1'
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2057 invokes the command before that, etc."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2058 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2059 (let* ((vip-intermediate-command 'repeating-display-destructive-command)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2060 (idx (cond (vip-this-kbd-macro
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2061 (string-to-number
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2062 (symbol-name (elt vip-this-kbd-macro 1))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2063 (t 0)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2064 (num idx)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2065 (vip-d-com vip-d-com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2066
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2067 (or (and (numberp num) (<= 0 num) (<= num 9))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2068 (setq idx 0
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2069 num 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2070 (message
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2071 "`vip-repeat-from-history' must be invoked as a Vi macro bound to `<key><digit>'"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2072 (while (< 0 num)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2073 (setq vip-d-com (vip-special-ring-rotate1 vip-command-ring -1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2074 (setq num (1- num)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2075 (vip-repeat nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2076 (while (> idx num)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2077 (vip-special-ring-rotate1 vip-command-ring 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2078 (setq num (1+ num)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2079 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2080
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2081
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2082 ;; This command is invoked interactively by the key sequence #<char>
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2083 (defun vip-special-prefix-com (char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2084 (cond ((= char ?c)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2085 (downcase-region (min vip-com-point (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2086 (max vip-com-point (point))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2087 ((= char ?C)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2088 (upcase-region (min vip-com-point (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2089 (max vip-com-point (point))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2090 ((= char ?g)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2091 (push-mark vip-com-point t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2092 (vip-global-execute))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2093 ((= char ?q)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2094 (push-mark vip-com-point t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2095 (vip-quote-region))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2096 ((= char ?s) (funcall vip-spell-function vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2097 (t (error "#%c: %s" char vip-InvalidViCommand))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2098
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2099
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2100 ;; undoing
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2101
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2102 (defun vip-undo ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2103 "Undo previous change."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2104 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2105 (message "undo!")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2106 (let ((modified (buffer-modified-p))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2107 (before-undo-pt (point-marker))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2108 (after-change-functions after-change-functions)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2109 undo-beg-posn undo-end-posn)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2110
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2111 ;; no need to remove this hook, since this var has scope inside a let.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2112 (add-hook 'after-change-functions
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2113 '(lambda (beg end len)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2114 (setq undo-beg-posn beg
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2115 undo-end-posn (or end beg))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2116
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2117 (undo-start)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2118 (undo-more 2)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2119 (setq undo-beg-posn (or undo-beg-posn before-undo-pt)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2120 undo-end-posn (or undo-end-posn undo-beg-posn))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2121
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2122 (goto-char undo-beg-posn)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2123 (sit-for 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2124 (if (and vip-keep-point-on-undo
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2125 (pos-visible-in-window-p before-undo-pt))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2126 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2127 (push-mark (point-marker) t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2128 (vip-sit-for-short 300)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2129 (goto-char undo-end-posn)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2130 (vip-sit-for-short 300)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2131 (if (and (> (abs (- undo-beg-posn before-undo-pt)) 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2132 (> (abs (- undo-end-posn before-undo-pt)) 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2133 (goto-char before-undo-pt)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2134 (goto-char undo-beg-posn)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2135 (push-mark before-undo-pt t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2136 (if (and (eolp) (not (bolp))) (backward-char 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2137 (if (not modified) (set-buffer-modified-p t)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2138 (setq this-command 'vip-undo))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2139
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2140 ;; Continue undoing previous changes.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2141 (defun vip-undo-more ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2142 (message "undo more!")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2143 (condition-case nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2144 (undo-more 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2145 (error (beep)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2146 (message "No further undo information in this buffer")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2147 (if (and (eolp) (not (bolp))) (backward-char 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2148 (setq this-command 'vip-undo))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2149
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2150 ;; The following two functions are used to set up undo properly.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2151 ;; In VI, unlike Emacs, if you open a line, say, and add a bunch of lines,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2152 ;; they are undone all at once.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2153 (defun vip-adjust-undo ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2154 (let ((inhibit-quit t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2155 tmp tmp2)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2156 (setq vip-undo-needs-adjustment nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2157 (if (listp buffer-undo-list)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2158 (if (setq tmp (memq vip-buffer-undo-list-mark buffer-undo-list))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2159 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2160 (setq tmp2 (cdr tmp)) ; the part after mark
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2161
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2162 ;; cut tail from buffer-undo-list temporarily by direct
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2163 ;; manipulation with pointers in buffer-undo-list
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2164 (setcdr tmp nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2165
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2166 (setq buffer-undo-list (delq nil buffer-undo-list))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2167 (setq buffer-undo-list
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2168 (delq vip-buffer-undo-list-mark buffer-undo-list))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2169 ;; restore tail of buffer-undo-list
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2170 (setq buffer-undo-list (nconc buffer-undo-list tmp2)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2171 (setq buffer-undo-list (delq nil buffer-undo-list))))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2172
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2173
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2174 (defun vip-set-complex-command-for-undo ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2175 (if (listp buffer-undo-list)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2176 (if (not vip-undo-needs-adjustment)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2177 (let ((inhibit-quit t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2178 (setq buffer-undo-list
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2179 (cons vip-buffer-undo-list-mark buffer-undo-list))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2180 (setq vip-undo-needs-adjustment t)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2181
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2182
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2183
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2184
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2185 (defun vip-display-current-destructive-command ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2186 (let ((text (nth 4 vip-d-com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2187 (keys (nth 5 vip-d-com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2188 (max-text-len 30))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2189
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2190 (setq this-command 'vip-display-current-destructive-command)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2191
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2192 (message " `.' runs %s%s"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2193 (concat "`" (vip-array-to-string keys) "'")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2194 (vip-abbreviate-string text max-text-len
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2195 " inserting `" "'" " ......."))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2196 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2197
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2198
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2199 ;; don't change vip-d-com if it was vip-repeat command invoked with `.'
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2200 ;; or in some other way (non-interactively).
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2201 (defun vip-set-destructive-command (list)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2202 (or (eq vip-intermediate-command 'vip-repeat)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2203 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2204 (setq vip-d-com list)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2205 (setcar (nthcdr 5 vip-d-com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2206 (vip-array-to-string (this-command-keys)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2207 (vip-push-onto-ring vip-d-com 'vip-command-ring))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2208
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2209 (defun vip-prev-destructive-command (next)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2210 "Find previous destructive command in the history of destructive commands.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2211 With prefix argument, find next destructive command."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2212 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2213 (let (cmd vip-intermediate-command)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2214 (if (eq last-command 'vip-display-current-destructive-command)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2215 ;; repeated search through command history
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2216 (setq vip-intermediate-command 'repeating-display-destructive-command)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2217 ;; first search through command history--set temp ring
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2218 (setq vip-temp-command-ring (copy-list vip-command-ring)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2219 (setq cmd (if next
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2220 (vip-special-ring-rotate1 vip-temp-command-ring 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2221 (vip-special-ring-rotate1 vip-temp-command-ring -1)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2222 (if (null cmd)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2223 ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2224 (setq vip-d-com cmd))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2225 (vip-display-current-destructive-command)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2226
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2227 (defun vip-next-destructive-command ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2228 "Find next destructive command in the history of destructive commands."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2229 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2230 (vip-prev-destructive-command 'next))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2231
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2232 (defun vip-insert-prev-from-insertion-ring (arg)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2233 "Cycle through insertion ring in the direction of older insertions.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2234 Undoes previous insertion and inserts new.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2235 With prefix argument, cycles in the direction of newer elements.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2236 In minibuffer, this command executes whatever the invocation key is bound
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2237 to in the global map, instead of cycling through the insertion ring."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2238 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2239 (let (vip-intermediate-command)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2240 (if (eq last-command 'vip-insert-from-insertion-ring)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2241 (progn ; repeated search through insertion history
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2242 (setq vip-intermediate-command 'repeating-insertion-from-ring)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2243 (if (eq vip-current-state 'replace-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2244 (undo 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2245 (if vip-last-inserted-string-from-insertion-ring
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2246 (backward-delete-char
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2247 (length vip-last-inserted-string-from-insertion-ring))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2248 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2249 ;;first search through insertion history
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2250 (setq vip-temp-insertion-ring (copy-list vip-insertion-ring)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2251 (setq this-command 'vip-insert-from-insertion-ring)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2252 ;; so that things will be undone properly
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2253 (setq buffer-undo-list (cons nil buffer-undo-list))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2254 (setq vip-last-inserted-string-from-insertion-ring
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2255 (vip-special-ring-rotate1 vip-temp-insertion-ring (if arg 1 -1)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2256
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2257 ;; this change of vip-intermediate-command must come after
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2258 ;; vip-special-ring-rotate1, so that the ring will rotate, but before the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2259 ;; insertion.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2260 (setq vip-intermediate-command nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2261 (if vip-last-inserted-string-from-insertion-ring
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2262 (insert vip-last-inserted-string-from-insertion-ring))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2263 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2264
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2265 (defun vip-insert-next-from-insertion-ring ()
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2266 "Cycle through insertion ring in the direction of older insertions.
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2267 Undo previous insertion and inserts new."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2268 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2269 (vip-insert-prev-from-insertion-ring 'next))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2270
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2271
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2272 ;; some region utilities
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2273
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2274 ;; If at the last line of buffer, add \\n before eob, if newline is missing.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2275 (defun vip-add-newline-at-eob-if-necessary ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2276 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2277 (end-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2278 ;; make sure all lines end with newline, unless in the minibuffer or
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2279 ;; when requested otherwise (vip-add-newline-at-eob is nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2280 (if (and
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2281 (eobp)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2282 (not (bolp))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2283 vip-add-newline-at-eob
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2284 (not (vip-is-in-minibuffer)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2285 (insert "\n"))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2286
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2287 (defun vip-yank-defun ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2288 (mark-defun)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2289 (copy-region-as-kill (point) (mark t)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2290
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2291 ;; Enlarge region between BEG and END.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2292 (defun vip-enlarge-region (beg end)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2293 (or beg (setq beg end)) ; if beg is nil, set to end
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2294 (or end (setq end beg)) ; if end is nil, set to beg
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2295
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2296 (if (< beg end)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2297 (progn (goto-char beg) (set-mark end))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2298 (goto-char end)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2299 (set-mark beg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2300 (beginning-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2301 (exchange-point-and-mark)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2302 (if (or (not (eobp)) (not (bolp))) (forward-line 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2303 (if (not (eobp)) (beginning-of-line))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2304 (if (> beg end) (exchange-point-and-mark)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2305
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2306
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2307 ;; Quote region by each line with a user supplied string.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2308 (defun vip-quote-region ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2309 (setq vip-quote-string
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2310 (vip-read-string-with-history
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2311 "Quote string: "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2312 nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2313 'vip-quote-region-history
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2314 vip-quote-string))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2315 (vip-enlarge-region (point) (mark t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2316 (if (> (point) (mark t)) (exchange-point-and-mark))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2317 (insert vip-quote-string)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2318 (beginning-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2319 (forward-line 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2320 (while (and (< (point) (mark t)) (bolp))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2321 (insert vip-quote-string)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2322 (beginning-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2323 (forward-line 1)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2324
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2325 ;; Tells whether BEG is on the same line as END.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2326 ;; If one of the args is nil, it'll return nil.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2327 (defun vip-same-line (beg end)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2328 (let ((selective-display nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2329 (cond ((and beg end)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2330 ;; This 'if' is needed because Emacs treats the next empty line
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2331 ;; as part of the previous line.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2332 (if (or (> beg (point-max)) (> end (point-max))) ; out of range
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2333 ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2334 (if (and (> end beg) (= (vip-line-pos 'start) end))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2335 (setq end (min (1+ end) (point-max))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2336 (if (and (> beg end) (= (vip-line-pos 'start) beg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2337 (setq beg (min (1+ beg) (point-max))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2338 (<= (count-lines beg end) 1) ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2339
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2340 (t nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2341 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2342
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2343
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2344 ;; Check if the string ends with a newline.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2345 (defun vip-end-with-a-newline-p (string)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2346 (or (string= string "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2347 (= (vip-seq-last-elt string) ?\n)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2348
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2349 (defun vip-tmp-insert-at-eob (msg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2350 (let ((savemax (point-max)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2351 (goto-char savemax)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2352 (insert msg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2353 (sit-for 2)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2354 (goto-char savemax) (delete-region (point) (point-max))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2355 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2356
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2357
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2358
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2359 ;;; Minibuffer business
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2360
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2361 (defsubst vip-set-minibuffer-style ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2362 (add-hook 'minibuffer-setup-hook 'vip-minibuffer-setup-sentinel))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2363
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2364
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2365 (defun vip-minibuffer-setup-sentinel ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2366 (let ((hook (if vip-vi-style-in-minibuffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2367 'vip-change-state-to-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2368 'vip-change-state-to-emacs)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2369 (funcall hook)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2370
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2371 ;; Make sure the minibufer overlay is kept up-to-date. In XEmacs also
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2372 ;; guards against the possibility of detaching this overlay.
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2373 (vip-add-hook 'vip-post-command-hooks 'vip-move-minibuffer-overlay)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2374 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2375
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2376 ;; Interpret last event in the local map
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2377 (defun vip-exit-minibuffer ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2378 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2379 (let (command)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2380 (setq command (local-key-binding (char-to-string last-command-char)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2381 (if command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2382 (command-execute command)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2383 (exit-minibuffer))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2384
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2385
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2386 (defun vip-set-search-face ()
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2387 (if (not (vip-window-display-p))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2388 ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2389 (defvar vip-search-face
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2390 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2391 (make-face 'vip-search-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2392 (or (face-differs-from-default-p 'vip-search-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2393 ;; face wasn't set in .vip or .Xdefaults
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2394 (if (vip-can-use-colors "Black" "khaki")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2395 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2396 (set-face-background 'vip-search-face "khaki")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2397 (set-face-foreground 'vip-search-face "Black"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2398 (copy-face 'italic 'vip-search-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2399 (set-face-underline-p 'vip-search-face t)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2400 'vip-search-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2401 "*Face used to flash out the search pattern.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2402 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2403
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2404
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2405 (defun vip-set-minibuffer-faces ()
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2406 (if (not (vip-window-display-p))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2407 ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2408 (defvar vip-minibuffer-emacs-face
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2409 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2410 (make-face 'vip-minibuffer-emacs-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2411 (or (face-differs-from-default-p 'vip-minibuffer-emacs-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2412 ;; face wasn't set in .vip or .Xdefaults
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2413 (if vip-vi-style-in-minibuffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2414 ;; emacs state is an exception in the minibuffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2415 (if (vip-can-use-colors "darkseagreen2" "Black")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2416 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2417 (set-face-background
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2418 'vip-minibuffer-emacs-face "darkseagreen2")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2419 (set-face-foreground
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2420 'vip-minibuffer-emacs-face "Black"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2421 (copy-face 'highlight 'vip-minibuffer-emacs-face))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2422 ;; emacs state is the main state in the minibuffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2423 (if (vip-can-use-colors "Black" "pink")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2424 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2425 (set-face-background 'vip-minibuffer-emacs-face "pink")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2426 (set-face-foreground
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2427 'vip-minibuffer-emacs-face "Black"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2428 (copy-face 'italic 'vip-minibuffer-emacs-face))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2429 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2430 'vip-minibuffer-emacs-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2431 "Face used in the Minibuffer when it is in Emacs state.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2432
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2433 (defvar vip-minibuffer-insert-face
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2434 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2435 (make-face 'vip-minibuffer-insert-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2436 (or (face-differs-from-default-p 'vip-minibuffer-insert-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2437 (if vip-vi-style-in-minibuffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2438 (if (vip-can-use-colors "Black" "pink")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2439 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2440 (set-face-background 'vip-minibuffer-insert-face "pink")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2441 (set-face-foreground
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2442 'vip-minibuffer-insert-face "Black"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2443 (copy-face 'italic 'vip-minibuffer-insert-face))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2444 ;; If Insert state is an exception
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2445 (if (vip-can-use-colors "darkseagreen2" "Black")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2446 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2447 (set-face-background
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2448 'vip-minibuffer-insert-face "darkseagreen2")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2449 (set-face-foreground
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2450 'vip-minibuffer-insert-face "Black"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2451 (copy-face 'highlight 'vip-minibuffer-insert-face))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2452 (vip-italicize-face 'vip-minibuffer-insert-face)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2453 'vip-minibuffer-insert-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2454 "Face used in the Minibuffer when it is in Insert state.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2455
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2456 (defvar vip-minibuffer-vi-face
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2457 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2458 (make-face 'vip-minibuffer-vi-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2459 (or (face-differs-from-default-p 'vip-minibuffer-vi-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2460 (if vip-vi-style-in-minibuffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2461 (if (vip-can-use-colors "Black" "grey")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2462 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2463 (set-face-background 'vip-minibuffer-vi-face "grey")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2464 (set-face-foreground 'vip-minibuffer-vi-face "Black"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2465 (copy-face 'bold 'vip-minibuffer-vi-face))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2466 (copy-face 'bold 'vip-minibuffer-vi-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2467 (invert-face 'vip-minibuffer-vi-face)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2468 'vip-minibuffer-vi-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2469 "Face used in the Minibuffer when it is in Vi state.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2470
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2471 ;; the current face used in the minibuffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2472 (vip-deflocalvar vip-minibuffer-current-face vip-minibuffer-emacs-face "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2473 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2474
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2475
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2476
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2477 ;;; Reading string with history
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2478
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2479 (defun vip-read-string-with-history (prompt &optional initial
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2480 history-var default keymap)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2481 ;; Reads string, prompting with PROMPT and inserting the INITIAL
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2482 ;; value. Uses HISTORY-VAR. DEFAULT is the default value to accept if the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2483 ;; input is an empty string. Uses KEYMAP, if given, or the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2484 ;; minibuffer-local-map.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2485 ;; Default value is displayed until the user types something in the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2486 ;; minibuffer.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2487 (let ((minibuffer-setup-hook
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2488 '(lambda ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2489 (if (stringp initial)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2490 (progn
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
2491 ;; don't wait if we have unread events
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
2492 (or unread-command-events
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
2493 (sit-for 840))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2494 (erase-buffer)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2495 (insert initial)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2496 (vip-minibuffer-setup-sentinel)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2497 (val "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2498 (padding "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2499 temp-msg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2500
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2501 (setq keymap (or keymap minibuffer-local-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2502 initial (or initial "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2503 temp-msg (if default
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2504 (format "(default: %s) " default)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2505 ""))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2506
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2507 (setq vip-incomplete-ex-cmd nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2508 (setq val (read-from-minibuffer prompt
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2509 (concat temp-msg initial val padding)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2510 keymap nil history-var))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2511 (setq minibuffer-setup-hook nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2512 padding (vip-array-to-string (this-command-keys))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2513 temp-msg "")
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2514 ;; the following tries to be smart about what to put in history
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2515 (if (not (string= val (car (eval history-var))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2516 (set history-var (cons val (eval history-var))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2517 (if (or (string= (nth 0 (eval history-var)) (nth 1 (eval history-var)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2518 (string= (nth 0 (eval history-var)) ""))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2519 (set history-var (cdr (eval history-var))))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2520 ;; if the user enters nothing but the prev cmd wasn't vip-ex or
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2521 ;; vip-command-argument, this means that the user typed something then
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2522 ;; erased. Return "" in this case, not the default---default is too
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2523 ;; confusing in this case
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2524 (cond ((and (string= val "")
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2525 (not (memq last-command
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2526 (list 'vip-ex 'vip-command-argument t))))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2527 "")
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2528 ((string= val "") (or default ""))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2529 (t val))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2530 ))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2531
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2532
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2533
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2534 ;; insertion commands
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2535
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2536 ;; Called when state changes from Insert Vi command mode.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2537 ;; Repeats the insertion command if Insert state was entered with prefix
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2538 ;; argument > 1.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2539 (defun vip-repeat-insert-command ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2540 (let ((i-com (car vip-d-com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2541 (val (nth 1 vip-d-com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2542 (char (nth 2 vip-d-com)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2543 (if (and val (> val 1)) ; first check that val is non-nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2544 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2545 (setq vip-d-com (list i-com (1- val) ?r nil nil nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2546 (vip-repeat nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2547 (setq vip-d-com (list i-com val char nil nil nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2548 ))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2549
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2550 (defun vip-insert (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2551 "Insert before point."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2552 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2553 (vip-set-complex-command-for-undo)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2554 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2555 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2556 (vip-set-destructive-command (list 'vip-insert val ?r nil nil nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2557 (if com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2558 (vip-loop val (vip-yank-last-insertion))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2559 (vip-change-state-to-insert))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2560
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2561 (defun vip-append (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2562 "Append after point."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2563 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2564 (vip-set-complex-command-for-undo)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2565 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2566 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2567 (vip-set-destructive-command (list 'vip-append val ?r nil nil nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2568 (if (not (eolp)) (forward-char))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2569 (if (equal com ?r)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2570 (vip-loop val (vip-yank-last-insertion))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2571 (vip-change-state-to-insert))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2572
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2573 (defun vip-Append (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2574 "Append at end of line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2575 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2576 (vip-set-complex-command-for-undo)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2577 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2578 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2579 (vip-set-destructive-command (list 'vip-Append val ?r nil nil nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2580 (end-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2581 (if (equal com ?r)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2582 (vip-loop val (vip-yank-last-insertion))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2583 (vip-change-state-to-insert))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2584
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2585 (defun vip-Insert (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2586 "Insert before first non-white."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2587 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2588 (vip-set-complex-command-for-undo)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2589 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2590 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2591 (vip-set-destructive-command (list 'vip-Insert val ?r nil nil nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2592 (back-to-indentation)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2593 (if (equal com ?r)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2594 (vip-loop val (vip-yank-last-insertion))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2595 (vip-change-state-to-insert))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2596
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2597 (defun vip-open-line (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2598 "Open line below."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2599 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2600 (vip-set-complex-command-for-undo)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2601 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2602 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2603 (vip-set-destructive-command (list 'vip-open-line val ?r nil nil nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2604 (let ((col (current-indentation)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2605 (if (equal com ?r)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2606 (vip-loop val
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2607 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2608 (end-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2609 (newline 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2610 (if vip-auto-indent
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2611 (progn (setq vip-cted t) (indent-to col)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2612 (vip-yank-last-insertion)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2613 (end-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2614 (newline 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2615 (if vip-auto-indent (progn (setq vip-cted t) (indent-to col)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2616 (vip-change-state-to-insert)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2617 ))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2618
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2619 (defun vip-Open-line (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2620 "Open line above."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2621 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2622 (vip-set-complex-command-for-undo)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2623 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2624 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2625 (vip-set-destructive-command (list 'vip-Open-line val ?r nil nil nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2626 (let ((col (current-indentation)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2627 (if (equal com ?r)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2628 (vip-loop val
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2629 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2630 (beginning-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2631 (open-line 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2632 (if vip-auto-indent
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2633 (progn (setq vip-cted t) (indent-to col)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2634 (vip-yank-last-insertion)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2635 (beginning-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2636 (open-line 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2637 (if vip-auto-indent (progn (setq vip-cted t) (indent-to col)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2638 (vip-change-state-to-insert)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2639
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2640 (defun vip-open-line-at-point (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2641 "Open line at point."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2642 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2643 (vip-set-complex-command-for-undo)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2644 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2645 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2646 (vip-set-destructive-command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2647 (list 'vip-open-line-at-point val ?r nil nil nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2648 (if (equal com ?r)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2649 (vip-loop val
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2650 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2651 (open-line 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2652 (vip-yank-last-insertion)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2653 (open-line 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2654 (vip-change-state-to-insert))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2655
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2656 (defun vip-substitute (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2657 "Substitute characters."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2658 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2659 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2660 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2661 (push-mark nil t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2662 (forward-char val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2663 (if (equal com ?r)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2664 (vip-change-subr (mark t) (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2665 (vip-change (mark t) (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2666 (vip-set-destructive-command (list 'vip-substitute val ?r nil nil nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2667 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2668
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2669 (defun vip-substitute-line (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2670 "Substitute lines."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2671 (interactive "p")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2672 (vip-set-complex-command-for-undo)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2673 (vip-line (cons arg ?C)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2674
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2675 ;; Prepare for replace
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2676 (defun vip-start-replace ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2677 (setq vip-began-as-replace t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2678 vip-sitting-in-replace t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2679 vip-replace-chars-to-delete 0
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2680 vip-replace-chars-deleted 0)
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2681 (vip-add-hook 'vip-after-change-functions 'vip-replace-mode-spy-after t)
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2682 (vip-add-hook 'vip-before-change-functions 'vip-replace-mode-spy-before t)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2683 ;; this will get added repeatedly, but no harm
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2684 (add-hook 'after-change-functions 'vip-after-change-sentinel t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2685 (add-hook 'before-change-functions 'vip-before-change-sentinel t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2686 (vip-move-marker-locally 'vip-last-posn-in-replace-region
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2687 (vip-replace-start))
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2688 (vip-add-hook
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2689 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel t)
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2690 (vip-add-hook
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2691 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2692 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2693
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2694 ;; Runs vip-after-change-functions inside after-change-functions
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2695 (defun vip-after-change-sentinel (beg end len)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2696 (let ((list vip-after-change-functions))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2697 (while list
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2698 (funcall (car list) beg end len)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2699 (setq list (cdr list)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2700
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2701 ;; Runs vip-before-change-functions inside before-change-functions
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2702 (defun vip-before-change-sentinel (beg end)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2703 (let ((list vip-before-change-functions))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2704 (while list
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2705 (funcall (car list) beg end)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2706 (setq list (cdr list)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2707
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2708 (defsubst vip-post-command-sentinel ()
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2709 (run-hooks 'vip-post-command-hooks))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2710
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2711 (defsubst vip-pre-command-sentinel ()
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2712 (run-hooks 'vip-pre-command-hooks))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2713
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2714 ;; Needed so that Viper will be able to figure the last inserted
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2715 ;; chunk of text with reasonable accuracy.
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2716 (defsubst vip-insert-state-post-command-sentinel ()
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2717 (if (and (memq vip-current-state '(insert-state replace-state))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2718 vip-insert-point
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2719 (>= (point) vip-insert-point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2720 (setq vip-last-posn-while-in-insert-state (point-marker)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2721 (if (and (eq this-command 'dabbrev-expand)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2722 (integerp vip-pre-command-point)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2723 (> vip-insert-point vip-pre-command-point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2724 (move-marker vip-insert-point vip-pre-command-point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2725 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2726
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2727 (defsubst vip-insert-state-pre-command-sentinel ()
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2728 (if (and (eq this-command 'dabbrev-expand)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2729 (markerp vip-insert-point)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2730 (marker-position vip-insert-point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2731 (setq vip-pre-command-point (marker-position vip-insert-point))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2732
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2733 (defsubst vip-R-state-post-command-sentinel ()
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2734 ;; Restoring cursor color is needed despite
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2735 ;; vip-replace-state-pre-command-sentinel: When you jump to another buffer in
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2736 ;; another frame, the pre-command hook won't change cursor color to default
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2737 ;; in that other frame. So, if the second frame cursor was red and we set
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2738 ;; the point outside the replacement region, then the cursor color will
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2739 ;; remain red. Restoring the default, below, prevents this.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2740 (if (and (<= (vip-replace-start) (point))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2741 (<= (point) (vip-replace-end)))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2742 (vip-change-cursor-color vip-replace-overlay-cursor-color)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2743 (vip-restore-cursor-color)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2744 ))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2745
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2746 ;; to speed up, don't change cursor color before self-insert
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2747 ;; and common move commands
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2748 (defsubst vip-replace-state-pre-command-sentinel ()
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2749 (or (memq this-command '(self-insert-command))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2750 (memq (vip-event-key last-command-event)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2751 '(up down left right (meta f) (meta b)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2752 (control n) (control p) (control f) (control b)))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2753 (vip-restore-cursor-color)))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2754
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2755 (defun vip-replace-state-post-command-sentinel ()
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2756 ;; Restoring cursor color is needed despite
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2757 ;; vip-replace-state-pre-command-sentinel: When one jumps to another buffer
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2758 ;; in another frame, the pre-command hook won't change cursor color to
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2759 ;; default in that other frame. So, if the second frame cursor was red and
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2760 ;; we set the point outside the replacement region, then the cursor color
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2761 ;; will remain red. Restoring the default, below, fixes this problem.
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2762 ;;
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2763 ;; We optimize for self-insert-command's here, since they either don't change
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2764 ;; cursor color or, if they terminate replace mode, the color will be changed
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2765 ;; in vip-finish-change
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2766 (or (memq this-command '(self-insert-command))
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2767 (vip-restore-cursor-color))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2768 (cond
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2769 ((eq vip-current-state 'replace-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2770 ;; delete characters to compensate for inserted chars.
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2771 (let ((replace-boundary (vip-replace-end)))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2772 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2773 (goto-char vip-last-posn-in-replace-region)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2774 (delete-char vip-replace-chars-to-delete)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2775 (setq vip-replace-chars-to-delete 0
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2776 vip-replace-chars-deleted 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2777 ;; terminate replace mode if reached replace limit
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2778 (if (= vip-last-posn-in-replace-region
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2779 (vip-replace-end))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2780 (vip-finish-change vip-last-posn-in-replace-region)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2781
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2782 (if (and (<= (vip-replace-start) (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2783 (<= (point) replace-boundary))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2784 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2785 ;; the state may have changed in vip-finish-change above
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2786 (if (eq vip-current-state 'replace-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2787 (vip-change-cursor-color vip-replace-overlay-cursor-color))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2788 (setq vip-last-posn-in-replace-region (point-marker))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2789 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2790
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2791 (t ;; terminate replace mode if changed Viper states.
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2792 (vip-finish-change vip-last-posn-in-replace-region))))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2793
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2794
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2795 ;; checks how many chars were deleted by the last change
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2796 (defun vip-replace-mode-spy-before (beg end)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2797 (setq vip-replace-chars-deleted
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2798 (- end beg
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2799 (max 0 (- end (vip-replace-end)))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2800 (max 0 (- (vip-replace-start) beg))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2801 )))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2802
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2803 ;; Invoked as an after-change-function to set up parameters of the last change
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2804 (defun vip-replace-mode-spy-after (beg end length)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2805 (if (memq vip-intermediate-command '(repeating-insertion-from-ring))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2806 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2807 (setq vip-replace-chars-to-delete 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2808 (vip-move-marker-locally
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2809 'vip-last-posn-in-replace-region (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2810
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2811 (let (beg-col end-col real-end chars-to-delete)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2812 (setq real-end (min end (vip-replace-end)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2813 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2814 (goto-char beg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2815 (setq beg-col (current-column))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2816 (goto-char real-end)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2817 (setq end-col (current-column)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2818
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2819 ;; If beg of change is outside the replacement region, then don't
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2820 ;; delete anything in the repl region (set chars-to-delete to 0).
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2821 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2822 ;; This works fine except that we have to take special care of
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2823 ;; dabbrev-expand. The problem stems from new-dabbrev.el, which
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2824 ;; sometimes simply shifts the repl region rightwards, without
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2825 ;; deleting an equal amount of characters.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2826 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2827 ;; The reason why new-dabbrev.el causes this are this:
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2828 ;; if one dinamically completes a partial word that starts before the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2829 ;; replacement region (but ends inside)then new-dabbrev.el first
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2830 ;; moves cursor backwards, to the beginning of the word to be
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2831 ;; completed (say, pt A). Then it inserts the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2832 ;; completed word and then deletes the old, incomplete part.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2833 ;; Since the complete word is inserted at position before the repl
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2834 ;; region, the next If-statement would have set chars-to-delete to 0
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2835 ;; unless we check for the current command, which must be
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2836 ;; dabbrev-expand.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2837 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2838 ;; We should be able deal with these problems in a better way
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2839 ;; when emacs will have overlays with sticky back ends.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2840 ;; In fact, it would be also useful to add overlays for insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2841 ;; regions as well, since this will let us capture the situation when
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2842 ;; dabbrev-expand goes back past the insertion point to find the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2843 ;; beginning of the word to be expanded.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2844 (if (or (and (<= (vip-replace-start) beg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2845 (<= beg (vip-replace-end)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2846 (and (= length 0) (eq this-command 'dabbrev-expand)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2847 (setq chars-to-delete
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2848 (max (- end-col beg-col) (- real-end beg) 0))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2849 (setq chars-to-delete 0))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2850
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2851 ;; if beg = last change position, it means that we are within the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2852 ;; same command that does multiple changes. Moreover, it means
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2853 ;; that we have two subsequent changes (insert/delete) that
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2854 ;; complement each other.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2855 (if (= beg (marker-position vip-last-posn-in-replace-region))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2856 (setq vip-replace-chars-to-delete
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2857 (- (+ chars-to-delete vip-replace-chars-to-delete)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2858 vip-replace-chars-deleted))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2859 (setq vip-replace-chars-to-delete chars-to-delete))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2860
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2861 (vip-move-marker-locally
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2862 'vip-last-posn-in-replace-region
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2863 (max (if (> end (vip-replace-end)) (vip-replace-start) end)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2864 (or (marker-position vip-last-posn-in-replace-region)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2865 (vip-replace-start))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2866 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2867
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2868 (setq vip-replace-chars-to-delete
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2869 (max 0 (min vip-replace-chars-to-delete
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2870 (- (vip-replace-end)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2871 vip-last-posn-in-replace-region))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2872 )))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2873
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2874
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2875 ;; Delete stuff between posn and the end of vip-replace-overlay-marker, if
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2876 ;; posn is within the overlay.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2877 (defun vip-finish-change (posn)
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2878 (vip-remove-hook 'vip-after-change-functions 'vip-replace-mode-spy-after)
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2879 (vip-remove-hook 'vip-before-change-functions 'vip-replace-mode-spy-before)
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2880 (vip-remove-hook 'vip-post-command-hooks
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2881 'vip-replace-state-post-command-sentinel)
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2882 (vip-remove-hook
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2883 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2884 (vip-restore-cursor-color)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2885 (setq vip-sitting-in-replace nil) ; just in case we'll need to know it
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2886 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2887 (if (and
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2888 vip-replace-overlay
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2889 (>= posn (vip-replace-start))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2890 (< posn (vip-replace-end)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2891 (delete-region posn (vip-replace-end)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2892 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2893
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2894 (if (eq vip-current-state 'replace-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2895 (vip-downgrade-to-insert))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2896 ;; replace mode ended => nullify vip-last-posn-in-replace-region
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2897 (vip-move-marker-locally 'vip-last-posn-in-replace-region nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2898 (vip-hide-replace-overlay)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2899 (vip-refresh-mode-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2900 (vip-put-string-on-kill-ring vip-last-replace-region)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2901 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2902
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2903 ;; Make STRING be the first element of the kill ring.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2904 (defun vip-put-string-on-kill-ring (string)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2905 (setq kill-ring (cons string kill-ring))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2906 (if (> (length kill-ring) kill-ring-max)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2907 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2908 (setq kill-ring-yank-pointer kill-ring))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2909
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2910 (defun vip-finish-R-mode ()
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2911 (vip-remove-hook 'vip-post-command-hooks 'vip-R-state-post-command-sentinel)
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2912 (vip-remove-hook
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2913 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2914 (vip-downgrade-to-insert))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2915
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2916 (defun vip-start-R-mode ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2917 ;; Leave arg as 1, not t: XEmacs insists that it must be a pos number
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2918 (overwrite-mode 1)
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2919 (vip-add-hook
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2920 'vip-post-command-hooks 'vip-R-state-post-command-sentinel t)
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2921 (vip-add-hook
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
2922 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2923 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2924
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2925
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2926
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2927 (defun vip-replace-state-exit-cmd ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2928 "Binding for keys that cause Replace state to switch to Vi or to Insert.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2929 These keys are ESC, RET, and LineFeed"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2930 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2931 (if overwrite-mode ;; If you are in replace mode invoked via 'R'
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2932 (vip-finish-R-mode)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2933 (vip-finish-change vip-last-posn-in-replace-region))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2934 (let (com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2935 (if (eq this-command 'vip-intercept-ESC-key)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2936 (setq com 'vip-exit-insert-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2937 (vip-set-unread-command-events last-input-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2938 (setq com (key-binding (read-key-sequence nil))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2939
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2940 (condition-case conds
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2941 (command-execute com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2942 (error
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2943 (vip-message-conditions conds)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2944 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2945 (vip-hide-replace-overlay))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2946
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2947
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2948 ;; This is the function bound to 'R'---unlimited replace.
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2949 ;; Similar to Emacs's own overwrite-mode.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2950 (defun vip-overwrite (arg)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2951 "Begin overwrite mode."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2952 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2953 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2954 (com (vip-getcom arg)) (len))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2955 (vip-set-destructive-command (list 'vip-overwrite val ?r nil nil nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2956 (if com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2957 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2958 ;; Viper saves inserted text in vip-last-insertion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2959 (setq len (length vip-last-insertion))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2960 (delete-char len)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2961 (vip-loop val (vip-yank-last-insertion)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2962 (setq last-command 'vip-overwrite)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2963 (vip-set-complex-command-for-undo)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2964 (vip-set-replace-overlay (point) (vip-line-pos 'end))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2965 (vip-change-state-to-replace)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2966 )))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2967
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2968
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2969 ;; line commands
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2970
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2971 (defun vip-line (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2972 (let ((val (car arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2973 (com (cdr arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2974 (vip-move-marker-locally 'vip-com-point (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2975 (if (not (eobp))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2976 (vip-next-line-carefully (1- val)))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2977 ;; this ensures that dd, cc, D, yy will do the right thing on the last
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2978 ;; line of buffer when this line has no \n.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2979 (vip-add-newline-at-eob-if-necessary)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2980 (vip-execute-com 'vip-line val com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2981 (if (and (eobp) (not (bobp))) (forward-line -1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2982 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2983
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2984 (defun vip-yank-line (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2985 "Yank ARG lines (in Vi's sense)."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2986 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2987 (let ((val (vip-p-val arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2988 (vip-line (cons val ?Y))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2989
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2990
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2991 ;; region commands
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2992
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2993 (defun vip-region (arg)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
2994 "Execute command on a region."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2995 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2996 (let ((val (vip-P-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2997 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2998 (vip-move-marker-locally 'vip-com-point (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2999 (exchange-point-and-mark)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3000 (vip-execute-com 'vip-region val com)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3001
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3002 (defun vip-Region (arg)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3003 "Execute command on a Region."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3004 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3005 (let ((val (vip-P-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3006 (com (vip-getCom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3007 (vip-move-marker-locally 'vip-com-point (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3008 (exchange-point-and-mark)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3009 (vip-execute-com 'vip-Region val com)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3010
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3011 (defun vip-replace-char (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3012 "Replace the following ARG chars by the character read."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3013 (interactive "P")
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
3014 (if (and (eolp) (bolp)) (error "No character to replace here"))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3015 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3016 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3017 (vip-replace-char-subr (if (equal com ?r) vip-d-char (read-char)) val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3018 (if (and (eolp) (not (bolp))) (forward-char 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3019 (vip-set-destructive-command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3020 (list 'vip-replace-char val ?r nil vip-d-char nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3021 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3022
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3023 (defun vip-replace-char-subr (char arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3024 (delete-char arg t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3025 (setq vip-d-char char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3026 (vip-loop (if (> arg 0) arg (- arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3027 (if (eq char ?\C-m) (insert "\n") (insert char)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3028 (backward-char arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3029
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3030
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3031 ;; basic cursor movement. j, k, l, h commands.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3032
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3033 (defun vip-forward-char (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3034 "Move point right ARG characters (left if ARG negative).
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3035 On reaching end of line, stop and signal error."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3036 (interactive "P")
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
3037 (vip-leave-region-active)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3038 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3039 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3040 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3041 (if vip-ex-style-motion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3042 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3043 ;; the boundary condition check gets weird here because
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3044 ;; forward-char may be the parameter of a delete, and 'dl' works
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3045 ;; just like 'x' for the last char on a line, so we have to allow
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3046 ;; the forward motion before the 'vip-execute-com', but, of
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3047 ;; course, 'dl' doesn't work on an empty line, so we have to
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3048 ;; catch that condition before 'vip-execute-com'
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3049 (if (and (eolp) (bolp)) (error "") (forward-char val))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3050 (if com (vip-execute-com 'vip-forward-char val com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3051 (if (eolp) (progn (backward-char 1) (error ""))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3052 (forward-char val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3053 (if com (vip-execute-com 'vip-forward-char val com)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3054
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3055 (defun vip-backward-char (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3056 "Move point left ARG characters (right if ARG negative).
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3057 On reaching beginning of line, stop and signal error."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3058 (interactive "P")
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
3059 (vip-leave-region-active)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3060 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3061 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3062 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3063 (if vip-ex-style-motion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3064 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3065 (if (bolp) (error "") (backward-char val))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3066 (if com (vip-execute-com 'vip-backward-char val com)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3067 (backward-char val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3068 (if com (vip-execute-com 'vip-backward-char val com)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3069
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3070 ;; Like forward-char, but doesn't move at end of buffer.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3071 (defun vip-forward-char-carefully (&optional arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3072 (setq arg (or arg 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3073 (if (>= (point-max) (+ (point) arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3074 (forward-char arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3075 (goto-char (point-max))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3076
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3077 ;; Like backward-char, but doesn't move at end of buffer.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3078 (defun vip-backward-char-carefully (&optional arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3079 (setq arg (or arg 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3080 (if (<= (point-min) (- (point) arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3081 (backward-char arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3082 (goto-char (point-min))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3083
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3084 (defun vip-next-line-carefully (arg)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3085 (condition-case nil
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3086 (next-line arg)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3087 (error nil)))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3088
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3089
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3090
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3091 ;;; Word command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3092
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3093 ;; Words are formed from alpha's and nonalphas - <sp>,\t\n are separators
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3094 ;; for word movement. When executed with a destructive command, \n is
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3095 ;; usually left untouched for the last word.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3096
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3097 ;; skip only one \n
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3098 (defun vip-skip-separators (forward)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3099 (if forward
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3100 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3101 (skip-chars-forward " \t")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3102 (if (looking-at "\n")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3103 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3104 (forward-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3105 (skip-chars-forward " \t"))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3106 (skip-chars-backward " \t")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3107 (backward-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3108 (if (looking-at "\n")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3109 (skip-chars-backward " \t")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3110 (forward-char))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3111
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3112 (defconst vip-ALPHA "a-zA-Z0-9_")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3113 (defconst vip-ALPHA-B (concat "[" vip-ALPHA "]"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3114 (defconst vip-NONALPHA (concat "^" vip-ALPHA))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3115 (defconst vip-NONALPHA-B (concat "[" vip-NONALPHA "]"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3116 (defconst vip-SEP " \t\n")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3117 (defconst vip-SEP-B (concat "[" vip-SEP "]"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3118 (defconst vip-NONSEP (concat "^" vip-SEP))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3119 (defconst vip-NONSEP-B (concat "[" vip-NONSEP "]"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3120 (defconst vip-ALPHASEP (concat vip-ALPHA vip-SEP))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3121 (defconst vip-ALPHASEP-B (concat "[" vip-ALPHASEP "]"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3122 (defconst vip-NONALPHASEP (concat "^" vip-ALPHASEP ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3123 (defconst vip-NONALPHASEP-B (concat "[" vip-NONALPHASEP "]"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3124
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3125
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3126 (defun vip-forward-word-kernel (val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3127 (while (> val 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3128 (cond ((looking-at vip-ALPHA-B)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3129 (skip-chars-forward vip-ALPHA)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3130 (vip-skip-separators t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3131 ((looking-at vip-SEP-B)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3132 (vip-skip-separators t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3133 ((looking-at vip-NONALPHASEP-B)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3134 (skip-chars-forward vip-NONALPHASEP)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3135 (vip-skip-separators t)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3136 (setq val (1- val))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3137
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3138 ;; first search backward for pat. Then skip chars backwards using aux-pat
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3139 (defun vip-fwd-skip (pat aux-pat lim)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3140 (if (and (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3141 (re-search-backward pat lim t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3142 (= (point) (match-end 0)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3143 (goto-char (match-beginning 0)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3144 (skip-chars-backward aux-pat lim)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3145 (if (= (point) lim)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3146 (vip-forward-char-carefully))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3147 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3148
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3149
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3150 (defun vip-forward-word (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3151 "Forward word."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3152 (interactive "P")
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
3153 (vip-leave-region-active)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3154 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3155 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3156 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3157 (vip-forward-word-kernel val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3158 (if com (progn
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3159 (cond ((memq com (list ?c (- ?c)))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3160 (vip-fwd-skip "\n[ \t]*" " \t" vip-com-point))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3161 ;; Yank words including the whitespace, but not newline
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3162 ((memq com (list ?y (- ?y)))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3163 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3164 ((vip-dotable-command-p com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3165 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3166 (vip-execute-com 'vip-forward-word val com)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3167
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3168
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3169 (defun vip-forward-Word (arg)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3170 "Forward word delimited by white characters."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3171 (interactive "P")
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
3172 (vip-leave-region-active)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3173 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3174 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3175 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3176 (vip-loop val
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3177 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3178 (skip-chars-forward vip-NONSEP)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3179 (vip-skip-separators t)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3180 (if com (progn
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3181 (cond ((memq com (list ?c (- ?c)))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3182 (vip-fwd-skip "\n[ \t]*" " \t" vip-com-point))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3183 ;; Yank words including the whitespace, but not newline
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3184 ((memq com (list ?y (- ?y)))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3185 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3186 ((vip-dotable-command-p com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3187 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3188 (vip-execute-com 'vip-forward-Word val com)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3189
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3190
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3191 ;; this is a bit different from Vi, but Vi's end of word
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3192 ;; makes no sense whatsoever
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3193 (defun vip-end-of-word-kernel ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3194 (if (vip-end-of-word-p) (forward-char))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3195 (if (looking-at "[ \t\n]")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3196 (skip-chars-forward vip-SEP))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3197
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3198 (cond ((looking-at vip-ALPHA-B) (skip-chars-forward vip-ALPHA))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3199 ((looking-at vip-NONALPHASEP-B)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3200 (skip-chars-forward vip-NONALPHASEP)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3201 (vip-backward-char-carefully))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3202
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3203 (defun vip-end-of-word-p ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3204 (if (eobp) t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3205 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3206 (cond ((looking-at vip-ALPHA-B)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3207 (forward-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3208 (looking-at vip-NONALPHA-B))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3209 ((looking-at vip-NONALPHASEP-B)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3210 (forward-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3211 (looking-at vip-ALPHASEP-B))))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3212
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3213 (defun vip-one-char-word-p ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3214 (let ((step 2))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3215 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3216 (cond ((looking-at vip-ALPHA-B)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3217 (if (bobp) (setq step 1) (backward-char))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3218 (if (or (bobp) (looking-at vip-NONALPHA-B))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3219 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3220 (forward-char step)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3221 (looking-at vip-NONALPHA-B))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3222 nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3223 ((looking-at vip-NONALPHASEP-B)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3224 (if (bobp) (setq step 1) (backward-char))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3225 (if (or (bobp) (looking-at vip-ALPHASEP-B))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3226 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3227 (forward-char step)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3228 (looking-at vip-ALPHASEP-B))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3229 nil))))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3230
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3231 (defun vip-one-char-Word-p ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3232 (and (looking-at vip-NONSEP-B)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3233 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3234 (if (bobp)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3235 t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3236 (backward-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3237 (looking-at vip-SEP-B)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3238 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3239 (forward-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3240 (or (eobp)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3241 (looking-at vip-SEP-B)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3242
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3243 (defun vip-end-of-word (arg &optional careful)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3244 "Move point to end of current word."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3245 (interactive "P")
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
3246 (vip-leave-region-active)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3247 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3248 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3249 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3250 (vip-loop val (vip-end-of-word-kernel))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3251 (if com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3252 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3253 (forward-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3254 (vip-execute-com 'vip-end-of-word val com)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3255
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3256 (defun vip-end-of-Word (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3257 "Forward to end of word delimited by white character."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3258 (interactive "P")
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
3259 (vip-leave-region-active)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3260 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3261 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3262 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3263 (vip-loop val
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3264 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3265 (vip-end-of-word-kernel)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3266 (if (not (re-search-forward
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3267 vip-SEP-B nil t 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3268 (goto-char (point-max)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3269 (skip-chars-backward vip-SEP)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3270 (backward-char)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3271 (if com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3272 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3273 (forward-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3274 (vip-execute-com 'vip-end-of-Word val com)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3275
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3276 (defun vip-backward-word-kernel (val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3277 (while (> val 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3278 (backward-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3279 (cond ((looking-at vip-ALPHA-B)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3280 (skip-chars-backward vip-ALPHA))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3281 ((looking-at vip-SEP-B)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3282 (forward-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3283 (vip-skip-separators nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3284 (backward-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3285 (cond ((looking-at vip-ALPHA-B)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3286 (skip-chars-backward vip-ALPHA))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3287 ((looking-at vip-NONALPHASEP-B)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3288 (skip-chars-backward vip-NONALPHASEP))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3289 (t (forward-char))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3290 ((looking-at vip-NONALPHASEP-B)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3291 (skip-chars-backward vip-NONALPHASEP)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3292 (setq val (1- val))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3293
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3294 (defun vip-backward-word (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3295 "Backward word."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3296 (interactive "P")
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
3297 (vip-leave-region-active)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3298 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3299 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3300 (if com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3301 (let (i)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3302 (if (setq i (save-excursion (backward-char) (looking-at "\n")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3303 (backward-char))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3304 (vip-move-marker-locally 'vip-com-point (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3305 (if i (forward-char))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3306 (vip-backward-word-kernel val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3307 (if com (vip-execute-com 'vip-backward-word val com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3308
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3309 (defun vip-backward-Word (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3310 "Backward word delimited by white character."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3311 (interactive "P")
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
3312 (vip-leave-region-active)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3313 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3314 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3315 (if com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3316 (let (i)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3317 (if (setq i (save-excursion (backward-char) (looking-at "\n")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3318 (backward-char))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3319 (vip-move-marker-locally 'vip-com-point (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3320 (if i (forward-char))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3321 (vip-loop val
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3322 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3323 (vip-skip-separators nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3324 (skip-chars-backward vip-NONSEP)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3325 (if com (vip-execute-com 'vip-backward-Word val com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3326
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3327
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3328
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3329 ;; line commands
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3330
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3331 (defun vip-beginning-of-line (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3332 "Go to beginning of line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3333 (interactive "P")
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
3334 (vip-leave-region-active)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3335 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3336 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3337 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3338 (beginning-of-line val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3339 (if com (vip-execute-com 'vip-beginning-of-line val com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3340
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3341 (defun vip-bol-and-skip-white (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3342 "Beginning of line at first non-white character."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3343 (interactive "P")
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
3344 (vip-leave-region-active)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3345 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3346 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3347 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3348 (forward-to-indentation (1- val))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3349 (if com (vip-execute-com 'vip-bol-and-skip-white val com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3350
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3351 (defun vip-goto-eol (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3352 "Go to end of line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3353 (interactive "P")
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
3354 (vip-leave-region-active)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3355 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3356 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3357 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3358 (end-of-line val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3359 (if com (vip-execute-com 'vip-goto-eol val com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3360 (if vip-ex-style-motion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3361 (if (and (eolp) (not (bolp))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3362 ;; a fix for vip-change-to-eol
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3363 (not (equal vip-current-state 'insert-state)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3364 (backward-char 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3365 ))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3366
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3367
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3368 (defun vip-goto-col (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3369 "Go to ARG's column."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3370 (interactive "P")
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
3371 (vip-leave-region-active)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3372 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3373 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3374 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3375 (end-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3376 (if (> val (1+ (current-column))) (error "")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3377 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3378 (beginning-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3379 (forward-char (1- val))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3380 (if com (vip-execute-com 'vip-goto-col val com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3381
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3382
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3383 (defun vip-next-line (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3384 "Go to next line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3385 (interactive "P")
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
3386 (vip-leave-region-active)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3387 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3388 (com (vip-getCom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3389 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3390 (next-line val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3391 (if vip-ex-style-motion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3392 (if (and (eolp) (not (bolp))) (backward-char 1)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3393 (setq this-command 'next-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3394 (if com (vip-execute-com 'vip-next-line val com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3395
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3396 (defun vip-next-line-at-bol (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3397 "Next line at beginning of line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3398 (interactive "P")
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
3399 (vip-leave-region-active)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3400 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3401 (end-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3402 (if (eobp) (error "Last line in buffer")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3403 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3404 (com (vip-getCom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3405 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3406 (forward-line val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3407 (back-to-indentation)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3408 (if com (vip-execute-com 'vip-next-line-at-bol val com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3409
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3410 (defun vip-previous-line (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3411 "Go to previous line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3412 (interactive "P")
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
3413 (vip-leave-region-active)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3414 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3415 (com (vip-getCom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3416 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3417 (previous-line val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3418 (if vip-ex-style-motion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3419 (if (and (eolp) (not (bolp))) (backward-char 1)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3420 (setq this-command 'previous-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3421 (if com (vip-execute-com 'vip-previous-line val com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3422
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3423
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3424 (defun vip-previous-line-at-bol (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3425 "Previous line at beginning of line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3426 (interactive "P")
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
3427 (vip-leave-region-active)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3428 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3429 (beginning-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3430 (if (bobp) (error "First line in buffer")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3431 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3432 (com (vip-getCom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3433 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3434 (forward-line (- val))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3435 (back-to-indentation)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3436 (if com (vip-execute-com 'vip-previous-line val com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3437
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3438 (defun vip-change-to-eol (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3439 "Change to end of line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3440 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3441 (vip-goto-eol (cons arg ?c)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3442
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3443 (defun vip-kill-line (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3444 "Delete line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3445 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3446 (vip-goto-eol (cons arg ?d)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3447
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3448 (defun vip-erase-line (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3449 "Erase line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3450 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3451 (vip-beginning-of-line (cons arg ?d)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3452
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3453
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3454 ;;; Moving around
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3455
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3456 (defun vip-goto-line (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3457 "Go to ARG's line. Without ARG go to end of buffer."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3458 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3459 (let ((val (vip-P-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3460 (com (vip-getCom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3461 (vip-move-marker-locally 'vip-com-point (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3462 (vip-deactivate-mark)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3463 (push-mark nil t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3464 (if (null val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3465 (goto-char (point-max))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3466 (goto-char (point-min))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3467 (forward-line (1- val)))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3468
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3469 ;; positioning is done twice: before and after command execution
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3470 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3471 (back-to-indentation)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3472
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3473 (if com (vip-execute-com 'vip-goto-line val com))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3474
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3475 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3476 (back-to-indentation)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3477 ))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3478
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3479 ;; Find ARG's occurrence of CHAR on the current line.
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3480 ;; If FORWARD then search is forward, otherwise backward. OFFSET is used to
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3481 ;; adjust point after search.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3482 (defun vip-find-char (arg char forward offset)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3483 (or (char-or-string-p char) (error ""))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3484 (let ((arg (if forward arg (- arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3485 (cmd (if (eq vip-intermediate-command 'vip-repeat)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3486 (nth 5 vip-d-com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3487 (vip-array-to-string (this-command-keys))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3488 point)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3489 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3490 (save-restriction
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3491 (if (> arg 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3492 (narrow-to-region
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3493 ;; forward search begins here
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3494 (if (eolp) (error "Command `%s': At end of line" cmd) (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3495 ;; forward search ends here
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3496 (progn (end-of-line) (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3497 (narrow-to-region
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3498 ;; backward search begins from here
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3499 (if (bolp)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3500 (error "Command `%s': At beginning of line" cmd) (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3501 ;; backward search ends here
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3502 (progn (beginning-of-line) (point))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3503 ;; if arg > 0, point is forwarded before search.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3504 (if (> arg 0) (goto-char (1+ (point-min)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3505 (goto-char (point-max)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3506 (if (let ((case-fold-search nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3507 (search-forward (char-to-string char) nil 0 arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3508 (setq point (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3509 (error "Command `%s': `%c' not found" cmd char))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3510 (goto-char (+ point (if (> arg 0) (if offset -2 -1) (if offset 1 0))))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3511
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3512 (defun vip-find-char-forward (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3513 "Find char on the line.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3514 If called interactively read the char to find from the terminal, and if
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3515 called from vip-repeat, the char last used is used. This behaviour is
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3516 controlled by the sign of prefix numeric value."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3517 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3518 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3519 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3520 (if (> val 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3521 ;; this means that the function was called interactively
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3522 (setq vip-f-char (read-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3523 vip-f-forward t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3524 vip-f-offset nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3525 ;; vip-repeat --- set vip-F-char from command-keys
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3526 (setq vip-F-char (if (stringp (nth 5 vip-d-com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3527 (vip-seq-last-elt (nth 5 vip-d-com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3528 vip-F-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3529 vip-f-char vip-F-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3530 (setq val (- val)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3531 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3532 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3533 (setq val (- val))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3534 (if com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3535 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3536 (setq vip-F-char vip-f-char) ; set new vip-F-char
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3537 (forward-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3538 (vip-execute-com 'vip-find-char-forward val com)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3539
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3540 (defun vip-goto-char-forward (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3541 "Go up to char ARG forward on line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3542 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3543 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3544 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3545 (if (> val 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3546 ;; this means that the function was called interactively
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3547 (setq vip-f-char (read-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3548 vip-f-forward t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3549 vip-f-offset t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3550 ;; vip-repeat --- set vip-F-char from command-keys
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3551 (setq vip-F-char (if (stringp (nth 5 vip-d-com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3552 (vip-seq-last-elt (nth 5 vip-d-com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3553 vip-F-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3554 vip-f-char vip-F-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3555 (setq val (- val)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3556 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3557 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3558 (setq val (- val))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3559 (if com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3560 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3561 (setq vip-F-char vip-f-char) ; set new vip-F-char
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3562 (forward-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3563 (vip-execute-com 'vip-goto-char-forward val com)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3564
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3565 (defun vip-find-char-backward (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3566 "Find char ARG on line backward."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3567 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3568 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3569 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3570 (if (> val 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3571 ;; this means that the function was called interactively
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3572 (setq vip-f-char (read-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3573 vip-f-forward nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3574 vip-f-offset nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3575 ;; vip-repeat --- set vip-F-char from command-keys
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3576 (setq vip-F-char (if (stringp (nth 5 vip-d-com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3577 (vip-seq-last-elt (nth 5 vip-d-com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3578 vip-F-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3579 vip-f-char vip-F-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3580 (setq val (- val)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3581 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3582 (vip-find-char
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3583 val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3584 (setq val (- val))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3585 (if com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3586 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3587 (setq vip-F-char vip-f-char) ; set new vip-F-char
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3588 (vip-execute-com 'vip-find-char-backward val com)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3589
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3590 (defun vip-goto-char-backward (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3591 "Go up to char ARG backward on line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3592 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3593 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3594 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3595 (if (> val 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3596 ;; this means that the function was called interactively
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3597 (setq vip-f-char (read-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3598 vip-f-forward nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3599 vip-f-offset t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3600 ;; vip-repeat --- set vip-F-char from command-keys
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3601 (setq vip-F-char (if (stringp (nth 5 vip-d-com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3602 (vip-seq-last-elt (nth 5 vip-d-com))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3603 vip-F-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3604 vip-f-char vip-F-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3605 (setq val (- val)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3606 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3607 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3608 (setq val (- val))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3609 (if com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3610 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3611 (setq vip-F-char vip-f-char) ; set new vip-F-char
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3612 (vip-execute-com 'vip-goto-char-backward val com)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3613
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3614 (defun vip-repeat-find (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3615 "Repeat previous find command."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3616 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3617 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3618 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3619 (vip-deactivate-mark)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3620 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3621 (vip-find-char val vip-f-char vip-f-forward vip-f-offset)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3622 (if com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3623 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3624 (if vip-f-forward (forward-char))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3625 (vip-execute-com 'vip-repeat-find val com)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3626
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3627 (defun vip-repeat-find-opposite (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3628 "Repeat previous find command in the opposite direction."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3629 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3630 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3631 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3632 (vip-deactivate-mark)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3633 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3634 (vip-find-char val vip-f-char (not vip-f-forward) vip-f-offset)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3635 (if com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3636 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3637 (if vip-f-forward (forward-char))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3638 (vip-execute-com 'vip-repeat-find-opposite val com)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3639
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3640
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3641 ;; window scrolling etc.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3642
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3643 (defun vip-other-window (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3644 "Switch to other window."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3645 (interactive "p")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3646 (other-window arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3647 (or (not (eq vip-current-state 'emacs-state))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3648 (string= (buffer-name (current-buffer)) " *Minibuf-1*")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3649 (vip-change-state-to-vi)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3650
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3651 (defun vip-window-top (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3652 "Go to home window line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3653 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3654 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3655 (com (vip-getCom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3656 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3657 (push-mark nil t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3658 (move-to-window-line (1- val))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3659
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3660 ;; positioning is done twice: before and after command execution
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3661 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3662 (back-to-indentation)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3663
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3664 (if com (vip-execute-com 'vip-window-top val com))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3665
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3666 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3667 (back-to-indentation)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3668 ))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3669
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3670 (defun vip-window-middle (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3671 "Go to middle window line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3672 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3673 (let ((val (vip-p-val arg))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3674 (com (vip-getCom arg))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3675 lines)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3676 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3677 (push-mark nil t)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3678 (if (not (pos-visible-in-window-p (point-max)))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3679 (move-to-window-line (+ (/ (1- (window-height)) 2) (1- val)))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3680 (setq lines (count-lines (window-start) (point-max)))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3681 (move-to-window-line (+ (/ lines 2) (1- val))))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3682
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3683 ;; positioning is done twice: before and after command execution
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3684 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3685 (back-to-indentation)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3686
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3687 (if com (vip-execute-com 'vip-window-middle val com))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3688
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3689 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3690 (back-to-indentation)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3691 ))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3692
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3693 (defun vip-window-bottom (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3694 "Go to last window line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3695 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3696 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3697 (com (vip-getCom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3698 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3699 (push-mark nil t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3700 (move-to-window-line (- val))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3701
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3702 ;; positioning is done twice: before and after command execution
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3703 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3704 (back-to-indentation)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3705
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3706 (if com (vip-execute-com 'vip-window-bottom val com))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3707
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3708 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3709 (back-to-indentation)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3710 ))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3711
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3712 (defun vip-line-to-top (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3713 "Put current line on the home line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3714 (interactive "p")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3715 (recenter (1- arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3716
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3717 (defun vip-line-to-middle (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3718 "Put current line on the middle line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3719 (interactive "p")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3720 (recenter (+ (1- arg) (/ (1- (window-height)) 2))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3721
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3722 (defun vip-line-to-bottom (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3723 "Put current line on the last line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3724 (interactive "p")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3725 (recenter (- (window-height) (1+ arg))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3726
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3727
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3728 ;; paren match
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3729 ;; must correct this to only match ( to ) etc. On the other hand
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3730 ;; it is good that paren match gets confused, because that way you
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3731 ;; catch _all_ imbalances.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3732
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3733 (defun vip-paren-match (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3734 "Go to the matching parenthesis."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3735 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3736 (let ((com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3737 (if (numberp arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3738 (if (or (> arg 99) (< arg 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3739 (error "Prefix must be between 1 and 99")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3740 (goto-char
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3741 (if (> (point-max) 80000)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3742 (* (/ (point-max) 100) arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3743 (/ (* (point-max) arg) 100)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3744 (back-to-indentation))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3745 (let (lim)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3746 (if (and (eolp) (not (bolp))) (forward-char -1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3747 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3748 (end-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3749 (setq lim (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3750 (if (re-search-forward "[][(){}]" lim t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3751 (backward-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3752 (error "No matching character on line")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3753 (cond ((looking-at "[\(\[{]")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3754 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3755 (forward-sexp 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3756 (if com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3757 (vip-execute-com 'vip-paren-match nil com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3758 (backward-char)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3759 ((looking-at "[])}]")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3760 (forward-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3761 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3762 (backward-sexp 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3763 (if com (vip-execute-com 'vip-paren-match nil com)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3764 (t (error ""))))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3765
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3766
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3767 ;; sentence ,paragraph and heading
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3768
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3769 (defun vip-forward-sentence (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3770 "Forward sentence."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3771 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3772 (push-mark nil t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3773 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3774 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3775 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3776 (forward-sentence val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3777 (if com (vip-execute-com 'vip-forward-sentence nil com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3778
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3779 (defun vip-backward-sentence (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3780 "Backward sentence."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3781 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3782 (push-mark nil t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3783 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3784 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3785 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3786 (backward-sentence val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3787 (if com (vip-execute-com 'vip-backward-sentence nil com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3788
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3789 (defun vip-forward-paragraph (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3790 "Forward paragraph."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3791 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3792 (push-mark nil t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3793 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3794 (com (vip-getCom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3795 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3796 (forward-paragraph val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3797 (if com (vip-execute-com 'vip-forward-paragraph nil com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3798
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3799 (defun vip-backward-paragraph (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3800 "Backward paragraph."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3801 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3802 (push-mark nil t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3803 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3804 (com (vip-getCom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3805 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3806 (backward-paragraph val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3807 (if com (vip-execute-com 'vip-backward-paragraph nil com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3808
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3809 ;; should be mode-specific etc.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3810
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3811 (defun vip-prev-heading (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3812 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3813 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3814 (com (vip-getCom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3815 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3816 (re-search-backward vip-heading-start nil t val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3817 (goto-char (match-beginning 0))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3818 (if com (vip-execute-com 'vip-prev-heading nil com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3819
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3820 (defun vip-heading-end (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3821 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3822 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3823 (com (vip-getCom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3824 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3825 (re-search-forward vip-heading-end nil t val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3826 (goto-char (match-beginning 0))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3827 (if com (vip-execute-com 'vip-heading-end nil com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3828
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3829 (defun vip-next-heading (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3830 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3831 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3832 (com (vip-getCom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3833 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3834 (end-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3835 (re-search-forward vip-heading-start nil t val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3836 (goto-char (match-beginning 0))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3837 (if com (vip-execute-com 'vip-next-heading nil com))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3838
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3839
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3840 ;; scrolling
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3841
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3842 (setq scroll-step 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3843
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3844 (defun vip-scroll (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3845 "Scroll to next screen."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3846 (interactive "p")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3847 (if (> arg 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3848 (while (> arg 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3849 (scroll-up)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3850 (setq arg (1- arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3851 (while (> 0 arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3852 (scroll-down)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3853 (setq arg (1+ arg)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3854
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3855 (defun vip-scroll-back (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3856 "Scroll to previous screen."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3857 (interactive "p")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3858 (vip-scroll (- arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3859
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3860 (defun vip-scroll-down (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3861 "Pull down half screen."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3862 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3863 (condition-case nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3864 (if (null arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3865 (scroll-down (/ (window-height) 2))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3866 (scroll-down arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3867 (error (beep 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3868 (message "Beginning of buffer")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3869 (goto-char (point-min)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3870
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3871 (defun vip-scroll-down-one (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3872 "Scroll up one line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3873 (interactive "p")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3874 (scroll-down arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3875
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3876 (defun vip-scroll-up (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3877 "Pull up half screen."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3878 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3879 (condition-case nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3880 (if (null arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3881 (scroll-up (/ (window-height) 2))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3882 (scroll-up arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3883 (error (beep 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3884 (message "End of buffer")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3885 (goto-char (point-max)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3886
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3887 (defun vip-scroll-up-one (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3888 "Scroll down one line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3889 (interactive "p")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3890 (scroll-up arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3891
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3892
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3893 ;; searching
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3894
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3895 (defun vip-if-string (prompt)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3896 (let ((s (vip-read-string-with-history
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3897 prompt
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3898 nil ; no initial
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3899 'vip-search-history
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3900 (car vip-search-history))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3901 (if (not (string= s ""))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3902 (setq vip-s-string s))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3903
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3904
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3905 (defun vip-toggle-search-style (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3906 "Toggle the value of vip-case-fold-search/vip-re-search.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3907 Without prefix argument, will ask which search style to toggle. With prefix
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3908 arg 1,toggles vip-case-fold-search; with arg 2 toggles vip-re-search.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3909
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3910 Although this function is bound to \\[vip-toggle-search-style], the most
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3911 convenient way to use it is to bind `//' to the macro
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3912 `1 M-x vip-toggle-search-style' and `///' to
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3913 `2 M-x vip-toggle-search-style'. In this way, hitting `//' quickly will
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3914 toggle case-fold-search and hitting `/' three times witth toggle regexp
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3915 search. Macros are more convenient in this case because they don't affect
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3916 the Emacs binding of `/'."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3917 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3918 (let (msg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3919 (cond ((or (eq arg 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3920 (and (null arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3921 (y-or-n-p (format "Search style: '%s'. Want '%s'? "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3922 (if vip-case-fold-search
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3923 "case-insensitive" "case-sensitive")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3924 (if vip-case-fold-search
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3925 "case-sensitive"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3926 "case-insensitive")))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3927 (setq vip-case-fold-search (null vip-case-fold-search))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3928 (if vip-case-fold-search
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3929 (setq msg "Search becomes case-insensitive")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3930 (setq msg "Search becomes case-sensitive")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3931 ((or (eq arg 2)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3932 (and (null arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3933 (y-or-n-p (format "Search style: '%s'. Want '%s'? "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3934 (if vip-re-search
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3935 "regexp-search" "vanilla-search")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3936 (if vip-re-search
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3937 "vanilla-search"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3938 "regexp-search")))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3939 (setq vip-re-search (null vip-re-search))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3940 (if vip-re-search
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3941 (setq msg "Search becomes regexp-style")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3942 (setq msg "Search becomes vanilla-style")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3943 (t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3944 (setq msg "Search style remains unchanged")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3945 (prin1 msg t)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3946
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3947
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3948 (defun vip-search-forward (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3949 "Search a string forward.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3950 ARG is used to find the ARG's occurrence of the string.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3951 Null string will repeat previous search."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3952 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3953 (let ((val (vip-P-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3954 (com (vip-getcom arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3955 (old-str vip-s-string))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3956 (setq vip-s-forward t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3957 (vip-if-string "/")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3958 ;; this is not used at present, but may be used later
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3959 (if (or (not (equal old-str vip-s-string))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3960 (not (markerp vip-local-search-start-marker))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3961 (not (marker-buffer vip-local-search-start-marker)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3962 (setq vip-local-search-start-marker (point-marker)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3963 (vip-search vip-s-string t val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3964 (if com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3965 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3966 (vip-move-marker-locally 'vip-com-point (mark t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3967 (vip-execute-com 'vip-search-next val com)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3968
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3969 (defun vip-search-backward (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3970 "Search a string backward.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3971 ARG is used to find the ARG's occurrence of the string.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3972 Null string will repeat previous search."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3973 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3974 (let ((val (vip-P-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3975 (com (vip-getcom arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3976 (old-str vip-s-string))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3977 (setq vip-s-forward nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3978 (vip-if-string "?")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3979 ;; this is not used at present, but may be used later
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3980 (if (or (not (equal old-str vip-s-string))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3981 (not (markerp vip-local-search-start-marker))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3982 (not (marker-buffer vip-local-search-start-marker)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3983 (setq vip-local-search-start-marker (point-marker)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3984 (vip-search vip-s-string nil val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3985 (if com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3986 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3987 (vip-move-marker-locally 'vip-com-point (mark t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3988 (vip-execute-com 'vip-search-next val com)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3989
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3990
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3991 ;; Search for COUNT's occurrence of STRING.
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3992 ;; Search is forward if FORWARD is non-nil, otherwise backward.
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3993 ;; INIT-POINT is the position where search is to start.
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
3994 ;; Arguments: (STRING FORWARD COUNT &optional NO-OFFSET INIT-POINT LIMIT)."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3995 (defun vip-search (string forward arg &optional no-offset init-point)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3996 (if (not (equal string ""))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3997 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3998 (com (vip-getcom arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3999 (null-arg (null (vip-P-val arg))) (offset (not no-offset))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4000 (case-fold-search vip-case-fold-search)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4001 (start-point (or init-point (point))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4002 (vip-deactivate-mark)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4003 (if forward
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4004 (condition-case nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4005 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4006 (if offset (vip-forward-char-carefully))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4007 (if vip-re-search
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4008 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4009 (re-search-forward string nil nil val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4010 (re-search-backward string))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4011 (search-forward string nil nil val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4012 (search-backward string))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4013 (vip-flash-search-pattern)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4014 (if (not (equal start-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4015 (push-mark start-point t)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4016 (search-failed
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4017 (if (and null-arg vip-search-wrap-around-t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4018 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4019 (message "Search wrapped around end of buffer")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4020 (goto-char (point-min))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4021 (vip-search string forward (cons 1 com) t start-point)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4022 ;; delete the wrapped around message
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4023 (sit-for 2)(message "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4024 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4025 (goto-char start-point)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4026 (error "`%s': %s not found"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4027 string
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4028 (if vip-re-search "Pattern" "String"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4029 )))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4030 ;; backward
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4031 (condition-case nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4032 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4033 (if vip-re-search
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4034 (re-search-backward string nil nil val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4035 (search-backward string nil nil val))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4036 (vip-flash-search-pattern)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4037 (if (not (equal start-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4038 (push-mark start-point t)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4039 (search-failed
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4040 (if (and null-arg vip-search-wrap-around-t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4041 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4042 (message "Search wrapped around beginning of buffer")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4043 (goto-char (point-max))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4044 (vip-search string forward (cons 1 com) t start-point)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4045 ;; delete the wrapped around message
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4046 (sit-for 2)(message "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4047 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4048 (goto-char start-point)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4049 (error "`%s': %s not found"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4050 string
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4051 (if vip-re-search "Pattern" "String"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4052 )))))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4053
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4054 (defun vip-search-next (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4055 "Repeat previous search."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4056 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4057 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4058 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4059 (if (null vip-s-string) (error vip-NoPrevSearch))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4060 (vip-search vip-s-string vip-s-forward arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4061 (if com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4062 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4063 (vip-move-marker-locally 'vip-com-point (mark t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4064 (vip-execute-com 'vip-search-next val com)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4065
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4066 (defun vip-search-Next (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4067 "Repeat previous search in the reverse direction."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4068 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4069 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4070 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4071 (if (null vip-s-string) (error vip-NoPrevSearch))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4072 (vip-search vip-s-string (not vip-s-forward) arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4073 (if com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4074 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4075 (vip-move-marker-locally 'vip-com-point (mark t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4076 (vip-execute-com 'vip-search-Next val com)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4077
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4078
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4079 ;; Search contents of buffer defined by one of Viper's motion commands.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4080 ;; Repeatable via `n' and `N'.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4081 (defun vip-buffer-search-enable (&optional c)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4082 (cond (c (setq vip-buffer-search-char c))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4083 ((null vip-buffer-search-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4084 (setq vip-buffer-search-char ?g)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4085 (define-key vip-vi-basic-map
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4086 (char-to-string vip-buffer-search-char) 'vip-command-argument)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4087 (aset vip-exec-array vip-buffer-search-char 'vip-exec-buffer-search)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4088 (setq vip-prefix-commands (cons vip-buffer-search-char vip-prefix-commands)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4089
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4090 ;; This is a Viper wraper for isearch-forward.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4091 (defun vip-isearch-forward (arg)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4092 "Do incremental search forward."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4093 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4094 ;; emacs bug workaround
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4095 (if (listp arg) (setq arg (car arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4096 (vip-exec-form-in-emacs (list 'isearch-forward arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4097
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4098 ;; This is a Viper wraper for isearch-backward."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4099 (defun vip-isearch-backward (arg)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4100 "Do incremental search backward."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4101 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4102 ;; emacs bug workaround
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4103 (if (listp arg) (setq arg (car arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4104 (vip-exec-form-in-emacs (list 'isearch-backward arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4105
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4106
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4107 ;; visiting and killing files, buffers
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4108
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4109 (defun vip-switch-to-buffer ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4110 "Switch to buffer in the current window."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4111 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4112 (let (buffer)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4113 (setq buffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4114 (read-buffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4115 (format "Switch to buffer in this window \(%s\): "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4116 (buffer-name (other-buffer (current-buffer))))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4117 (switch-to-buffer buffer)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4118 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4119
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4120 (defun vip-switch-to-buffer-other-window ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4121 "Switch to buffer in another window."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4122 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4123 (let (buffer)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4124 (setq buffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4125 (read-buffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4126 (format "Switch to buffer in another window \(%s\): "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4127 (buffer-name (other-buffer (current-buffer))))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4128 (switch-to-buffer-other-window buffer)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4129 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4130
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4131 (defun vip-kill-buffer ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4132 "Kill a buffer."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4133 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4134 (let (buffer buffer-name)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4135 (setq buffer-name
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4136 (read-buffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4137 (format "Kill buffer \(%s\): "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4138 (buffer-name (current-buffer)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4139 (setq buffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4140 (if (null buffer-name)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4141 (current-buffer)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4142 (get-buffer buffer-name)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4143 (if (null buffer) (error "`%s': No such buffer" buffer-name))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4144 (if (or (not (buffer-modified-p buffer))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4145 (y-or-n-p
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4146 (format
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4147 "Buffer `%s' is modified, are you sure you want to kill it? "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4148 buffer-name)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4149 (kill-buffer buffer)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4150 (error "Buffer not killed"))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4151
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4152
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4153 (defvar vip-smart-suffix-list '("" "tex" "c" "cc" "el" "p")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4154 "*List of suffixes that Viper automatically tries to append to filenames ending with a `.'.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4155 This is useful when you the current directory contains files with the same
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4156 prefix and many different suffixes. Usually, only one of the suffixes
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4157 represents an editable file. However, file completion will stop at the `.'
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4158 The smart suffix feature lets you hit RET in such a case, and Viper will
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4159 select the appropriate suffix.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4160
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4161 Suffixes are tried in the order given and the first suffix for which a
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4162 corresponding file exists is selected. If no file exists for any of the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4163 suffixes, the user is asked to confirm.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4164
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4165 To turn this feature off, set this variable to nil.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4166
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4167 ;; Try to add suffix to files ending with a `.'
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4168 ;; Useful when the user hits RET on a non-completed file name.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4169 (defun vip-file-add-suffix ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4170 (let ((count 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4171 (len (length vip-smart-suffix-list))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4172 (file (buffer-string))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4173 found key cmd suff)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4174 (goto-char (point-max))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4175 (if (and vip-smart-suffix-list (string-match "\\.$" file))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4176 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4177 (while (and (not found) (< count len))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4178 (setq suff (nth count vip-smart-suffix-list)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4179 count (1+ count))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4180 (if (file-exists-p (format "%s%s" file suff))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4181 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4182 (setq found t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4183 (insert suff))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4184
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4185 (if found
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4186 ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4187 (vip-tmp-insert-at-eob " [Please complete file name]")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4188 (unwind-protect
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4189 (while (not (memq cmd '(exit-minibuffer vip-exit-minibuffer)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4190 (setq cmd
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4191 (key-binding (setq key (read-key-sequence nil))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4192 (cond ((eq cmd 'self-insert-command)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4193 (if vip-xemacs-p
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4194 (insert (events-to-keys key))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4195 (insert key)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4196 ((memq cmd '(exit-minibuffer vip-exit-minibuffer))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4197 nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4198 (t (command-execute cmd)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4199 )))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4200 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4201 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4202
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4203
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4204 ;; Advice for use in find-file and read-file-name commands.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4205 (defadvice exit-minibuffer (before vip-exit-minibuffer-advice activate)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4206 "Run `vip-minibuffer-exit-hook' just before exiting the minibuffer."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4207 (run-hooks 'vip-minibuffer-exit-hook))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4208
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4209 (defadvice find-file (before vip-add-suffix-advice activate)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4210 "Use `read-file-name' for reading arguments."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4211 (interactive (list (read-file-name "Find file: "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4212 nil default-directory))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4213
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4214 (defadvice find-file-other-window (before vip-add-suffix-advice activate)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4215 "Use `read-file-name' for reading arguments."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4216 (interactive (list (read-file-name "Find file in other window: "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4217 nil default-directory))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4218
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4219 (defadvice find-file-other-frame (before vip-add-suffix-advice activate)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4220 "Use `read-file-name' for reading arguments."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4221 (interactive (list (read-file-name "Find file in other frame: "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4222 nil default-directory))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4223
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4224 (defadvice read-file-name (around vip-suffix-advice activate)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4225 "Tell `exit-minibuffer' to run `vip-file-add-suffix' as a hook."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4226 (let ((vip-minibuffer-exit-hook 'vip-file-add-suffix))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4227 ad-do-it))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4228
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4229
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4230
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4231 ;; yank and pop
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4232
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4233 (defsubst vip-yank (text)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4234 "Yank TEXT silently. This works correctly with Emacs's yank-pop command."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4235 (insert text)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4236 (setq this-command 'yank))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4237
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4238 (defun vip-put-back (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4239 "Put back after point/below line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4240 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4241 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4242 (text (if vip-use-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4243 (cond ((vip-valid-register vip-use-register '(digit))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4244 (current-kill (- vip-use-register ?1) 'do-not-rotate))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4245 ((vip-valid-register vip-use-register)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4246 (get-register (downcase vip-use-register)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4247 (t (error vip-InvalidRegister vip-use-register)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4248 (current-kill 0))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4249 (if (null text)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4250 (if vip-use-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4251 (let ((reg vip-use-register))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4252 (setq vip-use-register nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4253 (error vip-EmptyRegister reg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4254 (error "")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4255 (setq vip-use-register nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4256 (if (vip-end-with-a-newline-p text)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4257 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4258 (if (eobp)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4259 (insert "\n")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4260 (forward-line 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4261 (beginning-of-line))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4262 (if (not (eolp)) (vip-forward-char-carefully)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4263 (set-marker (vip-mark-marker) (point) (current-buffer))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4264 (vip-set-destructive-command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4265 (list 'vip-put-back val nil vip-use-register nil nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4266 (vip-loop val (vip-yank text)))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4267 ;; Vi puts cursor on the last char when the yanked text doesn't contain a
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4268 ;; newline; it leaves the cursor at the beginning when the text contains
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4269 ;; a newline
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4270 (if (vip-same-line (point) (mark))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4271 (or (= (point) (mark)) (vip-backward-char-carefully))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4272 (exchange-point-and-mark)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4273 (if (bolp)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4274 (back-to-indentation)))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4275 (vip-deactivate-mark))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4276
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4277 (defun vip-Put-back (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4278 "Put back at point/above line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4279 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4280 (let ((val (vip-p-val arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4281 (text (if vip-use-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4282 (cond ((vip-valid-register vip-use-register '(digit))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4283 (current-kill (- vip-use-register ?1) 'do-not-rotate))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4284 ((vip-valid-register vip-use-register)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4285 (get-register (downcase vip-use-register)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4286 (t (error vip-InvalidRegister vip-use-register)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4287 (current-kill 0))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4288 (if (null text)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4289 (if vip-use-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4290 (let ((reg vip-use-register))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4291 (setq vip-use-register nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4292 (error vip-EmptyRegister reg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4293 (error "")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4294 (setq vip-use-register nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4295 (if (vip-end-with-a-newline-p text) (beginning-of-line))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4296 (vip-set-destructive-command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4297 (list 'vip-Put-back val nil vip-use-register nil nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4298 (set-marker (vip-mark-marker) (point) (current-buffer))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4299 (vip-loop val (vip-yank text)))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4300 ;; Vi puts cursor on the last char when the yanked text doesn't contain a
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4301 ;; newline; it leaves the cursor at the beginning when the text contains
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4302 ;; a newline
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4303 (if (vip-same-line (point) (mark))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4304 (or (= (point) (mark)) (vip-backward-char-carefully))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4305 (exchange-point-and-mark)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4306 (if (bolp)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4307 (back-to-indentation)))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4308 (vip-deactivate-mark))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4309
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4310
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4311 ;; Copy region to kill-ring.
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4312 ;; If BEG and END do not belong to the same buffer, copy empty region.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4313 (defun vip-copy-region-as-kill (beg end)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4314 (condition-case nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4315 (copy-region-as-kill beg end)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4316 (error (copy-region-as-kill beg beg))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4317
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4318 ;; Saves last inserted text for possible use by vip-repeat command.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4319 (defun vip-save-last-insertion (beg end)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4320 (setq vip-last-insertion (buffer-substring beg end))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4321 (or (< (length vip-d-com) 5)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4322 (setcar (nthcdr 4 vip-d-com) vip-last-insertion))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4323 (or (null vip-command-ring)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4324 (ring-empty-p vip-command-ring)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4325 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4326 (setcar (nthcdr 4 (vip-current-ring-item vip-command-ring))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4327 vip-last-insertion)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4328 ;; del most recent elt, if identical to the second most-recent
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4329 (vip-cleanup-ring vip-command-ring)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4330 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4331
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4332 (defsubst vip-yank-last-insertion ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4333 "Inserts the text saved by the previous vip-save-last-insertion command."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4334 (condition-case nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4335 (insert vip-last-insertion)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4336 (error nil)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4337
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4338
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4339 (defun vip-delete-char (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4340 "Delete character."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4341 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4342 (let ((val (vip-p-val arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4343 (vip-set-destructive-command (list 'vip-delete-char val nil nil nil nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4344 (if (> val 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4345 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4346 (let ((here (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4347 (end-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4348 (if (> val (- (point) here))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4349 (setq val (- (point) here))))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4350 (if (and (eq val 0) (not vip-ex-style-motion)) (setq val 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4351 (if (and vip-ex-style-motion (eolp))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4352 (if (bolp) (error "") (setq val 0))) ; not bol---simply back 1 ch
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4353 (if vip-use-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4354 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4355 (cond ((vip-valid-register vip-use-register '((Letter)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4356 (vip-append-to-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4357 (downcase vip-use-register) (point) (- (point) val)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4358 ((vip-valid-register vip-use-register)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4359 (copy-to-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4360 vip-use-register (point) (- (point) val) nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4361 (t (error vip-InvalidRegister vip-use-register)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4362 (setq vip-use-register nil)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4363 (if vip-ex-style-motion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4364 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4365 (delete-char val t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4366 (if (and (eolp) (not (bolp))) (backward-char 1)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4367 (if (eolp)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4368 (delete-backward-char val t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4369 (delete-char val t)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4370
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4371 (defun vip-delete-backward-char (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4372 "Delete previous character. On reaching beginning of line, stop and beep."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4373 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4374 (let ((val (vip-p-val arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4375 (vip-set-destructive-command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4376 (list 'vip-delete-backward-char val nil nil nil nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4377 (if (> val 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4378 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4379 (let ((here (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4380 (beginning-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4381 (if (> val (- here (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4382 (setq val (- here (point)))))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4383 (if vip-use-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4384 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4385 (cond ((vip-valid-register vip-use-register '(Letter))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4386 (vip-append-to-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4387 (downcase vip-use-register) (point) (+ (point) val)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4388 ((vip-valid-register vip-use-register)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4389 (copy-to-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4390 vip-use-register (point) (+ (point) val) nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4391 (t (error vip-InvalidRegister vip-use-register)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4392 (setq vip-use-register nil)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4393 (if (bolp) (ding)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4394 (delete-backward-char val t))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4395
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4396 (defun vip-del-backward-char-in-insert ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4397 "Delete 1 char backwards while in insert mode."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4398 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4399 (if (and vip-ex-style-editing-in-insert (bolp))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4400 (beep 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4401 (delete-backward-char 1 t)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4402
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4403 (defun vip-del-backward-char-in-replace ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4404 "Delete one character in replace mode.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4405 If `vip-delete-backwards-in-replace' is t, then DEL key actually deletes
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4406 charecters. If it is nil, then the cursor just moves backwards, similarly
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4407 to Vi. The variable `vip-ex-style-editing-in-insert', if t, doesn't let the
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4408 cursor move past the beginning of line."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4409 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4410 (cond (vip-delete-backwards-in-replace
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4411 (cond ((not (bolp))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4412 (delete-backward-char 1 t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4413 (vip-ex-style-editing-in-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4414 (beep 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4415 ((bobp)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4416 (beep 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4417 (t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4418 (delete-backward-char 1 t))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4419 (vip-ex-style-editing-in-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4420 (if (bolp)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4421 (beep 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4422 (backward-char 1)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4423 (t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4424 (backward-char 1))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4425
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4426
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4427
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4428 ;; join lines.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4429
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4430 (defun vip-join-lines (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4431 "Join this line to next, if ARG is nil. Otherwise, join ARG lines."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4432 (interactive "*P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4433 (let ((val (vip-P-val arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4434 (vip-set-destructive-command (list 'vip-join-lines val nil nil nil nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4435 (vip-loop (if (null val) 1 (1- val))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4436 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4437 (end-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4438 (if (not (eobp))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4439 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4440 (forward-line 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4441 (delete-region (point) (1- (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4442 (fixup-whitespace)))))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4443
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4444
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4445 ;; Replace state
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4446
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4447 (defun vip-change (beg end)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4448 (if (markerp beg) (setq beg (marker-position beg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4449 (if (markerp end) (setq end (marker-position end)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4450 ;; beg is sometimes (mark t), which may be nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4451 (or beg (setq beg end))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4452
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4453 (vip-set-complex-command-for-undo)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4454 (if vip-use-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4455 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4456 (copy-to-register vip-use-register beg end nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4457 (setq vip-use-register nil)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4458 (vip-set-replace-overlay beg end)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4459 (setq last-command nil) ; separate repl text from prev kills
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4460
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4461 (if (= (vip-replace-start) (point-max))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4462 (error "End of buffer"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4463
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4464 (setq vip-last-replace-region
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4465 (buffer-substring (vip-replace-start)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4466 (vip-replace-end)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4467
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4468 ;; protect against error while inserting "@" and other disasters
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4469 ;; (e.g., read-only buff)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4470 (condition-case conds
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4471 (if (vip-same-line (vip-replace-start)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4472 (vip-replace-end))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4473 (progn
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4474 ;; tabs cause problems in replace, so untabify
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4475 (goto-char (vip-replace-end))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4476 (insert-before-markers "@") ; put placeholder after the TAB
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4477 (untabify (vip-replace-start) (point))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4478 ;; del @, don't put on kill ring
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4479 (delete-backward-char 1)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4480
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4481 (vip-set-replace-overlay-glyphs
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4482 vip-replace-region-start-delimiter
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4483 vip-replace-region-end-delimiter)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4484 ;; this move takes care of the last posn in the overlay, which
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4485 ;; has to be shifted because of insert. We can't simply insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4486 ;; "$" before-markers because then overlay-start will shift the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4487 ;; beginning of the overlay in case we are replacing a single
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4488 ;; character. This fixes the bug with `s' and `cl' commands.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4489 (vip-move-replace-overlay (vip-replace-start) (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4490 (goto-char (vip-replace-start))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4491 (vip-change-state-to-replace t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4492 (kill-region (vip-replace-start)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4493 (vip-replace-end))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4494 (vip-restore-cursor-color)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4495 (vip-change-state-to-insert))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4496 (error ;; make sure that the overlay doesn't stay.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4497 ;; go back to the original point
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4498 (goto-char (vip-replace-start))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4499 (vip-hide-replace-overlay)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4500 (vip-message-conditions conds))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4501
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4502
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4503 (defun vip-change-subr (beg end)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4504 ;; beg is sometimes (mark t), which may be nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4505 (or beg (setq beg end))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4506
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4507 (if vip-use-register
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4508 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4509 (copy-to-register vip-use-register beg end nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4510 (setq vip-use-register nil)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4511 (kill-region beg end)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4512 (setq this-command 'vip-change)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4513 (vip-yank-last-insertion))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4514
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4515 (defun vip-toggle-case (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4516 "Toggle character case."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4517 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4518 (let ((val (vip-p-val arg)) (c))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4519 (vip-set-destructive-command (list 'vip-toggle-case val nil nil nil nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4520 (while (> val 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4521 (setq c (following-char))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4522 (delete-char 1 nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4523 (if (eq c (upcase c))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4524 (insert-char (downcase c) 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4525 (insert-char (upcase c) 1))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4526 (if (eolp) (backward-char 1))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4527 (setq val (1- val)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4528
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4529
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4530 ;; query replace
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4531
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4532 (defun vip-query-replace ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4533 "Query replace.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4534 If a null string is suplied as the string to be replaced,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4535 the query replace mode will toggle between string replace
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4536 and regexp replace."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4537 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4538 (let (str)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4539 (setq str (vip-read-string-with-history
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4540 (if vip-re-query-replace "Query replace regexp: "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4541 "Query replace: ")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4542 nil ; no initial
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4543 'vip-replace1-history
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4544 (car vip-replace1-history) ; default
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4545 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4546 (if (string= str "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4547 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4548 (setq vip-re-query-replace (not vip-re-query-replace))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4549 (message "Query replace mode changed to %s"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4550 (if vip-re-query-replace "regexp replace"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4551 "string replace")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4552 (if vip-re-query-replace
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4553 (query-replace-regexp
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4554 str
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4555 (vip-read-string-with-history
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4556 (format "Query replace regexp `%s' with: " str)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4557 nil ; no initial
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4558 'vip-replace1-history
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4559 (car vip-replace1-history) ; default
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4560 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4561 (query-replace
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4562 str
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4563 (vip-read-string-with-history
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4564 (format "Query replace `%s' with: " str)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4565 nil ; no initial
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4566 'vip-replace1-history
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4567 (car vip-replace1-history) ; default
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4568 ))))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4569
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4570
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4571 ;; marking
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4572
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4573 (defun vip-mark-beginning-of-buffer ()
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4574 "Mark beginning of buffer."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4575 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4576 (push-mark (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4577 (goto-char (point-min))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4578 (exchange-point-and-mark)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4579 (message "Mark set at the beginning of buffer"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4580
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4581 (defun vip-mark-end-of-buffer ()
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4582 "Mark end of buffer."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4583 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4584 (push-mark (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4585 (goto-char (point-max))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4586 (exchange-point-and-mark)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4587 (message "Mark set at the end of buffer"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4588
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4589 (defun vip-mark-point ()
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4590 "Set mark at point of buffer."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4591 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4592 (let ((char (vip-read-char-exclusive)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4593 (cond ((and (<= ?a char) (<= char ?z))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4594 (point-to-register (1+ (- char ?a))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4595 ((= char ?<) (vip-mark-beginning-of-buffer))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4596 ((= char ?>) (vip-mark-end-of-buffer))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4597 ((= char ?.) (vip-set-mark-if-necessary))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4598 ((= char ?,) (vip-cycle-through-mark-ring))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4599 ((= char ?D) (mark-defun))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4600 (t (error ""))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4601 )))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4602
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4603 ;; Algorithm: If first invocation of this command save mark on ring, goto
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4604 ;; mark, M0, and pop the most recent elt from the mark ring into mark,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4605 ;; making it into the new mark, M1.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4606 ;; Push this mark back and set mark to the original point position, p1.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4607 ;; So, if you hit '' or `` then you can return to p1.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4608 ;;
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4609 ;; If repeated command, pop top elt from the ring into mark and
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4610 ;; jump there. This forgets the position, p1, and puts M1 back into mark.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4611 ;; Then we save the current pos, which is M0, jump to M1 and pop M2 from
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4612 ;; the ring into mark. Push M2 back on the ring and set mark to M0.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4613 ;; etc.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4614 (defun vip-cycle-through-mark-ring ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4615 "Visit previous locations on the mark ring.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4616 One can use `` and '' to temporarily jump 1 step back."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4617 (let* ((sv-pt (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4618 ;; if repeated `m,' command, pop the previously saved mark.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4619 ;; Prev saved mark is actually prev saved point. It is used if the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4620 ;; user types `` or '' and is discarded
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4621 ;; from the mark ring by the next `m,' command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4622 ;; In any case, go to the previous or previously saved mark.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4623 ;; Then push the current mark (popped off the ring) and set current
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4624 ;; point to be the mark. Current pt as mark is discarded by the next
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4625 ;; m, command.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4626 (if (eq last-command 'vip-cycle-through-mark-ring)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4627 ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4628 ;; save current mark if the first iteration
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4629 (setq mark-ring (delete (vip-mark-marker) mark-ring))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4630 (if (mark t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4631 (push-mark (mark t) t)) )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4632 (pop-mark)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4633 (set-mark-command 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4634 ;; don't duplicate mark on the ring
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4635 (setq mark-ring (delete (vip-mark-marker) mark-ring))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4636 (push-mark sv-pt t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4637 (vip-deactivate-mark)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4638 (setq this-command 'vip-cycle-through-mark-ring)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4639 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4640
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4641
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4642 (defun vip-goto-mark (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4643 "Go to mark."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4644 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4645 (let ((char (read-char))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4646 (com (vip-getcom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4647 (vip-goto-mark-subr char com nil)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4648
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4649 (defun vip-goto-mark-and-skip-white (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4650 "Go to mark and skip to first non-white character on line."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4651 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4652 (let ((char (read-char))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4653 (com (vip-getCom arg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4654 (vip-goto-mark-subr char com t)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4655
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4656 (defun vip-goto-mark-subr (char com skip-white)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4657 (if (eobp)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4658 (if (bobp)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4659 (error "Empty buffer")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4660 (backward-char 1)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4661 (cond ((vip-valid-register char '(letter))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4662 (let* ((buff (current-buffer))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4663 (reg (1+ (- char ?a)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4664 (text-marker (get-register reg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4665 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4666 (if (not (vip-valid-marker text-marker))
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
4667 (error (format vip-EmptyTextmarker char)))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4668 (if (and (vip-same-line (point) vip-last-jump)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4669 (= (point) vip-last-jump-ignore))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4670 (push-mark vip-last-jump t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4671 (push-mark nil t)) ; no msg
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4672 (vip-register-to-point reg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4673 (setq vip-last-jump (point-marker))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4674 (cond (skip-white
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4675 (back-to-indentation)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4676 (setq vip-last-jump-ignore (point))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4677 (if com
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4678 (if (equal buff (current-buffer))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4679 (vip-execute-com (if skip-white
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4680 'vip-goto-mark-and-skip-white
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4681 'vip-goto-mark)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4682 nil com)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4683 (switch-to-buffer buff)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4684 (goto-char vip-com-point)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4685 (vip-change-state-to-vi)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4686 (error "")))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4687 ((and (not skip-white) (= char ?`))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4688 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4689 (if (and (vip-same-line (point) vip-last-jump)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4690 (= (point) vip-last-jump-ignore))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4691 (goto-char vip-last-jump))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4692 (if (= (point) (mark t)) (pop-mark))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4693 (exchange-point-and-mark)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4694 (setq vip-last-jump (point-marker)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4695 vip-last-jump-ignore 0)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4696 (if com (vip-execute-com 'vip-goto-mark nil com)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4697 ((and skip-white (= char ?'))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4698 (if com (vip-move-marker-locally 'vip-com-point (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4699 (if (and (vip-same-line (point) vip-last-jump)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4700 (= (point) vip-last-jump-ignore))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4701 (goto-char vip-last-jump))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4702 (if (= (point) (mark t)) (pop-mark))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4703 (exchange-point-and-mark)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4704 (setq vip-last-jump (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4705 (back-to-indentation)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4706 (setq vip-last-jump-ignore (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4707 (if com (vip-execute-com 'vip-goto-mark-and-skip-white nil com)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4708 (t (error vip-InvalidTextmarker char))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4709
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4710 (defun vip-insert-tab ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4711 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4712 (insert-tab))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4713
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4714 (defun vip-exchange-point-and-mark ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4715 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4716 (exchange-point-and-mark)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4717 (back-to-indentation))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4718
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4719 ;; Input Mode Indentation
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4720
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4721 (defun vip-forward-indent ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4722 "Indent forward -- `C-t' in Vi."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4723 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4724 (setq vip-cted t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4725 (indent-to (+ (current-column) vip-shift-width)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4726
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4727 (defun vip-backward-indent ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4728 "Backtab, C-d in VI"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4729 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4730 (if vip-cted
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4731 (let ((p (point)) (c (current-column)) bol (indent t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4732 (if (vip-looking-back "[0^]")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4733 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4734 (if (= ?^ (preceding-char)) (setq vip-preserve-indent t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4735 (delete-backward-char 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4736 (setq p (point))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4737 (setq indent nil)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4738 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4739 (beginning-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4740 (setq bol (point)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4741 (if (re-search-backward "[^ \t]" bol 1) (forward-char))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4742 (delete-region (point) p)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4743 (if indent
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4744 (indent-to (- c vip-shift-width)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4745 (if (or (bolp) (vip-looking-back "[^ \t]"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4746 (setq vip-cted nil)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4747
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4748 (defun vip-autoindent ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4749 "Auto Indentation, Vi-style."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4750 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4751 (let ((col (current-indentation)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4752 (if (not vip-preserve-indent)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4753 (setq vip-current-indent col)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4754 (setq vip-preserve-indent nil))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4755 ;; don't leave whitespace lines around
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
4756 (if (memq last-command
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
4757 '(vip-autoindent
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
4758 vip-open-line vip-Open-line
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
4759 vip-replace-state-exit-cmd))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4760 (indent-to-left-margin))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4761 (newline 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4762 (if vip-auto-indent
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4763 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4764 (setq vip-cted t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4765 (indent-to vip-current-indent)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4766
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4767
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4768 ;; Viewing registers
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4769
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4770 (defun vip-ket-function (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4771 "Function called by \], the ket. View registers and call \]\]."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4772 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4773 (let ((reg (read-char)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4774 (cond ((vip-valid-register reg '(letter Letter))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4775 (view-register (downcase reg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4776 ((vip-valid-register reg '(digit))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4777 (let ((text (current-kill (- reg ?1) 'do-not-rotate)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4778 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4779 (set-buffer (get-buffer-create "*Output*"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4780 (delete-region (point-min) (point-max))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4781 (insert (format "Register %c contains the string:\n" reg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4782 (insert text)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4783 (goto-char (point-min)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4784 (display-buffer "*Output*")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4785 ((= ?\] reg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4786 (vip-next-heading arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4787 (t (error
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4788 vip-InvalidRegister reg)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4790 (defun vip-brac-function (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4791 "Function called by \[, the brac. View textmarkers and call \[\["
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4792 (interactive "P")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4793 (let ((reg (read-char)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4794 (cond ((= ?\[ reg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4795 (vip-prev-heading arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4796 ((= ?\] reg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4797 (vip-heading-end arg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4798 ((vip-valid-register reg '(letter))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4799 (let* ((val (get-register (1+ (- reg ?a))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4800 (buf (if (not val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4801 (error
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4802 (format vip-EmptyTextmarker reg))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4803 (marker-buffer val)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4804 (pos (marker-position val))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4805 line-no text (s pos) (e pos))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4806 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4807 (set-buffer (get-buffer-create "*Output*"))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4808 (delete-region (point-min) (point-max))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4809 (if (and buf pos)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4810 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4811 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4812 (set-buffer buf)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4813 (setq line-no (1+ (count-lines (point-min) val)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4814 (goto-char pos)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4815 (beginning-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4816 (if (re-search-backward "[^ \t]" nil t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4817 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4818 (beginning-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4819 (setq s (point))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4820 (goto-char pos)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4821 (forward-line 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4822 (if (re-search-forward "[^ \t]" nil t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4823 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4824 (end-of-line)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4825 (setq e (point))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4826 (setq text (buffer-substring s e))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4827 (setq text (format "%s<%c>%s"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4828 (substring text 0 (- pos s))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4829 reg (substring text (- pos s)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4830 (insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4831 (format
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4832 "Textmarker `%c' is in buffer `%s' at line %d.\n"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4833 reg (buffer-name buf) line-no))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4834 (insert (format "Here is some text around %c:\n\n %s"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4835 reg text)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4836 (insert (format vip-EmptyTextmarker reg)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4837 (goto-char (point-min)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4838 (display-buffer "*Output*")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4839 (t (error vip-InvalidTextmarker reg)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4840
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4841
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4842
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4843 ;; commands in insertion mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4844
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4845 (defun vip-delete-backward-word (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4846 "Delete previous word."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4847 (interactive "p")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4848 (save-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4849 (push-mark nil t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4850 (backward-word arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4851 (delete-region (point) (mark t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4852 (pop-mark)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4853
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4854
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4855 (defun vip-set-expert-level (&optional dont-change-unless)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4856 "Sets the expert level for a Viper user.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4857 Can be called interactively to change (temporarily or permanently) the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4858 current expert level.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4859
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4860 The optional argument DONT-CHANGE-UNLESS if not nil, says that
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4861 the level should not be changed, unless its current value is
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4862 meaningless (i.e., not one of 1,2,3,4,5).
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4863
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4864 User level determines the setting of Viper variables that are most
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4865 sensitive for VI-style look-and-feel."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4866
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4867 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4868
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4869 (if (not (numberp vip-expert-level)) (setq vip-expert-level 0))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4870
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4871 (save-window-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4872 (delete-other-windows)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4873 ;; if 0 < vip-expert-level < vip-max-expert-level
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4874 ;; & dont-change-unless = t -- use it; else ask
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4875 (vip-ask-level dont-change-unless))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4876
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4877 (setq vip-always t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4878 vip-ex-style-motion t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4879 vip-ex-style-editing-in-insert t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4880 vip-want-ctl-h-help nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4881
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4882 (cond
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4883 ;; a novice or a beginner
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4884 ((eq vip-expert-level 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4885 (global-set-key vip-toggle-key ;; in emacs-state
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4886 (if (vip-window-display-p)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4887 'vip-iconify
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4888 'suspend-emacs))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4889 (setq vip-no-multiple-ESC t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4890 vip-re-search t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4891 vip-vi-style-in-minibuffer t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4892 vip-search-wrap-around-t t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4893 vip-want-emacs-keys-in-vi nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4894 vip-want-emacs-keys-in-insert nil))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4895
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4896 ;; an intermediate to guru
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4897 ((and (> vip-expert-level 1) (< vip-expert-level 5))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4898 (setq vip-no-multiple-ESC (if (vip-window-display-p) t 'twice)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4899 vip-want-emacs-keys-in-vi t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4900 vip-want-emacs-keys-in-insert (> vip-expert-level 2))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4901
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4902 (if (eq vip-expert-level 4) ; respect user's ex-style motions
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4903 ; and vip-no-multiple-ESC
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4904 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4905 (setq-default vip-ex-style-editing-in-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4906 (cdr (assoc 'vip-ex-style-editing-in-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4907 vip-saved-user-settings))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4908 vip-ex-style-motion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4909 (cdr (assoc 'vip-ex-style-motion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4910 vip-saved-user-settings)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4911 (setq vip-ex-style-motion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4912 (cdr (assoc 'vip-ex-style-motion vip-saved-user-settings))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4913 vip-ex-style-editing-in-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4914 (cdr (assoc 'vip-ex-style-editing-in-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4915 vip-saved-user-settings))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4916 vip-re-search
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4917 (cdr (assoc 'vip-re-search vip-saved-user-settings))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4918 vip-no-multiple-ESC
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4919 (cdr (assoc 'vip-no-multiple-ESC
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4920 vip-saved-user-settings))))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4921
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4922 ;; A wizard
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4923 ;; Ideally, if 5 is selected, a buffer should pop up to let the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4924 ;; user toggle variable values.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4925 (t (setq-default vip-ex-style-editing-in-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4926 (cdr (assoc 'vip-ex-style-editing-in-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4927 vip-saved-user-settings))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4928 vip-ex-style-motion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4929 (cdr (assoc 'vip-ex-style-motion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4930 vip-saved-user-settings)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4931 (setq vip-want-ctl-h-help
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4932 (cdr (assoc 'vip-want-ctl-h-help vip-saved-user-settings))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4933 vip-always
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4934 (cdr (assoc 'vip-always vip-saved-user-settings))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4935 vip-no-multiple-ESC
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4936 (cdr (assoc 'vip-no-multiple-ESC vip-saved-user-settings))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4937 vip-ex-style-motion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4938 (cdr (assoc 'vip-ex-style-motion vip-saved-user-settings))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4939 vip-ex-style-editing-in-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4940 (cdr (assoc 'vip-ex-style-editing-in-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4941 vip-saved-user-settings))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4942 vip-re-search
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4943 (cdr (assoc 'vip-re-search vip-saved-user-settings))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4944 vip-want-emacs-keys-in-vi
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4945 (cdr (assoc 'vip-want-emacs-keys-in-vi
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4946 vip-saved-user-settings))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4947 vip-want-emacs-keys-in-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4948 (cdr (assoc 'vip-want-emacs-keys-in-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4949 vip-saved-user-settings)))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4950 (vip-set-mode-vars-for vip-current-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4951 (if (or vip-always
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4952 (and (> vip-expert-level 0) (> 5 vip-expert-level)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4953 (vip-set-hooks)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4954
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
4955 ;; Ask user expert level.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4956 (defun vip-ask-level (dont-change-unless)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4957 (let ((ask-buffer " *vip-ask-level*")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4958 level-changed repeated)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4959 (save-window-excursion
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4960 (switch-to-buffer ask-buffer)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4961
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4962 (or (eq this-command 'vip-set-expert-level)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4963 (and
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4964 (<= vip-expert-level vip-max-expert-level)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4965 (>= vip-expert-level 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4966 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4967 (insert "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4968
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4969 *** Important Notice for VIP users***
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4970
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4971 This is VIPER
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4972
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4973 @joke
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4974 Viper Is a Package for Emacs Rebels,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4975 a VI Plan for Emacs Rescue,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4976 and a venomous VI PERil.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4977 @end joke
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4978
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4979 Technically speaking, Viper is a new Vi emulator that replaces
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4980 the old VIP package.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4981
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4982 Viper emulates Vi much better than VIP. It also significantly
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4983 extends and improves upon Vi in many useful ways.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4984
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4985 Although many VIP settings in your ~/.vip are compatible with Viper,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4986 you may have to change some of them. Please refer to the documentation,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4987 which can be obtained by executing
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4988
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4989 :help
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4990
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4991 when Viper is in Vi state.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4992
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4993 If you will be so lucky as to find a bug, report it via the command
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4994
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4995 :submitReport
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4996
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4997 Type any key to continue... ")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4998
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4999 (read-char)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5000 (erase-buffer)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5001
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5002 (while (or (> vip-expert-level vip-max-expert-level)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5003 (< vip-expert-level 1)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5004 (null dont-change-unless))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5005 (erase-buffer)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5006 (if repeated
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5007 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5008 (message "Invalid user level")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5009 (beep 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5010 (setq repeated t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5011 (setq dont-change-unless t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5012 level-changed t)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5013 (insert "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5014 Please specify your level of familiarity with the venomous VI PERil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5015 (and the VI Plan for Emacs Rescue).
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5016 You can change it at any time by typing `M-x vip-set-expert-level RET'
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5017
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5018 1 -- BEGINNER: Almost all Emacs features are suppressed.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5019 Feels almost like straight Vi. File name completion and
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5020 command history in the minibuffer are thrown in as a bonus.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5021 To use Emacs productively, you must reach level 3 or higher.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5022 2 -- MASTER: C-c now has its standard Emacs meaning in Vi command state,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5023 so most Emacs commands can be used when Viper is in Vi state.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5024 Good progress---you are well on the way to level 3!
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5025 3 -- GRAND MASTER: Like 3, but most Emacs commands are available also
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5026 in Viper's insert state.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5027 4 -- GURU: Like 3, but user settings are respected for vip-no-multiple-ESC,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5028 vip-re-search, vip-ex-style-motion, & vip-ex-style-editing-in-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5029 variables. Adjust these settings to your taste.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5030 5 -- WIZARD: Like 4, but user settings are also respected for vip-always,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5031 vip-want-ctl-h-help, vip-want-emacs-keys-in-vi, and
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5032 vip-want-emacs-keys-in-insert. Adjust these to your taste.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5033
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5034 Please, specify your level now: ")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5035
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5036 (setq vip-expert-level (- (vip-read-char-exclusive) ?0))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5037 ) ; end while
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5038
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5039 ;; tell the user if level was changed
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5040 (and level-changed
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5041 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5042 (insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5043 (format "\n\n\n\n\n\t\tYou have selected user level %d"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5044 vip-expert-level))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5045 (if (y-or-n-p "Do you wish to make this change permanent? ")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5046 ;; save the setting for vip-expert-level
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5047 (vip-save-setting
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5048 'vip-expert-level
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5049 (format "Saving user level %d ..." vip-expert-level)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5050 vip-custom-file-name))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5051 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5052 (bury-buffer) ; remove ask-buffer from screen
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5053 (message "")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5054 )))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5055
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5056
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5057 (defun viper-version ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5058 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5059 (message "Viper version is %s" viper-version))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5060
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5061 (defalias 'vip-version 'viper-version)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5062
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5063 (defun vip-nil ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5064 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5065 (beep 1))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5066
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5067
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5068 ;; Returns t, if the string before point matches the regexp STR.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5069 (defsubst vip-looking-back (str)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5070 (and (save-excursion (re-search-backward str nil t))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5071 (= (point) (match-end 0))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5072
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5073
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5074
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5075 ;; if ENFORCE-BUFFER is not nil, error if CHAR is a marker in another buffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5076 (defun vip-register-to-point (char &optional enforce-buffer)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5077 "Like jump-to-register, but switches to another buffer in another window."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5078 (interactive "cViper register to point: ")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5079 (let ((val (get-register char)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5080 (cond
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5081 ((and (fboundp 'frame-configuration-p)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5082 (frame-configuration-p val))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5083 (set-frame-configuration val))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5084 ((window-configuration-p val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5085 (set-window-configuration val))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5086 ((vip-valid-marker val)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5087 (if (and enforce-buffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5088 (not (equal (current-buffer) (marker-buffer val))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5089 (error (concat vip-EmptyTextmarker " in this buffer")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5090 (1- (+ char ?a))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5091 (pop-to-buffer (marker-buffer val))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5092 (goto-char val))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5093 ((and (consp val) (eq (car val) 'file))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5094 (find-file (cdr val)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5095 (t
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5096 (error vip-EmptyTextmarker (1- (+ char ?a)))))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5097
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5098
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5099 (defun vip-save-kill-buffer ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5100 "Save then kill current buffer. "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5101 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5102 (if (< vip-expert-level 2)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5103 (save-buffers-kill-emacs)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5104 (save-buffer)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5105 (kill-buffer (current-buffer))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5106
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5107
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5108
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5109 ;;; Bug Report
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5110
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5111 (defun vip-submit-report ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5112 "Submit bug report on Viper."
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5113 (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5114 (let ((reporter-prompt-for-summary-p t)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5115 (vip-device-type (vip-device-type))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5116 color-display-p frame-parameters
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5117 minibuffer-emacs-face minibuffer-vi-face minibuffer-insert-face
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5118 varlist salutation window-config)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5119
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5120 ;; If mode info is needed, add variable to `let' and then set it below,
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5121 ;; like we did with color-display-p.
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5122 (setq color-display-p (if (vip-window-display-p)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5123 (vip-color-display-p)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5124 'non-x)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5125 minibuffer-vi-face (if (vip-window-display-p)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5126 (vip-get-face vip-minibuffer-vi-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5127 'non-x)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5128 minibuffer-insert-face (if (vip-window-display-p)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5129 (vip-get-face vip-minibuffer-insert-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5130 'non-x)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5131 minibuffer-emacs-face (if (vip-window-display-p)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5132 (vip-get-face vip-minibuffer-emacs-face)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5133 'non-x)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5134 frame-parameters (if (fboundp 'frame-parameters)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5135 (frame-parameters (selected-frame))))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5136
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5137 (setq varlist (list 'vip-vi-minibuffer-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5138 'vip-insert-minibuffer-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5139 'vip-vi-intercept-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5140 'vip-vi-local-user-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5141 'vip-vi-kbd-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5142 'vip-vi-global-user-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5143 'vip-vi-state-modifier-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5144 'vip-vi-diehard-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5145 'vip-vi-basic-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5146 'vip-replace-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5147 'vip-insert-intercept-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5148 'vip-insert-local-user-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5149 'vip-insert-kbd-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5150 'vip-insert-global-user-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5151 'vip-insert-state-modifier-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5152 'vip-insert-diehard-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5153 'vip-insert-basic-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5154 'vip-emacs-intercept-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5155 'vip-emacs-local-user-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5156 'vip-emacs-kbd-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5157 'vip-emacs-global-user-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5158 'vip-emacs-state-modifier-minor-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5159 'vip-automatic-iso-accents
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5160 'vip-want-emacs-keys-in-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5161 'vip-want-emacs-keys-in-vi
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5162 'vip-keep-point-on-undo
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5163 'vip-no-multiple-ESC
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5164 'vip-ESC-key
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5165 'vip-want-ctl-h-help
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5166 'vip-ex-style-editing-in-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5167 'vip-delete-backwards-in-replace
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5168 'vip-vi-style-in-minibuffer
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5169 'vip-vi-state-hooks
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5170 'vip-insert-state-hooks
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5171 'vip-replace-state-hooks
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5172 'vip-emacs-state-hooks
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5173 'ex-cycle-other-window
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5174 'ex-cycle-through-non-files
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5175 'vip-expert-level
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5176 'major-mode
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5177 'vip-device-type
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5178 'color-display-p
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5179 'frame-parameters
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5180 'minibuffer-vi-face
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5181 'minibuffer-insert-face
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5182 'minibuffer-emacs-face
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5183 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5184 (setq salutation "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5185 Congratulations! You may have unearthed a bug in Viper!
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5186 Please mail a concise, accurate summary of the problem to the address above.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5187
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5188 -------------------------------------------------------------------")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5189 (setq window-config (current-window-configuration))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5190 (with-output-to-temp-buffer " *vip-info*"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5191 (switch-to-buffer " *vip-info*")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5192 (delete-other-windows)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5193 (princ "
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5194 PLEASE FOLLOW THESE PROCEDURES
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5195 ------------------------------
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5196
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5197 Before reporting a bug, please verify that it is related to Viper, and is
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5198 not cause by other packages you are using.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5199
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5200 Don't report compilation warnings, unless you are certain that there is a
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5201 problem. These warnings are normal and unavoidable.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5202
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5203 Please note that users should not modify variables and keymaps other than
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5204 those advertised in the manual. Such `customization' is likely to crash
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5205 Viper, as it would any other improperly customized Emacs package.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5206
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5207 If you are reporting an error message received while executing one of the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5208 Viper commands, type:
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5209
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5210 M-x set-variable <Return> debug-on-error <Return> t <Return>
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5211
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5212 Then reproduce the error. The above command will cause Emacs to produce a
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5213 back trace of the execution that leads to the error. Please include this
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5214 trace in your bug report.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5215
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5216 If you believe that one of Viper's commands goes into an infinite loop
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5217 \(e.g., Emacs freezes\), type:
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5218
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5219 M-x set-variable <Return> debug-on-quit <Return> t <Return>
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5220
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5221 Then reproduce the problem. Wait for a few seconds, then type C-g to abort
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5222 the current command. Include the resulting back trace in the bug report.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5223
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5224 Mail anyway (y or n)? ")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5225 (if (y-or-n-p "Mail anyway? ")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5226 ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5227 (set-window-configuration window-config)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5228 (error "Bug report aborted")))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5229
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5230 (require 'reporter)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5231 (set-window-configuration window-config)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5232
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5233 (reporter-submit-bug-report "kifer@cs.sunysb.edu"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5234 (vip-version)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5235 varlist
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5236 nil 'delete-other-windows
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5237 salutation)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5238 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5239
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5240
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5241
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5242
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5243 ;; Smoothes out the difference between Emacs' unread-command-events
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5244 ;; and XEmacs unread-command-event. Arg is a character, an event, a list of
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5245 ;; events or a sequence of keys.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5246 ;;
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5247 ;; Due to the way unread-command-events in Emacs (not XEmacs), a non-event
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5248 ;; symbol in unread-command-events list may cause Emacs to turn this symbol
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5249 ;; into an event. Below, we delete nil from event lists, since nil is the most
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5250 ;; common symbol that might appear in this wrong context.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5251 (defun vip-set-unread-command-events (arg)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5252 (if vip-emacs-p
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5253 (setq
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5254 unread-command-events
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5255 (let ((new-events
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5256 (cond ((eventp arg) (list arg))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5257 ((listp arg) arg)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5258 ((sequencep arg)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5259 (listify-key-sequence arg))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5260 (t (error
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5261 "vip-set-unread-command-events: Invalid argument, %S"
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5262 arg)))))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5263 (if (not (eventp nil))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5264 (setq new-events (delq nil new-events)))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5265 (append new-events unread-command-events)))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5266 ;; XEmacs
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5267 (setq
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5268 unread-command-events
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5269 (append
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5270 (cond ((numberp arg) (list (character-to-event arg)))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5271 ((eventp arg) (list arg))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5272 ((stringp arg) (mapcar 'character-to-event arg))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5273 ((vectorp arg) (append arg nil)) ; turn into list
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
5274 ((listp arg) (vip-eventify-list-xemacs arg))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5275 (t (error
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5276 "vip-set-unread-command-events: Invalid argument, %S" arg)))
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5277 unread-command-events))))
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
5278
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
5279 ;; list is assumed to be a list of events of characters
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
5280 (defun vip-eventify-list-xemacs (lis)
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
5281 (mapcar
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
5282 (function (lambda (elt)
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
5283 (cond ((numberp elt) (character-to-event elt))
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
5284 ((eventp elt) elt)
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
5285 (t (error
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
5286 "vip-eventify-list-xemacs: can't convert to event, %S"
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
5287 elt)))))
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
5288 lis))
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
5289
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5290
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5291
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5292 ;;; Bring in the rest of the files
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5293 (require 'viper-mous)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5294 (require 'viper-macs)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5295 (require 'viper-ex)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5296
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5297
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5298
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5299 ;; The following is provided for compatibility with older VIP's
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5300
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5301 (defalias 'vip-change-mode-to-vi 'vip-change-state-to-vi)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5302 (defalias 'vip-change-mode-to-insert 'vip-change-state-to-insert)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5303 (defalias 'vip-change-mode-to-emacs 'vip-change-state-to-emacs)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5304
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5305
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5306
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5307 ;;; Load .vip and set up hooks
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5308
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5309 ;; This hook designed to enable Vi-style editing in comint-based modes."
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5310 (defun vip-comint-mode-hook ()
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5311 (setq vip-add-newline-at-eob nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5312 (setq vip-ex-style-editing-in-insert nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5313 vip-ex-style-motion nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5314 (vip-add-local-keys 'vi-state
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5315 '(("\C-m" . comint-send-input) ; return
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5316 ("\C-d" . comint-delchar-or-maybe-eof))) ; \C-d
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5317 (vip-add-local-keys 'insert-state
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5318 '(("\C-m" . comint-send-input) ; return
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5319 ("\C-d" . comint-delchar-or-maybe-eof))) ; \C-d
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5320 )
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5321
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5322
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5323 ;; This sets major mode hooks to make them come up in vip-state.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5324 (defun vip-set-hooks ()
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5325
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5326 ;; It is of course a misnomer to call viper-mode a `major mode'.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5327 ;; However, this has the effect that if the user didn't specify the
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5328 ;; default mode, new buffers that fall back on the default will come up
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5329 ;; in Fundamental Mode and Vi state.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5330 (setq default-major-mode 'viper-mode)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5331
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5332 ;; The following major modes should come up in vi-state
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5333 (defadvice fundamental-mode (after vip-fundamental-mode-ad activate)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5334 "Run `vip-change-state-to-vi' on entry."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5335 (vip-change-state-to-vi))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5336
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5337 (defvar help-mode-hook nil)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5338 (add-hook 'help-mode-hook 'viper-mode)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5339
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5340 (defvar emacs-lisp-mode-hook nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5341 (add-hook 'emacs-lisp-mode-hook 'viper-mode)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5342
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5343 (defvar html-mode-hook nil)
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5344 (add-hook 'html-mode-hook 'viper-mode)
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5345
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5346 (defvar lisp-mode-hook nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5347 (add-hook 'lisp-mode-hook 'viper-mode)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5348
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5349 (defvar bibtex-mode-hook nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5350 (add-hook 'bibtex-mode-hook 'viper-mode)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5351
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5352 (defvar cc-mode-hook nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5353 (add-hook 'cc-mode-hook 'viper-mode)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5354
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5355 (defvar c-mode-hook nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5356 (add-hook 'c-mode-hook 'viper-mode)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5357
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5358 (defvar c++-mode-hook nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5359 (add-hook 'c++-mode-hook 'viper-mode)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5360
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5361 (defvar lisp-interaction-mode-hook nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5362 (add-hook 'lisp-interaction-mode-hook 'viper-mode)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5363
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5364 (defvar text-mode-hook nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5365 (add-hook 'text-mode-hook 'viper-mode)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5366
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5367 (add-hook 'completion-list-mode-hook 'viper-mode)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5368 (add-hook 'compilation-mode-hook 'viper-mode)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5369
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5370 (defvar emerge-startup-hook nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5371 (add-hook 'emerge-startup-hook 'vip-change-state-to-emacs)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5372 ;; Run vip-change-state-to-vi after quitting emerge.
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5373 (vip-eval-after-load
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5374 "emerge"
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5375 '(defadvice emerge-quit (after vip-emerge-advice activate)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5376 "Run `vip-change-state-to-vi' after quitting emerge."
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5377 (vip-change-state-to-vi)))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5378 ;; In case Emerge was loaded before Viper.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5379 (defadvice emerge-quit (after vip-emerge-advice activate)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5380 "Run `vip-change-state-to-vi' after quitting emerge."
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5381 (vip-change-state-to-vi))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5382
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5383 (vip-eval-after-load
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5384 "asm-mode"
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5385 '(defadvice asm-mode (after vip-asm-mode-ad activate)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5386 "Run `vip-change-state-to-vi' on entry."
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5387 (vip-change-state-to-vi)))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5388
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5389 ;; passwd.el sets up its own buffer, which turns up in Vi mode,
12691
7bd050135516 (vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12203
diff changeset
5390 ;; thus overriding the local map. We don't need Vi mode here.
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5391 (vip-eval-after-load
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5392 "passwd"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5393 '(defadvice read-passwd-1 (before vip-passwd-ad activate)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5394 "Switch to emacs state while reading password."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5395 (vip-change-state-to-emacs)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5396
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5397 ;; Emacs shell, ange-ftp, and comint-based modes
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5398 (defvar comint-mode-hook nil)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5399 (add-hook 'comint-mode-hook 'vip-change-state-to-insert)
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5400 (add-hook 'comint-mode-hook 'vip-comint-mode-hook)
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5401
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5402 ;; Shell scripts
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5403 (defvar sh-mode-hook nil)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5404 (add-hook 'sh-mode-hook 'viper-mode)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5405
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5406 ;; Dired
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5407 ;; This is only necessary when the user uses vip-modify-major-mode
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5408 (add-hook 'dired-mode-hook 'vip-change-state-to-emacs)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5409
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5410 (if vip-emacs-p
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5411 (progn
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5412 (defvar view-mode-hook nil
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5413 "View hook. Run after view mode.")
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5414 (add-hook 'view-mode-hook 'vip-change-state-to-emacs))
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5415 (defadvice view-minor-mode (after vip-view-ad activate)
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5416 "Switch to Emacs state in View mode."
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5417 (vip-change-state-to-emacs))
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5418 (defvar view-hook nil
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5419 "View hook. Run after view mode.")
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5420 (add-hook 'view-hook 'vip-change-state-to-emacs))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5421
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5422 ;; For VM users.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5423 ;; Put summary and other VM buffers in Emacs state.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5424 (defvar vm-mode-hooks nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5425 "This hook is run after vm is started.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5426 (defvar vm-summary-mode-hooks nil
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5427 "This hook is run after vm switches to summary mode.")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5428 (add-hook 'vm-mode-hooks 'vip-change-state-to-emacs)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5429 (add-hook 'vm-summary-mode-hooks 'vip-change-state-to-emacs)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5430
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5431 ;; For RMAIL users.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5432 ;; Put buf in Emacs state after edit.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5433 (vip-eval-after-load
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5434 "rmailedit"
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5435 '(defadvice rmail-cease-edit (after vip-rmail-advice activate)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5436 "Switch to emacs state when done editing message."
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5437 (vip-change-state-to-emacs)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5438 ;; In case RMAIL was loaded before Viper.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5439 (defadvice rmail-cease-edit (after vip-rmail-advice activate)
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5440 "Switch to emacs state when done editing message."
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5441 (vip-change-state-to-emacs))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5442 ) ; vip-set-hooks
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5443
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5444 ;; Set some useful macros
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5445 ;; These must be before we load .vip, so the user can unrecord them.
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5446
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5447 ;; repeat the 2nd previous command without rotating the command history
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5448 (vip-record-kbd-macro
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5449 (vector vip-repeat-from-history-key '\1) 'vi-state
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5450 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't)
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5451 ;; repeat the 3d previous command without rotating the command history
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5452 (vip-record-kbd-macro
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5453 (vector vip-repeat-from-history-key '\2) 'vi-state
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5454 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't)
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5455
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5456 ;; toggle case sensitivity in search
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5457 (vip-record-kbd-macro
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5458 "//" 'vi-state
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5459 [1 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 't)
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5460 ;; toggle regexp/vanila search
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5461 (vip-record-kbd-macro
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5462 "///" 'vi-state
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5463 [2 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 't)
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5464
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5465
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5466 ;; ~/.vip is loaded if it exists
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5467 (if (and (file-exists-p vip-custom-file-name)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5468 (not noninteractive))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5469 (load vip-custom-file-name))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5470
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5471 ;; VIP compatibility: merge whatever the user has in vip-mode-map into
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5472 ;; Viper's basic map.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5473 (vip-add-keymap vip-mode-map vip-vi-global-user-map)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5474
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5475
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5476 ;; Applying Viper customization -- runs after (load .vip)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5477
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5478 ;; Save user settings or Viper defaults for vars controled by vip-expert-level
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5479 (setq vip-saved-user-settings
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5480 (list (cons 'vip-want-ctl-h-help vip-want-ctl-h-help)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5481 (cons 'vip-always vip-always)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5482 (cons 'vip-no-multiple-ESC vip-no-multiple-ESC)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5483 (cons 'vip-ex-style-motion vip-ex-style-motion)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5484 (cons 'vip-ex-style-editing-in-insert
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5485 vip-ex-style-editing-in-insert)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5486 (cons 'vip-want-emacs-keys-in-vi vip-want-emacs-keys-in-vi)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5487 (cons 'vip-want-emacs-keys-in-insert vip-want-emacs-keys-in-insert)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5488 (cons 'vip-re-search vip-re-search)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5489
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5490
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5491 (vip-set-minibuffer-style)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5492 (vip-set-minibuffer-faces)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5493 (vip-set-search-face)
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5494 (if vip-buffer-search-char
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5495 (vip-buffer-search-enable))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5496
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5497 ;;; Familiarize Viper with some minor modes that have their own keymaps
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5498 (vip-harness-minor-mode "compile")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5499 (vip-harness-minor-mode "outline")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5500 (vip-harness-minor-mode "allout")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5501 (vip-harness-minor-mode "xref")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5502 (vip-harness-minor-mode "lmenu")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5503 (vip-harness-minor-mode "vc")
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5504 (vip-harness-minor-mode "ltx-math") ; LaTeX-math-mode in AUC-TeX
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5505 (vip-harness-minor-mode "latex") ; which is in one of these two files
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5506 (vip-harness-minor-mode "cyrillic")
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5507 (vip-harness-minor-mode "russian")
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5508 (vip-harness-minor-mode "view-less")
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5509
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5510
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5511 ;; Intercept maps could go in viper-keym.el
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5512 ;; We keep them here in case someone redefines them in ~/.vip
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5513
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5514 (define-key vip-vi-intercept-map vip-ESC-key 'vip-intercept-ESC-key)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5515 (define-key vip-insert-intercept-map vip-ESC-key 'vip-intercept-ESC-key)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5516
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5517 ;; This is taken care of by vip-insert-global-user-map.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5518 ;;(define-key vip-replace-map vip-ESC-key 'vip-intercept-ESC-key)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5519
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5520 (define-key vip-insert-intercept-map vip-toggle-key 'vip-alternate-ESC)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5521 ;; The default vip-toggle-key is \C-z; for the novice, it suspends or
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5522 ;; iconifies Emacs
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5523 (define-key vip-vi-intercept-map vip-toggle-key
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5524 '(lambda () (interactive)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5525 (if (and (< vip-expert-level 2) (equal vip-toggle-key "\C-z"))
12137
e6af973190dc (vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents: 11255
diff changeset
5526 (if (vip-window-display-p) (vip-iconify) (suspend-emacs))
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5527 (vip-change-state-to-emacs))))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5528
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5529 (define-key vip-emacs-intercept-map vip-toggle-key 'vip-change-state-to-vi)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5530
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5531
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5532 (if (or vip-always
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5533 (and (< vip-expert-level 5) (> vip-expert-level 0)))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5534 (vip-set-hooks))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5535
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5536 ;; Let all minor modes take effect after loading
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5537 ;; this may not be enough, so we also set default minor-mode-alist.
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5538 ;; Without setting the default, new buffers that come up in emacs mode have
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5539 ;; minor-mode-map-alist = nil, unless we call vip-change-state-*
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5540 (if (eq vip-current-state 'emacs-state)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5541 (progn
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5542 (vip-change-state-to-emacs)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5543 (setq-default minor-mode-map-alist minor-mode-map-alist)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5544 ))
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5545
12900
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5546
7a7b8d42bdec * viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents: 12855
diff changeset
5547 (run-hooks 'vip-load-hooks) ; the last chance to change something
10789
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5548
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5549 (provide 'viper)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5550 (provide 'vip19)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5551 (provide 'vip)
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5552
af7c0bb1059f Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5553 ;;; viper.el ends here