;; This avoids a hang of `cus-test-apropos' in 21.2.
;; (add-to-list 'cus-test-skip-list 'sh-alias-alist)
-(defvar viper-mode)
-(or noninteractive
- ;; Never Viperize.
- (setq viper-mode nil))
-
;; Don't create a file `save-place-file'.
(eval-after-load "saveplace"
'(remove-hook 'kill-emacs-hook 'save-place-kill-emacs-hook))
modus-themes newsticker nxml-mode octave-mode org pcl-cvs pgg \
rcirc reftex remember sasl sc ses sieve smtpmail \
speedbar todo-mode tramp transient url use-package \
- viper vtable widget woman
+ vtable widget woman
## Info files to install on current platform.
INFO_INSTALL = $(INFO_COMMON) $(DOCMISC_W32)
+++ /dev/null
-% -*-texinfo-*-
-\input texinfo
-
-@comment Using viper.info instead of viper in setfilename breaks DOS.
-@comment @setfilename viper
-@comment @setfilename viper.info
-@setfilename ../../info/viper.info
-@include docstyle.texi
-
-@copying
-Copyright @copyright{} 1995--2025 Free Software Foundation, Inc.
-
-@quotation
-Permission is granted to copy, distribute and/or modify this document
-under the terms of the GNU Free Documentation License, Version 1.3 or
-any later version published by the Free Software Foundation; with no
-Invariant Sections, with the Front-Cover Texts being ``A GNU Manual'',
-and with the Back-Cover Texts as in (a) below. A copy of the license
-is included in the section entitled ``GNU Free Documentation License''.
-
-(a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
-modify this GNU manual.''
-@end quotation
-@end copying
-
-@dircategory Emacs misc features
-@direntry
-* VIPER: (viper). A VI-emulation mode for Emacs.
-@end direntry
-
-@finalout
-
-@titlepage
-@title Viper Is a Package for Emacs Rebels
-@subtitle a Vi emulator for Emacs
-@subtitle July 2013, Viper Version 3.14.2
-
-@author Michael Kifer (Viper)
-@author Aamod Sane (VIP 4.4)
-@author Masahiko Sato (VIP 3.5)
-
-@page
-@vskip 0pt plus 1filll
-@insertcopying
-@end titlepage
-
-@contents
-
-@ifnottex
-@node Top
-@top Viper
-
-We believe that one or more of the following statements are adequate
-descriptions of Viper:
-
-@example
-Viper Is a Package for Emacs Rebels;
-it is a VI Plan for Emacs Rescue
-and/or a venomous VI PERil.
-@end example
-
-Technically speaking, Viper is a Vi emulation package for Emacs. It
-implements all Vi and Ex commands, occasionally improving on them and
-adding many new features. It gives the user the best of both worlds: Vi
-keystrokes for editing combined with the power of the Emacs environment.
-
-Viper emulates Vi at several levels, from the one that closely follows Vi
-conventions to the one that departs from many of them. It has many
-customizable options, which can be used to tailor Viper to the work habits
-of various users.
-This manual describes Viper, concentrating on the differences from Vi and
-new features of Viper.
-
-Viper, formerly known as VIP-19, was written by Michael Kifer. It is based
-on VIP version 3.5 by Masahiko Sato and VIP version 4.4 by Aamod Sane.
-About 15% of the code still comes from those older packages.
-
-Viper is intended to be usable without reading this manual; the defaults
-are set to make Viper as close to Vi as possible. At startup, Viper will
-try to set the most appropriate default environment for you, based on
-your familiarity with Emacs. It will also tell you the basic GNU Emacs window
-management commands to help you start immediately.
-
-Although this manual explains how to customize Viper, some basic
-familiarity with Emacs Lisp is a plus.
-
-It is recommended that you read the Overview node. The other nodes may
-be visited as needed.
-
-Comments and bug reports are welcome.
-@code{kifer@@cs.stonybrook.edu} is the current address for Viper bug reports.
-Please use the Ex command @kbd{:submitReport} for this purpose.
-
-@insertcopying
-@end ifnottex
-
-@menu
-* Overview:: Read for a smoother start
-* Improvements over Vi:: New features, Improvements
-* Customization:: How to customize Viper
-* Commands:: Vi and Ex Commands
-* GNU Free Documentation License:: The license for this documentation.
-* Acknowledgments::
-* Key Index:: Index of Vi and Ex Commands
-* Function Index:: Index of Viper Functions
-* Variable Index:: Index of Viper Variables
-* Package Index:: Index of Packages Mentioned in this Document
-* Concept Index:: Vi, Ex and Emacs concepts
-@end menu
-@iftex
-@unnumbered Introduction
-
-We believe that one or more of the following statements are adequate
-descriptions of Viper:
-
-@example
-Viper Is a Package for Emacs Rebels;
-it is a VI Plan for Emacs Rescue
-and/or a venomous VI PERil.
-@end example
-
-Viper is a Vi emulation package for Emacs. Viper contains virtually all
-of Vi and Ex functionality and much more. It gives you the best of both
-worlds: Vi keystrokes for editing combined with the GNU Emacs
-environment. Viper also fixes some common complaints with Vi commands.
-This manual describes Viper, concentrating on the differences from Vi
-and on the new features of Viper.
-
-Viper was written by Michael Kifer. It is based on VIP version 3.5 by
-Masahiko Sato and VIP version 4.4 by Aamod Sane. About 15% of the code
-still comes from those older packages.
-
-Viper is intended to be usable out of the box, without reading this manual;
-the defaults are set to make Viper as close to Vi as possible. At
-startup, Viper will attempt to set the most appropriate default environment
-for you, based on your familiarity with Emacs. It will also tell you the
-basic GNU Emacs window management commands to help you start immediately.
-
-Although this manual explains how to customize Viper, some basic
-familiarity with Emacs Lisp is a plus.
-
-It is recommended that you read the chapter Overview. The other chapters
-will be useful for customization and advanced usage.
-
-You should also learn to use the Info on-line hypertext manual system that
-comes with Emacs. This manual can be read as an Info file. Try the command
-@kbd{@key{ESC} x info} with vanilla Emacs sometime.
-
-Comments and bug reports are welcome.
-@code{kifer@@cs.stonybrook.edu} is the current address for Viper bug reports.
-Please use the Ex command @kbd{:submitReport} for this purpose.
-
-@end iftex
-
-@node Overview
-@chapter Overview of Viper
-
-Viper is a Vi emulation on top of Emacs. At the same time, Viper provides a
-virtually unrestricted access to Emacs facilities. Perfect compatibility
-with Vi is possible but not desirable. This chapter tells you about the
-Emacs ideas that you should know about, how to use Viper within Emacs and
-some incompatibilities.
-
-This manual is written with the assumption that you are an experienced Vi
-user who wants to switch to Emacs while retaining the ability to edit files
-Vi style. Incredible as it might seem, there are experienced Emacs users
-who use Viper as a backdoor into the superior (as every Vi user already knows)
-world of Vi! These users are well familiar with Emacs bindings and prefer them
-in some cases, especially in the Vi Insert state. John Hawkins
-<jshawkin@@eecs.umich.edu> has provided a set of customizations, which
-enables additional Emacs bindings under Viper. These customizations can be
-included in your @file{~/.emacs.d/viper} file and are found at the
-following URL: @file{http://traeki.freeshell.org/files/viper-sample}.
-
-@menu
-* Emacs Preliminaries:: Basic concepts in Emacs.
-* Loading Viper:: Loading and Preliminary Configuration.
-* States in Viper:: Viper has four states orthogonal to Emacs
- modes.
-* The Minibuffer:: Command line in Emacs.
-* Multiple Files in Viper:: True multiple file handling.
-* Unimplemented Features:: That are unlikely to be implemented.
-@end menu
-
-@node Emacs Preliminaries
-@section Emacs Preliminaries
-
-@cindex buffer
-@cindex point
-@cindex mark
-@cindex text
-@cindex looking at
-@cindex end (of buffer)
-@cindex end (of line)
-@cindex region
-
-Emacs can edit several files at once. A file in Emacs is placed in a
-@dfn{buffer} that usually has the same name as the file. Buffers are also used
-for other purposes, such as shell interfaces, directory editing, etc.
-@xref{Dired,,Directory Editor,emacs,The
-GNU Emacs Manual}, for an example.
-
-A buffer has a distinguished position called the @dfn{point}.
-A @dfn{point} is always between 2 characters, and is @dfn{looking at}
-the right hand character. The cursor is positioned on the right hand
-character. Thus, when the @dfn{point} is looking at the end-of-line,
-the cursor is on the end-of-line character, i.e., beyond the last
-character on the line. This is the default Emacs behavior.
-
-The default settings of Viper try to mimic the behavior of Vi, preventing
-the cursor from going beyond the last character on the line. By using
-Emacs commands directly (such as those bound to arrow keys), it is possible
-to get the cursor beyond the end-of-line. However, this won't (or
-shouldn't) happen if you restrict yourself to standard Vi keys, unless you
-modify the default editing style. @xref{Customization}.
-
-In addition to the @dfn{point}, there is another distinguished buffer
-position called the @dfn{mark}. @xref{Mark,,Mark,emacs,The GNU Emacs
-manual}, for more info on the mark. The text between the @dfn{point} and
-the @dfn{mark} is called the @dfn{region} of the buffer. For the Viper
-user, this simply means that in addition to the Vi textmarkers a--z, there
-is another marker called @dfn{mark}. This is similar to the unnamed Vi
-marker used by the jump commands @kbd{``} and @kbd{''}, which move the
-cursor to the position of the last absolute jump. Viper provides access to
-the region in most text manipulation commands as @kbd{r} and @kbd{R} suffix
-to commands that operate on text regions, e.g., @kbd{dr} to delete region,
-etc.
-
-Furthermore, Viper lets Ex-style commands to work on the current region.
-This is done by typing a digit argument before @kbd{:}. For instance,
-typing @kbd{1:} will prompt you with something like @emph{:123,135},
-assuming that the current region starts at line 123 and ends at line
-135. There is no need to type the line numbers, since Viper inserts them
-automatically in front of the Ex command.
-
-@xref{Basics}, for more info.
-
-@cindex window
-@cindex mode line
-@cindex buffer information
-@cindex Minibuffer
-@cindex command line
-@cindex buffer (modified)
-
-Emacs divides the screen into tiled @dfn{windows}. You can see the
-contents of a buffer through the window associated with the buffer. The
-cursor of the screen is positioned on the character after @dfn{point}.
-Every window has a @dfn{mode line} that displays information about the buffer.
-You can change the format of the mode
-line, but normally if you see @samp{**} at the beginning of a mode line it
-means that the buffer is @dfn{modified}. If you write out the contents of
-a buffer to a file, then the buffer will become not modified. Also if
-you see @samp{%%} at the beginning of the mode line, it means that the file
-associated with the buffer is write protected. The mode line will also
-show the buffer name and current major and minor modes (see below).
-A special buffer called @dfn{Minibuffer} is displayed as the last line
-in a minibuffer window. The minibuffer window is used for command input
-output. Viper uses minibuffer window for @kbd{/} and @kbd{:}
-commands.
-
-@cindex mode
-@cindex keymap
-@cindex local keymap
-@cindex global keymap
-@cindex major mode
-@cindex minor mode
-
-An Emacs buffer can have a @dfn{major mode} that customizes Emacs for
-editing text of a particular sort by changing the functionality of the keys.
-Keys are defined using a @dfn{keymap} that records the bindings between
-keystrokes and
-functions. The @dfn{global keymap} is common to all the
-buffers. Additionally, each buffer has its @dfn{local keymap} that determines the
-@dfn{mode} of the buffer. If a function is bound to some key in the local
-keymap then that function will be executed when you type the key.
-If no function is bound to a key in the
-local map, however, the function bound to the key in the global map
-will be executed. @xref{Major Modes,Major Modes,Major Modes,emacs,The
-GNU Emacs Manual}, for more information.
-
-A buffer can also have a @dfn{minor mode}. Minor modes are options that
-you can use or not. A buffer in @code{text-mode} can have
-@code{auto-fill-mode} as minor mode, which can be turned off or on at
-any time. In Emacs, a minor mode may have it own keymap,
-which overrides the local keymap when the minor mode is turned on. For
-more information, @pxref{Minor Modes,Minor Modes,Minor Modes,emacs,The
-GNU Emacs Manual}.
-
-@cindex Viper as minor mode
-@cindex Control keys
-@cindex Meta key
-
-Viper is implemented as a collection of minor modes. Different minor modes
-are involved when Viper emulates Vi command mode, Vi insert mode, etc.
-You can also turn Viper on and off at any time while in Vi command mode.
-@xref{States in Viper}, for
-more information.
-
-Emacs uses Control and Meta modifiers. These are denoted as C and M,
-e.g., @kbd{^Z} as @kbd{C-z} and @kbd{Meta-x} as @kbd{M-x}. The Meta key is
-usually located on each side of the Space bar; it is used in a manner
-similar to the Control key, e.g., @kbd{M-x} means typing @kbd{x} while
-holding the Meta key down. For keyboards that do not have a Meta key,
-@key{ESC} is used as Meta. Thus @kbd{M-x} is typed as @kbd{@key{ESC}
-x}. Viper uses @key{ESC} to switch from Insert state to Vi state. Therefore
-Viper defines @kbd{C-\} as its Meta key in Vi state. @xref{Vi State}, for
-more info.
-
-Emacs is structured as a Lisp interpreter around a C core. Emacs keys
-cause Lisp functions to be called. It is possible to call these
-functions directly, by typing @kbd{M-x function-name}.
-
-@node Loading Viper
-@section Loading Viper
-
-The most common way to load it automatically is to include the following
-lines (in the given order!):
-
-@lisp
-(setq viper-mode t)
-(require 'viper)
-@end lisp
-
-@noindent
-in your @file{~/.emacs} file. The @file{.emacs} file is placed in your
-home directory and it is be executed every time you invoke Emacs. This is
-the place where all general Emacs customization takes place. Emacs
-has an interactive interface (@kbd{M-x customize}), which simplifies
-the job of customization significantly.
-
-Viper also uses the file @file{~/.emacs.d/viper} for Viper-specific customization.
-The location of Viper customization file can be changed by setting the
-variable @code{viper-custom-file-name} in @file{.emacs} @emph{prior} to loading
-Viper.
-
-The latest versions of Emacs have an interactive customization facility,
-which allows you to (mostly) bypass the use of the @file{.emacs} and
-@code{viper-custom-file-name} files. You can reach this customization
-facility from within Viper's VI state by executing the Ex command
-@kbd{:customize}.
-
-Once invoked, Viper will arrange to bring up Emacs buffers in Vi state
-whenever this makes sense.
-@xref{Packages that Change Keymaps}, to find out when forcing Vi command state
-on a buffer may be counter-productive.
-
-Even if your @file{.emacs} file does not invoke Viper automatically,
-you can still load Viper and enter the Vi command state by typing the
-following from within Emacs:
-
-@lisp
-M-x viper-mode
-@end lisp
-
-When Emacs first comes up, if you have not specified a file on the
-command line, it will show the @file{*scratch*} buffer, in the
-@samp{Lisp Interaction} mode. After you invoke Viper, you can start
-editing files by using @kbd{:e}, @kbd{:vi}, or @kbd{v} commands.
-(@xref{File and Buffer Handling}, for more information on @kbd{v} and other
-new commands that, in many cases, are more convenient than @kbd{:e},
-@kbd{:vi}, and similar old-style Vi commands.)
-
-Finally, if at some point you would want to de-Viperize your running
-copy of Emacs after Viper has been loaded, the command @kbd{M-x
-viper-go-away} will do it for you. The function @code{toggle-viper-mode}
-toggles Viperization of Emacs on and off.
-
-@node States in Viper
-@section States in Viper
-
-@kindex C-z
-@kindex ESC
-@kindex i
-@cindex Emacs state
-@cindex Vi state
-@cindex Insert state
-@cindex Replace state
-@cindex Ex commands
-@findex viper-go-away
-@findex toggle-viper-mode
-
-Viper has four states, Emacs, Vi, Insert, and Replace.
-
-@table @samp
-@item Emacs state
-This is the state plain vanilla Emacs is normally in. After you have loaded
-Viper, @kbd{C-z} will normally take you to Vi command state. Another
-@kbd{C-z} will take you back to Emacs state. This toggle key can be
-changed, @pxref{Customization} You can also type @kbd{M-x viper-mode} to
-change to Vi state.
-
-
-For users who chose to set their user level to 1 at Viper setup time,
-switching to Emacs state is deliberately made harder in order to not
-confuse the novice user. In this case, @kbd{C-z} will either iconify Emacs
-(if Emacs runs as an application under X) or it will stop Emacs (if
-Emacs runs on a dumb terminal or in an Xterm window).
-
-@item Vi state
-This is the Vi command mode. Any of the Vi commands, such as @kbd{i, o, a},
-@dots{}, will take you to Insert state. All Vi commands may
-be used in this mode. Most Ex commands can also be used.
-For a full list of Ex commands supported by Viper, type
-@kbd{:} and then @key{TAB}. To get help on any issue, including the Ex
-commands, type @kbd{:help}. This will invoke Viper Info
-(if it is installed). Then typing @kbd{i} will prompt you for a topic to
-search in the index. Note: to search for Ex commands in the index, you
-should start them with a @kbd{:}, e.g., @kbd{:WW}.
-
-In Viper, Ex commands can be made to work on the current Emacs region.
-This is done by typing a digit argument before @kbd{:}.
-For instance, typing @kbd{1:} will prompt you with something like
-@emph{:123,135}, assuming that the current region starts at line 123 and
-ends at line 135. There is no need to type the line numbers, since Viper
-inserts them automatically in front of the Ex command.
-
-@item Insert state
-Insert state is the Vi insertion mode. @key{ESC} will take you back to
-Vi state. Insert state editing can be done, including auto-indentation. By
-default, Viper disables Emacs key bindings in Insert state.
-
-@item Replace state
-Commands like @kbd{cw} invoke the Replace state. When you cross the
-boundary of a replacement region (usually designated via a @samp{$} sign),
-it will automatically change to Insert state. You do not have to worry
-about it. The key bindings remain practically the same as in Insert
-state. If you type @key{ESC}, Viper will switch to Vi command mode, terminating the
-replacement state.
-@end table
-
-@cindex mode line
-
-The modes are indicated on the @dfn{mode line} as <E>, <I>, <V>, and <R>,
-so that the multiple modes do not confuse you. Most of your editing can be
-done in Vi and Insert states. Viper will try to make all new buffers be in Vi
-state, but sometimes they may come up in Emacs state. @kbd{C-z}
-will take you to Vi state in such a case. In some major modes, like Dired,
-Info, Gnus, etc., you should not switch to Vi state (and Viper will not
-attempt to do so) because these modes are not intended for text editing and
-many of the Vi keys have special meaning there. If you plan to read news,
-browse directories, read mail, etc., from Emacs (which you should start
-doing soon!), you should learn about the meaning of the various keys in
-those special modes (typing @kbd{C-h m} in a buffer provides
-help with key bindings for the major mode of that buffer).
-
-If you switch to Vi in Dired or similar modes, no harm is done. It is just
-that the special key bindings provided by those modes will be temporarily
-overshadowed by Viper's bindings. Switching back to Viper's Emacs state
-will revive the environment provided by the current major mode.
-
-States in Viper are orthogonal to Emacs major modes, such as C mode or Dired
-mode. You can turn Viper on and off for any Emacs state. When Viper is turned
-on, Vi state can be used to move around. In Insert state, the bindings for
-these modes can be accessed. For beginners (users at Viper levels 1 and 2),
-these bindings are suppressed in Insert state, so that new users are not
-confused by the Emacs states. Note that unless you allow Emacs bindings in
-Insert state, you cannot do many interesting things, like language
-sensitive editing. For the novice user (at Viper level 1), all major mode
-bindings are turned off in Vi state as well. This includes the bindings for
-key sequences that start with @kbd{C-c}, which practically means that all
-major mode bindings are unsupported. @xref{Customization}, to find out how
-to allow Emacs keys in Insert state.
-
-@menu
-* Emacs State:: This is the state you should learn more about when
- you get up to speed with Viper.
-* Vi State:: Vi commands are executed in this state.
-* Insert State:: You can enter text, and also can do sophisticated
- editing if you know enough Emacs commands.
-* Replace State:: Like Insert mode, but it is invoked via the
- replacement commands, such as cw, C, R, etc.
-@end menu
-
-@node Emacs State
-@subsection Emacs State
-
-@kindex C-z
-@cindex Emacs state
-
-
-You will be in this mode only by accident (hopefully). This is the state
-Emacs is normally in (imagine!!). Now leave it as soon as possible by
-typing @kbd{C-z}. Then you will be in Vi state (sigh of relief) :-).
-
-Emacs state is actually a Viperism to denote all the major and minor modes
-(@pxref{Emacs Preliminaries}) other than Viper that Emacs can be in. Emacs
-can have several modes, such as C mode for editing C programs, LaTeX mode
-for editing LaTeX documents, Dired for directory editing, etc. These are
-major modes, each with a different set of key-bindings. Viper states are
-orthogonal to these Emacs major modes. The presence of these language
-sensitive and other modes is a major win over Vi. @xref{Improvements over
-Vi}, for more.
-
-The bindings for these modes can be made available in the Viper Insert state
-as well as in Emacs state. Unless you specify your user level as 1 (a
-novice), all major mode key sequences that start with @kbd{C-x} and
-@kbd{C-c} are also available in Vi state. This is important because major
-modes designed for editing files, such as cc-mode or latex-mode, use key
-sequences that begin with @kbd{C-x} and @kbd{C-c}.
-
-There is also a key that lets you temporarily escape to Vi command state
-from the Insert state: typing @kbd{C-z} will let you execute a
-single Vi command while staying in Viper's Insert state.
-
-
-@node Vi State
-@subsection Vi State
-
-@cindex Vi state
-
-This is the Vi command mode. When Viper is in Vi state, you will see the sign
-<V> in the mode line. Most keys will work as in Vi. The notable
-exceptions are:
-
-@table @kbd
-@item C-x
-@kindex C-x
-@kbd{C-x} is used to invoke Emacs commands, mainly those that do window
-management. @kbd{C-x 2} will split a window, @kbd{C-x 0} will close a
-window. @kbd{C-x 1} will close all other windows. @kbd{C-xb} is used to
-switch buffers in a window, and @kbd{C-xo} to move through windows.
-These are about the only necessary keystrokes.
-For the rest, see the GNU Emacs Manual.
-
-@item C-c
-@kindex C-c
-For user levels 2 and higher, this key serves as a prefix key for the key
-sequences used by various major modes. For users at Viper level 1, @kbd{C-c}
-simply beeps.
-
-@item C-g and C-]
-@kindex C-g
-@kindex C-]
-
-These are the Emacs @samp{quit} keys.
-There will be cases where you will have to
-use @kbd{C-g} to quit. Similarly, @kbd{C-]} is used to exit
-@samp{Recursive Edits} in Emacs for which there is no comparable Vi
-functionality and no key-binding. Recursive edits are indicated by
-@samp{[]} brackets framing the modes on the mode line.
-@xref{Recursive Edit,Recursive
-Edit,Recursive Edit,emacs,The GNU Emacs Manual}.
-At user level 1, @kbd{C-g} is bound to @code{viper-info-on-file}
-function instead.
-@item C-\
-@kindex C-\
-@cindex Meta key
-
-Viper uses @key{ESC} as a switch between Insert and Vi states. Emacs uses
-@key{ESC} for Meta. The Meta key is very important in Emacs since many
-functions are accessible only via that key as @kbd{M-x function-name}.
-Therefore, we need to simulate it somehow. In Viper's Vi, Insert, and
-Replace states, the meta key is set to be @kbd{C-\}. Thus, to get
-@kbd{M-x}, you should type @kbd{C-\ x} (if the keyboard has no Meta key,
-which is rare these days).
-This works both in the Vi command state and in the Insert and Replace
-states. In Vi command state, you can also use @kbd{\ @key{ESC}} as the
-meta key.
-
-Note: Emacs binds @kbd{C-\} to a function that offers to change the
-keyboard input method in the multilingual environment. Viper overrides this
-binding. However, it is still possible to switch the input method by typing
-@kbd{\ C-\} in the Vi command state and @kbd{C-z \ C-\} in the Insert state.
-Or you can use the MULE menu in the menubar.
-@end table
-@noindent
-Other differences are mostly improvements. The ones you should know
-about are:
-
-@table @samp
-@item Undo
-@kindex u
-@kbd{u} will undo. Undo can be repeated by the @kbd{.} key. Undo itself
-can be undone. Another @kbd{u} will change the direction. The presence
-of repeatable undo means that @kbd{U}, undoing lines, is not very
-important. Therefore, @kbd{U} also calls @code{viper-undo}.
-@cindex multiple undo
-@cindex undo
-
-
-@item Counts
-Most commands, @kbd{~}, @kbd{[[}, @kbd{p}, @kbd{/}, @dots{}, etc., take counts.
-
-@comment ]] Just to balance parens
-@item Regexps
-Viper uses Emacs Regular Expressions for searches. These are a superset of
-Vi regular
-expressions, excepting the change-of-case escapes @samp{\u}, @samp{\L},
-@dots{}, etc. @xref{Regexps,,Syntax of Regular Expressions,emacs,The
-GNU Emacs Manual}, for details.
-Files specified to @kbd{:e} use @code{csh} regular expressions
-(globbing, wildcards, what have you).
-However, the function @code{viper-toggle-search-style}, bound to @kbd{C-c /},
-lets the user switch from search with regular expressions to plain vanilla
-search and vice versa. It also lets one switch from case-sensitive search
-to case-insensitive and back.
-@xref{Viper Specials}, for more details.
-@cindex regular expressions
-@cindex vanilla search
-@cindex case-sensitive search
-@cindex case-insensitive search
-@kindex C-c /
-
-@item Ex commands
-@cindex Ex commands
-The current working directory of a buffer is automatically inserted in the
-minibuffer if you type @kbd{:e} then space. Absolute filenames are
-required less often in Viper. For file names, Emacs uses a convention that
-is slightly different from other programs. It is designed to minimize the
-need for deleting file names that Emacs provides in its prompts. (This is
-usually convenient, but occasionally the prompt may suggest a wrong file
-name for you.) If you see a prompt @kbd{/usr/foo/} and you wish to edit the
-file @kbd{~/.file}, you don't have to erase the prompt. Instead, simply
-continue typing what you need. Emacs will interpret @kbd{/usr/foo/~/.file}
-correctly. Similarly, if the prompt is @kbd{~/foo/} and you need to get to
-@kbd{/bar/file}, keep typing. Emacs interprets @kbd{~/foo//bar/} as
-@kbd{/bar/file}, since when it sees @samp{//}, it understands that
-@kbd{~/foo/} is to be discarded.
-
-The command @kbd{:cd} will change the default directory for the
-current buffer. The command @kbd{:e} will interpret the
-filename argument in @code{csh}. @xref{Customization}, if you
-want to change the default shell.
-The command @kbd{:next} takes counts from
-@kbd{:args}, so that @kbd{:rew} is obsolete. Also, @kbd{:args} will show only
-the invisible files (i.e., those that are not currently seen in Emacs
-windows).
-
-When applicable, Ex commands support file completion and history. This
-means that by typing a partial file name and then @key{TAB}, Emacs will try
-to complete the name or it will offer a menu of possible completions.
-This works similarly to Tcsh and extends the behavior of Csh. While Emacs
-is waiting for a file name, you can type @kbd{M-p} to get the previous file
-name you typed. Repeatedly typing @kbd{M-p} and @kbd{M-n} will let you
-browse through the file history.
-
-Like file names, partially typed Ex commands can be completed by typing
-@key{TAB}, and Viper keeps the history of Ex commands. After typing
-@kbd{:}, you can browse through the previously entered Ex commands by
-typing @kbd{M-p} and @kbd{M-n}. Viper tries to rationalize when it puts Ex
-commands on the history list. For instance, if you typed @kbd{:w!@: foo},
-only @kbd{:w!} will be placed on the history list. This is because the
-last history element is the default that can be invoked simply by typing
-@kbd{: @key{RET}}. If @kbd{:w!@: foo} were placed on the list, it would be all to
-easy to override valuable data in another file. Reconstructing the full
-command, @kbd{:w!@: foo}, from the history is still not that hard, since Viper
-has a separate history for file names. By typing @kbd{: M-p}, you will get
-@kbd{:w!} in the minibuffer. Then, repeated @kbd{M-p} will get you through
-the file history, inserting one file name after another.
-
-In contrast to @kbd{:w!@: foo}, if the command were @kbd{:r foo}, the entire
-command will appear in the history list. This is because having @kbd{:r}
-alone as a default is meaningless, since this command requires a file
-argument.
-@end table
-@noindent
-As in Vi, Viper's destructive commands can be re-executed by typing
-a period (@kbd{.}).
-However, in addition, Viper keeps track of the history of such commands. This
-history can be perused by typing @kbd{C-c M-p} and @kbd{C-c M-n}.
-Having found the appropriate command, it can be then executed by typing
-a period.
-@xref{Improvements over Vi}, for more information.
-
-@node Insert State
-@subsection Insert State
-
-@cindex Insert state
-
-To avoid confusing the beginner (at Viper level 1 and 2), Viper makes only the
-standard Vi keys available in Insert state. The implication is that
-Emacs major modes cannot be used in Insert state.
-It is strongly recommended that as soon as you are comfortable, make the
-Emacs state bindings visible (by changing your user level to 3 or higher).
-@xref{Customization},
-to see how to do this.
-
-Once this is done, it is possible to do quite a bit of editing in
-Insert state. For instance, Emacs has a @dfn{yank} command, @kbd{C-y},
-which is similar to Vi's @kbd{p}. However, unlike @kbd{p}, @kbd{C-y} can be
-used in Insert state of Viper. Emacs also has a kill ring where it keeps
-pieces of text you deleted while editing buffers. The command @kbd{M-y} is
-used to delete the text previously put back by Emacs's @kbd{C-y} or by Vi's
-@kbd{p} command and reinsert text that was placed on the kill-ring earlier.
-
-This works both in Vi and Insert states.
-In Vi state, @kbd{M-y} is a much better alternative to the usual Vi's way
-of recovering the 10 previously deleted chunks of text. In Insert state,
-you can
-use this as follows. Suppose you deleted a piece of text and now you need
-to re-insert it while editing in Insert mode. The key @kbd{C-y} will put
-back the most recently deleted chunk. If this is not what you want, type
-@kbd{M-y} repeatedly and, hopefully, you will find the chunk you want.
-
-Finally, in Insert and Replace states, Viper provides the history of
-pieces of text inserted in previous insert or replace commands. These
-strings of text can be recovered by repeatedly typing @kbd{C-c M-p} or
-@kbd{C-c M-n} while in Insert or Replace state. (This feature is disabled
-in the minibuffer: the above keys are usually bound to other histories,
-which are more appropriate in the minibuffer.)
-
-
-@cindex Meta key
-
-You can call Meta functions from Insert state. As in Vi state, the Meta key
-is @kbd{C-\}. Thus @kbd{M-x} is typed as @kbd{C-\ x}.
-
-Other Emacs commands that are useful in Insert state are @kbd{C-e}
-and @kbd{C-a}, which move the cursor to the end and the beginning of the
-current line, respectively. You can also use @kbd{M-f} and @kbd{M-b},
-which move the cursor forward (or backward) one word.
-If your display has a Meta key, these functions are invoked by holding the
-Meta key and then typing @kbd{f} and @kbd{b}, respectively. On displays
-without the Meta key, these functions are invoked by typing
-@kbd{C-\ f} and @kbd{C-\ b} (@kbd{C-\} simulates the Meta key in Insert
-state, as explained above).
-
-The key @kbd{C-z} is sometimes also useful in Insert state: it allows you
-to execute a single command in Vi state without leaving the Insert state!
-For instance, @kbd{C-z d2w} will delete the next two words without leaving
-the Insert state.
-
-When Viper is in Insert state, you will see <I> in the mode line.
-
-@node Replace State
-@subsection Replace State
-
-@cindex Replace state
-
-This state is entered through Vi replacement commands, such as @kbd{C},
-@kbd{cw}, etc., or by typing @kbd{R}. In Replace state, Viper puts <R> in
-the mode line to let you know which state is in effect. If Replace state is
-entered through @kbd{R}, Viper stays in that state until the user hits
-@key{ESC}. If this state is entered via the other replacement commands,
-then Replace state is in effect until you hit @key{ESC} or until you cross
-the rightmost boundary of the replacement region. In the latter case, Viper
-changes its state from Replace to Insert (which you will notice by the
-change in the mode line).
-
-Since Viper runs under Emacs, it is possible to switch between buffers
-while in Replace state. You can also move the cursor using the arrow keys
-(even on dumb terminals!)@: and the mouse. Because of this freedom (which is
-unattainable in regular Vi), it is possible to take the cursor outside the
-replacement region. (This may be necessary for several reasons, including
-the need to enable text selection and region-setting with the mouse.)
-
-The issue then arises as to what to do when the user
-hits the @key{ESC} key. In Vi, this would cause the text between cursor and
-the end of the replacement region to be deleted. But what if, as is
-possible in Viper, the cursor is not inside the replacement region?
-
-To solve the problem, Viper keeps track of the last cursor position while it
-was still inside the replacement region. So, in the above situation, Viper
-would delete text between this position and the end of the replacement
-region.
-
-@node The Minibuffer
-@section The Minibuffer
-
-@cindex Minibuffer
-
-The minibuffer is where commands are entered in. Editing can be done
-by commands from Insert state, namely:
-
-@table @kbd
-@item C-h
-Backspace
-@item C-w
-Delete Word
-@item C-u
-Erase line
-@item C-v
-Quote the following character
-@item @key{RET}
-Execute command
-@item C-g and C-]
-Emacs quit and abort keys. These may be necessary. @xref{Vi State}, for an
-explanation.
-@item M-p and M-n
-These keys are bound to functions that peruse minibuffer history. The
-precise history to be perused depends on the context. It may be the history
-of search strings, Ex commands, file names, etc.
-@item C-s
-If the minibuffer is entered via the Viper search commands @kbd{/} or
-@kbd{?}, then this key inserts the last search string used by the
-Emacs incremental search command
-(which is bound to @kbd{C-s} everywhere except in this case).
-@end table
-
-Most of the Emacs keys are functional in the minibuffer. While in the
-minibuffer, Viper tries to make editing resemble Vi's behavior when the
-latter is waiting for the user to type an Ex command. In particular, you
-can use the regular Vi commands to edit the minibuffer. You can switch
-between the Vi state and Insert state at will, and even use the replace mode.
-Initially, the minibuffer comes up in Insert state.
-
-Some users prefer plain Emacs bindings in the minibuffer. To this end, set
-@code{viper-vi-style-in-minibuffer} to @code{nil} in
-your Viper customization file. @xref{Customization}, to learn how to do this.
-
-When the minibuffer changes Viper states, you will notice that the appearance
-of the text there changes as well. This is useful because the minibuffer
-has no mode line to tell which Vi state it is in.
-The appearance of the text in the minibuffer can be changed.
-@xref{Viper Specials}, for more details.
-
-@node Multiple Files in Viper
-@section Multiple Files in Viper
-
-@cindex multiple files
-@cindex managing multiple files
-
-Viper can edit multiple files. This means, for example that you never need
-to suffer through @code{No write since last change} errors.
-Some Viper elements are common over all the files.
-
-@table @samp
-@item Textmarkers
-@cindex markers
-@cindex textmarkers
-Textmarkers remember @emph{files and positions}.
-If you set marker @samp{a} in
-file @file{foo}, start editing file @file{bar} and type @kbd{'a}, then
-@emph{YOU WILL SWITCH TO FILE @file{foo}}. You can see the contents of a
-textmarker using the Viper command @kbd{[<a-z>} where <a-z> are the
-textmarkers, e.g., @kbd{[a} to view marker @samp{a} .
-@item Repeated Commands
-Command repetitions are common over files. Typing @kbd{!!} will repeat the
-last @kbd{!} command whichever file it was issued from.
-Typing @kbd{.} will repeat the last command from any file, and
-searches will repeat the last search. Ex commands can be repeated by typing
-@kbd{: @key{RET}}.
-Note: in some rare cases, that @kbd{: @key{RET}} may do something dangerous.
-However, usually its effect can be undone by typing @kbd{u}.
-@item Registers
-@cindex registers
-Registers are common to files. Also, text yanked with @kbd{y} can be
-put back (@kbd{p}) into any file. The Viper command @kbd{]<a-z>}, where <a-z> are
-the registers, can be used to look at the contents of a register, e.g.,
-type @kbd{]a} to view register @samp{a}.
-
-There is one difference in text deletion that you should be
-aware of. This difference comes from Emacs and was adopted in Viper
-because we find it very useful. In Vi, if you delete a line, say, and then
-another line, these two deletions are separated and are put back
-separately if you use the @samp{p} command. In Emacs (and Viper), successive
-series of deletions that are @emph{not interrupted} by other commands are
-lumped together, so the deleted text gets accumulated and can be put back
-as one chunk. If you want to break a sequence of deletions so that the
-newly deleted text could be put back separately from the previously deleted
-text, you should perform a non-deleting action, e.g., move the cursor one
-character in any direction.
-@item Absolute Filenames
-@cindex absolute file names
-The current directory name for a file is automatically prepended to the
-file name in any
-@kbd{:e}, @kbd{:r}, @kbd{:w}, etc., command (in Emacs, each buffer has a
-current directory).
-This directory is inserted in the minibuffer once you type space after
-@kbd{:e, r}, etc. Viper also supports completion of file names and Ex
-commands (@key{TAB}), and it keeps track of
-command and file history (@kbd{M-p}, @kbd{M-n}).
-Absolute filenames are required less
-often in Viper.
-
-You should be aware that Emacs interprets @kbd{/foo/bar//bla} as
-@kbd{/bla} and @kbd{/foo/~/bar} as @kbd{~/bar}. This is designed to
-minimize the need for erasing file names that Emacs suggests in its
-prompts, if a suggested file name is not what you wanted.
-
-The command @kbd{:cd} will change the default directory for the
-current Emacs buffer. The Ex command @kbd{:e} will interpret the
-filename argument in @samp{csh}, by default. @xref{Customization}, if you
-want to change this.
-@end table
-
-@noindent
-Currently undisplayed files can be listed using the @kbd{:ar} command. The
-command @kbd{:n} can be given counts from the @kbd{:ar} list to switch to
-other files. For example, use @samp{:n3} to move to the third file in
-that list.
-
-@node Unimplemented Features
-@section Unimplemented Features
-
-Unimplemented features include:
-
-@itemize @bullet
-@item
-@kbd{:ab} and @kbd{:una} are not implemented, since
-@kbd{:ab} is considered obsolete, since Emacs has much
-more powerful facilities for defining abbreviations.
-@item
-@kbd{:set option?} is not implemented. The current
-@kbd{:set} can also be used to set Emacs variables.
-@item
-@kbd{:se list} requires modification of the display code for Emacs, so
-it is not implemented.
-A useful alternative is @code{cat -t -e file}. Unfortunately, it cannot
-be used directly inside Emacs, since Emacs will obdurately change @samp{^I}
-back to normal tabs.
-@end itemize
-
-@node Improvements over Vi
-@chapter Improvements over Vi
-
-Some common problems with Vi and Ex have been solved in Viper. This
-includes better implementation of existing commands, new commands, and
-the facilities provided by Emacs.
-
-@menu
-* Basics:: Basic Viper differences, Multi-file effects.
-* Undo and Backups:: Multiple undo, auto-save, backups and changes
-* History:: History for Ex and Vi commands.
-* Macros and Registers:: Keyboard Macros (extended ".")@: @@reg execution.
-* Completion:: Filename and Command Completion for Ex.
-* Improved Search:: Incremental Search and Buffer Content Search.
-* Abbreviation Facilities:: Normal Abbrevs, Templates, and Dynamic Abbrevs.
-* Movement and Markers:: Screen Editor movements, viewing textmarkers.
-* New Commands:: Commands that do not exist in Vi.
-* Useful Packages:: A Sampling of some Emacs packages, and things
- you should know about.
-@end menu
-
-@node Basics
-@section Basics
-
-The Vi command set is based on the idea of combining motion commands
-with other commands. The motion command is used as a text region
-specifier for other commands.
-We classify motion commands into @dfn{point commands} and
-@dfn{line commands}.
-
-@cindex point commands
-
-The point commands are:
-
-@quotation
-@kbd{h}, @kbd{l}, @kbd{0}, @kbd{$}, @kbd{w}, @kbd{W}, @kbd{b}, @kbd{B},
-@kbd{e}, @kbd{E}, @kbd{(}, @kbd{)}, @kbd{/}, @kbd{?}, @kbd{`}, @kbd{f},
-@kbd{F}, @kbd{t}, @kbd{T}, @kbd{%}, @kbd{;}, @kbd{,}, @kbd{^}
-@end quotation
-
-@cindex line commands
-
-The line commands are:
-
-@quotation
-@kbd{j}, @kbd{k}, @kbd{+}, @kbd{-}, @kbd{H}, @kbd{M}, @kbd{L}, @kbd{@{},
-@kbd{@}}, @kbd{G}, @kbd{'}, @kbd{[[}, @kbd{]]}, @kbd{[]}
-@end quotation
-
-@cindex region
-@cindex region specification
-@cindex expanding (region)
-@cindex describing regions
-@cindex movement commands
-
-@noindent
-If a point command is given as an argument to a modifying command, the
-region determined by the point command will be affected by the modifying
-command. On the other hand, if a line command is given as an argument to a
-modifying command, the region determined by the line command will be
-enlarged so that it will become the smallest region properly containing the
-region and consisting of whole lines (we call this process @dfn{expanding
-the region}), and then the enlarged region will be affected by the modifying
-command.
-Text Deletion Commands (@pxref{Deleting Text}), Change commands
-(@pxref{Changing Text}), even Shell Commands (@pxref{Shell Commands})
-use these commands to describe a region of text to operate on.
-Thus, type @kbd{dw} to delete a word, @kbd{>@}} to shift a paragraph, or
-@kbd{!'afmt} to format a region from @samp{point} to textmarker
-@samp{a}.
-
-@cindex r and R region specifiers
-
-Viper adds the region specifiers @samp{r} and @samp{R}. Emacs has a
-special marker called @dfn{mark}. The text-area between the current cursor
-position @dfn{point} and the @dfn{mark} is called the @dfn{region}.
-@samp{r} specifies the raw region and @samp{R} is the expanded region
-(i.e., the minimal contiguous chunk of full lines that contains the raw
-region).
-@kbd{dr} will now delete the region, @kbd{>r} will shift it, etc.
-@kbd{r,R} are not motion commands, however. The special mark is set by
-@kbd{m.} and other commands. @xref{Marking}, for more info.
-
-Viper also adds counts to most commands for which it would make sense.
-
-In the Overview chapter, some Multiple File issues were discussed
-(@pxref{Multiple Files in Viper}). In addition to the files, Emacs has
-buffers. These can be seen in the @kbd{:args} list and switched using
-@kbd{:next} if you type @kbd{:set ex-cycle-through-non-files t}, or
-specify @code{(setq ex-cycle-through-non-files t)} in your
-Viper customization file. @xref{Customization}, for details.
-
-@node Undo and Backups
-@section Undo and Backups
-
-@cindex undo
-
-Viper provides multiple undo. The number of undo's and the size is limited
-by the machine. The Viper command @kbd{u} does an undo. Undo can be
-repeated by typing @kbd{.} (a period). Another @kbd{u} will undo the undo,
-and further
-@kbd{.} will repeat it. Typing @kbd{u} does the first undo, and changes the
-direction.
-
-@cindex backup files
-@cindex auto save
-
-Since the undo size is limited, Viper can create backup files and
-auto-save files. It will normally do this automatically. It is possible
-to have numbered backups, etc. For details, @pxref{Backup,,Backup and
-Auto-Save,emacs,The GNU Emacs Manual}.
-
-@comment [ balance parens
-@cindex viewing registers and markers
-@cindex registers
-@cindex markers
-@cindex textmarkers
-
-The results of the 9 previous changes are available in the 9 numeric
-registers, as in Vi. The extra goody is the ability to @emph{view} these
-registers, in addition to being able to access them through @kbd{p} and
-@kbd{M-y} (@xref{Insert State}, for details.)
-The Viper command @kbd{] register} will display the contents of any
-register, numeric or alphabetical. The related command @kbd{[ textmarker}
-will show the text around the textmarker. @samp{register} and @samp{textmarker}
-can be any letters from a through z.
-@comment ] balance parens
-
-@node History
-@section History
-
-@cindex history
-@cindex Minibuffer
-
-History is provided for Ex commands, Vi searches, file names, pieces of
-text inserted in earlier commands that use Insert or Replace state, and for
-destructive commands in Vi state. These are
-useful for fixing those small typos that screw up searches and @kbd{:s},
-and for eliminating routine associated with repeated typing of file names
-or pieces of text that need to be inserted frequently.
-At the @kbd{:} or @kbd{/} prompts in the minibuffer, you can do the following:
-
-@table @kbd
-@item M-p and M-n
-To move to previous and next history items. This causes the history
-items to appear on the command line, where you can edit them, or
-simply type Return to execute.
-@item M-r and M-s
-To search backward and forward through the history.
-@item @key{RET}
-Type @key{RET} to accept a default (which is displayed in the prompt).
-@end table
-
-The history of insertions can be perused by
-typing @kbd{C-c M-p} and @kbd{C-c M-n} while in Insert or Replace state.
-The history of destructive Vi commands can be perused via the same keys
-when Viper is in Vi state. @xref{Viper Specials}, for details.
-
-All Ex commands have a file history. For instance, typing @kbd{:e}, space
-and then @kbd{M-p} will bring up the name of the previously typed file
-name. Repeatedly typing @kbd{M-p}, @kbd{M-n}, etc., will let you browse
-through the file history.
-
-Similarly, commands that have to do with switching buffers
-have a buffer history, and commands that expect strings or regular
-expressions keep a history on those items.
-
-@node Macros and Registers
-@section Macros and Registers
-
-@cindex keyboard macros
-@cindex macros
-@cindex registers
-@cindex register execution
-
-Viper facilitates the use of Emacs-style keyboard macros. @kbd{@@#} will
-start a macro definition. As you type, the commands will be executed, and
-remembered (This is called ``learn mode'' in some editors.)
-@kbd{@@register} will complete the macro, putting it into @samp{register},
-where @samp{register} is any character from @samp{a} through @samp{z}. Then
-you can execute this macro using @kbd{@@register}. It is, of course,
-possible to yank some text into a register and execute it using
-@kbd{@@register}. Typing @kbd{@@@@}, @kbd{@@@key{RET}}, or @kbd{@@C-j} will
-execute the last macro that was executed using @kbd{@@register}.
-
-Viper will automatically lowercase the register, so that pressing the
-@kbd{SHIFT} key for @kbd{@@} will not create problems. This is for
-@kbd{@@} macros and @kbd{"p} @emph{only}. In the case of @kbd{y},
-@kbd{"Ayy} will append to @emph{register a}. For @kbd{[,],',`}, it
-is an error to use a Uppercase register name.
-
-@comment [ balance parens
-@cindex viewing registers and markers
-
-The contents of a register can be seen by @kbd{]register}. (@kbd{[textmarker}
-will show the contents of a textmarker).
-@comment ] balance parens
-
-@cindex last keyboard macro
-
-The last keyboard macro can also be executed using
-@kbd{*}, and it can be yanked into a register using @kbd{@@!register}.
-This is useful for Emacs style keyboard macros defined using @kbd{C-x(}
-and @kbd{C-x)}. Emacs keyboard macros have more capabilities.
-@xref{Keyboard Macros,,Keyboard Macros,emacs, The GNU Emacs Manual}, for
-details.
-
-Keyboard Macros allow an interesting form of Query-Replace:
-@kbd{/pattern} or @kbd{n} to go to the next pattern (the query), followed by a
-Keyboard Macro execution @kbd{@@@@} (the replace).
-
-Viper also provides Vi-style macros. @xref{Vi Macros}, for details.
-
-
-@node Completion
-@section Completion
-
-@cindex completion
-
-Completion is done when you type @key{TAB}. The Emacs completer does not
-grok wildcards in file names. Once you type a wildcard, the completer will
-no longer work for that file name. Remember that Emacs interprets a file name
-of the form @kbd{/foo//bar} as @kbd{/bar} and @kbd{/foo/~/bar} as
-@kbd{~/bar}.
-
-@node Improved Search
-@section Improved Search
-
-@cindex buffer search
-@cindex word search
-
-Viper provides buffer search, the ability to search the buffer for a region
-under the cursor. You have to turn this on in your Viper customization file
-either by calling
-
-@example
-(viper-buffer-search-enable)
-@end example
-
-@noindent
-or by setting @code{viper-buffer-search-char} to, say, @kbd{f3}:
-@example
-(setq viper-buffer-search-char ?g)
-@end example
-
-@noindent
-If the user calls @code{viper-buffer-search-enable} explicitly (the first
-method), then @code{viper-buffer-search-char} will be set to @kbd{g}.
-Regardless of how this feature is enabled, the key
-@code{viper-buffer-search-char} will take movement commands, like
-@kbd{w,/,e}, to find a region and then search for the contents of that
-region. This command is very useful for searching for variable names, etc.,
-in a program. The search can be repeated by @kbd{n} or reversed by @kbd{N}.
-
-@cindex incremental search
-
-Emacs provides incremental search. As you type the string in, the
-cursor will move to the next match. You can snarf words from the buffer
-as you go along. Incremental Search is normally bound to @kbd{C-s} and
-@kbd{C-r}. @xref{Customization}, to find out how to change the bindings
-of @kbd{C-r or C-s}.
-For details, @pxref{Incremental Search,,Incremental
-Search,emacs,The GNU Emacs Manual}.
-
-@cindex query replace
-
-Viper also provides a query replace function that prompts through the
-minibuffer. It is invoked by the @kbd{Q} key in Vi state.
-
-@cindex mouse search
-
-On a window display, Viper supports mouse search, i.e., you can search for a
-word by clicking on it. @xref{Viper Specials}, for details.
-
-Finally, on a window display, Viper highlights search patterns as it finds
-them. This is done through what is known as @emph{faces} in Emacs. The
-variable that controls how search patterns are highlighted is
-@code{viper-search-face}. If you don't want any highlighting at all, put
-@example
-(copy-face 'default 'viper-search-face)
-@end example
-@vindex viper-search-face
-@noindent
-in your Viper customization file. If you want to change how patterns are
-highlighted, you will have to change @code{viper-search-face} to your liking.
-The easiest way to do this is to use Emacs customization widget, which is
-accessible from the menubar. Viper customization group is located under the
-@emph{Emulations} customization group, which in turn is under the
-@emph{Editing} group (or simply by typing @kbd{:customize}). All Viper
-faces are grouped together under Viper's
-@emph{Highlighting} group.
-
-Try it: it is really simple!
-
-@node Abbreviation Facilities
-@section Abbreviation Facilities
-
-@cindex abbrevs
-
-It is possible in Emacs to define abbrevs based on the contents of the
-buffer.
-Sophisticated templates can be defined using the Emacs abbreviation
-facilities. @xref{Abbrevs,,Abbreviations,emacs,The GNU Emacs Manual}, for
-details.
-
-@cindex dynamic abbrevs
-
-Emacs also provides Dynamic Abbreviations. Given a partial word, Emacs
-will search the buffer to find an extension for this word. For instance,
-one can type @samp{Abbreviations} by typing @samp{A}, followed by a keystroke
-that completed the @samp{A} to @samp{Abbreviations}. Repeated typing
-will search further back in the buffer, so that one could get
-@samp{Abbrevs} by repeating the
-keystroke, which appears earlier in the text. Emacs binds this to
-@kbd{@key{ESC} /}, so you will have to find a key and bind the function
-@code{dabbrev-expand} to that key.
-Facilities like this make Vi's @kbd{:ab} command obsolete.
-
-@node Movement and Markers
-@section Movement and Markers
-
-@cindex Ex style motion
-@cindex line editor motion
-
-Viper can be set free from the line-limited movements in Vi, such as @kbd{l}
-refusing to move beyond the line, @key{ESC} moving one character back,
-etc. These derive from Ex, which is a line editor. If your
-Viper customization file contains
-
-@example
-@code{(setq viper-ex-style-motion nil)}
-@end example
-
-@noindent
-the motion will be a true screen editor motion. One thing you must then
-watch out for is that it is possible to be on the end-of-line character.
-The keys @kbd{x} and @kbd{%} will still work correctly, i.e., as if they
-were on the last character.
-
-@vindex viper-syntax-preference
-@cindex syntax table
-
-The word-movement commands @kbd{w}, @kbd{e}, etc., and the associated
-deletion/yanking commands, @kbd{dw}, @kbd{yw}, etc., can be made to
-understand Emacs syntax tables. If the variable
-@code{viper-syntax-preference} is set to @code{strict-vi} then
-the meaning of @emph{word} is the same as in
-Vi. However, if the value is @code{reformed-vi} (the default) then the
-alphanumeric symbols will be those specified by the current Emacs syntax
-table (which may be different for different major modes) plus the
-underscore symbol @kbd{_}, minus some non-word symbols, like '.;,|, etc.
-Both @code{strict-vi} and @code{reformed-vi} work close to Vi in
-traditional cases, but @code{reformed-vi} does a better job when editing
-text in non-Latin alphabets.
-
-The user can also specify the value @code{emacs}, which would
-make Viper use exactly the Emacs notion of word. In particular, the
-underscore may not be part of a word. Finally, if
-@code{viper-syntax-preference} is set to @code{extended}, Viper words would
-consist of characters that are classified as alphanumeric @emph{or} as
-parts of symbols. This is convenient for writing programs and in many other
-situations.
-
-@code{viper-syntax-preference} is a local variable, so it can have different
-values for different major modes. For instance, in programming modes it can
-have the value @code{extended}. In text modes where words contain special
-characters, such as European (non-English) letters, Cyrillic letters, etc.,
-the value can be @code{reformed-vi} or @code{emacs}.
-
-Changes to @code{viper-syntax-preference} should be done in the hooks to
-various major modes by executing @code{viper-set-syntax-preference} as in
-the following example:
-
-@example
-(viper-set-syntax-preference nil "emacs")
-@end example
-
-@findex viper-set-syntax-preference
-
-The above discussion of the meaning of Viper's words concerns only Viper's
-movement commands. In regular expressions, words remain the same as in
-Emacs. That is, the expressions @code{\w}, @code{\>}, @code{\<}, etc., use
-Emacs's idea of what is a word, and they don't look into the value of
-variable @code{viper-syntax-preference}. This is because Viper doesn't change
-syntax tables in fear of upsetting the various major modes that set these
-tables.
-
-@cindex textmarkers
-
-Textmarkers in Viper remember the file and the position, so that you can
-switch files by simply doing @kbd{'a}. If you set up a regimen for using
-Textmarkers, this is very useful. Contents of textmarkers can be viewed
-by @kbd{[marker}. (Contents of registers can be viewed by @kbd{]register}).
-
-@node New Commands
-@section New Commands
-
-These commands have no Vi analogs.
-
-@table @kbd
-@item C-x, C-c
-@kindex C-x
-@kindex C-c
-These two keys invoke many important Emacs functions. For example, if you
-hit @kbd{C-x} followed by @kbd{2}, then the current window will be split
-into 2. Except for novice users, @kbd{C-c} is also set to execute an Emacs
-command from the current major mode. @key{ESC} will do the same, if you
-configure @key{ESC} as Meta by setting @code{viper-no-multiple-ESC} to
-@code{nil} in your Viper customization file. @xref{Customization}.
-@kbd{C-\} in Insert, Replace, or Vi states will make Emacs think
-@kbd{Meta} has been hit.
-@item \
-@kindex \
-Escape to Emacs to execute a single Emacs command. For instance,
-@kbd{\ @key{ESC}} will act like a Meta key.
-@item Q
-@kindex Q
-@cindex query replace
-@kbd{Q} is for query replace. By default,
-each string to be replaced is treated as a regular expression. You can use
-@code{(setq viper-re-query-replace nil)} in your @file{.emacs} file to
-turn this off. (For normal searches, @kbd{:se nomagic} will work. Note
-that @kbd{:se nomagic} turns Regexps off completely, unlike Vi).
-@item v
-@itemx V
-@itemx C-v
-@kindex v
-@kindex V
-@kindex C-v
-These keys are used to visit files. @kbd{v} will switch to a buffer
-visiting file whose name can be entered in the minibuffer. @kbd{V} is
-similar, but will use a window different from the current window.
-@kbd{C-v} is like @kbd{V}, except that a new frame (X window) will be used
-instead of a new Emacs window.
-@item #
-@kindex #
-If followed by a certain character @var{ch}, it becomes an operator whose
-argument is the region determined by the motion command that follows
-(indicated as <move>).
-Currently, @var{ch} can be one of @kbd{c}, @kbd{C}, @kbd{g}, @kbd{q}, and
-@kbd{s}. For instance, @kbd{#qr} will prompt you for a string and then
-prepend this string to each line in the buffer.
-@item # c
-@kindex #c<move>
-@cindex changing case
-Change upper-case characters in the region to lower-case
-(@code{downcase-region}).
-Emacs command @kbd{M-l} does the same for words.
-@item # C
-@kindex #C<move>
-Change lower-case characters in the region to upper-case. For instance,
-@kbd{# C 3 w} will capitalize 3 words from the current point
-(@code{upcase-region}).
-Emacs command @kbd{M-u} does the same for words.
-@item # g
-@kindex #g<move>
-Execute last keyboard macro for each line in the region
-(@code{viper-global-execute}).
-@item # q
-@kindex #q<move>
-Insert specified string at the beginning of each line in the region
-(@code{viper-quote-region}). The default string is composed of the comment
-character(s) appropriate for the current major mode.
-@item # s
-@kindex #s<move>
-Check spelling of words in the region (@code{spell-region}).
-The function used for spelling is determined from the variable
-@code{viper-spell-function}.
-@vindex viper-spell-function
-@item *
-@kindex *
-Call last keyboard macro.
-@item m .
-Set mark at point and push old mark off the ring
-@item m<
-@item m>
-Set mark at beginning and end of buffer, respectively.
-@item m,
-Jump to mark and pop mark off the ring. @xref{Mark,,Mark,emacs,The GNU
-Emacs Manual}, for more info.
-@item ] register
-@kindex ]<a-z>
-View contents of register
-@item [ textmarker
-@kindex [<a-z>
-View filename and position of textmarker
-@item @@#
-@item @@register
-@item @@!
-@kindex @@#
-@kindex @@<a-z>
-@kindex @@!
-@cindex keyboard macros
-@cindex register execution
-
-Begin/end keyboard macro. @@register has a different meaning when used after
-a @kbd{@@#}. @xref{Macros and Registers}, for details
-@item []
-@kindex []
-Go to end of heading.
-@item g <@emph{movement command}>
-Search buffer for text delimited by movement command. The canonical
-example is @kbd{gw} to search for the word under the cursor.
-@xref{Improved Search}, for details.
-@item C-g and C-]
-@kindex C-g
-@kindex C-]
-Quit and Abort Recursive edit. These may be necessary on occasion.
-@xref{Vi State}, for a reason.
-@item C-c C-g
-@kindex C-c C-g
-Hitting @kbd{C-c} followed by @kbd{C-g} will display the information on the
-current buffer. This is the same as hitting @kbd{C-g} in Vi, but, as
-explained above, @kbd{C-g} is needed for other purposes in Emacs.
-@item C-c /
-@kindex C-c /
-Without a prefix argument, this command toggles
-case-sensitive/case-insensitive search modes and plain vanilla/regular
-expression search. With the prefix argument 1, i.e.,
-@kbd{1 C-c /}, this toggles case-sensitivity; with the prefix argument 2,
-toggles plain vanilla search and search using
-regular expressions. @xref{Viper Specials}, for alternative ways to invoke
-this function.
-@cindex vanilla search
-@cindex case-sensitive search
-@cindex case-insensitive search
-
-@item M-p and M-n
-@kindex M-p
-@kindex M-n
-In the minibuffer, these commands navigate through the minibuffer
-histories, such as the history of search strings, Ex commands, etc.
-
-@item C-s
-@kindex C-s
-If the minibuffer is entered via a Viper search commands @kbd{/} or @kbd{?},
-then typing this key inserts the last search string used by the
-Emacs incremental search command (that is bound to @kbd{C-s} everywhere
-except in this case).
-
-@item C-c M-p and C-c M-n
-@kindex C-c M-p
-@kindex C-c M-n
-@cindex Insertion history
-@cindex Insertion ring
-@cindex Command history
-@cindex Command ring
-
-In Insert or Replace state, these commands let the user
-peruse the history of insertion strings used in previous insert or replace
-commands. Try to hit @kbd{C-c M-p} or @kbd{C-c M-n} repeatedly and see what
-happens. @xref{Viper Specials}, for more.
-
-In Vi state, these commands let the user peruse the history of Vi-style
-destructive commands, such as @kbd{dw}, @kbd{J}, @kbd{a}, etc.
-By repeatedly typing @kbd{C-c M-p} or @kbd{C-c M-n} you will cycle Viper
-through the recent history of Vi commands, displaying the commands one by
-one. Once an appropriate command is found, it can be executed by
-typing a period.
-
-Since typing @kbd{C-c M-p} is tedious, it is more convenient to bind an
-appropriate function to a function key on the keyboard and use that key.
-@xref{Viper Specials}, for details.
-
-@item Ex commands
-@findex @kbd{Ex args}
-@findex @kbd{Ex n}
-@findex @kbd{Ex pwd}
-@findex @kbd{Ex pre}
-The commands @kbd{:args}, @kbd{:next}, @kbd{:pre} behave
-differently. @kbd{:pwd} exists to get current directory.
-The commands @kbd{:b} and @kbd{:B} switch buffers around. @xref{File and
-Buffer Handling}, for details.
-There are also the new commands @kbd{:RelatedFile} and
-@kbd{PreviousRelatedFile} (which abbreviate to @kbd{R} and @kbd{P},
-respectively. @xref{Viper Specials}, for details.
-@findex @kbd{Ex RelatedFile}
-@findex @kbd{Ex PreviousRelatedFile}
-@end table
-
-Apart from the new commands, many old commands have been enhanced. Most
-notably, Vi style macros are much more powerful in Viper than in Vi. @xref{Vi
-Macros}, for details.
-
-@node Useful Packages
-@section Useful Packages
-
-Some Emacs packages are mentioned here as an aid to the new Viper user, to
-indicate what Viper is capable of.
-A vast number comes with the standard Emacs distribution, and many more exist
-on the net and on the archives.
-
-This manual also mentions some Emacs features a new user
-should know about. The details of these are found in the GNU Emacs
-Manual.
-
-The features first. For details, look up the Emacs Manual.
-
-@table @samp
-@item Make
-@cindex make
-@cindex compiling
-
-Makes and Compiles can be done from the editor. Error messages will be
-parsed and you can move to the error lines.
-@item Shell
-@cindex shell
-@cindex interactive shell
-You can talk to Shells from inside the editor. Your entire shell session
-can be treated as a file.
-@item Mail
-@cindex email
-@cindex mail
-Mail can be read from and sent within the editor. Several sophisticated
-packages exist.
-@item Language Sensitive Editing
-Editing modes are written for most computer languages in existence. By
-controlling indentation, they catch punctuation errors.
-@end table
-
-The packages, below, represents a drop in the sea of special-purpose
-packages that come with standard distribution of Emacs.
-
-@table @samp
-@item Transparent FTP
-@cindex transparent ftp
-@pindex ange-ftp.el
-@code{ange-ftp.el} can ftp from the editor to files on other machines
-transparent to the user.
-@item RCS Interfaces
-@cindex version maintenance
-@cindex RCS
-@pindex vc.el
-@code{vc.el} for doing RCS commands from inside the editor
-@item Directory Editor
-@cindex dired
-@pindex dired.el
-@code{dired.el} for editing contents of directories and for navigating in
-the file system.
-@item Syntactic Highlighting
-@cindex font-lock
-@pindex font-lock.el
-@code{font-lock.el} for automatic highlighting various parts of a buffer
-using different fonts and colors.
-@item Saving Emacs Configuration
-@cindex desktop
-@pindex desktop.el
-@code{desktop.el} for saving/restoring configuration on Emacs exit/startup.
-@item Spell Checker
-@cindex ispell
-@pindex ispell.el
-@code{ispell.el} for spell checking the buffer, words, regions, etc.
-@item File and Buffer Comparison
-@cindex ediff
-@pindex ediff.el
-@code{ediff.el} for finding differences between files and for applying
-patches.
-@end table
-
-@noindent
-Emacs Lisp archives exist on
-@samp{archive.cis.ohio-state.edu}
-and @samp{wuarchive.wustl.edu}
-
-
-@node Customization
-@chapter Customization
-
-@cindex customization
-
-Customization can be done in 2 ways.
-
-@itemize @bullet
-@item
-@cindex initialization
-@cindex .viper
-Elisp code in a @file{~/.emacs.d/viper} (or @file{~/.viper}) file.
-Viper loads this file just before it does the binding for mode hooks.
-This is recommended for experts only.
-@item
-@cindex .emacs
-Elisp code in your @file{.emacs} file before and after the @code{(require
-'viper)} line. This method is @emph{not} recommended, unless you know what
-you are doing. Only two variables, @code{viper-mode} and
-@code{viper-custom-file-name}, are supposed to be customized in @file{.emacs},
-prior to loading Viper (i.e., prior to @code{(require 'viper)} command.
-@item
-@cindex Ex customize
-By executing the @kbd{:customize} Ex command. This takes you to the Emacs
-customization widget, which lets you change the values of Viper
-customizable variables easily. This method is good for novice and
-experts alike. The customization code in the form of Lisp commands will be
-placed in @file{~/.emacs} or some other customization file depending on the
-version of Emacs that you use. Still, it is recommended to separate
-Viper-related customization produced by the Emacs customization widget
-and keep it in your Viper customization file.
-
-Some advanced customization cannot be accomplished this way, however, and
-has to be done in Emacs Lisp in your Viper customization file. For the common
-cases, examples are provided that you can use directly.
-@end itemize
-
-
-@menu
-* Rudimentary Changes:: Simple constant definitions.
-* Key Bindings:: Enabling Emacs Keys, Rebinding keys, etc.
-* Packages that Change Keymaps:: How to deal with such beasts.
-* Viper Specials:: Special Viper commands.
-* Vi Macros:: How to do Vi style macros.
-@end menu
-
-@node Rudimentary Changes
-@section Rudimentary Changes
-
-@cindex setting variables
-@cindex variables for customization
-@findex @kbd{Ex set}
-
-An easy way to customize Viper is to change the values of constants used in
-Viper. Here is the list of the constants used in Viper and their default
-values. The corresponding :se command is also indicated. (The symbols
-@code{t} and @code{nil} represent ``true'' and ``false'' in Lisp).
-
-Viper supports both the abbreviated Vi variable names and their full
-names. Variable completion is done on full names only. @key{TAB} and
-@key{SPC} complete
-variable names. Typing @kbd{=} will complete the name and then will prompt for
-a value, if applicable. For instance, @kbd{:se au @key{SPC}} will complete the
-command to @kbd{:set autoindent}; @kbd{:se ta @key{SPC}} will complete the command
-and prompt further like this: @kbd{:set tabstop = }.
-However, typing @kbd{:se ts @key{SPC}} will produce a ``No match'' message
-because @kbd{ts} is an abbreviation for @kbd{tabstop} and Viper supports
-completion on full names only. However, you can still hit @key{RET}
-or @kbd{=}, which will complete the command like this: @kbd{:set ts = } and
-Viper will be waiting for you to type a value for the tabstop variable.
-To get the full list of Vi variables, type @kbd{:se @key{SPC} @key{TAB}}.
-
-@table @code
-@item viper-auto-indent nil
-@itemx :se ai (:se autoindent)
-@itemx :se ai-g (:se autoindent-global)
-If @code{t}, enable auto indentation.
-by @key{RET}, @kbd{o} or @kbd{O} command.
-
-@code{viper-auto-indent} is a local variable. To change the value globally, use
-@code{setq-default}. It may be useful for certain major modes to have their
-own values of @code{viper-auto-indent}. This can be achieved by using
-@code{setq} to change the local value of this variable in the hooks to the
-appropriate major modes.
-
-@kbd{:se ai} changes the value of @code{viper-auto-indent} in the current
-buffer only; @kbd{:se ai-g} does the same globally.
-@item viper-electric-mode t
-If not @code{nil}, auto-indentation becomes electric, which means that
-@key{RET}, @kbd{O}, and @kbd{o} indent cursor according to the current
-major mode. In the future, this variable may control additional electric
-features.
-
-This is a local variable: @code{setq} changes the value of this variable
-in the current buffer only. Use @code{setq-default} to change the value in
-all buffers.
-@item viper-case-fold-search nil
-@itemx :se ic (:se ignorecase)
-If not @code{nil}, search ignores cases.
-This can also be toggled by quickly hitting @kbd{/} twice.
-@item viper-re-search nil
-@itemx :se magic
-If not @code{nil}, search will use regular expressions; if @code{nil} then
-use vanilla search.
-This behavior can also be toggled by quickly hitting @kbd{/} trice.
-@item buffer-read-only
-@itemx :se ro (:se readonly)
-Set current buffer to read only. To change globally put
-@code{(setq-default buffer-read-only t)} in your @file{.emacs} file.
-@item blink-matching-paren t
-@itemx :se sm (:se showmatch)
-Show matching parens by blinking cursor.
-@item tab-width t (default setting via @code{setq-default})
-@itemx :se ts=value (:se tabstop=value)
-@itemx :se ts-g=value (:se tabstop-global=value)
-@code{tab-width} is a local variable that controls the width of the tab stops.
-To change the value globally, use @code{setq-default}; for local settings,
-use @code{setq}.
-
-The command @kbd{:se ts}
-sets the tab width in the current
-buffer only; it has no effect on other buffers.
-
-The command @kbd{:se ts-g} sets tab width globally,
-for all buffers where the tab is not yet set locally,
-including the new buffers.
-
-Note that typing @key{TAB} normally
-doesn't insert the tab, since this key is usually bound to
-a text-formatting function, @code{indent-for-tab-command} (which facilitates
-programming and document writing). Instead, the tab is inserted via the
-command @code{viper-insert-tab}, which is bound to @kbd{S-tab} (shift + tab).
-
-On some text terminals, Shift doesn't modify the @key{TAB} key, so
-@kbd{S-tab} behaves as if it were @key{TAB}. In such a case, you will have
-to bind @code{viper-insert-tab} to some other convenient key.
-
-@item viper-shift-width 8
-@itemx :se sw=value (:se shiftwidth=value)
-The number of columns shifted by @kbd{>} and @kbd{<} commands.
-@item viper-search-wrap-around t
-@itemx :se ws (:se wrapscan)
-If not @code{nil}, search wraps around the end/beginning of buffer.
-@item viper-search-scroll-threshold 2
-If search lands within this many lines of the window top or bottom, the
-window will be scrolled up or down by about 1/7-th of its size, to reveal
-the context. If the value is negative, don't scroll.
-@item viper-tags-file-name "TAGS"
-The name of the file used as the tag table.
-@item viper-re-query-replace nil
-If not @code{nil}, use reg-exp replace in query replace.
-@item viper-want-ctl-h-help nil
-If not @code{nil}, @kbd{C-h} is bound to @code{help-command};
-otherwise, @kbd{C-h} is bound as usual in Vi.
-@item viper-vi-style-in-minibuffer t
-If not @code{nil}, Viper provides a high degree of compatibility with Vi
-insert mode when you type text in the minibuffer; if @code{nil}, typing in
-the minibuffer feels like plain Emacs.
-@item viper-no-multiple-ESC t
-If you set this to @code{nil}, you can use @key{ESC} as Meta in Vi state.
-Normally, this is not necessary, since graphical displays have separate
-Meta keys (usually on each side of the space bar). On a dumb terminal, Viper
-sets this variable to @code{twice}, which is almost like @code{nil}, except
-that double @key{ESC} beeps. This, too, lets @key{ESC} to be used as a Meta.
-@item viper-fast-keyseq-timeout 200
-Key sequences separated by this many milliseconds are treated as Vi-style
-keyboard macros. If the key sequence is defined as such a macro, it will be
-executed. Otherwise, it is processed as an ordinary sequence of typed keys.
-
-Setting this variable too high may slow down your typing. Setting it too
-low may make it hard to type macros quickly enough.
-@item viper-ex-style-motion t
-Set this to @code{nil}, if you want @kbd{l,h} to cross
-lines, etc. @xref{Movement and Markers}, for more info.
-@item viper-ex-style-editing t
-Set this to @code{nil}, if you want
-@kbd{C-h} and @key{DEL} to not stop
-at the beginning of a line in Insert state, @kbd{X} and @kbd{x} to delete
-characters across lines in Vi command state, etc.
-@item viper-ESC-moves-cursor-back t
-It @code{t}, cursor moves back 1 character when switching from insert state to vi
-state. If @code{nil}, the cursor stays where it was before the switch.
-@item viper-always t
-@code{t} means: leave it to Viper to decide when a buffer must be brought
-up in Vi state,
-Insert state, or Emacs state. This heuristic works well in virtually all
-cases. @code{nil} means you either have to invoke @code{viper-mode} manually
-for each buffer (or you can add @code{viper-mode} to the appropriate major mode
-hooks using @code{with-eval-after-load}).
-
-This option must be set in your Viper customization file.
-@item viper-custom-file-name "~/.emacs.d/viper"
-File used for Viper-specific customization.
-Change this setting, if you want. Must be set in @file{.emacs}
-before Viper is loaded. Note that you
-have to set it as a string inside double quotes.
-@item viper-spell-function 'ispell-region
-Function used by the command @kbd{#c<move>} to spell.
-@item viper-glob-function
-The value of this variable is the function symbol used to expand wildcard
-symbols. This is platform-dependent. The default tries to set this variable
-to work with most shells, MS Windows, etc. However, if it
-doesn't work the way you expect, you should write your own.
-Use @code{viper-glob-unix-files} and @code{viper-glob-mswindows-files} in
-@file{viper-util.el} as examples.
-
-This feature is used to expand wildcards in the Ex command @kbd{:e}.
-Note that Viper doesn't support wildcards in the @kbd{:r} and @kbd{:w}
-commands, because file completion is a better mechanism.
-@findex viper-glob-function
-
-@item ex-cycle-other-window t
-If not @code{nil}, @kbd{:n} and @kbd{:b} will cycle through files in another
-window, if one exists.
-@item ex-cycle-through-non-files nil
-@kbd{:n} does not normally cycle through buffers. Set this to get
-buffers also.
-@item viper-want-emacs-keys-in-insert
-This is set to @code{nil} for user levels 1 and 2 and to @code{t} for user
-levels 3 and 4. Users who specify level 5 are allowed to set this variable
-as they please (the default for this level is @code{t}). If set to
-@code{nil}, complete Vi compatibility is provided in Insert state. This is
-really not recommended, as this precludes you from using language-specific
-features provided by the major modes.
-@item viper-want-emacs-keys-in-vi
-This is set to @code{nil} for user
-level 1 and to @code{t} for user levels 2--4.
-At level 5, users are allowed to set this variable as they please (the
-default for this level is @code{t}).
-If set to @code{nil}, complete Vi compatibility is provided
-in Vi command state. Setting this to @code{nil} is really a bad idea,
-unless you are a novice, as this precludes the use
-of language-specific features provided by the major modes.
-@item viper-keep-point-on-repeat t
-If not @code{nil}, point is not moved when the user repeats the previous
-command by typing a period. This is very useful for doing repeated
-changes with the @kbd{.} key.
-@item viper-repeat-from-history-key 'f12
-Prefix key used to invoke the macros @kbd{f12 1} and @kbd{f12 2} that repeat
-the second-last and the third-last destructive command.
-Both these macros are bound (as Viper macros) to
-@code{viper-repeat-from-history},
-which checks the second key by which it is invoked to see which of the
-previous commands to invoke. Viper binds @kbd{f12 1} and @kbd{f12 2} only,
-but the user can bind more in his/her Viper customization file.
-@xref{Vi Macros}, for how to do this.
-@item viper-keep-point-on-undo nil
-If not @code{nil}, Viper tries to not move point when undoing commands.
-Instead, it will briefly move the cursor to the place where change has
-taken place. However, if the undone piece of text is not seen in window,
-then point will be moved to the place where the change took place.
-Set it to @code{t} and see if you like it better.
-@item viper-delete-backwards-in-replace nil
-If not @code{nil}, @key{DEL} key will delete characters while moving the cursor
-backwards. If @code{nil}, the cursor will move backwards without deleting
-anything.
-@item viper-replace-overlay-face 'viper-replace-overlay-face
-On a graphical display, Viper highlights replacement regions instead of
-putting a @samp{$} at the end. This variable controls the so called
-@dfn{face} used to highlight the region.
-
-By default, @code{viper-replace-overlay-face} underlines the replacement on
-monochrome displays and also lays a stipple over them. On color displays,
-replacement regions are highlighted with color.
-
-If you know something about Emacs faces and don't like how Viper highlights
-replacement regions, you can change @code{viper-replace-overlay-face} by
-specifying a new face. (Emacs faces are described in the Emacs Lisp
-reference.) On a color display, the following customization method is
-usually most effective:
-@smallexample
-(set-face-foreground viper-replace-overlay-face "DarkSlateBlue")
-(set-face-background viper-replace-overlay-face "yellow")
-@end smallexample
-For a complete list of colors available to you, evaluate the expression
-@code{(defined-colors)}. (Type it in the buffer @file{*scratch*} and then
-hit the @kbd{C-j} key.
-
-@item viper-replace-overlay-cursor-color "Red"
-@vindex viper-replace-overlay-cursor-color
-Cursor color when it is inside the replacement region.
-This has effect only on color displays and only when Emacs runs as an X
-application.
-@item viper-insert-state-cursor-color nil
-@vindex viper-insert-state-cursor-color
-If set to a valid color, this will be the cursor color when Viper is in
-insert state.
-@item viper-emacs-state-cursor-color nil
-@vindex viper-emacs-state-cursor-color
-If set to a valid color, this will be the cursor color when Viper is in
-emacs state.
-@item viper-replace-region-end-delimiter "$"
-A string used to mark the end of replacement regions. It is used only on
-TTYs or if @code{viper-use-replace-region-delimiters} is non-@code{nil}.
-@item viper-replace-region-start-delimiter ""
-A string used to mark the beginning of replacement regions. It is used
-only on TTYs or if @code{viper-use-replace-region-delimiters} is non-@code{nil}.
-@item viper-use-replace-region-delimiters
-If non-@code{nil}, Viper will always use @code{viper-replace-region-end-delimiter} and
-@code{viper-replace-region-start-delimiter} to delimit replacement regions,
-even on color displays (where this is unnecessary). By default, this
-variable is non-@code{nil} only on TTYs or monochrome displays.
-@item viper-allow-multiline-replace-regions t
-If non-@code{nil}, multi-line text replacement regions, such as those produced by
-commands @kbd{c55w}, @kbd{3C}, etc., will stay around until the user exits
-the replacement mode. In this variable is set to @code{nil}, Viper will
-emulate the standard Vi behavior, which supports only intra-line
-replacement regions (and multi-line replacement regions are deleted).
-@item viper-toggle-key "\C-z"
-Specifies the key used to switch from Emacs to Vi and back.
-Must be set in your Viper customization file. This variable can't be
-changed interactively after Viper is loaded.
-
-In Insert state, this key acts as a temporary escape to Vi state, i.e., it
-will set Viper up so that the very next command will be executed as if it
-were typed in Vi state.
-@item viper-buffer-search-char nil
-Key used for buffer search. @xref{Viper Specials}, for details.
-@item viper-surrounding-word-function 'viper-surrounding-word
-The value of this variable is a function name that is used to determine
-what constitutes a word clicked upon by the mouse. This is used by mouse
-search and insert.
-@item viper-search-face 'viper-search-face
-Variable that controls how search patterns are highlighted when they are
-found.
-@item viper-vi-state-hook nil
-List of parameterless functions to be run just after entering the Vi
-command state.
-@item viper-insert-state-hook nil
-Same for Insert state. This hook is also run after entering Replace state.
-@item viper-replace-state-hook nil
-List of (parameterless) functions called just after entering Replace state
-(and after all @code{viper-insert-state-hook}).
-@item viper-emacs-state-hook nil
-List of (parameterless) functions called just after switching from Vi state
-to Emacs state.
-@end table
-@noindent
-You can reset some of these constants in Viper with the Ex command @kbd{:set}
-(when so indicated in the table). Or you
-can include a line like this in your Viper customization file:
-@example
-(setq viper-case-fold-search t)
-@end example
-@vindex viper-auto-indent
-@vindex viper-electric-mode
-@vindex viper-case-fold-search
-@vindex viper-re-search
-@vindex viper-shift-width
-@vindex buffer-read-only
-@vindex viper-search-wrap-around
-@vindex viper-search-scroll-threshold
-@vindex viper-search-face
-@vindex viper-tags-file-name
-@vindex viper-re-query-replace
-@vindex viper-want-ctl-h-help
-@vindex viper-vi-style-in-minibuffer
-@vindex viper-no-multiple-ESC
-@vindex viper-always
-@vindex viper-fast-keyseq-timeout
-@vindex viper-ex-style-motion
-@vindex viper-ex-style-editing
-@vindex viper-ESC-moves-cursor-back
-@vindex viper-custom-file-name
-@vindex viper-spell-function
-@vindex ex-cycle-other-window
-@vindex ex-cycle-through-non-files
-@vindex viper-want-emacs-keys-in-insert
-@vindex viper-want-emacs-keys-in-vi
-@vindex viper-keep-point-on-repeat
-@vindex viper-keep-point-on-undo
-@vindex viper-delete-backwards-in-replace
-@vindex viper-replace-overlay-face
-@vindex viper-replace-region-end-symbol
-@vindex viper-replace-region-start-symbol
-@vindex viper-allow-multiline-replace-regions
-@vindex viper-toggle-key
-@vindex viper-buffer-search-char
-@vindex viper-surrounding-word-function
-@vindex viper-vi-state-hook
-@vindex viper-insert-state-hook
-@vindex viper-replace-state-hook
-@vindex viper-emacs-state-hook
-
-@node Key Bindings
-@section Key Bindings
-
-@cindex key bindings
-@cindex keymaps
-
-Viper lets you define hot keys, i.e., you can associate keyboard keys
-such as F1, Help, PgDn, etc., with Emacs Lisp functions (that may already
-exist or that you will write). Each key has a ``preferred form'' in
-Emacs. For instance, the Up key's preferred form is [up], the Help key's
-preferred form is [help], and the Undo key has the preferred form [f14].
-You can find out the preferred form of a key by typing @kbd{M-x
-describe-key-briefly} and then typing the key you want to know about.
-
-Under the X Window System, every keyboard key emits its preferred form,
-so you can just type
-
-@lisp
-(keymap-global-set "<f11>" 'calendar) ; L1, Stop
-(keymap-global-set "<f14>" 'undo) ; L4, Undo
-@end lisp
-
-@noindent
-to bind L1 (a key that exists on some SUN workstations) so it will invoke
-the Emacs Calendar and to bind L4 so it will undo changes.
-However, on a dumb terminal or in an Xterm window, even the standard arrow
-keys may
-not emit the right signals for Emacs to understand. To let Emacs know about
-those keys, you will have to find out which key sequences they emit
-by typing @kbd{C-q} and then the key (you should switch to Emacs state
-first). Then you can bind those sequences to their preferred forms using
-@code{input-decode-map} as follows:
-
-@lisp
-(cond ((string= (getenv "TERM") "xterm")
-(define-key input-decode-map "\e[192z" [f11]) ; L1
-(define-key input-decode-map "\e[195z" [f14]) ; L4, Undo
-@end lisp
-
-The above illustrates how to do this for Xterm. On VT100, you would have to
-replace "xterm" with "vt100" and also change the key sequences (the same
-key may emit different sequences on different types of terminals).
-
-The above keys are global, so they are overwritten by the local maps
-defined by the major modes and by Viper itself. Therefore, if you wish to
-change a binding set by a major mode or by Viper, read this.
-
-Viper users who wish to specify their own key bindings should be concerned
-only with the following three keymaps:
-@code{viper-vi-global-user-map} for Vi state commands,
-@code{viper-insert-global-user-map} for Insert state commands,
-and @code{viper-emacs-global-user-map} for Emacs state commands (note:
-customized bindings for Emacs state made to @code{viper-emacs-global-user-map}
-are @emph{not} inherited by Insert state).
-
-For more information on Viper keymaps, see the header of the file
-@file{viper.el}.
-If you wish to change a Viper binding, you can use the
-@code{define-key} command, to modify @code{viper-vi-global-user-map},
-@code{viper-insert-global-user-map}, and @code{viper-emacs-global-user-map}, as
-explained below. Each of these key maps affects the corresponding Viper state.
-The keymap @code{viper-insert-global-user-map} also affects Viper's Replace
-state.
-
-@noindent
-If you want to
-bind a key, say @kbd{C-v}, to the function that scrolls
-page down and to make @kbd{0} display information on the current buffer,
-putting this in your Viper customization file will do the trick in Vi state:
-@example
-(define-key viper-vi-global-user-map "\C-v" 'scroll-down)
-@end example
-@noindent
-To set a key globally,
-@example
-(define-key viper-emacs-global-user-map "\C-c m" 'smail)
-(define-key viper-vi-global-user-map "0" 'viper-info-on-file)
-@end example
-@noindent
-Note, however, that this binding may be overwritten by other keymaps, since
-the global keymap has the lowest priority.
-To make sure that nothing will override a binding in Emacs state, you
-can write this:
-@example
-(define-key viper-emacs-global-user-map "\C-c m" 'smail)
-@end example
-@noindent
-To customize the binding for @kbd{C-h} in Insert state:
-@example
-(define-key viper-insert-global-user-map "\C-h"
- 'my-del-backwards-function)
-@end example
-@noindent
-
-Each Emacs command key calls some Lisp function. If you have enabled the
-Help, (@pxref{Rudimentary Changes}) @kbd{C-h k} will show you the function
-for each specific key; @kbd{C-h b} will show all bindings, and @kbd{C-h m}
-will provide information on the major mode in effect. If Help is not
-enabled, you can still get help in Vi state by prefixing the above commands
-with @kbd{\}, e.g., @kbd{\ C-h k} (or you can use the Help menu in the
-menu bar, if Emacs runs under X).
-
-Viper users can also change bindings on a per major mode basis. As with
-global bindings, this can be done separately for each of the three main Viper
-states. To this end, Viper provides the function
-@code{viper-modify-major-mode}.
-@findex viper-modify-major-mode
-
-To modify keys in Emacs state for @code{my-favorite-major-mode}, the user
-needs to create a sparse keymap, say, @code{my-fancy-map}, bind whatever
-keys necessary in that keymap, and put
-
-@example
-(viper-modify-major-mode 'dired-mode 'emacs-state my-fancy-map)
-@end example
-
-@noindent
-in your Viper customization file. To do the same in Vi and Insert states, you
-should use @code{vi-state} and @code{insert-state}. Changes in Insert state
-are also in effect in Replace state. For instance, suppose that the user wants
-to use @kbd{dd} in Vi state under Dired mode to delete files, @kbd{u} to unmark
-files, etc. The following code in the Viper customization file will then do
-the job:
-
-@example
-(setq my-dired-modifier-map (make-sparse-keymap))
-(define-key my-dired-modifier-map "dd" 'dired-flag-file-deletion)
-(define-key my-dired-modifier-map "u" 'dired-unmark)
-(viper-modify-major-mode 'dired-mode 'vi-state my-dired-modifier-map)
-@end example
-
-A Vi purist may want to modify Emacs state under Dired mode so that
-@kbd{k}, @kbd{l}, etc., will move around in directory buffers, as in
-Vi. Although this is not recommended, as these keys are bound to useful
-Dired functions, the trick can be accomplished via the following code:
-
-@example
-(setq my-dired-vi-purist-map (make-sparse-keymap))
-(define-key my-dired-vi-purist-map "k" 'viper-previous-line)
-(define-key my-dired-vi-purist-map "l" 'viper-forward-char)
-(viper-modify-major-mode 'dired-mode
- 'emacs-state my-dired-vi-purist-map)
-@end example
-
-Yet another way to customize key bindings in a major mode is to edit the
-list @code{viper-major-mode-modifier-list} using the customization widget.
-@vindex viper-major-mode-modifier-list
-(This variable is in the Viper-misc customization group.)
-The elements of this list are triples of the form: (major-mode viper-state
-keymap), where the keymap contains bindings that are supposed to be active
-in the given major mode and the given viper-state.
-
-Effects similar to key binding changes can be achieved by defining Vi
-keyboard macros using the Ex commands @kbd{:map} and @kbd{:map!}. The
-difference is that multi-key Vi macros do not override the keys they are
-bound to, unless these keys are typed in quick succession. So, with macros,
-one can use the normal keys alongside with the macros. If per-mode
-modifications are needed, the user can try both ways and see which one is
-more convenient.
-@findex @kbd{Ex map}
-@xref{Vi Macros}, for details.
-
-Note: in major modes that come up in @emph{Emacs state} by default, the
-aforesaid modifications may not take place immediately (but only after the
-buffer switches to some other Viper state and then back to Emacs state). To
-avoid this, one should add @code{viper-change-state-to-emacs} to an
-appropriate hook of that major mode. (Check the function
-@code{viper-set-hooks} in @file{viper.el} for examples.) However, if you
-did not set @code{viper-always} to @code{nil}, chances are that you won't
-need to perform the above procedure, because Viper will take care of most
-useful defaults.
-
-
-Finally, Viper has a facility that lets the user define per-buffer
-bindings, i.e., bindings that are in effect in some specific buffers
-only. Unlike per-mode bindings described above, per-buffer bindings can be
-defined based on considerations other than the major mode. This is done
-via the function @code{viper-add-local-keys}, which lets one specify bindings
-that should be in effect in the current buffer only and for a specific Viper
-state. For instance,
-@lisp
-(viper-add-local-keys 'vi-state '(("ZZ" .@: TeX-command-master)
- ("ZQ" .@: viper-save-kill-buffer)))
-@end lisp
-@noindent
-redefines @kbd{ZZ} to invoke @code{TeX-command-master} in @code{vi-state}
-and @kbd{ZQ} to save-then-kill the current buffer. These bindings take
-effect only in the buffer where this command is executed. The typical use
-of this function is to execute the above expression from within a function
-that is included in a hook to some major mode. For instance, the above
-expression
-could be called from a function, @code{my-tex-init}, which may be added to
-@code{tex-mode-hook} as follows:
-@lisp
-(add-hook 'tex-mode-hook 'my-tex-init)
-@end lisp
-@noindent
-When TeX mode starts, the hook is executed and the above Lisp expression is
-evaluated. Then, the bindings for @kbd{ZZ} and @kbd{ZQ} are changed in Vi
-command mode for all buffers in TeX mode.
-
-Another useful application is to bind @kbd{ZZ} to @code{send-mail}
-in the Mail mode buffers (the specifics of this depend on which mail
-package you are using, @code{rmail}, @code{mh-e}, @code{vm}, etc.
-For instance, here is how to do this for @code{mh-e}, the Emacs interface
-to MH:
-@lisp
-(defun mh-add-vi-keys ()
- "Set up ZZ for MH-e and XMH."
- (viper-add-local-keys 'vi-state '(("ZZ" .@: mh-send-letter))))
-(add-hook 'mh-letter-mode-hook 'mh-add-vi-keys)
-@end lisp
-
-You can also use @code{viper-add-local-keys} to set per buffer
-bindings in Insert state and Emacs state by passing as a parameter the
-symbols @code{insert-state} and @code{emacs-state}, respectively.
-As with global bindings, customized local bindings done to Emacs state
-are not inherited by Insert state.
-
-On rare occasions, local keys may be added by mistake. Usually this is done
-indirectly, by invoking a major mode that adds local keys (e.g.,
-@code{shell-mode} redefines @key{RET}). In such a case, exiting the wrong
-major mode won't rid you from unwanted local keys, since these keys are
-local to Viper state and the current buffer, not to the major mode.
-In such situations, the remedy is to type @kbd{M-x viper-zap-local-keys}.
-
-So much about Viper-specific bindings.
-@xref{Customization,,Customization,emacs,The GNU Emacs
-Manual}, and the Emacs quick reference card for the general info on key
-bindings in Emacs.
-
-@vindex input-decode-map
-@vindex local-function-key-map
-@vindex viper-vi-global-user-map
-@vindex viper-insert-global-user-map
-@vindex viper-emacs-global-user-map
-@findex viper-add-local-keys
-@findex viper-zap-local-keys
-
-@node Packages that Change Keymaps
-@section Packages that Change Keymaps
-@cindex C-c and Viper
-@cindex Viper and C-c
-
-Viper is designed to coexist with all major and minor modes of Emacs. This
-means that bindings set by those modes are generally available with Viper
-(unless you explicitly prohibit them by setting
-@code{viper-want-emacs-keys-in-vi} and @code{viper-want-emacs-keys-in-insert} to
-@code{nil}).
-If @code{viper-always} is set to @code{t} (which is the default), Viper
-will try to bring each buffer
-in the Viper state that is most appropriate for that buffer.
-Usually, this would be the Vi state, but sometimes it could be the Insert
-state or the Emacs state.
-
-Some major mode bindings will necessarily be overwritten by Viper. Indeed, in
-Vi state, most of the 1-character keys are used for Vi-style editing. This
-usually causes no problems because most packages designed for editing files
-typically do not bind such keys. Instead, they use key sequences that start
-with @kbd{C-x} and @kbd{C-c}. This is why it was so important for us to
-free up @kbd{C-x} and @kbd{C-c}.
-It is common for language-specific major modes to bind @key{TAB} and
-@kbd{C-j} (the line feed) keys to various formatting functions. This is
-extremely useful, but may require some getting used to for a Vi user. If you
-decide that this feature is not for you, you can re-bind these keys as
-explained earlier (@pxref{Customization}).
-
-Binding for @key{TAB} is one of the most unusual aspects of Viper for many
-novice users. In Emacs, @key{TAB} is used to format text and programs, and
-is extremely useful. For instance, hitting @key{TAB} causes the current
-line to be re-indented in accordance with the context. In programming,
-this is very important, since improper automatic indentation would
-immediately alert the programmer to a possible error. For instance, if a
-@kbd{)} or a @kbd{"} is missing somewhere above the current
-line, @key{TAB} is likely to mis-indent the line.
-
-For this reason, Viper doesn't change the standard Emacs binding of
-@key{TAB}, thereby sacrificing Vi compatibility
-(except for users at level 1). Instead, in Viper, the key
-@kbd{S-tab} (shift+ tab) is chosen to emulate Vi's @key{TAB}.
-
-We should note that on some text terminals, Shift doesn't modify
-the @key{TAB} key, so @kbd{S-tab} behaves as if it were @key{TAB}. In such
-a case, you will have to bind @code{viper-insert-tab} to some other
-convenient key.
-
-Some packages, notably Dired, Gnus, Info, etc., attach special meaning to
-common keys like @key{SPC}, @kbd{x}, @kbd{d}, @kbd{v}, and others. This
-means that Vi command state is inappropriate for working with these
-packages. Fortunately, these modes operate on read-only buffers and are
-designed not for editing files, but for special-purpose browsing, reading
-news, mail, etc., and Vi commands are meaningless in these situations. For
-this reason, Viper doesn't force Vi state on such major modes---it
-brings them in Emacs state. You can switch to Vi state by typing @kbd{C-z}
-if, for instance, you want to do Vi-style search in a buffer (although,
-usually, incremental search, which is bound to @kbd{C-s}, is sufficient in
-these situations). But you should then switch back to Emacs state if you
-plan to continue using these major modes productively. You can also switch
-to Vi temporarily, to execute just one command. This is done by typing
-@kbd{C-c \}. (In some of these modes, @kbd{/} and @kbd{:} are bound
-Vi-style, unless these keys perform essential duties.)
-
-If you would like certain major modes to come up in Emacs state rather than
-Vi state (but Viper thinks otherwise), you should put these major modes
-on the @code{viper-emacs-state-mode-list} list and delete them from
-@code{viper-vi-state-mode-list}.
-Likewise, you can force Viper's Insert state on a major mode by putting it
-in @code{viper-insert-state-mode-list}.
-@vindex viper-emacs-state-mode-list
-@vindex viper-insert-state-mode-list
-@vindex viper-vi-state-mode-list
-
-It is also possible to impose Vi on some major modes, even though they may
-bind common keys to specialized commands. This might make sense for modes
-that bind only a small number of common keys. For instance, Viper subverts
-the Shell mode by changing the bindings for @kbd{C-m} and @kbd{C-d} using
-@code{viper-add-local-keys} described in the section on customization
-(@pxref{Customization}).
-
-In some cases, some @emph{minor} modes might override certain essential
-bindings in Vi command state. This is not a big problem because this
-can happen only in the beginning, when the minor mode kicks in. Typing
-@code{M-x viper-mode} will correct the situation. Viper knows about
-several such minor modes and takes care of them, so the above trick
-is usually not necessary. If you find that some minor mode, e.g.,
-@code{nasty-mode} interferes with Viper, putting the following in
-your Viper customization file should fix the problem:
-@lisp
-(viper-harness-minor-mode "nasty-mode")
-@end lisp
-@noindent
-The argument to @code{viper-harness-minor-mode} is the name of the file for the
-offending minor mode with the suffixes @file{.el} and @file{.elc} removed.
-
-It may not be always obvious which minor mode is at fault. The only
-guidance here is to look into the file that defines the minor mode you are
-suspecting, say @file{nasty-mode.el}, and see if it has a variable called
-@code{nasty-mode-map}. Then check if there is a statement of the form
-@lisp
-(define-key nasty-mode-map key function)
-@end lisp
-@noindent
-that binds the misbehaving
-keys. If so, use the above line to harness @code{nasty-mode}. If your
-suspicion is wrong, no harm is done if you harness a minor mode that
-doesn't need to be harnessed.
-
-It is recommended to harness even those minor modes that don't override
-Viper keys, but still have their own keymaps. A general way to
-make a minor mode, @code{my-mode},
-compatible with Viper is to have the file @file{my-mode.el} include the following code:
-
-@lisp
-(when (fboundp 'viper-harness-minor-mode)
- (let ((lib (file-name-sans-extension
- (file-name-nondirectory load-file-name))))
- (viper-harness-minor-mode lib)))
-@end lisp
-
-@vindex viper-want-emacs-keys-in-vi
-@vindex viper-want-emacs-keys-in-insert
-@vindex viper-always
-@findex viper-set-hooks
-@findex viper-mode
-@findex viper-harness-minor-mode
-@findex remove-hook
-@findex add-hook
-
-@node Viper Specials
-@section Viper Specials
-
-Viper extends Vi with a number of useful features. This includes various
-search functions, histories of search strings, Ex commands, insertions, and
-Vi's destructive commands. In addition, Viper supports file name completion
-and history, completion of Ex commands and variables, and many other
-features. Some of these features are explained in detail elsewhere in this
-document. Other features are explained here.
-
-@table @code
-@item (viper-buffer-search-enable)
-@item viper-buffer-search-char nil
-Enable buffer search. Explicit call to @code{viper-buffer-search-enable}
-sets @code{viper-buffer-search-char} to @kbd{g}. Alternatively, the user can
-set @code{viper-buffer-search-char} in his/her Viper customization file to a key
-sequence to be used for buffer search. There is no need to call
-@code{viper-buffer-search-enable} in that case.
-@findex viper-buffer-search-enable
-@vindex viper-buffer-search-char
-@item viper-toggle-search-style
-This function, bound to @kbd{C-c /}, lets one toggle case-sensitive and
-case-insensitive search, and also switch between plain vanilla search and
-search via regular expressions. Without the prefix argument, the user is
-asked which mode to toggle. With prefix argument 1, this toggles
-case-sensitivity. With prefix argument 2, regular expression/vanilla search
-will be toggled.
-
-However, we found that the most convenient way to toggle
-these options is to bind a Vi macro to
-bind @kbd{//} to toggles case sensitivity and to @kbd{///} to toggles
-vanilla search. Thus, quickly hitting @kbd{/} twice will switch Viper from
-case sensitive search to case-insensitive. Repeating this once again will
-restore the original state. Likewise, quickly hitting @kbd{/} three times
-will switch you from vanilla-style search to search via regular expressions.
-If you hit something other than @kbd{/} after the first @kbd{/} or if the
-second @kbd{/} doesn't follow quickly enough, then Viper will issue the
-usual prompt @kbd{/} and will wait for input, as usual in Vi.
-If you don't like this behavior, you can ``unrecord'' these macros in your
-Viper customization file. For instance, if you don't like the above
-feature, put this in the file:
-@example
-(viper-set-searchstyle-toggling-macros 'undefine)
-@end example
-@findex viper-set-searchstyle-toggling-macros
-
-If you don't like this feature as a default, but would still like to have
-it in some major modes, you can do so by first unsetting it globally, as
-shown above, and then setting it in the desired major modes as follows:
-@example
-(viper-set-searchstyle-toggling-macros nil 'c-mode)
-(viper-set-searchstyle-toggling-macros nil 'lisp-mode)
-@end example
-
-@item Vi-isms in Emacs state
-Some people find it useful to use the Vi-style search key, @kbd{/}, to invoke
-search in modes which Viper leaves in emacs-state. These modes are:
-@code{dired-mode}, @code{mh-folder-mode},
-@code{Info-mode}, and @code{Buffer-menu-mode}
-(more may be added in the future). So, in the above modes, Viper binds @kbd{/}
-so that it will behave Vi-style. Furthermore, in those major modes, Viper
-binds @kbd{:} to invoke ex-style commands, like in vi-state. And, as described
-above, @kbd{//} and @kbd{///} get bound to Vi-style macros that toggle
-case-insensitivity and regexp-search.
-
-If you don't like these features---which I don't really understand---you
-can unbind @kbd{/} and @kbd{:} in @code{viper-dired-modifier-map} (for
-Dired) or in @code{viper-slash-and-colon-map}, for other modes.
-@vindex viper-slash-and-colon-map
-@vindex viper-dired-modifier-map
-
-To unbind the macros @kbd{//} and @kbd{///} for a major mode where you
-feel they
-are undesirable, execute @code{viper-set-emacs-state-searchstyle-macros} with a
-non-@code{nil} argument. This can be done either interactively, by supplying a
-prefix argument, or by placing
-@example
-(viper-set-emacs-state-searchstyle-macros 'undefine)
-@end example
-@findex viper-set-emacs-state-searchstyle-macros
-in the hook to the major mode (e.g., @code{dired-mode-hook}).
-@xref{Vi Macros}, for more information on Vi macros.
-
-@item viper-heading-start
-@item viper-heading-end
-@cindex headings
-@cindex sections
-@cindex paragraphs
-@cindex sentences
-Regular Expressions for @kbd{[[} and @kbd{]]}. Note that Emacs defines
-Regexps for paragraphs and sentences. @xref{Paragraphs,,Paragraphs and
-Sentences,emacs,The GNU Emacs Manual}, for details.
-@item M-x viper-set-expert-level
-@findex viper-set-expert-level
-Change your user level interactively.
-@item viper-smart-suffix-list '("" "tex" "c" "cc" "el" "p")
-@vindex viper-smart-suffix-list
-Viper supports Emacs-style file completion when it prompts the user for a
-file name. However, in many cases, the same directory may contain files
-with identical prefix but different suffixes, e.g., prog.c, prog.o,
-paper.tex, paper.dvi. In such cases, completion will stop at the period.
-If the above variable is a list of strings representing suffixes, Viper will
-try these suffixes
-in the order listed and will check if the corresponding file exists.
-
-For instance, if completion stopped at @samp{paper.} and the user
-typed @key{RET}, then Viper will check if the files @file{paper.},
-@file{paper.tex}, @file{paper.c}, etc., exist.
-It will take the first such file. If no file exists, Viper will give a chance
-to complete the file name by typing the appropriate suffix.
-If @file{paper.} was
-the intended file name, hitting return will accept it.
-
-To turn this feature off, set the above variable to @code{nil}.
-
-@item viper-insertion-ring-size 14
-@vindex viper-insertion-ring-size
-@cindex Insertion ring
-Viper remembers what was previously inserted in Insert and Replace states.
-Several such recent insertions are kept in a special ring of strings of size
-@code{viper-insertion-ring-size}.
-If you enter Insert or Replace state you can reinsert strings from this
-ring by typing @kbd{C-c M-p} or @kbd{C-c M-n}. The former will search the
-ring in
-the direction of older insertions, and the latter will search in
-the direction of newer insertions. Hitting @kbd{C-c M-p} or @kbd{C-c M-n}
-in succession
-will undo the previous insertion from the ring and insert the next item on
-the ring. If a larger ring size is needed, change the value of the above
-variable in the Viper customization file.
-
-Since typing these sequences of keys may be tedious, it is suggested that the
-user should bind a function key, such as @kbd{f31}, as follows:
-@example
-(define-key viper-insert-global-user-map [f31]
- 'viper-insert-prev-from-insertion-ring)
-@end example
-This binds @kbd{f31} (which is usually @kbd{R11} on a Sun workstation)
-to the function that inserts the previous string in the insertion history.
-To rotate the history in the opposite
-direction, you can either bind an unused key to
-@code{viper-insert-next-from-insertion-ring} or hit any digit (1 to 9) then
-@kbd{f31}.
-
-One should not bind the above functions to @kbd{M-p} or @kbd{M-n}, since
-this will interfere with the minibuffer histories and, possibly, other
-major modes.
-
-@item viper-command-ring-size 14
-@vindex viper-command-ring-size
-@cindex Destructive command ring
-@cindex Destructive command history
-Viper keeps track of the recent history of destructive
-commands, such as @kbd{dw}, @kbd{i}, etc.
-In Vi state,
-the most recent command can be re-executed by hitting a period, as in Vi.
-However, repeated typing @kbd{C-c M-p} will cause Viper to show the
-previous destructive commands in the minibuffer. Subsequent hitting period
-will execute the command that was displayed last.
-The key @kbd{C-c M-n} will cycle through the command history in the
-opposite direction.
-Since typing @kbd{C-c M-p} may be tedious, it is more convenient to bind an
-appropriate function to an unused function key on the keyboard and use that
-key. For instance, the following
-@example
-(define-key viper-vi-global-user-map [f31]
- 'viper-prev-destructive-command)
-@end example
-binds the key @kbd{f31} (which is usually @kbd{R11} on a Sun workstation)
-to the function that searches the command history in the direction of older
-commands. To search in the opposite
-direction, you can either bind an unused key to
-@code{viper-next-destructive-command} or hit any digit (1 to 9) then @kbd{f31}.
-
-One should not bind the above functions to @kbd{M-p} or @kbd{M-n}, since
-this will interfere with the minibuffer histories and, possibly, other
-major modes.
-
-@item viper-minibuffer-vi-face 'viper-minibuffer-vi-face
-@item viper-minibuffer-insert-face 'viper-minibuffer-insert-face
-@item viper-minibuffer-emacs-face 'viper-minibuffer-emacs-face
-These faces control the appearance of the minibuffer text in the
-corresponding Viper states. You can change the appearance of these faces
-through Emacs's customization widget, which is accessible through the
-menubar.
-
-Viper is located in this widget under the @emph{Emulations} customization
-subgroup of the @emph{Editing} group. All Viper faces are grouped together
-in Viper's @emph{Highlighting} customization subgroup.
-
-Note that only the text you type in is affected by the above faces.
-Prompts and minibuffer messages are not affected.
-
-Purists who do not like adornments in the minibuffer can always zap them by
-putting
-@example
-(copy-face 'default 'viper-minibuffer-vi-face)
-(copy-face 'default 'viper-minibuffer-insert-face)
-(copy-face 'default 'viper-minibuffer-emacs-face)
-@end example
-in their Viper customization file or through the customization widget, as
-described above. However, in that case, the user will not have any
-indication of the current Viper state in the minibuffer. (This is important
-if the user accidentally switches to another Viper state by typing @key{ESC} or
-@kbd{C-z}).
-@item M-x viper-go-away
-@findex viper-go-away
-Make Viper disappear from the face of your running Emacs instance. If your
-fingers start aching again, @kbd{M-x viper-mode} might save your day.
-@item M-x toggle-viper-mode
-@findex toggle-viper-mode
-Toggle Viperization of Emacs on and off.
-@end table
-
-@cindex Multifile documents and programs
-
-Viper provides some support for multi-file documents and programs.
-If a document consists of several files we can designate one of them as a
-master and put the following at the end of that file:
-@lisp
-;; Local Variables:
-;; eval: (viper-setup-master-buffer "file1" "file2" "file3" "file4")
-;; End:
-@end lisp
-@noindent
-where @code{file1} to @code{file4} are names of files related to the master
-file. Next time, when the master file is visited, the command
-@code{viper-setup-master-buffer} will be evaluated and the above files will
-be associated with the master file. Then, the new Ex command
-@kbd{:RelatedFile} (abbr.@: @kbd{:R}) will display files 1 to 4 one after
-another, so you can edit them. If a file is not in any Emacs buffer, it
-will be visited. The command @kbd{PreviousRelatedFile} (abbr., @kbd{:P})
-goes through the file list in the opposite direction.
-@findex @kbd{Ex RelatedFile}
-@findex @kbd{Ex PreviousRelatedFile}
-
-These commands are akin to @kbd{:n} and @kbd{:N}, but they allow the user to
-focus on relevant files only.
-
-Note that only the master file needs to have the aforementioned block of
-commands. Also, ";;" above can be replaced by some other
-markers. Semicolon is good for Lisp programs, since it is considered a
-comment designator there. For LaTeX, this could be "%%%", and for C the
-above block should be commented out.
-
-Even though these commands are sometimes useful, they are no substitute for
-the powerful @emph{tag table} facility of Emacs. Viper's @kbd{:tag} command
-in a primitive interface to Emacs tags. @xref{Tags Tables,,,emacs,
-The GNU Emacs Manual}, for more information on tags.
-
-The following two commands are normally bound to a mouse click and are part
-of Viper. They work only if Emacs runs as an application under X
-Windows (or under some other window system for which a port of GNU Emacs
-is available). Clicking the mouse when Emacs is invoked in an Xterm window
-(using @code{emacs -nw}) will do no good.
-
-@table @code
-@cindex mouse
-@cindex mouse-search
-@item viper-mouse-search-key (meta shift 1)
-@vindex viper-mouse-insert-key
-This variable controls the @emph{mouse-search} feature of Viper. The
-default value
-states that holding Meta and Shift keys while clicking mouse button 1
-should initiate search for a region under the mouse pointer (defined
-below). This command can take a prefix argument, which indicates the
-occurrence of the pattern to search for.
-
-Note: while loading initially, Viper binds this mouse action only if it is
-not already bound to something else. If you want to use the mouse-search
-feature, and the @kbd{Meta-Shift-mouse-1} mouse action is already bound to
-something else, you can rebind the mouse-search feature by setting
-@code{viper-mouse-search-key} to something else in
-your Viper customization file:
-@lisp
-(setq viper-mouse-search-key '(meta 1))
-@end lisp
-This would bind mouse search to the action invoked by pressing the
-Meta key and clicking mouse button 1. The allowed values of
-@code{viper-mouse-search-key} are lists that contain a mouse-button number
-(1,2, or 3) and any combination of the words ``control'', ``meta'', and
-``shift''.
-
-If the requested mouse action (e.g., (meta 1)) is already taken for other
-purposes then you have to confirm your intention by placing the following
-command in your Viper customization file after setting
-@code{viper-mouse-search-key}:
-@lisp
-(viper-bind-mouse-search-key 'force)
-@end lisp
-
-You can also change this setting interactively, through the customization
-widget of Emacs (type @kbd{:customize}).
-
-The region that is chosen as a pattern to search for is determined as
-follows. If search is invoked via a single click, Viper chooses the region
-that lies between the beginning of the ``word'' under the pointer (``word''
-is understood in Vi sense) and the end of that word. The only difference
-with Vi's words is that in Lisp major modes @samp{-} is considered an
-alphanumeric symbol. This is done for the convenience of working with Lisp
-symbols, which often have an @samp{-} in them. Also, if you click on a
-non-alphanumeric character that is not a word separator (in Vi sense) then
-this character will also be considered alphanumeric, provided that it is
-adjacent (from either side) to an alphanumeric character. This useful
-feature gives added control over the patterns selected by the mouse click.
-
-On a double-click, the region is determined by the beginning of the current
-Vi's ``Word'' (i.e., the largest non-separator chunk of text) and the End
-of that ``Word'' (as determined by the @kbd{E} command).
-
-On a triple-click, the region consists of the entire line where the click
-occurred with all leading and trailing spaces and tabs removed.
-
-@cindex mouse-insert
-@item viper-mouse-insert-key (meta shift 2)
-@vindex viper-mouse-insert-key
-This variable controls the @emph{mouse-insert} feature of Viper.
-The above default value states that
-holding Meta and Shift keys while clicking mouse button 2
-should insert the region surrounding the
-mouse pointer. The rules defining this region are the same as for
-mouse-search. This command takes an optional prefix argument, which
-indicates how many such regions to snarf from the buffer and insert. (In
-case of a triple-click, the prefix argument is ignored.)
-
-Note: while loading initially, Viper binds this mouse action only if it not
-already bound to something else. If you want to use this feature and the
-default mouse action is already bound, you can rebind mouse-insert by
-placing this command in your Viper customization file:
-@lisp
-(setq viper-mouse-insert-key '(meta 2))
-@end lisp
-If you want to bind mouse-insert to an action even if this action is
-already taken for other purposes in Emacs, then you should add this command
-to your Viper customization file, after setting @code{viper-mouse-insert-key}:
-@lisp
-(viper-bind-mouse-insert-key 'force)
-@end lisp
-
-This value can also be changed via the Emacs customization widget at the
-menubar.
-
-@item viper-multiclick-timeout
-This variable controls the rate at which double-clicking must occur for the
-purpose of mouse search and mouse insert. By default, this is set to
-@code{double-click-time}.
-@end table
-@kindex S-mouse-1
-@kindex S-mouse-2
-@kindex META SHIFT button1up
-@kindex META SHIFT button2up
-@vindex viper-multiclick-timeout
-@findex viper-mouse-click-insert-word
-@findex viper-mouse-click-search-word
-
-Note: The above functions search and insert in the selected window of
-the latest active frame. This means that you can click in another window or
-another frame and have search or insertion done in the frame and window you
-just left. This lets one use these functions in a multi-frame
-configuration. However, this may require some getting used to. For
-instance, if you are typing in a frame, A, and then move the mouse to frame
-B and click to invoke mouse search, search (or insertion) will be performed
-in frame A@. To perform search/insertion in frame B, you will first have to
-shift focus there, which doesn't happen until you type a character or
-perform some other action in frame B---mouse search doesn't shift focus.
-
-If you decide that you don't like the above feature and always want
-search/insertion be performed in the frame where the click occurs, don't
-bind (and unbind, if necessary) @code{viper-mouse-catch-frame-switch} from
-the mouse event it is bound to.
-
-Mouse search is integrated with Vi-style search, so you can
-repeat it with @kbd{n} and @kbd{N}. It should be also noted that, while
-case-sensitivity of search in Viper is controlled by the variable
-@code{viper-case-fold-search}, the case of mouse search is
-controlled by the Emacs variable @code{case-fold-search}, which may be set
-differently from @code{viper-case-fold-search}. Therefore, case-sensitivity
-of mouse search may be different from that of the usual Vi-style search.
-
-Finally, if the way Viper determines the word to be searched for or to be
-inserted is not what you want, there is a variable,
-@code{viper-surrounding-word-function}, which can be changed to indicate
-another function for snarfing words out of the buffer. The catch is that
-you will then have to write such a function and make it known to your
-Emacs. The function @code{viper-surrounding-word} in @file{viper.el} can be
-used as a guiding example.
-
-@node Vi Macros
-@section Vi Macros
-
-@cindex Vi macros
-
-Viper supports much enhanced Vi-style macros and also facilitates the use
-of Emacs-style macros. To define a temporary macro, it is generally more
-convenient to use Emacs keyboard macro facility. Emacs keyboard macros are
-usually defined anonymously, and the latest macro can be executed by typing
-@kbd{C-x e} (or @kbd{*}, if Viper is in Vi state). If you need to use several
-temporary macros, Viper lets you save them to a
-register (a lowercase letter); such macros can then be executed by typing
-@kbd{@@a} in Vi state (if a macro was previously saved in register
-@kbd{a}).
-@xref{Macros and Registers}, for details.
-
-If, however, you need to use a macro regularly, it must be given a
-permanent name and saved. Emacs manual explains how to do this, but
-invocation of named Emacs macros is quite different from Vi's. First,
-invocation of permanent Emacs macros takes time because it requires typing
-too many keys (to a Vi user's taste, anyway).
-Second, binding such macros to function keys, for
-fast access, hogs valuable real estate on the keyboard.
-
-Vi-style macros are better in that respect, since Vi lets the user overload
-the meaning of key sequences: keys typed in fast succession are treated
-specially, if this key sequence is bound to a macro.
-
-Viper provides Vi-style keyboard macros through the usual Ex commands,
-@kbd{:map} and
-@kbd{:map!}. These macros are much more powerful in Viper than
-they are in the original Vi and in other emulators. This is because Viper
-implements an enhanced vi-style
-interface to the powerful Emacs keyboard macro facility.
-
-First, any Emacs
-command can be executed while defining a macro, not just the Vi
-commands. In particular, the user can invoke Emacs commands via @kbd{M-x
-command-name} or by pressing various function keys on the keyboard. One
-can even use the mouse, although this is usually not useful and is not
-recommended (and macros defined with the use of the mouse cannot be saved in
-command history and in the startup file, for future use).
-
-Macros defined by mixing Vi and Emacs commands are represented as
-vectors. So, don't be confused when you see one (usually through the
-history of Ex commands). For instance, if @kbd{gg} is defined by typing
-@kbd{l}, the up-arrow key and @kbd{M-x next-line}, its definition will look
-as follows in Emacs:
-
-@example
-[l up (meta x) n e x t - l i n e return]
-@end example
-
-Second, Viper macros are defined in a WYSIWYG style. This means that
-commands are executed as you type them, so you can see precisely what is
-being defined. Third, macros can be bound to arbitrary sequences of keys,
-not just to printable keys. For instance, one can define a macro that will
-be invoked by hitting @kbd{f3} then @kbd{f2} function keys. (The keys
-@kbd{delete} and @kbd{backspace} are excluded; also, a macro invocation
-sequence can't start with @key{ESC}. Some other keys, such as @kbd{f1} and
-@kbd{help}, can't be bound to macros under Emacs, since they
-are bound in @code{key-translation-map}, which overrides any other binding
-the user gives to keys. In general, keys that have a binding in
-@code{key-translation-map} can't be bound to a macro.)
-
-Fourth, in Viper, one can define macros that are specific to a given
-buffer, a given major mode, or macros that are defined for all buffers. In
-fact, the same macro name can have several different definitions: one
-global, several definitions for various major modes, and
-definitions for various specific buffers. Buffer-specific definitions
-override mode-specific definitions, which, in turn, override global
-definitions.
-
-As if all that is not enough, Viper (through its interface to Emacs
-macros) lets the user define keyboard macros that ask for confirmation or
-even prompt the user for input and then continue. To do this, one should
-type @kbd{C-x q} (for confirmation) or @kbd{C-u C-x q} (for prompt).
-For details, @pxref{Keyboard Macro Query,,Customization,emacs,The GNU Emacs
-Manual}.
-
-When the user finishes defining a macro (which is done by typing @kbd{C-x)},
-a departure from Vi), you will be asked whether you want this
-macro to be global, mode-specific, or buffer-specific. You will also be
-given a chance to save the macro in your Viper customization file.
-This is the easiest way to save a macro and make
-it permanently available. If you work your startup files with bare hands,
-here is how Viper saves the above macro so that it will be
-available in Viper's Insert state (and Replace state) in buffer @code{my-buf}
-only:
-
-@example
-(viper-record-kbd-macro "gg" 'insert-state
- [l up (meta x) n e x t - l i n e return]
- "my-buf")
-@end example
-
-@noindent
-To do the same for Vi state and all buffers with the major mode
-@code{cc-mode}, use:
-
-@example
-(viper-record-kbd-macro "gg" 'vi-state
- [l up (meta x) n e x t - l i n e return]
- 'cc-mode)
-@end example
-
-@noindent
-Both macro names and macro definitions are vectors of symbols that denote
-keys on the keyboard. Some keys, like @kbd{\}, @kbd{ }, or digit-keys must
-be escaped with a backslash. Modified keys are represented as lists. For
-instance, holding Meta and Control and pressing @kbd{f4} is represented as
-@kbd{(control meta f4)}.
-If all members of a vectors are printable characters (or sequences, such as
-@kbd{\e}, @kbd{\t}, for @key{ESC} and @key{TAB}), then they can also be represented as
-strings:
-
-@example
-(viper-record-kbd-macro "aa" 'vi-state "aaa\e" "my-buffer")
-@end example
-
-@noindent
-Thus, typing @kbd{aa} fast in Vi state will switch Viper to Insert state
-(due to the first @kbd{a}), insert @kbd{aa}, and then it will switch back to Vi
-state. All this will take effect only in the buffer named @code{my-buffer}.
-
-Note that the last argument to @code{viper-record-kbd-macro} must be either a
-string (a buffer name), a symbol representing a major mode, or @code{t};
-the latter says that the macro is to be defined for all buffers
-(which is how macros are defined in original Vi).
-
-For convenience, Viper also lets you define Vi-style macros in its Emacs
-state. There is no Ex command, like @kbd{:map} and @kbd{:map!} for doing
-this, but the user can include such a macro in the Viper customization file.
-The only thing is that the @code{viper-record-kbd-macro} command should specify
-@code{emacs-state} instead of @code{vi-state} or @code{insert-state}.
-
-The user can get rid of a macro either by using the Ex commands @kbd{:unmap}
-and @kbd{:unmap!} or by issuing a call to @code{viper-unrecord-kbd-macro}.
-The latter is more powerful, since it can delete macros even in
-@code{emacs-state}. However, @code{viper-unrecord-kbd-macro} is usually
-needed only when the user needs to get rid of the macros that are already
-predefined in Viper.
-The syntax is:
-@findex viper-unrecord-kbd-macro
-@example
-(viper-unrecord-kbd-macro macro state)
-@end example
-@noindent
-The second argument must be @code{vi-state}, @code{insert-state}, or
-@code{emacs-state}. The first argument is a name of a macro. To avoid
-mistakes in specifying names of existing macros, type @kbd{M-x
-viper-describe-kbd-macros} and use a name from the list displayed by this
-command.
-
-If an error occurs during macro definition, Emacs
-aborts the process, and it must be repeated. This is analogous to Vi,
-except that in Vi the user doesn't know there is an error until the macro is
-actually run. All that means that in order for a definition to be
-successful, the user must do some simple planning of the process in
-advance, to avoid errors. For instance, if you want to map @kbd{gg} to
-@kbd{llll} in Vi state, you must make sure that there is enough room on the
-current line. Since @kbd{l} moves the cursor forward, it may signal an
-error on reaching the end of line, which will abort the definition.
-
-These precautions are necessary only when defining macros; they will help
-avoid the need to redo the job. When macros are actually run, an error
-during the execution will simply terminate the current execution
-(but the macro will remain mapped).
-
-A macro name can be a string of characters or a vector of keys.
-The latter makes it possible to define macros bound to, say, double-hits
-on a function key, such as @kbd{up} or @kbd{f13}.
-This is very useful if you run out of function keys on your keyboard; it
-makes Viper macro facility a @emph{keyboard doubler}, so to speak.
-
-Elsewhere (@xref{Key Bindings}, for details), we review
-the standard Emacs mechanism for binding function keys to commands.
-For instance,
-
-@example
-(keymap-global-set "<f13>" 'repeat-complex-command)
-@end example
-
-@noindent
-binds the key f13 to the Emacs function that repeats the last minibuffer
-command. Under Viper, however, you may still use this key for additional
-purposes, if you bind, say, a double-hitting action for that key to some
-other function. Emacs doesn't allow the user to do that, but Viper does
-this through its keyboard macro facility. To do this, type @kbd{:map }
-first. When you are asked to enter a macro name, hit f13 twice, followed by
-@key{RET} or @key{SPC}.
-
-Emacs will now start the mapping process by actually executing
-Vi and Emacs commands, so that you could see what will happen each time the
-macro is executed. Suppose now we wanted to bind the key sequence
-@kbd{f13 f13} to the command @code{eval-last-sexp}. To accomplish this, we
-can type @kbd{M-x eval-last-sexp} followed by @kbd{C-x )}.
-If you answer positively to Viper's offer to save this macro in your
-Viper customization file for future uses, the following will be inserted
-in that file:
-
-@example
-(viper-record-kbd-macro [f16 f16] 'vi-state
- [(meta x) e v a l - l a s t - s e x p]
- 'lisp-interaction-mode)
-@end example
-
-To illustrate the above point, Viper provides two canned macros, which, by
-default, are bound to @kbd{[f12 \1]} and @kbd{[f12 \2]} (invoked by typing
-@kbd{f12} then @kbd{1} and @kbd{2}, respectively). These macros are useful
-shortcuts to Viper's command ring history. The first macro will execute the
-second-last destructive command (the last one is executed by @kbd{.}, as
-usual). The second macro executes the third-last command.
-
-If you need to go deeper into the command history, you will have to use
-other commands, as described earlier in this section; or you can bind,
-say, @kbd{f12 \3} like this:
-
-@example
-(viper-record-kbd-macro [f12 \3] 'vi-state
- [(meta x) r e p e a t - f r o m - h i s t o r y]
- t)
-@end example
-
-
-Note that even though the macro uses the function key @kbd{f12}, the key is
-actually free and can still be bound to some Emacs function via
-@code{define-key} or @code{keymap-global-set}.
-
-
-Viper allows the user to define macro names that are prefixes of other macros.
-For instance, one can define @kbd{[[} and @kbd{[[[[} to be macros.
-If you type the exact sequence of such keys and then pause, Viper will
-execute the right macro. However, if you don't pause and, say, type
-@kbd{[[[[text} then the conflict is resolved as follows. If only one of the
-key sequences, @kbd{[[} or @kbd{[[[[} has a definition applicable to the
-current buffer, then, in fact, there is no conflict and the right macro
-will be chosen. If both have applicable definitions, then the first one
-found will be executed. Usually this is the macro with a shorter name. So,
-in our case, @kbd{[[[[text} will cause the macro @kbd{[[} to be executed
-twice and then the remaining keys, @kbd{t e x t}, will be processed.
-
-When defining macros using @kbd{:map} or @kbd{:map!}, the user enters
-the actually keys to be used to invoke the macro. For instance, you
-should hit the actual key @kbd{f6} if it is to be part of a macro
-name; you do @emph{not} write @kbd{f 6}. When entering keys, Viper
-displays them as strings or vectors (e.g., @code{"abc"} or @code{[f6
-f7 a]}). The same holds for unmapping. Hitting @key{TAB} while
-typing a macro name in the @kbd{:unmap} or @kbd{:unmap!} command will
-cause name completion. Completions are displayed as strings or
-vectors. However, as before, you don't actually type @samp{"},
-@samp{[}, or @samp{]} that appear in the completions. These are
-meta-symbols that indicate whether the corresponding macro name is a
-vector or a string.
-
-One last difference from Vi: Vi-style keyboard macros cannot be defined in
-terms of other Vi-style keyboard macros (but named Emacs macros are OK).
-More precisely, while defining or executing a macro, the special meaning
-of key sequences (as Vi macros) is ignored.
-This is because it is all too easy to create an infinite loop in this way.
-Since Viper macros are much more powerful than Vi's it is impossible to
-detect such loops. In practice, this is not really a limitation but,
-rather, a feature.
-
-We should also note that Vi macros are disabled in the minibuffer, which
-helps keep some potential troubles away.
-
-The rate at which the user must type keys in order for them to be
-recognized as a timeout macro is controlled by the variable
-@code{viper-fast-keyseq-timeout}, which defaults to 200 milliseconds.
-
-For the most part, Viper macros defined in the Viper customization file can
-be shared between X and TTY modes.
-The problem with TTY may be that the function keys there generate sequences
-of events instead of a single event (as under a window system).
-Emacs maps some of these sequences back to the logical keys
-(e.g., the sequences generated by the arrow keys are mapped to @kbd{up},
-@kbd{left}, etc.). However, not all function keys are mapped in this way.
-Macros that are bound to key sequences that contain such unmapped function
-keys have to be redefined for TTY's (and possibly for every type of TTY you
-may be using). To do this, start Emacs on an appropriate TTY device and
-define the macro using @kbd{:map}, as usual.
-
-@findex viper-describe-kbd-macros
-Finally, Viper provides a function that conveniently displays all macros
-currently defined. To see all macros along with their definitions, type
-@kbd{M-x viper-describe-kbd-macros}.
-
-@node Commands
-@chapter Commands
-
-This section is a semi-automatically bowdlerized version of the Vi
-reference created by @* @samp{maart@@cs.vu.nl} and others. It can be
-found on the Vi archives. This reference has been adapted for Viper.
-
-@menu
-* Groundwork:: Textual Conventions and Viper basics
-* Text Handling:: Moving, Editing, Undoing.
-* Display:: Scrolling.
-* File and Buffer Handling:: Editing, Writing and Quitting.
-* Mapping:: Mapping Keys, Keyboard Macros
-* Shell Commands:: Accessing Shell Commands, Processing Text
-* Options:: Ex options, the @kbd{:set} commands
-* Emacs Related Commands:: Meta Keys, Windows
-* Mouse-bound Commands:: Search and insertion of text
-@end menu
-
-@node Groundwork
-@section Groundwork
-
-The VI command set is based on the idea of combining motion commands
-with other commands. The motion command is used as a text region
-specifier for other commands.
-We classify motion commands into @dfn{point commands} and
-@dfn{line commands}.
-
-@cindex point commands
-
-The point commands are:
-
-@quotation
-@kbd{h}, @kbd{l}, @kbd{0}, @kbd{$}, @kbd{w}, @kbd{W}, @kbd{b}, @kbd{B},
-@kbd{e}, @kbd{E}, @kbd{(}, @kbd{)}, @kbd{/}, @kbd{?}, @kbd{`}, @kbd{f},
-@kbd{F}, @kbd{t}, @kbd{T}, @kbd{%}, @kbd{;}, @kbd{,}, @kbd{^}
-@end quotation
-
-@cindex line commands
-
-The line commands are:
-
-@quotation
-@kbd{j}, @kbd{k}, @kbd{+}, @kbd{-}, @kbd{H}, @kbd{M}, @kbd{L}, @kbd{@{},
-@kbd{@}}, @kbd{G}, @kbd{'}, @kbd{[[}, @kbd{]]}, @kbd{[]}
-@end quotation
-@noindent
-
-Text Deletion Commands (@pxref{Deleting Text}), Change commands
-(@pxref{Changing Text}), even Shell Commands (@pxref{Shell Commands})
-use these commands to describe a region of text to operate on.
-
-@cindex r and R region specifiers
-
-Viper adds two region descriptors, @kbd{r} and @kbd{R}. These describe
-the Emacs regions (@pxref{Basics}), but they are not movement commands.
-
-The command description uses angle brackets @samp{<>} to indicate
-metasyntactic variables, since the normal conventions of using simple
-text can be confusing with Viper where the commands themselves are
-characters. Watch out where @kbd{<} shift commands and @kbd{<count>} are
-mentioned together!!!
-
-@kindex <move>
-@kindex <a-z>
-@kindex <address>
-@cindex <move>
-@cindex <a-z>
-@cindex <address>
-@cindex movements
-
-@samp{<move>} refers to the above movement commands, and @samp{<a-z>}
-refers to registers or textmarkers from @samp{a} to @samp{z}. Note
-that the @samp{<move>} is described by full move commands, that is to
-say they will take counts, and otherwise behave like normal move commands.
-@cindex Ex addresses
-@samp{<address>} refers to Ex line addresses, which include
-
-@table @kbd
-@item .@: <No address>
-Current line
-@item .+n .-n
-Add or subtract for current line
-@item number
-Actual line number, use @kbd{.=} to get the line number
-@item '<a-z>
-Textmarker
-@item $
-Last line
-@item x,y
-Where x and y are one of the above
-@item %
-@cindex % (Ex address)
-For the whole file, same as (1,$).
-@item /<pat>/
-@itemx ?<pat>?
-Next or previous line with pattern <pat>.
-
-Note that the pattern is allowed to contain newline character (inserted as
-@kbd{C-qC-j}). Therefore, one can search for patterns that span several
-lines.
-@end table
-
-@cindex % (Current file)
-Note that @samp{%} is used in Ex commands @kbd{:e} and @kbd{:r <shell-cmd>}
-to mean current file. If you want a @samp{%} in your command, it must be
-escaped as @samp{\%}. Note that @kbd{:w} and the regular @kbd{:r <file>}
-command doesn't support the meta symbols @samp{%} and @samp{#}, because
-file history is a better mechanism.
-@cindex # (Previous file)
-Similarly, @samp{#} expands to the previous file. The previous file is
-the first file in @kbd{:args} listing. This defaults to previous window
-in the VI sense if you have one window only.
-
-@kindex <args>
-@kindex <cmd>
-@cindex <args>
-@cindex <cmd>
-@noindent
-Others like @samp{<args> -- arguments}, @samp{<cmd> -- command} etc.
-should be fairly obvious.
-
-@noindent
-Common characters referred to include:
-
-@table @kbd
-@item <sp>
-Space
-@item <ht>
-Tab
-@item <lf>
-Linefeed
-@item <esc>
-Escape
-@item <cr>
-Return, Enter
-@end table
-@cindex <cr>
-@cindex <esc>
-@cindex <lf>
-@cindex <ht>
-@cindex <sp>
-
-@cindex words
-@cindex WORDS
-@cindex char
-@cindex CHAR
-
-We also use @samp{word} for alphanumeric/non-alphanumeric words, and
-@samp{WORD} for whitespace delimited words. @samp{char} refers to any
-@acronym{ASCII} character, @samp{CHAR} to non-whitespace character.
-Brackets @samp{[]} indicate optional parameters; @samp{<count>} also
-optional, usually defaulting to 1. Brackets are elided for
-@samp{<count>} to eschew obfuscation.
-
-Viper's idea of Vi's words is slightly different from Vi. First, Viper
-words understand Emacs symbol tables. Therefore, all symbols declared to be
-alphanumeric in a symbol table can automatically be made part of the Viper
-word. This is useful when, for instance, editing text containing European,
-Cyrillic, Japanese, etc., texts.
-
-Second, Viper lets you depart from Vi's idea of a word by changing the a
-syntax preference via the customization widget (the variable
-@code{viper-syntax-preference}) or by executing
-@code{viper-set-syntax-preference} interactively.
-
-By default, Viper syntax preference is @code{reformed-vi}, which means that
-Viper considers only those symbols to be part of a word that are specified
-as word-symbols by the current Emacs syntax table (which may be different
-for different major modes) plus the underscore symbol @kbd{_}, minus the
-symbols that are not considered words in Vi (e.g., @samp{,}, @samp{;},
-etc.), but may be
-considered as word-symbols by various Emacs major modes. Reformed-Vi works
-very close to Vi, and it also recognizes words in other
-alphabets. Therefore, this is the most appropriate mode for editing text
-and is likely to fit all your needs.
-
-You can also set Viper syntax preference to @code{strict-vi}, which would
-cause Viper to view all non-English letters as non-word-symbols.
-
-You can also specify @code{emacs} as your preference, which would
-make Viper use exactly the same notion of a word as Emacs does. In
-particular, the underscore may not be part of a word in some major modes.
-
-Finally, if @code{viper-syntax-preference} is set to @code{extended}, Viper
-words would consist of characters that are classified as alphanumeric
-@emph{or} as parts of symbols. This is convenient for editing programs.
-
-@code{viper-syntax-preference} is a local variable, so it can have different
-values for different major modes. For instance, in programming modes it can
-have the value @code{extended}. In text modes where words contain special
-characters, such as European (non-English) letters, Cyrillic letters, etc.,
-the value can be @code{reformed-vi} or @code{emacs}.
-If you consider using different syntactic preferences for different major
-modes, you should execute, for example,
-
-@example
-(viper-set-syntax-preference nil "extended")
-@end example
-
-in the appropriate major mode hooks.
-
-@vindex viper-syntax-preference
-@findex viper-set-syntax-preference
-@cindex syntax table
-
-
-
-The above discussion concerns only the movement commands. In regular
-expressions, words remain the same as in Emacs. That is, the expressions
-@code{\w}, @code{\>}, @code{\<}, etc., use Emacs's idea of what is a word,
-and they don't look into the value of variable
-@code{viper-syntax-preference}. This is because Viper avoids changing
-syntax tables in order to not thwart the various major modes that set these
-tables.
-
-The usual Emacs convention is used to indicate Control Characters, i.e.,
-C-h for Control-h. @emph{Do not confuse this with a sequence of separate
-characters
-C, -, h!!!} The @kbd{^} is itself, never used to indicate a
-Control character.
-
-Finally, we note that Viper's Ex-style commands can be made to work on the
-current Emacs region. This is done by typing a digit argument before
-@kbd{:}. For instance, typing @kbd{1:} will prompt you with something like
-@emph{:123,135}, assuming that the current region starts at line 123 and
-ends at line 135. There is no need to type the line numbers, since Viper
-inserts them automatically in front of the Ex command.
-@cindex Ex commands
-
-@node Text Handling
-@section Text Handling
-
-@menu
-* Move Commands:: Moving, Searching
-* Marking:: Textmarkers in Viper and the Emacs Mark.
-* Appending Text:: Text insertion, Shifting, Putting
-* Editing in Insert State:: Autoindent, Quoting etc.
-* Deleting Text:: Deleting
-* Changing Text:: Changing, Replacement, Joining
-* Search and Replace:: Searches, Query Replace, Pattern Commands
-* Yanking:: Yanking, Viewing Registers
-* Undoing:: Multiple Undo, Backups
-@end menu
-
-@node Move Commands
-@subsection Move Commands
-
-@cindex movement commands
-@cindex searching
-@cindex textmarkers
-@cindex markers
-@cindex column movement
-@cindex paragraphs
-@cindex headings
-@cindex sections
-@cindex sentences
-@cindex matching parens
-@cindex paren matching
-
-@table @kbd
-@item <count> h C-h
-<count> chars to the left.
-@item <count> j <lf> C-n
-<count> lines downward.
-@item <count> l <sp>
-<count> chars to the right.
-@item <count> k C-p
-<count> lines upward.
-@item <count> $
-To the end of line <count> from the cursor.
-@item <count> ^
-To the first CHAR <count> @minus{} 1 lines lower.
-@item <count> -
-To the first CHAR <count> lines higher.
-@item <count> + <cr>
-To the first CHAR <count> lines lower.
-@item 0
-To the first char of the line.
-@item <count> |
-To column <count>
-@item <count> f<char>
-<count> <char>s to the right (find).
-@item <count> t<char>
-Till before <count> <char>s to the right.
-@item <count> F<char>
-<count> <char>s to the left.
-@item <count> T<char>
-Till after <count> <char>s to the left.
-@item <count> ;
-Repeat latest @kbd{f t F T} <count> times.
-@item <count> ,
-Repeat latest @kbd{f t F T}
-<count> times in opposite direction.
-@item <count> w
-<count> words forward.
-@item <count> W
-<count> WORDS forward.
-@item <count> b
-<count> words backward.
-@item <count> B
-<count> WORDS backward.
-@item <count> e
-To the end of word <count> forward.
-@item <count> E
-To the end of WORD <count> forward.
-@item <count> G
-Go to line <count> (default end-of-file).
-@item <count> H
-To line <count> from top of the screen (home).
-@item <count> L
-To line <count> from bottom of the screen (last).
-@item M
-To the middle line of the screen.
-@item <count> )
-<count> sentences forward.
-@item <count> (
-<count> sentences backward.
-@item <count> @}
-<count> paragraphs forward.
-@item <count> @{
-<count> paragraphs backward.
-@item <count> ]]
-To the <count>th heading.
-@item <count> [[
-To the <count>th previous heading.
-@item <count> []
-To the end of <count>th heading.
-@item m<a-z>
-Mark the cursor position with a letter.
-@item `<a-z>
-To the mark.
-@item '<a-z>
-To the first CHAR of the line with the mark.
-@item [<a-z>
-Show contents of textmarker.
-@item ]<a-z>
-Show contents of register.
-@item ``
-To the cursor position before the latest absolute
-jump (of which are examples @kbd{/} and @kbd{G}).
-@item ''
-To the first CHAR of the line on which the cursor
-was placed before the latest absolute jump.
-@item <count> /<string>
-To the <count>th occurrence of <string>.
-@item <count> /<cr>
-To the <count>th occurrence of <string> from previous @kbd{/ or ?}.
-@item <count> ?<string>
-To the <count>th previous occurrence of <string>.
-@item <count> ?<cr>
-To the <count>th previous occurrence of <string> from previous @kbd{?@: or /}.
-@item n
-Repeat latest @kbd{/} @kbd{?} (next).
-@item N
-Repeat latest search in opposite direction.
-@item C-c /
-Without a prefix argument, this command toggles
-case-sensitive/case-insensitive search modes and plain vanilla/regular
-expression search. With the prefix argument 1, i.e.,
-@kbd{1 C-c /}, this toggles case-sensitivity; with the prefix argument 2,
-toggles plain vanilla search and search using
-regular expressions. @xref{Viper Specials}, for alternative ways to invoke
-this function.
-@cindex vanilla search
-@cindex case-sensitive search
-@cindex case-insensitive search
-@item %
-Find the next bracket/parenthesis/brace and go to its match.
-By default, Viper ignores brackets/parentheses/braces that occur inside
-parentheses. You can change this by setting
-@code{viper-parse-sexp-ignore-comments} to @code{nil} in your Viper
-customization file.
-This option can also be toggled interactively if you quickly hit @kbd{%%%}.
-
-This latter feature is implemented as a vi-style keyboard macro. If you
-don't want this macro, put
-
-@example
-(viper-set-parsing-style-toggling-macro 'undefine)
-@end example
-@findex viper-set-parsing-style-toggling-macro
-
-in your Viper customization file.
-
-@end table
-@kindex %
-@kindex C-c /
-@kindex N
-@kindex n
-@kindex ?<cr>
-@kindex /<cr>
-@kindex ?<string>
-@kindex /<string>
-@kindex ''
-@kindex ``
-@kindex ]<a-z>
-@kindex [<a-z>
-@kindex '<a-z>
-@kindex `<a-z>
-@kindex m<a-z>
-@kindex []
-@kindex [[
-@kindex ]]
-@kindex @{
-@kindex @}
-@kindex (
-@kindex )
-@kindex M
-@kindex L
-@kindex H
-@kindex G
-@kindex E
-@kindex e
-@kindex B
-@kindex b
-@kindex W
-@kindex w
-@kindex ,
-@kindex ;
-@kindex T<char>
-@kindex F<char>
-@kindex t<char>
-@kindex f<char>
-@kindex |
-@kindex 0
-@kindex CR
-@kindex +
-@kindex -
-@kindex ^
-@kindex $
-@kindex C-p
-@kindex LF
-@kindex SPC
-@kindex C-n
-@kindex C-h
-@kindex h
-@kindex j
-@kindex k
-@kindex l
-@vindex viper-parse-sexp-ignore-comments
-
-@node Marking
-@subsection Marking
-
-Emacs mark is referred to in the region specifiers @kbd{r} and @kbd{R}.
-@xref{Emacs Preliminaries}, and @xref{Basics}, for explanation. Also
-see @ref{Mark,,Mark,emacs,The GNU Emacs manual}, for an explanation of
-the Emacs mark ring.
-
-@cindex marking
-
-@table @kbd
-@item m<a-z>
-Mark the current file and position with the specified letter.
-@item m .
-Set the Emacs mark (@pxref{Emacs Preliminaries}) at point.
-@item m ^
-Set the Emacs mark (@pxref{Emacs Preliminaries}) back to where it was last
-set with the @kbd{m.} command. This is useful when you set the mark with
-@kbd{m.}, but then some other command (such as @kbd{L} or @kbd{G}) changes
-it in a way that you didn't like.
-@item m <
-Set the Emacs mark at beginning of buffer.
-@item m >
-Set the Emacs mark at end of buffer.
-@item m ,
-Jump to the Emacs mark.
-@item :mark <char>
-Mark position with text marker named <char>. This is an Ex command.
-@item :k <char>
-Same as @kbd{:mark}.
-@item ``
-Exchange point and mark.
-@item ''
-Exchange point and mark and go to the first CHAR on line.
-@item '<a-z>
-Go to specified Viper mark.
-@item `<a-z>
-Go to specified Viper mark and go to the first CHAR on line.
-@end table
-@kindex m<a-z>
-@kindex m.
-@kindex m>
-@kindex m<
-@kindex m,
-@kindex m^
-@findex @kbd{Ex mark}
-@findex @kbd{Ex k}
-@kindex ''
-@kindex ``
-@kindex `<a-z>
-@kindex '<a-z>
-
-@node Appending Text
-@subsection Appending Text
-
-@xref{Options}, to see how to change tab and shiftwidth size. See the GNU
-Emacs manual, or try @kbd{C-ha tabs} (If you have turned Emacs help on).
-Check out the variable @code{indent-tabs-mode} to put in just spaces.
-Also see options for word-wrap.
-
-@cindex inserting
-@cindex appending
-@cindex paste
-@cindex put
-
-@table @kbd
-@item <count> a
-<count> times after the cursor.
-@item <count> A
-<count> times at the end of line.
-@item <count> i
-<count> times before the cursor (insert).
-@item <count> I
-<count> times before the first CHAR of the line
-@item <count> o
-On a new line below the current (open).
-The count is only useful on a slow terminal.
-@item <count> O
-On a new line above the current.
-The count is only useful on a slow terminal.
-@item <count> ><move>
-Shift the lines described by <count><move> one
-shiftwidth to the right (layout!).
-@item <count> >>
-Shift <count> lines one shiftwidth to the right.
-@item <count> ["<a-z1-9>]p
-Put the contents of the (default undo) buffer
-<count> times after the cursor. The register will
-be automatically down-cased.
-@item <count> ["<a-z1-9>]P
-Put the contents of the (default undo) buffer
-<count> times before the cursor. The register will
-@item [<a-z>
-Show contents of textmarker.
-@item ]<a-z>
-Show contents of register.
-@item <count> .
-Repeat previous command <count> times. For destructive
-commands as well as undo.
-@item f1 1 and f1 2
-While @kbd{.} repeats the last destructive command,
-these two macros repeat the second-last and the third-last destructive
-commands. @xref{Vi Macros}, for more information on Vi macros.
-@item C-c M-p and C-c M-n
-In Vi state,
-these commands help peruse the history of Vi's destructive commands.
-Successive typing of @kbd{C-c M-p} causes Viper to search the history in
-the direction
-of older commands, while hitting @kbd{C-c M-n} does so in reverse
-order. Each command in the history is displayed in the minibuffer. The
-displayed command can
-then be executed by typing a period.
-
-Since typing the above sequences of keys may be tedious, the
-functions doing the perusing can be bound to unused keyboard keys in the
-Viper customization file. @xref{Viper Specials}, for details.
-@end table
-@kindex C-c M-p
-@kindex C-c M-n
-@kindex .
-@kindex ]<a-z>
-@kindex [<a-z>
-@kindex P
-@kindex p
-@kindex "<a-z1-9>p
-@kindex "<a-z1-9>P
-@kindex >>
-@kindex ><move>
-@kindex O
-@kindex o
-@kindex i
-@kindex A
-@kindex a
-
-@node Editing in Insert State
-@subsection Editing in Insert State
-
-Minibuffer can be edited similarly to Insert state, and you can switch
-between Insert/Replace/Vi states at will.
-Some users prefer plain Emacs feel in the minibuffer. To this end, set
-@code{viper-vi-style-in-minibuffer} to @code{nil}.
-
-@cindex Insert state
-
-@table @kbd
-@item C-v
-Deprive the next char of its special meaning (quoting).
-@item C-h
-One char back.
-@item C-w
-One word back.
-@item C-u
-Back to the begin of the change on the
-current line.
-
-@end table
-@kindex C-u
-@kindex C-w
-@kindex C-v
-
-@node Deleting Text
-@subsection Deleting Text
-
-
-There is one difference in text deletion that you should be
-aware of. This difference comes from Emacs and was adopted in Viper
-because we find it very useful. In Vi, if you delete a line, say, and then
-another line, these two deletions are separated and are put back
-separately if you use the @samp{p} command. In Emacs (and Viper), successive
-series of deletions that are @emph{not interrupted} by other commands are
-lumped together, so the deleted text gets accumulated and can be put back
-as one chunk. If you want to break a sequence of deletions so that the
-newly deleted text could be put back separately from the previously deleted
-text, you should perform a non-deleting action, e.g., move the cursor one
-character in any direction.
-
-@cindex shifting text
-
-@table @kbd
-@item <count> x
-Delete <count> chars under and after the cursor.
-@item <count> X
-Delete <count> chars before the cursor.
-@item <count> d<move>
-Delete from point to endpoint of <count><move>.
-@item <count> dd
-Delete <count> lines.
-@item D
-The rest of the line.
-@item <count> <<move>
-Shift the lines described by <count><move> one
-shiftwidth to the left (layout!).
-@item <count> <<
-Shift <count> lines one shiftwidth to the left.
-@end table
-@kindex <<
-@kindex <<move>
-@kindex D
-@kindex dd
-@kindex d<move>
-@kindex X
-@kindex x
-
-@node Changing Text
-@subsection Changing Text
-
-@cindex joining lines
-@cindex changing case
-@cindex quoting regions
-@cindex substitution
-
-@table @kbd
-@item <count> r<char>
-Replace <count> chars by <char>; no <esc>.
-@item <count> R
-Overwrite the rest of the line,
-appending change @var{count} @minus{} 1 times.
-@item <count> s
-Substitute <count> chars.
-@item <count> S
-Change <count> lines.
-@item <count> c<move>
-Change from begin to endpoint of <count><move>.
-@item <count> cc
-Change <count> lines.
-@item <count> C
-The rest of the line and <count> @minus{} 1 next lines.
-@item <count> =<move>
-Reindent the region described by move.
-@item <count> ~
-Switch lower and upper cases.
-@item <count> J
-Join <count> lines (default 2).
-@item :[x,y]s/<pat>/<repl>/<f>
-Substitute (on lines x through y) the pattern
-<pat> (default the last pattern) with <repl>. Useful
-flags <f> are @samp{g} for @samp{global} (i.e., change every
-non-overlapping occurrence of <pat>) and @samp{c} for
-@samp{confirm} (type @samp{y} to confirm a particular
-substitution, else @samp{n} ). Instead of @kbd{/} any
-punctuation CHAR unequal to <space> <tab> and <lf> can be used as
-delimiter.
-
-In Emacs, @samp{\&} stands for the last matched expression, so
-@kbd{s/[ab]+/\&\&/} will double the string matched by @kbd{[ab]}.
-Viper doesn't treat @samp{&} specially, unlike Vi: use @samp{\&} instead.
-
-Viper does not parse search patterns and does not expand special symbols
-found there (e.g., @samp{~} is not expanded to the result of the previous
-substitution).
-
-Note: @emph{The newline character (inserted as @kbd{C-qC-j})
-can be used in <repl>}.
-@item :[x,y]copy [z]
-Copy text between @kbd{x} and @kbd{y} to the position after @kbd{z}.
-@item :[x,y]t [z]
-Same as @kbd{:copy}.
-@item :[x,y]move [z]
-Move text between @kbd{x} and @kbd{y} to the position after @kbd{z}.
-@item &
-Repeat latest Ex substitute command, e.g.,
-@kbd{:s/wrong/right}.
-@item :x,yp
-@itemx :g/Pat/p
-@itemx :v/Pat/p
-The above commands display certain buffer lines in a
-temporary buffer. The first form above displays the buffer lines between
-@kbd{x} and @kbd{y}. The second displays the lines of the buffer, which
-match a given pattern. The third form displays the lines that do @emph{not}
-match the given pattern.
-@item #c<move>
-Change upper-case characters in the region to lower-case.
-@item #C<move>
-Change lower-case characters in the region to upper-case.
-@item #q<move>
-Insert specified string at the beginning of each line in the region
-@item C-c M-p and C-c M-n
-In Insert and Replace states, these keys are bound to commands that peruse
-the history of the text
-previously inserted in other insert or replace commands. By repeatedly typing
-@kbd{C-c M-p} or @kbd{C-c M-n}, you will cause Viper to
-insert these previously used strings one by one.
-When a new string is inserted, the previous one is deleted.
-
-In Vi state, these keys are bound to functions that peruse the history of
-destructive Vi commands.
-@xref{Viper Specials}, for details.
-@end table
-@kindex C-c M-p
-@kindex C-c M-n
-@kindex #q<move>
-@kindex #C<move>
-@kindex #c<move>
-@kindex &
-@kindex \&
-@findex @kbd{Ex substitute/<pat>/<repl>/<f>}
-@findex @kbd{Ex s/<pat>/<repl>/<f>}
-@findex @kbd{Ex copy [z]}
-@findex @kbd{Ex t [z]}
-@findex @kbd{Ex move [z]}
-@kindex J
-@kindex ~
-@kindex =<move>
-@kindex C
-@kindex cc
-@kindex c<move>
-@kindex S
-@kindex s
-@kindex R
-@kindex r<char>
-
-@node Search and Replace
-@subsection Search and Replace
-
-@xref{Groundwork}, for Ex address syntax. @xref{Options}, to see how to
-get literal (non-regular-expression) search and how to stop search from
-wrapping around.
-
-@table @kbd
-@item C-c /
-Toggle case-sensitive search. With prefix argument, toggle vanilla/regular
-expression search.
-@item <count> /<string>
-To the <count>th occurrence of <string>.
-
-Viper does not parse search patterns and does not expand special symbols
-found there (e.g., @samp{~} is not expanded to the result of the previous
-substitution).
-
-After typing @kbd{/} or @kbd{?} all the usual Emacs minibuffer commands, such as
-@kbd{M-p} and @kbd{M-n} are available. In addition, typing @kbd{C-s} will
-insert the last search string used by the Emacs incremental search command
-(which is bound to @kbd{C-s} everywhere except in this case).
-
-@item <count> ?<string>
-To the <count>th previous occurrence of <string>.
-@item <count> g<move>
-Search for the text described by move. (off by default)
-@item n
-Repeat latest @kbd{/} @kbd{?} (next).
-@item N
-Idem in opposite direction.
-@item %
-Find the next bracket and go to its match
-@item :[x,y]g/<string>/<cmd>
-@cindex text processing
-Search globally [from line x to y] for <string>
-and execute the Ex <cmd> on each occurrence.
-@item :[x,y]v/<string>/<cmd>
-Execute <cmd> on the lines that don't match.
-@item #g<move>
-Execute the last keyboard macro for each line in the region.
-@xref{Macros and Registers}, for more info.
-@item Q
-Query Replace.
-@item :ta <name>
-Search in the tags file where <name> is defined (file, line), and go to it.
-@item :[x,y]s/<pat>/<repl>/<f>
-Substitute (on lines x through y) the pattern <pat> (default the last
-pattern) with <repl>. Useful
-flags <f> are @samp{g} for @samp{global} (i.e., change every
-non-overlapping occurrence of <pat>) and @samp{c} for
-@samp{confirm} (type @samp{y} to confirm a particular
-substitution, else @samp{n}). Instead of @kbd{/} any
-punctuation character other than <space> <tab> and <lf> can be used as
-delimiter.
-
-Note: @emph{The newline character (inserted as @kbd{C-qC-j})
-can be used in <repl>}.
-@item &
-Repeat latest Ex substitute command, e.g., @kbd{:s/wrong/right}.
-@item :global /<pattern>/<ex-command>
-@itemx :g /<pattern>/<ex-command>
-Execute <ex-command> on all lines that match <pattern>.
-@item :vglobal /<pattern>/<ex-command>
-@itemx :v /<pattern>/<ex-command>
-Execute <ex-command> on all lines that do not match <pattern>.
-@end table
-@kindex &
-@findex @kbd{Ex substitute/<pat>/<repl>/<f>}
-@kindex Q
-@kindex #g<move>
-@findex @kbd{Ex v}
-@findex @kbd{Ex g}
-@findex @kbd{Ex global}
-@findex @kbd{Ex vglobal}
-@findex @kbd{Ex tag <name>}
-@kindex %
-@kindex N
-@kindex n
-@kindex g<move>
-@kindex ?<string>
-@kindex /<string>
-
-@node Yanking
-@subsection Yanking
-
-@cindex cut and paste
-@cindex paste
-
-@table @kbd
-@item <count> y<move>
-Yank from begin to endpoint of <count><move>.
-@item <count> "<a-z>y<move>
-Yank from begin to endpoint of <count><move> to register.
-@item <count> "<A-Z>y<move>
-Yank from begin to endpoint of <count><move> and append
-to register.
-@item <count> yy
-<count> lines.
-@item <count> Y
-Idem (should be equivalent to @kbd{y$} though).
-@item m<a-z>
-Mark the cursor position with a letter.
-@item [<a-z>
-Show contents of textmarker.
-@item ]<a-z>
-Show contents of register.
-@item <count> ["<a-z1-9>]p
-Put the contents of the (default undo) buffer
-<count> times after the cursor. The register will
-be automatically down-cased.
-@item <count> ["<a-z1-9>]P
-Put the contents of the (default undo) buffer
-<count> times before the cursor. The register will
-@end table
-@kindex P
-@kindex p
-@kindex "<a-z1-9>p
-@kindex "<a-z1-9>P
-@kindex ]<a-z>
-@kindex [<a-z>
-@kindex m<a-z>
-@kindex Y
-@kindex yy
-@kindex "<A-Z>y<move>
-@kindex "<a-z>y<move>
-@kindex y<move>
-@kindex yank
-@findex @kbd{Ex yank}
-
-@node Undoing
-@subsection Undoing
-
-@cindex undo
-@cindex backup files
-
-@table @kbd
-@item u U
-Undo the latest change.
-@item .
-Repeat undo.
-@item :q!
-Quit Vi without writing.
-@item :e!
-Re-edit a messed-up file.
-@item :rec
-Recover file from autosave. Viper also creates backup files
-that have a @samp{~} appended to them.
-@end table
-@findex @kbd{Ex rec}
-@findex @kbd{Ex e!}
-@findex @kbd{Ex q!}
-@kindex .
-@kindex U
-@kindex u
-
-@node Display
-@section Display
-
-@cindex scrolling
-
-@table @kbd
-@item C-g
-At user level 1,
-give file name, status, current line number
-and relative position.@*
-At user levels 2 and higher, abort the current command.
-@item C-c g
-Give file name, status, current line number and relative position---all
-user levels.
-@item C-l
-Refresh the screen.
-@item <count> C-e
-Expose <count> more lines at bottom, cursor stays put (if possible).
-@item <count> C-y
-Expose <count> more lines at top, cursor stays put (if possible).
-@item <count> C-d
-Scroll <count> lines downward (default the number of the previous scroll;
-initialization: half a page).
-@item <count> C-u
-Scroll <count> lines upward (default the number of the previous scroll;
-initialization: half a page).
-@item <count> C-f
-<count> pages forward.
-@item <count> C-b
-<count> pages backward (in older versions @kbd{C-b} only works without count).
-@item <count> z<cr>
-@item zH
-Put line <count> at the top of the window (default the current line).
-@item <count> z-
-@item zL
-Put line <count> at the bottom of the window
-(default the current line).
-@item <count> z.
-@item zM
-Put line <count> in the center of the window
-(default the current line).
-@end table
-@kindex zM
-@kindex zL
-@kindex zH
-@kindex z<cr>
-@kindex z.
-@kindex z-
-@kindex z<cr>
-@kindex C-b
-@kindex C-f
-@kindex C-u
-@kindex C-d
-@kindex C-y
-@kindex C-e
-@kindex C-l
-@kindex C-g
-
-
-@node File and Buffer Handling
-@section File and Buffer Handling
-
-@cindex multiple files
-
-In all file handling commands, space should be typed before entering the file
-name. If you need to type a modifier, such as @kbd{>>} or @kbd{!}, don't
-put any space between the command and the modifier.
-
-Note that many Ex commands, e.g., @kbd{:w}, accept command arguments. The
-effect is that the command would start acting on the current region. For
-instance, if the current region spans the lines 11 through 22, then if you
-type @kbd{1:w} you would see @samp{:11,22w} in the minibuffer.
-
-@table @kbd
-@item :q
-Quit buffer except if modified.
-@item :q!
-Quit buffer without checking. In Viper, these two commands
-are identical. Confirmation is required if exiting modified buffers that
-visit files.
-@item :suspend
-@item :stop
-Suspend Viper
-@item :[x,y] w
-Write the file. Viper makes sure that a final newline is always added to
-any file where this newline is missing. This is done by setting Emacs
-variable @code{require-final-newline} to @code{t}. If you don't like this
-feature, use @code{setq-default} to set @code{require-final-newline} to
-@code{nil}. This must be done in the Viper customization file.
-@item :[x,y] w <name>
-Write to the file <name>.
-@item :[x,y] w>> <name>
-Append the buffer to the file <name>. There should be no space between
-@kbd{w} and @kbd{>>}. Type space after the @kbd{>>} and see what happens.
-@item :w!@: <name>
-Overwrite the file <name>. In Viper, @kbd{:w} and @kbd{:w!} are identical.
-Confirmation is required for writing to an existing file (if this is not
-the file the buffer is visiting) or to a read-only file.
-@item :x,y w <name>
-Write lines x through y to the file <name>.
-@item :wq
-Write the file and kill buffer.
-@item :r <file> [<file> ...]
-Read file into a buffer, inserting its contents after the current line.
-@item :xit
-Same as @kbd{:wq}.
-@item :Write
-@itemx :W
-Save all unsaved buffers, asking for confirmation.
-@item :WWrite
-@itemx :WW
-Like @kbd{W}, but without asking for confirmation.
-@item ZZ
-Save current buffer and kill it. If user level is 1, then save all files
-and kill Emacs. Killing Emacs is the wrong way to use it, so you should
-switch to higher user levels as soon as possible.
-@item :x [<file>]
-Save and kill buffer.
-@item :x!@: [<file>]
-@kbd{:w![<file>]} and @kbd{:q}.
-@item :pre
-Preserve the file---autosave buffers.
-@item :rec
-Recover file from autosave.
-@item :f [<file>]
-without the argument, prints file name and character/line information afout
-the currently visited file. With an argument, sets the currently visited
-filename to @file{file}.
-@item :cd [<dir>]
-Set the working directory to <dir> (default home directory).
-@item :pwd
-Print present working directory.
-@item :e [+<cmd>] <files>
-Edit files. If no filename is given, edit the file visited by the current
-buffer. If buffer was modified or the file changed on disk, ask for
-confirmation. Unlike Vi, Viper allows @kbd{:e} to take multiple arguments.
-The first file is edited the same way as in Vi. The rest are visited
-in the usual Emacs way.
-@item :e!@: [+<cmd>] <files>
-Re-edit file. If no filename, re-edit current file.
-In Viper, unlike Vi, @kbd{e!} is identical to @kbd{:e}. In both cases, the
-user is asked to confirm if there is a danger of discarding changes to a
-buffer.
-@item :q!
-Quit Vi without writing.
-@item C-^
-Edit the alternate (normally the previous) file.
-@item :rew
-Obsolete
-@item :args
-List files not shown anywhere with counts for next
-@item :n [count] [+<cmd>] [<files>]
-Edit <count> file, or edit files. The count comes from @kbd{:args}.
-@item :N [count] [+<cmd>] [<files>]
-Like @kbd{:n}, but the meaning of the variable
-@code{ex-cycle-other-window} is reversed.
-@item :b
-Switch to another buffer. If @code{ex-cycle-other-window} is @code{t},
-switch in another window. Buffer completion is supported.
-The variable @code{viper-read-buffer-function} controls which function is
-actually used to read the buffer name. The default is @code{read-buffer},
-but better alternatives are also available in Emacs (e.g.,
-@code{ido-read-buffer}).
-@vindex viper-read-buffer-function
-@item :B
-Like @kbd{:b}, but the meaning of @code{ex-cycle-other-window} is reversed.
-@item :<address>r <name>
-Read the file <name> into the buffer after the line <address>.
-@item v, V, C-v
-Edit a file in current or another window, or in another frame. File name
-is typed in minibuffer. File completion and history are supported.
-@end table
-@kindex v
-@kindex V
-@findex @kbd{Ex args}
-@findex @kbd{Ex rew}
-@kindex C-^
-@findex @kbd{Ex e!@: [<files>]}
-@findex @kbd{Ex e [<files>]}
-@findex @kbd{Ex edit [<files>]}
-@findex @kbd{Ex edit!@: [<files>]}
-@findex @kbd{Ex q!}
-@findex @kbd{Ex q}
-@findex @kbd{Ex quit}
-@findex @kbd{Ex quit!}
-@findex @kbd{Ex f}
-@findex @kbd{Ex rec}
-@findex @kbd{Ex r}
-@findex @kbd{Ex read}
-@findex @kbd{Ex pre}
-@kindex ZZ
-@findex @kbd{Ex wq}
-@findex @kbd{Ex w <file>}
-@findex @kbd{Ex w!@: <file>}
-@findex @kbd{Ex w >> <file>}
-@findex @kbd{Ex write <file>}
-@findex @kbd{Ex write!@: <file>}
-@findex @kbd{Ex write >> <file>}
-@findex @kbd{Ex W}
-@findex @kbd{Ex WW}
-@findex @kbd{Ex Write}
-@findex @kbd{Ex WWrite}
-@findex @kbd{Ex WWrite}
-@findex @kbd{Ex x}
-@findex @kbd{Ex x!}
-@findex @kbd{Ex suspend}
-@findex @kbd{Ex stop}
-@findex @kbd{Ex n [<count> | <file>]}
-@findex @kbd{Ex cd [<dir>]}
-@findex @kbd{Ex pwd}
-
-@node Mapping
-@section Mapping
-
-@cindex key bindings
-@cindex key mapping
-
-@table @kbd
-@item :map <string>
-Start defining a Vi-style keyboard macro.
-For instance, typing
-@kbd{:map www} followed by @kbd{:!wc %} and then typing @kbd{C-x )}
-will cause @kbd{www} to run wc on
-current file (Vi replaces @samp{%} with the current file name).
-@item C-x )
-Finish defining a keyboard macro.
-In Viper, this command completes the process of defining all keyboard
-macros, whether they are Emacs-style or Vi-style.
-This is a departure from Vi, needed to allow WYSIWYG mapping of
-keyboard macros and to permit the use of function keys and arbitrary Emacs
-functions in the macros.
-@item :unmap <string>
-Deprive <string> of its mappings in Vi state.
-@item :map!@: <string>
-Map a macro for Insert state.
-@item :unmap!@: <string>
-Deprive <string> of its mapping in Insert state (see @kbd{:unmap}).
-@item @@<a-z>
-In Vi state,
-execute the contents of register as a command.
-@item @@@@
-In Vi state,
-repeat last register command.
-@item @@#
-In Vi state,
-begin keyboard macro. End with @@<a-z>. This will
-put the macro in the proper register. Register will
-be automatically down-cased.
-@xref{Macros and Registers}, for more info.
-@item @@!<a-z>
-In Vi state,
-yank anonymous macro to register
-@item *
-In Vi state,
-execute anonymous macro (defined by C-x( and C-x )).
-@item C-x e
-Like @kbd{*}, but works in all Viper states.
-@item #g<move>
-Execute the last keyboard macro for each line in the region.
-@xref{Macros and Registers}, for more info.
-@item [<a-z>
-Show contents of textmarker.
-@item ]<a-z>
-Show contents of register.
-@end table
-@kindex ]<a-z>
-@kindex [<a-z>
-@kindex #g<move>
-@kindex *
-@kindex @@!<a-z>
-@kindex @@#
-@kindex @@@@
-@kindex @@<a-z>
-@findex @kbd{Ex unmap <char>}
-@findex @kbd{Ex map <char> <seq>}
-@findex @kbd{Ex unmap!@: <char>}
-@findex @kbd{Ex map!@: <char> <seq>}
-
-@node Shell Commands
-@section Shell Commands
-
-@cindex % (Current file)
-
-The symbol @samp{%} is used in Ex shell commands to mean current file. If
-you want a @samp{%} in your command, it must be escaped as @samp{\%}.
-@cindex @samp{%} (Ex address)
-However if @samp{%} is the first character, it stands as the address for
-the whole file.
-@cindex @samp{#} (Previous file)
-Similarly, @samp{#} expands to the previous file. The previous file is the
-first file in @kbd{:args} listing. This defaults to the previous file in
-the VI sense if you have one window.
-
-Symbols @samp{%} and @samp{#} are also used in the Ex commands @kbd{:e} and
-@kbd{:r <shell-cmd>}. The commands @kbd{:w} and the regular @kbd{:r
-<file>} command don't support these meta symbols, because file history is a
-better mechanism.
-
-@cindex shell commands
-
-@table @kbd
-@item :sh
-Execute a subshell in another window
-@item :[x,y]!<cmd>
-Execute a shell <cmd> [on lines x through y;
-% is replace by current file, \% is changed to %
-@item :[x,y]!!@: [<args>]
-Repeat last shell command [and append <args>].
-@item :!<cmd>
-Just execute command and display result in a buffer.
-@item :!!@: <args>
-Repeat last shell command and append <args>
-@item <count> !<move><cmd>
-The shell executes <cmd>, with standard
-input the lines described by <count><move>,
-next the standard output replaces those lines
-(think of @samp{cb}, @samp{sort}, @samp{nroff}, etc.).
-@item <count> !!<cmd>
-Give <count> lines as standard input to the
-shell <cmd>, next let the standard output
-replace those lines.
-@item :[x,y] w !<cmd>
-Let lines x to y be standard input for <cmd>
-(notice the <sp> between @kbd{w} and @kbd{!}).
-@item :<address>r !<cmd>
-Put the output of <cmd> after the line <address> (default current).
-@item :<address>r <name>
-Read the file <name> into the buffer after the line <address> (default
-current).
-@item :make
-Run the make command in the current directory.
-@end table
-@findex @kbd{Ex <address>r <name>}
-@findex @kbd{Ex <address>r !<cmd>}
-@findex @kbd{!<cmd>}
-@findex @kbd{!!<cmd>}
-@findex @kbd{!<move><cmd>}
-@findex @kbd{Ex w !<cmd>}
-@findex @kbd{Ex x,y w !<cmd>}
-@findex @kbd{Ex !!@: <args>}
-@findex @kbd{Ex !<cmd>}
-@findex @kbd{Ex sh}
-@findex @kbd{Ex make}
-
-@node Options
-@section Options
-
-@cindex Vi options
-
-@table @kbd
-@item autoindent
-@itemx ai
-@cindex autoindent
-autoindent: In append mode after a <cr> the
-cursor will move directly below the first
-character on the previous line.
-This setting affects the current buffer only.
-@item autoindent-global
-@itemx ai-global
-Same as @code{autoindent}, but affects all buffers.
-@item noautoindent
-@itemx noai
-Cancel autoindent.
-@item noautoindent-global
-@itemx noai-g
-Cancel autoindent-global.
-@item ignorecase
-@itemx ic
-@cindex case and searching
-ignorecase: No distinction between upper and lower cases when searching.
-@item noignorecase
-@itemx noic
-Cancel ignorecase.
-@item magic
-@itemx ma
-@cindex literal searching
-Regular expressions used in searches; nomagic means no regexps.
-@item nomagic
-@item noma
-Cancel magic.
-@item readonly
-@itemx ro
-@cindex readonly files
-readonly: The file is not to be changed.
-If the user attempts to write to this file, confirmation will be requested.
-@item noreadonly
-@itemx noro
-Cancel readonly.
-@item shell=<string>
-@itemx sh=<string>
-@cindex shell
-shell: The program to be used for shell escapes
-(default @samp{$SHELL} (default @file{/bin/sh})).
-@item shiftwidth=<count>
-@itemx sw=<count>
-@cindex layout
-@cindex shifting text
-shiftwidth: Gives the shiftwidth (default 8 positions).
-@item showmatch
-@itemx sm
-@cindex paren matching
-@cindex matching parens
-showmatch: Whenever you append a @kbd{)}, Vi shows
-its match if it's on the same page; also with
-@kbd{@{} and @kbd{@}}. If there's no match, Vi will beep.
-@item noshowmatch
-@itemx nosm
-Cancel showmatch.
-@item tabstop=<count>
-@itemx ts=<count>
-@cindex changing tab width
-@cindex tabbing
-tabstop: The length of a <ht>; warning: this is
-only IN the editor, outside of it <ht>s have
-their normal length (default 8 positions).
-This setting affects the current buffer only.
-@item tabstop-global
-@itemx ts-g
-Same as @code{tabstop}, but affects all buffers.
-@item wrapmargin=<count>
-@itemx wm=<count>
-@cindex auto fill
-@cindex word wrap
-wrapmargin: In append mode Vi automatically
-puts an <lf> whenever there is an <sp> or <ht>
-within <wm> columns from the right margin.
-@item wrapscan
-@itemx ws
-@cindex searching
-wrapscan: When searching, the end is
-considered @samp{stuck} to the begin of the file.
-@item nowrapscan
-@itemx nows
-Cancel wrapscan.
-@item :set <option>
-Turn <option> on.
-@item :set no<option>
-Turn <option> off.
-@item :set <option>=<value>
-Set <option> to <value>.
-@end table
-@findex @kbd{Ex set <option>=<value>}
-@findex @kbd{Ex set no<option>}
-@findex @kbd{Ex set <option>}
-@findex @kbd{Ex set ws}
-@findex @kbd{Ex set wrapscan}
-@findex @kbd{Ex set wm=<count>}
-@findex @kbd{Ex set wrapmargin=<count>}
-@findex @kbd{Ex set ts=<count>}
-@findex @kbd{Ex set tabstop=<count>}
-@findex @kbd{Ex set tab-stop-local=<count>}
-@findex @kbd{Ex set sm}
-@findex @kbd{Ex set showmatch}
-@findex @kbd{Ex set sw=<count>}
-@findex @kbd{Ex set shiftwidth=<count>}
-@findex @kbd{Ex set sh=<string>}
-@findex @kbd{Ex set shell=<string>}
-@findex @kbd{Ex set ro}
-@findex @kbd{Ex set readonly}
-@findex @kbd{Ex set magic}
-@findex @kbd{Ex set ic}
-@findex @kbd{Ex set ignorecase}
-@findex @kbd{Ex set ai}
-@findex @kbd{Ex set autoindent}
-
-@node Emacs Related Commands
-@section Emacs Related Commands
-
-@table @kbd
-@item C-\
-Begin Meta command in Vi or Insert states. Most often used as C-\ x (M-x).
-
-Note: Emacs binds @kbd{C-\} to a function that offers to change the
-keyboard input method in the multilingual environment. Viper overrides this
-binding. However, it is still possible to switch the input method by typing
-@kbd{\ C-\} in the Vi command state and @kbd{C-z \ C-\} in the Insert state.
-Or you can use the MULE menu on the menubar.
-@item C-z
-In Insert and Replace states, prepare Viper to accept the next command and
-execute it as if Viper was in Vi state. Then return to Insert state.
-
-In Vi state, switch to Emacs state; in Emacs state, switch to Vi state.
-@item C-c \
-Switches to Vi state for the duration of a single command. Then goes back
-to the original Viper state. Works from Vi, Insert, Replace, and Emacs states.
-@item C-x0
-Close Window
-@item C-x1
-Close Other Windows
-@item C-x2
-Split Window
-@item C-xo
-Move among windows
-@item C-xC-f
-Emacs find-file, useful in Insert state
-@item C-y
-Put back the last killed text. Similar to Vi's @kbd{p}, but also works in
-Insert and Replace state. This command doesn't work in Vi command state,
-since this binding is taken for something else.
-@item M-y
-Undoes the last @kbd{C-y} and puts another kill from the kill ring.
-Using this command, you can try may different kills until you find the one
-you need.
-@end table
-@kindex M-y
-@kindex C-y
-@kindex C-x C-f
-@kindex C-x o
-@kindex C-x 2
-@kindex C-x 1
-@kindex C-x 0
-@kindex C-z
-@kindex C-\
-@kindex C-c\
-
-@node Mouse-bound Commands
-@section Mouse-bound Commands
-
-The following two mouse actions are normally bound to special search and
-insert commands in of Viper:
-
-@table @kbd
-@item S-mouse-1
-Holding Shift and clicking mouse button 1 will
-initiate search for
-a region under the mouse pointer.
-This command can take a prefix argument. Note: Viper sets this
-binding only if this mouse action is not
-already bound to something else.
-@xref{Viper Specials}, for more information.
-
-@item S-mouse-2
-Holding Shift and clicking button 2 of the mouse will
-insert a region surrounding the mouse pointer.
-This command can also take a prefix argument.
-Note: Viper sets this binding only if this mouse action is not
-already bound to something else.
-@xref{Viper Specials}, for more details.
-@end table
-@kindex S-mouse-1
-@kindex S-mouse-2
-@kindex META button1up
-@kindex META button2up
-
-@node GNU Free Documentation License
-@appendix GNU Free Documentation License
-@include doclicense.texi
-
-@node Acknowledgments
-@unnumbered Acknowledgments
-
-Viper, formerly known as VIP-19, was written by Michael Kifer. Viper is
-based on the original VIP package by Masahiko Sato and on its enhancement,
-VIP 4.4, by Aamod Sane. This manual is an adaptation of the manual for VIP
-4.4, which, in turn, was based on Sato's manual for VIP 3.5.
-
-Many contributors on the Net pointed out bugs and suggested a number of
-useful features. Scott Bronson and Samuel Padgett contributed patches that
-were incorporated in this code. Here is a hopefully complete list of
-contributors:
-
-@example
-aaronl@@vitelus.com (Aaron Lehmann),
-ahg@@panix.com (Al Gelders),
-amade@@diagram.fr (Paul-Bernard Amade),
-ascott@@fws214.intel.com (Andy Scott),
-bronson@@trestle.com (Scott Bronson),
-cook@@biostat.wisc.edu (Tom Cook),
-csdayton@@midway.uchicago.edu (Soren Dayton),
-dave@@hellgate.utah.edu,
-dm@@scs.cs.nyu.edu (David Mazieres),
-dominik@@strw.LeidenUniv.nl (Carsten Dominik),
-dwallach@@cs.princeton.edu (Dan Wallach),
-dwight@@toolucky.llnl.gov (Dwight Shih),
-dxc@@xprt.net (David X Callaway),
-edmonds@@edmonds.home.cs.ubc.ca (Brian Edmonds),
-gin@@mo.msk.ru (Golubev I.N.),
-gviswana@@cs.wisc.edu (Guhan Viswanathan),
-gvr@@halcyon.com (George V. Reilly),
-hatazaki@@bach.convex.com (Takao Hatazaki),
-hpz@@ibmhpz.aug.ipp-garching.mpg.de (Hans-Peter Zehrfeld),
-irie@@t.email.ne.jp (Irie Tetsuya),
-jackr@@dblues.engr.sgi.com (Jack Repenning),
-jamesm@@bga.com (D.J. Miller II),
-jjm@@hplb.hpl.hp.com (Jean-Jacques Moreau),
-jl@@cse.ogi.edu (John Launchbury),
-jobrien@@hchp.org (John O'Brien),
-johnw@@borland.com (John Wiegley),
-kanze@@gabi-soft.fr (James Kanze),
-kin@@isi.com (Kin Cho),
-kwzh@@gnu.org (Karl Heuer),
-lindstro@@biostat.wisc.edu (Mary Lindstrom),
-lektu@@terra.es (Juanma Barranquero),
-lennart.borgman.073@@student.lu.se (Lennart Borgman),
-minakaji@@osaka.email.ne.jp (Mikio Nakajima),
-Mark.Bordas@@East.Sun.COM (Mark Bordas),
-meyering@@comco.com (Jim Meyering),
-martin@@xemacs.org (Martin Buchholz),
-mbutler@@redfernnetworks.com (Malcolm Butler),
-mveiga@@dit.upm.es (Marcelino Veiga Tuimil),
-paulk@@summit.esg.apertus.com (Paul Keusemann),
-pfister@@cs.stonybrook.edu (Hanspeter Pfister),
-phil_brooks@@MENTORG.COM (Phil Brooks),
-pogrell@@informatik.hu-berlin.de (Lutz Pogrell),
-pradyut@@cs.uchicago.edu (Pradyut Shah),
-roderick@@argon.org (Roderick Schertler),
-rxga@@ulysses.att.com,
-sawdey@@lcse.umn.edu (Aaron Sawdey),
-simonb@@prl.philips.co.uk (Simon Blanchard),
-spadgett1@@nc.rr.com (Samuel Padgett),
-stephen@@farrell.org (Stephen Farrell),
-storm@@cua.dk (Kim F. Storm),
-sudish@@MindSpring.COM (Sudish Joseph),
-schwab@@issan.informatik.uni-dortmund.de (Andreas Schwab)
-terra@@diku.dk (Morten Welinder),
-thanh@@informatics.muni.cz (Han The Thanh),
-toma@@convex.convex.com,
-vrenjak@@sun1.racal.com (Milan Vrenjak),
-whicken@@dragon.parasoft.com (Wendell Hicken),
-zapman@@cc.gatech.edu (Jason Zapman II),
-@end example
-
-@node Key Index
-@unnumbered Key Index
-
-@printindex ky
-
-@node Function Index
-@unnumbered Function Index
-
-@printindex fn
-
-@node Variable Index
-@unnumbered Variable Index
-
-@printindex vr
-
-@node Package Index
-@unnumbered Package Index
-
-@printindex pg
-
-@node Concept Index
-@unnumbered Concept Index
-
-@printindex cp
-
-@bye
gnus-refcard.pdf \
orgcard.pdf \
refcard.pdf \
- survival.pdf \
- viperCard.pdf
+ survival.pdf
PDF_CZECH = \
cs-dired-ref.pdf \
survival.dvi: $(survival_deps)
$(ENVADD) tex survival.tex
-vipercard_deps = viperCard.tex emacsver.tex pdflayout.sty
-viperCard.pdf: $(vipercard_deps)
- $(ENVADD) pdftex viperCard.tex
-viperCard.dvi: $(vipercard_deps)
- $(ENVADD) tex viperCard.tex
-
-
.PHONY: clean
clean:
orgcard.pdf Org-Mode Reference Card
refcard.pdf Emacs Reference Card
survival.pdf Emacs Survival Card
- viperCard.pdf ViperCard: Viper Reference Pal
Brazilian Portuguese
+++ /dev/null
-% ViperCard -- The Reference Card for Viper under GNU Emacs
-
-% Copyright (C) 1995--1997, 2001--2025 Free Software Foundation, Inc.
-
-% Author: Michael Kifer <kifer@cs.stonybrook.edu> (Viper)
-% Aamod Sane <sane@cs.uiuc.edu> (VIP 4.3)
-% Masahiko Sato <ms@sail.stanford.edu> (VIP 3.5)
-
-% This document is free software: you can redistribute it and/or modify
-% it under the terms of the GNU General Public License as published by
-% the Free Software Foundation, either version 3 of the License, or
-% (at your option) any later version.
-
-% As a special additional permission, you may distribute reference cards
-% printed, or formatted for printing, with the notice "Released under
-% the terms of the GNU General Public License version 3 or later"
-% instead of the usual distributed-under-the-GNU-GPL notice, and without
-% a copy of the GPL itself.
-
-% This document is distributed in the hope that it will be useful,
-% but WITHOUT ANY WARRANTY; without even the implied warranty of
-% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-% GNU General Public License for more details.
-
-% You should have received a copy of the GNU General Public License
-% along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
-
-
-% This file is intended to be processed by plain TeX (TeX82).
-%
-% The final reference card has six columns, three on each side.
-% This file can be used to produce it in any of three ways:
-% 1 column per page
-% produces six separate pages, each of which needs to be reduced to 80%.
-% This gives the best resolution.
-% 2 columns per page
-% produces three already-reduced pages.
-% You will still need to cut and paste.
-% 3 columns per page
-% produces two pages which must be printed sideways to make a
-% ready-to-use 8.5 x 11 inch reference card.
-% For this you need a dvi device driver that can print sideways.
-% Which mode to use is controlled by setting \columnsperpage.
-
-
-%**start of header
-
-
-% This file can be printed with 1 or 2 columns per page.
-% Specify how many you want here.
-\newcount\columnsperpage
-\columnsperpage=2
-
-% PDF output layout. 0 for A4, 1 for letter (US), a `l' is added for
-% a landscape layout.
-\input pdflayout.sty
-\pdflayout=(1)
-
-\input emacsver.tex
-\def\versionemacs{21} % version of Emacs this is for
-\def\versionviper{3.0} % version of Viper this is for
-
-% Nothing else needs to be changed.
-
-\def\shortcopyrightnotice{\vskip 1ex plus 2 fill
- \centerline{\small \copyright\ \year\ Free Software Foundation, Inc.
- Permissions on back.}}
-
-\def\copyrightnotice{
-%\vskip 1ex plus 2 fill\begingroup\small
-\vskip 1ex \begingroup\small
-\centerline{Copyright \copyright\ \year\ Free Software Foundation, Inc.}
-\centerline{by Michael Kifer, Viper \versionviper}
-\centerline{by Aamod Sane, VIP version 4.3}
-\centerline{by Masahiko Sato, VIP version 3.5}
-
-Released under the terms of the GNU General Public License version 3 or later.
-
-For more Emacs documentation, and the \TeX{} source for this card,
-see the Emacs distribution, or {\tt https://www.gnu.org/software/emacs}
-\endgroup}
-
-% make \bye not \outer so that the \def\bye in the \else clause below
-% can be scanned without complaint.
-\def\bye{\par\vfill\supereject\end}
-
-\newdimen\intercolumnskip
-\newbox\columna
-\newbox\columnb
-
-\def\ncolumns{\the\columnsperpage}
-
-\message{[\ncolumns\space
- column\if 1\ncolumns\else s\fi\space per page]}
-
-\def\scaledmag#1{ scaled \magstep #1}
-
-% This multi-way format was designed by Stephen Gildea
-% October 1986.
-% Slightly modified by Masahiko Sato, September 1987.
-\if 1\ncolumns
- \hsize 4in
- \vsize 10in
- %\voffset -.7in
- \voffset -.57in
- \font\titlefont=\fontname\tenbf \scaledmag3
- \font\headingfont=\fontname\tenbf \scaledmag2
- \font\miniheadingfont=\fontname\tenbf \scaledmag1 % masahiko
- \font\smallfont=\fontname\sevenrm
- \font\smallsy=\fontname\sevensy
-
- \footline{\hss\folio}
- \def\makefootline{\baselineskip10pt\hsize6.5in\line{\the\footline}}
-\else
- %\hsize 3.2in
- %\vsize 7.95in
- \hsize 3.41in % masahiko
- \vsize 8in % masahiko
- \hoffset -.75in
- \voffset -.745in
- \font\titlefont=cmbx10 \scaledmag2
- \font\headingfont=cmbx10 \scaledmag1
- \font\miniheadingfont=cmbx10 % masahiko
- \font\smallfont=cmr6
- \font\smallsy=cmsy6
- \font\eightrm=cmr8
- \font\eightbf=cmbx8
- \font\eightit=cmti8
- \font\eightsl=cmsl8
- \font\eighttt=cmtt8
- \font\eightsy=cmsy8
- \textfont0=\eightrm
- \textfont2=\eightsy
- \def\rm{\eightrm}
- \def\bf{\eightbf}
- \def\it{\eightit}
- \def\sl{\eightsl} % masahiko
- \def\tt{\eighttt}
- \normalbaselineskip=.8\normalbaselineskip
- \normallineskip=.8\normallineskip
- \normallineskiplimit=.8\normallineskiplimit
- \normalbaselines\rm %make definitions take effect
-
- \if 2\ncolumns
- \let\maxcolumn=b
- \footline{\hss\rm\folio\hss}
- \def\makefootline{\vskip 2in \hsize=6.86in\line{\the\footline}}
- \else \if 3\ncolumns
- \let\maxcolumn=c
- \nopagenumbers
- \else
- \errhelp{You must set \columnsperpage equal to 1, 2, or 3.}
- \errmessage{Illegal number of columns per page}
- \fi\fi
-
- %\intercolumnskip=.46in
- \intercolumnskip=.19in % masahiko .19x4 + 3.41x3 = 10.99
- \def\abc{a}
- \output={%
- % This next line is useful when designing the layout.
- %\immediate\write16{Column \folio\abc\space starts with \firstmark}
- \if \maxcolumn\abc \multicolumnformat \global\def\abc{a}
- \else\if a\abc
- \global\setbox\columna\columnbox \global\def\abc{b}
- %% in case we never use \columnb (two-column mode)
- \global\setbox\columnb\hbox to -\intercolumnskip{}
- \else
- \global\setbox\columnb\columnbox \global\def\abc{c}\fi\fi}
- \def\multicolumnformat{\shipout\vbox{\makeheadline
- \hbox{\box\columna\hskip\intercolumnskip
- \box\columnb\hskip\intercolumnskip\columnbox}
- \makefootline}\advancepageno}
- \def\columnbox{\leftline{\pagebody}}
-
- \def\bye{\par\vfill\supereject
- \if a\abc \else\null\vfill\eject\fi
- \if a\abc \else\null\vfill\eject\fi
- \end}
-\fi
-
-% we won't be using math mode much, so redefine some of the characters
-% we might want to talk about
-\catcode`\^=12
-\catcode`\_=12
-
-\chardef\\=`\\
-\chardef\{=`\{
-\chardef\}=`\}
-
-\hyphenation{mini-buf-fer}
-
-\parindent 0pt
-\parskip 1ex plus .5ex minus .5ex
-
-\def\small{\smallfont\textfont2=\smallsy\baselineskip=.8\baselineskip}
-
-\outer\def\newcolumn{\vfill\eject}
-
-\outer\def\title#1{{\titlefont\centerline{#1}}\vskip 1ex plus .5ex}
-
-\outer\def\section#1{\par\filbreak
- \vskip 3ex plus 2ex minus 2ex {\headingfont #1}\mark{#1}%
- \vskip 2ex plus 1ex minus 1.5ex}
-
-% masahiko
-\outer\def\subsection#1{\par\filbreak
- \vskip 2ex plus 2ex minus 2ex {\miniheadingfont #1}\mark{#1}%
- \vskip 1ex plus 1ex minus 1.5ex}
-
-\newdimen\keyindent
-
-\def\beginindentedkeys{\keyindent=1em}
-\def\endindentedkeys{\keyindent=0em}
-\endindentedkeys
-
-\def\paralign{\vskip\parskip\halign}
-
-\def\<#1>{$\langle${\rm #1}$\rangle$}
-
-\def\kbd#1{{\tt#1}\null} %\null so not an abbrev even if period follows
-
-\def\beginexample{\par\leavevmode\begingroup
- \obeylines\obeyspaces\parskip0pt\tt}
-{\obeyspaces\global\let =\ }
-\def\endexample{\endgroup}
-
-\def\key#1#2{\leavevmode\hbox to \hsize{\vtop
- {\hsize=.75\hsize\rightskip=1em
- \hskip\keyindent\relax#1}\kbd{#2}\hfil}}
-
-\newbox\metaxbox
-\setbox\metaxbox\hbox{\kbd{M-x }}
-\newdimen\metaxwidth
-\metaxwidth=\wd\metaxbox
-
-\def\metax#1#2{\leavevmode\hbox to \hsize{\hbox to .75\hsize
- {\hskip\keyindent\relax#1\hfil}%
- \hskip -\metaxwidth minus 1fil
- \kbd{#2}\hfil}}
-
-\def\fivecol#1#2#3#4#5{\hskip\keyindent\relax#1\hfil&\kbd{#2}\quad
- &\kbd{#3}\quad&\kbd{#4}\quad&\kbd{#5}\cr}
-
-\def\fourcol#1#2#3#4{\hskip\keyindent\relax#1\hfil&\kbd{#2}\quad
- &\kbd{#3}\quad&\kbd{#4}\quad\cr}
-
-\def\threecol#1#2#3{\hskip\keyindent\relax#1\hfil&\kbd{#2}\quad
- &\kbd{#3}\quad\cr}
-
-\def\twocol#1#2{\hskip\keyindent\relax\kbd{#1}\hfil&\kbd{#2}\quad\cr}
-
-\def\twocolkey#1#2#3#4{\hskip\keyindent\relax#1\hfil&\kbd{#2}\quad&\relax#3\hfil&\kbd{#4}\quad\cr}
-
-%**end of header
-\f
-\beginindentedkeys
-
-\title{ViperCard: Viper Reference Pal}
-
-\centerline{(Version \versionviper\ for Emacs \versionemacs)}
-
-%\copyrightnotice
-
-\section{Loading Viper}
-
-Just type \kbd{M-x viper-mode} followed by \kbd{RET}
-
-OR put
-
-(setq viper-mode t)
-(require 'viper)
-
-in .emacs
-
-\section{Viper States}
-
-Viper has four states: {\it emacs state}, {\it vi state}, {\it insert state},
-{\it replace state}.
-Mode line tells you which state you are in.
-In emacs state you can do all the normal GNU Emacs editing.
-This card explains only vi state and insert state (replace state is similar
-to insert state).
-{\bf GNU Emacs Reference Card} explains emacs state.
-You can switch states as follows.
-
-\key{from emacs state to vi state}{C-z}
-\key{from vi state to emacs state}{C-z}
-\key{from vi state to emacs state for 1 command}{$\backslash$}
-\metax{from vi state to insert state}{i, I, a, A, o, O}
-\metax{from vi state to replace state}{c, C, R}
-\key{from insert or replace state to vi state}{ESC}
-\key{from insert state to vi state for 1 command}{C-z}
-
-
-\section{Insert Mode}
-You can do editing in insert state.
-
-\metax{go back to vi state}{ESC}
-\metax{delete previous character}{C-h, DEL}
-\key{delete previous word}{C-w}
-\key{delete line word}{C-u}
-\key{indent shiftwidth forward}{C-t}
-\key{indent shiftwidth backward}{C-d}
-\key{quote following character}{C-v}
-\key{emulate Meta key in emacs state}{C-$\backslash$}
-\key{escape to Vi state for one command}{C-z}
-
-\vskip 2mm
-
-{\bf The rest of this card explains commands in {\bf vi state}.}
-
-\section{Getting Information on Viper}
-
-Execute info command by typing \kbd{M-x info} and select menu item
-\kbd{viper}. Also:
-
-\key{describe function attached to the key {\it x}}{$\backslash$ C-h k {\it x}}
-
-\section{Leaving Emacs}
-
-\metax{suspend Emacs}{:st {\rm or} :su}
-\metax{exit Emacs permanently}{C-xC-c}
-\metax{exit current file}{:wq {\rm or} :q}
-
-\shortcopyrightnotice
-
-\section{Error Recovery}
-
-\metax{abort command}{C-c (user level = 1)}
-\metax{abort command}{C-g (user level > 1)}
-\key{redraw messed up screen}{C-l}
-\metax{{\bf recover} after system crash}{:rec file}
-\metax{restore a buffer }{:e!\ {\rm or} M-x revert-buffer}
-
-
-\section{Counts}
-
-Most commands in vi state accept a {\it count} which can be supplied as a
-prefix to the commands. In most cases, if a count is given, the
-command is executed that many times. E.g., \kbd{5 d d} deletes 5
-lines.
-
-\section{Registers}
-
-There are 26 registers (\kbd{a} to \kbd{z}) that can store texts
-and marks.
-You can append a text at the end of a register (say \kbd{x}) by
-specifying the register name in capital letter (say \kbd{X}).
-There are also 9 read only registers (\kbd{1} to \kbd{9}) that store
-up to 9 previous changes.
-We will use {\it x\/} to denote a register.
-\section{Entering Insert Mode}
-
-\key{{\bf insert} at point}{i}
-\key{{\bf append} after cursor}{a}
-\key{{\bf insert} before first non-white}{I}
-\key{{\bf append} at end of line}{A}
-\key{{\bf open} line below}{o}
-\key{{\bf open} line above}{O}
-
-\section{Buffers and Windows}
-
-\key{move cursor to {\bf next} window}{C-x o}
-\key{delete current window}{C-x 0}
-\key{delete other windows}{C-x 1}
-\key{split current window into two windows}{C-x 2}
-\key{{\bf switch} to a buffer in the current window}{C-x {\sl buffer}}
-\metax{{\bf switch} to a buffer in another window}{:n, :b, {\rm or} C-x 4 {\sl buf}}
-\key{{\bf kill} a buffer}{:q! {\rm or} C-x k}
-\key{list existing {\bf buffers}}{:args {\rm or} C-x b}
-
-\section{Files}
-
-\metax{{\bf visit} file in the current window}{v {\sl file} {\rm or} :e {\sl file}}
-\key{{\bf visit} file in another window}{V {\sl file}}
-\key{{\bf visit} file in another frame}{C-v {\sl file}}
-\key{{\bf save} buffer to the associated file}{:w {\rm or} C-xC-s}
-\metax{{\bf write} buffer to a specified file}{:w {\sl file} {\rm or} C-xC-w}
-\metax{{\bf insert} a specified file at point}{:r {\sl file} {\rm or} C-xi}
-\key{{\bf get} information on the current {\bf file}}{C-c g {\rm or} :f}
-\key{run the {\bf directory} editor}{:e RET {\rm or} C-xd}
-
-%\shortcopyrightnotice
-
-\section{Viewing the Buffer}
-
-\key{scroll to next screen}{C-f}
-\key{scroll to previous screen}{C-b}
-\key{scroll {\bf down} half screen}{C-d}
-\key{scroll {\bf up} half screen}{C-u}
-\key{scroll down one line}{C-e}
-\key{scroll up one line}{C-y}
-
-\key{put current line on the {\bf home} line}{z H {\rm or} z RET}
-\key{put current line on the {\bf middle} line}{z M {\rm or} z .}
-\key{put current line on the {\bf last} line}{z L {\rm or} z -}
-
-\section{Marking and Returning}
-
-\key{{\bf mark} point in register {\it x}}{m {\it x}}
-\key{set mark at buffer beginning}{m <}
-\key{set mark at buffer end}{m >}
-\key{set mark at point}{m .}
-\key{jump to mark}{m ,}
-\key{exchange point and mark}{` `}
-\key{... and skip to first non-white on line}{' '}
-\key{go to mark {\it x}}{` {\it x}}
-\key{... and skip to first non-white on line}{' {\it x}}
-\key{view contents of marker {\it x}}{[ {\it x}}
-\key{view contents of register {\it x}}{] {\it x}}
-
-\section{Macros}
-
-Emacs style macros:
-
-\key{start remembering keyboard macro}{C-x (}
-\key{finish remembering keyboard macro}{C-x )}
-\key{call last keyboard macro}{*}
-
-\key{start remembering keyboard macro}{@ \#}
-\key{finish macro and put into register {\it x}}{@ {\it x}}
-\key{execute macro stored in register {\it x}}{@ {\it x}}
-\key{repeat last @{\it x} command}{@ @}
-
-\key{Pull last macro into register {\it x}}{@ ! {\it x}}
-
-Vi-style macros (keys to be hit in quick succession):
-
-\key{define Vi-style macro for Vi state}{:map}
-\key{define Vi-style macro for Insert state}{:map!}
-
-\key{toggle case-sensitive search}{//}
-\key{toggle regular expression search}{///}
-\key{toggle `\%' to ignore parentheses inside comments}{\%\%\%}
-
-
-\section{Motion Commands}
-
-\key{go backward one character}{h {\rm or} C-h}
-\key{go forward one character}{l}
-\metax{next line keeping the column}{j {\rm or} LF {\rm or} C-n}
-\key{previous line keeping the column}{k}
-\metax{next line at first non-white}{+ {\rm or} RET {\rm or} C-p}
-\key{previous line at first non-white}{-}
-
-\key{beginning of line}{0}
-\key{first non-white on line}{^}
-\key{end of line}{\$}
-\key{go to {\it n}-th column on line}{{\it n} |}
-
-\key{go to {\it n}-th line}{{\it n} G}
-\key{go to last line}{G}
-\key{find matching parenthesis for \kbd{()}, \kbd{\{\}} and \kbd{[]}}{\%}
-
-\key{go to {\bf home} window line}{H}
-\key{go to {\bf middle} window line}{M}
-\key{go to {\bf last} window line}{L}
-
-\subsection{Words, Sentences, Paragraphs, Headings}
-
-\key{forward {\bf word}}{w {\rm or} W}
-\key{{\bf backward} word}{b {\rm or} B}
-\key{{\bf end} of word}{e {\rm or} E}
-
-In the case of capital letter commands, a word is delimited by a
-non-white character.
-
-\key{forward sentence}{)}
-\key{backward sentence}{(}
-
-\key{forward paragraph}{\}}
-\key{backward paragraph}{\{}
-
-\key{forward heading}{]]}
-\key{backward heading}{[[}
-\key{end of heading}{[]}
-
-\subsection{Find Characters on the Line}
-
-\key{{\bf find} {\it c} forward on line}{f {\it c}}
-\key{{\bf find} {\it c} backward on line}{F {\it c}}
-\key{up {\bf to} {\it c} forward on line}{t {\it c}}
-\key{up {\bf to} {\it c} backward on line}{T {\it c}}
-\key{repeat previous \kbd{f}, \kbd{F}, \kbd{t} or \kbd{T}}{;}
-\key{... in the opposite direction}{,}
-
-%\newcolumn
-%\title{Viper Quick Reference Card}
-
-\section{Searching and Replacing}
-
-\key{search forward for {\sl pat}}{/ {\sl pat}}
-\key{search backward with previous {\sl pat}}{?\ RET}
-\key{search forward with previous {\sl pat}}{/ RET}
-\key{search backward for {\sl pat}}{?\ {\sl pat}}
-\key{repeat previous search}{n}
-\key{... in the opposite direction}{N}
-
-\key{{\bf query} replace}{Q}
-\key{{\bf replace} a character by another character {\it c}}{r {\it c}}
-\key{{\bf overwrite} {\it n} lines}{{\it n} R}
-
-\metax{{\bf buffer} search (if enabled)}{g {\it move command}}
-
-\section{Modifying Commands}
-
-Most commands that operate on text regions accept the motion commands,
-to describe regions. They also accept the Emacs region specifications
-{\bf r} and {\bf R}. {\bf r} describes the region between {\it point}
-and {\it mark}, and {\bf R} describes whole lines in that region.
-Motion commands are classified into {\it point commands} and
-{\it line commands}. In the case of line commands, whole lines will
-be affected by the command.
-
-The point commands are as follows:
-
-\hskip 5ex
-\kbd{h l 0 ^ \$ w W b B e E ( ) / ?\ ` f F t T \% ; ,}
-
-The line commands are as follows:
-
-\hskip 5ex
-\kbd{j k + - H M L \{ \} G '}
-
-These region specifiers will be referred to as {\it m} below.
-
-\subsection{Delete/Yank/Change Commands}
-
-\paralign to \hsize{#\tabskip=10pt plus 1 fil&#\tabskip=0pt&#\tabskip=0pt&#\cr
-\fourcol{}{{\bf delete}}{{\bf yank}}{{\bf change}}
-\fourcol{region determined by {\it m}}{d {\it m}}{y {\it m}}{c {\it m}}
-\fourcol{... into register {\it x}}{" {\it x\/} d {\it m}}{" {\it x\/} y {\it m}}{" {\it x\/} c {\it m}}
-\fourcol{a line}{d d}{Y {\rm or} y y}{c c}
-\fourcol{current {\bf region}}{d r}{y r}{c r}
-\fourcol{expanded {\bf region}}{d R}{y R}{c R}
-\fourcol{to end of line}{D}{y \$}{c \$}
-\fourcol{a character after point}{x}{y l}{c l}
-\fourcol{a character before point}{DEL}{y h}{c h}
-}
-
-\vskip 2ex
-\key{Overwrite {\it n} lines}{{\it n} R}
-
-\subsection{Put Back Commands}
-
-Deleted/yanked/changed text can be put back by the following commands.
-
-\key{{\bf Put} back at point/above line}{P}
-\key{... from register {\it x}}{" {\it x\/} P}
-\key{{\bf put} back after point/below line}{p}
-\key{... from register {\it x}}{" {\it x\/} p}
-
-\subsection{Repeating and Undoing Modifications}
-
-\key{{\bf undo} last change}{u {\rm or} :und}
-\key{repeat last change}{.\ {\rm (dot)}}
-
-Undo is undoable by \kbd{u} and repeatable by \kbd{.}.
-For example, \kbd{u...} will undo 4 previous changes.
-A \kbd{.} after \kbd{5dd} is equivalent to \kbd{5dd},
-while \kbd{3.} after \kbd{5dd} is equivalent to \kbd{3dd}.
-
-\section{Miscellaneous Commands}
-
-\endindentedkeys
-
-\paralign to \hsize{#\tabskip=5pt plus 1 fil&#\tabskip=0pt&#\tabskip=0pt&#\tabskip=0pt&#\cr
-\fivecol{}{{\bf shift left}}{{\bf shift right}}{{\bf filter shell command}}{{\bf indent}}
-\fivecol{region}{< {\it m}}{> {\it m}}{!\ {\it m\/} {\sl shell-com}}{= {\it m}}
-\fivecol{line}{< <}{> >}{!\ !\ {\sl shell-com}}{= =}
-}
-
-\key{{\bf join} lines}{J}
-\key{toggle case (takes count)}{\~{}}
-
-\key{view register {\it x}}{] {\it x}}
-\key{view marker {\it x}}{] {\it x}}
-
-\key{lowercase region}{\# c {\it m}}
-\key{uppercase region}{\# C {\it m}}
-\key{execute last keyboard macro on each line in the region}{\# g {\it m}}
-
-\key{insert specified string for each line in the region}{\# q {\it m}}
-\key{check spelling of the words in the region}{\# s {\it m}}
-
-\key{repeat previous ex substitution}{\&}
-\key{change to previous file}{C-^}
-
-\key{Viper Meta key}{_}
-
-\section{Customization}
-
-By default, search is case sensitive.
-You can change this by including the following line in your \kbd{\~{}/.vip} file.
-
-\hskip 5ex
-\kbd{(setq viper-case-fold-search t)}
-
-The following is a subset of the variety of
-options available for customizing Viper.
-See the Viper manual for details on these and other options.
-
-\beginindentedkeys
-
-\paralign to \hsize{#\tabskip=10pt plus 1 fil&#\tabskip=0pt&#\cr
-\twocol{{\bf variable}}{{\bf default value}}
-\twocol{viper-search-wrap-around}{t}
-\twocol{viper-case-fold-search}{nil}
-\twocol{viper-re-search}{t}
-\twocol{viper-re-replace}{t}
-\twocol{viper-re-query-replace}{t}
-\twocol{viper-auto-indent}{nil}
-\twocol{viper-shift-width}{8}
-\twocol{viper-tags-file-name}{"TAGS"}
-\twocol{viper-no-multiple-ESC}{t}
-\twocol{viper-ex-style-motion}{t}
-\twocol{viper-always}{t}
-\twocol{viper-custom-file-name}{"\~{}/.vip"}
-\twocol{ex-find-file-shell}{"csh"}
-\twocol{ex-cycle-other-window}{t}
-\twocol{ex-cycle-through-non-buffers}{t}
-\twocol{blink-matching-paren}{t}
-\twocol{buffer-read-only}{{\it buffer dependent}}
-}
-
-To bind keys in Vi command state, put lines like these in your
-\kbd{\~{}/.vip} file:
-
-\beginexample
-(define-key viper-vi-global-user-map "\\C-v" 'scroll-down)
-(define-key viper-vi-global-user-map "\\C-cm" 'smail)
-\endexample
-
-
-\newcolumn
-
-\title{Ex Commands in Viper}
-
-In vi state, an Ex command is entered by typing:
-
-\hskip 5ex
-\kbd{:\ {\sl ex-command} RET}
-
-\section{Ex Addresses}
-
-\paralign to \hsize{#\tabskip=5pt plus 1 fil&#\tabskip=2pt&#\tabskip=5pt plus 1 fil&#\cr
-\twocolkey{current line}{.}{next line with {\sl pat}}{/ {\sl pat} /}
-\twocolkey{line {\it n}}{{\it n}}{previous line with {\sl pat}}{?\ {\sl pat} ?}
-\twocolkey{last line}{\$}{{\it n\/} line before {\it a}}{{\it a} - {\it n}}
-\twocolkey{next line}{+}{{\it a\/} through {\it b}}{{\it a\/} , {\it b}}
-\twocolkey{previous line}{-}{line marked with {\it x}}{' {\it x}}
-\twocolkey{entire buffer}{\%}{previous context}{' '}
-}
-
-Addresses can be specified in front of a command.
-For example,
-
-\hskip 5ex
-\kbd{:.,.+10m\$}
-
-moves 11 lines below current line to the end of buffer.
-
-\section{Ex Commands}
-
-Avoid Ex text manipulation commands except substitute.
-There are better VI equivalents
-for all of them. Also note that all Ex commands expand \% to
-current file name. To include a \% in the command, escape it with a $\backslash$.
-Similarly, \# is replaced by previous file. For Viper, this is the
-first file in the {\sl :args} listing for that buffer. This defaults
-to the previous file in the VI sense if you have one window.
-Ex commands can be made to have history. See the manual for details.
-
-\subsection{Ex Text Commands}
-
-\endindentedkeys
-
-\key{mark lines matching {\sl pat} and execute {\sl cmds} on these lines}{:g /{\sl pat}/ {\sl cmds}}
-
-\key{mark lines {\it not\/} matching {\sl pat} and execute {\sl cmds} on these lines}{:v /{\sl pat}/ {\sl cmds}}
-
-
-\key{{\bf move} specified lines after {\sl addr}}{:m {\sl addr}}
-\key{{\bf copy} specified lines after {\sl addr}}{:co\rm\ (or \kbd{:t})\ \sl addr}
-\key{{\bf delete} specified lines [into register {\it x\/}]}{:d {\rm [{\it x\/}]}}
-\key{{\bf yank} specified lines [into register {\it x\/}]}{:y {\rm [{\it x\/}]}}
-\key{{\bf put} back text [from register {\it x\/}]}{:pu {\rm [{\it x\/}]}}
-
-\key{{\bf substitute} {\sl repl} for first string on line matching {\sl pat}}{:s /{\sl pat}/{\sl repl}/}
-
-\key{repeat last substitution}{:\&}
-\key{repeat previous substitute with previous search pattern as {\sl pat}}{:\~{}}
-
-\subsection{Ex File and Shell Commands}
-
-\key{{\bf edit} file}{:e {\sl file}}
-\key{reedit messed up current file}{:e!}
-\key{edit previous file}{:e\#}
-\key{{\bf read} in a file}{:r {\sl file}}
-\key{{\bf read} in the output of a shell command}{:r {\sl !command}}
-\key{write out specified lines into {\sl file}}{:w {\sl file}}
-\key{save all modified buffers, ask confirmation}{:W {\sl file}}
-\key{save all modified buffers, no confirmation}{:WW {\sl file}}
-\key{write out specified lines at the end of {\sl file}}{:w>> {\sl file}}
-\key{{\bf write} to the input of a shell command}{:w {\sl !command}}
-\key{write out and then quit}{:wq {\sl file}}
-
-\key{run a sub{\bf shell} in a window}{:sh}
-\key{execute shell command {\sl command}}{:!\ {\sl command}}
-\key{execute previous shell command with {\it args} appended}{:!! {\sl args}}
-
-\subsection{Ex Miscellaneous Commands}
-
-\key{define a macro {\it x} that expands to {\sl cmd}}{:map {\it x} {\sl cmd}}
-\key{remove macro expansion associated with {\it x}}{:unma {\it x}}
-\key{define a macro {\it x} that expands to {\sl cmd} in insert state}{:map!\ {\it x} {\sl cmd}}
-\key{remove macro expansion associated with {\it x} in insert state}{:unma!\ {\it x}}
-
-\key{print line number}{:.=}
-\key{print last line number}{:=}
-\key{print {\bf version} number of Viper}{:ve}
-
-\key{shift specified lines to the right}{:>}
-\key{shift specified lines to the left}{:<}
-
-\key{{\bf join} lines}{:j}
-\key{mark specified line to register {\it x}}{:k {\it x}}
-\key{{\bf set} a variable's value}{:se}
-\key{find first definition of {\bf tag} {\sl tag}}{:ta {\sl tag}}
-
-\key{Current directory}{:pwd}
-
-
-\copyrightnotice
-
-\bye
-\f
-% Local variables:
-% compile-command: "pdftex viperCard"
-% End:
+++ /dev/null
-;;; viper-cmd.el --- Vi command support for Viper -*- lexical-binding:t -*-
-
-;; Copyright (C) 1997-2025 Free Software Foundation, Inc.
-
-;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
-;; Package: viper
-
-;; This file is part of GNU Emacs.
-
-;; GNU Emacs is free software: you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; GNU Emacs is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;;; Code:
-
-;; Compiler pacifier
-(defvar viper-minibuffer-current-face)
-(defvar viper-minibuffer-insert-face)
-(defvar viper-minibuffer-vi-face)
-(defvar viper-minibuffer-emacs-face)
-(defvar viper-always)
-(defvar viper-mode-string)
-(defvar viper-custom-file-name)
-(defvar viper--key-maps)
-(defvar viper--intercept-key-maps)
-(defvar iso-accents-mode)
-(defvar quail-current-str)
-(defvar viper--init-message)
-(defvar viper-initial)
-(defvar undo-beg-posn)
-(defvar undo-end-posn)
-
-;; end pacifier
-
-
-(require 'viper-util)
-(require 'viper-keym)
-(require 'viper-mous)
-(require 'viper-macs)
-(require 'viper-ex)
-
-
-\f
-;; Generic predicates
-
-;; These test functions are shamelessly lifted from vip 4.4.2 by Aamod Sane
-
-;; generate test functions
-;; given symbol foo, foo-p is the test function, foos is the set of
-;; Viper command keys
-;; (macroexpand '(viper-test-com-defun foo))
-;; (defun foo-p (com) (consp (memq com foos)))
-
-(defmacro viper-test-com-defun (name)
- (let* ((snm (symbol-name name))
- (nm-p (intern (concat snm "-p")))
- (nms (intern (concat snm "s"))))
- `(defun ,nm-p (com)
- (consp (memq com ,nms)))))
-
-;; Variables for defining VI commands
-
-;; Modifying commands that can be prefixes to movement commands
-(defvar viper-prefix-commands '(?c ?d ?y ?! ?= ?# ?< ?> ?\"))
-;; define viper-prefix-command-p
-(viper-test-com-defun viper-prefix-command)
-
-;; Commands that are pairs eg. dd. r and R here are a hack
-(defconst viper-charpair-commands '(?c ?d ?y ?! ?= ?< ?> ?r ?R))
-;; define viper-charpair-command-p
-(viper-test-com-defun viper-charpair-command)
-
-(defconst viper-movement-commands '(?b ?B ?e ?E ?f ?F ?G ?h ?j ?k ?l
- ?H ?M ?L ?n ?t ?T ?w ?W ?$ ?%
- ?^ ?\( ?\) ?- ?+ ?| ?{ ?} ?\[ ?\] ?' ?`
- ?\; ?, ?0 ?? ?/ ?\ ?\C-m
- space return
- delete backspace
- )
- "Movement commands.")
-;; define viper-movement-command-p
-(viper-test-com-defun viper-movement-command)
-
-;; Vi digit commands
-(defconst viper-digit-commands '(?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
-
-;; define viper-digit-command-p
-(viper-test-com-defun viper-digit-command)
-
-;; Commands that can be repeated by . (dotted)
-(defconst viper-dotable-commands '(?c ?d ?C ?s ?S ?D ?> ?<))
-;; define viper-dotable-command-p
-(viper-test-com-defun viper-dotable-command)
-
-;; Commands that can follow a #
-(defconst viper-hash-commands '(?c ?C ?g ?q ?s))
-;; define viper-hash-command-p
-(viper-test-com-defun viper-hash-command)
-
-;; Commands that may have registers as prefix
-(defconst viper-regsuffix-commands '(?d ?y ?Y ?D ?p ?P ?x ?X))
-;; define viper-regsuffix-command-p
-(viper-test-com-defun viper-regsuffix-command)
-
-(defconst viper-vi-commands (append viper-movement-commands
- viper-digit-commands
- viper-dotable-commands
- viper-charpair-commands
- viper-hash-commands
- viper-prefix-commands
- viper-regsuffix-commands)
- "The list of all commands in Vi-state.")
-;; define viper-vi-command-p
-(viper-test-com-defun viper-vi-command)
-
-;; Contains user settings for vars affected by viper-set-expert-level function.
-;; Not a user option.
-(defvar viper-saved-user-settings nil)
-
-
-\f
-;;; CODE
-
-;; sentinels
-
-;; Runs viper-after-change-functions inside after-change-functions
-(defun viper-after-change-sentinel (beg end len)
- (run-hook-with-args 'viper-after-change-functions beg end len))
-
-;; Runs viper-before-change-functions inside before-change-functions
-(defun viper-before-change-sentinel (beg end)
- (run-hook-with-args 'viper-before-change-functions beg end))
-
-(defsubst viper-post-command-sentinel ()
- (condition-case conds
- (run-hooks 'viper-post-command-hooks)
- (error (viper-message-conditions conds)))
- (if (eq viper-current-state 'vi-state)
- (viper-restore-cursor-color 'after-insert-mode)))
-
-(defsubst viper-pre-command-sentinel ()
- (run-hooks 'viper-pre-command-hooks))
-
-;; Needed so that Viper will be able to figure the last inserted
-;; chunk of text with reasonable accuracy.
-(defsubst viper-insert-state-post-command-sentinel ()
- (if (and (memq viper-current-state '(insert-state replace-state))
- viper-insert-point
- (>= (point) viper-insert-point))
- (setq viper-last-posn-while-in-insert-state (point-marker)))
- (or (overlayp viper-replace-overlay)
- (progn
- (viper-set-replace-overlay (point-min) (point-min))
- (viper-hide-replace-overlay)))
- (if (eq viper-current-state 'insert-state)
- (let ((icolor (viper-frame-value viper-insert-state-cursor-color)))
- (or (stringp (viper-get-saved-cursor-color-in-insert-mode))
- (string= (viper-get-cursor-color) icolor)
- ;; save current color, if not already saved
- (viper-save-cursor-color 'before-insert-mode))
- ;; set insert mode cursor color
- (viper-change-cursor-color icolor)))
- (let ((ecolor (viper-frame-value viper-emacs-state-cursor-color)))
- (when (and ecolor (eq viper-current-state 'emacs-state))
- (or (stringp (viper-get-saved-cursor-color-in-emacs-mode))
- (string= (viper-get-cursor-color) ecolor)
- ;; save current color, if not already saved
- (viper-save-cursor-color 'before-emacs-mode))
- ;; set emacs mode cursor color
- (viper-change-cursor-color ecolor)))
-
- (if (and (eq this-command 'dabbrev-expand)
- (integerp viper-pre-command-point)
- (markerp viper-insert-point)
- (marker-position viper-insert-point)
- (> viper-insert-point viper-pre-command-point))
- (viper-move-marker-locally viper-insert-point viper-pre-command-point)))
-
-(defsubst viper-preserve-cursor-color ()
- (or (memq this-command '(self-insert-command
- viper-del-backward-char-in-insert
- viper-del-backward-char-in-replace
- viper-delete-backward-char
- viper-join-lines
- viper-delete-char))
- (member (viper-event-key last-command-event)
- '(up down left right (meta f) (meta b)
- (control n) (control p) (control f) (control b)))))
-
-(defsubst viper-insert-state-pre-command-sentinel ()
- (or (viper-preserve-cursor-color)
- (viper-restore-cursor-color 'after-insert-mode))
- (if (and (eq this-command 'dabbrev-expand)
- (markerp viper-insert-point)
- (marker-position viper-insert-point))
- (setq viper-pre-command-point (marker-position viper-insert-point))))
-
-(defun viper-R-state-post-command-sentinel ()
- ;; Restoring cursor color is needed despite
- ;; viper-replace-state-pre-command-sentinel: When you jump to another buffer
- ;; in another frame, the pre-command hook won't change cursor color to
- ;; default in that other frame. So, if the second frame cursor was red and
- ;; we set the point outside the replacement region, then the cursor color
- ;; will remain red. Restoring the default, below, prevents this.
- (if (and (<= (viper-replace-start) (point))
- (<= (point) (viper-replace-end)))
- (viper-change-cursor-color
- (viper-frame-value viper-replace-overlay-cursor-color))
- (viper-restore-cursor-color 'after-replace-mode)))
-
-;; to speed up, don't change cursor color before self-insert
-;; and common move commands
-(defsubst viper-replace-state-pre-command-sentinel ()
- (or (viper-preserve-cursor-color)
- (viper-restore-cursor-color 'after-replace-mode)))
-
-
-;; Make sure we don't delete more than needed.
-;; This is executed at viper-last-posn-in-replace-region
-(defsubst viper-trim-replace-chars-to-delete-if-necessary ()
- (setq viper-replace-chars-to-delete
- (max 0
- (min viper-replace-chars-to-delete
- ;; Don't delete more than to the end of repl overlay
- (viper-chars-in-region
- (viper-replace-end) viper-last-posn-in-replace-region)
- ;; point is viper-last-posn-in-replace-region now
- ;; So, this limits deletion to the end of line
- (viper-chars-in-region (point) (viper-line-pos 'end))
- ))))
-
-
-(defun viper-replace-state-post-command-sentinel ()
- ;; Restoring cursor color is needed despite
- ;; viper-replace-state-pre-command-sentinel: When one jumps to another buffer
- ;; in another frame, the pre-command hook won't change cursor color to
- ;; default in that other frame. So, if the second frame cursor was red and
- ;; we set the point outside the replacement region, then the cursor color
- ;; will remain red. Restoring the default, below, fixes this problem.
- ;;
- ;; We optimize for some commands, like self-insert-command,
- ;; viper-delete-backward-char, etc., since they either don't change
- ;; cursor color or, if they terminate replace mode, the color will be changed
- ;; in viper-finish-change
- (or (viper-preserve-cursor-color)
- (viper-restore-cursor-color 'after-replace-mode))
- (cond
- ((eq viper-current-state 'replace-state)
- ;; delete characters to compensate for inserted chars.
- (let ((replace-boundary (viper-replace-end)))
- (save-excursion
- (goto-char viper-last-posn-in-replace-region)
- (viper-trim-replace-chars-to-delete-if-necessary)
- (delete-char viper-replace-chars-to-delete)
- (setq viper-replace-chars-to-delete 0)
- ;; terminate replace mode if reached replace limit
- (if (= viper-last-posn-in-replace-region (viper-replace-end))
- (viper-finish-change)))
-
- (when (viper-pos-within-region
- (point) (viper-replace-start) replace-boundary)
- ;; the state may have changed in viper-finish-change above
- (if (eq viper-current-state 'replace-state)
- (viper-change-cursor-color
- (viper-frame-value viper-replace-overlay-cursor-color)))
- (setq viper-last-posn-in-replace-region (point-marker)))))
- ;; terminate replace mode if changed Viper states.
- (t (viper-finish-change))))
-
-
-;; changing mode
-
-;; Change state to NEW-STATE---either emacs-state, vi-state, or insert-state.
-(defun viper-change-state (new-state)
- ;; Keep viper-post/pre-command-hooks fresh.
- ;; We remove then add viper-post/pre-command-sentinel since it is very
- ;; desirable that viper-pre-command-sentinel is the last hook and
- ;; viper-post-command-sentinel is the first hook.
-
- (remove-hook 'post-command-hook #'viper-post-command-sentinel)
- (add-hook 'post-command-hook #'viper-post-command-sentinel)
- (remove-hook 'pre-command-hook #'viper-pre-command-sentinel)
- (add-hook 'pre-command-hook #'viper-pre-command-sentinel t)
- ;; These hooks will be added back if switching to insert/replace mode
- (remove-hook 'viper-post-command-hooks
- #'viper-insert-state-post-command-sentinel 'local)
- (remove-hook 'viper-pre-command-hooks
- #'viper-insert-state-pre-command-sentinel 'local)
- (setq viper-intermediate-command nil)
- (cond ((eq new-state 'vi-state)
- (cond ((member viper-current-state '(insert-state replace-state))
-
- ;; move viper-last-posn-while-in-insert-state
- ;; This is a normal hook that is executed in insert/replace
- ;; states after each command. In Vi/Emacs state, it does
- ;; nothing. We need to execute it here to make sure that
- ;; the last posn was recorded when we hit ESC.
- ;; It may be left unrecorded if the last thing done in
- ;; insert/repl state was dabbrev-expansion or abbrev
- ;; expansion caused by hitting ESC
- (viper-insert-state-post-command-sentinel)
-
- (condition-case conds
- (progn
- (viper-save-last-insertion
- viper-insert-point
- viper-last-posn-while-in-insert-state)
- (if viper-began-as-replace
- (setq viper-began-as-replace nil)
- ;; repeat insert commands if numerical arg > 1
- (save-excursion
- (viper-repeat-insert-command))))
- (error
- (viper-message-conditions conds)))
-
- (if (> (length viper-last-insertion) 0)
- (viper-push-onto-ring viper-last-insertion
- 'viper-insertion-ring))
-
- (if viper-ESC-moves-cursor-back
- (or (bolp) (viper-beginning-of-field) (backward-char 1))))
- ))
-
- ;; insert or replace
- ((memq new-state '(insert-state replace-state))
- (if (memq viper-current-state '(emacs-state vi-state))
- (viper-move-marker-locally 'viper-insert-point (point)))
- (viper-move-marker-locally
- 'viper-last-posn-while-in-insert-state (point))
- (add-hook 'viper-post-command-hooks
- #'viper-insert-state-post-command-sentinel t 'local)
- (add-hook 'viper-pre-command-hooks
- #'viper-insert-state-pre-command-sentinel t 'local))
- ) ; outermost cond
-
- ;; Nothing needs to be done to switch to emacs mode! Just set some
- ;; variables, which is already done in viper-change-state-to-emacs!
-
- ;; ISO accents
- ;; always turn off iso-accents-mode in vi-state, or else we won't be able to
- ;; use the keys `,',^ , as they will do accents instead of Vi actions.
- (cond ((eq new-state 'vi-state) (viper-set-iso-accents-mode nil));accents off
- (viper-automatic-iso-accents (viper-set-iso-accents-mode t));accents on
- (t (viper-set-iso-accents-mode nil)))
- ;; Always turn off quail mode in vi state
- (cond ((eq new-state 'vi-state) (viper-set-input-method nil)) ;intl input off
- (viper-special-input-method (viper-set-input-method t)) ;intl input on
- (t (viper-set-input-method nil)))
-
- (setq viper-current-state new-state)
-
- (viper-update-syntax-classes)
- (viper-normalize-minor-mode-map-alist)
- (viper-adjust-keys-for new-state)
- (viper-set-mode-vars-for new-state)
- (viper-refresh-mode-line)
- )
-
-
-(defun viper-adjust-keys-for (state)
- "Make necessary adjustments to keymaps before entering STATE."
- (cond ((memq state '(insert-state replace-state))
- (if viper-auto-indent
- (progn
- (define-key viper-insert-basic-map "\C-m" #'viper-autoindent)
- (if viper-want-emacs-keys-in-insert
- ;; expert
- (define-key viper-insert-basic-map "\C-j" nil)
- ;; novice
- (define-key viper-insert-basic-map "\C-j" #'viper-autoindent)))
- (define-key viper-insert-basic-map "\C-m" nil)
- (define-key viper-insert-basic-map "\C-j" nil))
-
- (setq viper-insert-diehard-minor-mode
- (not viper-want-emacs-keys-in-insert))
-
- (if viper-want-ctl-h-help
- (progn
- (define-key viper-insert-basic-map "\C-h" #'help-command)
- (define-key viper-replace-map "\C-h" #'help-command))
- (define-key viper-insert-basic-map
- "\C-h" #'viper-del-backward-char-in-insert)
- (define-key viper-replace-map
- "\C-h" #'viper-del-backward-char-in-replace))
- ;; In XEmacs, C-h overrides backspace, so we make sure it doesn't.
- (define-key viper-insert-basic-map
- [backspace] #'viper-del-backward-char-in-insert)
- (define-key viper-replace-map
- [backspace] #'viper-del-backward-char-in-replace)
- ) ; end insert/replace case
- (t ; Vi state
- (setq viper-vi-diehard-minor-mode (not viper-want-emacs-keys-in-vi))
- (define-key viper-vi-basic-map "\C-h"
- (if viper-want-ctl-h-help #'help-command #'viper-backward-char))
- ;; In XEmacs, C-h overrides backspace, so we make sure it doesn't.
- (define-key viper-vi-basic-map [backspace] #'viper-backward-char))
- ))
-
-
-;; Normalizes minor-mode-map-alist by putting Viper keymaps first.
-;; This ensures that Viper bindings are in effect, regardless of which minor
-;; modes were turned on by the user or by other packages.
-(defun viper-normalize-minor-mode-map-alist ()
- (setq viper--intercept-key-maps
- (list
- (cons 'viper-vi-intercept-minor-mode viper-vi-intercept-map)
- (cons 'viper-insert-intercept-minor-mode viper-insert-intercept-map)
- (cons 'viper-emacs-intercept-minor-mode viper-emacs-intercept-map)
- ))
- (setq viper--key-maps
- (list (cons 'viper-vi-minibuffer-minor-mode viper-minibuffer-map)
- (cons 'viper-vi-local-user-minor-mode viper-vi-local-user-map)
- (cons 'viper-vi-kbd-minor-mode viper-vi-kbd-map)
- (cons 'viper-vi-global-user-minor-mode viper-vi-global-user-map)
- (cons 'viper-vi-state-modifier-minor-mode
- (if (keymapp
- (cdr (assoc major-mode viper-vi-state-modifier-alist)))
- (cdr (assoc major-mode viper-vi-state-modifier-alist))
- viper-empty-keymap))
- (cons 'viper-vi-diehard-minor-mode viper-vi-diehard-map)
- (cons 'viper-vi-basic-minor-mode viper-vi-basic-map)
- (cons 'viper-replace-minor-mode viper-replace-map)
- ;; viper-insert-minibuffer-minor-mode must come after
- ;; viper-replace-minor-mode
- (cons 'viper-insert-minibuffer-minor-mode
- viper-minibuffer-map)
- (cons 'viper-insert-local-user-minor-mode
- viper-insert-local-user-map)
- (cons 'viper-insert-kbd-minor-mode viper-insert-kbd-map)
- (cons 'viper-insert-global-user-minor-mode
- viper-insert-global-user-map)
- (cons 'viper-insert-state-modifier-minor-mode
- (if (keymapp
- (cdr (assoc major-mode
- viper-insert-state-modifier-alist)))
- (cdr (assoc major-mode
- viper-insert-state-modifier-alist))
- viper-empty-keymap))
- (cons 'viper-insert-diehard-minor-mode viper-insert-diehard-map)
- (cons 'viper-insert-basic-minor-mode viper-insert-basic-map)
- (cons 'viper-emacs-local-user-minor-mode
- viper-emacs-local-user-map)
- (cons 'viper-emacs-kbd-minor-mode viper-emacs-kbd-map)
- (cons 'viper-emacs-global-user-minor-mode
- viper-emacs-global-user-map)
- (cons 'viper-emacs-state-modifier-minor-mode
- (if (keymapp
- (cdr
- (assoc major-mode viper-emacs-state-modifier-alist)))
- (cdr
- (assoc major-mode viper-emacs-state-modifier-alist))
- viper-empty-keymap)))))
-
-
-\f
-;; Viper mode-changing commands and utilities
-
-(defcustom viper-enable-minibuffer-faces t
- "If non-nil, viper uses distinct faces in the minibuffer."
- :type 'boolean
- :version "30.1"
- :group 'viper-misc)
-
-;; Modifies mode-line-buffer-identification.
-(defun viper-refresh-mode-line ()
- (setq-local viper-mode-string
- (cond ((eq viper-current-state 'emacs-state) viper-emacs-state-id)
- ((eq viper-current-state 'vi-state) viper-vi-state-id)
- ((eq viper-current-state 'replace-state) viper-replace-state-id)
- ((eq viper-current-state 'insert-state) viper-insert-state-id)))
-
- ;; Sets Viper mode string in global-mode-string
- (force-mode-line-update))
-
-
-;; Switch from Insert state to Vi state.
-(defun viper-exit-insert-state ()
- (interactive)
- (viper-change-state-to-vi))
-
-(defun viper-set-mode-vars-for (state)
- "Set Viper minor mode variables to put Viper's state STATE in effect."
-
- ;; Emacs state
- (setq viper-vi-minibuffer-minor-mode nil
- viper-insert-minibuffer-minor-mode nil
- viper-vi-intercept-minor-mode nil
- viper-insert-intercept-minor-mode nil
-
- viper-vi-local-user-minor-mode nil
- viper-vi-kbd-minor-mode nil
- viper-vi-global-user-minor-mode nil
- viper-vi-state-modifier-minor-mode nil
- viper-vi-diehard-minor-mode nil
- viper-vi-basic-minor-mode nil
-
- viper-replace-minor-mode nil
-
- viper-insert-local-user-minor-mode nil
- viper-insert-kbd-minor-mode nil
- viper-insert-global-user-minor-mode nil
- viper-insert-state-modifier-minor-mode nil
- viper-insert-diehard-minor-mode nil
- viper-insert-basic-minor-mode nil
- viper-emacs-intercept-minor-mode t
- viper-emacs-local-user-minor-mode t
- viper-emacs-kbd-minor-mode (not (viper-is-in-minibuffer))
- viper-emacs-global-user-minor-mode t
- viper-emacs-state-modifier-minor-mode t
- )
-
- ;; Vi state
- (if (eq state 'vi-state) ; adjust for vi-state
- (setq
- viper-vi-intercept-minor-mode t
- viper-vi-minibuffer-minor-mode (viper-is-in-minibuffer)
- viper-vi-local-user-minor-mode t
- viper-vi-kbd-minor-mode (not (viper-is-in-minibuffer))
- viper-vi-global-user-minor-mode t
- viper-vi-state-modifier-minor-mode t
- ;; don't let the diehard keymap block command completion
- ;; and other things in the minibuffer
- viper-vi-diehard-minor-mode (not
- (or viper-want-emacs-keys-in-vi
- (viper-is-in-minibuffer)))
- viper-vi-basic-minor-mode t
- viper-emacs-intercept-minor-mode nil
- viper-emacs-local-user-minor-mode nil
- viper-emacs-kbd-minor-mode nil
- viper-emacs-global-user-minor-mode nil
- viper-emacs-state-modifier-minor-mode nil
- ))
-
- ;; Insert and Replace states
- (if (member state '(insert-state replace-state))
- (setq
- viper-insert-intercept-minor-mode t
- viper-replace-minor-mode (eq state 'replace-state)
- viper-insert-minibuffer-minor-mode (viper-is-in-minibuffer)
- viper-insert-local-user-minor-mode t
- viper-insert-kbd-minor-mode (not (viper-is-in-minibuffer))
- viper-insert-global-user-minor-mode t
- viper-insert-state-modifier-minor-mode t
- ;; don't let the diehard keymap block command completion
- ;; and other things in the minibuffer
- viper-insert-diehard-minor-mode (not
- (or
- viper-want-emacs-keys-in-insert
- (viper-is-in-minibuffer)))
- viper-insert-basic-minor-mode t
- viper-emacs-intercept-minor-mode nil
- viper-emacs-local-user-minor-mode nil
- viper-emacs-kbd-minor-mode nil
- viper-emacs-global-user-minor-mode nil
- viper-emacs-state-modifier-minor-mode nil
- ))
-
- ;; minibuffer faces
- (if (and (viper-has-face-support-p) viper-enable-minibuffer-faces)
- (setq viper-minibuffer-current-face
- (cond ((eq state 'emacs-state) viper-minibuffer-emacs-face)
- ((eq state 'vi-state) viper-minibuffer-vi-face)
- ((memq state '(insert-state replace-state))
- viper-minibuffer-insert-face))))
-
- (if (and (viper-is-in-minibuffer) viper-enable-minibuffer-faces)
- (viper-set-minibuffer-overlay))
- )
-
-;; This also takes care of the annoying incomplete lines in files.
-;; Also, this fixes `undo' to work vi-style for complex commands.
-(defun viper-change-state-to-vi (&rest _)
- "Change Viper state to Vi."
- (interactive)
- (if (and viper-first-time (not (viper-is-in-minibuffer)))
- (viper-mode)
- (if overwrite-mode (overwrite-mode -1))
- (or (overlayp viper-replace-overlay)
- (viper-set-replace-overlay (point-min) (point-min)))
- (viper-hide-replace-overlay)
- ;; Expand abbrevs iff the previous character has word syntax.
- (and abbrev-mode
- (eq (char-syntax (preceding-char)) ?w)
- (expand-abbrev))
- (if (and auto-fill-function (> (current-column) fill-column))
- (funcall auto-fill-function))
- ;; don't leave whitespace lines around
- (if (and (memq last-command
- '(viper-autoindent
- viper-open-line viper-Open-line
- viper-replace-state-exit-cmd))
- (viper-over-whitespace-line))
- (indent-to-left-margin))
- (viper-add-newline-at-eob-if-necessary)
- (viper-adjust-undo)
-
- (if (eq viper-current-state 'emacs-state)
- (viper-restore-cursor-color 'after-emacs-mode)
- (viper-restore-cursor-color 'after-insert-mode))
-
- (viper-change-state 'vi-state)
-
- ;; Protect against user errors in hooks
- (condition-case conds
- (run-hooks 'viper-vi-state-hook)
- (error
- (viper-message-conditions conds)))))
-
-(defun viper-change-state-to-insert ()
- "Change Viper state to Insert."
- (interactive)
- (viper-change-state 'insert-state)
-
- (or (overlayp viper-replace-overlay)
- (viper-set-replace-overlay (point-min) (point-min)))
- (viper-hide-replace-overlay)
-
- (let ((icolor (viper-frame-value viper-insert-state-cursor-color)))
- (or (stringp (viper-get-saved-cursor-color-in-insert-mode))
- (string= (viper-get-cursor-color) icolor)
- (viper-save-cursor-color 'before-insert-mode))
- (viper-change-cursor-color icolor))
-
- ;; Protect against user errors in hooks
- (condition-case conds
- (run-hooks 'viper-insert-state-hook)
- (error
- (viper-message-conditions conds))))
-
-(defsubst viper-downgrade-to-insert ()
- ;; Protect against user errors in hooks
- (condition-case conds
- (run-hooks 'viper-insert-state-hook)
- (error
- (viper-message-conditions conds)))
- (setq viper-current-state 'insert-state
- viper-replace-minor-mode nil))
-
-
-
-;; Change to replace state. When the end of replacement region is reached,
-;; replace state changes to insert state.
-(defun viper-change-state-to-replace (&optional non-R-cmd)
- (viper-change-state 'replace-state)
- ;; Run insert-state-hook
- (condition-case conds
- (run-hooks 'viper-insert-state-hook 'viper-replace-state-hook)
- (error
- (viper-message-conditions conds)))
-
- (if non-R-cmd
- (viper-start-replace)
- ;; 'R' is implemented using Emacs's overwrite-mode
- (viper-start-R-mode))
- )
-
-
-(defun viper-change-state-to-emacs (&rest _)
- "Change Viper state to Emacs."
- (interactive)
- (or (overlayp viper-replace-overlay)
- (viper-set-replace-overlay (point-min) (point-min)))
- (viper-hide-replace-overlay)
-
- (let ((ecolor (viper-frame-value viper-emacs-state-cursor-color)))
- (when ecolor
- (or (stringp (viper-get-saved-cursor-color-in-emacs-mode))
- (string= (viper-get-cursor-color) ecolor)
- (viper-save-cursor-color 'before-emacs-mode))
- (viper-change-cursor-color ecolor)))
-
- (viper-change-state 'emacs-state)
-
- ;; Protect against user errors in hooks
- (condition-case conds
- (run-hooks 'viper-emacs-state-hook)
- (error
- (viper-message-conditions conds))))
-
-;; escape to emacs mode temporarily
-(defun viper-escape-to-emacs (arg &optional events)
- "Escape to Emacs state from Vi state for one Emacs command.
-ARG is used as the prefix value for the executed command. If
-EVENTS is a list of events, which become the beginning of the command."
- (interactive "P")
- (if (viper= last-command-event ?\\)
- (message "Switched to EMACS state for the next command..."))
- (viper-escape-to-state arg events 'emacs-state))
-
-;; escape to Vi mode temporarily
-(defun viper-escape-to-vi (arg)
- "Escape from Emacs state to Vi state for one Vi 1-character command.
-If the Vi command that the user types has a prefix argument, e.g., `d2w', then
-Vi's prefix argument will be used. Otherwise, the prefix argument passed to
-`viper-escape-to-vi' is used."
- (interactive "P")
- (message "Switched to VI state for the next command...")
- (viper-escape-to-state arg nil 'vi-state))
-
-;; Escape to STATE mode for one Emacs command.
-(defun viper-escape-to-state (arg events state)
- ;;(let (com key prefix-arg)
- (let (com key)
- ;; this temporarily turns off Viper's minor mode keymaps
- (viper-set-mode-vars-for state)
- (viper-normalize-minor-mode-map-alist)
- (if events (viper-set-unread-command-events events))
-
- ;; protect against keyboard quit and other errors
- (condition-case nil
- (let (viper-vi-kbd-minor-mode
- viper-insert-kbd-minor-mode
- viper-emacs-kbd-minor-mode)
- (setq com (key-binding (setq key (read-key-sequence nil))))
- ;; In case of binding indirection--chase definitions.
- ;; Have to do it here because we execute this command under
- ;; different keymaps, so command-execute may not do the
- ;; right thing there
- (while (vectorp com) (setq com (key-binding com)))
- ;; Execute command com in the original Viper state, not in state
- ;; `state'. Otherwise, if we switch buffers while executing the
- ;; escaped to command, Viper's mode vars will remain those of
- ;; `state'. When we return to the orig buffer, the bindings will be
- ;; screwed up.
- (viper-set-mode-vars-for viper-current-state)
-
- ;; this-command, last-command-char, last-command-event
- (setq this-command com)
- ;; Emacs represents key sequences as sequences (str or vec)
- (setq last-command-event (viper-seq-last-elt key))
-
- (if (commandp com)
- ;; pretend that current state is the state we escaped to
- (let ((viper-current-state state))
- (setq prefix-arg (or prefix-arg arg))
- (command-execute com))))
- (quit (ding))
- (error (beep 1))))
- ;; set state in the new buffer
- (viper-set-mode-vars-for viper-current-state))
-
-;; This is used in order to allow reading characters according to the input
-;; method. The character is read in emacs and inserted into the buffer.
-;; If an input method is in effect, this might
-;; cause several characters to be combined into one.
-;; Also takes care of the iso-accents mode
-(defun viper-special-read-and-insert-char ()
- (viper-set-mode-vars-for 'emacs-state)
- (viper-normalize-minor-mode-map-alist)
- (if viper-special-input-method
- (viper-set-input-method t))
- (if viper-automatic-iso-accents
- (viper-set-iso-accents-mode t))
- (condition-case nil
- (let (viper-vi-kbd-minor-mode
- viper-insert-kbd-minor-mode
- viper-emacs-kbd-minor-mode
- ch)
- (cond ((and viper-special-input-method
- (fboundp 'quail-input-method))
- ;; (let ...) is used to restore unread-command-events to the
- ;; original state. We don't want anything left in there after
- ;; key translation. (Such left-overs are possible if the user
- ;; types a regular key.)
- (let (unread-command-events)
- ;; The next cmd and viper-set-unread-command-events
- ;; are intended to prevent the input method
- ;; from swallowing ^M, ^Q and other special characters
- (setq ch (read-char-exclusive))
- ;; replace ^M with the newline
- (if (eq ch ?\C-m) (setq ch ?\n))
- ;; Make sure ^V and ^Q work as quotation chars
- (if (memq ch '(?\C-v ?\C-q))
- (setq ch (read-char-exclusive)))
- (viper-set-unread-command-events ch)
- (quail-input-method nil)
-
- (if (and ch (string= quail-current-str ""))
- (insert ch)
- (insert quail-current-str))
- (setq ch (or ch
- (aref quail-current-str
- (1- (length quail-current-str)))))))
- ((and (boundp 'iso-accents-mode) iso-accents-mode)
- (setq ch (aref (read-key-sequence nil) 0))
- ;; replace ^M with the newline
- (if (eq ch ?\C-m) (setq ch ?\n))
- ;; Make sure ^V and ^Q work as quotation chars
- (if (memq ch '(?\C-v ?\C-q))
- (setq ch (aref (read-key-sequence nil) 0)))
- (insert ch))
- (t
- (setq ch (aref (read-key-sequence nil) 0))
- ;; replace ^M with the newline
- (if (eq ch ?\C-m) (setq ch ?\n))
- ;; Make sure ^V and ^Q work as quotation chars
- (if (memq ch '(?\C-v ?\C-q))
- (setq ch (aref (read-key-sequence nil) 0)))
- (insert ch)))
- (setq last-command-event ch)
- ) ; let
- (error nil)
- ) ; condition-case
-
- (viper-set-input-method nil)
- (viper-set-iso-accents-mode nil)
- (viper-set-mode-vars-for viper-current-state)
- )
-
-
-(defun viper-exec-form-in-vi (form)
- "Execute FORM in Vi state, regardless of the current Vi state."
- (let ((buff (current-buffer))
- result)
- (viper-set-mode-vars-for 'vi-state)
-
- (condition-case nil
- (let (viper-vi-kbd-minor-mode) ; execute without kbd macros
- (setq result (eval form t)))
- (error
- (signal 'quit nil)))
-
- (if (not (equal buff (current-buffer))) ; cmd switched buffer
- (with-current-buffer buff
- (viper-set-mode-vars-for viper-current-state)))
- (viper-set-mode-vars-for viper-current-state)
- result))
-
-(defun viper-exec-form-in-emacs (form)
- "Execute FORM in Emacs, temporarily disabling Viper's minor modes.
-Similar to `viper-escape-to-emacs', but accepts forms rather than keystrokes."
- (let ((buff (current-buffer))
- result)
- (viper-set-mode-vars-for 'emacs-state)
- (setq result (eval form t))
- (if (not (equal buff (current-buffer))) ; cmd switched buffer
- (with-current-buffer buff
- (viper-set-mode-vars-for viper-current-state)))
- (viper-set-mode-vars-for viper-current-state)
- result))
-
-;; This executes the last kbd event in emacs mode. Is used when we want to
-;; interpret certain keys directly in emacs (as, for example, in comint mode).
-(defun viper-exec-key-in-emacs (arg)
- (interactive "P")
- (viper-escape-to-emacs arg last-command-event))
-
-
-;; This is needed because minor modes sometimes override essential Viper
-;; bindings. By letting Viper know which files these modes are in, it will
-;; arrange to reorganize minor-mode-map-alist so that things will work right.
-(defun viper-harness-minor-mode (load-file)
- "Familiarize Viper with a minor mode defined in LOAD-FILE.
-Minor modes that have their own keymaps may overshadow Viper keymaps.
-This function is designed to make Viper aware of the packages that define
-such minor modes.
-Usage:
- (viper-harness-minor-mode load-file)
-
-LOAD-FILE is the name of the file where the specific minor mode is defined.
-Suffixes such as .el or .elc should be stripped."
-
- (interactive "sEnter name of the load file: ")
- (eval-after-load load-file '(viper-normalize-minor-mode-map-alist)))
-
-
-(defun viper-ESC (arg)
- "Emulate ESC key in Emacs.
-Prevents multiple escape keystrokes if viper-no-multiple-ESC is true.
-If `viper-no-multiple-ESC' is `twice' double ESC would ding in vi-state.
-Other ESC sequences are emulated via the current Emacs's major mode
-keymap. This is more convenient on TTYs, since this won't block
-function keys such as up, down, etc. ESC will also will also work as
-a Meta key in this case. When `viper-no-multiple-ESC' is nil, ESC works
-as a Meta key and any number of multiple escapes are allowed."
- (interactive "P")
- (let (char)
- (cond ((and (not viper-no-multiple-ESC) (eq viper-current-state 'vi-state))
- (setq char (viper-read-char-exclusive))
- (viper-escape-to-emacs arg (list ?\e char) ))
- ((and (eq viper-no-multiple-ESC 'twice)
- (eq viper-current-state 'vi-state))
- (setq char (viper-read-char-exclusive))
- (if (= char (string-to-char viper-ESC-key))
- (ding)
- (viper-escape-to-emacs arg (list ?\e char) )))
- (t (ding)))
- ))
-
-(defun viper-alternate-Meta-key (arg)
- "Simulate Emacs Meta key."
- (interactive "P")
- (sit-for 1) (message "ESC-")
- (viper-escape-to-emacs arg '(?\e)))
-
-(defun viper-toggle-key-action ()
- "Action bound to `viper-toggle-key'."
- (interactive)
- (if (and (< viper-expert-level 2) (equal viper-toggle-key "\C-z"))
- (if (viper-window-display-p)
- (iconify-or-deiconify-frame)
- (suspend-emacs))
- (viper-change-state-to-emacs)))
-
-;; Listen to ESC key.
-(defun viper-intercept-ESC-key ()
- "Function that implements ESC key in Viper emulation of Vi."
- (interactive)
- ;; `key-binding' needs to be called in a context where Viper's
- ;; minor-mode map(s) have been temporarily disabled so the ESC
- ;; binding to viper-intercept-ESC-key doesn't hide the binding we're
- ;; looking for (Bug#9146):
- (let* ((cmd 'viper-intercept-ESC-key))
-
- ;; call the actual function to execute ESC (if no other symbols followed)
- ;; or the key bound to the ESC sequence (if the sequence was issued
- ;; with very short delay between characters).
- (if (eq cmd 'viper-intercept-ESC-key)
- (setq cmd
- (cond ((eq viper-current-state 'vi-state)
- 'viper-ESC)
- ((eq viper-current-state 'insert-state)
- 'viper-exit-insert-state)
- ((eq viper-current-state 'replace-state)
- 'viper-replace-state-exit-cmd)
- (t 'viper-change-state-to-vi)
- )))
- (call-interactively cmd)))
-
-
-
-\f
-;; prefix argument for Vi mode
-
-;; In Vi mode, prefix argument is a dotted pair (NUM . COM) where NUM
-;; represents the numeric value of the prefix argument and COM represents
-;; command prefix such as "c", "d", "m" and "y".
-
-;; Get value part of prefix-argument ARG.
-(defsubst viper-p-val (arg)
- (cond ((null arg) 1)
- ((consp arg)
- (if (or (null (car arg)) (equal (car arg) '(nil)))
- 1 (car arg)))
- (t arg)))
-
-;; Get raw value part of prefix-argument ARG.
-(defsubst viper-P-val (arg)
- (cond ((consp arg) (car arg))
- (t arg)))
-
-;; Get com part of prefix-argument ARG.
-(defsubst viper-getcom (arg)
- (cond ((null arg) nil)
- ((consp arg) (cdr arg))
- (t nil)))
-
-;; Get com part of prefix-argument ARG and modify it.
-(defun viper-getCom (arg)
- (let ((com (viper-getcom arg)))
- (cond ((viper= com ?c) ?c)
- ;; Previously, ?c was being converted to ?C, but this prevented
- ;; multiline replace regions.
- ;;((viper= com ?c) ?C)
- ((viper= com ?d) ?D)
- ((viper= com ?y) ?Y)
- (t com))))
-
-
-;; Compute numeric prefix arg value.
-;; Invoked by EVENT-CHAR. COM is the command part obtained so far.
-(defun viper-prefix-arg-value (event-char com)
- (let ((viper-intermediate-command 'viper-digit-argument)
- value func)
- ;; read while number
- (while (and (characterp event-char)
- (>= event-char ?0) (<= event-char ?9))
- (setq value (+ (* (if (integerp value) value 0) 10) (- event-char ?0)))
- (setq event-char (read-event)))
-
- (setq prefix-arg value)
- (if com (setq prefix-arg (cons prefix-arg com)))
- (while (eq event-char ?U)
- (viper-describe-arg prefix-arg)
- (setq event-char (read-event)))
-
- (if (or com (and (not (eq viper-current-state 'vi-state))
- ;; make sure it is a Vi command
- (characterp event-char)
- (viper-vi-command-p event-char)
- ))
- ;; If appears to be one of the vi commands,
- ;; then execute it with funcall and clear prefix-arg in order to not
- ;; confuse subsequent commands
- (progn
- ;; last-command-event is the char we want emacs to think was typed
- ;; last. If com is not nil, the viper-digit-argument command was
- ;; called from within viper-prefix-arg command, such as `d', `w',
- ;; etc., i.e., the user typed, say, d2. In this case, `com' would be
- ;; `d', `w', etc. If viper-digit-argument was invoked by
- ;; viper-escape-to-vi (which is indicated by the fact that the
- ;; current state is not vi-state), then `event-char' represents the
- ;; vi command to be executed (e.g., `d', `w', etc). Again,
- ;; last-command-event must make emacs believe that this is the command
- ;; we typed.
- (cond ((eq event-char 'return) (setq event-char ?\C-m))
- ((eq event-char 'delete) (setq event-char ?\C-?))
- ((eq event-char 'backspace) (setq event-char ?\C-h))
- ((eq event-char 'space) (setq event-char ?\ )))
- (setq last-command-event (or com event-char))
- (setq func (viper-exec-form-in-vi
- `(key-binding (char-to-string ,event-char))))
- (funcall func prefix-arg)
- (setq prefix-arg nil))
- ;; some other command -- let emacs do it in its own way
- (viper-set-unread-command-events event-char))
- ))
-
-
-;; Vi operator as prefix argument."
-(defun viper-prefix-arg-com (char value com)
- (let ((cont t)
- cmd-info
- cmd-to-exec-at-end)
- (while (and cont
- (memq char
- (list ?c ?d ?y ?! ?< ?> ?= ?# ?r ?R ?\"
- viper-buffer-search-char)))
- (if com
- ;; this means that we already have a command character, so we
- ;; construct a com list and exit while. however, if char is "
- ;; it is an error.
- (progn
- ;; new com is (CHAR . OLDCOM)
- (if (memq char '(?# ?\")) (user-error viper-ViperBell))
- (setq com (cons char com))
- (setq cont nil))
- ;; If com is nil we set com as char, and read more. Again, if char is
- ;; ", we read the name of register and store it in viper-use-register.
- ;; if char is !, =, or #, a complete com is formed so we exit the while
- ;; loop.
- (cond ((memq char '(?! ?=))
- (setq com char)
- (setq char (read-char))
- (setq cont nil))
- ((viper= char ?#)
- ;; read a char and encode it as com
- (setq com (+ 128 (read-char)))
- (setq char (read-char)))
- ((viper= char ?\")
- (let ((reg (read-char)))
- (if (viper-valid-register reg)
- (setq viper-use-register reg)
- (user-error viper-ViperBell))
- (setq char (read-char))))
- (t
- (setq com char)
- (setq char (read-char))))))
-
- (if (atom com)
- ;; `com' is a single char, so we construct the command argument
- ;; and if `char' is `?', we describe the arg; otherwise
- ;; we prepare the command that will be executed at the end.
- (progn
- (setq cmd-info (cons value com))
- (while (viper= char ?U)
- (viper-describe-arg cmd-info)
- (setq char (read-char)))
- ;; `char' is a movement cmd, a digit arg cmd, or a register cmd---so
- ;; we execute it at the very end
- (or (viper-movement-command-p char)
- (viper-digit-command-p char)
- (viper-regsuffix-command-p char)
- (viper= char ?!) ; bang command
- (viper= char ?g) ; the gg command (like G0)
- (user-error viper-ViperBell))
- (setq cmd-to-exec-at-end
- (viper-exec-form-in-vi
- `(key-binding (char-to-string ,char)))))
-
- ;; as com is non-nil, this means that we have a command to execute
- (if (memq (car com) '(?r ?R))
- ;; execute appropriate region command.
- (let ((char (car com)) (com (cdr com)))
- (setq prefix-arg (cons value com))
- (if (viper= char ?r)
- (viper-region prefix-arg)
- (viper-Region prefix-arg))
- ;; reset prefix-arg
- (setq prefix-arg nil))
- ;; otherwise, reset prefix arg and call appropriate command
- (setq value (if (null value) 1 value))
- (setq prefix-arg nil)
- (cond
- ;; If we change ?C to ?c here, then cc will enter replacement mode
- ;; rather than deleting lines. However, it will affect 1 less line
- ;; than normal. We decided to not use replacement mode here and
- ;; follow Vi, since replacement mode on n full lines can be achieved
- ;; with nC.
- ((equal com '(?c . ?c)) (viper-line (cons value ?C)))
- ((equal com '(?d . ?d)) (viper-line (cons value ?D)))
- ((equal com '(?d . ?y)) (viper-yank-defun))
- ((equal com '(?y . ?y)) (viper-line (cons value ?Y)))
- ((equal com '(?< . ?<)) (viper-line (cons value ?<)))
- ((equal com '(?> . ?>)) (viper-line (cons value ?>)))
- ((equal com '(?! . ?!)) (viper-line (cons value ?!)))
- ((equal com '(?= . ?=)) (viper-line (cons value ?=)))
- ;; gg acts as G0
- ((equal (car com) ?g) (viper-goto-line 0))
- (t (user-error viper-ViperBell)))))
-
- (if cmd-to-exec-at-end
- (progn
- (setq last-command-event char)
- (condition-case err
- (funcall cmd-to-exec-at-end cmd-info)
- (error
- (error "%s" (error-message-string err))))))
- ))
-
-(defun viper-describe-arg (arg)
- (let (val com)
- (setq val (viper-P-val arg)
- com (viper-getcom arg))
- (if (null val)
- (if (null com)
- (message "Value is nil, and command is nil")
- (message "Value is nil, and command is `%c'" com))
- (if (null com)
- (message "Value is `%d', and command is nil" val)
- (message "Value is `%d', and command is `%c'" val com)))))
-
-(defun viper-digit-argument (arg)
- "Begin numeric argument for the next command."
- (interactive "P")
- (viper-prefix-arg-value
- last-command-event (if (consp arg) (cdr arg) nil)))
-
-(defun viper-command-argument (arg)
- "Accept a motion command as an argument."
- (interactive "P")
- (let ((viper-intermediate-command 'viper-command-argument))
- (condition-case nil
- (viper-prefix-arg-com
- last-command-event
- (cond ((null arg) nil)
- ((consp arg) (car arg))
- ((integerp arg) arg)
- (t (error viper-InvalidCommandArgument)))
- (cond ((null arg) nil)
- ((consp arg) (cdr arg))
- ((integerp arg) nil)
- (t (error viper-InvalidCommandArgument))))
- (quit (setq viper-use-register nil)
- (signal 'quit nil)))
- (deactivate-mark)))
-
-\f
-;; repeat last destructive command
-
-;; Append region to text in register REG.
-;; START and END are buffer positions indicating what to append.
-(defsubst viper-append-to-register (reg start end)
- (set-register reg (concat (if (stringp (get-register reg))
- (get-register reg) "")
- (buffer-substring start end))))
-
-;; Saves last inserted text for possible use by viper-repeat command.
-(defun viper-save-last-insertion (beg end)
- (condition-case nil
- (setq viper-last-insertion (buffer-substring beg end))
- (error
- ;; beg or end marker are somehow screwed up
- (setq viper-last-insertion nil)))
- (setq viper-last-insertion (buffer-substring beg end))
- (or (< (length viper-d-com) 5)
- (setcar (nthcdr 4 viper-d-com) viper-last-insertion))
- (or (null viper-command-ring)
- (ring-empty-p viper-command-ring)
- (progn
- (setcar (nthcdr 4 (viper-current-ring-item viper-command-ring))
- viper-last-insertion)
- ;; del most recent elt, if identical to the second most-recent
- (viper-cleanup-ring viper-command-ring)))
- )
-
-(defsubst viper-yank-last-insertion ()
- "Insert the text saved by the previous viper-save-last-insertion command."
- (condition-case nil
- (insert viper-last-insertion)
- (error nil)))
-
-
-;; define functions to be executed
-
-;; invoked by the `C' command
-(defun viper-exec-change (m-com _com)
- (or (and (markerp viper-com-point) (marker-position viper-com-point))
- (set-marker viper-com-point (point) (current-buffer)))
- ;; handle C cmd at the eol and at eob.
- (if (or (and (eolp) (= viper-com-point (point)))
- (= viper-com-point (point-max)))
- (progn
- (insert " ")(backward-char 1)))
- (if (= viper-com-point (point))
- (viper-forward-char-carefully))
- (push-mark viper-com-point)
- (if (eq m-com 'viper-next-line-at-bol)
- (viper-enlarge-region (mark t) (point)))
- (if (< (point) (mark t))
- (exchange-point-and-mark))
- (if (eq (preceding-char) ?\n)
- (viper-backward-char-carefully)) ; give back the newline
- (if (eq viper-intermediate-command 'viper-repeat)
- (viper-change-subr (mark t) (point))
- (viper-change (mark t) (point))))
-
-;; this is invoked by viper-substitute-line
-(defun viper-exec-Change (_m-com _com)
- (save-excursion
- (set-mark viper-com-point)
- (viper-enlarge-region (mark t) (point))
- (if viper-use-register
- (progn
- (cond ((viper-valid-register viper-use-register '(letter digit))
- (copy-to-register
- viper-use-register (mark t) (point) nil))
- ((viper-valid-register viper-use-register '(Letter))
- (viper-append-to-register
- (downcase viper-use-register) (mark t) (point)))
- (t (setq viper-use-register nil)
- (error viper-InvalidRegister viper-use-register)))
- (setq viper-use-register nil)))
- (delete-region (mark t) (point)))
- (open-line 1)
- (if (eq viper-intermediate-command 'viper-repeat)
- (viper-yank-last-insertion)
- (viper-change-state-to-insert)
- ))
-
-(defun viper-exec-delete (_m-com _com)
- (or (and (markerp viper-com-point) (marker-position viper-com-point))
- (set-marker viper-com-point (point) (current-buffer)))
- (let (chars-deleted)
- (if viper-use-register
- (progn
- (cond ((viper-valid-register viper-use-register '(letter digit))
- (copy-to-register
- viper-use-register viper-com-point (point) nil))
- ((viper-valid-register viper-use-register '(Letter))
- (viper-append-to-register
- (downcase viper-use-register) viper-com-point (point)))
- (t (setq viper-use-register nil)
- (error viper-InvalidRegister viper-use-register)))
- (setq viper-use-register nil)))
- (setq chars-deleted (abs (- (point) viper-com-point)))
- (if (> chars-deleted viper-change-notification-threshold)
- (unless (viper-is-in-minibuffer)
- (message "Deleted %d characters" chars-deleted)))
- (kill-region viper-com-point (point))
- (setq this-command 'd-command)
- (if viper-ex-style-motion
- (if (and (eolp) (not (bolp))) (backward-char 1)))))
-
-(defun viper-exec-Delete (m-com _com)
- (save-excursion
- (set-mark viper-com-point)
- (viper-enlarge-region (mark t) (point))
- (let (lines-deleted)
- (if viper-use-register
- (progn
- (cond ((viper-valid-register viper-use-register '(letter digit))
- (copy-to-register
- viper-use-register (mark t) (point) nil))
- ((viper-valid-register viper-use-register '(Letter))
- (viper-append-to-register
- (downcase viper-use-register) (mark t) (point)))
- (t (setq viper-use-register nil)
- (error viper-InvalidRegister viper-use-register)))
- (setq viper-use-register nil)))
- (setq lines-deleted (count-lines (point) viper-com-point))
- (if (> lines-deleted viper-change-notification-threshold)
- (unless (viper-is-in-minibuffer)
- (message "Deleted %d lines" lines-deleted)))
- (kill-region (mark t) (point))
- (if (eq m-com 'viper-line) (setq this-command 'D-command)))
- (back-to-indentation)))
-
-;; save region
-(defun viper-exec-yank (_m-com _com)
- (or (and (markerp viper-com-point) (marker-position viper-com-point))
- (set-marker viper-com-point (point) (current-buffer)))
- (let (chars-saved)
- (if viper-use-register
- (progn
- (cond ((viper-valid-register viper-use-register '(letter digit))
- (copy-to-register
- viper-use-register viper-com-point (point) nil))
- ((viper-valid-register viper-use-register '(Letter))
- (viper-append-to-register
- (downcase viper-use-register) viper-com-point (point)))
- (t (setq viper-use-register nil)
- (error viper-InvalidRegister viper-use-register)))
- (setq viper-use-register nil)))
- (setq last-command nil)
- (copy-region-as-kill viper-com-point (point))
- (setq chars-saved (abs (- (point) viper-com-point)))
- (if (> chars-saved viper-change-notification-threshold)
- (unless (viper-is-in-minibuffer)
- (message "Saved %d characters" chars-saved)))
- (goto-char viper-com-point)))
-
-;; save lines
-(defun viper-exec-Yank (_m-com _com)
- (save-excursion
- (set-mark viper-com-point)
- (viper-enlarge-region (mark t) (point))
- (let (lines-saved)
- (if viper-use-register
- (progn
- (cond ((viper-valid-register viper-use-register '(letter digit))
- (copy-to-register
- viper-use-register (mark t) (point) nil))
- ((viper-valid-register viper-use-register '(Letter))
- (viper-append-to-register
- (downcase viper-use-register) (mark t) (point)))
- (t (setq viper-use-register nil)
- (error viper-InvalidRegister viper-use-register)))
- (setq viper-use-register nil)))
- (setq last-command nil)
- (copy-region-as-kill (mark t) (point))
- (setq lines-saved (count-lines (mark t) (point)))
- (if (> lines-saved viper-change-notification-threshold)
- (unless (viper-is-in-minibuffer)
- (message "Saved %d lines" lines-saved)))))
- (deactivate-mark)
- (goto-char viper-com-point))
-
-(defun viper-exec-bang (_m-com com)
- (save-excursion
- (set-mark viper-com-point)
- (viper-enlarge-region (mark t) (point))
- (exchange-point-and-mark)
- (shell-command-on-region
- (mark t) (point)
- (if (viper= com ?!)
- (setq viper-last-shell-com
- (viper-read-string-with-history
- "!"
- nil
- 'viper-shell-history
- (car viper-shell-history)
- ))
- viper-last-shell-com)
- t t)))
-
-(defun viper-exec-equals (_m-com _com)
- (save-excursion
- (set-mark viper-com-point)
- (viper-enlarge-region (mark t) (point))
- (if (> (mark t) (point)) (exchange-point-and-mark))
- (indent-region (mark t) (point) nil)))
-
-(defun viper-exec-shift (_m-com com)
- (save-excursion
- (set-mark viper-com-point)
- (viper-enlarge-region (mark t) (point))
- (if (> (mark t) (point)) (exchange-point-and-mark))
- (indent-rigidly (mark t) (point)
- (if (viper= com ?>)
- viper-shift-width
- (- viper-shift-width))))
- ;; return point to where it was before shift
- (goto-char viper-com-point))
-
-;; this is needed because some commands fake com by setting it to ?r, which
-;; denotes repeated insert command.
-(defsubst viper-exec-dummy (_m-com _com)
- nil)
-
-(defun viper-exec-buffer-search (_m-com _com)
- (setq viper-s-string
- (regexp-quote (buffer-substring (point) viper-com-point)))
- (setq viper-s-forward t)
- (setq viper-search-history (cons viper-s-string viper-search-history))
- (setq viper-intermediate-command 'viper-exec-buffer-search)
- (viper-search viper-s-string viper-s-forward 1))
-
-(defvar viper-exec-array (make-vector 128 nil))
-
-;; Using a dispatch array allows adding functions like buffer search
-;; without affecting other functions. Buffer search can now be bound
-;; to any character.
-
-(aset viper-exec-array ?c #'viper-exec-change)
-(aset viper-exec-array ?C #'viper-exec-Change)
-(aset viper-exec-array ?d #'viper-exec-delete)
-(aset viper-exec-array ?D #'viper-exec-Delete)
-(aset viper-exec-array ?y #'viper-exec-yank)
-(aset viper-exec-array ?Y #'viper-exec-Yank)
-(aset viper-exec-array ?r #'viper-exec-dummy)
-(aset viper-exec-array ?! #'viper-exec-bang)
-(aset viper-exec-array ?< #'viper-exec-shift)
-(aset viper-exec-array ?> #'viper-exec-shift)
-(aset viper-exec-array ?= #'viper-exec-equals)
-
-
-
-;; This function is called by various movement commands to execute a
-;; destructive command on the region specified by the movement command. For
-;; instance, if the user types cw, then the command viper-forward-word will
-;; call viper-execute-com to execute viper-exec-change, which eventually will
-;; call viper-change to invoke the replace mode on the region.
-;;
-;; The var viper-d-com is set to (M-COM VAL COM REG INSERTED-TEXT COMMAND-KEYS)
-;; via a call to viper-set-destructive-command, for later use by viper-repeat.
-(defun viper-execute-com (m-com val com)
- (let ((reg viper-use-register))
- ;; this is the special command `#'
- (if (> com 128)
- (viper-special-prefix-com (- com 128))
- (let ((fn (aref viper-exec-array com)))
- (if (null fn)
- (error "%c: %s" com viper-InvalidViCommand)
- (funcall fn m-com com))))
- (if (viper-dotable-command-p com)
- (viper-set-destructive-command
- (list m-com val com reg nil nil)))
- ))
-
-
-(defun viper-repeat (arg)
- "Re-execute last destructive command.
-Use the info in viper-d-com, which has the form
-\(com val ch reg inserted-text command-keys),
-where `com' is the command to be re-executed, `val' is the
-argument to `com', `ch' is a flag for repeat, and `reg' is optional;
-if it exists, it is the name of the register for `com'.
-If the prefix argument ARG is non-nil, it is used instead of `val'."
- (interactive "P")
- (let ((save-point (point)) ; save point before repeating prev cmd
- ;; Pass along that we are repeating a destructive command
- ;; This tells viper-set-destructive-command not to update
- ;; viper-command-ring
- (viper-intermediate-command 'viper-repeat))
- (if (eq last-command 'viper-undo)
- ;; if the last command was viper-undo, then undo-more
- (viper-undo-more)
- ;; otherwise execute the command stored in viper-d-com. if arg is
- ;; non-nil its prefix value is used as new prefix value for the command.
- (let ((m-com (car viper-d-com))
- (val (viper-P-val arg))
- (com (nth 2 viper-d-com))
- (reg (nth 3 viper-d-com)))
- (if (null val) (setq val (nth 1 viper-d-com)))
- (if (null m-com) (error "No previous command to repeat"))
- (setq viper-use-register reg)
- (if (nth 4 viper-d-com) ; text inserted by command
- (setq viper-last-insertion (nth 4 viper-d-com)
- viper-d-char (nth 4 viper-d-com)))
- (funcall m-com (cons val com))
- (cond ((and (< save-point (point)) viper-keep-point-on-repeat)
- (goto-char save-point)) ; go back to before repeat.
- ((and (< save-point (point)) viper-ex-style-editing)
- (or (bolp) (backward-char 1))))
- (if (and (eolp) (not (bolp)))
- (backward-char 1))
- ))
- (viper-adjust-undo) ; take care of undo
- ;; If the prev cmd was rotating the command ring, this means that `.' has
- ;; just executed a command from that ring. So, push it on the ring again.
- ;; If we are just executing previous command , then don't push viper-d-com
- ;; because viper-d-com is not fully constructed in this case (its keys and
- ;; the inserted text may be nil). Besides, in this case, the command
- ;; executed by `.' is already on the ring.
- (if (eq last-command 'viper-display-current-destructive-command)
- (viper-push-onto-ring viper-d-com 'viper-command-ring))
- (deactivate-mark)
- ))
-
-(defun viper-repeat-from-history ()
- "Repeat a destructive command from history.
-Doesn't change viper-command-ring in any way, so `.' will work as before
-executing this command.
-This command is supposed to be bound to a two-character Vi macro where
-the second character is a digit 0 to 9. The digit indicates which
-history command to execute. `<char>0' is equivalent to `.', `<char>1'
-invokes the command before that, etc."
- (interactive)
- (let* ((viper-intermediate-command 'repeating-display-destructive-command)
- (idx (cond (viper-this-kbd-macro
- (string-to-number
- (symbol-name (elt viper-this-kbd-macro 1))))
- (t 0)))
- (num idx)
- (viper-d-com viper-d-com))
-
- (or (and (numberp num) (<= 0 num) (<= num 9))
- (progn
- (setq idx 0
- num 0)
- (message
- "`viper-repeat-from-history' must be invoked as a Vi macro bound to `<key><digit>'")))
- (while (< 0 num)
- (setq viper-d-com (viper-special-ring-rotate1 viper-command-ring -1))
- (setq num (1- num)))
- (viper-repeat nil)
- (while (> idx num)
- (viper-special-ring-rotate1 viper-command-ring 1)
- (setq num (1+ num)))
- ))
-
-
-;; The hash-command. It is invoked interactively by the key sequence #<char>.
-;; The chars that can follow `#' are determined by viper-hash-command-p
-(defun viper-special-prefix-com (char)
- (cond ((viper= char ?c)
- (downcase-region (min viper-com-point (point))
- (max viper-com-point (point))))
- ((viper= char ?C)
- (upcase-region (min viper-com-point (point))
- (max viper-com-point (point))))
- ((viper= char ?g)
- (push-mark viper-com-point t)
- ;; execute the last emacs kbd macro on each line of the region
- (viper-global-execute))
- ((viper= char ?q)
- (push-mark viper-com-point t)
- (viper-quote-region))
- ((viper= char ?s)
- (funcall viper-spell-function viper-com-point (point)))
- (t (error "#%c: %s" char viper-InvalidViCommand))))
-
-\f
-;; undoing
-
-;; hook used inside undo
-(defvar viper-undo-functions nil)
-
-;; Runs viper-before-change-functions inside before-change-functions
-(defun viper-undo-sentinel (beg end length)
- (run-hook-with-args 'viper-undo-functions beg end length))
-
-(add-hook 'after-change-functions #'viper-undo-sentinel)
-
-;; Hook used in viper-undo
-(defun viper-after-change-undo-hook (beg end _len)
- (if undo-in-progress
- (setq undo-beg-posn beg
- undo-end-posn (or end beg))
- ;; some other hooks may be changing various text properties in
- ;; the buffer in response to 'undo'; so remove this hook to avoid
- ;; its repeated invocation
- (remove-hook 'viper-undo-functions #'viper-after-change-undo-hook 'local)
- ))
-
-(defun viper-undo ()
- "Undo previous change."
- (interactive)
- (message "undo!")
- (let ((before-undo-pt (point-marker))
- undo-beg-posn undo-end-posn)
-
- ;; the viper-after-change-undo-hook removes itself after the 1st invocation
- (add-hook 'viper-undo-functions #'viper-after-change-undo-hook nil 'local)
-
- (undo-start)
- (undo-more 2)
- ;;(setq undo-beg-posn (or undo-beg-posn (point))
- ;; undo-end-posn (or undo-end-posn (point)))
- ;;(setq undo-beg-posn (or undo-beg-posn before-undo-pt)
- ;; undo-end-posn (or undo-end-posn undo-beg-posn))
-
- (if (and undo-beg-posn undo-end-posn)
- (progn
- (goto-char undo-beg-posn)
- (sit-for 0)
- (if (and viper-keep-point-on-undo
- (pos-visible-in-window-p before-undo-pt))
- (progn
- (push-mark (point-marker) t)
- (sit-for 0.3)
- (goto-char undo-end-posn)
- (sit-for 0.3)
- (if (pos-visible-in-window-p undo-beg-posn)
- (goto-char before-undo-pt)
- (goto-char undo-beg-posn)))
- (push-mark before-undo-pt t))
- ))
-
- (if (and (eolp) (not (bolp))) (backward-char 1))
- )
- (setq this-command 'viper-undo))
-
-;; Continue undoing previous changes.
-(defun viper-undo-more ()
- (message "undo more!")
- (condition-case nil
- (undo-more 1)
- (error (beep)
- (message "No further undo information in this buffer")))
- (if (and (eolp) (not (bolp))) (backward-char 1))
- (setq this-command 'viper-undo))
-
-;; The following two functions are used to set up undo properly.
-;; In VI, unlike Emacs, if you open a line, say, and add a bunch of lines,
-;; they are undone all at once.
-(defvar-local viper--undo-change-group-handle nil)
-(put 'viper--undo-change-group-handle 'permanent-local t)
-
-(defun viper-adjust-undo ()
- (when viper--undo-change-group-handle
- (undo-amalgamate-change-group
- (prog1 viper--undo-change-group-handle
- (setq viper--undo-change-group-handle nil)))))
-
-(defun viper-set-complex-command-for-undo ()
- (and (listp buffer-undo-list)
- (not viper--undo-change-group-handle)
- (setq viper--undo-change-group-handle
- (prepare-change-group))))
-
-
-;;; Viper's destructive Command ring utilities
-
-(defun viper-display-current-destructive-command ()
- (let ((text (nth 4 viper-d-com))
- (keys (nth 5 viper-d-com))
- (max-text-len 30))
-
- (setq this-command 'viper-display-current-destructive-command)
-
- (message " `.' runs `%s'%s"
- (viper-array-to-string keys)
- (viper-abbreviate-string
- text max-text-len
- (format-message " inserting `") (format-message "'")
- " ......."))))
-
-
-;; don't change viper-d-com if it was viper-repeat command invoked with `.'
-;; or in some other way (non-interactively).
-(defun viper-set-destructive-command (list)
- (or (eq viper-intermediate-command 'viper-repeat)
- (progn
- (setq viper-d-com list)
- (setcar (nthcdr 5 viper-d-com)
- (viper-array-to-string (if (arrayp viper-this-command-keys)
- viper-this-command-keys
- (this-command-keys))))
- (viper-push-onto-ring viper-d-com 'viper-command-ring)))
- (setq viper-this-command-keys nil))
-
-
-(defun viper-prev-destructive-command (next)
- "Find previous destructive command in the history of destructive commands.
-With prefix argument, find next destructive command."
- (interactive "P")
- (let (cmd viper-intermediate-command)
- (if (eq last-command 'viper-display-current-destructive-command)
- ;; repeated search through command history
- (setq viper-intermediate-command
- 'repeating-display-destructive-command)
- ;; first search through command history--set temp ring
- (setq viper-temp-command-ring (ring-copy viper-command-ring)))
- (setq cmd (if next
- (viper-special-ring-rotate1 viper-temp-command-ring 1)
- (viper-special-ring-rotate1 viper-temp-command-ring -1)))
- (if (null cmd)
- ()
- (setq viper-d-com cmd))
- (viper-display-current-destructive-command)))
-
-
-(defun viper-next-destructive-command ()
- "Find next destructive command in the history of destructive commands."
- (interactive)
- (viper-prev-destructive-command 'next))
-
-
-(defun viper-insert-prev-from-insertion-ring (arg)
- "Cycle through insertion ring in the direction of older insertions.
-Undoes previous insertion and inserts new.
-With prefix argument, cycles in the direction of newer elements.
-In minibuffer, this command executes whatever the invocation key is bound
-to in the global map, instead of cycling through the insertion ring."
- (interactive "P")
- (let (viper-intermediate-command)
- (if (eq last-command 'viper-insert-from-insertion-ring)
- (progn ; repeated search through insertion history
- (setq viper-intermediate-command 'repeating-insertion-from-ring)
- (if (eq viper-current-state 'replace-state)
- (undo 1)
- (if viper-last-inserted-string-from-insertion-ring
- (delete-char
- (- (length viper-last-inserted-string-from-insertion-ring)))))
- )
- ;;first search through insertion history
- (setq viper-temp-insertion-ring (ring-copy viper-insertion-ring)))
- (setq this-command 'viper-insert-from-insertion-ring)
- ;; so that things will be undone properly
- (setq buffer-undo-list (cons nil buffer-undo-list))
- (setq viper-last-inserted-string-from-insertion-ring
- (viper-special-ring-rotate1 viper-temp-insertion-ring (if arg 1 -1)))
-
- ;; this change of viper-intermediate-command must come after
- ;; viper-special-ring-rotate1, so that the ring will rotate, but before the
- ;; insertion.
- (setq viper-intermediate-command nil)
- (if viper-last-inserted-string-from-insertion-ring
- (insert viper-last-inserted-string-from-insertion-ring))
- ))
-
-(defun viper-insert-next-from-insertion-ring ()
- "Cycle through insertion ring in the direction of older insertions.
-Undo previous insertion and inserts new."
- (interactive)
- (viper-insert-prev-from-insertion-ring 'next))
-
-
-\f
-;; some region utilities
-
-;; If at the last line of buffer, add \\n before eob, if newline is missing.
-(defun viper-add-newline-at-eob-if-necessary ()
- (save-excursion
- (end-of-line)
- ;; make sure all lines end with newline, unless in the minibuffer or
- ;; when requested otherwise (require-final-newline is nil)
- (save-restriction
- (widen)
- (if (and (eobp)
- (not (bolp))
- require-final-newline
- ;; add newline only if we actually edited buffer. otherwise it
- ;; might unintentionally modify binary buffers
- (buffer-modified-p)
- (not (viper-is-in-minibuffer))
- (not buffer-read-only))
- ;; text property may be read-only
- (condition-case nil
- (insert "\n")
- (error nil))
- ))
- ))
-
-(defun viper-yank-defun ()
- (mark-defun)
- (copy-region-as-kill (point) (mark t)))
-
-;; Enlarge region between BEG and END.
-(defun viper-enlarge-region (beg end)
- (or beg (setq beg end)) ; if beg is nil, set to end
- (or end (setq end beg)) ; if end is nil, set to beg
-
- (if (< beg end)
- (progn (goto-char beg) (set-mark end))
- (goto-char end)
- (set-mark beg))
- (beginning-of-line)
- (exchange-point-and-mark)
- (if (or (not (eobp)) (not (bolp))) (forward-line 1))
- (if (not (eobp)) (beginning-of-line))
- (if (> beg end) (exchange-point-and-mark)))
-
-
-;; Quote region by each line with a user supplied string.
-(defun viper-quote-region ()
- (let ((quote-str viper-quote-string)
- (do-not-change-default t))
- (setq quote-str
- (viper-read-string-with-history
- "Quote string: "
- nil
- 'viper-quote-region-history
- ;; FIXME: Use comment-region.
- (cond ((string-match "tex.*-mode" (symbol-name major-mode)) "%%")
- ((string-match "java.*-mode" (symbol-name major-mode)) "//")
- ((string-match "perl.*-mode" (symbol-name major-mode)) "#")
- ((string-match "lisp.*-mode" (symbol-name major-mode)) ";;")
- ((memq major-mode '(c-mode cc-mode c++-mode)) "//")
- ((memq major-mode '(sh-mode shell-mode)) "#")
- (t (setq do-not-change-default nil)
- quote-str))))
- (or do-not-change-default
- (setq viper-quote-string quote-str))
- (viper-enlarge-region (point) (mark t))
- (if (> (point) (mark t)) (exchange-point-and-mark))
- (insert quote-str)
- (beginning-of-line)
- (forward-line 1)
- (while (and (< (point) (mark t)) (bolp))
- (insert quote-str)
- (beginning-of-line)
- (forward-line 1))))
-
-;; Tells whether BEG is on the same line as END.
-;; If one of the args is nil, it'll return nil.
-(defun viper-same-line (beg end)
- (let ((selective-display nil)
- (incr 0)
- temp)
- (if (and beg end (> beg end))
- (setq temp beg
- beg end
- end temp))
- (if (and beg end)
- (cond ((or (> beg (point-max)) (> end (point-max))) ; out of range
- nil)
- (t
- ;; This 'if' is needed because Emacs treats the next empty line
- ;; as part of the previous line.
- (if (= (viper-line-pos 'start) end)
- (setq incr 1))
- (<= (+ incr (count-lines beg end)) 1))))
- ))
-
-
-;; Check if the string ends with a newline.
-(defun viper-end-with-a-newline-p (string)
- (or (string= string "")
- (= (viper-seq-last-elt string) ?\n)))
-
-(defun viper-tmp-insert-at-eob (msg)
- (let ((savemax (point-max)))
- (goto-char savemax)
- (insert msg)
- (sit-for 2)
- (goto-char savemax) (delete-region (point) (point-max))
- ))
-
-
-\f
-;;; Minibuffer business
-
-(defsubst viper-set-minibuffer-style ()
- (add-hook 'minibuffer-setup-hook #'viper-minibuffer-setup-sentinel)
- (add-hook 'post-command-hook #'viper-minibuffer-post-command-hook))
-
-
-(defun viper-minibuffer-setup-sentinel ()
- (let ((hook (if viper-vi-style-in-minibuffer
- 'viper-change-state-to-insert
- 'viper-change-state-to-emacs)))
- ;; making buffer-local variables so that normal buffers won't affect the
- ;; minibuffer and vice versa. Otherwise, command arguments will affect
- ;; minibuffer ops and insertions from the minibuffer will change those in
- ;; the normal buffers
- (setq-local viper-d-com nil)
- (setq-local viper-last-insertion nil)
- (setq-local viper-command-ring nil)
- (funcall hook)))
-
-;; This is a temp hook that uses free variables viper--init-message and viper-initial.
-;; A dirty feature, but it is the simplest way to have it do the right thing.
-;; The VIPER--INIT-MESSAGE and VIPER-INITIAL vars come from the scope set by
-;; viper-read-string-with-history
-(defun viper-minibuffer-standard-hook ()
- (if (stringp viper--init-message)
- (viper-tmp-insert-at-eob viper--init-message))
- (when (stringp viper-initial)
- ;; don't wait if we have unread events or in kbd macro
- (or unread-command-events
- executing-kbd-macro
- (sit-for 840))
- (delete-region (minibuffer-prompt-end) (point-max))
- (insert viper-initial)))
-
-(defsubst viper-minibuffer-real-start ()
- (minibuffer-prompt-end))
-
-(defun viper-minibuffer-post-command-hook()
- (when (active-minibuffer-window)
- (when (< (point) (viper-minibuffer-real-start))
- (goto-char (viper-minibuffer-real-start)))))
-
-
-;; Interpret last event in the local map first; if fails, use exit-minibuffer.
-;; Run viper-minibuffer-exit-hook before exiting.
-(defun viper-exit-minibuffer ()
- "Exit minibuffer Viper way."
- (interactive)
- (let (command)
- (setq command (local-key-binding (char-to-string last-command-event)))
- (run-hooks 'viper-minibuffer-exit-hook)
- (if command
- (command-execute command)
- (exit-minibuffer))))
-
-
-(defcustom viper-smart-suffix-list
- '("" "tex" "c" "cc" "C" "java" "el" "html" "htm" "xml"
- "pl" "flr" "P" "p" "h" "H")
- "List of suffixes that Viper tries to append to filenames ending with a `.'.
-This is useful when the current directory contains files with the same
-prefix and many different suffixes. Usually, only one of the suffixes
-represents an editable file. However, file completion will stop at the `.'
-The smart suffix feature lets you hit RET in such a case, and Viper will
-select the appropriate suffix.
-
-Suffixes are tried in the order given and the first suffix for which a
-corresponding file exists is selected. If no file exists for any of the
-suffixes, the user is asked to confirm.
-
-To turn this feature off, set this variable to nil."
- :type '(repeat string)
- :group 'viper-misc)
-
-
-;; Try to add a suitable suffix to files whose name ends with a `.'
-;; Useful when the user hits RET on a non-completed file name.
-;; Used as a minibuffer exit hook in read-file-name
-(defun viper-file-add-suffix ()
- (let ((count 0)
- (len (length viper-smart-suffix-list))
- (file (buffer-substring-no-properties
- (viper-minibuffer-real-start) (point-max)))
- found key cmd suff)
- (goto-char (point-max))
- (if (and viper-smart-suffix-list (string-match "\\.\\'" file))
- (progn
- (while (and (not found) (< count len))
- (setq suff (nth count viper-smart-suffix-list)
- count (1+ count))
- (if (file-exists-p
- (format "%s%s" (substitute-in-file-name file) suff))
- (progn
- (setq found t)
- (insert suff))))
-
- (if found
- ()
- (viper-tmp-insert-at-eob " [Please complete file name]")
-
- (while (not (memq cmd
- '(exit-minibuffer viper-exit-minibuffer)))
- (setq cmd
- (key-binding (setq key (read-key-sequence nil))))
- (cond ((eq cmd 'self-insert-command)
- (insert key))
- ((memq cmd '(exit-minibuffer viper-exit-minibuffer))
- nil)
- (t (command-execute cmd)))))))))
-
-
-(defun viper-minibuffer-trim-tail ()
- "Delete junk at the end of the first line of the minibuffer input.
-Remove this function from `viper-minibuffer-exit-hook', if this causes
-problems."
- (if (viper-is-in-minibuffer)
- (let ((inhibit-field-text-motion t))
- (goto-char (viper-minibuffer-real-start))
- (end-of-line)
- (delete-region (point) (point-max)))))
-
-\f
-;;; Reading string with history
-
-(defun viper-read-string-with-history (prompt &optional initial
- history-var default keymap
- init-message)
- ;; Read string, prompting with PROMPT and inserting the INITIAL
- ;; value. Uses HISTORY-VAR. DEFAULT is the default value to accept if the
- ;; input is an empty string.
- ;; Default value is displayed until the user types something in the
- ;; minibuffer.
- ;; KEYMAP is used, if given, instead of minibuffer-local-map.
- ;; INIT-MESSAGE is the message temporarily displayed after entering the
- ;; minibuffer.
- (let ((viper-initial initial)
- (viper--init-message init-message)
- (minibuffer-setup-hook
- ;; stolen from add-hook
- (let ((old
- (if (boundp 'minibuffer-setup-hook)
- minibuffer-setup-hook
- nil)))
- (cons
- #'viper-minibuffer-standard-hook
- (if (or (not (listp old)) (eq (car old) 'lambda))
- (list old) old))))
- (val "")
- (padding "")
- temp-msg)
-
- (setq keymap (or keymap minibuffer-local-map)
- initial (or initial "")
- viper-initial initial
- temp-msg (if default
- (format "(default %s) " default)
- ""))
-
- (setq viper-incomplete-ex-cmd nil)
- (setq val (read-from-minibuffer prompt
- (concat temp-msg initial val padding)
- keymap nil history-var))
- (setq minibuffer-setup-hook nil
- padding (viper-array-to-string (this-command-keys))
- temp-msg "")
- ;; the following tries to be smart about what to put in history
- (if (not (string= val (car (symbol-value history-var))))
- (push val (symbol-value history-var)))
- (if (or (string= (nth 0 (symbol-value history-var))
- (nth 1 (symbol-value history-var)))
- (string= (nth 0 (symbol-value history-var)) ""))
- (pop (symbol-value history-var)))
- ;; If the user enters nothing but the prev cmd wasn't viper-ex,
- ;; viper-command-argument, or `! shell-command', this probably means
- ;; that the user typed something then erased. Return "" in this case, not
- ;; the default---the default is too confusing in this case.
- (cond ((and (string= val "")
- (not (string= prompt "!")) ; was a `! shell-command'
- (not (memq last-command
- '(viper-ex
- viper-command-argument
- t)
- )))
- "")
- ((string= val "") (or default ""))
- (t val))
- ))
-
-
-\f
-;; insertion commands
-
-;; Called when state changes from Insert Vi command mode.
-;; Repeats the insertion command if Insert state was entered with prefix
-;; argument > 1.
-(defun viper-repeat-insert-command ()
- (let ((i-com (car viper-d-com))
- (val (nth 1 viper-d-com))
- (char (nth 2 viper-d-com)))
- (if (and val (> val 1)) ; first check that val is non-nil
- (progn
- (setq viper-d-com (list i-com (1- val) ?r nil nil nil))
- (viper-repeat nil)
- (setq viper-d-com (list i-com val char nil nil nil))
- ))))
-
-(defun viper-insert (arg)
- "Insert before point."
- (interactive "P")
- (viper-set-complex-command-for-undo)
- (let ((val (viper-p-val arg))
- ;;(com (viper-getcom arg))
- )
- (viper-set-destructive-command (list 'viper-insert val ?r nil nil nil))
- (if (eq viper-intermediate-command 'viper-repeat)
- (viper-loop val (viper-yank-last-insertion))
- (viper-change-state-to-insert))))
-
-(defun viper-append (arg)
- "Append after point."
- (interactive "P")
- (viper-set-complex-command-for-undo)
- (let ((val (viper-p-val arg))
- ;;(com (viper-getcom arg))
- )
- (viper-set-destructive-command (list 'viper-append val ?r nil nil nil))
- (if (not (eolp)) (forward-char))
- (if (eq viper-intermediate-command 'viper-repeat)
- (viper-loop val (viper-yank-last-insertion))
- (viper-change-state-to-insert))))
-
-(defun viper-Append (arg)
- "Append at end of line."
- (interactive "P")
- (viper-set-complex-command-for-undo)
- (let ((val (viper-p-val arg))
- ;;(com (viper-getcom arg))
- )
- (viper-set-destructive-command (list 'viper-Append val ?r nil nil nil))
- (end-of-line)
- (if (eq viper-intermediate-command 'viper-repeat)
- (viper-loop val (viper-yank-last-insertion))
- (viper-change-state-to-insert))))
-
-(defun viper-Insert (arg)
- "Insert before first non-white."
- (interactive "P")
- (viper-set-complex-command-for-undo)
- (let ((val (viper-p-val arg))
- ;;(com (viper-getcom arg))
- )
- (viper-set-destructive-command (list 'viper-Insert val ?r nil nil nil))
- (back-to-indentation)
- (if (eq viper-intermediate-command 'viper-repeat)
- (viper-loop val (viper-yank-last-insertion))
- (viper-change-state-to-insert))))
-
-(defun viper-open-line (arg)
- "Open line below."
- (interactive "P")
- (viper-set-complex-command-for-undo)
- (let ((val (viper-p-val arg))
- ;;(com (viper-getcom arg))
- )
- (viper-set-destructive-command (list 'viper-open-line val ?r nil nil nil))
- (let ((col (current-indentation)))
- (if (eq viper-intermediate-command 'viper-repeat)
- (viper-loop val
- (end-of-line)
- (newline 1)
- (viper-indent-line col)
- (viper-yank-last-insertion))
- (end-of-line)
- (newline 1)
- (viper-indent-line col)
- (viper-change-state-to-insert)))))
-
-(defun viper-Open-line (arg)
- "Open line above."
- (interactive "P")
- (viper-set-complex-command-for-undo)
- (let ((val (viper-p-val arg))
- ;;(com (viper-getcom arg))
- )
- (viper-set-destructive-command (list 'viper-Open-line val ?r nil nil nil))
- (let ((col (current-indentation)))
- (if (eq viper-intermediate-command 'viper-repeat)
- (viper-loop val
- (beginning-of-line)
- (open-line 1)
- (viper-indent-line col)
- (viper-yank-last-insertion))
- (beginning-of-line)
- (open-line 1)
- (viper-indent-line col)
- (viper-change-state-to-insert)))))
-
-(defun viper-open-line-at-point (arg)
- "Open line at point."
- (interactive "P")
- (viper-set-complex-command-for-undo)
- (let ((val (viper-p-val arg))
- ;;(com (viper-getcom arg))
- )
- (viper-set-destructive-command
- (list 'viper-open-line-at-point val ?r nil nil nil))
- (if (eq viper-intermediate-command 'viper-repeat)
- (viper-loop val
- (open-line 1)
- (viper-yank-last-insertion))
- (open-line 1)
- (viper-change-state-to-insert))))
-
-;; bound to s
-(defun viper-substitute (arg)
- "Substitute characters."
- (interactive "P")
- (let ((val (viper-p-val arg))
- ;;(com (viper-getcom arg))
- )
- (push-mark nil t)
- (forward-char val)
- (if (eq viper-intermediate-command 'viper-repeat)
- (viper-change-subr (mark t) (point))
- (viper-change (mark t) (point)))
- ;; com is set to ?r when we repeat this command with dot
- (viper-set-destructive-command (list 'viper-substitute val ?r nil nil nil))
- ))
-
-;; Command bound to S
-(defun viper-substitute-line (arg)
- "Substitute lines."
- (interactive "p")
- (viper-set-complex-command-for-undo)
- (viper-line (cons arg ?C)))
-
-;; Prepare for replace
-(defun viper-start-replace ()
- (setq viper-began-as-replace t
- viper-sitting-in-replace t
- viper-replace-chars-to-delete 0)
- (add-hook
- 'viper-after-change-functions #'viper-replace-mode-spy-after t 'local)
- (add-hook
- 'viper-before-change-functions #'viper-replace-mode-spy-before t 'local)
- ;; this will get added repeatedly, but no harm
- (add-hook 'after-change-functions #'viper-after-change-sentinel t)
- (add-hook 'before-change-functions #'viper-before-change-sentinel t)
- (viper-move-marker-locally
- 'viper-last-posn-in-replace-region (viper-replace-start))
- (add-hook
- 'viper-post-command-hooks #'viper-replace-state-post-command-sentinel
- t 'local)
- (add-hook
- 'viper-pre-command-hooks #'viper-replace-state-pre-command-sentinel t 'local)
- ;; guard against a smarty who switched from R-replace to normal replace
- (remove-hook
- 'viper-post-command-hooks #'viper-R-state-post-command-sentinel 'local)
- (if overwrite-mode (overwrite-mode -1))
- )
-
-
-(defun viper-replace-mode-spy-before (beg end)
- (setq viper-replace-region-chars-deleted (viper-chars-in-region beg end))
- )
-
-;; Invoked as an after-change-function to calculate how many chars have to be
-;; deleted. This function may be called several times within a single command,
-;; if this command performs several separate buffer changes. Therefore, if
-;; adds up the number of chars inserted and subtracts the number of chars
-;; deleted.
-(defun viper-replace-mode-spy-after (beg end length)
- (if (memq viper-intermediate-command
- '(dabbrev-expand repeating-insertion-from-ring))
- ;; Take special care of text insertion from insertion ring inside
- ;; replacement overlays.
- (progn
- (setq viper-replace-chars-to-delete 0)
- (viper-move-marker-locally
- 'viper-last-posn-in-replace-region (point)))
-
- (let* ((real-end (min end (viper-replace-end)))
- (column-shift (- (save-excursion (goto-char real-end)
- (current-column))
- (save-excursion (goto-char beg)
- (current-column))))
- (chars-deleted 0))
-
- (if (> length 0)
- (setq chars-deleted viper-replace-region-chars-deleted))
- (setq viper-replace-region-chars-deleted 0)
- (setq viper-replace-chars-to-delete
- (+ viper-replace-chars-to-delete
- (-
- ;; if column shift is bigger, due to a TAB insertion, take
- ;; column-shift instead of the number of inserted chars
- (max (viper-chars-in-region beg real-end)
- ;; This test accounts for Chinese/Japanese/... chars,
- ;; which occupy 2 columns instead of one. If we use
- ;; column-shift here, we may delete two chars instead of
- ;; one when the user types one Chinese character.
- ;; Deleting two would be OK, if they were European chars,
- ;; but it is not OK if they are Chinese chars.
- ;; Since it is hard to
- ;; figure out which characters are being deleted in any
- ;; given region, we decided to treat Eastern and European
- ;; characters equally, even though Eastern chars may
- ;; occupy more columns.
- (if (memq this-command '(self-insert-command
- quoted-insert viper-insert-tab))
- column-shift
- 0))
- ;; the number of deleted chars
- chars-deleted)))
-
- (viper-move-marker-locally
- 'viper-last-posn-in-replace-region
- (max (if (> end (viper-replace-end)) (viper-replace-end) end)
- (or (marker-position viper-last-posn-in-replace-region)
- (viper-replace-start))
- ))
-
- )))
-
-
-;; Delete stuff between viper-last-posn-in-replace-region and the end of
-;; viper-replace-overlay-marker, if viper-last-posn-in-replace-region is within
-;; the overlay and current point is before the end of the overlay.
-;; Don't delete anything if current point is past the end of the overlay.
-(defun viper-finish-change ()
- (remove-hook
- 'viper-after-change-functions #'viper-replace-mode-spy-after 'local)
- (remove-hook
- 'viper-before-change-functions #'viper-replace-mode-spy-before 'local)
- (remove-hook
- 'viper-post-command-hooks #'viper-replace-state-post-command-sentinel 'local)
- (remove-hook
- 'viper-pre-command-hooks #'viper-replace-state-pre-command-sentinel 'local)
- (viper-restore-cursor-color 'after-replace-mode)
- (setq viper-sitting-in-replace nil) ; just in case we'll need to know it
- (save-excursion
- (if (and viper-replace-overlay
- (viper-pos-within-region viper-last-posn-in-replace-region
- (viper-replace-start)
- (viper-replace-end))
- (< (point) (viper-replace-end)))
- (delete-region
- viper-last-posn-in-replace-region (viper-replace-end))))
-
- (if (eq viper-current-state 'replace-state)
- (viper-downgrade-to-insert))
- ;; replace mode ended => nullify viper-last-posn-in-replace-region
- (viper-move-marker-locally 'viper-last-posn-in-replace-region nil)
- (viper-hide-replace-overlay)
- (viper-refresh-mode-line)
- (viper-put-string-on-kill-ring viper-last-replace-region)
- )
-
-;; Make STRING be the first element of the kill ring.
-(defun viper-put-string-on-kill-ring (string)
- (setq kill-ring (cons string kill-ring))
- (if (> (length kill-ring) kill-ring-max)
- (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
- (setq kill-ring-yank-pointer kill-ring))
-
-(defun viper-finish-R-mode ()
- (remove-hook
- 'viper-post-command-hooks #'viper-R-state-post-command-sentinel 'local)
- (remove-hook
- 'viper-pre-command-hooks #'viper-replace-state-pre-command-sentinel 'local)
- (viper-downgrade-to-insert))
-
-(defun viper-start-R-mode ()
- (overwrite-mode 1)
- (add-hook
- 'viper-post-command-hooks #'viper-R-state-post-command-sentinel t 'local)
- (add-hook
- 'viper-pre-command-hooks #'viper-replace-state-pre-command-sentinel t 'local)
- ;; guard against a smarty who switched from R-replace to normal replace
- (remove-hook
- 'viper-post-command-hooks #'viper-replace-state-post-command-sentinel 'local)
- )
-
-
-
-(defun viper-replace-state-exit-cmd ()
- "Binding for keys that cause Replace state to switch to Vi or to Insert.
-These keys are ESC, RET, and LineFeed."
- (interactive)
- (if overwrite-mode ; if in replace mode invoked via 'R'
- (viper-finish-R-mode)
- (viper-finish-change))
- (let (com)
- (if (eq this-command 'viper-intercept-ESC-key)
- (setq com 'viper-exit-insert-state)
- (viper-set-unread-command-events last-input-event)
- (setq com (key-binding (read-key-sequence nil))))
-
- (condition-case conds
- (command-execute com)
- (error
- (viper-message-conditions conds)))
- )
- (viper-hide-replace-overlay))
-
-
-(defun viper-replace-state-carriage-return ()
- "Carriage return in Viper replace state."
- (interactive)
- ;; If Emacs start supporting overlay maps, as it currently supports
- ;; text-property maps, we could do away with viper-replace-minor-mode and
- ;; just have keymap attached to replace overlay. Then the "if part" of this
- ;; statement can be deleted.
- (if (or (< (point) (viper-replace-start))
- (> (point) (viper-replace-end)))
- (let (viper-replace-minor-mode com)
- (viper-set-unread-command-events last-input-event)
- (setq com (key-binding (read-key-sequence nil)))
- (condition-case conds
- (command-execute com)
- (error
- (viper-message-conditions conds))))
- (if (not viper-allow-multiline-replace-regions)
- (viper-replace-state-exit-cmd)
- (if (viper-same-line (point) (viper-replace-end))
- (viper-replace-state-exit-cmd)
- ;; delete the rest of line
- (delete-region (point) (viper-line-pos 'end))
- (save-excursion
- (end-of-line)
- (if (eobp) (error "Last line in buffer")))
- ;; skip to the next line
- (forward-line 1)
- (back-to-indentation)
- ))))
-
-
-;; This is the function bound to 'R'---unlimited replace.
-;; Similar to Emacs's own overwrite-mode.
-(defun viper-overwrite (arg)
- "Begin overwrite mode."
- (interactive "P")
- (let ((val (viper-p-val arg))
- ;;(com (viper-getcom arg))
- (len))
- (viper-set-destructive-command (list 'viper-overwrite val ?r nil nil nil))
- (if (eq viper-intermediate-command 'viper-repeat)
- (progn
- ;; Viper saves inserted text in viper-last-insertion
- (setq len (length viper-last-insertion))
- (delete-char (min len (- (point-max) (point) 1)))
- (viper-loop val (viper-yank-last-insertion)))
- (setq last-command 'viper-overwrite)
- (viper-set-complex-command-for-undo)
- (viper-set-replace-overlay (point) (viper-line-pos 'end))
- (viper-change-state-to-replace)
- )))
-
-\f
-;; line commands
-
-(defun viper-line (arg)
- (let ((val (car arg))
- (com (cdr arg)))
- (viper-move-marker-locally 'viper-com-point (point))
- (if (not (eobp))
- (viper-next-line-carefully (1- val)))
- ;; the following ensures that dd, cc, D, yy will do the right thing on the
- ;; last line of buffer when this line has no \n.
- (viper-add-newline-at-eob-if-necessary)
- (viper-execute-com 'viper-line val com))
- (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
- )
-
-(defun viper-yank-line (arg)
- "Yank ARG lines (in Vi's sense)."
- (interactive "P")
- (let ((val (viper-p-val arg)))
- (viper-line (cons val ?Y))))
-
-\f
-;; region commands
-
-(defun viper-region (arg)
- "Execute command on a region."
- (interactive "P")
- (let ((val (viper-P-val arg))
- (com (viper-getcom arg)))
- (viper-move-marker-locally 'viper-com-point (point))
- (exchange-point-and-mark)
- (viper-execute-com 'viper-region val com)))
-
-(defun viper-Region (arg)
- "Execute command on a Region."
- (interactive "P")
- (let ((val (viper-P-val arg))
- (com (viper-getCom arg)))
- (viper-move-marker-locally 'viper-com-point (point))
- (exchange-point-and-mark)
- (viper-execute-com 'viper-Region val com)))
-
-(defun viper-replace-char (arg)
- "Replace the following ARG chars by the character read."
- (interactive "P")
- (if (and (eolp) (bolp)) (error "No character to replace here"))
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg)))
- (viper-replace-char-subr com val)
- (if (and (eolp) (not (bolp))) (forward-char 1))
- (setq viper-this-command-keys
- (format "%sr" (if (integerp arg) arg "")))
- (viper-set-destructive-command
- (list 'viper-replace-char val ?r nil viper-d-char nil))
- ))
-
-(defun viper-replace-char-subr (com arg)
- (let ((inhibit-quit t)
- char)
- (viper-set-complex-command-for-undo)
- (or (eq viper-intermediate-command 'viper-repeat)
- (viper-special-read-and-insert-char))
-
- (delete-char 1 t)
- (setq char (if com viper-d-char (viper-char-at-pos 'backward)))
-
- (if com (insert char))
-
- (setq viper-d-char char)
-
- (viper-loop (1- (if (> arg 0) arg (- arg)))
- (delete-char 1 t)
- (insert char))
-
- (viper-adjust-undo)
- (backward-char arg)
- ))
-
-\f
-;; basic cursor movement. j, k, l, h commands.
-
-(defun viper-forward-char (arg)
- "Move point right ARG characters (left if ARG negative).
-On reaching end of line, stop and signal error."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (if viper-ex-style-motion
- (progn
- ;; the boundary condition check gets weird here because
- ;; forward-char may be the parameter of a delete, and 'dl' works
- ;; just like 'x' for the last char on a line, so we have to allow
- ;; the forward motion before the 'viper-execute-com', but, of
- ;; course, 'dl' doesn't work on an empty line, so we have to
- ;; catch that condition before 'viper-execute-com'
- (if (and (eolp) (bolp)) (user-error viper-ViperBell) (forward-char val))
- (if com (viper-execute-com 'viper-forward-char val com))
- (if (eolp) (progn (backward-char 1) (user-error viper-ViperBell))))
- (forward-char val)
- (if com (viper-execute-com 'viper-forward-char val com)))))
-
-
-(defun viper-backward-char (arg)
- "Move point left ARG characters (right if ARG negative).
-On reaching beginning of line, stop and signal error."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (if viper-ex-style-motion
- (progn
- (if (bolp) (user-error viper-ViperBell) (backward-char val))
- (if com (viper-execute-com 'viper-backward-char val com)))
- (backward-char val)
- (if com (viper-execute-com 'viper-backward-char val com)))))
-
-
-;; Like forward-char, but doesn't move at end of buffer.
-;; Returns distance traveled
-;; (positive or 0, if arg positive; negative if arg negative).
-(defun viper-forward-char-carefully (&optional arg)
- (setq arg (or arg 1))
- (let ((pt (point)))
- (condition-case nil
- (forward-char arg)
- (error nil))
- (if (< (point) pt) ; arg was negative
- (- (viper-chars-in-region pt (point)))
- (viper-chars-in-region pt (point)))))
-
-
-;; Like backward-char, but doesn't move at beg of buffer.
-;; Returns distance traveled
-;; (negative or 0, if arg positive; positive if arg negative).
-(defun viper-backward-char-carefully (&optional arg)
- (setq arg (or arg 1))
- (let ((pt (point)))
- (condition-case nil
- (backward-char arg)
- (error nil))
- (if (> (point) pt) ; arg was negative
- (viper-chars-in-region pt (point))
- (- (viper-chars-in-region pt (point))))))
-
-(defun viper-next-line-carefully (arg)
- (condition-case nil
- ;; do not use forward-line! need to keep column
- (let ((line-move-visual nil))
- (with-no-warnings
- (next-line arg)))
- (error nil)))
-
-
-\f
-;;; Word command
-
-;; Words are formed from alpha's and nonalphas - <sp>,\t\n are separators for
-;; word movement. When executed with a destructive command, \n is usually left
-;; untouched for the last word. Viper uses syntax table to determine what is a
-;; word and what is a separator. However, \n is always a separator. Also, if
-;; viper-syntax-preference is 'vi, then `_' is part of the word.
-
-;; skip only one \n
-(defun viper-skip-separators (forward)
- (if forward
- (progn
- (viper-skip-all-separators-forward 'within-line)
- (if (looking-at "\n")
- (progn
- (forward-char)
- (viper-skip-all-separators-forward 'within-line))))
- ;; check for eob and white space before it. move off of eob
- (if (and (eobp) (save-excursion
- (viper-backward-char-carefully)
- (viper-looking-at-separator)))
- (viper-backward-char-carefully))
- (viper-skip-all-separators-backward 'within-line)
- (viper-backward-char-carefully)
- (if (looking-at "\n")
- (viper-skip-all-separators-backward 'within-line)
- (or (viper-looking-at-separator) (forward-char)))))
-
-
-(defun viper-forward-word-kernel (val)
- (while (> val 0)
- (cond ((viper-looking-at-alpha)
- (viper-skip-alpha-forward "_")
- (viper-skip-separators t))
- ((viper-looking-at-separator)
- (viper-skip-separators t))
- ((not (viper-looking-at-alphasep))
- (viper-skip-nonalphasep-forward)
- (viper-skip-separators t)))
- (setq val (1- val))))
-
-;; first skip non-newline separators backward, then skip \n. Then, if TWICE is
-;; non-nil, skip non-\n back again, but don't overshoot the limit LIM.
-(defun viper-separator-skipback-special (twice lim)
- (let ((prev-char (viper-char-at-pos 'backward))
- (saved-point (point)))
- ;; skip non-newline separators backward
- (while (and (not (memq prev-char '(nil \n)))
- (< lim (point))
- ;; must be non-newline separator
- (if (eq viper-syntax-preference 'strict-vi)
- (memq prev-char '(?\ ?\t))
- (memq (char-syntax prev-char) '(?\ ?-))))
- (viper-backward-char-carefully)
- (setq prev-char (viper-char-at-pos 'backward)))
-
- (if (and (< lim (point)) (eq prev-char ?\n))
- (backward-char)
- ;; If we skipped to the next word and the prefix of this line doesn't
- ;; consist of separators preceded by a newline, then don't skip backwards
- ;; at all.
- (goto-char saved-point))
- (setq prev-char (viper-char-at-pos 'backward))
-
- ;; skip again, but make sure we don't overshoot the limit
- (if twice
- (while (and (not (memq prev-char '(nil \n)))
- (< lim (point))
- ;; must be non-newline separator
- (if (eq viper-syntax-preference 'strict-vi)
- (memq prev-char '(?\ ?\t))
- (memq (char-syntax prev-char) '(?\ ?-))))
- (viper-backward-char-carefully)
- (setq prev-char (viper-char-at-pos 'backward))))
-
- (if (= (point) lim)
- (viper-forward-char-carefully))
- ))
-
-
-(defun viper-forward-word (arg)
- "Forward word."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (viper-forward-word-kernel val)
- (if com
- (progn
- (cond ((eq com ?c)
- (viper-separator-skipback-special 'twice viper-com-point))
- ;; Yank words including the whitespace, but not newline
- ((eq com ?y)
- (viper-separator-skipback-special nil viper-com-point))
- ((viper-dotable-command-p com)
- (viper-separator-skipback-special nil viper-com-point)))
- (viper-execute-com 'viper-forward-word val com)))
- ))
-
-
-(defun viper-forward-Word (arg)
- "Forward word delimited by white characters."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (viper-loop val
- (viper-skip-nonseparators 'forward)
- (viper-skip-separators t))
- (if com (progn
- (cond ((eq com ?c)
- (viper-separator-skipback-special 'twice viper-com-point))
- ;; Yank words including the whitespace, but not newline
- ((eq com ?y)
- (viper-separator-skipback-special nil viper-com-point))
- ((viper-dotable-command-p com)
- (viper-separator-skipback-special nil viper-com-point)))
- (viper-execute-com 'viper-forward-Word val com)))))
-
-
-;; this is a bit different from Vi, but Vi's end of word
-;; makes no sense whatsoever
-(defun viper-end-of-word-kernel ()
- (if (viper-end-of-word-p) (forward-char))
- (if (viper-looking-at-separator)
- (viper-skip-all-separators-forward))
-
- (cond ((viper-looking-at-alpha) (viper-skip-alpha-forward "_"))
- ((not (viper-looking-at-alphasep)) (viper-skip-nonalphasep-forward)))
- (viper-backward-char-carefully))
-
-(defun viper-end-of-word-p ()
- (or (eobp)
- (save-excursion
- (cond ((viper-looking-at-alpha)
- (forward-char)
- (not (viper-looking-at-alpha)))
- ((not (viper-looking-at-alphasep))
- (forward-char)
- (viper-looking-at-alphasep))))))
-
-
-(defun viper-end-of-word (arg &optional _careful)
- "Move point to end of current word."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (viper-loop val (viper-end-of-word-kernel))
- (if com
- (progn
- (forward-char)
- (viper-execute-com 'viper-end-of-word val com)))))
-
-(defun viper-end-of-Word (arg)
- "Forward to end of word delimited by white character."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (viper-loop val
- (viper-end-of-word-kernel)
- (viper-skip-nonseparators 'forward)
- (backward-char))
- (if com
- (progn
- (forward-char)
- (viper-execute-com 'viper-end-of-Word val com)))))
-
-(defun viper-backward-word-kernel (val)
- (while (> val 0)
- (viper-backward-char-carefully)
- (cond ((viper-looking-at-alpha)
- (viper-skip-alpha-backward "_"))
- ((viper-looking-at-separator)
- (forward-char)
- (viper-skip-separators nil)
- (viper-backward-char-carefully)
- (cond ((viper-looking-at-alpha)
- (viper-skip-alpha-backward "_"))
- ((not (viper-looking-at-alphasep))
- (viper-skip-nonalphasep-backward))
- ((bobp)) ; could still be at separator, but at beg of buffer
- (t (forward-char))))
- ((not (viper-looking-at-alphasep))
- (viper-skip-nonalphasep-backward)))
- (setq val (1- val))))
-
-(defun viper-backward-word (arg)
- "Backward word."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg)))
- (if com
- (let (i)
- (if (setq i (save-excursion (backward-char) (looking-at "\n")))
- (backward-char))
- (viper-move-marker-locally 'viper-com-point (point))
- (if i (forward-char))))
- (viper-backward-word-kernel val)
- (if com (viper-execute-com 'viper-backward-word val com))))
-
-(defun viper-backward-Word (arg)
- "Backward word delimited by white character."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg)))
- (if com
- (let (i)
- (if (setq i (save-excursion (backward-char) (looking-at "\n")))
- (backward-char))
- (viper-move-marker-locally 'viper-com-point (point))
- (if i (forward-char))))
- (viper-loop val
- (viper-skip-separators nil) ; nil means backward here
- (viper-skip-nonseparators 'backward))
- (if com (viper-execute-com 'viper-backward-Word val com))))
-
-
-\f
-;; line commands
-
-(defun viper-beginning-of-line (arg)
- "Go to beginning of line."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (beginning-of-line val)
- (if com (viper-execute-com 'viper-beginning-of-line val com))))
-
-(defun viper-bol-and-skip-white (arg)
- "Beginning of line at first non-white character."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (forward-to-indentation (1- val))
- (if com (viper-execute-com 'viper-bol-and-skip-white val com))))
-
-(defun viper-goto-eol (arg)
- "Go to end of line."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (end-of-line val)
- (if com (viper-execute-com 'viper-goto-eol val com))
- (if viper-ex-style-motion
- (if (and (eolp) (not (bolp))
- ;; a fix for viper-change-to-eol
- (not (equal viper-current-state 'insert-state)))
- (backward-char 1)
- ))))
-
-
-(defun viper-goto-col (arg)
- "Go to ARG's column."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg))
- line-len)
- (setq line-len
- (viper-chars-in-region
- (viper-line-pos 'start) (viper-line-pos 'end)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (beginning-of-line)
- (forward-char (1- (min line-len val)))
- (while (> (current-column) (1- val))
- (backward-char 1))
- (if com (viper-execute-com 'viper-goto-col val com))
- (save-excursion
- (end-of-line)
- (if (> val (current-column)) (user-error viper-ViperBell)))
- ))
-
-
-(defun viper-next-line (arg)
- "Go to next line."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getCom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- ;; do not use forward-line! need to keep column
- (let ((line-move-visual nil))
- (with-no-warnings
- (next-line val)))
- (if viper-ex-style-motion
- (if (and (eolp) (not (bolp))) (backward-char 1)))
- (setq this-command 'next-line)
- (if com (viper-execute-com 'viper-next-line val com))))
-
-(declare-function widget-type "wid-edit" (widget))
-(declare-function widget-button-press "wid-edit" (pos &optional event))
-(declare-function viper-set-hooks "viper" ())
-
-(defun viper-next-line-at-bol (arg)
- "Next line at beginning of line.
-If point is on a widget or a button, simulate clicking on that widget/button."
- (interactive "P")
- (let* ((field (get-char-property (point) 'field))
- (button (get-char-property (point) 'button))
- (doc (get-char-property (point) 'widget-doc))
- (widget (or field button doc)))
- (if (and widget
- (if (symbolp widget)
- (get widget 'widget-type)
- (and (consp widget)
- (get (widget-type widget) 'widget-type))))
- (widget-button-press (point))
- (if (button-at (point))
- (push-button)
- ;; not a widget or a button
- (save-excursion
- (end-of-line)
- (if (eobp) (error "Last line in buffer")))
- (let ((val (viper-p-val arg))
- (com (viper-getCom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (forward-line val)
- (back-to-indentation)
- (if com (viper-execute-com 'viper-next-line-at-bol val com)))))))
-
-
-(defun viper-previous-line (arg)
- "Go to previous line."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getCom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- ;; do not use forward-line! need to keep column
- (let ((line-move-visual nil))
- (with-no-warnings
- (previous-line val)))
- (if viper-ex-style-motion
- (if (and (eolp) (not (bolp))) (backward-char 1)))
- (setq this-command 'previous-line)
- (if com (viper-execute-com 'viper-previous-line val com))))
-
-
-(defun viper-previous-line-at-bol (arg)
- "Previous line at beginning of line."
- (interactive "P")
- (save-excursion
- (beginning-of-line)
- (if (bobp) (error "First line in buffer")))
- (let ((val (viper-p-val arg))
- (com (viper-getCom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (forward-line (- val))
- (back-to-indentation)
- (if com (viper-execute-com 'viper-previous-line val com))))
-
-(defun viper-change-to-eol (arg)
- "Change to end of line."
- (interactive "P")
- (viper-goto-eol (cons arg ?c)))
-
-(defun viper-kill-line (arg)
- "Delete line."
- (interactive "P")
- (viper-goto-eol (cons arg ?d)))
-
-(defun viper-erase-line (arg)
- "Erase line."
- (interactive "P")
- (viper-beginning-of-line (cons arg ?d)))
-
-\f
-;;; Moving around
-
-(defun viper-goto-line (arg)
- "Go to ARG's line. Without ARG go to end of buffer."
- (interactive "P")
- (let ((val (viper-P-val arg))
- (com (viper-getCom arg)))
- (viper-move-marker-locally 'viper-com-point (point))
- (deactivate-mark)
- (push-mark nil t)
- (if (null val)
- (goto-char (point-max))
- (goto-char (point-min))
- (forward-line (1- val)))
-
- ;; positioning is done twice: before and after command execution
- (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
- (back-to-indentation)
-
- (if com (viper-execute-com 'viper-goto-line val com))
-
- (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
- (back-to-indentation)
- ))
-
-;; Find ARG's occurrence of CHAR on the current line.
-;; If FORWARD then search is forward, otherwise backward. OFFSET is used to
-;; adjust point after search.
-(defun viper-find-char (arg char forward offset)
- (or (char-or-string-p char) (user-error viper-ViperBell))
- (let ((arg (if forward arg (- arg)))
- (cmd (if (eq viper-intermediate-command 'viper-repeat)
- (nth 5 viper-d-com)
- (viper-array-to-string (this-command-keys))))
- point region-beg region-end)
- (save-excursion
- (save-restriction
- (if (> arg 0) ; forward
- (progn
- (setq region-beg (point))
- (if viper-allow-multiline-replace-regions
- (viper-forward-paragraph 1)
- (end-of-line))
- (setq region-end (point)))
- (setq region-end (point))
- (if viper-allow-multiline-replace-regions
- (viper-backward-paragraph 1)
- (beginning-of-line))
- (setq region-beg (point)))
- (if (or (and (< arg 0)
- (< (- region-end region-beg)
- (if viper-allow-multiline-replace-regions
- 2 1))
- (bolp))
- (and (> arg 0)
- (< (- region-end region-beg)
- (if viper-allow-multiline-replace-regions
- 3 2))
- (eolp)))
- (error "Command `%s': At %s of %s"
- cmd
- (if (> arg 0) "end" "beginning")
- (if viper-allow-multiline-replace-regions
- "paragraph" "line")))
- (narrow-to-region region-beg region-end)
- ;; if arg > 0, point is forwarded before search.
- (if (> arg 0) (goto-char (1+ (point-min)))
- (goto-char (point-max)))
- (if (let ((case-fold-search nil))
- (search-forward (char-to-string char) nil 0 arg))
- (setq point (point))
- (error "Command `%s': `%c' not found" cmd char))))
- (goto-char point)
- (if (> arg 0)
- (backward-char (if offset 2 1))
- (forward-char (if offset 1 0)))))
-
-(defun viper-find-char-forward (arg)
- "Find char on the line.
-If called interactively read the char to find from the terminal, and if
-called from viper-repeat, the char last used is used. This behavior is
-controlled by the sign of prefix numeric value."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg))
- (cmd-representation (nth 5 viper-d-com)))
- (if (> val 0)
- ;; this means that the function was called interactively
- (setq viper-f-char (read-char)
- viper-f-forward t
- viper-f-offset nil)
- ;; viper-repeat --- set viper-F-char from command-keys
- (setq viper-F-char (if (stringp cmd-representation)
- (viper-seq-last-elt cmd-representation)
- viper-F-char)
- viper-f-char viper-F-char)
- (setq val (- val)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (viper-find-char
- val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) t nil)
- (setq val (- val))
- (if com
- (progn
- (setq viper-F-char viper-f-char) ; set new viper-F-char
- (forward-char)
- (viper-execute-com 'viper-find-char-forward val com)))))
-
-(defun viper-goto-char-forward (arg)
- "Go up to char ARG forward on line."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg))
- (cmd-representation (nth 5 viper-d-com)))
- (if (> val 0)
- ;; this means that the function was called interactively
- (setq viper-f-char (read-char)
- viper-f-forward t
- viper-f-offset t)
- ;; viper-repeat --- set viper-F-char from command-keys
- (setq viper-F-char (if (stringp cmd-representation)
- (viper-seq-last-elt cmd-representation)
- viper-F-char)
- viper-f-char viper-F-char)
- (setq val (- val)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (viper-find-char
- val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) t t)
- (setq val (- val))
- (if com
- (progn
- (setq viper-F-char viper-f-char) ; set new viper-F-char
- (forward-char)
- (viper-execute-com 'viper-goto-char-forward val com)))))
-
-(defun viper-find-char-backward (arg)
- "Find char ARG on line backward."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg))
- (cmd-representation (nth 5 viper-d-com)))
- (if (> val 0)
- ;; this means that the function was called interactively
- (setq viper-f-char (read-char)
- viper-f-forward nil
- viper-f-offset nil)
- ;; viper-repeat --- set viper-F-char from command-keys
- (setq viper-F-char (if (stringp cmd-representation)
- (viper-seq-last-elt cmd-representation)
- viper-F-char)
- viper-f-char viper-F-char)
- (setq val (- val)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (viper-find-char
- val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) nil nil)
- (setq val (- val))
- (if com
- (progn
- (setq viper-F-char viper-f-char) ; set new viper-F-char
- (viper-execute-com 'viper-find-char-backward val com)))))
-
-(defun viper-goto-char-backward (arg)
- "Go up to char ARG backward on line."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg))
- (cmd-representation (nth 5 viper-d-com)))
- (if (> val 0)
- ;; this means that the function was called interactively
- (setq viper-f-char (read-char)
- viper-f-forward nil
- viper-f-offset t)
- ;; viper-repeat --- set viper-F-char from command-keys
- (setq viper-F-char (if (stringp cmd-representation)
- (viper-seq-last-elt cmd-representation)
- viper-F-char)
- viper-f-char viper-F-char)
- (setq val (- val)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (viper-find-char
- val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) nil t)
- (setq val (- val))
- (if com
- (progn
- (setq viper-F-char viper-f-char) ; set new viper-F-char
- (viper-execute-com 'viper-goto-char-backward val com)))))
-
-(defun viper-repeat-find (arg)
- "Repeat previous find command."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg)))
- (deactivate-mark)
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (viper-find-char val viper-f-char viper-f-forward viper-f-offset)
- (if com
- (progn
- (if viper-f-forward (forward-char))
- (viper-execute-com 'viper-repeat-find val com)))))
-
-(defun viper-repeat-find-opposite (arg)
- "Repeat previous find command in the opposite direction."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg)))
- (deactivate-mark)
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (viper-find-char val viper-f-char (not viper-f-forward) viper-f-offset)
- (if com
- (progn
- (if viper-f-forward (forward-char))
- (viper-execute-com 'viper-repeat-find-opposite val com)))))
-
-\f
-;; window scrolling etc.
-
-(defun viper-window-top (arg)
- "Go to home window line."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getCom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (push-mark nil t)
- (move-to-window-line (1- val))
-
- ;; positioning is done twice: before and after command execution
- (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
- (back-to-indentation)
-
- (if com (viper-execute-com 'viper-window-top val com))
-
- (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
- (back-to-indentation)
- ))
-
-(defun viper-window-middle (arg)
- "Go to middle window line."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getCom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (push-mark nil t)
- (move-to-window-line (+ (/ (1- (window-height)) 2) (1- val)))
-
- ;; positioning is done twice: before and after command execution
- (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
- (back-to-indentation)
-
- (if com (viper-execute-com 'viper-window-middle val com))
-
- (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
- (back-to-indentation)
- ))
-
-(defun viper-window-bottom (arg)
- "Go to last window line."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getCom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (push-mark nil t)
- (move-to-window-line (- val))
-
- ;; positioning is done twice: before and after command execution
- (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
- (back-to-indentation)
-
- (if com (viper-execute-com 'viper-window-bottom val com))
-
- (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
- (back-to-indentation)
- ))
-
-(defun viper-line-to-top (arg)
- "Put current line on the home line."
- (interactive "p")
- (recenter (1- arg)))
-
-(defun viper-line-to-middle (arg)
- "Put current line on the middle line."
- (interactive "p")
- (recenter (+ (1- arg) (/ (1- (window-height)) 2))))
-
-(defun viper-line-to-bottom (arg)
- "Put current line on the last line."
- (interactive "p")
- (recenter (- (window-height) (1+ arg))))
-
-;; If point is within viper-search-scroll-threshold of window top or bottom,
-;; scroll up or down 1/7 of window height, depending on whether we are at the
-;; bottom or at the top of the window. This function is called by viper-search
-;; (which is called from viper-search-forward/backward/next). If the value of
-;; viper-search-scroll-threshold is negative - don't scroll.
-(defun viper-adjust-window ()
- (let ((win-height (1- (window-height))) ; adjust for mode line
- (pt (point))
- at-top-p at-bottom-p
- min-scroll direction)
- (save-excursion
- (move-to-window-line 0) ; top
- (setq at-top-p
- (<= (count-lines pt (point))
- viper-search-scroll-threshold))
- (move-to-window-line -1) ; bottom
- (setq at-bottom-p
- (<= (count-lines pt (point)) viper-search-scroll-threshold)))
- (cond (at-top-p (setq min-scroll (1- viper-search-scroll-threshold)
- direction 1))
- (at-bottom-p (setq min-scroll (1+ viper-search-scroll-threshold)
- direction -1)))
- (if min-scroll
- (recenter
- (* (max min-scroll (/ win-height 7)) direction)))
- ))
-
-\f
-;; paren match
-;; must correct this to only match ( to ) etc. On the other hand
-;; it is good that paren match gets confused, because that way you
-;; catch _all_ imbalances.
-
-(defun viper-paren-match (arg)
- "Go to the matching parenthesis."
- (interactive "P")
- (let ((com (viper-getcom arg))
- (parse-sexp-ignore-comments viper-parse-sexp-ignore-comments)
- anchor-point)
- (if (integerp arg)
- (if (or (> arg 99) (< arg 1))
- (error "Prefix must be between 1 and 99")
- (goto-char
- (if (> (point-max) 80000)
- (* (/ (point-max) 100) arg)
- (/ (* (point-max) arg) 100)))
- (back-to-indentation))
- (let (beg-lim end-lim)
- (if (and (eolp) (not (bolp))) (forward-char -1))
- (if (not (looking-at "[][(){}]"))
- (setq anchor-point (point)))
- (setq beg-lim (line-beginning-position)
- end-lim (line-end-position))
- (cond ((re-search-forward "[][(){}]" end-lim t)
- (backward-char) )
- ((re-search-backward "[][(){}]" beg-lim t))
- (t
- (error "No matching character on line"))))
- (cond ((looking-at "[([{]")
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (forward-sexp 1)
- (if com
- (viper-execute-com 'viper-paren-match nil com)
- (backward-char)))
- (anchor-point
- (if com
- (progn
- (viper-move-marker-locally 'viper-com-point anchor-point)
- (forward-char 1)
- (viper-execute-com 'viper-paren-match nil com)
- )))
- ((looking-at "[])}]")
- (forward-char)
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (backward-sexp 1)
- (if com (viper-execute-com 'viper-paren-match nil com)))
- (t (user-error viper-ViperBell))))))
-
-(defun viper-toggle-parse-sexp-ignore-comments ()
- (interactive)
- (setq viper-parse-sexp-ignore-comments
- (not viper-parse-sexp-ignore-comments))
- (princ (format-message
- "From now on, `%%' will %signore parentheses inside comment fields"
- (if viper-parse-sexp-ignore-comments "" "NOT "))))
-
-\f
-;; sentence, paragraph and heading
-
-(defun viper-forward-sentence (arg)
- "Forward sentence."
- (interactive "P")
- (or (eq last-command this-command)
- (push-mark nil t))
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (forward-sentence val)
- (if com (viper-execute-com 'viper-forward-sentence nil com))))
-
-(defun viper-backward-sentence (arg)
- "Backward sentence."
- (interactive "P")
- (or (eq last-command this-command)
- (push-mark nil t))
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (backward-sentence val)
- (if com (viper-execute-com 'viper-backward-sentence nil com))))
-
-(defun viper-forward-paragraph (arg)
- "Forward paragraph."
- (interactive "P")
- (or (eq last-command this-command)
- (push-mark nil t))
- (let ((val (viper-p-val arg))
- ;; if you want d} operate on whole lines, change viper-getcom to
- ;; viper-getCom below
- (com (viper-getcom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (forward-paragraph val)
- (if com
- (progn
- (backward-char 1)
- (viper-execute-com 'viper-forward-paragraph nil com)))))
-
-(defun viper-backward-paragraph (arg)
- "Backward paragraph."
- (interactive "P")
- (or (eq last-command this-command)
- (push-mark nil t))
- (let ((val (viper-p-val arg))
- ;; if you want d{ operate on whole lines, change viper-getcom to
- ;; viper-getCom below
- (com (viper-getcom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (backward-paragraph val)
- (if com
- (progn
- (forward-char 1)
- (viper-execute-com 'viper-backward-paragraph nil com)
- (backward-char 1)))))
-
-;; should be mode-specific
-(defun viper-prev-heading (arg)
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getCom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (re-search-backward viper-heading-start nil t val)
- (goto-char (match-beginning 0))
- (if com (viper-execute-com 'viper-prev-heading nil com))))
-
-(defun viper-heading-end (arg)
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getCom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (re-search-forward viper-heading-end nil t val)
- (goto-char (match-beginning 0))
- (if com (viper-execute-com 'viper-heading-end nil com))))
-
-(defun viper-next-heading (arg)
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getCom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (end-of-line)
- (re-search-forward viper-heading-start nil t val)
- (goto-char (match-beginning 0))
- (if com (viper-execute-com 'viper-next-heading nil com))))
-
-\f
-;; scrolling
-
-(defun viper-scroll-screen (arg)
- "Scroll to next screen."
- (interactive "p")
- (condition-case nil
- (if (> arg 0)
- (while (> arg 0)
- (scroll-up)
- (setq arg (1- arg)))
- (while (> 0 arg)
- (scroll-down)
- (setq arg (1+ arg))))
- (error (beep 1)
- (if (> arg 0)
- (progn
- (message "End of buffer")
- (goto-char (point-max)))
- (message "Beginning of buffer")
- (goto-char (point-min))))
- ))
-
-(defun viper-scroll-screen-back (arg)
- "Scroll to previous screen."
- (interactive "p")
- (viper-scroll-screen (- arg)))
-
-(defun viper-scroll-down (arg)
- "Pull down half screen."
- (interactive "P")
- (condition-case nil
- (if (null arg)
- (scroll-down (/ (window-height) 2))
- (scroll-down arg))
- (error (beep 1)
- (message "Beginning of buffer")
- (goto-char (point-min)))))
-
-(defun viper-scroll-down-one (arg)
- "Scroll up one line."
- (interactive "p")
- (scroll-down arg))
-
-(defun viper-scroll-up (arg)
- "Pull up half screen."
- (interactive "P")
- (condition-case nil
- (if (null arg)
- (scroll-up (/ (window-height) 2))
- (scroll-up arg))
- (error (beep 1)
- (message "End of buffer")
- (goto-char (point-max)))))
-
-(defun viper-scroll-up-one (arg)
- "Scroll down one line."
- (interactive "p")
- (scroll-up arg))
-
-\f
-;; searching
-
-(defun viper-insert-isearch-string ()
- "Insert `isearch' last search string."
- (interactive)
- (when isearch-string (insert isearch-string)))
-
-(defun viper-if-string (prompt)
- (if (memq viper-intermediate-command
- '(viper-command-argument viper-digit-argument viper-repeat))
- (setq viper-this-command-keys (this-command-keys)))
- (let* ((keymap (let ((keymap (copy-keymap minibuffer-local-map)))
- (define-key keymap [(control ?s)]
- #'viper-insert-isearch-string)
- keymap))
- (s (viper-read-string-with-history
- prompt
- nil ; no initial
- 'viper-search-history
- (car viper-search-history)
- keymap)))
- (if (not (string= s ""))
- (setq viper-s-string s))))
-
-
-(defun viper-toggle-search-style (arg)
- "Toggle the value of viper-case-fold-search/viper-re-search.
-Without prefix argument, will ask which search style to toggle. With prefix
-arg 1, toggles viper-case-fold-search; with arg 2 toggles viper-re-search.
-
-Although this function is bound to \\[viper-toggle-search-style], the most
-convenient way to use it is to bind `//' to the macro
-`1 M-x viper-toggle-search-style' and `///' to
-`2 M-x viper-toggle-search-style'. In this way, hitting `//' quickly will
-toggle case-fold-search and hitting `/' three times with toggle regexp
-search. Macros are more convenient in this case because they don't affect
-the Emacs binding of `/'."
- (interactive "P")
- (let (msg)
- (cond ((or (eq arg 1)
- (and (null arg)
- (y-or-n-p (format-message
- "Search style: `%s'. Want `%s'? "
- (if viper-case-fold-search
- "case-insensitive" "case-sensitive")
- (if viper-case-fold-search
- "case-sensitive"
- "case-insensitive")))))
- (setq viper-case-fold-search (null viper-case-fold-search))
- (if viper-case-fold-search
- (setq msg "Search becomes case-insensitive")
- (setq msg "Search becomes case-sensitive")))
- ((or (eq arg 2)
- (and (null arg)
- (y-or-n-p (format-message
- "Search style: `%s'. Want `%s'? "
- (if viper-re-search
- "regexp-search" "vanilla-search")
- (if viper-re-search
- "vanilla-search"
- "regexp-search")))))
- (setq viper-re-search (null viper-re-search))
- (if viper-re-search
- (setq msg "Search becomes regexp-style")
- (setq msg "Search becomes vanilla-style")))
- (t
- (setq msg "Search style remains unchanged")))
- (princ msg t)))
-
-(defun viper-set-searchstyle-toggling-macros (unset &optional mode)
- "Set the macros for toggling the search style in Viper's vi-state.
-The macro that toggles case sensitivity is bound to `//', and the one that
-toggles regexp search is bound to `///'.
-With a prefix argument, this function unsets the macros.
-If MODE is set, set the macros only in that major mode."
- (interactive "P")
- (let ((scope (if (and mode (symbolp mode)) mode t)))
- (or noninteractive
- (if (not unset)
- (progn
- ;; toggle case sensitivity in search
- (viper-record-kbd-macro
- "//" 'vi-state
- [1 (meta x) v i p e r - t o g g l e - s e a r c h - s t y l e return]
- scope)
- ;; toggle regexp/vanilla search
- (viper-record-kbd-macro
- "///" 'vi-state
- [2 (meta x) v i p e r - t o g g l e - s e a r c h - s t y l e return]
- scope)
- (if (called-interactively-p 'interactive)
- (message
- "// and /// now toggle case-sensitivity and regexp search")))
- (viper-unrecord-kbd-macro "//" 'vi-state)
- (sit-for 2)
- (viper-unrecord-kbd-macro "///" 'vi-state)))
- ))
-
-
-(defun viper-set-parsing-style-toggling-macro (unset)
- "Set or unset `%%%' as a macro that toggles comment parsing for parentheses.
-This is used in conjunction with the `%' command.
-By default, sets the macro which will toggle whether comment fields should
-be parsed for matching parentheses. With a prefix argument, unsets the
-macro instead."
- (interactive "P")
- (or noninteractive
- (if (not unset)
- (progn
- ;; Make %%% toggle parsing comments for matching parentheses
- (viper-record-kbd-macro
- "%%%" 'vi-state
- [(meta x) v i p e r - t o g g l e - p a r s e - s e x p - i g n o r e - c o m m e n t s return]
- 't)
- (if (called-interactively-p 'interactive)
- (message
- "%%%%%% now toggles whether comments should be parsed for matching parentheses")))
- (viper-unrecord-kbd-macro "%%%" 'vi-state))))
-
-
-(defun viper-set-emacs-state-searchstyle-macros (unset &optional arg-majormode)
- "Set the macros for toggling the search style in Viper's emacs-state.
-The macro that toggles case sensitivity is bound to `//', and the one that
-toggles regexp search is bound to `///'.
-With a prefix argument, this function unsets the macros.
-If the optional prefix argument is non-nil and specifies a valid major mode,
-this sets the macros only in the macros in that major mode. Otherwise,
-the macros are set in the current major mode.
-\(When unsetting the macros, the second argument has no effect.)"
- (interactive "P")
- (or noninteractive
- (if (not unset)
- (progn
- ;; toggle case sensitivity in search
- (viper-record-kbd-macro
- "//" 'emacs-state
- [1 (meta x) v i p e r - t o g g l e - s e a r c h - s t y l e return]
- (or arg-majormode major-mode))
- ;; toggle regexp/vanilla search
- (viper-record-kbd-macro
- "///" 'emacs-state
- [2 (meta x) v i p e r - t o g g l e - s e a r c h - s t y l e return]
- (or arg-majormode major-mode))
- (if (called-interactively-p 'interactive)
- (message
- "// and /// now toggle case-sensitivity and regexp search.")))
- (viper-unrecord-kbd-macro "//" 'emacs-state)
- (sit-for 2)
- (viper-unrecord-kbd-macro "///" 'emacs-state))))
-
-
-(defun viper-search-forward (arg)
- "Search a string forward.
-ARG is used to find the ARG's occurrence of the string.
-Null string will repeat previous search."
- (interactive "P")
- (let ((val (viper-P-val arg))
- (com (viper-getcom arg))
- (old-str viper-s-string)
- debug-on-error)
- (setq viper-s-forward t)
- (viper-if-string "/")
- ;; this is not used at present, but may be used later
- (if (or (not (equal old-str viper-s-string))
- (not (markerp viper-local-search-start-marker))
- (not (marker-buffer viper-local-search-start-marker)))
- (setq viper-local-search-start-marker (point-marker)))
- (viper-search viper-s-string t val)
- (if com
- (progn
- (viper-move-marker-locally 'viper-com-point (mark t))
- (viper-execute-com 'viper-search-next val com)))
- ))
-
-(defun viper-search-backward (arg)
- "Search a string backward.
-ARG is used to find the ARG's occurrence of the string.
-Null string will repeat previous search."
- (interactive "P")
- (let ((val (viper-P-val arg))
- (com (viper-getcom arg))
- (old-str viper-s-string)
- debug-on-error)
- (setq viper-s-forward nil)
- (viper-if-string "?")
- ;; this is not used at present, but may be used later
- (if (or (not (equal old-str viper-s-string))
- (not (markerp viper-local-search-start-marker))
- (not (marker-buffer viper-local-search-start-marker)))
- (setq viper-local-search-start-marker (point-marker)))
- (viper-search viper-s-string nil val)
- (if com
- (progn
- (viper-move-marker-locally 'viper-com-point (mark t))
- (viper-execute-com 'viper-search-next val com)))))
-
-
-;; Search for COUNT's occurrence of STRING.
-;; Search is forward if FORWARD is non-nil, otherwise backward.
-;; INIT-POINT is the position where search is to start.
-;; Arguments:
-;; (STRING FORW COUNT &optional NO-OFFSET INIT-POINT LIMIT FAIL-IF-NOT-FOUND)
-(defun viper-search (string forward arg
- &optional no-offset init-point fail-if-not-found)
- (if (not (equal string ""))
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg))
- (offset (not no-offset))
- (case-fold-search viper-case-fold-search)
- (start-point (or init-point (point))))
- (deactivate-mark)
- (if forward
- (condition-case nil
- (progn
- (if offset (viper-forward-char-carefully))
- (if viper-re-search
- (progn
- (re-search-forward string nil nil val)
- (re-search-backward string))
- (search-forward string nil nil val)
- (search-backward string))
- (if (not (equal start-point (point)))
- (push-mark start-point t)))
- (search-failed
- (if (and (not fail-if-not-found) viper-search-wrap-around)
- (progn
- (message "Search wrapped around BOTTOM of buffer")
- (goto-char (point-min))
- (viper-search string forward (cons 1 com) t start-point 'fail)
- ;; don't wait in macros
- (or executing-kbd-macro
- (memq viper-intermediate-command
- '(viper-repeat
- viper-digit-argument
- viper-command-argument))
- (sit-for 2))
- ;; delete the wrap-around message
- (message "")
- )
- (goto-char start-point)
- (error "`%s': %s not found"
- string
- (if viper-re-search "Pattern" "String"))
- )))
- ;; backward
- (condition-case nil
- (progn
- (if viper-re-search
- (re-search-backward string nil nil val)
- (search-backward string nil nil val))
- (if (not (equal start-point (point)))
- (push-mark start-point t)))
- (search-failed
- (if (and (not fail-if-not-found) viper-search-wrap-around)
- (progn
- (message "Search wrapped around TOP of buffer")
- (goto-char (point-max))
- (viper-search string forward (cons 1 com) t start-point 'fail)
- ;; don't wait in macros
- (or executing-kbd-macro
- (memq viper-intermediate-command
- '(viper-repeat
- viper-digit-argument
- viper-command-argument))
- (sit-for 2))
- ;; delete the wrap-around message
- (message "")
- )
- (goto-char start-point)
- (error "`%s': %s not found"
- string
- (if viper-re-search "Pattern" "String"))
- ))))
- ;; pull up or down if at top/bottom of window
- (viper-adjust-window)
- ;; highlight the result of search
- ;; don't wait and don't highlight in macros
- (or executing-kbd-macro
- (memq viper-intermediate-command
- '(viper-repeat viper-digit-argument viper-command-argument))
- (viper-flash-search-pattern))
- )))
-
-(defun viper-search-next (arg)
- "Repeat previous search."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg))
- debug-on-error)
- (if (or (null viper-s-string) (string= viper-s-string ""))
- (error viper-NoPrevSearch))
- (viper-search viper-s-string viper-s-forward arg)
- (if com
- (progn
- (viper-move-marker-locally 'viper-com-point (mark t))
- (viper-execute-com 'viper-search-next val com)))))
-
-(defun viper-search-Next (arg)
- "Repeat previous search in the reverse direction."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (com (viper-getcom arg))
- debug-on-error)
- (if (null viper-s-string) (error viper-NoPrevSearch))
- (viper-search viper-s-string (not viper-s-forward) arg)
- (if com
- (progn
- (viper-move-marker-locally 'viper-com-point (mark t))
- (viper-execute-com 'viper-search-Next val com)))))
-
-
-;; Search contents of buffer defined by one of Viper's motion commands.
-;; Repeatable via `n' and `N'.
-(defun viper-buffer-search-enable (&optional c)
- (cond (c (setq viper-buffer-search-char c))
- ((null viper-buffer-search-char)
- ;; ?g acts as a default value for viper-buffer-search-char
- (setq viper-buffer-search-char ?g)))
- (define-key viper-vi-basic-map
- (cond ((characterp viper-buffer-search-char)
- (char-to-string viper-buffer-search-char))
- (t (error "viper-buffer-search-char: Wrong value type, %S"
- viper-buffer-search-char)))
- #'viper-command-argument)
- (aset viper-exec-array viper-buffer-search-char #'viper-exec-buffer-search)
- (setq viper-prefix-commands
- (cons viper-buffer-search-char viper-prefix-commands)))
-
-;; This is a Viper wrapper for isearch-forward.
-(defun viper-isearch-forward (arg)
- "Do incremental search forward."
- (interactive "P")
- ;; emacs bug workaround
- (if (listp arg) (setq arg (car arg)))
- (viper-exec-form-in-emacs (list 'isearch-forward arg)))
-
-;; This is a Viper wrapper for isearch-backward."
-(defun viper-isearch-backward (arg)
- "Do incremental search backward."
- (interactive "P")
- ;; emacs bug workaround
- (if (listp arg) (setq arg (car arg)))
- (viper-exec-form-in-emacs (list 'isearch-backward arg)))
-
-\f
-;; visiting and killing files, buffers
-
-(defun viper-switch-to-buffer ()
- "Switch to buffer in the current window."
- (interactive)
- (let ((other-buffer (other-buffer (current-buffer)))
- buffer)
- (setq buffer
- (funcall viper-read-buffer-function
- "Switch to buffer in this window: " other-buffer))
- (switch-to-buffer buffer)))
-
-(defun viper-switch-to-buffer-other-window ()
- "Switch to buffer in another window."
- (interactive)
- (let ((other-buffer (other-buffer (current-buffer)))
- buffer)
- (setq buffer
- (funcall viper-read-buffer-function
- "Switch to buffer in another window: " other-buffer))
- (switch-to-buffer-other-window buffer)))
-
-(defun viper-kill-buffer ()
- "Kill a buffer."
- (interactive)
- (let (buffer buffer-name)
- (setq buffer-name
- (funcall viper-read-buffer-function
- (format "Kill buffer (%s): "
- (buffer-name (current-buffer)))))
- (setq buffer
- (if (null buffer-name)
- (current-buffer)
- (get-buffer buffer-name)))
- (if (null buffer) (error "`%s': No such buffer" buffer-name))
- (if (or (not (buffer-modified-p buffer))
- (y-or-n-p
- (format-message
- "Buffer `%s' is modified, are you sure you want to kill it? "
- buffer-name)))
- (kill-buffer buffer)
- (error "Buffer not killed"))))
-
-
-\f
-;; yank and pop
-
-(defsubst viper-yank (text)
- "Yank TEXT silently. This works correctly with Emacs's `yank-pop' command."
- (insert text)
- (setq this-command 'yank))
-
-(defun viper-put-back (arg)
- "Put back after point/below line."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (text (if viper-use-register
- (cond ((viper-valid-register viper-use-register '(digit))
- (current-kill
- (- viper-use-register ?1) 'do-not-rotate))
- ((viper-valid-register viper-use-register)
- (get-register (downcase viper-use-register)))
- (t (error viper-InvalidRegister viper-use-register)))
- (current-kill 0)))
- sv-point chars-inserted lines-inserted)
- (if (null text)
- (if viper-use-register
- (let ((reg viper-use-register))
- (setq viper-use-register nil)
- (error viper-EmptyRegister reg))
- (user-error viper-ViperBell)))
- (setq viper-use-register nil)
- (if (viper-end-with-a-newline-p text)
- (progn
- (end-of-line)
- (if (eobp)
- (insert "\n")
- (forward-line 1))
- (beginning-of-line))
- (if (not (eolp)) (viper-forward-char-carefully)))
- (set-marker (mark-marker) (point) (current-buffer))
- (viper-set-destructive-command
- (list 'viper-put-back val nil viper-use-register nil nil))
- (setq sv-point (point))
- (viper-loop val (viper-yank text))
- (setq chars-inserted (abs (- (point) sv-point))
- lines-inserted (abs (count-lines (point) sv-point)))
- (if (or (> chars-inserted viper-change-notification-threshold)
- (> lines-inserted viper-change-notification-threshold))
- (unless (viper-is-in-minibuffer)
- (message "Inserted %d character(s), %d line(s)"
- chars-inserted lines-inserted))))
- ;; Vi puts cursor on the last char when the yanked text doesn't contain a
- ;; newline; it leaves the cursor at the beginning when the text contains
- ;; a newline
- (if (viper-same-line (point) (mark))
- (or (= (point) (mark)) (viper-backward-char-carefully))
- (exchange-point-and-mark)
- (if (bolp)
- (back-to-indentation)))
- (deactivate-mark))
-
-(defun viper-Put-back (arg)
- "Put back at point/above line."
- (interactive "P")
- (let ((val (viper-p-val arg))
- (text (if viper-use-register
- (cond ((viper-valid-register viper-use-register '(digit))
- (current-kill
- (- viper-use-register ?1) 'do-not-rotate))
- ((viper-valid-register viper-use-register)
- (get-register (downcase viper-use-register)))
- (t (error viper-InvalidRegister viper-use-register)))
- (current-kill 0)))
- sv-point chars-inserted lines-inserted)
- (if (null text)
- (if viper-use-register
- (let ((reg viper-use-register))
- (setq viper-use-register nil)
- (error viper-EmptyRegister reg))
- (user-error viper-ViperBell)))
- (setq viper-use-register nil)
- (if (viper-end-with-a-newline-p text) (beginning-of-line))
- (viper-set-destructive-command
- (list 'viper-Put-back val nil viper-use-register nil nil))
- (set-marker (mark-marker) (point) (current-buffer))
- (setq sv-point (point))
- (viper-loop val (viper-yank text))
- (setq chars-inserted (abs (- (point) sv-point))
- lines-inserted (abs (count-lines (point) sv-point)))
- (if (or (> chars-inserted viper-change-notification-threshold)
- (> lines-inserted viper-change-notification-threshold))
- (unless (viper-is-in-minibuffer)
- (message "Inserted %d character(s), %d line(s)"
- chars-inserted lines-inserted))))
- ;; Vi puts cursor on the last char when the yanked text doesn't contain a
- ;; newline; it leaves the cursor at the beginning when the text contains
- ;; a newline
- (if (viper-same-line (point) (mark))
- (or (= (point) (mark)) (viper-backward-char-carefully))
- (exchange-point-and-mark)
- (if (bolp)
- (back-to-indentation)))
- (deactivate-mark))
-
-
-;; Copy region to kill-ring.
-;; If BEG and END do not belong to the same buffer, copy empty region.
-(defun viper-copy-region-as-kill (beg end)
- (condition-case nil
- (copy-region-as-kill beg end)
- (error (copy-region-as-kill beg beg))))
-
-
-(defun viper-delete-char (arg)
- "Delete next character."
- (interactive "P")
- (let ((val (viper-p-val arg))
- end-del-pos)
- (viper-set-destructive-command
- (list 'viper-delete-char val nil nil nil nil))
- (if (and viper-ex-style-editing
- (> val (viper-chars-in-region (point) (viper-line-pos 'end))))
- (setq val (viper-chars-in-region (point) (viper-line-pos 'end))))
- (if (and viper-ex-style-motion (eolp))
- (if (bolp) (user-error viper-ViperBell) (setq val 0))) ; not bol---simply back 1 ch
- (save-excursion
- (viper-forward-char-carefully val)
- (setq end-del-pos (point)))
- (if viper-use-register
- (progn
- (cond ((viper-valid-register viper-use-register '((Letter)))
- (viper-append-to-register
- (downcase viper-use-register) (point) end-del-pos))
- ((viper-valid-register viper-use-register)
- (copy-to-register
- viper-use-register (point) end-del-pos nil))
- (t (error viper-InvalidRegister viper-use-register)))
- (setq viper-use-register nil)))
-
- (delete-char val t)
- (if viper-ex-style-motion
- (if (and (eolp) (not (bolp))) (backward-char 1)))
- ))
-
-(defun viper-delete-backward-char (arg)
- "Delete previous character. On reaching beginning of line, stop and beep."
- (interactive "P")
- (let ((val (viper-p-val arg))
- end-del-pos)
- (viper-set-destructive-command
- (list 'viper-delete-backward-char val nil nil nil nil))
- (if (and
- viper-ex-style-editing
- (> val (viper-chars-in-region (viper-line-pos 'start) (point))))
- (setq val (viper-chars-in-region (viper-line-pos 'start) (point))))
- (save-excursion
- (viper-backward-char-carefully val)
- (setq end-del-pos (point)))
- (if viper-use-register
- (progn
- (cond ((viper-valid-register viper-use-register '(Letter))
- (viper-append-to-register
- (downcase viper-use-register) end-del-pos (point)))
- ((viper-valid-register viper-use-register)
- (copy-to-register
- viper-use-register end-del-pos (point) nil))
- (t (error viper-InvalidRegister viper-use-register)))
- (setq viper-use-register nil)))
- (if (and (bolp) viper-ex-style-editing)
- (ding))
- (delete-char (- val) t)))
-
-
-(defun viper-del-backward-char-in-insert ()
- "Delete 1 char backwards while in insert mode."
- (interactive)
- (if (and viper-ex-style-editing (bolp))
- (beep 1)
- ;; don't put on kill ring
- (delete-char -1 nil)))
-
-
-(defun viper-del-backward-char-in-replace ()
- "Delete one character in replace mode.
-If `viper-delete-backwards-in-replace' is t, then DEL key actually deletes
-characters. If it is nil, then the cursor just moves backwards, similarly
-to Vi. The variable `viper-ex-style-editing', if t, doesn't let the
-cursor move past the beginning of line."
- (interactive)
- (cond (viper-delete-backwards-in-replace
- (cond ((not (bolp))
- ;; don't put on kill ring
- (delete-char -1 nil))
- (viper-ex-style-editing
- (beep 1))
- ((bobp)
- (beep 1))
- (t
- ;; don't put on kill ring
- (delete-char -1 nil))))
- (viper-ex-style-editing
- (if (bolp)
- (beep 1)
- (backward-char 1)))
- (t
- (backward-char 1))))
-
-(defun viper-del-forward-char-in-insert ()
- "Delete 1 char forward if in insert or replace state."
- (interactive)
- ;; don't put on kill ring
- (delete-char 1 nil))
-
-\f
-;; join lines.
-
-(defun viper-join-lines (arg)
- "Join this line to next, if ARG is nil. Otherwise, join ARG lines."
- (interactive "*P")
- (let ((val (viper-P-val arg)))
- (viper-set-destructive-command
- (list 'viper-join-lines val nil nil nil nil))
- (viper-loop (if (null val) 1 (1- val))
- (end-of-line)
- (if (not (eobp))
- (progn
- (forward-line 1)
- (delete-region (point) (1- (point)))
- (fixup-whitespace)
- ;; fixup-whitespace sometimes does not leave space
- ;; between objects, so we insert it as in Vi
- (or (looking-at " ")
- (insert " ")
- (backward-char 1))
- )))))
-
-\f
-;; Replace state
-
-(defun viper-change (beg end)
- (if (markerp beg) (setq beg (marker-position beg)))
- (if (markerp end) (setq end (marker-position end)))
- ;; beg is sometimes (mark t), which may be nil
- (or beg (setq beg end))
-
- (viper-set-complex-command-for-undo)
- (if viper-use-register
- (progn
- (copy-to-register viper-use-register beg end nil)
- (setq viper-use-register nil)))
- (viper-set-replace-overlay beg end)
- (setq last-command nil) ; separate repl text from prev kills
-
- (if (= (viper-replace-start) (point-max))
- (error "End of buffer"))
-
- (setq viper-last-replace-region
- (buffer-substring (viper-replace-start)
- (viper-replace-end)))
-
- ;; protect against error while inserting "@" and other disasters
- ;; (e.g., read-only buff)
- (condition-case conds
- (if (or viper-allow-multiline-replace-regions
- (viper-same-line (viper-replace-start)
- (viper-replace-end)))
- (progn
- ;; tabs cause problems in replace, so untabify
- (goto-char (viper-replace-end))
- (insert-before-markers "@") ; put placeholder after the TAB
- (untabify (viper-replace-start) (point))
- ;; del @, don't put on kill ring
- (delete-char -1)
-
- (viper-set-replace-overlay-glyphs
- viper-replace-region-start-delimiter
- viper-replace-region-end-delimiter)
- ;; this move takes care of the last posn in the overlay, which
- ;; has to be shifted because of insert. We can't simply insert
- ;; "$" before-markers because then overlay-start will shift the
- ;; beginning of the overlay in case we are replacing a single
- ;; character. This fixes the bug with `s' and `cl' commands.
- (viper-move-replace-overlay (viper-replace-start) (point))
- (goto-char (viper-replace-start))
- (viper-change-state-to-replace t))
- (kill-region (viper-replace-start)
- (viper-replace-end))
- (viper-hide-replace-overlay)
- (viper-change-state-to-insert))
- (error ;; make sure that the overlay doesn't stay.
- ;; go back to the original point
- (goto-char (viper-replace-start))
- (viper-hide-replace-overlay)
- (viper-message-conditions conds))))
-
-
-(defun viper-change-subr (beg end)
- ;; beg is sometimes (mark t), which may be nil
- (or beg (setq beg end))
- (if viper-use-register
- (progn
- (copy-to-register viper-use-register beg end nil)
- (setq viper-use-register nil)))
- (kill-region beg end)
- (setq this-command 'viper-change)
- (viper-yank-last-insertion))
-
-(defun viper-toggle-case (arg)
- "Toggle character case."
- (interactive "P")
- (let ((val (viper-p-val arg)) (c))
- (viper-set-destructive-command
- (list 'viper-toggle-case val nil nil nil nil))
- (while (> val 0)
- (setq c (following-char))
- (delete-char 1 nil)
- (if (eq c (upcase c))
- (insert-char (downcase c) 1)
- (insert-char (upcase c) 1))
- (if (eolp) (backward-char 1))
- (setq val (1- val)))))
-
-\f
-;; query replace
-
-(defun viper-query-replace ()
- "Query replace.
-If a null string is supplied as the string to be replaced,
-the query replace mode will toggle between string replace
-and regexp replace.
-
-As each match is found, the user must type a character saying
-what to do with it. Type SPC or `y' to replace the match,
-DEL or `n' to skip and go to the next match. For more directions,
-type \\[help-command] at that time."
- (interactive)
- (let (str)
- (setq str (viper-read-string-with-history
- (if viper-re-query-replace "Query replace regexp: "
- "Query replace: ")
- nil ; no initial
- 'viper-replace1-history
- (car viper-replace1-history) ; default
- ))
- (if (string= str "")
- (progn
- (setq viper-re-query-replace (not viper-re-query-replace))
- (message "Query replace mode changed to %s"
- (if viper-re-query-replace "regexp replace"
- "string replace")))
- (if viper-re-query-replace
- (query-replace-regexp
- str
- (viper-read-string-with-history
- (format-message "Query replace regexp `%s' with: " str)
- nil ; no initial
- 'viper-replace1-history
- (car viper-replace1-history) ; default
- ))
- (query-replace
- str
- (viper-read-string-with-history
- (format-message "Query replace `%s' with: " str)
- nil ; no initial
- 'viper-replace1-history
- (car viper-replace1-history) ; default
- ))))))
-
-\f
-;; marking
-
-(defun viper-mark-beginning-of-buffer ()
- "Mark beginning of buffer."
- (interactive)
- (push-mark)
- (goto-char (point-min))
- (exchange-point-and-mark)
- (message "Mark set at the beginning of buffer"))
-
-(defun viper-mark-end-of-buffer ()
- "Mark end of buffer."
- (interactive)
- (push-mark)
- (goto-char (point-max))
- (exchange-point-and-mark)
- (message "Mark set at the end of buffer"))
-
-(defun viper-mark-point ()
- "Set mark at point of buffer."
- (interactive)
- (let ((char (read-char)))
- (cond ((and (<= ?a char) (<= char ?z))
- (point-to-register (1+ (- char ?a))))
- ((viper= char ?<) (viper-mark-beginning-of-buffer))
- ((viper= char ?>) (viper-mark-end-of-buffer))
- ((viper= char ?.) (viper-set-mark-if-necessary))
- ((viper= char ?,) (viper-cycle-through-mark-ring))
- ((viper= char ?^) (push-mark viper-saved-mark t t))
- ((viper= char ?D) (mark-defun))
- (t (user-error viper-ViperBell))
- )))
-
-;; Algorithm: If first invocation of this command save mark on ring, goto
-;; mark, M0, and pop the most recent elt from the mark ring into mark,
-;; making it into the new mark, M1.
-;; Push this mark back and set mark to the original point position, p1.
-;; So, if you hit '' or `` then you can return to p1.
-;;
-;; If repeated command, pop top elt from the ring into mark and
-;; jump there. This forgets the position, p1, and puts M1 back into mark.
-;; Then we save the current pos, which is M0, jump to M1 and pop M2 from
-;; the ring into mark. Push M2 back on the ring and set mark to M0.
-;; etc.
-(defun viper-cycle-through-mark-ring ()
- "Visit previous locations on the mark ring.
-One can use \\=`\\=` and \\='\\=' to temporarily jump 1 step back."
- (let* ((sv-pt (point)))
- ;; if repeated `m,' command, pop the previously saved mark.
- ;; Prev saved mark is actually prev saved point. It is used if the
- ;; user types `` or '' and is discarded
- ;; from the mark ring by the next `m,' command.
- ;; In any case, go to the previous or previously saved mark.
- ;; Then push the current mark (popped off the ring) and set current
- ;; point to be the mark. Current pt as mark is discarded by the next
- ;; m, command.
- (if (eq last-command 'viper-cycle-through-mark-ring)
- ()
- ;; save current mark if the first iteration
- (setq mark-ring (delete (mark-marker) mark-ring))
- (if (mark t)
- (push-mark (mark t) t)) )
- (pop-mark)
- (set-mark-command 1)
- ;; don't duplicate mark on the ring
- (setq mark-ring (delete (mark-marker) mark-ring))
- (push-mark sv-pt t)
- (deactivate-mark)
- (setq this-command 'viper-cycle-through-mark-ring)
- ))
-
-
-(defun viper-goto-mark (arg)
- "Go to mark."
- (interactive "P")
- (let ((char (read-char))
- (com (viper-getcom arg)))
- (viper-goto-mark-subr char com nil)))
-
-(defun viper-goto-mark-and-skip-white (arg)
- "Go to mark and skip to first non-white character on line."
- (interactive "P")
- (let ((char (read-char))
- (com (viper-getCom arg)))
- (viper-goto-mark-subr char com t)))
-
-(defun viper-goto-mark-subr (char com skip-white)
- (if (eobp)
- (if (bobp)
- (error "Empty buffer")
- (backward-char 1)))
- (cond ((viper-valid-register char '(letter))
- (let* ((buff (current-buffer))
- (reg (1+ (- char ?a)))
- (text-marker (get-register reg)))
- ;; If marker points to file that had markers set (and those markers
- ;; were saved (as e.g., in session.el), then restore those markers
- (if (and (consp text-marker)
- (eq (car text-marker) 'file-query)
- (or (find-buffer-visiting (nth 1 text-marker))
- (y-or-n-p (format "Visit file %s again? "
- (nth 1 text-marker)))))
- (save-excursion
- (find-file (nth 1 text-marker))
- (when (and (<= (nth 2 text-marker) (point-max))
- (<= (point-min) (nth 2 text-marker)))
- (setq text-marker (copy-marker (nth 2 text-marker)))
- (set-register reg text-marker))))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (if (not (viper-valid-marker text-marker))
- (error viper-EmptyTextmarker char))
- (if (and (viper-same-line (point) viper-last-jump)
- (= (point) viper-last-jump-ignore))
- (push-mark viper-last-jump t)
- (push-mark nil t)) ; no msg
- (viper-register-to-point reg)
- (setq viper-last-jump (point-marker))
- (cond (skip-white
- (back-to-indentation)
- (setq viper-last-jump-ignore (point))))
- (if com
- (if (equal buff (current-buffer))
- (viper-execute-com (if skip-white
- 'viper-goto-mark-and-skip-white
- 'viper-goto-mark)
- nil com)
- (switch-to-buffer buff)
- (goto-char viper-com-point)
- (viper-change-state-to-vi)
- (user-error viper-ViperBell)))))
- ((and (not skip-white) (viper= char ?`))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (if (and (viper-same-line (point) viper-last-jump)
- (= (point) viper-last-jump-ignore))
- (goto-char viper-last-jump))
- (if (null (mark t)) (error "Mark is not set in this buffer"))
- (if (= (point) (mark t)) (pop-mark))
- (exchange-point-and-mark)
- (setq viper-last-jump (point-marker)
- viper-last-jump-ignore 0)
- (if com (viper-execute-com 'viper-goto-mark nil com)))
- ((and skip-white (viper= char ?'))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (if (and (viper-same-line (point) viper-last-jump)
- (= (point) viper-last-jump-ignore))
- (goto-char viper-last-jump))
- (if (= (point) (mark t)) (pop-mark))
- (exchange-point-and-mark)
- (setq viper-last-jump (point))
- (back-to-indentation)
- (setq viper-last-jump-ignore (point))
- (if com (viper-execute-com 'viper-goto-mark-and-skip-white nil com)))
- (t (error viper-InvalidTextmarker char))))
-
-(defun viper-insert-tab ()
- (interactive)
- (insert-tab))
-
-(defun viper-exchange-point-and-mark ()
- (interactive)
- (exchange-point-and-mark)
- (back-to-indentation))
-
-;; Input Mode Indentation
-
-(define-obsolete-function-alias 'viper-looking-back #'looking-back "24.4")
-
-
-(defun viper-forward-indent ()
- "Indent forward -- `C-t' in Vi."
- (interactive)
- (setq viper-cted t)
- (indent-to (+ (current-column) viper-shift-width)))
-
-(defun viper-backward-indent ()
- "Backtab, `C-d' in Vi."
- (interactive)
- (if viper-cted
- (let ((p (point)) (c (current-column)) bol (indent t))
- (if (memq (preceding-char) '(?0 ?^))
- (progn
- (if (eq ?^ (preceding-char))
- (setq viper-preserve-indent t))
- (delete-char -1)
- (setq p (point))
- (setq indent nil)))
- (setq bol (line-beginning-position))
- (if (re-search-backward "[^ \t]" bol 1) (forward-char))
- (delete-region (point) p)
- (if indent
- (indent-to (- c viper-shift-width)))
- (if (or (bolp) (looking-back "[^ \t]" (1- (point))))
- (setq viper-cted nil)))))
-
-;; do smart indent
-(defun viper-indent-line (col)
- (if viper-auto-indent
- (progn
- (setq viper-cted t)
- (if (and viper-electric-mode
- (not (memq major-mode '(fundamental-mode
- text-mode
- paragraph-indent-text-mode))))
- (indent-according-to-mode)
- (indent-to col)))))
-
-
-(defun viper-autoindent ()
- "Auto Indentation, Vi-style."
- (interactive)
- (let ((col (current-indentation)))
- (if abbrev-mode (expand-abbrev))
- (if viper-preserve-indent
- (setq viper-preserve-indent nil)
- (setq viper-current-indent col))
- ;; don't leave whitespace lines around
- (if (memq last-command
- '(viper-autoindent
- viper-open-line viper-Open-line
- viper-replace-state-exit-cmd))
- (indent-to-left-margin))
- ;; use \n instead of newline, or else <Return> will move the insert point
- ;;(newline 1)
- (insert "\n")
- (viper-indent-line viper-current-indent)
- ))
-
-
-;; Viewing registers
-
-(defun viper-ket-function (arg)
- "Function called by ], the ket. View registers and call ]]."
- (interactive "P")
- (let ((reg (read-char)))
- (cond ((viper-valid-register reg '(letter Letter))
- (view-register (downcase reg)))
- ((viper-valid-register reg '(digit))
- (let ((text (current-kill (- reg ?1) 'do-not-rotate)))
- (with-output-to-temp-buffer " *viper-info*"
- (princ (format "Register %c contains the string:\n" reg))
- (princ text))
- ))
- ((viper= ?\] reg)
- (viper-next-heading arg))
- (t (error
- viper-InvalidRegister reg)))))
-
-(defun viper-brac-function (arg)
- "Function called by [, the brac. View textmarkers and call [[."
- (interactive "P")
- (let ((reg (read-char)))
- (cond ((viper= ?\[ reg)
- (viper-prev-heading arg))
- ((viper= ?\] reg)
- (viper-heading-end arg))
- ((viper-valid-register reg '(letter))
- (let* ((val (get-register (1+ (- reg ?a))))
- (buf (if (not (markerp val))
- (error viper-EmptyTextmarker reg)
- (marker-buffer val)))
- (pos (marker-position val))
- line-no text (s pos) (e pos))
- (with-output-to-temp-buffer " *viper-info*"
- (if (and buf pos)
- (progn
- (with-current-buffer buf
- (setq line-no (1+ (count-lines (point-min) val)))
- (goto-char pos)
- (beginning-of-line)
- (if (re-search-backward "[^ \t]" nil t)
- (setq s (line-beginning-position)))
- (goto-char pos)
- (forward-line 1)
- (if (re-search-forward "[^ \t]" nil t)
- (progn
- (end-of-line)
- (setq e (point))))
- (setq text (buffer-substring s e))
- (setq text (format "%s<%c>%s"
- (substring text 0 (- pos s))
- reg (substring text (- pos s)))))
- (princ
- (format-message
- "Textmarker `%c' is in buffer `%s' at line %d.\n"
- reg (buffer-name buf) line-no))
- (princ (format "Here is some text around %c:\n\n %s"
- reg text)))
- (princ (format-message viper-EmptyTextmarker reg))))
- ))
- (t (error viper-InvalidTextmarker reg)))))
-
-
-
-(defun viper-delete-backward-word (arg)
- "Delete previous word."
- (interactive "p")
- (save-excursion
- (push-mark nil t)
- (backward-word arg)
- (delete-region (point) (mark t))
- (pop-mark)))
-
-\f
-
-;; Get viper standard value of SYMBOL. If symbol is customized, get its
-;; standard value. Otherwise, get the value saved in the alist STORAGE. If
-;; STORAGE is nil, use viper-saved-user-settings.
-(defun viper-standard-value (symbol &optional storage)
- (or (eval (car (get symbol 'customized-value)) t)
- (eval (car (get symbol 'saved-value)) t)
- (nth 1 (assoc symbol (or storage viper-saved-user-settings)))))
-
-
-
-(defun viper-set-expert-level (&optional dont-change-unless)
- "Set the expert level for a Viper user.
-Can be called interactively to change (temporarily or permanently) the
-current expert level.
-
-The optional argument DONT-CHANGE-UNLESS, if not nil, says that
-the level should not be changed, unless its current value is
-meaningless (i.e., not one of 1,2,3,4,5).
-
-User level determines the setting of Viper variables that are most
-sensitive for VI-style look-and-feel."
-
- (interactive)
-
- (if (not (natnump viper-expert-level)) (setq viper-expert-level 0))
-
- (save-window-excursion
- (delete-other-windows)
- ;; if 0 < viper-expert-level < viper-max-expert-level
- ;; & dont-change-unless = t -- use it; else ask
- (viper-ask-level dont-change-unless))
-
- (setq viper-always t
- viper-ex-style-motion t
- viper-ex-style-editing t
- viper-want-ctl-h-help nil)
-
- (cond ((eq viper-expert-level 1) ; novice or beginner
- (global-set-key ; in emacs-state
- viper-toggle-key
- (if (viper-window-display-p) 'viper-iconify 'suspend-emacs))
- (setq viper-no-multiple-ESC t
- viper-re-search t
- viper-vi-style-in-minibuffer t
- viper-search-wrap-around t
- viper-electric-mode nil
- viper-want-emacs-keys-in-vi nil
- viper-want-emacs-keys-in-insert nil))
-
- ((and (> viper-expert-level 1) (< viper-expert-level 5))
- ;; intermediate to guru
- (setq viper-no-multiple-ESC (if (viper-window-display-p)
- t 'twice)
- viper-electric-mode t
- viper-want-emacs-keys-in-vi t
- viper-want-emacs-keys-in-insert (> viper-expert-level 2))
-
- (if (eq viper-expert-level 4) ; respect user's ex-style motion
- ; and viper-no-multiple-ESC
- (progn
- (setq-default
- viper-ex-style-editing
- (viper-standard-value 'viper-ex-style-editing)
- viper-ex-style-motion
- (viper-standard-value 'viper-ex-style-motion))
- (setq viper-ex-style-motion
- (viper-standard-value 'viper-ex-style-motion)
- viper-ex-style-editing
- (viper-standard-value 'viper-ex-style-editing)
- viper-re-search
- (viper-standard-value 'viper-re-search)
- viper-no-multiple-ESC
- (viper-standard-value 'viper-no-multiple-ESC)))))
-
- ;; A wizard!!
- ;; Ideally, if 5 is selected, a buffer should pop up to let the
- ;; user toggle the values of variables.
- (t (setq-default viper-ex-style-editing
- (viper-standard-value 'viper-ex-style-editing)
- viper-ex-style-motion
- (viper-standard-value 'viper-ex-style-motion))
- (setq viper-want-ctl-h-help
- (viper-standard-value 'viper-want-ctl-h-help)
- viper-always
- (viper-standard-value 'viper-always)
- viper-no-multiple-ESC
- (viper-standard-value 'viper-no-multiple-ESC)
- viper-ex-style-motion
- (viper-standard-value 'viper-ex-style-motion)
- viper-ex-style-editing
- (viper-standard-value 'viper-ex-style-editing)
- viper-re-search
- (viper-standard-value 'viper-re-search)
- viper-electric-mode
- (viper-standard-value 'viper-electric-mode)
- viper-want-emacs-keys-in-vi
- (viper-standard-value 'viper-want-emacs-keys-in-vi)
- viper-want-emacs-keys-in-insert
- (viper-standard-value 'viper-want-emacs-keys-in-insert))))
-
- (viper-set-mode-vars-for viper-current-state)
- (if (or viper-always
- (and (> viper-expert-level 0) (> 5 viper-expert-level)))
- (viper-set-hooks)))
-
-
-;; Ask user expert level.
-(defun viper-ask-level (dont-change-unless)
- (let ((ask-buffer " *viper-ask-level*")
- level-changed repeated)
- (save-window-excursion
- (switch-to-buffer ask-buffer)
-
- (while (or (> viper-expert-level viper-max-expert-level)
- (< viper-expert-level 1)
- (null dont-change-unless))
- (erase-buffer)
- (if repeated
- (progn
- (message "Invalid user level")
- (beep 1))
- (setq repeated t))
- (setq dont-change-unless t
- level-changed t)
- (insert (substitute-command-keys "
-Please specify your level of familiarity with the venomous VI PERil
-\(and the VI Plan for Emacs Rescue).
-You can change it at any time by typing \\[viper-set-expert-level]
-
- 1 -- BEGINNER: Almost all Emacs features are suppressed.
- Feels almost like straight Vi. File name completion and
- command history in the minibuffer are thrown in as a bonus.
- To use Emacs productively, you must reach level 3 or higher.
- 2 -- MASTER: C-c now has its standard Emacs meaning in Vi command state,
- so most Emacs commands can be used when Viper is in Vi state.
- Good progress---you are well on the way to level 3!
- 3 -- GRAND MASTER: Like 2, but most Emacs commands are available also
- in Viper's insert state.
- 4 -- GURU: Like 3, but user settings are respected for viper-no-multiple-ESC,
- viper-ex-style-motion, viper-ex-style-editing, and
- viper-re-search variables. Adjust these settings to your taste.
- 5 -- WIZARD: Like 4, but user settings are also respected for viper-always,
- viper-electric-mode, viper-want-ctl-h-help, viper-want-emacs-keys-in-vi,
- and viper-want-emacs-keys-in-insert. Adjust these to your taste.
-
-Please, specify your level now: "))
-
- (setq viper-expert-level (- (viper-read-char-exclusive) ?0))
- ) ; end while
-
- ;; tell the user if level was changed
- (and level-changed
- (progn
- (insert
- (format "\n\n\n\n\n\t\tYou have selected user level %d"
- viper-expert-level))
- (if (y-or-n-p "Do you wish to make this change permanent? ")
- ;; save the setting for viper-expert-level
- (viper-save-setting
- 'viper-expert-level
- (format "Saving user level %d ..." viper-expert-level)
- viper-custom-file-name))
- ))
- (bury-buffer) ; remove ask-buffer from screen
- (message "")
- )))
-
-
-(defun viper-nil ()
- (interactive)
- (beep 1))
-
-
-;; FIXME Use register-read-with-preview?
-;; if ENFORCE-BUFFER is not nil, error if CHAR is a marker in another buffer
-(defun viper-register-to-point (char &optional enforce-buffer)
- "Like `jump-to-register', but switches to another buffer in another window."
- (interactive "cViper register to point: ")
- (let ((val (get-register char)))
- (cond
- ((frame-configuration-p val)
- (set-frame-configuration val))
- ((window-configuration-p val)
- (set-window-configuration val))
- ((viper-valid-marker val)
- (if (and enforce-buffer
- (not (equal (current-buffer) (marker-buffer val))))
- (error (concat viper-EmptyTextmarker " in this buffer")
- (1- (+ char ?a))))
- (pop-to-buffer (marker-buffer val))
- (goto-char val))
- ((and (consp val) (eq (car val) 'file))
- (find-file (cdr val)))
- (t
- (error viper-EmptyTextmarker (1- (+ char ?a)))))))
-
-
-(defun viper-save-kill-buffer ()
- "Save then kill current buffer."
- (interactive)
- (if (< viper-expert-level 2)
- (save-buffers-kill-emacs)
- (if (buffer-modified-p) (save-buffer))
- (kill-buffer (current-buffer))))
-
-
-\f
-;;; Bug Report
-
-(defvar reporter-prompt-for-summary-p)
-
-(defun viper-submit-report ()
- "Submit bug report on Viper."
- (interactive)
- (defvar display-color-p)
- (defvar viper-frame-parameters)
- (defvar viper-minibuffer-emacs-face)
- (defvar viper-minibuffer-vi-face)
- (defvar viper-minibuffer-insert-face)
- (let ((reporter-prompt-for-summary-p t)
- (display-color-p (if (viper-window-display-p)
- (display-color-p)
- 'non-x))
- (viper-frame-parameters (frame-parameters (selected-frame)))
- (viper-minibuffer-emacs-face (if (viper-has-face-support-p)
- (facep
- viper-minibuffer-emacs-face)
- 'non-x))
- (viper-minibuffer-vi-face (if (viper-has-face-support-p)
- (facep viper-minibuffer-vi-face)
- 'non-x))
- (viper-minibuffer-insert-face (if (viper-has-face-support-p)
- (facep
- viper-minibuffer-insert-face)
- 'non-x))
- varlist salutation window-config)
-
- (setq varlist (list 'viper-vi-minibuffer-minor-mode
- 'viper-insert-minibuffer-minor-mode
- 'viper-vi-intercept-minor-mode
- 'viper-vi-local-user-minor-mode
- 'viper-vi-kbd-minor-mode
- 'viper-vi-global-user-minor-mode
- 'viper-vi-state-modifier-minor-mode
- 'viper-vi-diehard-minor-mode
- 'viper-vi-basic-minor-mode
- 'viper-replace-minor-mode
- 'viper-insert-intercept-minor-mode
- 'viper-insert-local-user-minor-mode
- 'viper-insert-kbd-minor-mode
- 'viper-insert-global-user-minor-mode
- 'viper-insert-state-modifier-minor-mode
- 'viper-insert-diehard-minor-mode
- 'viper-insert-basic-minor-mode
- 'viper-emacs-intercept-minor-mode
- 'viper-emacs-local-user-minor-mode
- 'viper-emacs-kbd-minor-mode
- 'viper-emacs-global-user-minor-mode
- 'viper-emacs-state-modifier-minor-mode
- 'viper-automatic-iso-accents
- 'viper-special-input-method
- 'viper-want-emacs-keys-in-insert
- 'viper-want-emacs-keys-in-vi
- 'viper-keep-point-on-undo
- 'viper-no-multiple-ESC
- 'viper-electric-mode
- 'viper-ESC-key
- 'viper-want-ctl-h-help
- 'viper-ex-style-editing
- 'viper-delete-backwards-in-replace
- 'viper-vi-style-in-minibuffer
- 'viper-vi-state-hook
- 'viper-insert-state-hook
- 'viper-replace-state-hook
- 'viper-emacs-state-hook
- 'ex-cycle-other-window
- 'ex-cycle-through-non-files
- 'viper-expert-level
- 'major-mode
- 'window-system
- 'display-color-p
- 'viper-frame-parameters
- 'viper-minibuffer-vi-face
- 'viper-minibuffer-insert-face
- 'viper-minibuffer-emacs-face
- ))
- (setq salutation "
-Congratulations! You may have unearthed a bug in Viper!
-Please mail a concise, accurate summary of the problem to the address above.
-
--------------------------------------------------------------------")
- (setq window-config (current-window-configuration))
- (with-output-to-temp-buffer " *viper-info*"
- (switch-to-buffer " *viper-info*")
- (delete-other-windows)
- (princ "
-PLEASE FOLLOW THESE PROCEDURES
-------------------------------
-
-Before reporting a bug, please verify that it is related to Viper, and is
-not caused by other packages you are using.
-
-Don't report compilation warnings, unless you are certain that there is a
-problem. These warnings are normal and unavoidable.
-
-Please note that users should not modify variables and keymaps other than
-those advertised in the manual. Such `customization' is likely to crash
-Viper, as it would any other improperly customized Emacs package.
-
-If you are reporting an error message received while executing one of the
-Viper commands, type:
-
- M-x set-variable <Return> debug-on-error <Return> t <Return>
-
-Then reproduce the error. The above command will cause Emacs to produce a
-back trace of the execution that leads to the error. Please include this
-trace in your bug report.
-
-If you believe that one of Viper's commands goes into an infinite loop
-\(e.g., Emacs freezes), type:
-
- M-x set-variable <Return> debug-on-quit <Return> t <Return>
-
-Then reproduce the problem. Wait for a few seconds, then type C-g to abort
-the current command. Include the resulting back trace in the bug report.
-
-Mail anyway (y or n)? ")
- (if (y-or-n-p "Mail anyway? ")
- ()
- (set-window-configuration window-config)
- (error "Bug report aborted")))
-
- (require 'reporter)
- (set-window-configuration window-config)
-
- (reporter-submit-bug-report
- "kifer@cs.stonybrook.edu, bug-gnu-emacs@gnu.org"
- (viper-version)
- varlist
- nil 'delete-other-windows
- salutation)))
-
-(provide 'viper-cmd)
-;;; viper-cmd.el ends here
+++ /dev/null
-;;; viper-ex.el --- functions implementing the Ex commands for Viper -*- lexical-binding: t; -*-
-
-;; Copyright (C) 1994-1998, 2000-2025 Free Software Foundation, Inc.
-
-;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
-;; Package: viper
-
-;; This file is part of GNU Emacs.
-
-;; GNU Emacs is free software: you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; GNU Emacs is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;;; Code:
-
-;; Compiler pacifier
-(defvar viper-use-register)
-(defvar viper-s-string)
-(defvar viper-shift-width)
-(defvar viper-ex-history)
-(defvar viper-related-files-and-buffers-ring)
-(defvar viper-local-search-start-marker)
-(defvar viper-expert-level)
-(defvar viper-custom-file-name)
-(defvar viper-case-fold-search)
-(defvar explicit-shell-file-name)
-(defvar compile-command)
-(require 'viper-keym)
-;; end pacifier
-
-(require 'viper-util)
-
-(defgroup viper-ex nil
- "Viper support for Ex commands."
- :prefix "ex-"
- :group 'viper)
-
-
-
-;;; Variables
-
-(defconst viper-ex-work-buf-name " *ex-working-space*")
-(defvar viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
-(defconst viper-ex-tmp-buf-name " *ex-tmp*")
-(defconst viper-ex-print-buf-name " *ex-print*")
-(defvar viper-ex-print-buf (get-buffer-create viper-ex-print-buf-name))
-
-
-;;; ex-commands...
-
-(defun ex-cmd-obsolete (name)
- (error "`%s': Obsolete command, not supported by Viper" name))
-
-(defun ex-cmd-not-yet (name)
- (error "`%s': Command not implemented in Viper" name))
-
-;; alist entries: name (in any order), command, cont(??)
-;; If command is a string, then that is an alias to the real command
-;; to execute (for instance, ":m" -> ":move").
-;; command attributes:
-;; is-mashed: the command's args may be jammed right up against the command
-;; one-letter: this is a one-letter token. Any text appearing after
-;; the name gets appended as an argument for the command
-;; i.e. ":kabc" gets turned into (ex-mark "abc")
-(defconst ex-token-alist '(
- ("!" (ex-command))
- ("&" (ex-substitute t))
- ("=" (ex-line-no))
- (">" (ex-line "right"))
- ("<" (ex-line "left"))
- ("Buffer" (if ex-cycle-other-window
- (viper-switch-to-buffer)
- (viper-switch-to-buffer-other-window)))
- ("Next" (ex-next (not ex-cycle-other-window)))
- ("PreviousRelatedFile" (ex-next-related-buffer -1))
- ("RelatedFile" (ex-next-related-buffer 1))
- ("W" "Write")
- ("WWrite" (save-some-buffers t))
- ("Write" (save-some-buffers))
- ("a" "append")
- ("args" (ex-args))
- ("buffer" (if ex-cycle-other-window
- (viper-switch-to-buffer-other-window)
- (viper-switch-to-buffer)))
- ("c" "change")
- ;; ch should be "change" but maintain old viper compatibility
- ("ch" "chdir")
- ("cd" (ex-cd))
- ("chdir" (ex-cd))
- ("copy" (ex-copy nil))
- ("customize" (customize-group "viper"))
- ("delete" (ex-delete))
- ("edit" (ex-edit))
- ("file" (ex-set-visited-file-name))
- ("g" "global")
- ("global" (ex-global nil) is-mashed)
- ("goto" (ex-goto))
- ("help" (ex-help))
- ("join" (ex-line "join"))
- ("k" (ex-mark) one-letter)
- ("kmark" (ex-mark))
- ("m" "move")
- ("make" (ex-compile))
- ; old viper doesn't specify a default for "ma" so leave it undefined
- ("map" (ex-map))
- ("mark" (ex-mark))
- ("move" (ex-copy t))
- ("next" (ex-next ex-cycle-other-window))
- ("p" "print")
- ("preserve" (ex-preserve))
- ("print" (ex-print))
- ("put" (ex-put))
- ("pwd" (ex-pwd))
- ("quit" (ex-quit))
- ("r" "read")
- ("re" "read")
- ("read" (ex-read))
- ("recover" (ex-recover))
- ("rewind" (ex-rewind))
- ("s" "substitute")
- ("su" "substitute")
- ("sub" "substitute")
- ("set" (ex-set))
- ("shell" (ex-shell))
- ("source" (ex-source))
- ("stop" (suspend-emacs))
- ("sr" (ex-substitute t t))
- ("submitReport" (viper-submit-report))
- ("substitute" (ex-substitute) is-mashed)
- ("suspend" (suspend-emacs))
- ("t" "transfer")
- ("tag" (ex-tag))
- ("transfer" (ex-copy nil))
- ("u" "undo")
- ("un" "undo")
- ("undo" (viper-undo))
- ("unmap" (ex-unmap))
- ("v" "vglobal")
- ("version" (viper-version))
- ("vglobal" (ex-global t) is-mashed)
- ("visual" (ex-edit))
- ("w" "write")
- ("wq" (ex-write t))
- ("write" (ex-write nil))
- ("xit" (ex-write t))
- ("yank" (ex-yank))
- ("~" (ex-substitute t t))
-
- ("append" (ex-cmd-obsolete "append"))
- ("change" (ex-cmd-obsolete "change"))
- ("insert" (ex-cmd-obsolete "insert"))
- ("open" (ex-cmd-obsolete "open"))
-
- ("list" (ex-cmd-not-yet "list"))
- ("z" (ex-cmd-not-yet "z"))
- ("#" (ex-cmd-not-yet "#"))
-
- ("abbreviate" (error "`%s': Vi abbreviations are obsolete. Use the more powerful Emacs abbrevs" ex-token))
- ("unabbreviate" (error "`%s': Vi abbreviations are obsolete. Use the more powerful Emacs abbrevs" ex-token))
- ))
-
-;; No code should touch anything in the alist entry! (other than the name,
-;; "car entry", of course) This way, changing this data structure
-;; requires changing only the following ex-cmd functions...
-
-;; Returns cmd if the command may be jammed right up against its
-;; arguments, nil if there must be a space.
-;; examples of mashable commands: g// g!// v// s// sno// sm//
-(defun ex-cmd-is-mashed-with-args (cmd)
- (if (eq 'is-mashed (car (nthcdr 2 cmd))) cmd))
-
-;; Returns true if this is a one-letter command that may be followed
-;; by anything, no whitespace needed. This is a special-case for ":k".
-(defun ex-cmd-is-one-letter (cmd)
- (if (eq 'one-letter (car (nthcdr 2 cmd))) cmd))
-
-;; Executes the function associated with the command
-(defun ex-cmd-execute (cmd)
- (eval (cadr cmd) t))
-
-;; If this is a one-letter magic command, splice in args.
-(defun ex-splice-args-in-1-letr-cmd (key list)
- (let ((oneletter (ex-cmd-is-one-letter (assoc (substring key 0 1) list))))
- (if oneletter
- (list key
- (append (cadr oneletter)
- (if (< 1 (length key)) (list (substring key 1))))
- (car (cdr (cdr oneletter))) ))
- ))
-
-
-;; Returns the alist entry for the appropriate key.
-;; Tries to complete the key before using it in the alist.
-;; If there is no appropriate key (no match or duplicate matches) return nil
-(defun ex-cmd-assoc (key list)
- (let ((entry (try-completion key list))
- result)
- (setq result (cond
- ((eq entry t) (assoc key list))
- ((stringp entry) (or (ex-splice-args-in-1-letr-cmd key list)
- (assoc entry list)))
- ((eq entry nil) (ex-splice-args-in-1-letr-cmd key list))
- (t nil)
- ))
- ;; If we end up with an alias, look up the alias...
- (if (stringp (cadr result))
- (setq result (ex-cmd-assoc (cadr result) list)))
- ;; and return the corresponding alist entry
- result
- ))
-
-
-;; A-list of Ex variables that can be set using the :set command.
-(defconst ex-variable-alist
- '(("wrapscan") ("ws") ("wrapmargin") ("wm")
- ("tabstop-global") ("ts-g") ("tabstop") ("ts")
- ("showmatch") ("sm") ("shiftwidth") ("sw") ("shell") ("sh")
- ("readonly") ("ro")
- ("nowrapscan") ("nows") ("noshowmatch") ("nosm")
- ("noreadonly") ("noro") ("nomagic") ("noma")
- ("noignorecase") ("noic")
- ("noautoindent-global") ("noai-g") ("noautoindent") ("noai")
- ("magic") ("ma") ("ignorecase") ("ic")
- ("autoindent-global") ("ai-g") ("autoindent") ("ai")
- ("all")
- ))
-
-
-
-;; Token recognized during parsing of Ex commands (e.g., "read", "comma")
-(defvar ex-token nil)
-
-;; Type of token.
-;; If non-nil, gives type of address; if nil, it is a command.
-(defvar ex-token-type nil)
-
-;; List of addresses passed to Ex command
-(defvar ex-addresses nil)
-
-;; This flag is supposed to be set only by `#', `print', and `list',
-;; none of which is implemented. So, it and the pieces of the code it
-;; controls are dead weight. We keep it just in case this might be
-;; needed in the future.
-(defvar ex-flag nil)
-
-;; "buffer" where Ex commands keep deleted data.
-;; In Emacs terms, this is a register.
-(defvar ex-buffer nil)
-
-;; Value of ex count.
-(defvar ex-count nil)
-
-;; Flag indicating that :global Ex command is being executed.
-(defvar ex-g-flag nil)
-;; Flag indicating that :vglobal Ex command is being executed.
-(defvar ex-g-variant nil)
-;; Marks to operate on during a :global Ex command.
-(defvar ex-g-marks nil)
-
-;; Save reg-exp used in substitute.
-(defvar ex-reg-exp nil)
-
-
-;; Replace pattern for substitute.
-(defvar ex-repl nil)
-
-;; Pattern for global command.
-(defvar ex-g-pat nil)
-
-(defcustom ex-unix-type-shell
- (let ((case-fold-search t))
- (and (stringp shell-file-name)
- (string-match
- (concat
- "\\("
- "csh$\\|csh.exe$"
- "\\|"
- "ksh$\\|ksh.exe$"
- "\\|"
- "^sh$\\|sh.exe$"
- "\\|"
- "[^a-z]sh$\\|[^a-z]sh.exe$"
- "\\|"
- "bash$\\|bash.exe$"
- "\\)")
- shell-file-name)
- t))
- "Is the user using a unix-type shell under a non-OS?"
- :type 'boolean)
-
-(defcustom ex-unix-type-shell-options
- (let ((case-fold-search t))
- (if ex-unix-type-shell
- (cond ((string-match "\\(csh$\\|csh.exe$\\)" shell-file-name)
- "-f") ; csh: do it fast
- ((string-match "\\(bash$\\|bash.exe$\\)" shell-file-name)
- "-noprofile") ; bash: ignore .profile
- )))
- "Options to pass to the Unix-style shell.
-Don't put `-c' here, as it is added automatically."
- :type '(choice (const nil) string))
-
-(defcustom ex-compile-command "make"
- "The command to run when the user types :make."
- :type 'string)
-
-(defcustom viper-glob-function
- (cond (ex-unix-type-shell 'viper-glob-unix-files)
- (viper-ms-style-os-p 'viper-glob-mswindows-files) ; Microsoft OS
- (t 'viper-glob-unix-files) ; presumably UNIX
- )
- "Expand the file spec containing wildcard symbols.
-The default tries to set this variable to work with Unix or MS Windows.
-
-However, if it doesn't work right for some types of Unix shells or some OS,
-the user should supply the appropriate function and set this variable to the
-corresponding function symbol."
- :type 'symbol)
-
-
-;; Remembers the previous Ex tag.
-(defvar ex-tag nil)
-
-;; file used by Ex commands like :r, :w, :n
-(defvar ex-file nil)
-
-;; If t, tells Ex that this is a variant-command, i.e., w>>, r!, etc.
-(defvar ex-variant nil)
-
-;; Specified the offset of an Ex command, such as :read.
-(defvar ex-offset nil)
-
-;; Tells Ex that this is a w>> command.
-(defvar ex-append nil)
-
-;; File containing the shell command to be executed at Ex prompt,
-;; e.g., :r !date
-(defvar ex-cmdfile nil)
-(defvar ex-cmdfile-args "")
-
-;; flag used in viper-ex-read-file-name to indicate that we may be reading
-;; multiple file names. Used for :edit and :next
-(defvar viper-keep-reading-filename nil)
-
-(defcustom ex-cycle-other-window t
- "If t, :n and :b cycles through files and buffers in other window.
-Then :N and :B cycles in the current window. If nil, this behavior is
-reversed."
- :type 'boolean)
-
-(defcustom ex-cycle-through-non-files nil
- "Cycle through *scratch* and other buffers that don't visit any file."
- :type 'boolean)
-
-;; Last shell command executed with :! command.
-(defvar viper-ex-last-shell-com nil)
-
-;; Indicates if Minibuffer was exited temporarily in Ex-command.
-(defvar viper-incomplete-ex-cmd nil)
-
-;; Remembers the last ex-command prompt.
-(defvar viper-last-ex-prompt "")
-
-
-;; Get a complete ex command
-(defun viper-get-ex-com-subr ()
- (let (cmd case-fold-search)
- (set-mark (point))
- (re-search-forward "[a-zA-Z][a-zA-Z]*")
- (setq ex-token-type 'command)
- (setq ex-token (buffer-substring (point) (mark t)))
- (setq cmd (ex-cmd-assoc ex-token ex-token-alist))
- (if cmd
- (setq ex-token (car cmd))
- (setq ex-token-type 'non-command))
- ))
-
-;; Get an ex-token which is either an address or a command.
-;; A token has a type, (command, address, end-mark), and a value
-(defun viper-get-ex-token ()
- (save-window-excursion
- (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
- (set-buffer viper-ex-work-buf)
- (skip-chars-forward " \t|")
- (let ((case-fold-search t)
- (char (following-char)))
- (cond ((= char ?#)
- (setq ex-token-type 'command)
- (setq ex-token (char-to-string char))
- (forward-char 1))
- ((looking-at "[a-z]") (viper-get-ex-com-subr))
- ((= char ?.)
- (forward-char 1)
- (setq ex-token-type 'dot))
- ((looking-at "[0-9]")
- (set-mark (point))
- (re-search-forward "[0-9]*")
- (setq ex-token-type
- (cond ((eq ex-token-type 'plus) 'add-number)
- ((eq ex-token-type 'minus) 'sub-number)
- (t 'abs-number)))
- (setq ex-token
- (string-to-number (buffer-substring (point) (mark t)))))
- ((= char ?$)
- (forward-char 1)
- (setq ex-token-type 'end))
- ((= char ?%)
- (forward-char 1)
- (setq ex-token-type 'whole))
- ((= char ?+)
- (cond ((looking-at "\\+[-+\n|]")
- (forward-char 1)
- (insert "1")
- (backward-char 1)
- (setq ex-token-type 'plus))
- ((looking-at "\\+[0-9]")
- (forward-char 1)
- (setq ex-token-type 'plus))
- (t
- (error viper-BadAddress))))
- ((= char ?-)
- (cond ((looking-at "-[-+\n|]")
- (forward-char 1)
- (insert "1")
- (backward-char 1)
- (setq ex-token-type 'minus))
- ((looking-at "-[0-9]")
- (forward-char 1)
- (setq ex-token-type 'minus))
- (t
- (error viper-BadAddress))))
- ((= char ?/)
- (forward-char 1)
- (set-mark (point))
- (let ((cont t))
- (while (and (not (eolp)) cont)
- ;;(re-search-forward "[^/]*/")
- (re-search-forward "[^/]*\\(/\\|\n\\)")
- (if (not (looking-back "[^\\]\\(\\\\\\\\\\)*\\\\/"
- (line-beginning-position 0)))
- (setq cont nil))))
- (backward-char 1)
- (setq ex-token (buffer-substring (point) (mark t)))
- (when (= (following-char) ?/) (forward-char 1))
- (setq ex-token-type 'search-forward))
- ((= char ??)
- (forward-char 1)
- (set-mark (point))
- (let ((cont t))
- (while (and (not (eolp)) cont)
- ;;(re-search-forward "[^\\?]*\\?")
- (re-search-forward "[^\\?]*\\(\\?\\|\n\\)")
- (if (not (looking-back "[^\\]\\(\\\\\\\\\\)*\\\\\\?"
- (line-beginning-position 0)))
- (setq cont nil))
- (backward-char 1)
- (when (/= (following-char) ?\n) (forward-char 1))))
- (setq ex-token-type 'search-backward)
- (setq ex-token (buffer-substring (1- (point)) (mark t))))
- ((= char ?,)
- (forward-char 1)
- (setq ex-token-type 'comma))
- ((= char ?\;)
- (forward-char 1)
- (setq ex-token-type 'semi-colon))
- ((looking-at "[!=><&~]")
- (setq ex-token-type 'command)
- (setq ex-token (char-to-string char))
- (forward-char 1))
- ((= char ?\')
- (setq ex-token-type 'goto-mark)
- (forward-char 1)
- (cond ((= (following-char) ?\') (setq ex-token nil))
- ((looking-at "[a-z]") (setq ex-token (following-char)))
- (t (error "%s" "Marks are ' and a-z")))
- (forward-char 1))
- ((= char ?\n)
- (setq ex-token-type 'end-mark)
- (setq ex-token "goto"))
- (t
- (error viper-BadExCommand))))))
-
-;; Reads Ex command. Tries to determine if it has to exit because command
-;; is complete or invalid. If not, keeps reading command.
-(defun ex-cmd-read-exit ()
- (interactive)
- (setq viper-incomplete-ex-cmd t)
- (let ((quit-regex1 (concat
- "\\(" "set[ \t]*"
- "\\|" "edit[ \t]*"
- "\\|" "[nN]ext[ \t]*"
- "\\|" "unm[ \t]*"
- "\\|" "^[ \t]*rep"
- "\\)"))
- (quit-regex2 (concat
- "[a-zA-Z][ \t]*"
- "\\(" "!" "\\|" ">>"
- "\\|" "\\+[0-9]+"
- "\\)"
- "*[ \t]*$"))
- (stay-regex (concat
- "\\(" "^[ \t]*$"
- "\\|" "[?/].*"
- "\\|" "[ktgjmsz][ \t]*$"
- "\\|" "^[ \t]*ab.*"
- "\\|" "tr[ansfer \t]*"
- "\\|" "sr[ \t]*"
- "\\|" "mo.*"
- "\\|" "^[ \t]*k?ma[^p]*"
- "\\|" "^[ \t]*fi.*"
- "\\|" "v?gl.*"
- "\\|" "[vg][ \t]*$"
- "\\|" "jo.*"
- "\\|" "^[ \t]*ta.*"
- "\\|" "^[ \t]*una.*"
- ;; don't jump up in :s command
- "\\|" "^[ \t]*\\([`'][a-z]\\|[.,%]\\)*[ \t]*su.*"
- "\\|" "^[ \t]*\\([`'][a-z]\\|[.,%]\\)*[ \t]*s[^a-z].*"
- "\\|" "['`][a-z][ \t]*"
- ;; r! assumes that the next one is a shell command
- "\\|" "\\(r\\|re\\|rea\\|read\\)[ \t]*!"
- ;; w ! assumes that the next one is a shell command
- "\\|" "\\(w\\|wr\\|wri\\|writ.?\\)[ \t]+!"
- "\\|" "![ \t]*[a-zA-Z].*"
- "\\)"
- "!*")))
-
- (save-window-excursion ;; put cursor at the end of the Ex working buffer
- (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
- (set-buffer viper-ex-work-buf)
- (goto-char (point-max)))
- (cond ((looking-back quit-regex1 (line-beginning-position))
- (exit-minibuffer))
- ;; Almost certainly point-min should be line-beginning-position,
- ;; but probably the two are identical anyway, and who really cares?
- ((looking-back stay-regex (point-min)) (insert " "))
- ((looking-back quit-regex2 (line-beginning-position))
- (exit-minibuffer))
- (t (insert " ")))))
-
-(declare-function viper-tmp-insert-at-eob "viper-cmd" (msg))
-
-;; complete Ex command
-(defun ex-cmd-complete ()
- (interactive)
- (let (save-pos dist compl-list string-to-complete completion-result)
-
- (save-excursion
- (setq dist (skip-chars-backward "a-zA-Z!=>&~")
- save-pos (point)))
-
- (if (or (= dist 0)
- (looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)"
- (line-beginning-position))
- (looking-back
- "^[ \t]*[a-zA-Z!=>&~][ \t]*[/?]*[ \t]+[a-zA-Z!=>&~]+"
- (line-beginning-position)))
- ;; Preceding characters are not the ones allowed in an Ex command
- ;; or we have typed past command name.
- ;; Note: we didn't do parsing, so there can be surprises.
- (if (or (looking-back "[a-zA-Z!=>&~][ \t]*[/?]*[ \t]*"
- (line-beginning-position))
- (looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)"
- (line-beginning-position))
- (looking-at "[^ \t\n\C-m]"))
- nil
- (with-output-to-temp-buffer "*Completions*"
- (display-completion-list
- (viper-alist-to-list ex-token-alist))))
- ;; Preceding chars may be part of a command name
- (setq string-to-complete (buffer-substring save-pos (point)))
- (setq completion-result
- (try-completion string-to-complete ex-token-alist))
-
- (cond ((eq completion-result t) ; exact match--do nothing
- (viper-tmp-insert-at-eob " (Sole completion)"))
- ((eq completion-result nil)
- (viper-tmp-insert-at-eob " (No match)"))
- (t ;; partial completion
- (goto-char save-pos)
- (delete-region (point) (point-max))
- (insert completion-result)
- (let (case-fold-search)
- (setq compl-list
- (viper-filter-alist (concat "^" completion-result)
- ex-token-alist)))
- (if (> (length compl-list) 1)
- (with-output-to-temp-buffer "*Completions*"
- (display-completion-list
- (viper-alist-to-list (reverse compl-list)))))))
- )))
-
-
-(declare-function viper-enlarge-region "viper-cmd" (beg end))
-(declare-function viper-read-string-with-history "viper-cmd"
- (prompt &optional viper-initial history-var
- default keymap init-message))
-
-;; Read Ex commands
-;; ARG is a prefix argument. If given, the ex command runs on the region
-;;(without the user having to specify the address :a,b
-;; STRING is the command to execute. If nil, then Viper asks you to enter the
-;; command.
-(defun viper-ex (arg &optional string)
- (interactive "P")
- (or string
- (setq ex-g-flag nil
- ex-g-variant nil))
- (let* ((map (copy-keymap minibuffer-local-map))
- (address nil)
- (cont t)
- (dot (point))
- reg-beg-line reg-end-line
- reg-beg reg-end
- initial-str
- prev-token-type com-str)
- (viper-add-keymap viper-ex-cmd-map map)
-
- (if arg
- (progn
- (viper-enlarge-region (mark t) (point))
- (if (> (point) (mark t))
- (setq reg-beg (mark t)
- reg-end (point))
- (setq reg-end (mark t)
- reg-beg (point)))
- (save-excursion
- (goto-char reg-beg)
- (setq reg-beg-line (1+ (count-lines (point-min) (point)))
- reg-end-line
- (+ reg-beg-line (count-lines reg-beg reg-end) -1)))))
- (if reg-beg-line
- (setq initial-str (format "%d,%d" reg-beg-line reg-end-line)))
-
- (setq com-str
- (if string
- (concat initial-str string)
- (viper-read-string-with-history
- ":"
- initial-str
- 'viper-ex-history
- ;; no default when working on region
- (if initial-str
- nil
- (car viper-ex-history))
- map
- (if initial-str
- " [Type command to execute on current region]"))))
- (save-window-excursion
- ;; just a precaution
- (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
- (set-buffer viper-ex-work-buf)
- (delete-region (point-min) (point-max))
- (insert com-str "\n")
- (goto-char (point-min)))
- (setq ex-token-type nil
- ex-addresses nil)
- (while cont
- (viper-get-ex-token)
- (cond ((memq ex-token-type '(command end-mark))
- (if address (setq ex-addresses (cons address ex-addresses)))
- (deactivate-mark)
- (let ((cmd (ex-cmd-assoc ex-token ex-token-alist)))
- (if (null cmd)
- (error "`%s': %s" ex-token viper-BadExCommand))
- (ex-cmd-execute cmd)
- (if (or (ex-cmd-is-mashed-with-args cmd)
- (ex-cmd-is-one-letter cmd))
- (setq cont nil)
- (save-excursion
- (save-window-excursion
- (setq viper-ex-work-buf
- (get-buffer-create viper-ex-work-buf-name))
- (set-buffer viper-ex-work-buf)
- (skip-chars-forward " \t")
- (cond ((= (following-char) ?|)
- (forward-char 1))
- ((= (following-char) ?\n)
- (setq cont nil))
- (t (error
- "`%s': %s" ex-token viper-SpuriousText)))
- )))
- ))
- ((eq ex-token-type 'non-command)
- (error "`%s': %s" ex-token viper-BadExCommand))
- ((eq ex-token-type 'whole)
- (setq address nil)
- (setq ex-addresses
- (if ex-addresses
- (cons (point-max) ex-addresses)
- (cons (point-max) (cons (point-min) ex-addresses)))))
- ((eq ex-token-type 'comma)
- (if (eq prev-token-type 'whole)
- (setq address (point-min)))
- (setq ex-addresses
- (cons (if (null address) (point) address) ex-addresses)))
- ((eq ex-token-type 'semi-colon)
- (if (eq prev-token-type 'whole)
- (setq address (point-min)))
- (if address (setq dot address))
- (setq ex-addresses
- (cons (if (null address) (point) address) ex-addresses)))
- (t (let ((ans (viper-get-ex-address-subr address dot)))
- (if ans (setq address ans)))))
- (setq prev-token-type ex-token-type))))
-
-
-;; Get a regular expression and set `ex-variant', if found
-;; Viper doesn't parse the substitution or search patterns.
-;; In particular, it doesn't expand ~ into the last substitution.
-(defun viper-get-ex-pat ()
- (save-window-excursion
- (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
- (set-buffer viper-ex-work-buf)
- (skip-chars-forward " \t")
- (if (looking-at "!")
- ;; this is probably a variant command r!
- (progn
- (setq ex-g-variant (not ex-g-variant)
- ex-g-flag (not ex-g-flag))
- (forward-char 1)
- (skip-chars-forward " \t")))
- (let ((c (following-char)))
- (cond ((string-match "[0-9A-Za-z]" (format "%c" c))
- (error
- "Global regexp must be inside matching non-alphanumeric chars"))
- ((= c ??) (error "`?' is not an allowed pattern delimiter here")))
- (if (looking-at "[^\\\n]")
- (progn
- (forward-char 1)
- (set-mark (point))
- (let ((cont t))
- ;; the use of eobp instead of eolp permits the use of newlines in
- ;; pat2 in s/pat1/pat2/
- (while (and (not (eobp)) cont)
- (if (not (re-search-forward (format "[^%c]*%c" c c) nil t))
- (if (member ex-token '("global" "vglobal"))
- (error "Missing closing delimiter for global regexp")
- (goto-char (point-max))))
- (if (not (looking-back
- (format "[^\\]\\(\\\\\\\\\\)*\\\\%c" c)
- (line-beginning-position 0)))
- (setq cont nil)
- ;; we are at an escaped delimiter: unescape it and continue
- (delete-char -2)
- (insert c)
- (if (eolp)
- ;; if at eol, exit loop and go to next line
- ;; later, delim will be inserted at the end
- (progn
- (setq cont nil)
- (forward-char))))
- ))
- (setq ex-token
- (if (= (mark t) (point)) ""
- (buffer-substring (1- (point)) (mark t))))
- (backward-char 1)
- ;; if the user didn't insert the final pattern delimiter, we're
- ;; at newline now. In this case, insert the initial delimiter
- ;; specified in variable c
- (if (eolp)
- (progn
- (insert c)
- (backward-char 1)))
- )
- (setq ex-token nil))
- c)))
-
-;; Get an Ex option g or c
-(defun viper-get-ex-opt-gc (c)
- (save-window-excursion
- (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
- (set-buffer viper-ex-work-buf)
- (if (looking-at (format "%c" c)) (forward-char 1))
- (skip-chars-forward " \t")
- (cond ((looking-at "g")
- (setq ex-token "g")
- (forward-char 1)
- t)
- ((looking-at "c")
- (setq ex-token "c")
- (forward-char 1)
- t)
- (t nil))))
-
-;; Compute default addresses. WHOLE-FLAG means use the whole buffer
-(defun viper-default-ex-addresses (&optional whole-flag)
- (cond ((null ex-addresses)
- (setq ex-addresses
- (if whole-flag
- (list (point-max) (point-min))
- (list (point) (point)))))
- ((null (cdr ex-addresses))
- (setq ex-addresses
- (cons (car ex-addresses) ex-addresses)))))
-
-;; Get an ex-address as a marker and set ex-flag if a flag is found
-(defun viper-get-ex-address ()
- (let ((address (point-marker))
- (cont t))
- (setq ex-token "")
- (setq ex-flag nil)
- (while cont
- (viper-get-ex-token)
- (cond ((eq ex-token-type 'command)
- (if (member ex-token '("print" "list" "#"))
- (progn
- (setq ex-flag t
- cont nil))
- (error "Address expected in this Ex command")))
- ((eq ex-token-type 'end-mark)
- (setq cont nil))
- ((eq ex-token-type 'whole)
- (error "Trailing address expected"))
- ((eq ex-token-type 'comma)
- (error "`%s': %s" ex-token viper-SpuriousText))
- (t (let ((ans (viper-get-ex-address-subr address (point-marker))))
- (if ans (setq address ans))))))
- address))
-
-(declare-function viper-register-to-point "viper-cmd"
- (char &optional enforce-buffer))
-
-;; Returns an address as a point
-(defun viper-get-ex-address-subr (old-address dot)
- (let ((address nil))
- (if (null old-address) (setq old-address dot))
- (cond ((eq ex-token-type 'dot)
- (setq address dot))
- ((eq ex-token-type 'add-number)
- (save-excursion
- (goto-char old-address)
- (forward-line (if (= old-address 0) (1- ex-token) ex-token))
- (setq address (point-marker))))
- ((eq ex-token-type 'sub-number)
- (save-excursion
- (goto-char old-address)
- (forward-line (- ex-token))
- (setq address (point-marker))))
- ((eq ex-token-type 'abs-number)
- (save-excursion
- (goto-char (point-min))
- (if (= ex-token 0) (setq address 0)
- (forward-line (1- ex-token))
- (setq address (point-marker)))))
- ((eq ex-token-type 'end)
- (save-excursion
- (goto-char (1- (point-max)))
- (setq address (point-marker))))
- ((eq ex-token-type 'plus) t) ; do nothing
- ((eq ex-token-type 'minus) t) ; do nothing
- ((eq ex-token-type 'search-forward)
- (save-excursion
- (ex-search-address t)
- (setq address (point-marker))))
- ((eq ex-token-type 'search-backward)
- (save-excursion
- (ex-search-address nil)
- (setq address (point-marker))))
- ((eq ex-token-type 'goto-mark)
- (save-excursion
- (if (null ex-token)
- (exchange-point-and-mark)
- (goto-char
- (viper-register-to-point (1+ (- ex-token ?a)) 'enforce-buffer)))
- (setq address (point-marker)))))
- address))
-
-
-;; Search pattern and set address
-;; Doesn't wrap around. Should it?
-(defun ex-search-address (forward)
- (if (string= ex-token "")
- (if (null viper-s-string)
- (error viper-NoPrevSearch)
- (setq ex-token viper-s-string))
- (setq viper-s-string ex-token))
- (if forward
- (progn
- (forward-line 1)
- (re-search-forward ex-token))
- (forward-line -1)
- (re-search-backward ex-token)))
-
-;; Get a buffer name and set `ex-count' and `ex-flag' if found
-(defun viper-get-ex-buffer ()
- (setq ex-buffer nil)
- (setq ex-count nil)
- (setq ex-flag nil)
- (save-window-excursion
- (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
- (set-buffer viper-ex-work-buf)
- (skip-chars-forward " \t")
- (if (looking-at "[a-zA-Z]")
- (progn
- (setq ex-buffer (following-char))
- (forward-char 1)
- (skip-chars-forward " \t")))
- (if (looking-at "[0-9]")
- (progn
- (set-mark (point))
- (re-search-forward "[0-9][0-9]*")
- (setq ex-count (string-to-number (buffer-substring (point) (mark t))))
- (skip-chars-forward " \t")))
- (if (looking-at "[pl#]")
- (progn
- (setq ex-flag t)
- (forward-char 1)))
- (if (not (looking-at "[\n|]"))
- (error "`%s': %s" ex-token viper-SpuriousText))))
-
-(defun viper-get-ex-count ()
- (setq ex-variant nil
- ex-count nil
- ex-flag nil)
- (save-window-excursion
- (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
- (set-buffer viper-ex-work-buf)
- (skip-chars-forward " \t")
- (if (looking-at "!")
- (progn
- (setq ex-variant t)
- (forward-char 1)))
- (skip-chars-forward " \t")
- (if (looking-at "[0-9]")
- (progn
- (set-mark (point))
- (re-search-forward "[0-9][0-9]*")
- (setq ex-count (string-to-number (buffer-substring (point) (mark t))))
- (skip-chars-forward " \t")))
- (if (looking-at "[pl#]")
- (progn
- (setq ex-flag t)
- (forward-char 1)))
- (if (not (looking-at "[\n|]"))
- (error "`%s': %s"
- (buffer-substring
- (point-min) (1- (point-max))) viper-BadExCommand))))
-
-;; Expand \% and \# in ex command
-(defun ex-expand-filsyms (cmd buf)
- (let (cf pf ret)
- (with-current-buffer buf
- (setq cf buffer-file-name)
- (setq pf (ex-next nil t))) ; this finds alternative file name
- (if (and (null cf) (string-match "[^\\]%\\|\\`%" cmd))
- (error "No current file to substitute for `%%'"))
- (if (and (null pf) (string-match "[^\\]#\\|\\`#" cmd))
- (error "No alternate file to substitute for `#'"))
- (with-current-buffer (get-buffer-create viper-ex-tmp-buf-name)
- (erase-buffer)
- (insert cmd)
- (goto-char (point-min))
- (while (re-search-forward "%\\|#" nil t)
- (let ((data (match-data))
- (char (buffer-substring (match-beginning 0) (match-end 0))))
- (if (looking-back "\\\\." (- (point) 2))
- (replace-match char)
- (store-match-data data)
- (if (string= char "%")
- (replace-match cf)
- (replace-match pf)))))
- (end-of-line)
- (setq ret (buffer-substring (point-min) (point)))
- (message "%s" ret))
- ret))
-
-;; Get a file name and set `ex-variant', `ex-append' and `ex-offset' if found
-;; If it is r!, then get the command name and whatever args
-(defun viper-get-ex-file ()
- (let (prompt)
- (setq ex-file nil
- ex-variant nil
- ex-append nil
- ex-offset nil
- ex-cmdfile nil
- ex-cmdfile-args "")
- (save-excursion
- (with-current-buffer (setq viper-ex-work-buf
- (get-buffer-create viper-ex-work-buf-name))
- (skip-chars-forward " \t")
- (when (= (following-char) ?!)
- (if (and (not (memq (preceding-char) '(?\s ?\t)))
- ;; read doesn't have a corresponding :r! form, so ! is
- ;; immediately interpreted as a shell command.
- (not (string= ex-token "read")))
- (progn
- (setq ex-variant t)
- (forward-char 1)
- (skip-chars-forward " \t"))
- (setq ex-cmdfile t)
- (forward-char 1)
- (skip-chars-forward " \t")))
- (when (looking-at ">>")
- (setq ex-append t
- ex-variant t)
- (forward-char 2)
- (skip-chars-forward " \t"))
- (when (= (following-char) ?+)
- (forward-char 1)
- (set-mark (point))
- (re-search-forward "[ \t\n]")
- (backward-char 1)
- (setq ex-offset (buffer-substring (point) (mark t)))
- (forward-char 1)
- (skip-chars-forward " \t"))
- ;; this takes care of :r, :w, etc., when they get file names
- ;; from the history list
- (if (member ex-token '("read" "write" "edit" "visual" "next"))
- (progn
- (setq ex-file (buffer-substring (point) (1- (point-max))))
- (setq ex-file
- ;; For :e, match multiple non-white strings separated
- ;; by white. For others, find the first non-white string
- (if (string-match
- (if (string= ex-token "edit")
- "[^ \t\n]+\\([ \t]+[^ \t\n]+\\)*"
- "[^ \t\n]+")
- ex-file)
- (progn
- ;; if file name comes from history, don't leave
- ;; minibuffer when the user types space
- (setq viper-incomplete-ex-cmd nil)
- (setq ex-cmdfile-args
- (substring ex-file (match-end 0) nil))
- ;; this must be the last clause in this progn
- (substring ex-file (match-beginning 0) (match-end 0))
- )
- ""))
- ;; this leaves only the command name in the work area
- ;; file names are gone
- (delete-region (point) (1- (point-max)))
- ))
- (goto-char (point-max))
- (skip-chars-backward " \t\n")
- (setq prompt (buffer-substring (point-min) (point)))
- ))
-
- (setq viper-last-ex-prompt prompt)
-
- ;; If we just finished reading command, redisplay prompt
- (if viper-incomplete-ex-cmd
- (setq ex-file (viper-ex-read-file-name (format ":%s " prompt)))
- ;; file was typed in-line
- (setq ex-file (or ex-file "")))
- ))
-
-
-;; Completes file name or exits minibuffer. If Ex command accepts multiple
-;; file names, arranges to re-enter the minibuffer.
-(defun viper-complete-filename-or-exit ()
- (interactive)
- (setq viper-keep-reading-filename t)
- ;; don't exit if directory---ex-commands don't
- (cond ((ex-cmd-accepts-multiple-files-p ex-token) (exit-minibuffer))
- ;; apparently the argument to an Ex command is
- ;; supposed to be a shell command
- ((looking-back "^[ \t]*!.*" (line-beginning-position))
- (setq ex-cmdfile t)
- (insert " "))
- (t
- (setq ex-cmdfile nil)
- (minibuffer-complete))))
-
-(defun viper-handle-! ()
- (interactive)
- (if (and (string=
- (buffer-string) (abbreviate-file-name default-directory))
- (member ex-token '("read" "write")))
- (erase-buffer))
- (insert "!"))
-
-(defun ex-cmd-accepts-multiple-files-p (token)
- (member token '("edit" "next" "Next")))
-
-;; Read file name from the minibuffer in an ex command.
-;; If user doesn't enter anything, then "" is returned, i.e., the
-;; prompt-directory is not returned.
-(defun viper-ex-read-file-name (prompt)
- (let* ((str "")
- (minibuffer-local-completion-map
- (copy-keymap minibuffer-local-completion-map))
- beg end cont val)
-
- (viper-add-keymap ex-read-filename-map minibuffer-local-completion-map)
-
- (setq cont (setq viper-keep-reading-filename t))
- (while cont
- (setq viper-keep-reading-filename nil
- val (read-file-name (concat prompt str) nil default-directory))
- (setq val (expand-file-name val))
- (if (and (string-search " " val)
- (ex-cmd-accepts-multiple-files-p ex-token))
- (setq val (concat "\"" val "\"")))
- (setq str (concat str (if (equal val "") "" " ")
- val (if (equal val "") "" " ")))
-
- ;; Only edit, next, and Next commands accept multiple files.
- ;; viper-keep-reading-filename is set in the anonymous function that is
- ;; bound to " " in ex-read-filename-map.
- (setq cont (and viper-keep-reading-filename
- (ex-cmd-accepts-multiple-files-p ex-token)))
- )
-
- (setq beg (string-match "[^ \t]" str) ; delete leading blanks
- end (string-match "[ \t]*$" str)) ; delete trailing blanks
- (if (member ex-token '("read" "write"))
- (if (string-match "[\t ]*!" str)
- ;; this is actually a shell command
- (progn
- (setq ex-cmdfile t)
- (setq beg (1+ beg))
- (setq viper-last-ex-prompt
- (concat viper-last-ex-prompt " !")))))
- (substring str (or beg 0) end)))
-
-
-(defun viper-undisplayed-files ()
- (mapcar
- (lambda (b)
- (if (null (get-buffer-window b))
- (let ((f (buffer-file-name b)))
- (if f f
- (if ex-cycle-through-non-files
- (let ((s (buffer-name b)))
- (if (string= " " (substring s 0 1))
- nil
- s))
- nil)))
- nil))
- (buffer-list)))
-
-
-(defun ex-args ()
- (let ((l (viper-undisplayed-files))
- (args "")
- (file-count 1))
- (while (not (null l))
- (if (car l)
- (setq args (format "%s %d) %s\n" args file-count (car l))
- file-count (1+ file-count)))
- (setq l (cdr l)))
- (if (string= args "")
- (message "All files are already displayed")
- (save-excursion
- (save-window-excursion
- (with-output-to-temp-buffer " *viper-info*"
- (princ "\n\nThese files are not displayed in any window.\n")
- (princ "\n=============\n")
- (princ args)
- (princ "\n=============\n")
- (princ "\nThe numbers can be given as counts to :next. ")
- (princ "\n\nPress any key to continue...\n\n"))
- (read-event))))))
-
-;; Ex cd command. Default directory of this buffer changes
-(defun ex-cd ()
- (viper-get-ex-file)
- (if (string= ex-file "")
- (setq ex-file "~"))
- (setq default-directory (file-name-as-directory (expand-file-name ex-file))))
-
-;; Ex copy and move command. DEL-FLAG means delete
-(defun ex-copy (del-flag)
- (viper-default-ex-addresses)
- (let ((address (viper-get-ex-address))
- (end (car ex-addresses)) (beg (car (cdr ex-addresses))))
- (goto-char end)
- (save-excursion
- (push-mark beg t)
- (viper-enlarge-region (mark t) (point))
- (if del-flag
- (kill-region (point) (mark t))
- (copy-region-as-kill (point) (mark t)))
- (if ex-flag
- (progn
- (with-output-to-temp-buffer " *copy text*"
- (princ
- (if (or del-flag ex-g-flag ex-g-variant)
- (current-kill 0)
- (buffer-substring (point) (mark t)))))
- (condition-case nil
- (progn
- (read-string "[Hit return to confirm] ")
- (save-excursion (kill-buffer " *copy text*")))
- (quit (save-excursion (kill-buffer " *copy text*"))
- (signal 'quit nil))))))
- (if (= address 0)
- (goto-char (point-min))
- (goto-char address)
- (forward-line 1))
- (insert (current-kill 0))))
-
-(declare-function viper-append-to-register "viper-cmd" (reg start end))
-
-;; Ex delete command
-(defun ex-delete ()
- (viper-default-ex-addresses)
- (viper-get-ex-buffer)
- (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))))
- (if (> beg end) (error viper-FirstAddrExceedsSecond))
- (save-excursion
- (viper-enlarge-region beg end)
- (exchange-point-and-mark)
- (if ex-count
- (progn
- (set-mark (point))
- (forward-line (1- ex-count)))
- (set-mark end))
- (viper-enlarge-region (point) (mark t))
- (if ex-flag
- ;; show text to be deleted and ask for confirmation
- (progn
- (with-output-to-temp-buffer " *delete text*"
- (princ (buffer-substring (point) (mark t))))
- (condition-case nil
- (read-string "[Hit return to confirm] ")
- (quit
- (save-excursion (kill-buffer " *delete text*"))
- (user-error viper-ViperBell)))
- (save-excursion (kill-buffer " *delete text*")))
- (if ex-buffer
- (cond ((viper-valid-register ex-buffer '(Letter))
- (viper-append-to-register
- (downcase ex-buffer) (point) (mark t)))
- ((viper-valid-register ex-buffer)
- (copy-to-register ex-buffer (point) (mark t) nil))
- (t (error viper-InvalidRegister ex-buffer))))
- (kill-region (point) (mark t))))))
-
-
-(declare-function viper-change-state-to-vi "viper-cmd" (&rest _))
-
-;; Ex edit command
-;; In Viper, `e' and `e!' behave identically. In both cases, the user is
-;; asked if current buffer should really be discarded.
-;; This command can take multiple file names. It replaces the current buffer
-;; with the first file in its argument list
-(defun ex-edit (&optional file)
- (if (not file)
- (viper-get-ex-file))
- (cond ((and (string= ex-file "") buffer-file-name)
- (setq ex-file (abbreviate-file-name (buffer-file-name))))
- ((string= ex-file "")
- (error viper-NoFileSpecified)))
-
- (let (msg do-edit)
- (if buffer-file-name
- (cond ((buffer-modified-p)
- (setq msg
- (format "Buffer %s is modified. Discard changes? "
- (buffer-name))
- do-edit t))
- ((not (verify-visited-file-modtime (current-buffer)))
- (setq msg
- (format "File %s changed on disk. Reread from disk? "
- buffer-file-name)
- do-edit t))
- (t (setq do-edit nil))))
-
- (if do-edit
- (if (yes-or-no-p msg)
- (progn
- (set-buffer-modified-p nil)
- (kill-buffer (current-buffer)))
- (message "Buffer %s was left intact" (buffer-name))))
- ) ; let
-
- (if (null (setq file (get-file-buffer ex-file)))
- (progn
- ;; this also does shell-style globbing
- (ex-find-file
- ;; replace # and % with the previous/current file
- (ex-expand-filsyms ex-file (current-buffer)))
- (or (eq major-mode 'dired-mode)
- (viper-change-state-to-vi))
- (goto-char (point-min)))
- (switch-to-buffer file))
- (if ex-offset
- (progn
- (with-current-buffer (setq viper-ex-work-buf
- (get-buffer-create viper-ex-work-buf-name))
- (delete-region (point-min) (point-max))
- (insert ex-offset "\n")
- (goto-char (point-min)))
- (goto-char (viper-get-ex-address))
- (beginning-of-line)))
- (ex-fixup-history viper-last-ex-prompt ex-file))
-
-;; Find-file FILESPEC if it appears to specify a single file.
-;; Otherwise, assume that FILESPEC is a wildcard.
-;; In this case, split it into substrings separated by newlines.
-;; Each line is assumed to be a file name.
-(defun ex-find-file (filespec)
- (let ((nonstandard-filename-chars "[^-a-zA-Z0-9_./,~$\\]"))
- (cond ((file-exists-p filespec) (find-file filespec))
- ((string-match nonstandard-filename-chars filespec)
- (mapcar #'find-file (funcall viper-glob-function filespec)))
- (t (find-file filespec)))
- ))
-
-
-(declare-function viper-backward-char-carefully "viper-cmd" (&optional arg))
-
-;; Ex global command
-;; This is executed in response to:
-;; :global "pattern" ex-command
-;; :vglobal "pattern" ex-command
-;; :global executes ex-command on all lines matching <pattern>
-;; :vglobal executes ex-command on all lines that don't match <pattern>
-;;
-;; With VARIANT nil, this functions executes :global
-;; With VARIANT t, executes :vglobal
-(defun ex-global (variant)
- (let ((gcommand ex-token))
- (if (or ex-g-flag ex-g-variant)
- (error "`%s' within `global' is not allowed" gcommand)
- (if variant
- (setq ex-g-flag nil
- ex-g-variant t)
- (setq ex-g-flag t
- ex-g-variant nil)))
- (viper-get-ex-pat)
- (if (null ex-token)
- (error "`%s': Missing regular expression" gcommand)))
-
- (if (string= ex-token "")
- (if (null viper-s-string)
- (error viper-NoPrevSearch)
- (setq ex-g-pat viper-s-string))
- (setq ex-g-pat ex-token
- viper-s-string ex-token))
- (if (null ex-addresses)
- (setq ex-addresses (list (point-max) (point-min)))
- (viper-default-ex-addresses))
- (setq ex-g-marks nil)
- (let ((mark-count 0)
- (end (car ex-addresses))
- (beg (car (cdr ex-addresses)))
- com-str)
- (if (> beg end) (error viper-FirstAddrExceedsSecond))
- (save-excursion
- (viper-enlarge-region beg end)
- (exchange-point-and-mark)
- (let ((cont t) (limit (point-marker)))
- (exchange-point-and-mark)
- ;; skip the last line if empty
- (beginning-of-line)
- (if (eobp) (viper-backward-char-carefully))
- (while (and cont (not (bobp)) (>= (point) limit))
- (beginning-of-line)
- (set-mark (point))
- (end-of-line)
- (let ((found (re-search-backward ex-g-pat (mark t) t)))
- (if (or (and ex-g-flag found)
- (and ex-g-variant (not found)))
- (progn
- (end-of-line)
- (setq mark-count (1+ mark-count))
- (setq ex-g-marks (cons (point-marker) ex-g-marks)))))
- (beginning-of-line)
- (if (bobp) (setq cont nil)
- (forward-line -1)
- (end-of-line)))))
- (with-current-buffer (setq viper-ex-work-buf
- (get-buffer-create viper-ex-work-buf-name))
- ;; com-str is the command string, i.e., g/pattern/ or v/pattern'
- (setq com-str (buffer-substring (1+ (point)) (1- (point-max)))))
- (while ex-g-marks
- (goto-char (car ex-g-marks))
- (viper-ex nil com-str)
- (setq mark-count (1- mark-count))
- (setq ex-g-marks (cdr ex-g-marks)))))
-
-;; Ex goto command
-(defun ex-goto ()
- (if (null ex-addresses)
- (setq ex-addresses (cons (point) nil)))
- (push-mark (point) t)
- (goto-char (car ex-addresses))
- (beginning-of-line)
- )
-
-;; Ex line commands. COM is join, shift-right or shift-left
-(defun ex-line (com)
- (viper-default-ex-addresses)
- (viper-get-ex-count)
- (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))) point)
- (if (> beg end) (error viper-FirstAddrExceedsSecond))
- (save-excursion
- (viper-enlarge-region beg end)
- (exchange-point-and-mark)
- (if ex-count
- (progn
- (set-mark (point))
- (forward-line ex-count)))
- (if ex-flag
- ;; show text to be joined and ask for confirmation
- (progn
- (with-output-to-temp-buffer " *join text*"
- (princ (buffer-substring (point) (mark t))))
- (condition-case nil
- (progn
- (read-string "[Hit return to confirm] ")
- (ex-line-subr com (point) (mark t)))
- (quit (ding)))
- (save-excursion (kill-buffer " *join text*")))
- (ex-line-subr com (point) (mark t)))
- (setq point (point)))
- (goto-char (1- point))
- (beginning-of-line)))
-
-(declare-function viper-forward-char-carefully "viper-cmd" (&optional arg))
-
-(defun ex-line-subr (com beg end)
- (cond ((string= com "join")
- (goto-char (min beg end))
- (while (and (not (eobp)) (< (point) (max beg end)))
- (end-of-line)
- (if (and (<= (point) (max beg end)) (not (eobp)))
- (progn
- (forward-line 1)
- (delete-region (point) (1- (point)))
- (if (not ex-variant) (fixup-whitespace))))))
- ((or (string= com "right") (string= com "left"))
- (indent-rigidly
- (min beg end) (max beg end)
- (if (string= com "right") viper-shift-width (- viper-shift-width)))
- (goto-char (max beg end))
- (end-of-line)
- (viper-forward-char-carefully))))
-
-
-;; Ex mark command
-;; Sets the mark to the current point.
-;; If name is omitted, get the name straight from the work buffer."
-(defun ex-mark (&optional name)
- (let (char)
- (if (null ex-addresses)
- (setq ex-addresses
- (cons (point) nil)))
- (if name
- (if (eq 1 (length name))
- (setq char (string-to-char name))
- (error "`%s': Spurious text \"%s\" after mark name"
- name (substring name 1)))
- (with-current-buffer (setq viper-ex-work-buf
- (get-buffer-create viper-ex-work-buf-name))
- (skip-chars-forward " \t")
- (if (looking-at "[a-z]")
- (progn
- (setq char (following-char))
- (forward-char 1)
- (skip-chars-forward " \t")
- (if (not (looking-at "[\n|]"))
- (error "`%s': %s" ex-token viper-SpuriousText)))
- (error "`%s' requires a following letter" ex-token))))
- (save-excursion
- (goto-char (car ex-addresses))
- (point-to-register (1+ (- char ?a))))))
-
-
-
-;; Alternate file is the file next to the first one in the buffer ring
-(defun ex-next (cycle-other-window &optional find-alt-file)
- (catch 'ex-edit
- (let (count l)
- (if (not find-alt-file)
- (progn
- (viper-get-ex-file)
- (if (or (char-or-string-p ex-offset)
- (and (not (string= "" ex-file))
- (not (string-match "^[0-9]+$" ex-file))))
- (progn
- (ex-edit t)
- (throw 'ex-edit nil))
- (setq count (string-to-number ex-file))
- (if (= count 0) (setq count 1))
- (if (< count 0) (error "Usage: `next <count>' (count >= 0)"))))
- (setq count 1))
- (setq l (viper-undisplayed-files))
- (while (> count 0)
- (while (and (not (null l)) (null (car l)))
- (setq l (cdr l)))
- (setq count (1- count))
- (if (> count 0)
- (setq l (cdr l))))
- (if find-alt-file (car l)
- (progn
- (if (and (car l) (get-file-buffer (car l)))
- (let* ((w (if cycle-other-window
- (get-lru-window) (selected-window)))
- (b (window-buffer w)))
- (set-window-buffer w (get-file-buffer (car l)))
- (bury-buffer b)
- ;; this puts "next <count>" in the ex-command history
- (ex-fixup-history viper-last-ex-prompt ex-file))
- (error "Not that many undisplayed files")))))))
-
-
-(defun ex-next-related-buffer (direction &optional no-recursion)
-
- (viper-ring-rotate1 viper-related-files-and-buffers-ring direction)
-
- (let ((file-or-buffer-name
- (viper-current-ring-item viper-related-files-and-buffers-ring))
- (old-ring viper-related-files-and-buffers-ring)
- (old-win (selected-window))
- skip-rest buf wind)
-
- (or (and (ring-p viper-related-files-and-buffers-ring)
- (> (ring-length viper-related-files-and-buffers-ring) 0))
- (error "This buffer has no related files or buffers"))
-
- (or (stringp file-or-buffer-name)
- (error
- "File and buffer names must be strings, %S" file-or-buffer-name))
-
- (setq buf (cond ((get-buffer file-or-buffer-name))
- ((file-exists-p file-or-buffer-name)
- (find-file-noselect file-or-buffer-name))
- ))
-
- (if (not (viper-buffer-live-p buf))
- (error "Didn't find buffer %S or file %S"
- file-or-buffer-name
- (abbreviate-file-name
- (expand-file-name file-or-buffer-name))))
-
- (if (equal buf (current-buffer))
- (or no-recursion
- ;; try again
- (progn
- (setq skip-rest t)
- (ex-next-related-buffer direction 'norecursion))))
-
- (if skip-rest
- ()
- ;; setup buffer
- (if (setq wind (get-buffer-window buf 'visible))
- ()
- (setq wind (get-lru-window 'visible))
- (set-window-buffer wind buf))
-
- (if (viper-window-display-p)
- (progn
- (raise-frame (window-frame wind))
- (if (equal (window-frame wind) (window-frame old-win))
- (save-window-excursion (select-window wind) (sit-for 1))
- (select-window wind)))
- (save-window-excursion (select-window wind) (sit-for 1)))
-
- (with-current-buffer buf
- (setq viper-related-files-and-buffers-ring old-ring))
-
- (setq viper-local-search-start-marker (point-marker))
- )))
-
-
-;; Force auto save
-(defun ex-preserve ()
- (message "Autosaving all buffers that need to be saved...")
- (do-auto-save t))
-
-(declare-function viper-Put-back "viper-cmd" (arg))
-(declare-function viper-put-back "viper-cmd" (arg))
-
-;; Ex put
-(defun ex-put ()
- (let ((point (if (null ex-addresses) (point) (car ex-addresses))))
- (viper-get-ex-buffer)
- (setq viper-use-register ex-buffer)
- (goto-char point)
- (if (bobp) (viper-Put-back 1) (viper-put-back 1))))
-
-;; Ex print working directory
-(defun ex-pwd ()
- (message "%s" default-directory))
-
-;; Ex quit command
-(defun ex-quit ()
- ;; skip "!", if it is q!. In Viper q!, w!, etc., behave as q, w, etc.
- (with-current-buffer (setq viper-ex-work-buf
- (get-buffer-create viper-ex-work-buf-name))
- (when (= (following-char) ?!) (forward-char 1)))
- (if (< viper-expert-level 3)
- (save-buffers-kill-emacs)
- (kill-buffer (current-buffer))))
-
-
-(declare-function viper-add-newline-at-eob-if-necessary "viper-cmd" ())
-
-;; Ex read command
-;; ex-read doesn't support wildcards, because file completion is a better
-;; mechanism. We also don't support # and % (except in :r <shell-command>
-;; because file history is a better mechanism.
-(defun ex-read ()
- (viper-get-ex-file)
- (let ((point (if (null ex-addresses) (point) (car ex-addresses)))
- command)
- (goto-char point)
- (viper-add-newline-at-eob-if-necessary)
- (if (not (or (bobp) (eobp))) (forward-line 1))
- (if (and (not ex-variant) (string= ex-file ""))
- (progn
- (if (null buffer-file-name)
- (error viper-NoFileSpecified))
- (setq ex-file buffer-file-name)))
- (if ex-cmdfile
- (progn
- (setq command
- ;; replace # and % with the previous/current file
- (ex-expand-filsyms
- (concat (shell-quote-argument ex-file) ex-cmdfile-args)
- (current-buffer)))
- (shell-command command t))
- (insert-file-contents ex-file)))
- (ex-fixup-history viper-last-ex-prompt ex-file ex-cmdfile-args))
-
-;; this function fixes ex-history for some commands like ex-read, ex-edit
-(defun ex-fixup-history (&rest args)
- (setq viper-ex-history
- (cons (mapconcat #'identity args " ") (cdr viper-ex-history))))
-
-
-;; Ex recover from emacs \#file\#
-(defun ex-recover ()
- (viper-get-ex-file)
- (if (or ex-append ex-offset)
- (error "`recover': %s" viper-SpuriousText))
- (if (string= ex-file "")
- (progn
- (if (null buffer-file-name)
- (error "This buffer isn't visiting any file"))
- (setq ex-file buffer-file-name))
- (setq ex-file (expand-file-name ex-file)))
- (if (and (not (string= ex-file (buffer-file-name)))
- (buffer-modified-p)
- (not ex-variant))
- (error "No write since last change (:rec! overrides)"))
- (recover-file ex-file))
-
-;; Tell that `rewind' is obsolete and to use `:next count' instead
-(defun ex-rewind ()
- (message
- "Use `:n <count>' instead. Counts are obtained from the `:args' command"))
-
-
-;; read variable name for ex-set
-(defun ex-set-read-variable ()
- (let ((minibuffer-local-completion-map
- (copy-keymap minibuffer-local-completion-map))
- (cursor-in-echo-area t)
- str batch)
- (define-key
- minibuffer-local-completion-map " " #'minibuffer-complete-and-exit)
- (define-key minibuffer-local-completion-map "=" #'exit-minibuffer)
- (if (viper-set-unread-command-events
- (ex-get-inline-cmd-args "[ \t]*[a-zA-Z]*[ \t]*" nil "\C-m"))
- (progn
- (setq batch t)
- (viper-set-unread-command-events ?\C-m)))
- (message ":set <Variable> [= <Value>]")
- (or batch (sit-for 2))
-
- (while (string-match "^[ \t\n]*$"
- (setq str
- (completing-read ":set " ex-variable-alist)))
- (message ":set <Variable> [= <Value>]")
- ;; if there are unread events, don't wait
- (or (viper-set-unread-command-events "") (sit-for 2))
- ) ; while
- str))
-
-
-(defun ex-set ()
- (let ((var (ex-set-read-variable))
- (val 0)
- (set-cmd "setq")
- (ask-if-save t)
- (auto-cmd-label "; don't touch or else...")
- (delete-turn-on-auto-fill-pattern
- "([ \t]*add-hook[ \t]+'viper-insert-state-hook[ \t]+'turn-on-auto-fill.*)")
- actual-lisp-cmd lisp-cmd-del-pattern
- val2 orig-var)
- (setq orig-var var)
- (cond ((string= var "all")
- (setq ask-if-save nil
- set-cmd nil))
- ((member var '("ai" "autoindent"))
- (setq var "viper-auto-indent"
- set-cmd "setq"
- ask-if-save nil
- val "t"))
- ((member var '("ai-g" "autoindent-global"))
- (kill-local-variable 'viper-auto-indent)
- (setq var "viper-auto-indent"
- set-cmd "setq-default"
- val "t"))
- ((member var '("noai" "noautoindent"))
- (setq var "viper-auto-indent"
- ask-if-save nil
- val "nil"))
- ((member var '("noai-g" "noautoindent-global"))
- (kill-local-variable 'viper-auto-indent)
- (setq var "viper-auto-indent"
- set-cmd "setq-default"
- val "nil"))
- ((member var '("ic" "ignorecase"))
- (setq var "viper-case-fold-search"
- val "t"))
- ((member var '("noic" "noignorecase"))
- (setq var "viper-case-fold-search"
- val "nil"))
- ((member var '("ma" "magic"))
- (setq var "viper-re-search"
- val "t"))
- ((member var '("noma" "nomagic"))
- (setq var "viper-re-search"
- val "nil"))
- ((member var '("ro" "readonly"))
- (setq var "buffer-read-only"
- val "t"))
- ((member var '("noro" "noreadonly"))
- (setq var "buffer-read-only"
- val "nil"))
- ((member var '("sm" "showmatch"))
- (setq var "blink-matching-paren"
- val "t"))
- ((member var '("nosm" "noshowmatch"))
- (setq var "blink-matching-paren"
- val "nil"))
- ((member var '("ws" "wrapscan"))
- (setq var "viper-search-wrap-around"
- val "t"))
- ((member var '("nows" "nowrapscan"))
- (setq var "viper-search-wrap-around"
- val "nil")))
- (if (and set-cmd (eq val 0)) ; value must be set by the user
- (let ((cursor-in-echo-area t))
- (message ":set %s = <Value>" var)
- ;; if there are unread events, don't wait
- (or (viper-set-unread-command-events "") (sit-for 2))
- (setq val (read-string (format ":set %s = " var)))
- (ex-fixup-history "set" orig-var val)
-
- ;; check numerical values
- (if (member var
- '("sw" "shiftwidth"
- "ts" "tabstop"
- "ts-g" "tabstop-global"
- "wm" "wrapmargin"))
- (condition-case nil
- (or (numberp (setq val2 (car (read-from-string val))))
- (error "%s: Invalid value, numberp, %S" var val))
- (error
- (error "%s: Invalid value, numberp, %S" var val))))
-
- (cond
- ((member var '("sw" "shiftwidth"))
- (setq var "viper-shift-width"))
- ((member var '("ts" "tabstop"))
- ;; make it take effect in curr buff and new bufs
- (setq var "tab-width"
- set-cmd "setq"
- ask-if-save nil))
- ((member var '("ts-g" "tabstop-global"))
- (kill-local-variable 'tab-width)
- (setq var "tab-width"
- set-cmd "setq-default"))
- ((member var '("wm" "wrapmargin"))
- ;; make it take effect in curr buff and new bufs
- (kill-local-variable 'fill-column)
- (setq var "fill-column"
- val (format "(- (window-width) %s)" val)
- set-cmd "setq-default"))
- ((member var '("sh" "shell"))
- (setq var "explicit-shell-file-name"
- val (format "\"%s\"" val)))))
- (ex-fixup-history "set" orig-var))
-
- (if set-cmd
- (setq actual-lisp-cmd
- (format "\n(%s %s %s) %s" set-cmd var val auto-cmd-label)
- lisp-cmd-del-pattern
- (format "^\n?[ \t]*([ \t]*%s[ \t]+%s[ \t].*)[ \t]*%s"
- set-cmd var auto-cmd-label)))
-
- (if (and ask-if-save
- (y-or-n-p (format "Do you want to save this setting in %s?"
- viper-custom-file-name)))
- (progn
- (viper-save-string-in-file
- actual-lisp-cmd viper-custom-file-name
- ;; del pattern
- lisp-cmd-del-pattern)
- (if (string= var "fill-column")
- (if (> val2 0)
- (viper-save-string-in-file
- (concat
- "(add-hook 'viper-insert-state-hook 'turn-on-auto-fill) "
- auto-cmd-label)
- viper-custom-file-name
- delete-turn-on-auto-fill-pattern)
- (viper-save-string-in-file
- nil viper-custom-file-name delete-turn-on-auto-fill-pattern)
- (viper-save-string-in-file
- nil viper-custom-file-name
- ;; del pattern
- lisp-cmd-del-pattern)
- ))
- ))
-
- (if set-cmd
- (message "%s %s %s"
- set-cmd var
- (if (string-match "^[ \t]*$" val)
- (format "%S" val)
- val)))
- (if actual-lisp-cmd
- (eval (car (read-from-string actual-lisp-cmd)) t))
- (if (string= var "fill-column")
- (if (> val2 0)
- (auto-fill-mode 1)
- (auto-fill-mode -1)))
- (if (string= var "all") (ex-show-vars))
- ))
-
-;; In inline args, skip regex-forw and (optionally) chars-back.
-;; Optional 3d arg is a string that should replace ' ' to prevent its
-;; special meaning
-(defun ex-get-inline-cmd-args (regex-forw &optional chars-back replace-str)
- (with-current-buffer (setq viper-ex-work-buf
- (get-buffer-create viper-ex-work-buf-name))
- (goto-char (point-min))
- (re-search-forward regex-forw nil t)
- (let ((beg (point))
- end)
- (goto-char (point-max))
- (if chars-back
- (skip-chars-backward chars-back)
- (skip-chars-backward " \t\n\C-m"))
- (setq end (point))
- ;; replace SPC with `=' to suppress the special meaning SPC has
- ;; in Ex commands
- (goto-char beg)
- (if replace-str
- (while (re-search-forward " +" nil t)
- (replace-match replace-str nil t)
- (viper-forward-char-carefully)))
- (goto-char end)
- (buffer-substring beg end))))
-
-
-;; Ex shell command
-(defun ex-shell ()
- (shell))
-
-;; Viper help. Invokes Info
-(defun ex-help ()
- (condition-case nil
- (progn
- (pop-to-buffer (get-buffer-create "*info*"))
- (info "viper")
- (message "Type `i' to search for a specific topic"))
- (error (beep 1)
- (with-output-to-temp-buffer " *viper-info*"
- (princ "
-The Info file for Viper does not seem to be installed.
-
-This file is part of the standard distribution of Emacs.
-Please contact your system administrator. ")))))
-
-;; Ex source command.
-;; Loads the file specified as argument or viper-custom-file-name.
-(defun ex-source ()
- (viper-get-ex-file)
- (if (string= ex-file "")
- (load viper-custom-file-name)
- (load ex-file)))
-
-;; Ex substitute command
-;; If REPEAT use previous regexp which is ex-reg-exp or viper-s-string
-(defun ex-substitute (&optional repeat r-flag)
- (let ((opt-g nil)
- (opt-c nil)
- (matched-pos nil)
- (case-fold-search viper-case-fold-search)
- delim pat repl)
- (if repeat (setq ex-token nil) (setq delim (viper-get-ex-pat)))
- (if (null ex-token)
- (progn
- (setq pat (if r-flag viper-s-string ex-reg-exp))
- (or (stringp pat)
- (error "No previous pattern to use in substitution"))
- (setq repl ex-repl
- delim (string-to-char pat)))
- (setq pat (if (string= ex-token "") viper-s-string ex-token))
- (setq viper-s-string pat
- ex-reg-exp pat)
- (setq delim (viper-get-ex-pat))
- (if (null ex-token)
- (setq ex-token ""
- ex-repl "")
- (setq repl ex-token
- ex-repl ex-token)))
- (while (viper-get-ex-opt-gc delim)
- (if (string= ex-token "g") (setq opt-g t) (setq opt-c t)))
- (viper-get-ex-count)
- (if ex-count
- (save-excursion
- (if ex-addresses (goto-char (car ex-addresses)))
- (set-mark (point))
- (forward-line (1- ex-count))
- (setq ex-addresses (cons (point) (cons (mark t) nil))))
- (if (null ex-addresses)
- (setq ex-addresses (cons (point) (cons (point) nil)))
- (if (null (cdr ex-addresses))
- (setq ex-addresses (cons (car ex-addresses) ex-addresses)))))
- ;(setq G opt-g)
- (let ((beg (car ex-addresses))
- (end (car (cdr ex-addresses)))
- eol-mark)
- (save-excursion
- (viper-enlarge-region beg end)
- (let ((limit (save-excursion
- (goto-char (max (point) (mark t)))
- (point-marker))))
- (goto-char (min (point) (mark t)))
- (while (< (point) limit)
- (save-excursion
- (end-of-line)
- ;; This move allows the use of newline as the last character in
- ;; the substitution pattern
- (viper-forward-char-carefully)
- (setq eol-mark (point-marker)))
- (beginning-of-line)
- (if opt-g
- (progn
- (while (and (not (eolp))
- (re-search-forward pat eol-mark t))
- (if (or (not opt-c)
- (progn
- (viper-put-on-search-overlay (match-beginning 0)
- (match-end 0))
- (y-or-n-p "Replace? ")))
- (progn
- (viper-hide-search-overlay)
- (setq matched-pos (point))
- (if (not (stringp repl))
- (error "Can't perform Ex substitution: No previous replacement pattern"))
- (replace-match repl t))))
- (end-of-line)
- (viper-forward-char-carefully))
- (if (null pat)
- (error
- "Can't repeat Ex substitution: No previous regular expression"))
- (if (and (re-search-forward pat eol-mark t)
- (or (not opt-c)
- (progn
- (viper-put-on-search-overlay (match-beginning 0)
- (match-end 0))
- (y-or-n-p "Replace? "))))
- (progn
- (viper-hide-search-overlay)
- (setq matched-pos (point))
- (if (not (stringp repl))
- (error "Can't perform Ex substitution: No previous replacement pattern"))
- (replace-match repl t)))
- ;;(end-of-line)
- ;;(viper-forward-char-carefully)
- (goto-char eol-mark)
- )))))
- (if matched-pos (goto-char matched-pos))
- (beginning-of-line)
- (if opt-c (message "done"))))
-
-(declare-function viper-change-state-to-emacs "viper-cmd" (&rest _))
-
-;; Ex tag command
-(defun ex-tag ()
- (let (tag)
- (with-current-buffer (setq viper-ex-work-buf
- (get-buffer-create viper-ex-work-buf-name))
- (skip-chars-forward " \t")
- (set-mark (point))
- (skip-chars-forward "^ |\t\n")
- (setq tag (buffer-substring (mark t) (point))))
- (if (not (string= tag "")) (setq ex-tag tag))
- (viper-change-state-to-emacs)
- (condition-case conds
- (progn
- (if (string= tag "")
- ;; If we have an *xref* window, `next-error' will take
- ;; us to the next definition.
- (next-error)
- (xref-find-definitions-other-window ex-tag))
- (viper-change-state-to-vi))
- (error
- (viper-change-state-to-vi)
- (viper-message-conditions conds)))))
-
-;; Ex write command
-;; ex-write doesn't support wildcards, because file completion is a better
-;; mechanism. We also don't support # and %
-;; because file history is a better mechanism.
-(defun ex-write (q-flag)
- (viper-default-ex-addresses t)
- (viper-get-ex-file)
- (let ((end (car ex-addresses))
- (beg (car (cdr ex-addresses)))
- (orig-buf (current-buffer))
- ;;(orig-buf-file-name (buffer-file-name))
- ;;(orig-buf-name (buffer-name))
- ;;(buff-changed-p (buffer-modified-p))
- temp-buf writing-same-file region
- file-exists writing-whole-file)
- (if (> beg end) (error viper-FirstAddrExceedsSecond))
- (if ex-cmdfile
- (progn
- (viper-enlarge-region beg end)
- (shell-command-on-region (point) (mark t)
- (concat ex-file ex-cmdfile-args)))
- (if (and (string= ex-file "") (not (buffer-file-name)))
- (setq ex-file
- (read-file-name
- (format "Buffer %s isn't visiting any file. File to save in: "
- (buffer-name)))))
-
- (setq writing-whole-file (and (= (point-min) beg) (= (point-max) end))
- ex-file (if (string= ex-file "")
- (buffer-file-name)
- (expand-file-name ex-file)))
- ;; if ex-file is a directory use the file portion of the buffer file name
- (if (and (file-directory-p ex-file)
- buffer-file-name
- (not (file-directory-p buffer-file-name)))
- (setq ex-file
- (concat (file-name-as-directory ex-file)
- (file-name-nondirectory buffer-file-name))))
-
- (setq file-exists (file-exists-p ex-file)
- writing-same-file (string= ex-file (buffer-file-name)))
-
- ;; do actual writing
- (if (and writing-whole-file writing-same-file)
- ;; saving whole buffer in visited file
- (if (not (buffer-modified-p))
- (message "(No changes need to be saved)")
- (viper-maybe-checkout (current-buffer))
- (save-buffer)
- (save-restriction
- (widen)
- (ex-write-info file-exists ex-file (point-min) (point-max))
- ))
- ;; writing to non-visited file and it already exists
- (if (and file-exists (not writing-same-file)
- (not (yes-or-no-p
- (format "File %s exists. Overwrite? " ex-file))))
- (error "Quit"))
- ;; writing a region or whole buffer to non-visited file
- (unwind-protect
- (save-excursion
- (viper-enlarge-region beg end)
- (setq region (buffer-substring (point) (mark t)))
- ;; create temp buffer for the region
- (setq temp-buf (get-buffer-create " *ex-write*"))
- (set-buffer temp-buf)
- (set-visited-file-name ex-file 'noquery)
- (erase-buffer)
- (if (and file-exists ex-append)
- (insert-file-contents ex-file))
- (goto-char (point-max))
- (insert region)
- ;; ask user
- (viper-maybe-checkout (current-buffer))
- (setq selective-display nil)
- (save-buffer)
- (ex-write-info
- file-exists ex-file (point-min) (point-max))
- )
- ;; this must be under unwind-protect so that
- ;; temp-buf will be deleted in case of an error
- (set-buffer temp-buf)
- (set-buffer-modified-p nil)
- (kill-buffer temp-buf)
- ;; buffer/region has been written, now take care of details
- (set-buffer orig-buf)))
- ;; set the right file modification time
- (if (and (buffer-file-name) writing-same-file)
- (set-visited-file-modtime))
- ;; prevent loss of data if saving part of the buffer in visited file
- (or writing-whole-file
- (not writing-same-file)
- (progn
- (sit-for 2)
- (message "Warning: you have saved only part of the buffer!")
- (set-buffer-modified-p t)))
- (if q-flag
- (if (< viper-expert-level 2)
- (save-buffers-kill-emacs)
- (kill-buffer (current-buffer))))
- )))
-
-
-(defun ex-write-info (exists file-name beg end)
- (message "`%s'%s %d lines, %d characters"
- (abbreviate-file-name file-name)
- (if exists "" " [New file]")
- (count-lines beg (min (1+ end) (point-max)))
- (- end beg)))
-
-;; Ex yank command
-(defun ex-yank ()
- (viper-default-ex-addresses)
- (viper-get-ex-buffer)
- (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))))
- (if (> beg end) (error viper-FirstAddrExceedsSecond))
- (save-excursion
- (viper-enlarge-region beg end)
- (exchange-point-and-mark)
- (if (or ex-g-flag ex-g-variant)
- (error "Can't execute `yank' within `global'"))
- (if ex-count
- (progn
- (set-mark (point))
- (forward-line (1- ex-count)))
- (set-mark end))
- (viper-enlarge-region (point) (mark t))
- (if ex-flag (error "`yank': %s" viper-SpuriousText))
- (if ex-buffer
- (cond ((viper-valid-register ex-buffer '(Letter))
- (viper-append-to-register
- (downcase ex-buffer) (point) (mark t)))
- ((viper-valid-register ex-buffer)
- (copy-to-register ex-buffer (point) (mark t) nil))
- (t (error viper-InvalidRegister ex-buffer))))
- (copy-region-as-kill (point) (mark t)))))
-
-;; Execute shell command
-(defun ex-command ()
- (let (command)
- (with-current-buffer (setq viper-ex-work-buf
- (get-buffer-create viper-ex-work-buf-name))
- (skip-chars-forward " \t")
- (setq command (buffer-substring (point) (point-max)))
- (end-of-line))
- ;; replace # and % with the previous/current file
- (setq command (ex-expand-filsyms command (current-buffer)))
- (if (and (> (length command) 0) (string= "!" (substring command 0 1)))
- (if viper-ex-last-shell-com
- (setq command
- (concat viper-ex-last-shell-com (substring command 1)))
- (error "No previous shell command")))
- (setq viper-ex-last-shell-com command)
- (if (null ex-addresses)
- (shell-command command)
- (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))))
- (if (null beg) (setq beg end))
- (save-excursion
- (goto-char beg)
- (set-mark end)
- (viper-enlarge-region (point) (mark t))
- (shell-command-on-region (point) (mark t) command t t))
- (goto-char beg)))))
-
-(defun ex-compile ()
- "Read args from the command line, then run make with the args.
-If no args are given, then it runs the last compile command.
-Type `mak ' (including the space) to run make with no args."
- (let (args)
- (with-current-buffer (setq viper-ex-work-buf
- (get-buffer-create viper-ex-work-buf-name))
- (setq args (buffer-substring (point) (point-max)))
- (end-of-line))
- ;; Remove the newline that may (will?) be at the end of the args
- (if (string= "\n" (substring args (1- (length args))))
- (setq args (substring args 0 (1- (length args)))))
- ;; Run last command if no args given, else construct a new command.
- (setq args
- (if (string= "" args)
- (if (boundp 'compile-command)
- compile-command
- ex-compile-command)
- (concat ex-compile-command " " args)))
- (compile args)
- ))
-
-;; Print line number
-(defun ex-line-no ()
- (message "%d"
- (1+ (count-lines
- (point-min)
- (if (null ex-addresses) (point-max) (car ex-addresses))))))
-
-;; Give information on the file visited by the current buffer
-(defun viper-info-on-file ()
- (interactive)
- (let ((pos1 (viper-line-pos 'start))
- (pos2 (viper-line-pos 'end))
- lines file info)
- (setq lines (count-lines (point-min) (viper-line-pos 'end))
- file (cond ((buffer-file-name)
- (concat (abbreviate-file-name (buffer-file-name)) ":"))
- ((buffer-file-name (buffer-base-buffer))
- (concat (abbreviate-file-name (buffer-file-name (buffer-base-buffer))) " (indirect buffer):"))
- (t (concat (buffer-name) " [Not visiting any file]:")))
- info (format "line=%d/%d pos=%d/%d col=%d %s"
- (if (= pos1 pos2)
- (1+ lines)
- lines)
- (count-lines (point-min) (point-max))
- (point) (1- (point-max))
- (1+ (current-column))
- (if (buffer-modified-p) "[Modified]" "[Unchanged]")))
- (if (< (+ 1 (length info) (length file))
- (window-width (minibuffer-window)))
- (message "%s" (concat file " " info))
- (save-window-excursion
- (with-output-to-temp-buffer " *viper-info*"
- (princ (concat "\n" file "\n\n\t" info "\n\n")))
- (let ((inhibit-quit t))
- (viper-set-unread-command-events (read-event)))
- (kill-buffer " *viper-info*")))
- ))
-
-
-;; Without arguments displays info on file. With an arg, sets the visited file
-;; name to that arg
-(defun ex-set-visited-file-name ()
- (viper-get-ex-file)
- (if (string= ex-file "")
- (viper-info-on-file)
- ;; If ex-file is a directory, use the file portion of the buffer
- ;; file name (like ex-write). Do this even if ex-file is a
- ;; non-existent directory, since set-visited-file-name signals an
- ;; error on this condition, too.
- (if (and (string= (file-name-nondirectory ex-file) "")
- buffer-file-name
- (not (file-directory-p buffer-file-name)))
- (setq ex-file (concat (file-name-as-directory ex-file)
- (file-name-nondirectory buffer-file-name))))
- (set-visited-file-name ex-file)))
-
-
-;; display all variables set through :set
-(defun ex-show-vars ()
- (with-output-to-temp-buffer " *viper-info*"
- (princ (if viper-auto-indent
- "autoindent (local)\n" "noautoindent (local)\n"))
- (princ (if (default-value 'viper-auto-indent)
- "autoindent (global) \n" "noautoindent (global) \n"))
- (princ (if viper-case-fold-search "ignorecase\n" "noignorecase\n"))
- (princ (if viper-re-search "magic\n" "nomagic\n"))
- (princ (if buffer-read-only "readonly\n" "noreadonly\n"))
- (princ (if blink-matching-paren "showmatch\n" "noshowmatch\n"))
- (princ (if viper-search-wrap-around "wrapscan\n" "nowrapscan\n"))
- (princ (format "shiftwidth \t\t= %S\n" viper-shift-width))
- (princ (format "tabstop (local) \t= %S\n" tab-width))
- (princ (format "tabstop (global) \t= %S\n" (default-value 'tab-width)))
- (princ (format "wrapmargin (local) \t= %S\n"
- (- (window-width) fill-column)))
- (princ (format "wrapmargin (global) \t= %S\n"
- (- (window-width) (default-value 'fill-column))))
- (princ (format "shell \t\t\t= %S\n" (if (boundp 'explicit-shell-file-name)
- explicit-shell-file-name
- 'none)))
- ))
-
-(defun ex-print ()
- (viper-default-ex-addresses)
- (let ((end (car ex-addresses))
- (beg (car (cdr ex-addresses))))
- (if (> beg end) (error viper-FirstAddrExceedsSecond))
- (save-excursion
- (viper-enlarge-region beg end)
- (if (or ex-g-flag ex-g-variant)
- ;; When executing a global command, collect output of each
- ;; print in viper-ex-print-buf.
- (progn
- (append-to-buffer viper-ex-print-buf (point) (mark t))
- ;; Is this the last mark for the global command?
- (unless (cdr ex-g-marks)
- (with-current-buffer viper-ex-print-buf
- (ex-print-display-lines (buffer-string))
- (erase-buffer))))
- (ex-print-display-lines (buffer-substring (point) (mark t)))))))
-
-(defun ex-print-display-lines (lines)
- (cond
- ;; String doesn't contain a newline.
- ((not (string-search "\n" lines))
- (message "%s" lines))
- ;; String contains only one newline at the end. Strip it off.
- ((= (string-search "\n" lines) (1- (length lines)))
- (message "%s" (substring lines 0 -1)))
- ;; String spans more than one line. Use a temporary buffer.
- (t
- (save-current-buffer
- (with-output-to-temp-buffer " *viper-info*"
- (princ lines))))))
-
-(provide 'viper-ex)
-;;; viper-ex.el ends here
+++ /dev/null
-;;; viper-init.el --- some common definitions for Viper -*- lexical-binding: t; -*-
-
-;; Copyright (C) 1997-2025 Free Software Foundation, Inc.
-
-;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
-;; Package: viper
-
-;; This file is part of GNU Emacs.
-
-;; GNU Emacs is free software: you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; GNU Emacs is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;;; Code:
-
-;; compiler pacifier
-(defvar iso-accents-mode)
-(defvar viper-current-state)
-(defvar viper-version)
-(defvar viper-expert-level)
-(defvar current-input-method)
-(defvar default-input-method)
-(defvar cursor-type)
-;; end pacifier
-
-
-;; Viper version
-(defun viper-version ()
- (interactive)
- (message "Viper version is %s" viper-version))
-
-;; Tell whether we are running as a window application or on a TTY
-
-(define-obsolete-function-alias 'viper-device-type #'window-system "27.1")
-
-(defun viper-window-display-p ()
- (and window-system (not (memq window-system '(tty stream pc)))))
-
-(defcustom viper-ms-style-os-p
- (not (not (memq system-type '(ms-dos windows-nt))))
- "Non-nil if Emacs is running under an MS-style OS: MS-DOS, or MS-Windows."
- :type 'boolean
- :tag "Is it Microsoft-made OS?"
- :group 'viper-misc)
-
-(defcustom viper-suppress-input-method-change-message nil
- "If t, the message notifying about changes in the input method is not displayed.
-Normally, a message is displayed each time on enters the vi, insert or replace
-state."
- :type 'boolean
- :group 'viper-misc)
-
-(defcustom viper-force-faces nil
- "If t, Viper will think that it is running on a display that supports faces.
-This is provided as a temporary relief for users of graphics-capable terminals
-that Viper doesn't know about.
-In all likelihood, you don't need to bother with this setting."
- :type 'boolean
- :group 'viper-highlighting)
-
-(defun viper-has-face-support-p ()
- (cond ((viper-window-display-p))
- (viper-force-faces)
- ((display-color-p))
- (t (memq window-system '(pc)))))
-
-\f
-;;; Macros
-
-(defmacro viper-deflocalvar (var default-value &optional documentation)
- "Define VAR as a buffer-local variable.
-DEFAULT-VALUE is the default value, and DOCUMENTATION is the
-docstring. The variable becomes buffer-local whenever set."
- (declare (indent defun)
- (obsolete defvar-local "28.1"))
- `(defvar-local ,var ,default-value ,documentation))
-
-;; (viper-loop COUNT BODY) Execute BODY COUNT times.
-(defmacro viper-loop (count &rest body)
- (declare (indent defun))
- `(let ((count ,count))
- (while (> count 0)
- ,@body
- (setq count (1- count)))))
-
-(defmacro viper-buffer-live-p (buf)
- `(and ,buf (get-buffer ,buf) (buffer-name (get-buffer ,buf))))
-
-;; return buffer-specific macro definition, given a full macro definition
-(defmacro viper-kbd-buf-alist (macro-elt)
- `(nth 1 ,macro-elt))
-;; get a pair: (curr-buffer . macro-definition)
-(defmacro viper-kbd-buf-pair (macro-elt)
- `(assoc (buffer-name) (viper-kbd-buf-alist ,macro-elt)))
-;; get macro definition for current buffer
-(defmacro viper-kbd-buf-definition (macro-elt)
- `(cdr (viper-kbd-buf-pair ,macro-elt)))
-
-;; return mode-specific macro definitions, given a full macro definition
-(defmacro viper-kbd-mode-alist (macro-elt)
- `(nth 2 ,macro-elt))
-;; get a pair: (major-mode . macro-definition)
-(defmacro viper-kbd-mode-pair (macro-elt)
- `(assoc major-mode (viper-kbd-mode-alist ,macro-elt)))
-;; get macro definition for the current major mode
-(defmacro viper-kbd-mode-definition (macro-elt)
- `(cdr (viper-kbd-mode-pair ,macro-elt)))
-
-;; return global macro definition, given a full macro definition
-(defmacro viper-kbd-global-pair (macro-elt)
- `(nth 3 ,macro-elt))
-;; get global macro definition from an elt of macro-alist
-(defmacro viper-kbd-global-definition (macro-elt)
- `(cdr (viper-kbd-global-pair ,macro-elt)))
-
-;; last elt of a sequence
-(defsubst viper-seq-last-elt (seq)
- (elt seq (1- (length seq))))
-
-(defsubst viper-string-to-list (string)
- (append (vconcat string) nil))
-
-(defsubst viper-charlist-to-string (list)
- (mapconcat #'char-to-string list ""))
-
-;; like char-after/before, but saves typing
-(defun viper-char-at-pos (direction &optional offset)
- (or (integerp offset) (setq offset 0))
- (if (eq direction 'forward)
- (char-after (+ (point) offset))
- (char-before (- (point) offset))))
-
-\f
-(defvar viper-minibuffer-overlay-priority 300)
-(defvar viper-replace-overlay-priority 400)
-(defvar viper-search-overlay-priority 500)
-
-\f
-;;; Viper minor modes
-
-;; Mode for vital things like \e, C-z.
-(defvar-local viper-vi-intercept-minor-mode nil)
-
-(defvar-local viper-vi-basic-minor-mode nil
- "Viper's minor mode for Vi bindings.")
-
-(defvar-local viper-vi-local-user-minor-mode nil
- "Auxiliary minor mode for user-defined local bindings in Vi state.")
-
-(defvar-local viper-vi-global-user-minor-mode nil
- "Auxiliary minor mode for user-defined global bindings in Vi state.")
-
-(defvar-local viper-vi-state-modifier-minor-mode nil
- "Minor mode used to make major-mode-specific modification to Vi state.")
-
-(defvar-local viper-vi-diehard-minor-mode nil
- "This minor mode is in effect when the user wants Viper to be Vi.")
-
-(defvar-local viper-vi-kbd-minor-mode nil
- "Minor mode for Ex command macros in Vi state.
-The corresponding keymap stores key bindings of Vi macros defined with
-the Ex command :map.")
-
-;; Mode for vital things like \e, C-z.
-(defvar-local viper-insert-intercept-minor-mode nil)
-
-(defvar-local viper-insert-basic-minor-mode nil
- "Viper's minor mode for bindings in Insert mode.")
-
-(defvar-local viper-insert-local-user-minor-mode nil
- "Auxiliary minor mode for buffer-local user-defined bindings in Insert state.
-This is a way to overshadow normal Insert mode bindings locally to certain
-designated buffers.")
-
-(defvar-local viper-insert-global-user-minor-mode nil
- "Auxiliary minor mode for global user-defined bindings in Insert state.")
-
-(defvar-local viper-insert-state-modifier-minor-mode nil
- "Minor mode used to make major-mode-specific modification to Insert state.")
-
-(defvar-local viper-insert-diehard-minor-mode nil
- "Minor mode that simulates Vi very closely.
-Not recommended, except for the novice user.")
-
-(defvar-local viper-insert-kbd-minor-mode nil
-"Minor mode for Ex command macros Insert state.
-The corresponding keymap stores key bindings of Vi macros defined with
-the Ex command :map!.")
-
-(defvar-local viper-replace-minor-mode nil
- "Minor mode in effect in replace state (cw, C, and the like commands).")
-
-;; Mode for vital things like \C-z and \C-x) This is set to t, when viper-mode
-;; is invoked. So, any new buffer will have C-z defined as switch to Vi,
-;; unless we switched states in this buffer
-(defvar-local viper-emacs-intercept-minor-mode nil)
-
-(defvar-local viper-emacs-local-user-minor-mode nil
- "Minor mode for local user bindings effective in Emacs state.
-Users can use it to override Emacs bindings when Viper is in its Emacs
-state.")
-
-(defvar-local viper-emacs-global-user-minor-mode nil
- "Minor mode for global user bindings in effect in Emacs state.
-Users can use it to override Emacs bindings when Viper is in its Emacs
-state.")
-
-(defvar-local viper-emacs-kbd-minor-mode nil
- "Minor mode for Vi style macros in Emacs state.
-The corresponding keymap stores key bindings of Vi macros defined with
-`viper-record-kbd-macro' command. There is no Ex-level command to do this
-interactively.")
-
-(defvar-local viper-emacs-state-modifier-minor-mode nil
- "Minor mode used to make major-mode-specific modification to Emacs state.
-For instance, a Vi purist may want to bind `dd' in Dired mode to a function
-that deletes a file.")
-
-(defvar-local viper-vi-minibuffer-minor-mode nil
- "Minor mode that forces Vi-style when the Minibuffer is in Vi state.")
-
-(defvar-local viper-insert-minibuffer-minor-mode nil
- "Minor mode that forces Vi-style when the Minibuffer is in Insert state.")
-
-\f
-
-;; Some common error messages
-
-(defconst viper-SpuriousText "Spurious text after command")
-(defconst viper-BadExCommand "Not an editor command")
-(defconst viper-InvalidCommandArgument "Invalid command argument")
-(defconst viper-NoPrevSearch "No previous search string")
-(defconst viper-EmptyRegister "`%c': Nothing in this register")
-(defconst viper-InvalidRegister "`%c': Invalid register")
-(defconst viper-EmptyTextmarker "`%c': Text marker doesn't point anywhere")
-(defconst viper-InvalidTextmarker "`%c': Invalid text marker")
-(defconst viper-InvalidViCommand "Invalid command")
-(defconst viper-BadAddress "Ill-formed address")
-(defconst viper-FirstAddrExceedsSecond "First address exceeds second")
-(defconst viper-NoFileSpecified "No file specified")
-(defconst viper-ViperBell "Viper bell")
-
-;; Is t until viper-mode executes for the very first time.
-;; Prevents recursive descend into startup messages.
-(defvar viper-first-time t)
-
-(defvar viper-expert-level (if (boundp 'viper-expert-level) viper-expert-level 0)
- "User's expert level.
-The minor mode `viper-vi-diehard-minor-mode' is in effect when
-`viper-expert-level' is 1 or 2 or when `viper-want-emacs-keys-in-vi' is t.
-The minor mode `viper-insert-diehard-minor-mode' is in effect when
-`viper-expert-level' is 1 or 2 or if `viper-want-emacs-keys-in-insert' is t.
-Use \\[viper-set-expert-level] to change this.")
-
-;; Max expert level supported by Viper. This is NOT a user option.
-;; It is here to make it hard for the user from resetting it.
-(defconst viper-max-expert-level 5)
-
-
-;;; ISO characters and MULE
-
-;; If non-nil, ISO accents will be turned on in insert/replace emacs states and
-;; turned off in vi-state. For some users, this behavior may be too
-;; primitive. In this case, use insert/emacs/vi state hooks.
-(defvar-local viper-automatic-iso-accents nil)
-;; Set iso-accents-mode to ARG. Check if it is bound first
-(defsubst viper-set-iso-accents-mode (arg)
- (if (boundp 'iso-accents-mode)
- (setq iso-accents-mode arg)))
-
-;; Internal flag used to control when viper mule hooks are run.
-;; Don't change this!
-(defvar viper-mule-hook-flag t)
-;; If non-nil, the default intl. input method is turned on.
-(defvar-local viper-special-input-method nil)
-
-;; viper hook to run on input-method activation
-(defun viper-activate-input-method-action ()
- (if (null viper-mule-hook-flag)
- ()
- (setq viper-special-input-method t)
- ;; turn off special input methods in vi-state
- (if (eq viper-current-state 'vi-state)
- (viper-set-input-method nil))
- (if (and (memq viper-current-state '(vi-state insert-state replace-state))
- (not viper-suppress-input-method-change-message))
- (message "Viper special input method%s: on"
- (if (or current-input-method default-input-method)
- (format " %S"
- (or current-input-method default-input-method))
- "")))
- ))
-
-;; viper hook to run on input-method deactivation
-(defun viper-deactivate-input-method-action ()
- (if (null viper-mule-hook-flag)
- ()
- (setq viper-special-input-method nil)
- (if (and (memq viper-current-state '(vi-state insert-state replace-state))
- (not viper-suppress-input-method-change-message))
- (message "Viper special input method%s: off"
- (if (or current-input-method default-input-method)
- (format " %S"
- (or current-input-method default-input-method))
- "")))))
-
-(define-obsolete-function-alias 'viper-deactivate-input-method
- #'deactivate-input-method "27.1")
-
-(defun viper-activate-input-method ()
- (declare (obsolete activate-input-method "27.1"))
- (activate-input-method default-input-method))
-
-;; Set quail-mode to ARG
-(defun viper-set-input-method (arg)
- (setq viper-mule-hook-flag t) ; just a precaution
- (let (viper-mule-hook-flag) ; temporarily deactivate viper mule hooks
- (cond ((and arg (> (prefix-numeric-value arg) 0) default-input-method)
- ;; activate input method
- (activate-input-method default-input-method))
- (t ; deactivate input method
- (deactivate-input-method)))))
-
-
-;; VI-style Undo
-
-(defcustom viper-keep-point-on-undo nil
- "Non-nil means not to move point while undoing commands.
-This style is different from Emacs and Vi. Try it to see if
-it better fits your working style."
- :type 'boolean
- :tag "Preserve Position of Point After Undo"
- :group 'viper)
-
-;; Replace mode and changing text
-
-;; Hack used to pass global states around for short period of time
-(defvar-local viper-intermediate-command nil)
-
-;; This is used to pass the right Vi command key sequence to
-;; viper-set-destructive-command whenever (this-command-keys) doesn't give the
-;; right result. For instance, in commands like c/bla<RET>,
-;; (this-command-keys) will return ^M, which invoked exit-minibuffer, while we
-;; need "c/"
-(defconst viper-this-command-keys nil)
-
-;; Indicates that the current destructive command has started in replace mode.
-(defvar-local viper-began-as-replace nil)
-
-(defcustom viper-allow-multiline-replace-regions t
- "If non-nil, Viper will allow multi-line replace regions.
-This is an extension to standard Vi.
-If nil, commands that attempt to replace text spanning multiple lines first
-delete the text being replaced, as in standard Vi."
- :type 'boolean
- :group 'viper)
-
-(defcustom viper-replace-overlay-cursor-color "Red"
- "Cursor color when Viper is in Replace state."
- :type 'string
- :group 'viper)
-
-(defcustom viper-insert-state-cursor-color "Green"
- "Cursor color when Viper is in insert state."
- :type 'string
- :group 'viper)
-
-;; viper-emacs-state-cursor-color doesn't work well. Causes cursor colors to be
-;; confused in some cases. So, this var is nulled for now.
-;; (defcustom viper-emacs-state-cursor-color "Magenta"
-(defcustom viper-emacs-state-cursor-color nil
- "Cursor color when Viper is in Emacs state."
- :type '(choice (const nil) string)
- :group 'viper)
-
-;; internal var, used to remember the default cursor color of emacs frames
-(defvar viper-vi-state-cursor-color nil)
-
-(defvar-local viper-replace-overlay nil)
-(put 'viper-replace-overlay 'permanent-local t)
-
-(defcustom viper-replace-region-end-delimiter "$"
- "A string marking the end of replacement regions.
-It is used only with TTYs or if `viper-use-replace-region-delimiters'
-is non-nil."
- :type 'string
- :group 'viper)
-(defcustom viper-replace-region-start-delimiter ""
- "A string marking the beginning of replacement regions.
-It is used only with TTYs or if `viper-use-replace-region-delimiters'
-is non-nil."
- :type 'string
- :group 'viper)
-(defcustom viper-use-replace-region-delimiters
- (not (viper-has-face-support-p))
- "If non-nil, Viper will always use `viper-replace-region-end-delimiter' and
-`viper-replace-region-start-delimiter' to delimit replacement regions, even on
-color displays. By default, the delimiters are used only on TTYs."
- :type 'boolean
- :group 'viper)
-
-(defcustom viper-read-buffer-function #'read-buffer
- "Function to use for prompting the user for a buffer name."
- :type 'symbol
- :group 'viper)
-
-;; These are local marker that must be initialized to nil and moved with
-;; `viper-move-marker-locally'
-;;
-;; Remember the last position inside the replace region.
-(defvar-local viper-last-posn-in-replace-region nil)
-;; Remember the last position while inserting
-(defvar-local viper-last-posn-while-in-insert-state nil)
-(put 'viper-last-posn-in-replace-region 'permanent-local t)
-(put 'viper-last-posn-while-in-insert-state 'permanent-local t)
-
-(defvar-local viper-sitting-in-replace nil)
-(put 'viper-sitting-in-replace 'permanent-local t)
-
-;; Remember the number of characters that have to be deleted in replace
-;; mode to compensate for the inserted characters.
-(defvar-local viper-replace-chars-to-delete 0)
-;; This variable is used internally by the before/after changed functions to
-;; determine how many chars were deleted by the change. This can't be
-;; determined inside after-change-functions because those get the length of the
-;; deleted region, not the number of chars deleted (which are two different
-;; things under MULE).
-(defvar-local viper-replace-region-chars-deleted 0)
-
-;; Insertion ring and command ring
-(defcustom viper-insertion-ring-size 14
- "The size of history of inserted text.
-This is a list where Viper keeps the history of previously inserted pieces of
-text."
- :type 'integer
- :group 'viper-misc)
-;; The insertion ring.
-(defvar viper-insertion-ring nil)
-;; This is temp insertion ring. Used to do rotation for display purposes.
-;; When rotation just started, it is initialized to viper-insertion-ring.
-(defvar viper-temp-insertion-ring nil)
-(defvar viper-last-inserted-string-from-insertion-ring "")
-
-(defcustom viper-command-ring-size 14
- "The size of history of Vi commands repeatable with dot."
- :type 'integer
- :group 'viper-misc)
-;; The command ring.
-(defvar viper-command-ring nil)
-;; This is temp command ring. Used to do rotation for display purposes.
-;; When rotation just started, it is initialized to viper-command-ring.
-(defvar viper-temp-command-ring nil)
-
-;; Fast keyseq and ESC keyseq timeouts
-(defcustom viper-fast-keyseq-timeout 200
- "Max milliseconds for a key sequence to be regarded as a Vi-style macro.
-Only regard key sequence as a macro if it is defined.
-Setting this too high may slow down your typing. Setting this value too low
-will make it hard to use Vi-style timeout macros."
- :type 'integer
- :group 'viper-misc)
-
-;; This function determines if ESC key sequences are to be translated into
-;; commands.
-(defun viper-translate-all-ESC-keysequences ()
- (not (viper-window-display-p)))
-
-;; Modes and related variables
-
-;; Current mode. One of: `emacs-state', `vi-state', `insert-state'
-(defvar-local viper-current-state 'emacs-state)
-
-
-;; Autoindent in insert
-
-;; Variable that keeps track of whether C-t has been pressed.
-(defvar-local viper-cted nil)
-
-;; Preserve the indent value, used by C-d in insert mode.
-(defvar-local viper-current-indent 0)
-
-;; Whether to preserve the indent, used by C-d in insert mode.
-(defvar-local viper-preserve-indent nil)
-
-(defvar-local viper-auto-indent nil)
-(defcustom viper-auto-indent nil
- "Enable autoindent, if t.
-This is a buffer-local variable."
- :type 'boolean
- :group 'viper)
-
-(defvar-local viper-electric-mode t)
-(defcustom viper-electric-mode t
- "If t, electrify Viper.
-Currently, this only electrifies auto-indentation, making it appropriate to the
-mode of the buffer.
-This means that auto-indentation will depart from standard Vi and will indent
-appropriate to the mode of the buffer. This is especially useful for editing
-programs and LaTeX documents."
- :type 'boolean
- :group 'viper)
-
-(defcustom viper-shift-width 8
- "The value of the shiftwidth.
-This determines the number of columns by which the Ctl-t moves the cursor in
-the Insert state."
- :type 'integer
- :group 'viper)
-
-;; Variables for repeating destructive commands
-
-(defcustom viper-keep-point-on-repeat t
- "If t, don't move point when repeating previous command.
-This is useful for doing repeated changes with the `.' key.
-The user can change this to nil, if she likes when the cursor moves
-to a new place after repeating previous Vi command."
- :type 'boolean
- :group 'viper)
-
-;; Remember insert point as a marker. This is a local marker that must be
-;; initialized to nil and moved with `viper-move-marker-locally'.
-(defvar-local viper-insert-point nil)
-(put 'viper-insert-point 'permanent-local t)
-
-;; This remembers the point before dabbrev-expand was called.
-;; If viper-insert-point turns out to be bigger than that, it is reset
-;; back to viper-pre-command-point.
-;; The reason this is needed is because dabbrev-expand (and possibly
-;; others) may jump to before the insertion point, delete something and
-;; then reinsert a bigger piece. For instance: bla^blo
-;; If dabbrev-expand is called after `blo' and ^ indicates viper-insert-point,
-;; then point jumps to the beginning of `blo'. If expansion is found, `blablo'
-;; is deleted, and we have |^, where | denotes point. Next, dabbrev-expand
-;; will insert the expansion, and we get: blablo^
-;; Whatever we insert next goes before the ^, i.e., before the
-;; viper-insert-point marker. So, Viper will think that nothing was
-;; inserted. Remembering the orig position of the marker circumvents the
-;; problem.
-;; We don't know of any command, except dabbrev-expand, that has the same
-;; problem. However, the same trick can be used if such a command is
-;; discovered later.
-;;
-(defvar-local viper-pre-command-point nil)
-(put 'viper-pre-command-point 'permanent-local t) ; this is probably an overkill
-
-;; This is used for saving inserted text.
-(defvar viper-last-insertion nil)
-
-;; Remembers the last replaced region.
-(defvar viper-last-replace-region "")
-
-;; Remember com point as a marker.
-;; This is a local marker. Should be moved with `viper-move-marker-locally'
-(defvar-local viper-com-point nil)
-
-;; If non-nil, the value is a list (M-COM VAL COM REG inserted-text cmd-keys)
-;; It is used to re-execute last destructive command.
-;; M-COM is a Lisp symbol representing the function to be executed.
-;; VAL is the prefix argument that was used with that command.
-;; COM is an internal descriptor, such as ?r, ?c, ?C, which contains
-;; additional information on how the function in M-COM is to be handled.
-;; REG is the register used by command
-;; INSERTED-TEXT is text inserted by that command (in case of o, c, C, i, r
-;; commands).
-;; COMMAND-KEYS are the keys that were typed to invoke the command.
-(defvar viper-d-com nil)
-
-;; The character remembered by the Vi `r' command.
-(defvar viper-d-char nil)
-
-;; Name of register to store deleted or yanked strings
-(defvar viper-use-register nil)
-
-
-;;; Variables for Moves and Searches
-
-(defgroup viper-search nil
- "Variables that define the search and `query-replace' behavior of Viper."
- :prefix "viper-"
- :group 'viper)
-
-;; For use by `;' command.
-(defvar viper-f-char nil)
-
-;; For use by `.' command.
-(defvar viper-F-char nil)
-
-;; For use by `;' command.
-(defvar viper-f-forward nil)
-
-;; For use by `;' command.
-(defvar viper-f-offset nil)
-
-;; Last search string
-(defvar viper-s-string "")
-
-(defcustom viper-quote-string "> "
- "String inserted at the beginning of quoted region."
- :type 'string
- :group 'viper)
-
-;; If t, search is forward.
-(defvar viper-s-forward nil)
-
-(defcustom viper-case-fold-search nil
- "If not nil, search ignores cases."
- :type 'boolean
- :group 'viper-search)
-
-(defcustom viper-re-search t
- "If not nil, search is regexp search, otherwise vanilla search."
- :type 'boolean
- :tag "Regexp Search"
- :group 'viper-search)
-
-(defcustom viper-search-scroll-threshold 2
- "If search lands within this threshold from the window top/bottom,
-the window will be scrolled up or down appropriately, to reveal context.
-If you want Viper search to behave as usual in Vi, set this variable to a
-negative number."
- :type 'integer
- :group 'viper-search)
-
-(defcustom viper-re-query-replace t
- "If t then do regexp replace, if nil then do string replace."
- :type 'boolean
- :tag "Regexp Query Replace"
- :group 'viper-search)
-
-(defcustom viper-re-replace t
- "If t, do regexp replace. nil means do string replace."
- :type 'boolean
- :tag "Regexp Replace"
- :group 'viper-search)
-
-(defcustom viper-parse-sexp-ignore-comments t
- "If t, `%' ignores the parentheses that occur inside comments."
- :type 'boolean
- :group 'viper)
-
-(defvar-local viper-ex-style-motion t)
-(defcustom viper-ex-style-motion t
- "If t, the commands l,h do not cross lines, etc (Ex-style).
-If nil, these commands cross line boundaries."
- :type 'boolean
- :group 'viper)
-
-(defvar-local viper-ex-style-editing t)
-(defcustom viper-ex-style-editing t
- "If t, Ex-style behavior while editing in Vi command and insert states.
-`Backspace' and `Delete' don't cross line boundaries in insert.
-`X' and `x' can't delete characters across line boundary in Vi, etc.
-Note: this doesn't preclude `Backspace' and `Delete' from deleting characters
-by moving past the insertion point. This is a feature, not a bug.
-
-If nil, the above commands can work across lines."
- :type 'boolean
- :group 'viper)
-
-(defvar-local viper-ESC-moves-cursor-back viper-ex-style-editing)
-(defcustom viper-ESC-moves-cursor-back nil
- "If t, ESC moves cursor back when changing from insert to vi state.
-If nil, the cursor stays where it was when ESC was hit."
- :type 'boolean
- :group 'viper)
-
-(defvar-local viper-delete-backwards-in-replace nil)
-(defcustom viper-delete-backwards-in-replace nil
- "If t, DEL key will delete characters while moving the cursor backwards.
-If nil, the cursor will move backwards without deleting anything."
- :type 'boolean
- :group 'viper)
-
-(defcustom viper-buffer-search-char nil
- "Key used for buffer-searching. Must be a character type, e.g., ?g."
- :type '(choice (const nil) character)
- :group 'viper-search)
-
-(defcustom viper-search-wrap-around t
- "If t, search wraps around."
- :type 'boolean
- :tag "Search Wraps Around"
- :group 'viper-search)
-
-(defvar-local viper-related-files-and-buffers-ring nil)
-(defcustom viper-related-files-and-buffers-ring nil
- "List of file and buffer names to consider related to the current buffer.
-Related buffers can be cycled through via :R and :P commands."
- :type 'boolean
- :local 'permanent-only
- :group 'viper-misc)
-
-;; Used to find out if we are done with searching the current buffer.
-(defvar-local viper-local-search-start-marker nil)
-;; As above, but global
-(defvar viper-search-start-marker (make-marker))
-
-;; the search overlay
-(defvar-local viper-search-overlay nil)
-
-
-(defvar viper-heading-start
- (concat "^\\s-*(\\s-*defun\\s-\\|" ; lisp
- "^{\\s-*$\\|^[_a-zA-Z][^()]*[()].*{\\s-*$\\|" ; C/C++
- "^\\s-*class.*{\\|^\\s-*struct.*{\\|^\\s-*enum.*{\\|"
- "^\\\\[sb][a-z]*{.*}\\s-*$\\|" ; latex
- "^@node\\|@table\\|^@m?enu\\|^@itemize\\|^@if\\|" ; texinfo
- "^.+:-") ; prolog
- "Regexps for Headings. Used by [[ and ]].")
-
-(defvar viper-heading-end
- (concat "^}\\|" ; C/C++
- "^\\\\end{\\|" ; latex
- "^@end \\|" ; texinfo
- ")\n\n[ \t\n]*\\|" ; lisp
- "\\.\\s-*$") ; prolog
- "Regexps to end Headings/Sections. Used by [].")
-
-
-;; These two vars control the interaction of jumps performed by ' and `.
-;; In this new version, '' doesn't erase the marks set by ``, so one can
-;; use both kinds of jumps interchangeably and without losing positions
-;; inside the lines.
-
-;; Remembers position of the last jump done using ``'.
-(defvar-local viper-last-jump nil)
-;; Remembers position of the last jump done using `''.
-(defvar-local viper-last-jump-ignore 0)
-
-;; History variables
-
-;; History of search strings.
-(defvar viper-search-history (list ""))
-;; History of query-replace strings used as a source.
-(defvar viper-replace1-history nil)
-;; History of query-replace strings used as replacement.
-(defvar viper-replace2-history nil)
-;; History of region quoting strings.
-(defvar viper-quote-region-history (list viper-quote-string))
-;; History of Ex-style commands.
-(defvar viper-ex-history nil)
-;; History of shell commands.
-(defvar viper-shell-history nil)
-
-
-;; Last shell command. There are two of these, one for Ex (in viper-ex)
-;; and one for Vi.
-
-;; Last shell command executed with ! command.
-(defvar viper-last-shell-com nil)
-
-\f
-;;; Face-saving tricks
-
-(defgroup viper-highlighting nil
- "Highlighting of replace region, search pattern, minibuffer, etc."
- :prefix "viper-"
- :group 'viper)
-
-
-(defface viper-search
- '((((class color)) (:foreground "Black" :background "khaki"))
- (t (:underline t :stipple "gray3")))
- "Face used to flash out the search pattern."
- :group 'viper-highlighting)
-;; An internal variable. Viper takes the face from here.
-(defvar viper-search-face 'viper-search
- "Face used to flash out the search pattern.
-DO NOT CHANGE this variable. Instead, use the customization widget
-to customize the actual face object `viper-search'
-this variable represents.")
-
-(defface viper-replace-overlay
- '((((class color)) (:foreground "Black" :background "darkseagreen2"))
- (t (:underline t :stipple "gray3")))
- "Face for highlighting replace regions on a window display."
- :group 'viper-highlighting)
-;; An internal variable. Viper takes the face from here.
-(defvar viper-replace-overlay-face 'viper-replace-overlay
- "Face for highlighting replace regions on a window display.
-DO NOT CHANGE this variable. Instead, use the customization widget
-to customize the actual face object `viper-replace-overlay'
-this variable represents.")
-
-(defface viper-minibuffer-emacs
- '((((class color)) (:foreground "Black" :background "darkseagreen2"))
- (t (:weight bold)))
- "Face used in the Minibuffer when it is in Emacs state."
- :group 'viper-highlighting)
-;; An internal variable. Viper takes the face from here.
-(defvar viper-minibuffer-emacs-face 'viper-minibuffer-emacs
- "Face used in the Minibuffer when it is in Emacs state.
-DO NOT CHANGE this variable. Instead, use the customization widget
-to customize the actual face object `viper-minibuffer-emacs'
-this variable represents.")
-
-(defface viper-minibuffer-insert
- '((((class color)) (:foreground "Black" :background "pink"))
- (t (:slant italic)))
- "Face used in the Minibuffer when it is in Insert state."
- :group 'viper-highlighting)
-;; An internal variable. Viper takes the face from here.
-(defvar viper-minibuffer-insert-face 'viper-minibuffer-insert
- "Face used in the Minibuffer when it is in Insert state.
-DO NOT CHANGE this variable. Instead, use the customization widget
-to customize the actual face object `viper-minibuffer-insert'
-this variable represents.")
-
-(defface viper-minibuffer-vi
- '((((class color)) (:foreground "DarkGreen" :background "grey"))
- (t (:inverse-video t)))
- "Face used in the Minibuffer when it is in Vi state."
- :group 'viper-highlighting)
-;; An internal variable. Viper takes the face from here.
-(defvar viper-minibuffer-vi-face 'viper-minibuffer-vi
- "Face used in the Minibuffer when it is in Vi state.
-DO NOT CHANGE this variable. Instead, use the customization widget
-to customize the actual face object `viper-minibuffer-vi'
-this variable represents.")
-
-;; the current face to be used in the minibuffer
-(defvar-local viper-minibuffer-current-face viper-minibuffer-emacs-face)
-
-\f
-;;; Miscellaneous
-
-(defvar viper-inhibit-startup-message nil
- "Whether Viper startup message should be inhibited.")
-
-(defcustom viper-spell-function 'ispell-region
- "Spell function used by #s<move> command to spell."
- :type 'function
- :group 'viper-misc)
-
-(defcustom viper-tags-file-name "TAGS"
- "The tags file used by Viper."
- :type 'string
- :group 'viper-misc)
-
-(defcustom viper-change-notification-threshold 1
- "Notify the user when this many lines or characters have been deleted/yanked.
-For line-deleting/yanking commands (like `dd', `yy'), the value denotes the
-number of lines. For character-based commands (such as `x', `dw', etc.), the
-value refers to the number of characters affected."
- :type 'integer
- :group 'viper-misc)
-
-;; Minibuffer
-
-(defcustom viper-vi-style-in-minibuffer t
- "If t, use vi-style editing in minibuffer.
-Should be set in `viper-custom-file-name'."
- :type 'boolean
- :group 'viper)
-
-;; overlay used in the minibuffer to indicate which state it is in
-(defvar-local viper-minibuffer-overlay nil)
-(put 'viper-minibuffer-overlay 'permanent-local t)
-
-;; Hook, specific to Viper, which is run just *before* exiting the
-;; minibuffer. This is needed because, the standard
-;; `minibuffer-exit-hook' is run *after* exiting the minibuffer
-(defvar viper-minibuffer-exit-hook nil)
-
-
-;; Mode line
-(defconst viper-vi-state-id "<V> "
- "Mode line tag identifying the Vi mode of Viper.")
-(defconst viper-emacs-state-id "<E> "
- "Mode line tag identifying the Emacs mode of Viper.")
-(defconst viper-insert-state-id "<I> "
- "Mode line tag identifying the Insert mode of Viper.")
-(defconst viper-replace-state-id "<R> "
- "Mode line tag identifying the Replace mode of Viper.")
-
-
-(defgroup viper-hooks nil
- "Viper hooks."
- :prefix "viper-"
- :group 'viper)
-
-(defcustom viper-vi-state-hook 'viper-restore-cursor-type
- "Hooks run just before the switch to Vi mode is completed."
- :type 'hook
- :group 'viper-hooks)
-(defcustom viper-insert-state-hook 'viper-set-insert-cursor-type
- "Hooks run just before the switch to Insert mode is completed."
- :type 'hook
- :group 'viper-hooks)
-(defcustom viper-replace-state-hook 'viper-restore-cursor-type
- "Hooks run just before the switch to Replace mode is completed."
- :type 'hook
- :group 'viper-hooks)
-(defcustom viper-emacs-state-hook 'viper-restore-cursor-type
- "Hooks run just before the switch to Emacs mode is completed."
- :type 'hook
- :group 'viper-hooks)
-
-(defcustom viper-load-hook nil
- "Hooks run just after loading Viper."
- :type 'hook
- :group 'viper-hooks)
-(make-obsolete-variable 'viper-load-hook
- "use `with-eval-after-load' instead." "28.1")
-
-(defun viper-restore-cursor-type ()
- (condition-case nil
- (setq cursor-type (default-value 'cursor-type))
- (error nil)))
-
-(defun viper-set-insert-cursor-type ()
- (setq cursor-type '(bar . 2)))
-
-(defun viper-ESC-keyseq-timeout ()
- "Return the timeout for considering an ESC sequence to be a function key.
-Sequences of keys beginning with ESC and separated by no more than this many
-milliseconds are considered to be generated by a keyboard function key.
-Setting this too high may slow down switching from insert to vi state. Setting
-this value too low will make it impossible to use function keys in insert mode
-on a dumb terminal."
- (if (viper-window-display-p)
- 0 viper-fast-keyseq-timeout))
-
-
-
-(provide 'viper-init)
-
-;;; viper-init.el ends here
+++ /dev/null
-;;; viper-keym.el --- Viper keymaps -*- lexical-binding:t -*-
-
-;; Copyright (C) 1994-1997, 2000-2025 Free Software Foundation, Inc.
-
-;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
-;; Package: viper
-
-;; This file is part of GNU Emacs.
-
-;; GNU Emacs is free software: you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; GNU Emacs is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;;; Code:
-
-;; compiler pacifier
-(defvar viper-always)
-(defvar viper-current-state)
-(defvar viper-mode-string)
-(defvar viper-expert-level)
-(defvar viper-ex-style-editing)
-(defvar viper-ex-style-motion)
-
-;; end pacifier
-
-(require 'viper-util)
-
-(declare-function viper-ex "viper-ex" (arg &optional string))
-(declare-function viper-normalize-minor-mode-map-alist "viper-cmd" ())
-(declare-function viper-set-mode-vars-for "viper-cmd" (state))
-
-;;; Variables
-
-
-;;; Emacs keys in other states.
-
-(defcustom viper-want-emacs-keys-in-insert t
- "Set to nil if you want complete Vi compatibility in insert mode.
-Complete compatibility with Vi is not recommended for power use of Viper."
- :type 'boolean
- :group 'viper)
-
-(defcustom viper-want-emacs-keys-in-vi t
- "Set to nil if you want complete Vi compatibility in Vi mode.
-Full Vi compatibility is not recommended for power use of Viper."
- :type 'boolean
- :group 'viper)
-
-(defcustom viper-no-multiple-ESC t
- "If non-nil, multiple ESC in Vi mode will cause bell to ring.
-This is set to t on a windowing terminal and to `twice' on a dumb
-terminal (unless the user level is 1, 2, or 5). On a dumb terminal, this
-enables cursor keys and is generally more convenient, as terminals usually
-don't have a convenient Meta key.
-Setting it to nil will allow as many multiple ESC, as is allowed by the
-major mode in effect."
- :type 'boolean
- :group 'viper)
-
-(defcustom viper-want-ctl-h-help nil
- "If non-nil, bind C-h to `help-command'.
-If nil, C-h gets the usual Vi bindings."
- :type 'boolean
- :group 'viper)
-
-
-;;; Keymaps
-
-;; Keymaps for vital things like \e and C-z.
-;; Not for users
-(defvar-keymap viper-vi-intercept-map)
-(defvar-keymap viper-insert-intercept-map)
-(defvar-keymap viper-emacs-intercept-map)
-
-(defvar-local viper-vi-local-user-map (make-sparse-keymap)
- "Keymap for user-defined local bindings.
-Useful for changing bindings such as ZZ in certain major modes.
-For instance, in letter-mode, one may want to bind ZZ to
-`mh-send-letter'. In a newsreader such as gnus, tin, or rn, ZZ could be bound
-to `save-buffers-kill-emacs' then post article, etc.")
-(put 'viper-vi-local-user-map 'permanent-local t)
-
-(defvar-keymap viper-vi-global-user-map
- :doc "Keymap for user-defined global bindings.
-These bindings are seen in all Viper buffers.")
-
-(defvar-keymap viper-vi-basic-map
- :doc "This is the main keymap in effect in Viper's Vi state.
-This map is global, shared by all buffers."
- :full t)
-
-(defvar-keymap viper-vi-kbd-map
- :doc "This keymap keeps keyboard macros defined via the :map command.")
-
-(defvar-keymap viper-vi-diehard-map
- :doc "This keymap is in use when the user asks Viper to simulate Vi very closely.
-This happens when `viper-expert-level' is 1 or 2. See `viper-set-expert-level'.")
-
-
-(defvar-local viper-insert-local-user-map (make-sparse-keymap)
- "Auxiliary map for per-buffer user-defined keybindings in Insert state.")
-(put 'viper-insert-local-user-map 'permanent-local t)
-
-(defvar-keymap viper-insert-global-user-map
- :doc "Auxiliary map for global user-defined bindings in Insert state.")
-
-(defvar-keymap viper-insert-basic-map
- :doc "The basic insert-mode keymap.")
-
-(defvar-keymap viper-insert-diehard-map
- :doc "Map used when user wants vi-style keys in insert mode.
-Most of the Emacs keys are suppressed. This map overshadows
-`viper-insert-basic-map'. Not recommended, except for novice users."
- :full t)
-
-(defvar-keymap viper-insert-kbd-map
- :doc "This keymap keeps VI-style kbd macros for insert mode.")
-
-(defvar-keymap viper-replace-map
- :doc "Map used in Viper's replace state.")
-
-(defvar-keymap viper-emacs-global-user-map
- :doc "Auxiliary map for global user-defined bindings in Emacs state.")
-
-(defvar-keymap viper-emacs-kbd-map
- :doc "This keymap keeps Vi-style kbd macros for Emacs mode.")
-
-(defvar-local viper-emacs-local-user-map (make-sparse-keymap)
- "Auxiliary map for local user-defined bindings in Emacs state.")
-(put 'viper-emacs-local-user-map 'permanent-local t)
-
-;; This keymap should stay empty
-(defvar-keymap viper-empty-keymap)
-
-;; This was the main Vi mode in old versions of VIP which may have been
-;; extensively used by VIP users. We declare it as a global var and, after
-;; viper-custom-file-name is loaded, we add this keymap to viper-vi-basic-map.
-(defvar-keymap viper-mode-map)
-
-;; Some important keys used in viper
-(defcustom viper-toggle-key [(control ?z)] ; "\C-z"
- "The key used to change states from Emacs to Vi and back.
-In insert mode, this key also functions as Meta."
- :type 'key-sequence
- :group 'viper
- :set (lambda (symbol value)
- (let ((old-value (if (boundp 'viper-toggle-key)
- viper-toggle-key
- [(control ?z)])))
- (dolist (buf (buffer-list))
- (with-current-buffer buf
- (when (and (boundp 'viper-insert-basic-map)
- (keymapp viper-insert-basic-map))
- (when old-value
- (define-key viper-insert-basic-map old-value nil))
- (define-key viper-insert-basic-map value 'viper-escape-to-vi))
- (when (and (boundp 'viper-vi-intercept-map)
- (keymapp viper-vi-intercept-map))
- (when old-value
- (define-key viper-vi-intercept-map old-value nil))
- (define-key
- viper-vi-intercept-map value 'viper-toggle-key-action))
- (when (and (boundp 'viper-emacs-intercept-map)
- (keymapp viper-emacs-intercept-map))
- (define-key viper-emacs-intercept-map old-value nil)
- (define-key
- viper-emacs-intercept-map value 'viper-change-state-to-vi))
- ))
- (set-default symbol value))))
-
-(defcustom viper-quoted-insert-key "\C-v"
- "The key used to quote special characters when inserting them in Insert state."
- :type 'string
- :group 'viper)
-
-(defconst viper-ESC-key [escape]
- "Key used to ESC.")
-
-
-;;; Variables used by minor modes
-
-;; Association list of the form
-;; ((major-mode . keymap) (major-mode . keymap) ...)
-;; Viper uses these keymaps to make user-requested adjustments
-;; to its Vi state in various major modes.")
-(defvar viper-vi-state-modifier-alist nil)
-
-;; Association list of the form
-;; ((major-mode . keymap) (major-mode . keymap) ...)
-;; Viper uses these keymaps to make user-requested adjustments
-;; to its Insert state in various major modes.")
-(defvar viper-insert-state-modifier-alist nil)
-
-;; Association list of the form
-;; ((major-mode . keymap) (major-mode . keymap) ...)
-;; Viper uses these keymaps to make user-requested adjustments
-;; to its Emacs state in various major modes.
-(defvar viper-emacs-state-modifier-alist nil)
-
-;; The list of viper keymaps. Set by viper-normalize-minor-mode-map-alist
-(defvar-local viper--key-maps nil)
-(defvar-local viper--intercept-key-maps nil)
-
-;; Tells viper-add-local-keys to create a new viper-vi-local-user-map for new
-;; buffers. Not a user option.
-(defvar-local viper-need-new-vi-local-map t)
-(put 'viper-need-new-vi-local-map 'permanent-local t)
-
-;; Tells viper-add-local-keys to create a new viper-insert-local-user-map for
-;; new buffers. Not a user option.
-(defvar-local viper-need-new-insert-local-map t)
-(put 'viper-need-new-insert-local-map 'permanent-local t)
-
-;; Tells viper-add-local-keys to create a new viper-emacs-local-user-map for
-;; new buffers. Not a user option.
-(defvar-local viper-need-new-emacs-local-map t)
-(put 'viper-need-new-emacs-local-map 'permanent-local t)
-
-
-\f
-;; Insert mode keymap
-
-;; for novice users, pretend you are the real vi.
-(define-key viper-insert-diehard-map "\t" 'viper-insert-tab)
-(define-key viper-insert-diehard-map "\C-a" 'self-insert-command)
-(define-key viper-insert-diehard-map "\C-b" 'self-insert-command)
-(define-key viper-insert-diehard-map "\C-c" 'viper-change-state-to-vi)
-(define-key viper-insert-diehard-map "\C-e" 'self-insert-command)
-(define-key viper-insert-diehard-map "\C-f" 'self-insert-command)
-(define-key viper-insert-diehard-map "\C-g" 'self-insert-command)
-(define-key viper-insert-diehard-map "\C-i" 'self-insert-command)
-(define-key viper-insert-diehard-map "\C-k" 'self-insert-command)
-(define-key viper-insert-diehard-map "\C-l" 'self-insert-command)
-(define-key viper-insert-diehard-map "\C-n" 'self-insert-command)
-(define-key viper-insert-diehard-map "\C-o" 'self-insert-command)
-(define-key viper-insert-diehard-map "\C-p" 'self-insert-command)
-(define-key viper-insert-diehard-map "\C-q" 'self-insert-command)
-(define-key viper-insert-diehard-map "\C-r" 'self-insert-command)
-(define-key viper-insert-diehard-map "\C-s" 'self-insert-command)
-(define-key viper-insert-diehard-map "\C-u" 'viper-erase-line)
-(define-key viper-insert-diehard-map "\C-x" 'self-insert-command)
-(define-key viper-insert-diehard-map "\C-y" 'self-insert-command)
-(define-key viper-insert-diehard-map "\C-z" 'self-insert-command)
-(define-key viper-insert-diehard-map "\C-]" 'self-insert-command)
-(define-key viper-insert-diehard-map "\C-_" 'self-insert-command)
-
-(let ((i ?\ ))
- (while (<= i ?~)
- (define-key viper-insert-diehard-map (string i) #'self-insert-command)
- (setq i (1+ i))))
-
-;; Insert mode map when user wants emacs style
-(define-key viper-insert-basic-map "\C-d" 'viper-backward-indent)
-(define-key viper-insert-basic-map "\C-w" 'viper-delete-backward-word)
-(define-key viper-insert-basic-map "\C-t" 'viper-forward-indent)
-(define-key viper-insert-basic-map viper-quoted-insert-key 'quoted-insert)
-(define-key viper-insert-basic-map "\C-?" 'viper-del-backward-char-in-insert)
-(define-key viper-insert-basic-map [backspace] 'viper-del-backward-char-in-insert)
-(define-key viper-insert-basic-map "\C-\\" 'viper-alternate-Meta-key)
-(define-key viper-insert-basic-map viper-toggle-key 'viper-escape-to-vi)
-(define-key viper-insert-basic-map "\C-c\M-p"
- 'viper-insert-prev-from-insertion-ring)
-(define-key viper-insert-basic-map "\C-c\M-n"
- 'viper-insert-next-from-insertion-ring)
-
-
-;; Replace keymap
-(define-key viper-replace-map "\C-t" 'viper-forward-indent)
-(define-key viper-replace-map "\C-j" 'viper-replace-state-carriage-return)
-(define-key viper-replace-map "\C-m" 'viper-replace-state-carriage-return)
-(define-key viper-replace-map "\C-?" 'viper-del-backward-char-in-replace)
-(define-key viper-replace-map [backspace] 'viper-del-backward-char-in-replace)
-
-
-\f
-;; Vi keymaps
-
-(define-key viper-vi-basic-map "\C-^" (lambda ()
- (interactive) (viper-ex nil "e#")))
-(define-key viper-vi-basic-map "\C-b" 'viper-scroll-screen-back)
-(define-key viper-vi-basic-map "\C-d" 'viper-scroll-up)
-(define-key viper-vi-basic-map "\C-e" 'viper-scroll-up-one)
-(define-key viper-vi-basic-map "\C-f" 'viper-scroll-screen)
-(define-key viper-vi-basic-map "\C-m" 'viper-next-line-at-bol)
-(define-key viper-vi-basic-map "\C-u" 'viper-scroll-down)
-(define-key viper-vi-basic-map "\C-y" 'viper-scroll-down-one)
-;;(define-key viper-vi-basic-map "\C-s" 'viper-isearch-forward)
-;;(define-key viper-vi-basic-map "\C-r" 'viper-isearch-backward)
-(define-key viper-vi-basic-map "\C-c/" 'viper-toggle-search-style)
-(define-key viper-vi-basic-map "\C-c\C-g" 'viper-info-on-file)
-
-(define-key viper-vi-basic-map "\C-c\M-p" 'viper-prev-destructive-command)
-(define-key viper-vi-basic-map "\C-c\M-n" 'viper-next-destructive-command)
-
-
-(define-key viper-vi-basic-map " " 'viper-forward-char)
-(define-key viper-vi-basic-map "!" 'viper-command-argument)
-(define-key viper-vi-basic-map "\"" 'viper-command-argument)
-(define-key viper-vi-basic-map "#" 'viper-command-argument)
-(define-key viper-vi-basic-map "$" 'viper-goto-eol)
-(define-key viper-vi-basic-map "%" 'viper-paren-match)
-(define-key viper-vi-basic-map "&" (lambda ()
- (interactive) (viper-ex nil "&")))
-(define-key viper-vi-basic-map "'" 'viper-goto-mark-and-skip-white)
-(define-key viper-vi-basic-map "(" 'viper-backward-sentence)
-(define-key viper-vi-basic-map ")" 'viper-forward-sentence)
-(define-key viper-vi-basic-map "*" 'call-last-kbd-macro)
-(define-key viper-vi-basic-map "+" 'viper-next-line-at-bol)
-(define-key viper-vi-basic-map "," 'viper-repeat-find-opposite)
-(define-key viper-vi-basic-map "-" 'viper-previous-line-at-bol)
-(define-key viper-vi-basic-map "." 'viper-repeat)
-(define-key viper-vi-basic-map "/" 'viper-search-forward)
-
-(define-key viper-vi-basic-map "0" 'viper-beginning-of-line)
-(define-key viper-vi-basic-map "1" 'viper-digit-argument)
-(define-key viper-vi-basic-map "2" 'viper-digit-argument)
-(define-key viper-vi-basic-map "3" 'viper-digit-argument)
-(define-key viper-vi-basic-map "4" 'viper-digit-argument)
-(define-key viper-vi-basic-map "5" 'viper-digit-argument)
-(define-key viper-vi-basic-map "6" 'viper-digit-argument)
-(define-key viper-vi-basic-map "7" 'viper-digit-argument)
-(define-key viper-vi-basic-map "8" 'viper-digit-argument)
-(define-key viper-vi-basic-map "9" 'viper-digit-argument)
-
-(define-key viper-vi-basic-map ":" 'viper-ex)
-(define-key viper-vi-basic-map ";" 'viper-repeat-find)
-(define-key viper-vi-basic-map "<" 'viper-command-argument)
-(define-key viper-vi-basic-map "=" 'viper-command-argument)
-(define-key viper-vi-basic-map ">" 'viper-command-argument)
-(define-key viper-vi-basic-map "?" 'viper-search-backward)
-(define-key viper-vi-basic-map "@" 'viper-register-macro)
-
-(define-key viper-vi-basic-map "A" 'viper-Append)
-(define-key viper-vi-basic-map "B" 'viper-backward-Word)
-(define-key viper-vi-basic-map "C" 'viper-change-to-eol)
-(define-key viper-vi-basic-map "D" 'viper-kill-line)
-(define-key viper-vi-basic-map "E" 'viper-end-of-Word)
-(define-key viper-vi-basic-map "F" 'viper-find-char-backward)
-(define-key viper-vi-basic-map "G" 'viper-goto-line)
-(define-key viper-vi-basic-map "H" 'viper-window-top)
-(define-key viper-vi-basic-map "I" 'viper-Insert)
-(define-key viper-vi-basic-map "J" 'viper-join-lines)
-(define-key viper-vi-basic-map "K" 'viper-nil)
-(define-key viper-vi-basic-map "L" 'viper-window-bottom)
-(define-key viper-vi-basic-map "M" 'viper-window-middle)
-(define-key viper-vi-basic-map "N" 'viper-search-Next)
-(define-key viper-vi-basic-map "O" 'viper-Open-line)
-(define-key viper-vi-basic-map "P" 'viper-Put-back)
-(define-key viper-vi-basic-map "Q" 'viper-query-replace)
-(define-key viper-vi-basic-map "R" 'viper-overwrite)
-(define-key viper-vi-basic-map "S" 'viper-substitute-line)
-(define-key viper-vi-basic-map "T" 'viper-goto-char-backward)
-(define-key viper-vi-basic-map "U" 'viper-undo)
-(define-key viper-vi-basic-map "V" 'find-file-other-window)
-(define-key viper-vi-basic-map "W" 'viper-forward-Word)
-(define-key viper-vi-basic-map "X" 'viper-delete-backward-char)
-(define-key viper-vi-basic-map "Y" 'viper-yank-line)
-(define-key viper-vi-basic-map "ZZ" 'viper-save-kill-buffer)
-
-(define-key viper-vi-basic-map "\\" 'viper-escape-to-emacs)
-(define-key viper-vi-basic-map "[" 'viper-brac-function)
-(define-key viper-vi-basic-map "]" 'viper-ket-function)
-(define-key viper-vi-basic-map "\C-\\" 'viper-alternate-Meta-key)
-(define-key viper-vi-basic-map "^" 'viper-bol-and-skip-white)
-(define-key viper-vi-basic-map "`" 'viper-goto-mark)
-
-(define-key viper-vi-basic-map "a" 'viper-append)
-(define-key viper-vi-basic-map "b" 'viper-backward-word)
-(define-key viper-vi-basic-map "c" 'viper-command-argument)
-(define-key viper-vi-basic-map "d" 'viper-command-argument)
-(define-key viper-vi-basic-map "e" 'viper-end-of-word)
-(define-key viper-vi-basic-map "f" 'viper-find-char-forward)
-(define-key viper-vi-basic-map "g" 'viper-nil)
-(define-key viper-vi-basic-map "h" 'viper-backward-char)
-(define-key viper-vi-basic-map [backspace] 'viper-backward-char)
-(define-key viper-vi-basic-map "i" 'viper-insert)
-(define-key viper-vi-basic-map "j" 'viper-next-line)
-(define-key viper-vi-basic-map "k" 'viper-previous-line)
-(define-key viper-vi-basic-map "l" 'viper-forward-char)
-(define-key viper-vi-basic-map "m" 'viper-mark-point)
-(define-key viper-vi-basic-map "n" 'viper-search-next)
-(define-key viper-vi-basic-map "o" 'viper-open-line)
-(define-key viper-vi-basic-map "p" 'viper-put-back)
-(define-key viper-vi-basic-map "q" 'viper-nil)
-(define-key viper-vi-basic-map "r" 'viper-replace-char)
-(define-key viper-vi-basic-map "s" 'viper-substitute)
-(define-key viper-vi-basic-map "t" 'viper-goto-char-forward)
-(define-key viper-vi-basic-map "u" 'viper-undo)
-(define-key viper-vi-basic-map "v" 'find-file)
-(define-key viper-vi-basic-map "\C-v" 'find-file-other-frame)
-(define-key viper-vi-basic-map "w" 'viper-forward-word)
-(define-key viper-vi-basic-map "x" 'viper-delete-char)
-(define-key viper-vi-basic-map "y" 'viper-command-argument)
-(define-key viper-vi-basic-map "zH" 'viper-line-to-top)
-(define-key viper-vi-basic-map "zM" 'viper-line-to-middle)
-(define-key viper-vi-basic-map "zL" 'viper-line-to-bottom)
-(define-key viper-vi-basic-map "z\C-m" 'viper-line-to-top)
-(define-key viper-vi-basic-map "z." 'viper-line-to-middle)
-(define-key viper-vi-basic-map "z-" 'viper-line-to-bottom)
-
-(define-key viper-vi-basic-map "{" 'viper-backward-paragraph)
-(define-key viper-vi-basic-map "|" 'viper-goto-col)
-(define-key viper-vi-basic-map "}" 'viper-forward-paragraph)
-(define-key viper-vi-basic-map "~" 'viper-toggle-case)
-(define-key viper-vi-basic-map "\C-?" 'viper-backward-char)
-(define-key viper-vi-basic-map "_" 'viper-nil)
-
-;;; This is viper-vi-diehard-map. Used when viper-vi-diehard-minor-mode is on.
-
-(define-key viper-vi-diehard-map "\C-a" 'viper-nil)
-(define-key viper-vi-diehard-map "\C-c" 'viper-nil)
-(define-key viper-vi-diehard-map "\C-g" 'viper-info-on-file)
-(define-key viper-vi-diehard-map "\C-i" 'viper-nil)
-(define-key viper-vi-diehard-map "\C-k" 'viper-nil)
-(define-key viper-vi-diehard-map "\C-l" 'redraw-display)
-(define-key viper-vi-diehard-map "\C-n" 'viper-next-line)
-(define-key viper-vi-diehard-map "\C-o" 'viper-nil)
-(define-key viper-vi-diehard-map "\C-p" 'viper-previous-line)
-(define-key viper-vi-diehard-map "\C-q" 'viper-nil)
-(define-key viper-vi-diehard-map "\C-r" 'redraw-display)
-(define-key viper-vi-diehard-map "\C-s" 'viper-nil)
-(define-key viper-vi-diehard-map "\C-t" 'viper-nil)
-(define-key viper-vi-diehard-map "\C-v" 'viper-nil)
-(define-key viper-vi-diehard-map "\C-w" 'viper-nil)
-(define-key viper-vi-diehard-map "@" 'viper-nil)
-(define-key viper-vi-diehard-map "_" 'viper-nil)
-(define-key viper-vi-diehard-map "*" 'viper-nil)
-(define-key viper-vi-diehard-map "#" 'viper-nil)
-(define-key viper-vi-diehard-map "\C-_" 'viper-nil)
-(define-key viper-vi-diehard-map "\C-]" 'viper-nil) ; This is actually tags.
-
-\f
-;;; Minibuffer keymap
-
-
-(defvar-keymap viper-minibuffer-map
- :doc "Keymap used to modify keys when Minibuffer is in Insert state.")
-
-(define-key viper-minibuffer-map "\C-m" 'viper-exit-minibuffer)
-(define-key viper-minibuffer-map "\C-j" 'viper-exit-minibuffer)
-
-;; Map used to read Ex-style commands.
-(defvar-keymap viper-ex-cmd-map)
-(define-key viper-ex-cmd-map " " 'ex-cmd-read-exit)
-(define-key viper-ex-cmd-map "\t" 'ex-cmd-complete)
-
-;; Keymap for reading file names in Ex-style commands.
-(defvar-keymap ex-read-filename-map)
-(define-key ex-read-filename-map " " 'viper-complete-filename-or-exit)
-(define-key ex-read-filename-map "!" 'viper-handle-!)
-
-;; Some other maps
-(defvar-keymap viper-slash-and-colon-map
- :doc "This map redefines \\`/' and \\`:' to behave as in Vi.
-Useful in some modes, such as Gnus, MH, etc.")
-(define-key viper-slash-and-colon-map ":" 'viper-ex)
-(define-key viper-slash-and-colon-map "/" 'viper-search-forward)
-
-(defvar-keymap viper-comint-mode-modifier-map
- :doc "This map modifies comint mode.")
-(define-key viper-comint-mode-modifier-map "\C-m" 'viper-exec-key-in-emacs)
-(define-key viper-comint-mode-modifier-map "\C-d" 'viper-exec-key-in-emacs)
-
-(defvar-keymap viper-dired-modifier-map
- :doc "This map modifies Dired behavior.")
-(define-key viper-dired-modifier-map ":" 'viper-ex)
-(define-key viper-dired-modifier-map "/" 'viper-search-forward)
-
-(defvar-keymap viper-gnus-modifier-map
- :doc "This map modifies Gnus behavior.")
-(define-key viper-gnus-modifier-map ":" 'viper-ex)
-
-
-\f
-;;; Code
-
-(defun viper-add-local-keys (state alist)
- "Override some vi-state or insert-state bindings in the current buffer.
-The effect is seen in the current buffer only.
-Useful for customizing mailer buffers, gnus, etc.
-STATE is `vi-state', `insert-state', or `emacs-state'.
-ALIST is of the form ((KEY . FUNC) (KEY . FUNC) ...)
-Normally, this would be called from a hook to a major mode or
-on a per buffer basis.
-Usage:
- (viper-add-local-keys state \\='((key-str . func) (key-str . func)...))"
-
- (let (map)
- (cond ((eq state 'vi-state)
- (if viper-need-new-vi-local-map
- (setq viper-vi-local-user-map (make-sparse-keymap)))
- (setq viper-need-new-vi-local-map nil
- map viper-vi-local-user-map))
- ((eq state 'insert-state)
- (if viper-need-new-insert-local-map
- (setq viper-insert-local-user-map (make-sparse-keymap)))
- (setq viper-need-new-insert-local-map nil
- map viper-insert-local-user-map))
- ((eq state 'emacs-state)
- (if viper-need-new-emacs-local-map
- (setq viper-emacs-local-user-map (make-sparse-keymap)))
- (setq viper-need-new-emacs-local-map nil
- map viper-emacs-local-user-map))
- (t
- (error
- "Invalid state in viper-add-local-keys: %S. Valid states: vi-state, insert-state or emacs-state" state)))
-
- (viper-modify-keymap map alist)
- (viper-normalize-minor-mode-map-alist)
- (viper-set-mode-vars-for viper-current-state)))
-
-(defun viper-zap-local-keys ()
- "Unconditionally reset Viper viper-*-local-user-map's.
-Rarely useful, but if you made a mistake by switching to a mode that adds
-undesirable local keys, e.g., `comint-mode', then this function can restore
-sanity."
- (interactive)
- (setq viper-vi-local-user-map (make-sparse-keymap)
- viper-need-new-vi-local-map nil
- viper-insert-local-user-map (make-sparse-keymap)
- viper-need-new-insert-local-map nil
- viper-emacs-local-user-map (make-sparse-keymap)
- viper-need-new-emacs-local-map nil)
- (viper-normalize-minor-mode-map-alist))
-
-
-(defun viper-modify-major-mode (mode state keymap)
- "Modify key bindings in a major-mode in a Viper state using a keymap.
-
-If the default for a major mode is emacs-state, then modifications to this
-major mode may not take effect until the buffer switches state to Vi,
-Insert or Emacs. If this happens, add viper-change-state-to-emacs to this
-major mode's hook. If no such hook exists, you may have to put an advice on
-the function that invokes the major mode. See viper-set-hooks for hints.
-
-The above needs not to be done for major modes that come up in Vi or Insert
-state by default.
-
-Arguments: (major-mode viper-state keymap)"
- (let* ((alist
- (cond ((eq state 'vi-state) 'viper-vi-state-modifier-alist)
- ((eq state 'insert-state) 'viper-insert-state-modifier-alist)
- ((eq state 'emacs-state) 'viper-emacs-state-modifier-alist))))
- (setf (alist-get mode (symbol-value alist)) keymap)
-
- ;; Normalization usually doesn't help here, since one needs to
- ;; normalize in the actual buffer where changes to the keymap are
- ;; to take place. However, it doesn't hurt, and it helps whenever this
- ;; function is actually called from within the affected buffer.
- (viper-normalize-minor-mode-map-alist)
-
- (viper-set-mode-vars-for viper-current-state)))
-
-
-;; Displays variables that control Viper's keymaps
-(defun viper-debug-keymaps ()
- (interactive)
- (with-output-to-temp-buffer " *viper-debug*"
- (princ (format "Buffer name: %s\n\n" (buffer-name)))
- (princ "Variables: \n")
- (princ (format "major-mode: %S\n" major-mode))
- (princ (format "viper-current-state: %S\n" viper-current-state))
- (princ (format "viper-mode-string: %S\n\n" viper-mode-string))
- (princ (format "viper-vi-intercept-minor-mode: %S\n"
- viper-vi-intercept-minor-mode))
- (princ (format "viper-insert-intercept-minor-mode: %S\n"
- viper-insert-intercept-minor-mode))
- (princ (format "viper-emacs-intercept-minor-mode: %S\n"
- viper-emacs-intercept-minor-mode))
- (princ (format "viper-vi-minibuffer-minor-mode: %S\n"
- viper-vi-minibuffer-minor-mode))
- (princ (format "viper-insert-minibuffer-minor-mode: %S\n\n"
- viper-insert-minibuffer-minor-mode))
- (princ (format "viper-vi-local-user-minor-mode: %S\n"
- viper-vi-local-user-minor-mode))
- (princ (format "viper-vi-global-user-minor-mode: %S\n"
- viper-vi-global-user-minor-mode))
- (princ (format "viper-vi-kbd-minor-mode: %S\n" viper-vi-kbd-minor-mode))
- (princ (format "viper-vi-state-modifier-minor-mode: %S\n"
- viper-vi-state-modifier-minor-mode))
- (princ (format "viper-vi-diehard-minor-mode: %S\n"
- viper-vi-diehard-minor-mode))
- (princ (format "viper-vi-basic-minor-mode: %S\n" viper-vi-basic-minor-mode))
- (princ (format "viper-replace-minor-mode: %S\n" viper-replace-minor-mode))
- (princ (format "viper-insert-local-user-minor-mode: %S\n"
- viper-insert-local-user-minor-mode))
- (princ (format "viper-insert-global-user-minor-mode: %S\n"
- viper-insert-global-user-minor-mode))
- (princ (format "viper-insert-kbd-minor-mode: %S\n"
- viper-insert-kbd-minor-mode))
- (princ (format "viper-insert-state-modifier-minor-mode: %S\n"
- viper-insert-state-modifier-minor-mode))
- (princ (format "viper-insert-diehard-minor-mode: %S\n"
- viper-insert-diehard-minor-mode))
- (princ (format "viper-insert-basic-minor-mode: %S\n"
- viper-insert-basic-minor-mode))
- (princ (format "viper-emacs-local-user-minor-mode: %S\n"
- viper-emacs-local-user-minor-mode))
- (princ (format "viper-emacs-kbd-minor-mode: %S\n"
- viper-emacs-kbd-minor-mode))
- (princ (format "viper-emacs-global-user-minor-mode: %S\n"
- viper-emacs-global-user-minor-mode))
- (princ (format "viper-emacs-state-modifier-minor-mode: %S\n"
- viper-emacs-state-modifier-minor-mode))
-
- (princ (format "\nviper-expert-level %S\n" viper-expert-level))
- (princ (format "viper-no-multiple-ESC %S\n" viper-no-multiple-ESC))
- (princ (format "viper-always %S\n" viper-always))
- (princ (format "viper-ex-style-motion %S\n"
- viper-ex-style-motion))
- (princ (format "viper-ex-style-editing %S\n"
- viper-ex-style-editing))
- (princ (format "viper-want-emacs-keys-in-vi %S\n"
- viper-want-emacs-keys-in-vi))
- (princ (format "viper-want-emacs-keys-in-insert %S\n"
- viper-want-emacs-keys-in-insert))
- (princ (format "viper-want-ctl-h-help %S\n" viper-want-ctl-h-help))
-
- (princ "\n\n\n")
- (princ (format "Default value for minor-mode-map-alist: \n%S\n\n"
- (default-value 'minor-mode-map-alist)))
- (princ (format "Actual value for minor-mode-map-alist: \n%S\n"
- minor-mode-map-alist))
- ))
-
-
-;;; Keymap utils
-
-(defun viper-add-keymap (mapsrc mapdst)
- "Add contents of mapsrc to mapdst. It is assumed that mapsrc is sparse."
- (mapc (lambda (p) (define-key mapdst (vector (car p)) (cdr p)))
- (cdr mapsrc)))
-
-(defun viper-modify-keymap (map alist)
- "Modifies MAP with bindings specified in the ALIST.
-The ALIST has the form ((KEY . FUNCTION) (KEY . FUNCTION) ... )."
- (mapcar (lambda (p) (define-key map (eval (car p) t) (cdr p)))
- alist))
-
-
-(provide 'viper-keym)
-
-;;; viper-keym.el ends here
+++ /dev/null
-;;; viper-macs.el --- functions implementing keyboard macros for Viper -*- lexical-binding:t -*-
-
-;; Copyright (C) 1994-1997, 2000-2025 Free Software Foundation, Inc.
-
-;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
-;; Package: viper
-
-;; This file is part of GNU Emacs.
-
-;; GNU Emacs is free software: you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; GNU Emacs is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;;; Code:
-
-;; compiler pacifier
-(defvar viper-ex-work-buf)
-(defvar viper-custom-file-name)
-(defvar viper-current-state)
-(defvar viper-fast-keyseq-timeout)
-(require 'viper-mous)
-(require 'viper-ex)
-;; end pacifier
-
-(require 'viper-util)
-(require 'viper-keym)
-(require 'seq)
-
-;;; Variables
-
-;; Register holding last macro.
-(defvar viper-last-macro-reg nil)
-
-;; format of the elements of kbd alists:
-;; (name ((buf . macr)...(buf . macr)) ((maj-mode . macr)...) (t . macr))
-;; kbd macro alist for Vi state
-(defvar viper-vi-kbd-macro-alist nil)
-;; same for insert/replace state
-(defvar viper-insert-kbd-macro-alist nil)
-;; same for emacs state
-(defvar viper-emacs-kbd-macro-alist nil)
-
-;; Internal var that passes info between start-kbd-macro and end-kbd-macro
-;; in :map and :map!
-(defvar viper-kbd-macro-parameters nil)
-
-(defvar viper-this-kbd-macro nil
- "Vector of keys representing the name of currently running Viper kbd macro.")
-(defvar viper-last-kbd-macro nil
- "Vector of keys representing the name of last Viper keyboard macro.")
-
-(defcustom viper-repeat-from-history-key 'f12
- "Prefix key for accessing previously typed Vi commands.
-
-The previous command is accessible, as usual, via `.'. The command before this
-can be invoked as `<this key> 1', and the command before that, and the command
-before that one is accessible as `<this key> 2'.
-Basically, a key is a symbol, e.g., `a', `\\1', `f2', etc., or a
-list, e.g., `(meta control f1)'."
- :type 'sexp
- :group 'viper)
-
-
-\f
-;;; Code
-
-(declare-function viper-change-state-to-insert "viper-cmd" ())
-
-;; Ex map command
-(defun ex-map ()
- (let ((mod-char "")
- macro-name macro-body map-args ins)
- (save-window-excursion
- (set-buffer viper-ex-work-buf)
- (if (looking-at "!")
- (progn
- (setq ins t
- mod-char "!")
- (forward-char 1))))
- (setq map-args (ex-map-read-args mod-char)
- macro-name (car map-args)
- macro-body (cdr map-args))
- (setq viper-kbd-macro-parameters (list ins mod-char macro-name macro-body))
- (if macro-body
- (viper-end-mapping-kbd-macro 'ignore)
- (ex-fixup-history (format "map%s %S" mod-char
- (viper-display-macro macro-name)))
- ;; if defining macro for insert, switch there for authentic WYSIWYG
- (if ins (viper-change-state-to-insert))
- (start-kbd-macro nil)
- (define-key viper-vi-intercept-map "\C-x)" #'viper-end-mapping-kbd-macro)
- (define-key viper-insert-intercept-map "\C-x)"
- #'viper-end-mapping-kbd-macro)
- (define-key viper-emacs-intercept-map "\C-x)"
- #'viper-end-mapping-kbd-macro)
- (message (substitute-command-keys "Mapping %S in %s state. \
-Type macro definition followed by \\[kmacro-end-macro]")
- (viper-display-macro macro-name)
- (if ins "Insert" "Vi")))
- ))
-
-
-;; Ex unmap
-(defun ex-unmap ()
- (let ((mod-char "")
- temp macro-name ins)
- (save-window-excursion
- (set-buffer viper-ex-work-buf)
- (if (looking-at "!")
- (progn
- (setq ins t
- mod-char "!")
- (forward-char 1))))
-
- (setq macro-name (ex-unmap-read-args mod-char))
- (setq temp (viper-fixup-macro (vconcat macro-name))) ;; copy and fixup
- (ex-fixup-history (format "unmap%s %S" mod-char
- (viper-display-macro temp)))
- (viper-unrecord-kbd-macro macro-name (if ins 'insert-state 'vi-state))
- ))
-
-
-;; read arguments for ex-map
-(defun ex-map-read-args (variant)
- (let ((cursor-in-echo-area t)
- (key-seq [])
- temp key event message
- macro-name macro-body args)
-
- (condition-case nil
- (setq args (concat (ex-get-inline-cmd-args ".*map[!]*[ \t]?" "\n\C-m")
- " nil nil ")
- temp (read-from-string args)
- macro-name (car temp)
- macro-body (car (read-from-string args (cdr temp))))
- (error
- (signal
- 'error
- '("map: Macro name and body must be a quoted string or a vector"))))
-
- ;; We expect macro-name to be a vector, a string, or a quoted string.
- ;; In the second case, it will emerge as a symbol when read from
- ;; the above read-from-string. So we need to convert it into a string
- (if macro-name
- (cond ((vectorp macro-name) nil)
- ((stringp macro-name)
- (setq macro-name (vconcat macro-name)))
- (t (setq macro-name (vconcat (prin1-to-string macro-name)))))
- (message ":map%s <Macro Name>" variant)(sit-for 2)
- (while
- (not (member key
- '(?\C-m ?\n (control m) (control j) return linefeed)))
- (setq key-seq (vconcat key-seq (if key (vector key) [])))
- ;; the only keys available for editing are these-- no help while there
- (if (member
- key
- '(?\b ?\d '^? '^H (control h) (control \?) backspace delete))
- (setq key-seq (seq-subseq key-seq 0 (- (length key-seq) 2))))
- (setq message
- (format
- ":map%s %s"
- variant (if (> (length key-seq) 0)
- (prin1-to-string (viper-display-macro key-seq))
- "")))
- (message "%s" message)
- (setq event (read-key))
- ;;(setq event (viper-read-event))
- (setq key
- (if (viper-mouse-event-p event)
- (progn
- (message "%s (No mouse---only keyboard keys, please)"
- message)
- (sit-for 2)
- nil)
- (viper-event-key event)))
- )
- (setq macro-name key-seq))
-
- (if (= (length macro-name) 0)
- (error "Can't map an empty macro name"))
- (setq macro-name (viper-fixup-macro macro-name))
- (if (viper-char-array-p macro-name)
- (setq macro-name (viper-char-array-to-macro macro-name)))
-
- (if macro-body
- (cond ((viper-char-array-p macro-body)
- (setq macro-body (viper-char-array-to-macro macro-body)))
- ((vectorp macro-body) nil)
- (t (error "map: Invalid syntax in macro definition"))))
- (setq cursor-in-echo-area nil)(sit-for 0) ; this overcomes xemacs tty bug
- (cons macro-name macro-body)))
-
-
-
-;; read arguments for ex-unmap
-(defun ex-unmap-read-args (variant)
- (let ((cursor-in-echo-area t)
- (macro-alist (if (string= variant "!")
- viper-insert-kbd-macro-alist
- viper-vi-kbd-macro-alist))
- ;; these are disabled just in case, to avoid surprises when doing
- ;; completing-read
- viper-vi-kbd-minor-mode viper-insert-kbd-minor-mode
- viper-emacs-kbd-minor-mode
- viper-vi-intercept-minor-mode viper-insert-intercept-minor-mode
- viper-emacs-intercept-minor-mode
- event message
- key key-seq macro-name)
- (setq macro-name (ex-get-inline-cmd-args ".*unma?p?[!]*[ \t]*"))
-
- (if (> (length macro-name) 0)
- ()
- (message ":unmap%s <Name>" variant) (sit-for 2)
- (while
- (not
- (member key '(?\C-m ?\n (control m) (control j) return linefeed)))
- (setq key-seq (vconcat key-seq (if key (vector key) [])))
- ;; the only keys available for editing are these-- no help while there
- (cond ((member
- key
- '(?\b ?\d '^? '^H (control h) (control \?) backspace delete))
- (setq key-seq (cl-subseq key-seq 0 (- (length key-seq) 2))))
- ((member key '(tab (control i) ?\t))
- (setq key-seq (cl-subseq key-seq 0 (1- (length key-seq))))
- (setq message
- (format
- ":unmap%s %s"
- variant (if (> (length key-seq) 0)
- (prin1-to-string
- (viper-display-macro key-seq))
- "")))
- (setq key-seq
- (viper-do-sequence-completion key-seq macro-alist message))
- ))
- (setq message
- (format
- ":unmap%s %s"
- variant (if (> (length key-seq) 0)
- (prin1-to-string
- (viper-display-macro key-seq))
- "")))
- (message "%s" message)
- (setq event (read-key))
- ;;(setq event (viper-read-event))
- (setq key
- (if (viper-mouse-event-p event)
- (progn
- (message "%s (No mouse---only keyboard keys, please)"
- message)
- (sit-for 2)
- nil)
- (viper-event-key event)))
- )
- (setq macro-name key-seq))
-
- (if (= (length macro-name) 0)
- (error "Can't unmap an empty macro name"))
-
- ;; convert macro names into vector, if starts with a `['
- (if (memq (elt macro-name 0) '(?\[ ?\"))
- (car (read-from-string macro-name))
- (vconcat macro-name))
- ))
-
-
-(declare-function viper-change-state-to-vi "viper-cmd" (&rest _))
-
-;; Terminate a Vi kbd macro.
-;; optional argument IGNORE, if t, indicates that we are dealing with an
-;; existing macro that needs to be registered, but there is no need to
-;; terminate a kbd macro.
-(defun viper-end-mapping-kbd-macro (&optional ignore)
- (interactive)
- (define-key viper-vi-intercept-map "\C-x)" nil)
- (define-key viper-insert-intercept-map "\C-x)" nil)
- (define-key viper-emacs-intercept-map "\C-x)" nil)
- (if (and (not ignore)
- (or (not viper-kbd-macro-parameters)
- (not defining-kbd-macro)))
- (error "Not mapping a kbd-macro"))
- (let ((mod-char (nth 1 viper-kbd-macro-parameters))
- (ins (nth 0 viper-kbd-macro-parameters))
- (macro-name (nth 2 viper-kbd-macro-parameters))
- (macro-body (nth 3 viper-kbd-macro-parameters)))
- (setq viper-kbd-macro-parameters nil)
- (or ignore
- (progn
- (end-kbd-macro nil)
- (setq macro-body (viper-events-to-macro last-kbd-macro))
- ;; always go back to Vi, since this is where we started
- ;; defining macro
- (viper-change-state-to-vi)))
-
- (viper-record-kbd-macro macro-name
- (if ins 'insert-state 'vi-state)
- (viper-display-macro macro-body))
-
- (ex-fixup-history (format "map%s %S %S" mod-char
- (viper-display-macro macro-name)
- (viper-display-macro macro-body)))
- ))
-
-
-
-\f
-;;; Recording, unrecording, executing
-
-;; Accepts as macro names: strings and vectors.
-;; strings must be strings of characters; vectors must be vectors of keys
-;; in canonical form, which is essentially the form used in XEmacs.
-;; More general definitions are inherited by more specific scopes:
-;; global->major mode->buffer. More specific definitions override more general
-(defun viper-record-kbd-macro (macro-name state macro-body &optional scope)
- "Record a Vi macro.
-Can be used in `viper-custom-file-name' to define permanent macros.
-MACRO-NAME is a string of characters or a vector of keys. STATE is
-either `vi-state' or `insert-state'. It specifies the Viper state in which to
-define the macro. MACRO-BODY is a string that represents the keyboard macro.
-Optional SCOPE says whether the macro should be global \(t), mode-specific
-\(a major-mode symbol), or buffer-specific \(buffer name, a string).
-If SCOPE is nil, the user is asked to specify the scope."
- (let* (state-name keymap
- (macro-alist-var
- (cond ((eq state 'vi-state)
- (setq state-name "Vi state"
- keymap viper-vi-kbd-map)
- 'viper-vi-kbd-macro-alist)
- ((memq state '(insert-state replace-state))
- (setq state-name "Insert state"
- keymap viper-insert-kbd-map)
- 'viper-insert-kbd-macro-alist)
- (t
- (setq state-name "Emacs state"
- keymap viper-emacs-kbd-map)
- 'viper-emacs-kbd-macro-alist)
- ))
- new-elt old-elt old-sub-elt msg
- temp lis lis2)
-
- (if (= (length macro-name) 0)
- (error "Can't map an empty macro name"))
-
- ;; Macro-name is usually a vector. However, command history or macros
- ;; recorded in viper-custom-file-name may be recorded as strings.
- ;; So, convert to vectors.
- (setq macro-name (viper-fixup-macro macro-name))
- (if (viper-char-array-p macro-name)
- (setq macro-name (viper-char-array-to-macro macro-name)))
- (setq macro-body (viper-fixup-macro macro-body))
- (if (viper-char-array-p macro-body)
- (setq macro-body (viper-char-array-to-macro macro-body)))
-
- ;; don't ask if scope is given and is of the right type
- (or (eq scope t)
- (stringp scope)
- (and scope (symbolp scope))
- (progn
- (setq scope
- (cond
- ((y-or-n-p
- (format-message
- "Map this macro for buffer `%s' only? "
- (buffer-name)))
- (setq msg
- (format-message
- "%S is mapped to %s for %s in `%s'"
- (viper-display-macro macro-name)
- (viper-abbreviate-string
- (format
- "%S"
- (setq temp (viper-display-macro macro-body)))
- 14 "" ""
- (if (stringp temp) " ....\"" " ....]"))
- state-name (buffer-name)))
- (buffer-name))
- ((y-or-n-p
- (format-message
- "Map this macro for the major mode `%S' only? "
- major-mode))
- (setq msg
- (format-message
- "%S is mapped to %s for %s in `%S'"
- (viper-display-macro macro-name)
- (viper-abbreviate-string
- (format
- "%S"
- (setq temp (viper-display-macro macro-body)))
- 14 "" ""
- (if (stringp macro-body) " ....\"" " ....]"))
- state-name major-mode))
- major-mode)
- (t
- (setq msg
- (format
- "%S is globally mapped to %s in %s"
- (viper-display-macro macro-name)
- (viper-abbreviate-string
- (format
- "%S"
- (setq temp (viper-display-macro macro-body)))
- 14 "" ""
- (if (stringp macro-body) " ....\"" " ....]"))
- state-name))
- t)))
- (if (y-or-n-p
- (format "Save this macro in %s? "
- (abbreviate-file-name viper-custom-file-name)))
- (viper-save-string-in-file
- (format "\n(viper-record-kbd-macro %S '%S %s '%S)"
- (viper-display-macro macro-name)
- state
- ;; if we don't let vector macro-body through %S,
- ;; the symbols `\.' `\[' etc will be converted into
- ;; characters, causing invalid read error on recorded
- ;; macros in viper-custom-file-name.
- ;; I am not sure is macro-body can still be a string at
- ;; this point, but I am preserving this option anyway.
- (if (vectorp macro-body)
- (format "%S" macro-body)
- macro-body)
- scope)
- viper-custom-file-name))
-
- (message "%s" msg)
- ))
-
- (setq new-elt
- (cons macro-name
- (cond ((eq scope t) (list nil nil (cons t nil)))
- ((symbolp scope)
- (list nil (list (cons scope nil)) (cons t nil)))
- ((stringp scope)
- (list (list (cons scope nil)) nil (cons t nil))))))
- (setq old-elt (assoc macro-name (symbol-value macro-alist-var)))
-
- (if (null old-elt)
- (progn
- ;; insert new-elt in macro-alist-var and keep the list sorted
- (define-key
- keymap
- (vector (viper-key-to-emacs-key (aref macro-name 0)))
- #'viper-exec-mapped-kbd-macro)
- (setq lis (symbol-value macro-alist-var))
- (while (and lis (string< (viper-array-to-string (car (car lis)))
- (viper-array-to-string macro-name)))
- (setq lis2 (cons (car lis) lis2))
- (setq lis (cdr lis)))
-
- (setq lis2 (reverse lis2))
- (set macro-alist-var (append lis2 (cons new-elt lis)))
- (setq old-elt new-elt)))
- (setq old-sub-elt
- (cond ((eq scope t) (viper-kbd-global-pair old-elt))
- ((symbolp scope) (assoc scope (viper-kbd-mode-alist old-elt)))
- ((stringp scope) (assoc scope (viper-kbd-buf-alist old-elt)))))
- (if old-sub-elt
- (setcdr old-sub-elt macro-body)
- (cond ((symbolp scope) (setcar (cdr (cdr old-elt))
- (cons (cons scope macro-body)
- (viper-kbd-mode-alist old-elt))))
- ((stringp scope) (setcar (cdr old-elt)
- (cons (cons scope macro-body)
- (viper-kbd-buf-alist old-elt))))))
- ))
-
-
-
-;; macro name must be a vector of viper-style keys
-;; viper-unrecord-kbd-macro doesn't have scope. Macro definitions are inherited
-;; from global -> major mode -> buffer
-;; More specific definition overrides more general
-;; Can't unrecord definition for more specific, if a more general definition is
-;; in effect
-(defun viper-unrecord-kbd-macro (macro-name state)
- "Delete macro MACRO-NAME from Viper STATE.
-MACRO-NAME must be a vector of viper-style keys. This command is used
-by Viper internally, but you can also use it in `viper-custom-file-name'
-to delete pre-defined macros supplied with Viper. The best way to avoid
-mistakes in macro names to be passed to this function is to use
-`viper-describe-kbd-macros' and copy the name from there."
- (let* (state-name keymap
- (macro-alist-var
- (cond ((eq state 'vi-state)
- (setq state-name "Vi state"
- keymap viper-vi-kbd-map)
- 'viper-vi-kbd-macro-alist)
- ((memq state '(insert-state replace-state))
- (setq state-name "Insert state"
- keymap viper-insert-kbd-map)
- 'viper-insert-kbd-macro-alist)
- (t
- (setq state-name "Emacs state"
- keymap viper-emacs-kbd-map)
- 'viper-emacs-kbd-macro-alist)
- ))
- buf-mapping mode-mapping global-mapping
- macro-pair macro-entry)
-
- ;; Macro-name is usually a vector. However, command history or macros
- ;; recorded in viper-custom-file-name may appear as strings.
- ;; So, convert to vectors.
- (setq macro-name (viper-fixup-macro macro-name))
- (if (viper-char-array-p macro-name)
- (setq macro-name (viper-char-array-to-macro macro-name)))
-
- (setq macro-entry (assoc macro-name (symbol-value macro-alist-var)))
- (if (= (length macro-name) 0)
- (error "Can't unmap an empty macro name"))
- (if (null macro-entry)
- (error "%S is not mapped to a macro for %s in `%s'"
- (viper-display-macro macro-name)
- state-name (buffer-name)))
-
- (setq buf-mapping (viper-kbd-buf-pair macro-entry)
- mode-mapping (viper-kbd-mode-pair macro-entry)
- global-mapping (viper-kbd-global-pair macro-entry))
-
- (cond ((and (cdr buf-mapping)
- (or (and (not (cdr mode-mapping)) (not (cdr global-mapping)))
- (y-or-n-p
- (format-message "Unmap %S for `%s' only? "
- (viper-display-macro macro-name)
- (buffer-name)))))
- (setq macro-pair buf-mapping)
- (message "%S is unmapped for %s in `%s'"
- (viper-display-macro macro-name)
- state-name (buffer-name)))
- ((and (cdr mode-mapping)
- (or (not (cdr global-mapping))
- (y-or-n-p
- (format-message "Unmap %S for the major mode `%S' only? "
- (viper-display-macro macro-name)
- major-mode))))
- (setq macro-pair mode-mapping)
- (message "%S is unmapped for %s in %S"
- (viper-display-macro macro-name) state-name major-mode))
- ((cdr (setq macro-pair global-mapping))
- (message
- "Global mapping for %S in %s is removed"
- (viper-display-macro macro-name) state-name))
- (t (error "%S is not mapped to a macro for %s in `%s'"
- (viper-display-macro macro-name)
- state-name (buffer-name))))
- (setcdr macro-pair nil)
- (or (cdr buf-mapping)
- (cdr mode-mapping)
- (cdr global-mapping)
- (progn
- (set macro-alist-var (delq macro-entry
- (symbol-value macro-alist-var)))
- (if (viper-can-release-key (aref macro-name 0)
- (symbol-value macro-alist-var))
- (define-key
- keymap
- (vector (viper-key-to-emacs-key (aref macro-name 0)))
- nil))
- ))
- ))
-
-;; Check if MACRO-ALIST has an entry for a macro name starting with
-;; CHAR. If not, this indicates that the binding for this char
-;; in viper-vi/insert-kbd-map can be released.
-(defun viper-can-release-key (char macro-alist)
- (let ((lis macro-alist)
- (can-release t)
- macro-name)
-
- (while (and lis can-release)
- (setq macro-name (car (car lis)))
- (if (eq char (aref macro-name 0))
- (setq can-release nil))
- (setq lis (cdr lis)))
- can-release))
-
-
-(defun viper-exec-mapped-kbd-macro (count)
- "Dispatch kbd macro."
- (interactive "P")
- (let* ((macro-alist (cond ((eq viper-current-state 'vi-state)
- viper-vi-kbd-macro-alist)
- ((memq viper-current-state
- '(insert-state replace-state))
- viper-insert-kbd-macro-alist)
- (t
- viper-emacs-kbd-macro-alist)))
- (unmatched-suffix "")
- ;; Macros and keys are executed with other macros turned off
- ;; For macros, this is done to avoid macro recursion
- viper-vi-kbd-minor-mode viper-insert-kbd-minor-mode
- viper-emacs-kbd-minor-mode
- next-best-match keyseq event-seq
- macro-first-char macro-alist-elt macro-body
- command)
-
- (setq macro-first-char last-command-event
- event-seq (viper-read-fast-keysequence macro-first-char macro-alist)
- keyseq (viper-events-to-macro event-seq)
- macro-alist-elt (assoc keyseq macro-alist)
- next-best-match (viper-find-best-matching-macro macro-alist keyseq))
-
- (if (null macro-alist-elt)
- (setq macro-alist-elt (car next-best-match)
- unmatched-suffix (cl-subseq event-seq (cdr next-best-match))))
-
- (cond ((null macro-alist-elt))
- ((setq macro-body (viper-kbd-buf-definition macro-alist-elt)))
- ((setq macro-body (viper-kbd-mode-definition macro-alist-elt)))
- ((setq macro-body (viper-kbd-global-definition macro-alist-elt))))
-
- ;; when defining keyboard macro, don't use the macro mappings
- (if (and macro-body (not defining-kbd-macro))
- ;; block cmd executed as part of a macro from entering command history
- (let ((command-history command-history))
- (setq viper-this-kbd-macro (car macro-alist-elt))
- (execute-kbd-macro (viper-macro-to-events macro-body) count)
- (setq viper-this-kbd-macro nil
- viper-last-kbd-macro (car macro-alist-elt))
- (viper-set-unread-command-events unmatched-suffix))
- ;; If not a macro, or the macro is suppressed while defining another
- ;; macro, put keyseq back on the event queue
- (viper-set-unread-command-events event-seq)
- ;; if the user typed arg, then use it if prefix arg is not set by
- ;; some other command (setting prefix arg can happen if we do, say,
- ;; 2dw and there is a macro starting with 2. Then control will go to
- ;; this routine
- (or prefix-arg (setq prefix-arg count))
- (setq command (key-binding (read-key-sequence nil)))
- (if (commandp command)
- (command-execute command)
- (beep 1)))
- ))
-
-
-\f
-;;; Displaying and completing macros
-
-(defun viper-describe-kbd-macros ()
- "Show currently defined keyboard macros."
- (interactive)
- (with-output-to-temp-buffer " *viper-info*"
- (princ "Macros in Vi state:\n===================\n")
- (mapc #'viper-describe-one-macro viper-vi-kbd-macro-alist)
- (princ "\n\nMacros in Insert and Replace states:\n====================================\n")
- (mapc #'viper-describe-one-macro viper-insert-kbd-macro-alist)
- (princ "\n\nMacros in Emacs state:\n======================\n")
- (mapc #'viper-describe-one-macro viper-emacs-kbd-macro-alist)
- ))
-
-(defun viper-describe-one-macro (macro)
- (princ (format "\n *** Mappings for %S:\n ------------\n"
- (viper-display-macro (car macro))))
- (princ " ** Buffer-specific:")
- (if (viper-kbd-buf-alist macro)
- (mapc #'viper-describe-one-macro-elt (viper-kbd-buf-alist macro))
- (princ " none\n"))
- (princ "\n ** Mode-specific:")
- (if (viper-kbd-mode-alist macro)
- (mapc #'viper-describe-one-macro-elt (viper-kbd-mode-alist macro))
- (princ " none\n"))
- (princ "\n ** Global:")
- (if (viper-kbd-global-definition macro)
- (princ (format "\n %S" (cdr (viper-kbd-global-pair macro))))
- (princ " none"))
- (princ "\n"))
-
-(defun viper-describe-one-macro-elt (elt)
- (let ((name (car elt))
- (defn (cdr elt)))
- (princ (format "\n * %S:\n %S\n" name defn))))
-
-
-
-;; check if SEQ is a prefix of some car of an element in ALIST
-(defun viper-keyseq-is-a-possible-macro (seq alist)
- (let ((converted-seq (viper-events-to-macro seq)))
- (seq-some
- (lambda (elt) (viper-prefix-subseq-p converted-seq elt))
- (viper-this-buffer-macros alist))))
-
-;; whether SEQ1 is a prefix of SEQ2
-(defun viper-prefix-subseq-p (seq1 seq2)
- (let ((len1 (length seq1))
- (len2 (length seq2)))
- (if (<= len1 len2)
- (equal seq1 (cl-subseq seq2 0 len1)))))
-
-;; find the longest common prefix
-(defun viper-common-seq-prefix (&rest seqs)
- (let* ((first (car seqs))
- (rest (cdr seqs))
- (pref [])
- (idx 0)
- len)
- (if (= (length seqs) 0)
- (setq len 0)
- (setq len (apply #'min (mapcar #'length seqs))))
- (while (< idx len)
- (if (seq-every-p (lambda (s) (equal (elt first idx) (elt s idx)))
- rest)
- (setq pref (vconcat pref (vector (elt first idx)))))
- (setq idx (1+ idx)))
- pref))
-
-;; get all sequences that match PREFIX from a given A-LIST
-(defun viper-extract-matching-alist-members (pref alist)
- (delq nil (mapcar (lambda (elt) (if (viper-prefix-subseq-p pref elt) elt))
- (viper-this-buffer-macros alist))))
-
-(defun viper-do-sequence-completion (seq alist compl-message)
- (let* ((matches (viper-extract-matching-alist-members seq alist))
- (new-seq (apply #'viper-common-seq-prefix matches))
- )
- (cond ((and (equal seq new-seq) (= (length matches) 1))
- (message "%s (Sole completion)" compl-message)
- (sit-for 2))
- ((null matches)
- (message "%s (No match)" compl-message)
- (sit-for 2)
- (setq new-seq seq))
- ((member seq matches)
- (message "%s (Complete, but not unique)" compl-message)
- (sit-for 2)
- (viper-display-vector-completions matches))
- ((equal seq new-seq)
- (viper-display-vector-completions matches)))
- new-seq))
-
-
-(defun viper-display-vector-completions (list)
- (with-output-to-temp-buffer "*Completions*"
- (display-completion-list
- (mapcar #'prin1-to-string
- (mapcar #'viper-display-macro list)))))
-
-
-
-;; alist is the alist of macros
-;; str is the fast key sequence entered
-;; returns: (matching-macro-def . unmatched-suffix-start-index)
-(defun viper-find-best-matching-macro (alist str)
- (let ((lis alist)
- (def-len 0)
- (str-len (length str))
- match unmatched-start-idx found macro-def)
- (while (and (not found) lis)
- (setq macro-def (car lis)
- def-len (length (car macro-def)))
- (if (and (>= str-len def-len)
- (equal (car macro-def) (cl-subseq str 0 def-len)))
- (if (or (viper-kbd-buf-definition macro-def)
- (viper-kbd-mode-definition macro-def)
- (viper-kbd-global-definition macro-def))
- (setq found t))
- )
- (setq lis (cdr lis)))
-
- (if found
- (setq match macro-def
- unmatched-start-idx def-len)
- (setq match nil
- unmatched-start-idx 0))
-
- (cons match unmatched-start-idx)))
-
-
-
-;; returns a list of names of macros defined for the current buffer
-(defun viper-this-buffer-macros (macro-alist)
- (let (candidates)
- (setq candidates
- (mapcar (lambda (elt)
- (if (or (viper-kbd-buf-definition elt)
- (viper-kbd-mode-definition elt)
- (viper-kbd-global-definition elt))
- (car elt)))
- macro-alist))
- (setq candidates (delq nil candidates))))
-
-
-;; if seq of Viper key symbols (representing a macro) can be converted to a
-;; string--do so. Otherwise, do nothing.
-(defun viper-display-macro (macro-name-or-body)
- (cond ((viper-char-symbol-sequence-p macro-name-or-body)
- (mapconcat #'symbol-name macro-name-or-body ""))
- ((viper-char-array-p macro-name-or-body)
- (mapconcat #'char-to-string macro-name-or-body ""))
- (t macro-name-or-body)))
-
-;; convert sequence of events (that came presumably from emacs kbd macro) into
-;; Viper's macro, which is a vector of the form
-;; [ desc desc ... ]
-;; Each desc is either a symbol of (meta symb), (shift symb), etc.
-;; Here we purge events that happen to be lists. In most cases, these events
-;; got into a macro definition unintentionally; say, when the user moves mouse
-;; during a macro definition, then something like (switch-frame ...) might get
-;; in. Another reason for purging lists-events is that we can't store them in
-;; textual form (say, in .emacs) and then read them back.
-(defun viper-events-to-macro (event-seq)
- (vconcat (delq nil (mapcar (lambda (elt) (if (consp elt)
- nil
- (viper-event-key elt)))
- event-seq))))
-
-;; convert strings or arrays of characters to Viper macro form
-(defun viper-char-array-to-macro (array)
- (vconcat (mapcar #'viper-event-key (vconcat array))))
-
-;; For macros bodies and names, goes over MACRO and checks if all members are
-;; names of keys (actually, it only checks if they are symbols or lists
-;; if a digit is found, it is converted into a symbol (e.g., 0 -> \0, etc).
-;; If MACRO is not a list or vector -- doesn't change MACRO.
-(defun viper-fixup-macro (macro)
- (let ((len (length macro))
- (idx 0)
- elt break)
- (if (or (vectorp macro) (listp macro))
- (while (and (< idx len) (not break))
- (setq elt (elt macro idx))
- (cond ((numberp elt)
- ;; fix number
- (if (and (<= 0 elt) (<= elt 9))
- (cond ((arrayp macro)
- (aset macro
- idx
- (intern (char-to-string (+ ?0 elt)))))
- ((listp macro)
- (setcar (nthcdr idx macro)
- (intern (char-to-string (+ ?0 elt)))))
- )))
- ((listp elt)
- (viper-fixup-macro elt))
- ((symbolp elt) nil)
- (t (setq break t)))
- (setq idx (1+ idx))))
-
- (if break
- (error "Wrong type macro component, symbol-or-listp, %S" elt)
- macro)))
-
-(defun viper-macro-to-events (macro-body)
- (vconcat (mapcar #'viper-key-to-emacs-key macro-body)))
-
-
-\f
-;;; Reading fast key sequences
-
-;; Assuming that CHAR was the first character in a fast succession of key
-;; strokes, read the rest. Return the vector of keys that was entered in
-;; this fast succession of key strokes.
-;; A fast keysequence is one that is terminated by a pause longer than
-;; viper-fast-keyseq-timeout.
-(defun viper-read-fast-keysequence (event macro-alist)
- ;; FIXME: Do we still need this? Now that the discrimination between the ESC
- ;; key and the ESC byte sent as part of terminal escape sequences is performed
- ;; in the input-decode-map, I suspect that we don't need this hack any more.
- (let ((lis (vector event))
- next-event)
- (while (and (viper-fast-keysequence-p)
- (viper-keyseq-is-a-possible-macro lis macro-alist))
- ;; Seems that viper-read-event is more robust here. We need to be able to
- ;; place these events on unread-command-events list. If we use
- ;; read-key then events will be converted to keys, and sometimes
- ;; (e.g., (control \[)) those keys differ from the corresponding events.
- ;; So, do not use (setq next-event (read-key))
- (setq next-event (read-event))
- (or (viper-mouse-event-p next-event)
- (setq lis (vconcat lis (vector next-event)))))
- lis))
-
-\f
-;;; Keyboard macros in registers
-
-;; sets register to last-kbd-macro carefully.
-(defun viper-set-register-macro (reg)
- (if (get-register reg)
- (if (y-or-n-p "Register contains data. Overwrite? ")
- ()
- (error
- (substitute-command-keys
- "Macro not saved in register. Can still be invoked via \\[kmacro-end-and-call-macro]"))))
- (set-register reg last-kbd-macro))
-
-(defun viper-register-macro (count)
- "Keyboard macros in registers - a modified @ command."
- (interactive "P")
- (let ((reg (downcase (read-char))))
- (cond ((or (and (<= ?a reg) (<= reg ?z)))
- (setq viper-last-macro-reg reg)
- (if defining-kbd-macro
- (progn
- (end-kbd-macro)
- (viper-set-register-macro reg))
- (execute-kbd-macro (get-register reg) count)))
- ((or (= ?@ reg) (= ?\^j reg) (= ?\^m reg))
- (if viper-last-macro-reg
- nil
- (error "No previous kbd macro"))
- (execute-kbd-macro (get-register viper-last-macro-reg) count))
- ((= ?\# reg)
- (start-kbd-macro count))
- ((= ?! reg)
- (setq reg (downcase (read-char)))
- (if (or (and (<= ?a reg) (<= reg ?z)))
- (progn
- (setq viper-last-macro-reg reg)
- (viper-set-register-macro reg))))
- (t
- (error "`%c': Unknown register" reg)))))
-
-
-(defun viper-global-execute ()
- "Call last keyboard macro for each line in the region."
- (if (> (point) (mark t)) (exchange-point-and-mark))
- (beginning-of-line)
- (call-last-kbd-macro)
- (while (< (point) (mark t))
- (forward-line 1)
- (beginning-of-line)
- (call-last-kbd-macro)))
-
-(provide 'viper-macs)
-;;; viper-macs.el ends here
+++ /dev/null
-;;; viper-mous.el --- mouse support for Viper -*- lexical-binding: t; -*-
-
-;; Copyright (C) 1994-1997, 2001-2025 Free Software Foundation, Inc.
-
-;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
-;; Package: viper
-
-;; This file is part of GNU Emacs.
-
-;; GNU Emacs is free software: you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; GNU Emacs is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;;; Code:
-
-;; compiler pacifier
-(defvar double-click-time)
-(defvar viper-search-start-marker)
-(defvar viper-local-search-start-marker)
-(defvar viper-search-history)
-(defvar viper-s-string)
-(defvar viper-re-search)
-
-(require 'viper-util)
-;; end pacifier
-
-
-(defgroup viper-mouse nil
- "Support for Viper special mouse-bound commands."
- :prefix "viper-"
- :group 'viper)
-
-\f
-;;; Variables
-
-;; Variable used for catching the switch-frame event.
-;; If non-nil, indicates that previous-frame should be the selected
-;; one. Used by viper-mouse-click-get-word. Not a user option.
-(defvar viper-frame-of-focus nil)
-
-;; Frame that was selected before the switch-frame event.
-(defvar viper-current-frame-saved (selected-frame))
-
-(defcustom viper-surrounding-word-function 'viper-surrounding-word
- "Function that determines what constitutes a word for clicking events.
-Takes two parameters: a COUNT, indicating how many words to return,
-and CLICK-COUNT, telling whether this is the first click, a double-click,
-or a triple-click."
- :type 'symbol)
-
-;; time interval in millisecond within which successive clicks are
-;; considered related
-(defcustom viper-multiclick-timeout (if (viper-window-display-p)
- (mouse-double-click-time)
- 500)
- "Time interval in milliseconds for mouse clicks to be considered related."
- :type 'integer)
-
-;; Local variable used to toggle wraparound search on click.
-(defvar-local viper-mouse-click-search-noerror t)
-
-;; Local variable used to delimit search after wraparound.
-(defvar-local viper-mouse-click-search-limit nil)
-
-;; remembers prefix argument to pass along to commands invoked by second
-;; click.
-;; This is needed because assigning to prefix-arg causes Emacs to
-;; count the second click as if it was a single click
-(defvar viper-global-prefix-argument nil)
-
-
-;; same keys, but parsed
-(defvar viper-mouse-up-search-key-parsed nil)
-(defvar viper-mouse-down-search-key-parsed nil)
-(defvar viper-mouse-up-insert-key-parsed nil)
-(defvar viper-mouse-down-insert-key-parsed nil)
-
-
-
-\f
-;;; Code
-
-(defsubst viper-multiclick-p ()
- (not (sit-for (/ viper-multiclick-timeout 1000.0) t)))
-
-;; Returns window where click occurs
-(defun viper-mouse-click-window (click)
- (let ((win (posn-window (event-start click))))
- (if (window-live-p win)
- win
- (error "Click was not over a live window"))))
-
-;; Returns window where click occurs
-(defsubst viper-mouse-click-frame (click)
- (window-frame (viper-mouse-click-window click)))
-
-;; Returns the buffer of the window where click occurs
-(defsubst viper-mouse-click-window-buffer (click)
- (window-buffer (viper-mouse-click-window click)))
-
-;; Returns the name of the buffer in the window where click occurs
-(defsubst viper-mouse-click-window-buffer-name (click)
- (buffer-name (viper-mouse-click-window-buffer click)))
-
-(defsubst viper-mouse-click-posn (click)
- "Return position of a click."
- (declare (obsolete nil "27.1"))
- (posn-point (event-start click)))
-
-
-
-(declare-function viper-backward-char-carefully "viper-cmd" (&optional arg))
-(declare-function viper-forward-char-carefully "viper-cmd" (&optional arg))
-
-(defun viper-surrounding-word (count click-count)
- "Return word surrounding point according to a heuristic.
-COUNT indicates how many regions to return.
-If CLICK-COUNT is 1, `word' is a word in Vi sense.
-If CLICK-COUNT is 2,then `word' is a Word in Vi sense.
-If the character clicked on is a non-separator and is non-alphanumeric but
-is adjacent to an alphanumeric symbol, then it is considered alphanumeric
-for the purpose of this command. If this character has a matching
-character, such as `(' is a match for `)', then the matching character is
-also considered alphanumeric.
-For convenience, in Lisp modes, `-' is considered alphanumeric.
-
-If CLICK-COUNT is 3 or more, returns the line clicked on with leading and
-trailing space and tabs removed. In that case, the first argument, COUNT,
-is ignored."
- (let ((modifiers "_")
- beg skip-flag result
- word-beg)
- (if (> click-count 2)
- (save-excursion
- (beginning-of-line)
- (viper-skip-all-separators-forward 'within-line)
- (setq beg (point))
- (end-of-line)
- (setq result (buffer-substring beg (point))))
-
- (if (and (not (viper-looking-at-alphasep))
- (or (save-excursion (viper-backward-char-carefully)
- (viper-looking-at-alpha))
- (save-excursion (viper-forward-char-carefully)
- (viper-looking-at-alpha))))
- (setq modifiers
- (concat modifiers
- (cond ((looking-at "\\\\") "\\\\")
- ((looking-at "-") "C-C-")
- ((looking-at "[][]") "][")
- ((looking-at "[()]") ")(")
- ((looking-at "[{}]") "{}")
- ((looking-at "[<>]") "<>")
- ((looking-at "[`']") "`'")
- ((looking-at "\\^") "\\^")
- ((viper-looking-at-separator) "")
- (t (char-to-string (following-char))))
- )
- ))
-
- ;; Add `-' to alphanum, if it wasn't added and if we are in Lisp
- (or (looking-at "-")
- (not (string-match "lisp" (symbol-name major-mode)))
- (setq modifiers (concat modifiers "C-C-")))
-
-
- (save-excursion
- (cond ((> click-count 1) (viper-skip-nonseparators 'backward))
- ((viper-looking-at-alpha modifiers)
- (viper-skip-alpha-backward modifiers))
- ((not (viper-looking-at-alphasep modifiers))
- (viper-skip-nonalphasep-backward))
- (t (if (> click-count 1)
- (viper-skip-nonseparators 'backward)
- (viper-skip-alpha-backward modifiers))))
-
- (setq word-beg (point))
-
- (setq skip-flag nil) ; don't move 1 char forw the first time
- (while (> count 0)
- (if skip-flag (viper-forward-char-carefully 1))
- (setq skip-flag t) ; now always move 1 char forward
- (if (> click-count 1)
- (viper-skip-nonseparators 'forward)
- (viper-skip-alpha-forward modifiers))
- (setq count (1- count)))
-
- (setq result (buffer-substring word-beg (point))))
- ) ; if
- ;; FIXME: Use `buffer-substring-no-properties' above instead?
- (set-text-properties 0 (length result) nil result)
- result))
-
-
-(defun viper-mouse-click-get-word (click count click-count)
- "Return word surrounding the position of a mouse click.
-Click may be in another window. Current window and buffer isn't changed.
-On single or double click, returns the word as determined by
-`viper-surrounding-word-function'."
-
- (let ((click-word "")
- (click-pos (posn-point (event-start click)))
- (click-buf (viper-mouse-click-window-buffer click)))
- (or (natnump count) (setq count 1))
- (or (natnump click-count) (setq click-count 1))
-
- (save-excursion
- (save-window-excursion
- (if click-pos
- (progn
- (set-buffer click-buf)
-
- (goto-char click-pos)
- (setq click-word
- (funcall viper-surrounding-word-function count click-count)))
- (error "Click must be over a window"))
- click-word))))
-
-
-(defun viper-mouse-click-insert-word (click arg)
- "Insert word clicked or double-clicked on.
-With prefix argument, N, insert that many words.
-This command must be bound to a mouse click.
-The double-click action of the same mouse button must not be bound
-\(or it must be bound to the same function).
-See `viper-surrounding-word' for the definition of a word in this case."
- (interactive "e\nP")
- (if viper-frame-of-focus ;; to handle clicks in another frame
- (select-frame viper-frame-of-focus))
- (if (save-excursion
- (or (not (eq (key-binding viper-mouse-down-insert-key-parsed)
- 'viper-mouse-catch-frame-switch))
- (not (eq (key-binding viper-mouse-up-insert-key-parsed)
- 'viper-mouse-click-insert-word))))
- () ; do nothing, if binding isn't right or not over text
- ;; turn arg into a number
- (cond ((integerp arg) nil)
- ;; prefix arg is a list when one hits C-u then command
- ((and (listp arg) (integerp (car arg)))
- (setq arg (car arg)))
- (t (setq arg 1)))
-
- (if (not (eq (key-binding viper-mouse-down-insert-key-parsed)
- 'viper-mouse-catch-frame-switch))
- () ; do nothing
- (let (click-count interrupting-event)
- (if (and
- (viper-multiclick-p)
- ;; This trick checks if there is a pending mouse event if so, we
- ;; use this latter event and discard the current mouse click If
- ;; the next pending event is not a mouse event, we execute the
- ;; current mouse event
- (progn
- (setq interrupting-event (read-event))
- (viper-mouse-event-p last-input-event)))
- (progn ; interrupted wait
- (setq viper-global-prefix-argument arg))
- ;; uninterrupted wait or the interrupting event wasn't a mouse event
- (setq click-count (event-click-count click))
- (if (> click-count 1)
- (setq arg viper-global-prefix-argument
- viper-global-prefix-argument nil))
- (insert (viper-mouse-click-get-word click arg click-count))
- (if (and interrupting-event
- (eventp interrupting-event)
- (not (viper-mouse-event-p interrupting-event)))
- (viper-set-unread-command-events interrupting-event))
- )))))
-
-;; Arg is an event. Accepts symbols and numbers, too
-(defun viper-mouse-event-p (event)
- (if (eventp event)
- (string-match "\\(mouse-\\|frame\\|screen\\|track\\)"
- (prin1-to-string (viper-event-key event)))))
-
-(define-obsolete-function-alias 'viper-event-click-count
- #'event-click-count "28.1")
-
-(declare-function viper-forward-word "viper-cmd" (arg))
-(declare-function viper-adjust-window "viper-cmd" ())
-
-(defun viper-mouse-click-search-word (click arg)
- "Find the word clicked or double-clicked on. Word may be in another window.
-With prefix argument, N, search for N-th occurrence.
-This command must be bound to a mouse click. The double-click action of the
-same button must not be bound \(or it must be bound to the same function).
-See `viper-surrounding-word' for the details on what constitutes a word for
-this command.
-\n(fn CLICK N)"
- (interactive "e\nP")
- (if viper-frame-of-focus ;; to handle clicks in another frame
- (select-frame viper-frame-of-focus))
- (if (save-excursion
- (or (not (eq (key-binding viper-mouse-down-search-key-parsed)
- 'viper-mouse-catch-frame-switch))
- (not (eq (key-binding viper-mouse-up-search-key-parsed)
- 'viper-mouse-click-search-word))))
- () ; do nothing, if binding isn't right or not over text
- (let ((previous-search-string viper-s-string)
- click-word click-count)
-
- (if (and
- (viper-multiclick-p)
- ;; This trick checks if there is a pending mouse event if so, we use
- ;; this latter event and discard the current mouse click If the next
- ;; pending event is not a mouse event, we execute the current mouse
- ;; event
- (progn
- (read-event)
- (viper-mouse-event-p last-input-event)))
- (progn ; interrupted wait
- (setq viper-global-prefix-argument (or viper-global-prefix-argument
- arg)
- ;; remember command that was before the multiclick
- this-command last-command))
- ;; uninterrupted wait
- (setq click-count (event-click-count click))
- (setq click-word (viper-mouse-click-get-word click nil click-count))
-
- (if (> click-count 1)
- (setq arg viper-global-prefix-argument
- viper-global-prefix-argument nil))
- (setq arg (or arg 1))
-
- (deactivate-mark)
- (if (or (not (string= click-word viper-s-string))
- (not (markerp viper-search-start-marker))
- (not (equal (marker-buffer viper-search-start-marker)
- (current-buffer)))
- (not (eq last-command 'viper-mouse-click-search-word)))
- (progn
- (setq viper-search-start-marker (point-marker)
- viper-local-search-start-marker viper-search-start-marker
- viper-mouse-click-search-noerror t
- viper-mouse-click-search-limit nil)
-
- ;; make search string known to Viper
- (setq viper-s-string (if viper-re-search
- (regexp-quote click-word)
- click-word))
- (if (not (string= viper-s-string (car viper-search-history)))
- (setq viper-search-history
- (cons viper-s-string viper-search-history)))
- ))
-
- (push-mark nil t)
- (while (> arg 0)
- (viper-forward-word 1)
- (condition-case nil
- (progn
- (if (not (search-forward
- click-word viper-mouse-click-search-limit
- viper-mouse-click-search-noerror))
- (progn
- (setq viper-mouse-click-search-noerror nil)
- (setq viper-mouse-click-search-limit
- (save-excursion
- (if (and
- (markerp viper-local-search-start-marker)
- (marker-buffer viper-local-search-start-marker))
- (goto-char viper-local-search-start-marker))
- (viper-line-pos 'end)))
-
- (goto-char (point-min))
- (search-forward click-word
- viper-mouse-click-search-limit nil)))
- (goto-char (match-beginning 0))
- (message "Searching for: %s" viper-s-string)
- (if (<= arg 1) ; found the right occurrence of the pattern
- (progn
- (viper-adjust-window)
- (viper-flash-search-pattern)))
- )
- (error (beep 1)
- (if (or (not (string= click-word previous-search-string))
- (not (eq last-command 'viper-mouse-click-search-word)))
- (message "`%s': String not found in %s"
- viper-s-string (buffer-name (current-buffer)))
- (message
- "`%s': Last occurrence in %s. Back to beginning of search"
- click-word (buffer-name (current-buffer)))
- (setq arg 1) ;; to terminate the loop
- (sit-for 2))
- (setq viper-mouse-click-search-noerror t)
- (setq viper-mouse-click-search-limit nil)
- (if (and (markerp viper-local-search-start-marker)
- (marker-buffer viper-local-search-start-marker))
- (goto-char viper-local-search-start-marker))))
- (setq arg (1- arg)))
- ))))
-
-(defun viper-mouse-catch-frame-switch (_event arg)
- "Catch the event of switching frame.
-Usually is bound to a `down-mouse' event to work properly. See sample
-bindings in the Viper manual."
- (interactive "e\nP")
- (setq viper-frame-of-focus nil)
- ;; pass prefix arg along to viper-mouse-click-search/insert-word
- (setq prefix-arg arg)
- (if (eq last-command 'handle-switch-frame)
- (setq viper-frame-of-focus viper-current-frame-saved))
- ;; make Emacs forget that it executed viper-mouse-catch-frame-switch
- (setq this-command last-command))
-
-;; Called just before switching frames. Saves the old selected frame.
-;; Sets last-command to handle-switch-frame (this is done automatically in
-;; Emacs.
-;; The semantics of switching frames is different in Emacs and XEmacs.
-;; In Emacs, if you select-frame A while mouse is over frame B and then
-;; start typing, input goes to frame B, which becomes selected.
-;; In XEmacs, input will go to frame A. This may be a bug in one of the
-;; Emacsen, but also may be a design decision.
-;; Also, in Emacs sending input to frame B generates handle-switch-frame
-;; event, while in XEmacs it doesn't.
-;; All this accounts for the difference in the behavior of
-;; viper-mouse-click-* commands when you click in a frame other than the one
-;; that was the last to receive input. In Emacs, focus will be in frame A
-;; until you do something other than viper-mouse-click-* command.
-;; In XEmacs, you have to manually select frame B (with the mouse click) in
-;; order to shift focus to frame B.
-(defun viper-remember-current-frame (&rest _)
- "Remember the selected frame before the switch-frame event."
- (setq last-command #'handle-switch-frame
- viper-current-frame-saved (selected-frame)))
-
-
-;; The key is of the form (MODIFIER ... BUTTON-NUMBER)
-;; Converts into a valid mouse button spec for the appropriate version of
-;; Emacs. EVENT-TYPE is either `up' or `down'. Up returns button-up key; down
-;; returns button-down key.
-(defun viper-parse-mouse-key (key-var event-type)
- (let ((key (symbol-value key-var))
- button-spec meta-spec shift-spec control-spec)
- (if (null key)
- ;; just return nil
- ()
- (setq button-spec
- (cond ((memq 1 key)
- (if (eq 'up event-type)
- "mouse-1" "down-mouse-1"))
- ((memq 2 key)
- (if (eq 'up event-type)
- "mouse-2" "down-mouse-2"))
- ((memq 3 key)
- (if (eq 'up event-type)
- "mouse-3" "down-mouse-3"))
- (t (error
- "%S: Invalid button number, %S" key-var key)))
- meta-spec
- (if (memq 'meta key) "M-" "")
- shift-spec
- (if (memq 'shift key) "S-" "")
- control-spec
- (if (memq 'control key) "C-" ""))
-
- (vector
- (intern (concat control-spec meta-spec
- shift-spec button-spec))))))
-
-(defun viper-unbind-mouse-search-key ()
- (if viper-mouse-up-search-key-parsed
- (global-unset-key viper-mouse-up-search-key-parsed))
- (if viper-mouse-down-search-key-parsed
- (global-unset-key viper-mouse-down-search-key-parsed))
- (setq viper-mouse-up-search-key-parsed nil
- viper-mouse-down-search-key-parsed nil))
-
-(defun viper-unbind-mouse-insert-key ()
- (if viper-mouse-up-insert-key-parsed
- (global-unset-key viper-mouse-up-insert-key-parsed))
- (if viper-mouse-down-insert-key-parsed
- (global-unset-key viper-mouse-down-insert-key-parsed))
- (setq viper-mouse-up-insert-key-parsed nil
- viper-mouse-down-insert-key-parsed nil))
-
-;; If FORCE, bind even if this mouse action is already bound to something else
-(defun viper-bind-mouse-search-key (&optional force)
- (setq viper-mouse-up-search-key-parsed
- (viper-parse-mouse-key 'viper-mouse-search-key 'up)
- viper-mouse-down-search-key-parsed
- (viper-parse-mouse-key 'viper-mouse-search-key 'down))
- (cond ((not (and viper-mouse-up-search-key-parsed
- viper-mouse-down-search-key-parsed))
- nil) ; just quit
- ((and (null force)
- (key-binding viper-mouse-up-search-key-parsed)
- (not (eq (key-binding viper-mouse-up-search-key-parsed)
- 'viper-mouse-click-search-word)))
- (message
- "%S already bound to a mouse event. Viper mouse-search feature disabled"
- viper-mouse-up-search-key-parsed))
- ((and (null force)
- (key-binding viper-mouse-down-search-key-parsed)
- (not (eq (key-binding viper-mouse-down-search-key-parsed)
- 'viper-mouse-catch-frame-switch)))
- (message
- "%S already bound to a mouse event. Viper mouse-search feature disabled"
- viper-mouse-down-search-key-parsed))
- (t
- (global-set-key viper-mouse-up-search-key-parsed
- #'viper-mouse-click-search-word)
- (global-set-key viper-mouse-down-search-key-parsed
- #'viper-mouse-catch-frame-switch))))
-
-;; If FORCE, bind even if this mouse action is already bound to something else
-(defun viper-bind-mouse-insert-key (&optional force)
- (setq viper-mouse-up-insert-key-parsed
- (viper-parse-mouse-key 'viper-mouse-insert-key 'up)
- viper-mouse-down-insert-key-parsed
- (viper-parse-mouse-key 'viper-mouse-insert-key 'down))
- (cond ((not (and viper-mouse-up-insert-key-parsed
- viper-mouse-down-insert-key-parsed))
- nil) ; just quit
- ((and (null force)
- (key-binding viper-mouse-up-insert-key-parsed)
- (not (eq (key-binding viper-mouse-up-insert-key-parsed)
- 'viper-mouse-click-insert-word)))
- (message
- "%S already bound to a mouse event. Viper mouse-insert feature disabled"
- viper-mouse-up-insert-key-parsed))
- ((and (null force)
- (key-binding viper-mouse-down-insert-key-parsed)
- (not (eq (key-binding viper-mouse-down-insert-key-parsed)
- 'viper-mouse-catch-frame-switch)))
- (message
- "%S already bound to a mouse event. Viper mouse-insert feature disabled"
- viper-mouse-down-insert-key-parsed))
- (t
- (global-set-key viper-mouse-up-insert-key-parsed
- #'viper-mouse-click-insert-word)
- (global-set-key viper-mouse-down-insert-key-parsed
- #'viper-mouse-catch-frame-switch))))
-
-(defun viper-reset-mouse-search-key (symb val)
- (viper-unbind-mouse-search-key)
- (set symb val)
- (viper-bind-mouse-search-key 'force))
-
-(defun viper-reset-mouse-insert-key (symb val)
- (viper-unbind-mouse-insert-key)
- (set symb val)
- (viper-bind-mouse-insert-key 'force))
-
-
-(defcustom viper-mouse-search-key '(meta shift 1)
- "Key used to click-search in Viper.
-This must be a list that specifies the mouse button and modifiers.
-The supported modifiers are `meta', `shift', and `control'.
-For instance, `(meta shift 1)' means that holding the meta and shift
-keys down and clicking on a word with mouse button 1
-will search for that word in the buffer that was current before the click.
-This buffer may be different from the one where the click occurred."
- :type '(list (set :inline t :tag "Modifiers" :format "%t: %v"
- (const :format "%v " meta)
- (const :format "%v " shift)
- (const control))
- (integer :tag "Button"))
- :set #'viper-reset-mouse-search-key)
-
-(defcustom viper-mouse-insert-key '(meta shift 2)
- "Key used to click-insert in Viper.
-Must be a list that specifies the mouse button and modifiers.
-The supported modifiers are `meta', `shift', and `control'.
-For instance, `(meta shift 2)' means that holding the meta and shift keys
-down, and clicking on a word with mouse button 2, will insert that word
-at the cursor in the buffer that was current just before the click.
-This buffer may be different from the one where the click occurred."
- :type '(list (set :inline t :tag "Modifiers" :format "%t: %v"
- (const :format "%v " meta)
- (const :format "%v " shift)
- (const control))
- (integer :tag "Button"))
- :set #'viper-reset-mouse-insert-key)
-
-(provide 'viper-mous)
-;;; viper-mous.el ends here
+++ /dev/null
-;;; viper-util.el --- Utilities used by viper.el -*- lexical-binding:t -*-
-
-;; Copyright (C) 1994-2025 Free Software Foundation, Inc.
-
-;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
-;; Package: viper
-
-;; This file is part of GNU Emacs.
-
-;; GNU Emacs is free software: you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; GNU Emacs is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;;; Code:
-
-(require 'seq)
-(require 'cl-lib)
-
-;; Compiler pacifier
-(defvar viper-minibuffer-current-face)
-(defvar viper-replace-overlay-face)
-(defvar viper-fast-keyseq-timeout)
-(defvar ex-unix-type-shell)
-(defvar ex-unix-type-shell-options)
-(defvar viper-ex-tmp-buf-name)
-(defvar viper-syntax-preference)
-
-(require 'ring)
-
-;; end pacifier
-
-(require 'viper-init)
-
-
-\f
-(define-obsolete-function-alias 'viper-overlay-p #'overlayp "27.1")
-(define-obsolete-function-alias 'viper-make-overlay #'make-overlay "27.1")
-(define-obsolete-function-alias 'viper-overlay-live-p #'overlayp "27.1")
-(define-obsolete-function-alias 'viper-move-overlay #'move-overlay "27.1")
-(define-obsolete-function-alias 'viper-overlay-start #'overlay-start "27.1")
-(define-obsolete-function-alias 'viper-overlay-end #'overlay-end "27.1")
-(define-obsolete-function-alias 'viper-overlay-get #'overlay-get "27.1")
-(define-obsolete-function-alias 'viper-overlay-put #'overlay-put "27.1")
-(define-obsolete-function-alias 'viper-read-event #'read-event "27.1")
-(define-obsolete-function-alias 'viper-characterp #'integerp "27.1")
-(define-obsolete-function-alias 'viper-int-to-char #'identity "27.1")
-(define-obsolete-function-alias 'viper-get-face #'facep "27.1")
-(define-obsolete-function-alias 'viper-color-defined-p
- #'color-defined-p "27.1")
-(define-obsolete-function-alias 'viper-iconify
- #'iconify-or-deiconify-frame "27.1")
-
-(define-obsolete-function-alias 'viper-memq-char #'memq "29.1")
-(define-obsolete-function-alias 'viper-char-equal #'eq "29.1")
-
-;; Like =, but accommodates null and also is t for eq-objects
-(defun viper= (char char1)
- (cond ((eq char char1) t)
- ((and (characterp char) (characterp char1))
- (= char char1))
- (t nil)))
-
-(define-obsolete-function-alias 'viper-color-display-p #'display-color-p "29.1")
-
-(defun viper-get-cursor-color (&optional _frame)
- (cdr (assoc 'cursor-color (frame-parameters))))
-
-(defmacro viper-frame-value (variable)
- "Return the value of VARIABLE local to the current frame, if there is one.
-Otherwise return the normal value."
- `(if (local-variable-p ',variable)
- ,variable
- ;; Distinguish between no frame parameter and a frame parameter
- ;; with a value of nil.
- (let ((fp (assoc ',variable (frame-parameters))))
- (if fp (cdr fp)
- ,variable))))
-
-;; cursor colors
-(defun viper-change-cursor-color (new-color &optional frame)
- (if (and (viper-window-display-p) (display-color-p)
- (stringp new-color) (color-defined-p new-color)
- (not (string= new-color (viper-get-cursor-color))))
- (modify-frame-parameters
- (or frame (selected-frame))
- (list (cons 'cursor-color new-color)))))
-
-;; Note that the colors this function uses might not be those
-;; associated with FRAME, if there are frame-local values.
-;; This was equally true before the advent of viper-frame-value.
-;; Now it could be changed by passing frame to v-f-v.
-(defun viper-set-cursor-color-according-to-state (&optional frame)
- (cond ((eq viper-current-state 'replace-state)
- (viper-change-cursor-color
- (viper-frame-value viper-replace-overlay-cursor-color)
- frame))
- ((and (eq viper-current-state 'emacs-state)
- (viper-frame-value viper-emacs-state-cursor-color))
- (viper-change-cursor-color
- (viper-frame-value viper-emacs-state-cursor-color)
- frame))
- ((eq viper-current-state 'insert-state)
- (viper-change-cursor-color
- (viper-frame-value viper-insert-state-cursor-color)
- frame))
- (t
- (viper-change-cursor-color
- (viper-frame-value viper-vi-state-cursor-color)
- frame))))
-
-;; By default, saves current frame cursor color before changing viper state
-(defun viper-save-cursor-color (before-which-mode)
- (if (and (viper-window-display-p) (display-color-p))
- (let ((color (viper-get-cursor-color)))
- (if (and (stringp color) (color-defined-p color)
- ;; there is something fishy in that the color is not saved if
- ;; it is the same as frames default cursor color. need to be
- ;; checked.
- (not (string= color
- (viper-frame-value
- viper-replace-overlay-cursor-color))))
- (modify-frame-parameters
- (selected-frame)
- (list
- (cons
- (cond ((eq before-which-mode 'before-replace-mode)
- 'viper-saved-cursor-color-in-replace-mode)
- ((eq before-which-mode 'before-emacs-mode)
- 'viper-saved-cursor-color-in-emacs-mode)
- (t
- 'viper-saved-cursor-color-in-insert-mode))
- color)))))))
-
-
-(defun viper-get-saved-cursor-color-in-replace-mode ()
- (or
- (frame-parameter (selected-frame) 'viper-saved-cursor-color-in-replace-mode)
- (or (and (eq viper-current-state 'emacs-mode)
- (viper-frame-value viper-emacs-state-cursor-color))
- (viper-frame-value viper-vi-state-cursor-color))))
-
-(defun viper-get-saved-cursor-color-in-insert-mode ()
- (or
- (frame-parameter (selected-frame) 'viper-saved-cursor-color-in-insert-mode)
- (or (and (eq viper-current-state 'emacs-mode)
- (viper-frame-value viper-emacs-state-cursor-color))
- (viper-frame-value viper-vi-state-cursor-color))))
-
-(defun viper-get-saved-cursor-color-in-emacs-mode ()
- (or
- (frame-parameter (selected-frame) 'viper-saved-cursor-color-in-emacs-mode)
- (viper-frame-value viper-vi-state-cursor-color)))
-
-;; restore cursor color from replace overlay
-(defun viper-restore-cursor-color(after-which-mode)
- (if (overlayp viper-replace-overlay)
- (viper-change-cursor-color
- (cond ((eq after-which-mode 'after-replace-mode)
- (viper-get-saved-cursor-color-in-replace-mode))
- ((eq after-which-mode 'after-emacs-mode)
- (viper-get-saved-cursor-color-in-emacs-mode))
- (t (viper-get-saved-cursor-color-in-insert-mode)))
- )))
-
-\f
-;; Check the current version against the major and minor version numbers
-;; using op: cur-vers op major.minor
-(defun viper-check-version (op major minor &optional _type-of-emacs)
- (declare (obsolete nil "28.1"))
- (cond ((eq op '=) (and (= emacs-minor-version minor)
- (= emacs-major-version major)))
- ((memq op '(> >= < <=))
- (and (or (funcall op emacs-major-version major)
- (= emacs-major-version major))
- (if (= emacs-major-version major)
- (funcall op emacs-minor-version minor)
- t)))
- (t
- (error "%S: Invalid op in viper-check-version" op))))
-
-
-(defun viper-get-visible-buffer-window (wind)
- (declare (obsolete "use `(get-buffer-window wind 'visible)'." "29.1"))
- (get-buffer-window wind 'visible))
-
-;; Return line position.
-;; If pos is 'start then returns position of line start.
-;; If pos is 'end, returns line end. If pos is 'mid, returns line center.
-;; Pos = 'indent returns beginning of indentation.
-;; Otherwise, returns point. Current point is not moved in any case."
-(defun viper-line-pos (pos)
- (let ((cur-pos (point))
- (result))
- (cond
- ((equal pos 'start)
- (beginning-of-line))
- ((equal pos 'end)
- (end-of-line))
- ((equal pos 'mid)
- (goto-char (+ (viper-line-pos 'start) (viper-line-pos 'end) 2)))
- ((equal pos 'indent)
- (back-to-indentation))
- (t nil))
- (setq result (point))
- (goto-char cur-pos)
- result))
-
-(defun viper-chars-in-region (beg end &optional preserve-sign)
- (let ((count (abs (- end beg))))
- (if (and (< end beg) preserve-sign)
- (- count)
- count)))
-
-;; Test if POS is between BEG and END
-(defsubst viper-pos-within-region (pos beg end)
- (and (>= pos (min beg end)) (>= (max beg end) pos)))
-
-
-;; Like move-marker but creates a virgin marker if arg isn't already a marker.
-;; The first argument must eval to a variable name.
-;; Arguments: (var-name position &optional buffer).
-;;
-;; This is useful for moving markers that are supposed to be local.
-;; For this, VAR-NAME should be made buffer-local with nil as a default.
-;; Then, each time this var is used in `viper-move-marker-locally' in a new
-;; buffer, a new marker will be created.
-(defun viper-move-marker-locally (var pos &optional buffer)
- (if (markerp (symbol-value var))
- ()
- (set var (make-marker)))
- (move-marker (symbol-value var) pos buffer))
-
-
-;; Print CONDITIONS as a message.
-(defun viper-message-conditions (conditions)
- (let ((case (car conditions)) (msg (cdr conditions)))
- (if (null msg)
- (message "%s" case)
- (message "%s: %s" case (mapconcat #'prin1-to-string msg " ")))
- (beep 1)))
-
-
-\f
-;;; List/alist utilities
-
-;; Convert LIST to an alist
-(defun viper-list-to-alist (lst)
- (let ((alist))
- (while lst
- (setq alist (cons (list (car lst)) alist))
- (setq lst (cdr lst)))
- alist))
-
-;; Convert ALIST to a list.
-(defun viper-alist-to-list (alst)
- (let ((lst))
- (while alst
- (setq lst (cons (car (car alst)) lst))
- (setq alst (cdr alst)))
- lst))
-
-;; Filter ALIST using REGEXP. Return alist whose elements match the regexp.
-(defun viper-filter-alist (regexp alst)
- (interactive "s x")
- (let ((outalst) (inalst alst))
- (while (car inalst)
- (if (string-match regexp (car (car inalst)))
- (setq outalst (cons (car inalst) outalst)))
- (setq inalst (cdr inalst)))
- outalst))
-
-;; Filter LIST using REGEXP. Return list whose elements match the regexp.
-(defun viper-filter-list (regexp lst)
- (interactive "s x")
- (let ((outlst) (inlst lst))
- (while (car inlst)
- (if (string-match regexp (car inlst))
- (setq outlst (cons (car inlst) outlst)))
- (setq inlst (cdr inlst)))
- outlst))
-
-
-;; Append LIS2 to LIS1, both alists, by side-effect and returns LIS1
-;; LIS2 is modified by filtering it: deleting its members of the form
-;; (car elt) such that (car elt') is in LIS1.
-(defun viper-append-filter-alist (lis1 lis2)
- (let ((temp lis1)
- elt)
- ;;filter-append the second list
- (while temp
- ;; delete all occurrences
- (while (setq elt (assoc (car (car temp)) lis2))
- (setq lis2 (delq elt lis2)))
- (setq temp (cdr temp)))
-
- (append lis1 lis2)))
-
-
-\f
-(declare-function viper-forward-Word "viper-cmd" (arg))
-
-;;; Support for :e, :r, :w file globbing
-
-;; Glob the file spec.
-;; This function is designed to work under Unix.
-(defun viper-glob-unix-files (filespec)
- (let ((gshell
- (cond (ex-unix-type-shell shell-file-name)
- (t "sh"))) ; probably Unix anyway
- (gshell-options
- ;; using cond in anticipation of further additions
- (cond (ex-unix-type-shell-options)
- ))
- (command (cond (viper-ms-style-os-p (format "\"ls -1 -d %s\"" filespec))
- (t (format "ls -1 -d %s" filespec))))
- status)
- (with-current-buffer (get-buffer-create viper-ex-tmp-buf-name)
- (erase-buffer)
- (setq status
- (if gshell-options
- (call-process gshell nil t nil
- gshell-options
- "-c"
- command)
- (call-process gshell nil t nil
- "-c"
- command)))
- (goto-char (point-min))
- ;; Issue an error, if no match.
- (unless (eq 0 status)
- (save-excursion
- (skip-chars-forward " \t\n")
- (if (looking-at "ls:")
- (viper-forward-Word 1))
- (error "%s: %s"
- (if (stringp gshell)
- gshell
- "shell")
- (buffer-substring (point) (viper-line-pos 'end)))
- ))
- (goto-char (point-min))
- (viper-get-filenames-from-buffer 'one-per-line))
- ))
-
-
-;; Interpret the stuff in the buffer as a list of file names
-;; return a list of file names listed in the buffer beginning at point
-;; If optional arg is supplied, assume each filename is listed on a separate
-;; line
-(defun viper-get-filenames-from-buffer (&optional one-per-line)
- (let ((skip-chars (if one-per-line "\t\n" " \t\n"))
- result fname delim)
- (skip-chars-forward skip-chars)
- (while (not (eobp))
- (if (cond ((looking-at "\"")
- (setq delim ?\")
- (re-search-forward "[^\"]+" nil t)) ; noerror
- ((looking-at "'")
- (setq delim ?')
- (re-search-forward "[^']+" nil t)) ; noerror
- (t
- (re-search-forward
- (concat "[^" skip-chars "]+") nil t))) ;noerror
- (setq fname
- (buffer-substring (match-beginning 0) (match-end 0))))
- (if delim
- (forward-char 1))
- (skip-chars-forward " \t\n")
- (setq result (cons fname result)))
- result))
-
-;; convert MS-DOS wildcards to regexp
-(defun viper-wildcard-to-regexp (wcard)
- (with-current-buffer (get-buffer-create viper-ex-tmp-buf-name)
- (erase-buffer)
- (insert wcard)
- (goto-char (point-min))
- (while (not (eobp))
- (skip-chars-forward "^*?.\\\\")
- (cond ((eq (char-after (point)) ?*) (insert ".")(forward-char 1))
- ((eq (char-after (point)) ?.) (insert "\\")(forward-char 1))
- ((eq (char-after (point)) ?\\) (insert "\\")(forward-char 1))
- ((eq (char-after (point)) ??) (delete-char 1)(insert ".")))
- )
- (buffer-string)
- ))
-
-
-;; glob windows files
-;; LIST is expected to be in reverse order
-(defun viper-glob-mswindows-files (filespec)
- (let ((case-fold-search t)
- tmp tmp2)
- (with-current-buffer (get-buffer-create viper-ex-tmp-buf-name)
- (erase-buffer)
- (insert filespec)
- (goto-char (point-min))
- (setq tmp (viper-get-filenames-from-buffer))
- (while tmp
- (setq tmp2 (cons (directory-files
- ;; the directory part
- (or (file-name-directory (car tmp))
- "")
- t ; return full names
- ;; the regexp part: globs the file names
- (concat "^"
- (viper-wildcard-to-regexp
- (file-name-nondirectory (car tmp)))
- "$"))
- tmp2))
- (setq tmp (cdr tmp)))
- (reverse (apply #'append tmp2)))))
-
-\f
-;;; Insertion ring
-
-;; Rotate RING's index. DIRection can be positive or negative.
-(defun viper-ring-rotate1 (ring dir)
- (if (and (ring-p ring) (> (ring-length ring) 0))
- (progn
- (setcar ring (cond ((> dir 0)
- (ring-plus1 (car ring) (ring-length ring)))
- ((< dir 0)
- (ring-minus1 (car ring) (ring-length ring)))
- ;; don't rotate if dir = 0
- (t (car ring))))
- (viper-current-ring-item ring)
- )))
-
-(defun viper-special-ring-rotate1 (ring dir)
- (if (memq viper-intermediate-command
- '(repeating-display-destructive-command
- repeating-insertion-from-ring))
- (viper-ring-rotate1 ring dir)
- ;; don't rotate otherwise
- (viper-ring-rotate1 ring 0)))
-
-;; current ring item; if N is given, then so many items back from the
-;; current
-(defun viper-current-ring-item (ring &optional n)
- (setq n (or n 0))
- (if (and (ring-p ring) (> (ring-length ring) 0))
- (aref (cdr (cdr ring)) (mod (- (car ring) 1 n) (ring-length ring)))))
-
-;; Push item onto ring. The second argument is a ring-variable, not value.
-(defun viper-push-onto-ring (item ring-var)
- (or (ring-p (symbol-value ring-var))
- (set ring-var (make-ring (symbol-value (intern (format "%S-size" ring-var))))))
- (or (null item) ; don't push nil
- (and (stringp item) (string= item "")) ; or empty strings
- (equal item (viper-current-ring-item (symbol-value ring-var))) ; or old stuff
- ;; Since viper-set-destructive-command checks if we are inside
- ;; viper-repeat, we don't check whether this-command-keys is a `.'. The
- ;; cmd viper-repeat makes a call to the current function only if `.' is
- ;; executing a command from the command history. It doesn't call the
- ;; push-onto-ring function if `.' is simply repeating the last
- ;; destructive command. We only check for ESC (which happens when we do
- ;; insert with a prefix argument, or if this-command-keys doesn't give
- ;; anything meaningful (in that case we don't know what to show to the
- ;; user).
- (and (eq ring-var 'viper-command-ring)
- (string-match "\\([0-9]*\e\\|^[ \t]*$\\|escape\\)"
- (viper-array-to-string (this-command-keys))))
- (viper-ring-insert (symbol-value ring-var) item))
- )
-
-
-;; removing elts from ring seems to break it
-(defun viper-cleanup-ring (ring)
- (or (< (ring-length ring) 2)
- (null (viper-current-ring-item ring))
- ;; last and previous equal
- (if (equal (viper-current-ring-item ring)
- (viper-current-ring-item ring 1))
- (viper-ring-pop ring))))
-
-;; ring-remove seems to be buggy, so we concocted this for our purposes.
-(defun viper-ring-pop (ring)
- (let* ((ln (ring-length ring))
- (vec (cdr (cdr ring)))
- (veclen (length vec))
- (hd (car ring))
- (idx (max 0 (ring-minus1 hd ln)))
- (top-elt (aref vec idx)))
-
- ;; shift elements
- (while (< (1+ idx) veclen)
- (aset vec idx (aref vec (1+ idx)))
- (setq idx (1+ idx)))
- (aset vec idx nil)
-
- (setq hd (max 0 (ring-minus1 hd ln)))
- (if (= hd (1- ln)) (setq hd 0))
- (setcar ring hd) ; move head
- (setcar (cdr ring) (max 0 (1- ln))) ; adjust length
- top-elt
- ))
-
-(defun viper-ring-insert (ring item)
- (let* ((ln (ring-length ring))
- (vec (cdr (cdr ring)))
- (veclen (length vec))
- (hd (car ring))
- (vecpos-after-hd (if (= hd 0) ln hd))
- (idx ln))
-
- (if (= ln veclen)
- (progn
- (aset vec hd item) ; hd is always 1+ the actual head index in vec
- (setcar ring (ring-plus1 hd ln)))
- (setcar (cdr ring) (1+ ln))
- (setcar ring (ring-plus1 vecpos-after-hd (1+ ln)))
- (while (and (>= idx vecpos-after-hd) (> ln 0))
- (aset vec idx (aref vec (1- idx)))
- (setq idx (1- idx)))
- (aset vec vecpos-after-hd item))
- item))
-
-\f
-;;; String utilities
-
-;; If STRING is longer than MAX-LEN, truncate it and print ...... instead
-;; PRE-STRING is a string to prepend to the abbrev string.
-;; POST-STRING is a string to append to the abbrev string.
-;; ABBREV_SIGN is a string to be inserted before POST-STRING
-;; if the orig string was truncated.
-(defun viper-abbreviate-string (string max-len
- pre-string post-string abbrev-sign)
- (let (truncated-str)
- (setq truncated-str
- (if (stringp string)
- (substring string 0 (min max-len (length string)))))
- (cond ((null truncated-str) "")
- ((> (length string) max-len)
- (format "%s%s%s%s"
- pre-string truncated-str abbrev-sign post-string))
- (t (format "%s%s%s" pre-string truncated-str post-string)))))
-
-;; tells if we are over a whitespace-only line
-(defsubst viper-over-whitespace-line ()
- (save-excursion
- (beginning-of-line)
- (looking-at "^[ \t]*$")))
-
-\f
-;;; Saving settings in custom file
-
-;; Save the current setting of VAR in FILE.
-;; If given, MESSAGE is a message to be displayed after that.
-;; This message is erased after 2 secs, if erase-msg is non-nil.
-;; Arguments: var message file &optional erase-message
-(defun viper-save-setting (var message file &optional erase-msg)
- (let* ((var-name (symbol-name var))
- (var-val (if (boundp var) (symbol-value var)))
- (regexp (format "^[^;]*%s[ \t\n]*[a-zA-Z0-9---_']*[ \t\n)]" var-name))
- (buf (find-file-noselect (substitute-in-file-name file)))
- )
- (message "%s" (or message ""))
- (with-current-buffer buf
- (goto-char (point-min))
- (if (re-search-forward regexp nil t)
- (let ((reg-end (1- (match-end 0))))
- (search-backward var-name)
- (delete-region (match-beginning 0) reg-end)
- (goto-char (match-beginning 0))
- (insert (format "%s '%S" var-name var-val)))
- (goto-char (point-max))
- (if (not (bolp)) (insert "\n"))
- (insert (format "(setq %s '%S)\n" var-name var-val)))
- (save-buffer))
- (kill-buffer buf)
- (if erase-msg
- (progn
- (sit-for 2)
- (message "")))
- ))
-
-;; Save STRING in FILE. If PATTERN is non-nil, remove strings that
-;; match this pattern.
-(defun viper-save-string-in-file (string file &optional pattern)
- (let ((buf (find-file-noselect (substitute-in-file-name file))))
- (with-current-buffer buf
- (let ((inhibit-read-only t))
- (goto-char (point-min))
- (if pattern (delete-matching-lines pattern))
- (goto-char (point-max))
- (if string (insert string))
- (save-buffer)))
- (kill-buffer buf)
- ))
-
-
-;; This is a simple-minded check for whether a file is under version control.
-;; If file,v exists but file doesn't, this file is considered to be not checked
-;; in and not checked out for the purpose of patching (since patch won't be
-;; able to read such a file anyway).
-;; FILE is a string representing file name
-;;(defun viper-file-under-version-control (file)
-;; (let* ((filedir (file-name-directory file))
-;; (file-nondir (file-name-nondirectory file))
-;; (trial (concat file-nondir ",v"))
-;; (full-trial (concat filedir trial))
-;; (full-rcs-trial (concat filedir "RCS/" trial)))
-;; (and (stringp file)
-;; (file-exists-p file)
-;; (or
-;; (and
-;; (file-exists-p full-trial)
-;; ;; in FAT FS, `file,v' and `file' may turn out to be the same!
-;; ;; don't be fooled by this!
-;; (not (equal (file-attributes file)
-;; (file-attributes full-trial))))
-;; ;; check if a version is in RCS/ directory
-;; (file-exists-p full-rcs-trial)))
-;; ))
-
-
-(defsubst viper-file-checked-in-p (file)
- (and (featurep 'vc-hooks)
- ;; CVS files are considered not checked in
- ;; FIXME: Should this deal with more than CVS?
- (not (memq (vc-backend file) '(nil CVS)))
- (if (fboundp 'vc-state)
- (and
- (not (memq (vc-state file) '(edited needs-merge)))
- (not (stringp (vc-state file)))))))
-
-;; checkout if visited file is checked in
-(defun viper-maybe-checkout (buf)
- (let ((file (expand-file-name (buffer-file-name buf)))
- (checkout-function (key-binding "\C-x\C-q")))
- (if (and (viper-file-checked-in-p file)
- (or (beep 1) t)
- (y-or-n-p
- (format
- "File %s is checked in. Check it out? "
- (abbreviate-file-name file))))
- (with-current-buffer buf
- (command-execute checkout-function)))))
-
-
-
-\f
-;;; Overlays
-(defun viper-put-on-search-overlay (beg end)
- (if (overlayp viper-search-overlay)
- (move-overlay viper-search-overlay beg end)
- (setq viper-search-overlay (make-overlay beg end (current-buffer)))
- (overlay-put
- viper-search-overlay 'priority viper-search-overlay-priority))
- (overlay-put viper-search-overlay 'face viper-search-face))
-
-;; Search
-
-(defun viper-flash-search-pattern ()
- (if (not (viper-has-face-support-p))
- nil
- (viper-put-on-search-overlay (match-beginning 0) (match-end 0))
- (sit-for 2)
- (overlay-put viper-search-overlay 'face nil)))
-
-(defun viper-hide-search-overlay ()
- (if (not (overlayp viper-search-overlay))
- (progn
- (setq viper-search-overlay
- (make-overlay (point-min) (point-min) (current-buffer)))
- (overlay-put
- viper-search-overlay 'priority viper-search-overlay-priority)))
- (overlay-put viper-search-overlay 'face nil))
-
-;; Replace state
-
-(defsubst viper-move-replace-overlay (beg end)
- (move-overlay viper-replace-overlay beg end))
-
-(defun viper-set-replace-overlay (beg end)
- (if (overlayp viper-replace-overlay)
- (viper-move-replace-overlay beg end)
- (setq viper-replace-overlay (make-overlay beg end (current-buffer)))
- ;; never detach
- (overlay-put viper-replace-overlay 'evaporate nil)
- (overlay-put
- viper-replace-overlay 'priority viper-replace-overlay-priority)
- ;; If Emacs will start supporting overlay maps, as it currently supports
- ;; text-property maps, we could do away with viper-replace-minor-mode and
- ;; just have keymap attached to replace overlay.
- ;;(overlay-put
- ;; viper-replace-overlay
- ;; 'local-map
- ;; viper-replace-map)
- )
- (if (viper-has-face-support-p)
- (overlay-put
- viper-replace-overlay 'face viper-replace-overlay-face))
- (viper-save-cursor-color 'before-replace-mode)
- (viper-change-cursor-color
- (viper-frame-value viper-replace-overlay-cursor-color)))
-
-
-(defun viper-set-replace-overlay-glyphs (before-glyph after-glyph)
- (or (overlayp viper-replace-overlay)
- (viper-set-replace-overlay (point-min) (point-min)))
- (if (or (not (viper-has-face-support-p))
- viper-use-replace-region-delimiters)
- (overlay-put viper-replace-overlay 'before-string before-glyph)
- (overlay-put viper-replace-overlay 'after-string after-glyph)))
-
-(defun viper-hide-replace-overlay ()
- (viper-set-replace-overlay-glyphs nil nil)
- (viper-restore-cursor-color 'after-replace-mode)
- (viper-restore-cursor-color 'after-insert-mode)
- (if (viper-has-face-support-p)
- (overlay-put viper-replace-overlay 'face nil)))
-
-
-(defsubst viper-replace-start ()
- (overlay-start viper-replace-overlay))
-(defsubst viper-replace-end ()
- (overlay-end viper-replace-overlay))
-
-
-;; Minibuffer
-
-(defun viper-set-minibuffer-overlay ()
- (viper-check-minibuffer-overlay)
- (when (viper-has-face-support-p)
- (overlay-put
- viper-minibuffer-overlay 'face viper-minibuffer-current-face)
- (overlay-put
- viper-minibuffer-overlay 'priority viper-minibuffer-overlay-priority)
- ;; never detach
- (overlay-put viper-minibuffer-overlay 'evaporate nil)))
-
-(defun viper-check-minibuffer-overlay ()
- (if (overlayp viper-minibuffer-overlay)
- (move-overlay
- viper-minibuffer-overlay (minibuffer-prompt-end) (1+ (buffer-size)))
- (setq viper-minibuffer-overlay
- ;; make overlay open-ended
- (make-overlay
- (minibuffer-prompt-end) (1+ (buffer-size))
- (current-buffer) nil 'rear-advance))))
-
-
-(defsubst viper-is-in-minibuffer ()
- (save-match-data
- (string-match "\\*Minibuf-" (buffer-name))))
-
-
-\f
-;;; XEmacs compatibility
-
-(define-obsolete-function-alias 'viper-abbreviate-file-name
- #'abbreviate-file-name "27.1")
-
-(defsubst viper-sit-for-short (val &optional nodisp)
- (declare (obsolete nil "28.1"))
- (sit-for (/ val 1000.0) nodisp))
-
-;; EVENT may be a single event of a sequence of events
-(defsubst viper-ESC-event-p (event)
- (let ((ESC-keys '(?\e (control \[) escape))
- (key (viper-event-key event)))
- (member key ESC-keys)))
-
-;; checks if object is a marker, has a buffer, and points to within that buffer
-(defun viper-valid-marker (marker)
- (if (and (markerp marker) (marker-buffer marker))
- (let ((buf (marker-buffer marker))
- (pos (marker-position marker)))
- (with-current-buffer buf
- (and (<= pos (point-max)) (<= (point-min) pos))))))
-
-(define-obsolete-function-alias 'viper-mark-marker #'mark-marker "27.1")
-
-(defvar viper-saved-mark nil
- "Where viper saves mark. This mark is resurrected by m^.")
-
-;; like (set-mark-command nil) but doesn't push twice, if (car mark-ring)
-;; is the same as (mark t).
-(defsubst viper-set-mark-if-necessary ()
- (setq mark-ring (delete (mark-marker) mark-ring))
- (set-mark-command nil)
- (setq viper-saved-mark (point)))
-
-;; In transient mark mode, it is annoying when regions become
-;; highlighted due to Viper's pushing marks. So, we deactivate marks,
-;; unless the user explicitly wants highlighting, e.g., by hitting ''
-;; or ``
-(define-obsolete-function-alias 'viper-deactivate-mark #'deactivate-mark "27.1")
-
-(define-obsolete-function-alias 'viper-leave-region-active #'ignore "27.1")
-
-;; Check if arg is a valid character for register
-;; TYPE is a list that can contain `letter', `Letter', and `digit'.
-;; Letter means lowercase letters, Letter means uppercase letters, and
-;; digit means digits from 1 to 9.
-;; If TYPE is nil, then down/uppercase letters and digits are allowed.
-(defun viper-valid-register (reg &optional type)
- (or type (setq type '(letter Letter digit)))
- (or (if (memq 'letter type)
- (and (<= ?a reg) (<= reg ?z)))
- (if (memq 'digit type)
- (and (<= ?1 reg) (<= reg ?9)))
- (if (memq 'Letter type)
- (and (<= ?A reg) (<= reg ?Z)))
- ))
-
-
-
-(define-obsolete-function-alias 'viper-copy-event #'identity "27.1")
-
-;; Uses different timeouts for ESC-sequences and others
-(defun viper-fast-keysequence-p ()
- (not (sit-for (/ (if (viper-ESC-event-p last-input-event)
- (viper-ESC-keyseq-timeout)
- viper-fast-keyseq-timeout) 1000.0)
- t)))
-
-(define-obsolete-function-alias 'viper-read-event-convert-to-char
- #'read-event "27.1")
-
-
-;; Emacs has a bug in eventp, which causes (eventp nil) to return (nil)
-;; instead of nil, if '(nil) was previously inadvertently assigned to
-;; unread-command-events
-(defun viper-event-key (event)
- (or (and event (eventp event))
- (error "viper-event-key: Wrong type argument, eventp, %S" event))
- (let ((mod (event-modifiers event))
- basis)
- (setq basis
- ;; Emacs doesn't handle capital letters correctly, since
- ;; \S-a isn't considered the same as A (it behaves as
- ;; plain `a' instead). So we take care of this here
- (cond ((and (characterp event) (<= ?A event) (<= event ?Z))
- (setq mod nil
- event event))
- ;; Emacs has the oddity whereby characters 128+char
- ;; represent M-char *if* this appears inside a string.
- ;; So, we convert them manually to (meta char).
- ((and (characterp event)
- (< ?\C-? event) (<= event 255))
- (setq mod '(meta)
- event (- event ?\C-? 1)))
- ((and (null mod) (eq event 'return))
- (setq event ?\C-m))
- ((and (null mod) (eq event 'space))
- (setq event ?\ ))
- ((and (null mod) (eq event 'delete))
- (setq event ?\C-?))
- ((and (null mod) (eq event 'backspace))
- (setq event ?\C-h))
- (t (event-basic-type event))))
-
- (if (characterp basis)
- (setq basis
- (if (viper= basis ?\C-?)
- (list 'control '\?) ; taking care of an emacs bug
- (intern (char-to-string basis)))))
- (if mod
- (append mod (list basis))
- basis)))
-
-(defun viper-last-command-char ()
- (declare (obsolete nil "28.1"))
- last-command-event)
-
-(defun viper-key-to-emacs-key (key)
- (let (key-name char-p modifiers mod-char-list base-key base-key-name)
- (cond ((symbolp key)
- (setq key-name (symbol-name key))
- (cond ((= (length key-name) 1) ; character event
- (string-to-char key-name))
- ;; Emacs doesn't recognize `return' and `escape' as events on
- ;; dumb terminals, so we translate them into characters
- ((and (not (viper-window-display-p))
- (string= key-name "return"))
- ?\C-m)
- ((and (not (viper-window-display-p))
- (string= key-name "escape"))
- ?\e)
- ;; pass symbol-event as is
- (t key)))
-
- ((listp key)
- (setq modifiers (cl-subseq key 0 (1- (length key)))
- base-key (viper-seq-last-elt key)
- base-key-name (symbol-name base-key)
- char-p (= (length base-key-name) 1))
- (setq mod-char-list
- (mapcar
- (lambda (elt) (upcase (substring (symbol-name elt) 0 1)))
- modifiers))
- (if char-p
- (setq key-name
- (car (read-from-string
- (concat
- "?\\"
- (mapconcat #'identity mod-char-list "-\\")
- "-"
- base-key-name))))
- (setq key-name
- (intern
- (concat
- (mapconcat #'identity mod-char-list "-")
- "-"
- base-key-name))))))
- ))
-
-
-;; LIS is assumed to be a list of events of characters
-(define-obsolete-function-alias 'viper-eventify-list-xemacs #'ignore "27.1")
-
-
-;; Arg is a character, an event, a list of events or a sequence of
-;; keys.
-;;
-;; Due to the way unread-command-events works in Emacs, a non-event
-;; symbol in unread-command-events list may cause Emacs to turn this
-;; symbol into an event. Below, we delete nil from event lists, since
-;; nil is the most common symbol that might appear in this wrong
-;; context.
-(defun viper-set-unread-command-events (arg)
- (setq
- unread-command-events
- (let ((new-events
- (cond ((eventp arg) (list arg))
- ((listp arg) arg)
- ((sequencep arg)
- (listify-key-sequence arg))
- (t (error
- "viper-set-unread-command-events: Invalid argument, %S"
- arg)))))
- (if (not (eventp nil))
- (setq new-events (delq nil new-events)))
- (append new-events unread-command-events))))
-
-
-;; Check if vec is a vector of key-press events representing characters
-;; XEmacs only
-(defun viper-event-vector-p (vec)
- (and (vectorp vec)
- (seq-every-p (lambda (elt) (if (eventp elt) t)) vec)))
-
-
-;; check if vec is a vector of character symbols
-(defun viper-char-symbol-sequence-p (vec)
- (and
- (sequencep vec)
- (seq-every-p (lambda (elt)
- (and (symbolp elt) (= (length (symbol-name elt)) 1)))
- vec)))
-
-
-(defun viper-char-array-p (array)
- (seq-every-p #'characterp array))
-
-
-;; Args can be a sequence of events, a string, or a Viper macro. Will try to
-;; convert events to keys and, if all keys are regular printable
-;; characters, will return a string. Otherwise, will return a string
-;; representing a vector of converted events. If the input was a Viper macro,
-;; will return a string that represents this macro as a vector.
-(defun viper-array-to-string (event-seq)
- (let (temp temp2)
- (cond ((stringp event-seq) event-seq)
- ((viper-event-vector-p event-seq)
- (setq temp (mapcar #'viper-event-key event-seq))
- (cond ((viper-char-symbol-sequence-p temp)
- (mapconcat #'symbol-name temp ""))
- ((and (viper-char-array-p
- (setq temp2 (mapcar #'viper-key-to-character temp))))
- (mapconcat #'char-to-string temp2 ""))
- (t (prin1-to-string (vconcat temp)))))
- ((viper-char-symbol-sequence-p event-seq)
- (mapconcat #'symbol-name event-seq ""))
- ((and (vectorp event-seq)
- (viper-char-array-p
- (setq temp (mapcar #'viper-key-to-character event-seq))))
- (mapconcat #'char-to-string temp ""))
- (t (prin1-to-string event-seq)))))
-
-(defun viper-key-press-events-to-chars (events)
- (declare (obsolete nil "29.1"))
- (mapconcat #'char-to-string events ""))
-
-
-(defun viper-read-char-exclusive ()
- (let (char
- (echo-keystrokes 1))
- (while (null char)
- (condition-case nil
- (setq char (read-char))
- (error
- ;; skip event if not char
- (read-event))))
- char))
-
-;; key is supposed to be in viper's representation, e.g., (control l), a
-;; character, etc.
-(defun viper-key-to-character (key)
- (cond ((eq key 'space) ?\ )
- ((eq key 'delete) ?\C-?)
- ((eq key 'return) ?\C-m)
- ((eq key 'backspace) ?\C-h)
- ((and (symbolp key)
- (= 1 (length (symbol-name key))))
- (string-to-char (symbol-name key)))
- ((and (listp key)
- (eq (car key) 'control)
- (= 1 (length (symbol-name (nth 1 key)))))
- (read (format "?\\C-%s" (symbol-name (nth 1 key)))))
- (t key)))
-
-
-(defun viper-setup-master-buffer (&rest other-files-or-buffers)
- "Set up the current buffer as a master buffer.
-Arguments become related buffers. This function should normally be used in
-the `Local variables' section of a file."
- (setq viper-related-files-and-buffers-ring
- (make-ring (1+ (length other-files-or-buffers))))
- (mapc (lambda (elt)
- (viper-ring-insert viper-related-files-and-buffers-ring elt))
- other-files-or-buffers)
- (viper-ring-insert viper-related-files-and-buffers-ring (buffer-name))
- )
-
-;;; Movement utilities
-
-;; Characters that should not be considered as part of the word, in reformed-vi
-;; syntax mode.
-;; Note: \\ (quoted \) must appear before `-' because this string is listified
-;; into characters at some point and then put back to string. The result is
-;; used in skip-chars-forward, which treats - specially. Here we achieve the
-;; effect of quoting - and preventing it from being special.
-(defconst viper-non-word-characters-reformed-vi
- "!@#$%^&*()\\-+=|\\~`{}[];:'\",<.>/?")
-;; These are characters that are not to be considered as parts of a word in
-;; Viper.
-;; Set each time state changes and at loading time
-(defvar-local viper-non-word-characters nil)
-
-;; must be buffer-local
-(defvar-local viper-ALPHA-char-class "w"
- "String of syntax classes characterizing Viper's alphanumeric symbols.
-In addition, the symbol `_' may be considered alphanumeric if
-`viper-syntax-preference' is `strict-vi' or `reformed-vi'.")
-
-(defconst viper-strict-ALPHA-chars "a-zA-Z0-9_"
- "Regexp matching the set of alphanumeric characters acceptable to strict Vi.")
-(defconst viper-strict-SEP-chars " \t\n"
- "Regexp matching the set of alphanumeric characters acceptable to strict Vi.")
-(defconst viper-strict-SEP-chars-sans-newline " \t"
- "Regexp matching the set of alphanumeric characters acceptable to strict Vi.")
-
-(defconst viper-SEP-char-class " -"
- "String of syntax classes for Vi separators.
-Usually contains ` ', linefeed, TAB or formfeed.")
-
-
-;; Set Viper syntax classes and related variables according to
-;; `viper-syntax-preference'.
-(defun viper-update-syntax-classes (&optional set-default)
- (let ((preference (cond ((eq viper-syntax-preference 'emacs)
- "w") ; Viper words have only Emacs word chars
- ((eq viper-syntax-preference 'extended)
- "w_") ; Viper words have Emacs word & symbol chars
- (t "w"))) ; Viper words are Emacs words plus `_'
- (non-word-chars (cond ((eq viper-syntax-preference 'reformed-vi)
- (viper-string-to-list
- viper-non-word-characters-reformed-vi))
- (t nil))))
- (if set-default
- (setq-default viper-ALPHA-char-class preference
- viper-non-word-characters non-word-chars)
- (setq viper-ALPHA-char-class preference
- viper-non-word-characters non-word-chars))
- ))
-
-;; SYMBOL is used because customize requires it, but it is ignored, unless it
-;; is nil. If nil, use setq.
-(defun viper-set-syntax-preference (&optional symbol value)
- "Set Viper syntax preference.
-If called interactively or if SYMBOL is nil, sets syntax preference in current
-buffer. If called non-interactively, preferably via the customization widget,
-sets the default value."
- (interactive)
- (or value
- (setq value
- (completing-read
- "Viper syntax preference: "
- '(("strict-vi") ("reformed-vi") ("extended") ("emacs"))
- nil 'require-match)))
- (if (stringp value) (setq value (intern value)))
- (or (memq value '(strict-vi reformed-vi extended emacs))
- (error "Invalid Viper syntax preference, %S" value))
- (if symbol
- (setq-default viper-syntax-preference value)
- (setq viper-syntax-preference value))
- (viper-update-syntax-classes))
-
-(defcustom viper-syntax-preference 'reformed-vi
- "Syntax type characterizing Viper's alphanumeric symbols.
-Affects movement and change commands that deal with Vi-style words.
-Works best when set in the hooks to various major modes.
-
-`strict-vi' means Viper words are (hopefully) exactly as in Vi.
-
-`reformed-vi' means Viper words are like Emacs words \(as determined using
-Emacs syntax tables, which are different for different major modes) with two
-exceptions: the symbol `_' is always part of a word and typical Vi non-word
-symbols like `\\=`', `\\='', `:', `\"', `)', and `{' are excluded.
-This behaves very close to `strict-vi', but also works well with non-ASCII
-characters from various alphabets.
-
-`extended' means Viper word constituents are symbols that are marked as being
-parts of words OR symbols in Emacs syntax tables.
-This is most appropriate for major modes intended for editing programs.
-
-`emacs' means Viper words are the same as Emacs words as specified by Emacs
-syntax tables.
-This option is appropriate if you like Emacs-style words."
- :type '(radio (const strict-vi) (const reformed-vi)
- (const extended) (const emacs))
- :set #'viper-set-syntax-preference
- :local t
- :group 'viper)
-
-
-;; addl-chars are characters to be temporarily considered as alphanumerical
-(defun viper-looking-at-alpha (&optional addl-chars)
- (or (stringp addl-chars) (setq addl-chars ""))
- (if (eq viper-syntax-preference 'reformed-vi)
- (setq addl-chars (concat addl-chars "_")))
- (let ((char (char-after (point))))
- (if char
- (if (eq viper-syntax-preference 'strict-vi)
- (looking-at (concat "[" viper-strict-ALPHA-chars addl-chars "]"))
- (or
- ;; or one of the additional chars being asked to include
- (memq char (viper-string-to-list addl-chars))
- (and
- ;; not one of the excluded word chars (note:
- ;; viper-non-word-characters is a list)
- (not (memq char viper-non-word-characters))
- ;; char of the Viper-word syntax class
- (memq (char-syntax char)
- (viper-string-to-list viper-ALPHA-char-class))))))))
-
-(defun viper-looking-at-separator ()
- (let ((char (char-after (point))))
- (if char
- (if (eq viper-syntax-preference 'strict-vi)
- (memq char (viper-string-to-list viper-strict-SEP-chars))
- (or (eq char ?\n) ; RET is always a separator in Vi
- (memq (char-syntax char)
- (viper-string-to-list viper-SEP-char-class)))))))
-
-(defsubst viper-looking-at-alphasep (&optional addl-chars)
- (or (viper-looking-at-separator) (viper-looking-at-alpha addl-chars)))
-
-(defun viper-skip-alpha-forward (&optional addl-chars)
- (or (stringp addl-chars) (setq addl-chars ""))
- (viper-skip-syntax
- 'forward
- (cond ((eq viper-syntax-preference 'strict-vi)
- "")
- (t viper-ALPHA-char-class))
- (cond ((eq viper-syntax-preference 'strict-vi)
- (concat viper-strict-ALPHA-chars addl-chars))
- (t addl-chars))))
-
-(defun viper-skip-alpha-backward (&optional addl-chars)
- (or (stringp addl-chars) (setq addl-chars ""))
- (viper-skip-syntax
- 'backward
- (cond ((eq viper-syntax-preference 'strict-vi)
- "")
- (t viper-ALPHA-char-class))
- (cond ((eq viper-syntax-preference 'strict-vi)
- (concat viper-strict-ALPHA-chars addl-chars))
- (t addl-chars))))
-
-;; weird syntax tables may confuse strict-vi style
-(defsubst viper-skip-all-separators-forward (&optional within-line)
- (if (eq viper-syntax-preference 'strict-vi)
- (if within-line
- (skip-chars-forward viper-strict-SEP-chars-sans-newline)
- (skip-chars-forward viper-strict-SEP-chars))
- (viper-skip-syntax 'forward
- viper-SEP-char-class
- (or within-line "\n")
- (if within-line (viper-line-pos 'end)))))
-
-(defsubst viper-skip-all-separators-backward (&optional within-line)
- (if (eq viper-syntax-preference 'strict-vi)
- (if within-line
- (skip-chars-backward viper-strict-SEP-chars-sans-newline)
- (skip-chars-backward viper-strict-SEP-chars))
- (viper-skip-syntax 'backward
- viper-SEP-char-class
- (or within-line "\n")
- (if within-line (viper-line-pos 'start)))))
-(defun viper-skip-nonseparators (direction)
- (viper-skip-syntax
- direction
- (concat "^" viper-SEP-char-class)
- nil
- (viper-line-pos (if (eq direction 'forward) 'end 'start))))
-
-
-;; skip over non-word constituents and non-separators
-(defun viper-skip-nonalphasep-forward ()
- (if (eq viper-syntax-preference 'strict-vi)
- (skip-chars-forward
- (concat "^" viper-strict-SEP-chars viper-strict-ALPHA-chars))
- (viper-skip-syntax
- 'forward
- (concat "^" viper-ALPHA-char-class viper-SEP-char-class)
- ;; Emacs may consider some of these as words, but we don't want them
- viper-non-word-characters
- (viper-line-pos 'end))))
-
-(defun viper-skip-nonalphasep-backward ()
- (if (eq viper-syntax-preference 'strict-vi)
- (skip-chars-backward
- (concat "^" viper-strict-SEP-chars viper-strict-ALPHA-chars))
- (viper-skip-syntax
- 'backward
- (concat "^" viper-ALPHA-char-class viper-SEP-char-class)
- ;; Emacs may consider some of these as words, but we don't want them
- viper-non-word-characters
- (viper-line-pos 'start))))
-
-;; Skip SYNTAX like skip-syntax-* and ADDL-CHARS like skip-chars-*
-;; Return the number of chars traveled.
-;; Both SYNTAX or ADDL-CHARS can be strings or lists of characters.
-;; When SYNTAX is "w", then viper-non-word-characters are not considered to be
-;; words, even if Emacs syntax table says they are.
-(defun viper-skip-syntax (direction syntax addl-chars &optional limit)
- (let ((total 0)
- (local 1)
- (skip-chars-func
- (if (eq direction 'forward)
- 'skip-chars-forward 'skip-chars-backward))
- (skip-syntax-func
- (if (eq direction 'forward)
- 'viper-forward-char-carefully 'viper-backward-char-carefully))
- char-looked-at syntax-of-char-looked-at negated-syntax)
- (setq addl-chars
- (cond ((listp addl-chars) (viper-charlist-to-string addl-chars))
- ((stringp addl-chars) addl-chars)
- (t "")))
- (setq syntax
- (cond ((listp syntax) syntax)
- ((stringp syntax) (viper-string-to-list syntax))
- (t nil)))
- (if (memq ?^ syntax) (setq negated-syntax t))
-
- (while (and (not (= local 0))
- (cond ((eq direction 'forward)
- (not (eobp)))
- (t (not (bobp)))))
- (setq char-looked-at (viper-char-at-pos direction)
- ;; if outside the range, set to nil
- syntax-of-char-looked-at (if char-looked-at
- (char-syntax char-looked-at)))
- (setq local
- (+ (if (and
- (cond ((and limit (eq direction 'forward))
- (< (point) limit))
- (limit ; backward & limit
- (> (point) limit))
- (t t)) ; no limit
- ;; char under/before cursor has appropriate syntax
- (if negated-syntax
- (not (memq syntax-of-char-looked-at syntax))
- (memq syntax-of-char-looked-at syntax))
- ;; if char-syntax class is "word", make sure it is not one
- ;; of the excluded characters
- (if (and (eq syntax-of-char-looked-at ?w)
- (not negated-syntax))
- (not (memq char-looked-at viper-non-word-characters))
- t))
- (funcall skip-syntax-func 1)
- 0)
- (funcall skip-chars-func addl-chars limit)))
- (setq total (+ total local)))
- total
- ))
-
-;; tells when point is at the beginning of field
-(defun viper-beginning-of-field ()
- (or (bobp)
- (not (eq (get-char-property (point) 'field)
- (get-char-property (1- (point)) 'field)))))
-
-(define-obsolete-function-alias 'viper-subseq #'cl-subseq "28.1")
-
-(provide 'viper-util)
-;;; viper-util.el ends here
+++ /dev/null
-;;; viper.el --- A full-featured Vi emulator for Emacs -*- lexical-binding:t -*-
-;; a VI Plan for Emacs Rescue,
-;; and a venomous VI PERil.
-;; Viper Is also a Package for Emacs Rebels.
-
-;; Copyright (C) 1994-2025 Free Software Foundation, Inc.
-
-;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
-;; Keywords: emulations
-;; Version: 3.14.2
-
-;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
-;; file on 20/3/2008, and the maintainer agreed that when a bug is
-;; filed in the Emacs bug reporting system against this file, a copy
-;; of the bug report be sent to the maintainer's email address.
-
-(defconst viper-version "3.14.2 of July 4, 2013"
- "The current version of Viper.")
-
-;; This file is part of GNU Emacs.
-
-;; GNU Emacs is free software: you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; GNU Emacs is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; Viper is a full-featured Vi emulator for Emacs. It emulates and
-;; improves upon the standard features of Vi and, at the same time, allows
-;; full access to all Emacs facilities. Viper supports multiple undo,
-;; file name completion, command, file, and search history and it extends
-;; Vi in many other ways. Viper is highly customizable through the various
-;; hooks, user variables, and keymaps. It is implemented as a collection
-;; of minor modes and it is designed to provide full access to all Emacs
-;; major and minor modes.
-;;
-;;; History:
-;;
-;; Viper is a new name for a package formerly known as VIP-19,
-;; which was a successor of VIP version 3.5 by Masahiko Sato
-;; <ms@sail.stanford.edu> and VIP version 4.2 by Aamod Sane
-;; <sane@cs.uiuc.edu>. Some ideas from vip 4.4.2 by Aamod Sane
-;; were also shamelessly plagiarized.
-;;
-;; Viper maintains some degree of compatibility with these older
-;; packages. See the documentation for customization.
-;;
-;; The main difference between Viper and these older packages are:
-;;
-;; 1. Viper emulates Vi at several levels, from almost complete conformity
-;; to a rather loose Vi-compliance.
-;;
-;; 2. Viper provides full access to all major and minor modes of Emacs
-;; without the need to type extra keys.
-;; The older versions of VIP (and other Vi emulators) do not work with
-;; some major and minor modes.
-;;
-;; 3. Viper supports vi-style undo.
-;;
-;; 4. Viper fully emulates (and improves upon) vi's replacement mode.
-;;
-;; 5. Viper has a better interface to ex, including command, variable, and
-;; file name completion.
-;;
-;; 6. Viper uses native Emacs history and completion features; it doesn't
-;; rely on other packages (such as gmhist.el and completer.el) to provide
-;; these features.
-;;
-;; 7. Viper supports Vi-style editing in the minibuffer, by allowing the
-;; user to switch from Insert state to Vi state to Replace state, etc.
-;;
-;; 8. Viper keeps history of recently inserted pieces of text and recently
-;; executed Vi-style destructive commands, such as `i', `d', etc.
-;; These pieces of text can be inserted in later insertion commands;
-;; the previous destructive commands can be re-executed.
-;;
-;; 9. Viper has Vi-style keyboard macros, which enhances the similar
-;; facility in the original Vi.
-;; First, one can execute any Emacs command while defining a
-;; macro, not just the Vi commands. Second, macros are defined in a
-;; WYSYWYG mode, using an interface to Emacs's WYSIWYG style of defining
-;; macros. Third, in Viper, one can define macros that are specific to
-;; a given buffer, a given major mode, or macros defined for all buffers.
-;; The same macro name can have several different definitions:
-;; one global, several definitions for various major modes, and
-;; definitions for specific buffers.
-;; Buffer-specific definitions override mode-specific
-;; definitions, which, in turn, override global definitions.
-;;
-;;
-;;; Installation:
-;; -------------
-;;
-;; (require 'viper)
-;;
-
-;;; Acknowledgments:
-;; ----------------
-;; Bug reports and ideas contributed by many users have helped
-;; improve Viper and the various versions of VIP.
-;; See the manual for a complete list of contributors.
-;;
-;;
-;;; Notes:
-;;
-;; 1. Major modes.
-;; In most cases, Viper handles major modes correctly, i.e., they come up
-;; in the right state (either vi-state or emacs-state). For instance, text
-;; files come up in vi-state, while, say, Dired appears in emacs-state by
-;; default.
-;; However, some modes do not appear in the right mode in the beginning,
-;; usually because they neglect to follow Emacs conventions (e.g., they don't
-;; use kill-all-local-variables when they start). Some major modes
-;; may fail to come up in emacs-state if they call hooks, such as
-;; text-hook, for no good reason.
-;;
-;; As an immediate solution, you can hit C-z to bring about the right mode.
-;; An interim solution is to add an appropriate hook to the mode like this:
-;;
-;; (add-hook 'your-favorite-mode #'viper-mode)
-;; or
-;; (add-hook 'your-favorite-mode #'viper-change-state-to-emacs)
-;;
-;; whichever applies. The right thing to do, however, is to complain to the
-;; author of the respective package. (Sometimes they also neglect to equip
-;; their modes with hooks, which is one more reason for complaining.)
-;;
-;; 2. Keymap handling
-;; Each Viper state (insert, vi, replace) is implemented as a collection of
-;; several minor modes, each with its own keymap.
-;;
-;; Viper's Vi state consists of seven minor modes:
-;;
-;; viper-vi-intercept-minor-mode
-;; viper-vi-local-user-minor-mode
-;; viper-vi-global-user-minor-mode
-;; viper-vi-kbd-minor-mode
-;; viper-vi-state-modifier-minor-mode
-;; viper-vi-diehard-minor-mode
-;; viper-vi-basic-minor-mode
-;;
-;; Bindings done to the keymap of the first mode overshadow those done to
-;; the second, which, in turn, overshadows those done to the third, etc.
-;;
-;; The last viper-vi-basic-minor-mode contains most of the usual Vi bindings
-;; in its edit mode. This mode provides access to all Emacs facilities.
-;; Novice users, however, may want to set their viper-expert-level to 1 in
-;; their viper-custom-file-name. This will enable viper-vi-diehard-minor-mode.
-;; This minor mode's bindings make Viper simulate the usual Vi very closely.
-;; For instance, C-c will not have its standard Emacs binding
-;; and so many of the goodies of Emacs are not available.
-;;
-;; A skilled user should set viper-expert-level to at least 3. This will
-;; enable `C-c' and many Emacs facilities will become available.
-;; In this case, viper-vi-diehard-minor-mode is inactive.
-;;
-;; Viper gurus should have at least
-;; (setq viper-expert-level 4)
-;; in their viper-custom-file-name. This will unsuppress all Emacs keys
-;; that are not essential for VI-style editing.
-;; Pick-and-choose users may want to put
-;; (setq viper-expert-level 5)
-;; in viper-custom-file-name. Viper will then leave it up to the user to
-;; set the variables viper-want-* See viper-set-expert-level for details.
-;;
-;; The very first minor mode, viper-vi-intercept-minor-mode, is of no
-;; concern for the user. It is needed to bind Viper's vital keys, such as
-;; ESC and C-z.
-;;
-;; The second mode, viper-vi-local-user-minor-mode, usually has an
-;; empty keymap. However, the user can set bindings in this keymap, which
-;; will overshadow the corresponding bindings in the other two minor
-;; modes. This is useful, for example, for setting up ZZ in gnus,
-;; rmail, mh-e, etc., to send message instead of saving it in a file.
-;; Likewise, in Dired mode, you may want to bind ZN and ZP to commands
-;; that would visit the next or the previous file in the Dired buffer.
-;; Setting local keys is tricky, so don't do it directly. Instead, use
-;; viper-add-local-keys function (see its doc).
-;;
-;; The third minor mode, viper-vi-global-user-minor-mode, is also intended
-;; for the users but, unlike viper-vi-local-user-minor-mode, its key
-;; bindings are seen in all Viper buffers. This mode keys can be done
-;; with define-key command.
-;;
-;; The fourth minor mode, viper-vi-kbd-minor-mode, is used by keyboard
-;; macros. Users are NOT supposed to modify this keymap directly.
-;;
-;; The fifth mode, viper-vi-state-modifier-minor-mode, can be used to set
-;; key bindings that are visible in some major modes but not in others.
-;;
-;; Users are allowed to modify keymaps that belong to
-;; viper-vi-local-user-minor-mode, viper-vi-global-user-minor-mode,
-;; and viper-vi-state-modifier-minor-mode only.
-;;
-;; Viper's Insert state also has seven minor modes:
-;;
-;; viper-insert-intercept-minor-mode
-;; viper-insert-local-user-minor-mode
-;; viper-insert-global-user-minor-mode
-;; viper-insert-kbd-minor-mode
-;; viper-insert-state-modifier-minor-mode
-;; viper-insert-diehard-minor-mode
-;; viper-insert-basic-minor-mode
-;;
-;; As with VI's editing modes, the first mode,
-;; viper-insert-intercept-minor-mode is used to bind vital keys that are not
-;; to be changed by the user.
-;;
-;; The next mode, viper-insert-local-user-minor-mode, is used to customize
-;; bindings in the insert state of Viper. The third mode,
-;; viper-insert-global-user-minor-mode is like
-;; viper-insert-local-user-minor-mode, except that its bindings are seen in
-;; all Viper buffers. As with viper-vi-local-user-minor-mode, its bindings
-;; should be done via the function viper-add-local-keys. Bindings for
-;; viper-insert-global-user-minor-mode can be set with the define-key command.
-;;
-;; The next minor mode, viper-insert-kbd-minor-mode,
-;; is used for keyboard VI-style macros defined with :map!.
-;;
-;; The fifth minor mode, viper-insert-state-modifier-minor-mode, is like
-;; viper-vi-state-modifier-minor-mode, except that it is used in the Insert
-;; state; it can be used to modify keys in a mode-specific fashion.
-;;
-;; The minor mode viper-insert-diehard-minor-mode is in effect when
-;; the user wants a high degree of Vi compatibility (a bad idea, really!).
-;; The last minor mode, viper-insert-basic-minor-mode, is always in effect
-;; when Viper is in insert state. It binds a small number of keys needed for
-;; Viper's operation.
-;;
-;; Finally, Viper provides minor modes for overriding bindings set by Emacs
-;; modes when Viper is in Emacs state:
-;;
-;; viper-emacs-local-user-minor-mode
-;; viper-emacs-global-user-minor-mode
-;; viper-emacs-kbd-minor-mode
-;; viper-emacs-state-modifier-minor-mode
-;;
-;; These minor modes are in effect when Viper is in Emacs state. The keymap
-;; associated with viper-emacs-global-user-minor-mode,
-;; viper-emacs-global-user-map, overrides the global and local keymaps as
-;; well as the minor mode keymaps set by other modes. The keymap of
-;; viper-emacs-local-user-minor-mode, viper-emacs-local-user-map, overrides
-;; everything, but it is used on a per buffer basis.
-;; The keymap associated with viper-emacs-state-modifier-minor-mode
-;; overrides keys on a per-major-mode basis. The mode
-;; viper-emacs-kbd-minor-mode is used to define Vi-style macros in Emacs
-;; state.
-;;
-;; 3. There is also one minor mode that is used when Viper is in its
-;; replace-state (used for commands like cw, C, etc.). This mode is
-;; called
-;;
-;; viper-replace-minor-mode
-;;
-;; and its keymap is viper-replace-map. Replace minor mode is always
-;; used in conjunction with the minor modes for insert-state, and its
-;; keymap overshadows the keymaps for insert minor modes.
-;;
-;; 4. Defining buffer-local bindings in Vi and Insert modes.
-;; As mentioned before, sometimes, it is convenient to have
-;; buffer-specific of mode-specific key bindings in Vi and insert modes.
-;; Viper provides a special function, viper-add-local-keys, to do precisely
-;; this. For instance, is you need to add couple of mode-specific bindings
-;; to Insert mode, you can put
-;;
-;; (viper-add-local-keys 'insert-state '((key1 . func1) (key2 .func2)))
-;;
-;; somewhere in a hook of this major mode. If you put something like this
-;; in your own elisp function, this will define bindings specific to the
-;; buffer that was current at the time of the call to viper-add-local-keys.
-;; The only thing to make sure here is that the major mode of this buffer
-;; is written according to Emacs conventions, which includes a call to
-;; (kill-all-local-variables). See viper-add-local-keys for more details.
-;;
-;;
-;; TO DO (volunteers?):
-;;
-;; 1. Some of the code that is inherited from VIP-3.5 is rather
-;; convoluted. Instead of viper-command-argument, keymaps should bind the
-;; actual commands. E.g., "dw" should be bound to a generic command
-;; viper-delete that will delete things based on the value of
-;; last-command-event. This would greatly simplify the logic and the code.
-;;
-;; 2. Somebody should venture to write a customization package a la
-;; options.el that would allow the user to change values of variables
-;; that meet certain specs (e.g., match a regexp) and whose doc string
-;; starts with a '*'. Then, the user should be offered to save
-;; variables that were changed. This will make user's customization job
-;; much easier.
-;;
-
-;;; Code:
-
-(require 'cl-lib)
-
-;; compiler pacifier
-(defvar mark-even-if-inactive)
-(defvar viper-expert-level)
-(defvar viper-mode-string)
-(defvar viper-major-mode-modifier-list)
-;; end pacifier
-
-(require 'viper-init)
-(require 'viper-keym)
-
-;; better be defined before Viper custom group.
-(defvar viper-custom-file-name (locate-user-emacs-file "viper" ".viper")
- "Viper customization file.
-If set by the user, this must be done _before_ Viper is loaded in `~/.emacs'.")
-
-(defgroup viper nil
- "Vi emulation within Emacs.
-NOTE: Viper customization should be saved in `viper-custom-file-name'."
- :prefix "viper-"
- :group 'emulations)
-
-(require 'viper-cmd)
-
-(defgroup viper-misc nil
- "Miscellaneous Viper customization."
- :prefix "viper-"
- :group 'viper)
-
-
-(defcustom viper-always t
- "Non-nil means, arrange for vi-state to be a default when appropriate.
-This is different from `viper-mode' variable in that `viper-mode' determines
-whether to use Viper in the first place, while `viper-always', if nil, lets
-user decide when to invoke Viper in a major mode."
- :type 'boolean
- :tag "Always Invoke Viper")
-
-;; Non-viper variables that need to be saved in case the user decides to
-;; de-viperize emacs.
-(defvar viper-saved-non-viper-variables nil)
-
-(defcustom viper-mode (cond (noninteractive nil)
- (t 'ask))
- "To Viperize or not to Viperize.
-If t, viperize Emacs. If nil -- don't. If `ask', ask the user.
-This variable is used primarily when Viper is being loaded.
-
-Must be set in your init file before Viper is loaded.
-DO NOT set this variable interactively, unless you are using the customization
-widget."
- :type '(choice (const nil) (const t) (const ask))
- :tag "Set Viper Mode on Loading")
-
-(defcustom viper-vi-state-mode-list
- '(fundamental-mode
- makefile-mode
-
- awk-mode
- m4-mode
- xrdb-mode
- winmgr-mode
- autoconf-mode
- cvs-edit-mode
-
- html-mode html-helper-mode
- emacs-lisp-mode lisp-mode lisp-interaction-mode
-
- jde-mode java-mode
- cc-mode c-mode c++-mode objc-mode
- fortran-mode f90-mode
- basic-mode
- bat-mode
- asm-mode
- prolog-mode
- flora-mode
- sql-mode
-
- text-mode
- tex-mode latex-mode bibtex-mode
- ps-mode
-
- ;; completion-list-mode
- diff-mode
- idl-mode
-
- perl-mode
- javascript-mode
- tcl-mode
- python-mode
-
- sh-mode ksh-mode csh-mode
-
- gnus-article-mode
- )
- "Major modes that require Vi command state."
- :type '(repeat symbol))
-
-(defcustom viper-emacs-state-mode-list
- '(Custom-mode
-
- dired-mode
- efs-mode
- tar-mode
- egg-status-buffer-mode
-
- browse-kill-ring-mode
- recentf-mode
- recentf-dialog-mode
- occur-mode
-
- gnus-group-mode
- gnus-summary-mode
-
- completion-list-mode
- help-mode
-
- Info-mode
- Buffer-menu-mode
- compilation-mode
-
- rcirc-mode
-
- jde-javadoc-checker-report-mode
-
- view-mode
- vm-mode
- vm-summary-mode)
- "A list of major modes that should come up in Emacs state.
-Normally, Viper would bring buffers up in Emacs state, unless the corresponding
-major mode has been placed on `viper-vi-state-mode-list' or
-`viper-insert-state-mode-list'. So, don't place a new mode on this list,
-unless it is coming up in a wrong Viper state."
- :type '(repeat symbol))
-
-(defcustom viper-insert-state-mode-list
- '(internal-ange-ftp-mode
- comint-mode
- gud-mode
- inferior-emacs-lisp-mode
- erc-mode
- eshell-mode
- shell-mode)
- "A list of major modes that should come up in Vi Insert state."
- :type '(repeat symbol))
-
-
-;; used to set viper-major-mode-modifier-list in defcustom
-(defun viper-apply-major-mode-modifiers (&optional symbol value)
- (if symbol
- (set symbol value))
- (mapc (lambda (triple)
- (viper-modify-major-mode
- (nth 0 triple) (nth 1 triple) (symbol-value (nth 2 triple))))
- viper-major-mode-modifier-list))
-
-;; We change standard bindings in some major modes, making them slightly
-;; different than in "normal" vi/insert/emacs states
-(defcustom viper-major-mode-modifier-list
- '((help-mode emacs-state viper-slash-and-colon-map)
- (comint-mode insert-state viper-comint-mode-modifier-map)
- (comint-mode vi-state viper-comint-mode-modifier-map)
- (gud-mode insert-state viper-comint-mode-modifier-map)
- (shell-mode insert-state viper-comint-mode-modifier-map)
- (inferior-emacs-lisp-mode insert-state viper-comint-mode-modifier-map)
- (shell-mode vi-state viper-comint-mode-modifier-map)
- (ange-ftp-shell-mode insert-state viper-comint-mode-modifier-map)
- (ange-ftp-shell-mode vi-state viper-comint-mode-modifier-map)
- (internal-ange-ftp-mode insert-state viper-comint-mode-modifier-map)
- (internal-ange-ftp-mode vi-state viper-comint-mode-modifier-map)
- (dired-mode emacs-state viper-dired-modifier-map)
- (tar-mode emacs-state viper-slash-and-colon-map)
- (gnus-group-mode emacs-state viper-gnus-modifier-map)
- (gnus-summary-mode emacs-state viper-gnus-modifier-map)
- (Info-mode emacs-state viper-slash-and-colon-map)
- (Buffer-menu-mode emacs-state viper-slash-and-colon-map)
- (erc-mode insert-state viper-comint-mode-modifier-map)
- (erc-mode vi-state viper-comint-mode-modifier-map)
- )
- "List specifying how to modify the various major modes to enable some Viperisms.
-The list has the structure: ((mode viper-state keymap) (mode viper-state
-keymap) ...). If `mode' is on the list, the `keymap' will be made active (on
-the `minor-mode-map-alist') in the specified viper state.
-If you change this list, have to restart Emacs for the change to take effect.
-However, if you did the change through the customization widget, then Emacs
-needs to be restarted only if you deleted a triple mode-state-keymap from the
-list. No need to restart Emacs in case of insertion or modification of an
-existing triple."
- :type '(repeat
- (list symbol
- (choice (const emacs-state)
- (const vi-state)
- (const insert-state))
- symbol))
- :set #'viper-apply-major-mode-modifiers)
-
-\f
-
-;;;###autoload
-(defun toggle-viper-mode ()
- "Toggle Viper on/off.
-If Viper is enabled, turn it off. Otherwise, turn it on."
- (interactive)
- (if (eq viper-mode t)
- (viper-go-away)
- (setq viper-mode nil)
- (viper-mode)))
-
-;;;###autoload
-(defun viper-mode ()
- "Turn on Viper emulation of Vi in Emacs. See Info node `(viper)Top'."
- (interactive)
- (if (not noninteractive)
- (progn
- ;; if the user requested viper-mode explicitly
- (if viper-mode
- ()
- (setq viper-mode t)
- ;; FIXME: Don't reload!
- (load-library "viper"))
-
- (if viper-first-time ; Important check. Prevents mix-up of startup
- (progn ; and expert-level msgs when viper-mode recurses
- (setq viper-first-time nil)
- (if (not viper-inhibit-startup-message)
- (save-window-excursion
- (setq viper-inhibit-startup-message t)
- (delete-other-windows)
- (switch-to-buffer "Viper Startup Message")
- (erase-buffer)
- (insert
- (substitute-command-keys
- "Viper Is a Package for Emacs Rebels,
-a VI Plan for Emacs Rescue, and a venomous VI PERil.
-
-Incidentally, Viper emulates Vi under Emacs.
-It supports all of what is good in Vi and Ex, while extending
-and improving upon much of it.
-
- 1. Viper supports Vi at several levels. Level 1 is the closest to Vi,
- level 5 provides the most flexibility to depart from many Vi conventions.
-
- You will be asked to specify your user level in a following screen.
-
- If you select user level 1 then the keys ^X, ^C, ^Z, and ^G will behave
- as in VI, to smooth transition to Viper for the beginners. However, to
- use Emacs productively, you are advised to reach user level 3 or higher.
-
- At user level 2 or higher, ^X and ^C have Emacs, not Vi, bindings;
- ^Z toggles Vi/Emacs states; ^G is Emacs's keyboard-quit (like ^C in Vi).
-
- 2. Vi exit functions (e.g., :wq, ZZ) work on INDIVIDUAL files -- they
- do not cause Emacs to quit, except at user level 1 (for a novice).
- 3. ^X^C EXITS EMACS.
- 4. Viper supports multiple undo: \\`u' will undo. Typing \\`.' will repeat
- undo. Another \\`u' changes direction.
-
- 6. Emacs Meta key is \\`C-\\' (in all modes) or \\`\\ ESC' (in Vi command mode).
- On a window system, the best way is to use the Meta-key on your keyboard.
- 7. Try \\[keyboard-quit] and \\[abort-recursive-edit] repeatedly,if
- something funny happens. This would abort the current editing command.
-
-For more information on Viper:
-
- a. Type `:help' in Vi command mode
- b. Print Viper manual, found in ./etc/viper.dvi
- c. Print the Quick Reference, found in ./etc/viperCard.dvi
-
-To submit a bug report or to contact the author, type \\`:submitReport' in Vi
-command mode. To shoo Viper away and return to pure Emacs (horror!), type:
-
- \\[viper-go-away]
-
-This startup message appears whenever you load Viper, unless you type \\`y' now."
- ))
- (goto-char (point-min))
- (if (y-or-n-p "Inhibit Viper startup message? ")
- (viper-save-setting
- 'viper-inhibit-startup-message
- "Viper startup message inhibited"
- viper-custom-file-name t))
- ;;(kill-buffer (current-buffer))
- (message
- "The last message is in buffer `Viper Startup Message'")
- (sit-for 4)
- ))
- (viper-set-expert-level 'dont-change-unless)))
-
- (or (derived-mode-p viper-emacs-state-mode-list) ; don't switch to Vi
- (derived-mode-p viper-insert-state-mode-list) ; don't switch
- (viper-change-state-to-vi))
- ))
-
- (if (eq major-mode 'viper-mode)
- (setq major-mode 'fundamental-mode))
- )
-
-
-;; Apply a little heuristic to invoke vi state on major-modes
-;; that are not listed in viper-vi-state-mode-list
-(defun viper-this-major-mode-requires-vi-state (mode)
- (let ((major-mode mode))
- (cond ((derived-mode-p viper-vi-state-mode-list) t)
- ((derived-mode-p viper-emacs-state-mode-list) nil)
- ((derived-mode-p viper-insert-state-mode-list) nil)
- (t (and (eq (key-binding "a") 'self-insert-command)
- (eq (key-binding " ") 'self-insert-command))))))
-
-\f
-;; This hook designed to enable Vi-style editing in comint-based modes."
-(defun viper-comint-mode-hook ()
- (setq-local require-final-newline nil)
- (setq viper-ex-style-editing nil
- viper-ex-style-motion nil)
- (viper-change-state-to-insert))
-
-
-;; remove viper hooks from SYMBOL
-(defun viper-remove-hooks (symbol)
- (cond ((not (boundp symbol)) nil)
- ((not (listp (symbol-value symbol))) nil)
- ((string-match "-hook" (symbol-name symbol))
- (remove-hook symbol #'viper-mode)
- (remove-hook symbol #'viper-change-state-to-emacs)
- (remove-hook symbol #'viper-change-state-to-insert)
- (remove-hook symbol #'viper-change-state-to-vi)
- (remove-hook symbol #'viper-minibuffer-post-command-hook)
- (remove-hook symbol #'viper-minibuffer-setup-sentinel)
- (remove-hook symbol #'viper-major-mode-change-sentinel)
- (remove-hook symbol #'viper-set-state-in-major-mode)
- (remove-hook symbol #'viper-post-command-sentinel)
- )))
-
-;; Remove local value in all existing buffers
-;; This doesn't delocalize vars (which would have been desirable)
-(defun viper-delocalize-var (symbol)
- (dolist (buf (buffer-list))
- (with-current-buffer buf
- (kill-local-variable symbol))))
-
-(defvar viper--advice-list nil)
-
-(defun viper--advice-add (function where advice)
- (advice-add function where advice)
- (push (cons function advice) viper--advice-list))
-
-(defun viper--deactivate-advice-list ()
- (mapc (lambda (n)
- (advice-remove
- (car n)
- (cdr n)))
- viper--advice-list)
- (setq viper--advice-list nil))
-
-(defun viper-go-away ()
- "De-Viperize Emacs.
-This function tries to do as good a job as possible. However, it may undo some
-user customization, unrelated to Viper. For instance, if the user advised
-`read-file-name', `describe-key', and some others, then this advice will be
-undone.
-It also can't undo some Viper settings."
- (interactive)
- (viper-setup-ESC-to-escape nil)
- ;; restore non-viper vars
- (setq-default
- next-line-add-newlines
- (viper-standard-value
- 'next-line-add-newlines viper-saved-non-viper-variables)
- require-final-newline
- (viper-standard-value
- 'require-final-newline viper-saved-non-viper-variables)
- scroll-step
- (viper-standard-value 'scroll-step viper-saved-non-viper-variables)
- mode-line-buffer-identification
- (viper-standard-value
- 'mode-line-buffer-identification viper-saved-non-viper-variables)
- global-mode-string
- (delq 'viper-mode-string global-mode-string))
-
- (setq-default major-mode
- (viper-standard-value 'major-mode
- viper-saved-non-viper-variables))
-
- (setq-default
- mark-even-if-inactive
- (viper-standard-value
- 'mark-even-if-inactive viper-saved-non-viper-variables))
-
- ;; Ideally, we would like to be able to de-localize local variables
- (viper-delocalize-var 'require-final-newline)
-
- ;; deactivate all advices done by Viper.
- (viper--deactivate-advice-list)
-
- (setq viper-mode nil)
-
- (setq emulation-mode-map-alists
- (delq 'viper--intercept-key-maps
- (delq 'viper--key-maps emulation-mode-map-alists)))
-
- (viper-delocalize-var 'viper-vi-minibuffer-minor-mode)
- (viper-delocalize-var 'viper-insert-minibuffer-minor-mode)
- (viper-delocalize-var 'viper-vi-intercept-minor-mode)
- (viper-delocalize-var 'viper-insert-intercept-minor-mode)
-
- (viper-delocalize-var 'viper-vi-local-user-minor-mode)
- (viper-delocalize-var 'viper-vi-kbd-minor-mode)
- (viper-delocalize-var 'viper-vi-global-user-minor-mode)
- (viper-delocalize-var 'viper-vi-state-modifier-minor-mode)
- (viper-delocalize-var 'viper-vi-diehard-minor-mode)
- (viper-delocalize-var 'viper-vi-basic-minor-mode)
-
- (viper-delocalize-var 'viper-replace-minor-mode)
-
- (viper-delocalize-var 'viper-insert-local-user-minor-mode)
- (viper-delocalize-var 'viper-insert-kbd-minor-mode)
- (viper-delocalize-var 'viper-insert-global-user-minor-mode)
- (viper-delocalize-var 'viper-insert-state-modifier-minor-mode)
- (viper-delocalize-var 'viper-insert-diehard-minor-mode)
- (viper-delocalize-var 'viper-insert-basic-minor-mode)
-
- (viper-delocalize-var 'viper-emacs-intercept-minor-mode)
- (viper-delocalize-var 'viper-emacs-local-user-minor-mode)
- (viper-delocalize-var 'viper-emacs-kbd-minor-mode)
- (viper-delocalize-var 'viper-emacs-global-user-minor-mode)
- (viper-delocalize-var 'viper-emacs-state-modifier-minor-mode)
-
- (viper-delocalize-var 'viper-current-state)
- (viper-delocalize-var 'viper-mode-string)
-
- (setq-default viper-vi-minibuffer-minor-mode nil
- viper-insert-minibuffer-minor-mode nil
- viper-vi-intercept-minor-mode nil
- viper-insert-intercept-minor-mode nil
-
- viper-vi-local-user-minor-mode nil
- viper-vi-kbd-minor-mode nil
- viper-vi-global-user-minor-mode nil
- viper-vi-state-modifier-minor-mode nil
- viper-vi-diehard-minor-mode nil
- viper-vi-basic-minor-mode nil
-
- viper-replace-minor-mode nil
-
- viper-insert-local-user-minor-mode nil
- viper-insert-kbd-minor-mode nil
- viper-insert-global-user-minor-mode nil
- viper-insert-state-modifier-minor-mode nil
- viper-insert-diehard-minor-mode nil
- viper-insert-basic-minor-mode nil
-
- viper-emacs-intercept-minor-mode nil
- viper-emacs-local-user-minor-mode nil
- viper-emacs-kbd-minor-mode nil
- viper-emacs-global-user-minor-mode nil
- viper-emacs-state-modifier-minor-mode nil
-
- viper-current-state 'emacs-state
- viper-mode-string viper-emacs-state-id
- )
-
- ;; remove all hooks set by viper
- (mapatoms #'viper-remove-hooks)
- (remove-hook 'comint-mode-hook #'viper-comint-mode-hook)
- (remove-hook 'erc-mode-hook #'viper-comint-mode-hook)
- (remove-hook 'change-major-mode-hook #'viper-major-mode-change-sentinel)
-
- ;; unbind Viper mouse bindings
- (viper-unbind-mouse-search-key)
- (viper-unbind-mouse-insert-key)
- ;; In emacs, we have to advice handle-switch-frame
- ;; This advice is undone earlier, when all advices matching "viper-" are
- ;; deactivated.
- ) ; end viper-go-away
-
-
-;; list of buffers that just changed their major mode
-;; used in a hack that triggers vi command mode whenever needed
-(defvar viper-new-major-mode-buffer-list nil)
-
-;; set appropriate Viper state in buffers that changed major mode
-(defun viper-set-state-in-major-mode ()
- (mapc
- (lambda (buf)
- (if (viper-buffer-live-p buf)
- (with-current-buffer buf
- (cond ((and (viper-this-major-mode-requires-vi-state major-mode)
- (eq viper-current-state 'emacs-state))
- (viper-mode))
- ((cl-member-if #'derived-mode-p viper-emacs-state-mode-list)
- ;; not checking (eq viper-current-state 'emacs-state)
- ;; because viper-current-state could have gotten it by
- ;; default. We need viper-change-state-to-emacs here to have
- ;; the keymaps take effect.
- (viper-change-state-to-emacs))
- ((and (cl-member-if #'derived-mode-p
- viper-insert-state-mode-list)
- (not (eq viper-current-state 'insert-state)))
- (viper-change-state-to-insert))
- )) ; with-current-buffer
- )) ; function
- viper-new-major-mode-buffer-list)
- ;; clear the list of bufs that changed major mode
- (setq viper-new-major-mode-buffer-list nil)
- ;; change the global value of hook
- (remove-hook 'viper-post-command-hooks #'viper-set-state-in-major-mode))
-
-;; sets up post-command-hook to turn viper-mode, if the current mode is
-;; fundamental
-(defun viper-major-mode-change-sentinel ()
- (save-match-data
- (or (string-match "\\*Minibuf-" (buffer-name))
- (setq viper-new-major-mode-buffer-list
- (cons (current-buffer) viper-new-major-mode-buffer-list))))
- ;; change the global value of hook
- (add-hook 'viper-post-command-hooks #'viper-set-state-in-major-mode t))
-
-
-;;; Handling of tty's ESC event
-
-;; On a tty, an ESC event can either be the user hitting the escape key, or
-;; some element of a byte sequence used to encode for example cursor keys.
-;; So we try to recognize those events that correspond to the escape key and
-;; turn them into `escape' events (same as used under GUIs). The heuristic we
-;; use to distinguish the two cases is based, as usual, on a timeout, and on
-;; the fact that the special ESC=>escape mapping only takes place if the whole
-;; last key-sequence so far is just [?\e], i.e. either we're still in
-;; read-key-sequence, or the last read-key-sequence only read [?\e], which
-;; should ideally never happen because it should have been mapped to [escape].
-
-(defun viper--tty-ESC-filter (map)
- (if (and (equal (this-single-command-keys) [?\e])
- (sit-for (/ viper-fast-keyseq-timeout 1000)))
- [escape] map))
-
-(defun viper--lookup-key (map key)
- "Kind of like `lookup-key'.
-Two differences:
-- KEY is a single key, not a sequence.
-- the result is the \"raw\" binding, so it can be a `menu-item', rather than the
- binding contained in that menu item."
- (catch 'found
- (map-keymap (lambda (k b) (if (equal key k) (throw 'found b))) map)))
-
-(defun viper-catch-tty-ESC ()
- "Setup key mappings of current terminal to turn a tty's ESC into `escape'."
- (when (memq (terminal-live-p (frame-terminal)) '(t pc))
- (let ((esc-binding (viper-uncatch-tty-ESC)))
- (define-key input-decode-map
- [?\e] `(menu-item "" ,esc-binding :filter viper--tty-ESC-filter)))))
-
-(defun viper-uncatch-tty-ESC ()
- "Don't hack ESC into `escape' any more."
- (let ((b (viper--lookup-key input-decode-map ?\e)))
- (and (eq 'menu-item (car-safe b))
- (eq 'viper--tty-ESC-filter (nth 4 b))
- (define-key input-decode-map [?\e] (setq b (nth 2 b))))
- b))
-
-(defun viper-setup-ESC-to-escape (enable)
- (if enable
- (add-hook 'tty-setup-hook #'viper-catch-tty-ESC)
- (remove-hook 'tty-setup-hook #'viper-catch-tty-ESC))
- (let ((seen ()))
- (dolist (frame (frame-list))
- (let ((terminal (frame-terminal frame)))
- (unless (memq terminal seen)
- (push terminal seen)
- (with-selected-frame frame
- (if enable (viper-catch-tty-ESC) (viper-uncatch-tty-ESC))))))))
-
-;; This sets major mode hooks to make them come up in vi-state.
-(defun viper-set-hooks ()
- ;; It is of course a misnomer to call viper-mode a `major mode'.
- ;; However, this has the effect that if the user didn't specify the
- ;; default mode, new buffers that fall back on the default will come up
- ;; in Fundamental Mode and Vi state.
- ;; When viper-mode is executed in such a case, it will set the major mode
- ;; back to fundamental-mode.
- (if (eq (default-value 'major-mode) #'fundamental-mode)
- ;; FIXME: We should use after-change-major-mode-hook instead!
- (setq-default major-mode #'viper-mode))
-
- (viper-setup-ESC-to-escape t)
-
- (add-hook 'change-major-mode-hook #'viper-major-mode-change-sentinel)
- (add-hook 'find-file-hook #'viper-set-state-in-major-mode)
-
- ;; keep this because many modes we don't know about use this hook
- (defvar text-mode-hook)
- (add-hook 'text-mode-hook #'viper-mode)
-
- (defvar emerge-startup-hook)
- (add-hook 'emerge-startup-hook #'viper-change-state-to-emacs)
-
- ;; if viper is started from .emacs, it might be impossible to get certain
- ;; info about the display and windows until emacs initialization is complete
- ;; So do it via the window-setup-hook
- (add-hook 'window-setup-hook
- (lambda ()
- (modify-frame-parameters
- (selected-frame)
- (list (cons 'viper-vi-state-cursor-color
- (viper-get-cursor-color))))
- (setq viper-vi-state-cursor-color (viper-get-cursor-color))
- ))
-
- ;; Tell vc-diff to put *vc* in Vi mode
- (viper--advice-add 'vc-diff :after #'viper-change-state-to-vi)
- (viper--advice-add 'emerge-quit :after #'viper-change-state-to-vi)
-
- ;; passwd.el sets up its own buffer, which turns up in Vi mode,
- ;; thus overriding the local map. We don't need Vi mode here.
- (viper--advice-add 'read-passwd-1 :before #'viper-change-state-to-emacs)
-
- (viper--advice-add 'self-insert-command :around
- (lambda (orig-fun &rest args)
- ;; FIXME: Use remapping?
- (if (and (eq viper-current-state 'vi-state)
- (called-interactively-p 'interactive))
- (beep 1)
- (apply orig-fun args))))
-
- (viper--advice-add 'set-cursor-color :after
- (lambda (color-name)
- "Change cursor color in VI state."
- (modify-frame-parameters
- (selected-frame)
- (list (cons 'viper-vi-state-cursor-color color-name)))
- (setq viper-vi-state-cursor-color color-name)))
-
-
- ;; needs to be as early as possible
- (add-to-ordered-list
- 'emulation-mode-map-alists 'viper--intercept-key-maps 100)
- ;; needs to be after cua-mode
- (add-to-ordered-list 'emulation-mode-map-alists 'viper--key-maps 500)
-
- ;; Emacs shell, ange-ftp, and comint-based modes
- (add-hook 'comint-mode-hook #'viper-comint-mode-hook) ; comint
- (add-hook 'erc-mode-hook #'viper-comint-mode-hook) ; ERC
-
- (add-hook 'eshell-mode-hook
- (lambda () (setq viper-auto-indent nil)))
-
- (viper-set-emacs-state-searchstyle-macros nil 'dired-mode) ; dired
- (viper-set-emacs-state-searchstyle-macros nil 'tar-mode) ; tar
- (viper-set-emacs-state-searchstyle-macros nil 'gnus-group-mode) ; gnus
- (viper-set-emacs-state-searchstyle-macros nil 'gnus-summary-mode)
- (viper-set-emacs-state-searchstyle-macros nil 'Info-mode) ; info
- (viper-set-emacs-state-searchstyle-macros nil 'Buffer-menu-mode) ;buffer-menu
-
- ;; Modify major modes according to viper-major-mode-modifier-list
- (viper-apply-major-mode-modifiers)
-
- ;; For RMAIL users.
- ;; Put buf in Emacs state after edit.
- (viper--advice-add 'rmail-cease-edit :after #'viper-change-state-to-emacs)
-
- ;; ISO accents.
- (viper--advice-add 'iso-accents-mode :after
- (lambda (arg &rest _)
- "Set viper-automatic-iso-accents to iso-accents-mode."
- (defvar iso-accents-mode)
- (setq viper-automatic-iso-accents
- (if (eq viper-current-state 'vi-state)
- (if arg
- ;; if iso-accents-mode was called with positive arg, turn
- ;; accents on
- (> (prefix-numeric-value arg) 0)
- ;; else: toggle viper-automatic-iso-accents
- (not viper-automatic-iso-accents))
- ;; other states: accept what iso-accents-mode has done
- iso-accents-mode))
- ;; turn off ISO accents in vi-state
- (if (eq viper-current-state 'vi-state)
- (viper-set-iso-accents-mode nil))
- (if (memq viper-current-state '(vi-state insert-state replace-state))
- (message "Viper ISO accents mode: %s"
- (if viper-automatic-iso-accents "on" "off")))
- ))
-
- ;; International input methods
- (if nil ;; (featurep 'emacs) ;;The hooks should now work!
- (progn
- (viper--advice-add 'deactivate-input-method :after
- #'viper-deactivate-input-method-action)
- (viper--advice-add 'activate-input-method :after
- #'viper-activate-input-method-action))
- ;; XEmacs Although these hooks exist in Emacs, they don't seem to be always
- ;; called on input-method activation/deactivation, so we the above advise
- ;; functions instead.
- (eval-after-load "mule-cmds"
- '(progn
- (add-hook 'input-method-activate-hook
- #'viper-activate-input-method-action t)
- (add-hook 'input-method-deactivate-hook
- #'viper-deactivate-input-method-action t)))
- )
- (viper--advice-add 'toggle-input-method :around
- (lambda (orig-fun &rest args)
- "Adjust input-method toggling in vi-state."
- (if (and viper-special-input-method (eq viper-current-state 'vi-state))
- (deactivate-input-method)
- (apply orig-fun args))))
-
- ) ; viper-set-hooks
-
-
-;; these are primarily advices and Vi-ish variable settings
-(defun viper-non-hook-settings ()
-
- ;;;; Viper changes the default mode-line-buffer-identification
- ;;(setq-default mode-line-buffer-identification '(" %b"))
-
- ;; setup emacs-supported vi-style feel
- (setq next-line-add-newlines nil
- require-final-newline t)
-
- ;; don't bark when mark is inactive
- (setq mark-even-if-inactive t)
-
- (setq scroll-step 1)
-
- ;; Variable displaying the current Viper state in the mode line.
- (or (memq 'viper-mode-string global-mode-string)
- (setq global-mode-string
- (append '("" viper-mode-string) (cdr global-mode-string))))
-
- (viper--advice-add 'read-file-name :around
- (lambda (orig-fun &rest args)
- "Tell `exit-minibuffer' to run `viper-file-add-suffix' as a hook."
- (let ((viper-minibuffer-exit-hook
- (append viper-minibuffer-exit-hook
- '(viper-minibuffer-trim-tail viper-file-add-suffix))))
- (apply orig-fun args))))
-
- (viper--advice-add 'start-kbd-macro :after
- (lambda (&rest _)
- "Remove Viper's intercepting bindings for C-x ).
-This may be needed if the previous `:map' command terminated abnormally."
- (define-key viper-vi-intercept-map "\C-x)" nil)
- (define-key viper-insert-intercept-map "\C-x)" nil)
- (define-key viper-emacs-intercept-map "\C-x)" nil)))
-
- (viper--advice-add 'add-minor-mode :after
- (lambda (&rest _)
- "Run viper-normalize-minor-mode-map-alist after adding a minor mode."
- (viper-normalize-minor-mode-map-alist)))
-
- ;; catch frame switching event
- (if (viper-window-display-p)
- (viper--advice-add
- 'handle-switch-frame :before
- #'viper-remember-current-frame))
-
- ) ; end viper-non-hook-settings
-
-
-\f
-;; Ask only if this-command/last-command are nil, i.e., when loading
-(cond ((and (eq viper-mode 'ask) (null this-command) (null last-command))
- (save-window-excursion
- (with-output-to-temp-buffer " *viper-info*"
- (princ "
-You have loaded Viper, and are about to Viperize your Emacs!
-
-Viper is a Package for Emacs Rebels and a venomous VI PERil,
-
-It's time to decide: to Viperize or not to Viperize...
-
-If you wish to Viperize AND make this your way of life, please put
-
- (setq viper-mode t)
- (require 'viper)
-
-in your init file (preferably, close to the top).
-These two lines must come in the order given."))
- (if (y-or-n-p "Viperize? ")
- (setq viper-mode t)
- (setq viper-mode nil))
- (message "")
- (kill-buffer " *viper-info*")))
-
- ;; If viper-mode is t, then just continue. Viper will kick in.
- ((eq viper-mode t))
- ;; Otherwise, it was asking Viper was not loaded through .emacs
- ;; In this case, it was either through M-x viper-mode or via something
- ;; else, like the custom widget. If Viper was loaded through
- ;; M-x viper-mode, then viper will kick in anyway.
- (t (setq viper-mode nil)))
-
-(defun viper-load-custom-file ()
- (if (and (file-exists-p viper-custom-file-name)
- (not noninteractive))
- (load viper-custom-file-name)))
-
-
-
-\f
-
-
-;; save non-viper vars that Viper might change
-(if (null viper-saved-non-viper-variables)
- (setq viper-saved-non-viper-variables
- (list
- (cons 'major-mode (list (default-value 'major-mode)))
- (cons 'next-line-add-newlines (list next-line-add-newlines))
- (cons 'require-final-newline (list require-final-newline))
- (cons 'scroll-step (list scroll-step))
- (cons 'mode-line-buffer-identification
- (list (default-value 'mode-line-buffer-identification)))
- (cons 'global-mode-string (list global-mode-string))
- (cons 'mark-even-if-inactive (list mark-even-if-inactive)))))
-
-
-;; Set some useful macros, advices
-;; These must be BEFORE viper-custom-file-name is loaded,
-;; so the user can unrecord them in viper-custom-file-name.
-(if viper-mode
- (progn
- ;; set advices and some variables that give emacs Vi look.
- (viper-non-hook-settings)
-
- ;; repeat the 2nd previous command without rotating the command history
- (viper-record-kbd-macro
- (vector viper-repeat-from-history-key '\1) 'vi-state
- [(meta x) v i p e r - r e p e a t - f r o m - h i s t o r y return] 't)
- ;; repeat the 3d previous command without rotating the command history
- (viper-record-kbd-macro
- (vector viper-repeat-from-history-key '\2) 'vi-state
- [(meta x) v i p e r - r e p e a t - f r o m - h i s t o r y return] 't)
-
- ;; set macros for toggling case sensitivity and regexp search
- (viper-set-searchstyle-toggling-macros nil)
- ;; Make %%% toggle parsing comments for matching parentheses
- (viper-set-parsing-style-toggling-macro nil)
-
- ;; viper-custom-file-name is loaded if exists
- (viper-load-custom-file)
-
- ;; should be after loading custom file to avoid the pesky msg that
- ;; mouse-search/insert keys are already bound
- (viper-bind-mouse-search-key)
- (viper-bind-mouse-insert-key)
- ))
-
-
-\f
-;; Applying Viper customization -- runs after (load viper-custom-file-name)
-
-;; Save user settings or Viper defaults for vars controlled by
-;; viper-expert-level
-(if (null viper-saved-user-settings)
- (setq viper-saved-user-settings
- (list (cons 'viper-want-ctl-h-help (list viper-want-ctl-h-help))
- (cons 'viper-always (list viper-always))
- (cons 'viper-no-multiple-ESC (list viper-no-multiple-ESC))
- (cons 'viper-ex-style-motion (list viper-ex-style-motion))
- (cons 'viper-ex-style-editing
- (list viper-ex-style-editing))
- (cons 'viper-want-emacs-keys-in-vi
- (list viper-want-emacs-keys-in-vi))
- (cons 'viper-electric-mode (list viper-electric-mode))
- (cons 'viper-want-emacs-keys-in-insert
- (list viper-want-emacs-keys-in-insert))
- (cons 'viper-re-search (list viper-re-search)))))
-
-
-\f
-;; Intercept maps could go in viper-keym.el
-;; We keep them here in case someone redefines them in viper-custom-file-name
-
-(define-key viper-vi-intercept-map viper-ESC-key #'viper-intercept-ESC-key)
-(define-key viper-insert-intercept-map viper-ESC-key #'viper-intercept-ESC-key)
-
-;; This is taken care of by viper-insert-global-user-map.
-;;(define-key viper-replace-map viper-ESC-key #'viper-intercept-ESC-key)
-
-
-;; The default viper-toggle-key is \C-z; for the novice, it suspends or
-;; iconifies Emacs
-(define-key viper-vi-intercept-map viper-toggle-key #'viper-toggle-key-action)
-(define-key
- viper-emacs-intercept-map viper-toggle-key #'viper-change-state-to-vi)
-
-;; Removed to avoid bad interaction with cua-mode.
-;; Escape from Emacs and Insert modes to Vi for one command
-;;(define-key viper-emacs-intercept-map "\C-c\\" 'viper-escape-to-vi)
-;;(define-key viper-insert-intercept-map "\C-c\\" 'viper-escape-to-vi)
-
-(when viper-mode
- (viper-set-minibuffer-style)
- (if viper-buffer-search-char
- (viper-buffer-search-enable))
- (viper-update-syntax-classes 'set-default)
-
- ;; Familiarize Viper with some minor modes that have their own keymaps
- (viper-harness-minor-mode "compile")
- (viper-harness-minor-mode "outline")
- (viper-harness-minor-mode "allout")
- (viper-harness-minor-mode "xref")
- (viper-harness-minor-mode "vc")
- (viper-harness-minor-mode "ltx-math") ; LaTeX-math-mode in AUC-TeX, which
- (viper-harness-minor-mode "latex") ; sits in one of these two files
- (viper-harness-minor-mode "cyrillic")
- (viper-harness-minor-mode "russian")
- (viper-harness-minor-mode "view-less")
- (viper-harness-minor-mode "view")
- (viper-harness-minor-mode "reftex")
- (viper-harness-minor-mode "flyspell")
-
- (setq-default viper-emacs-intercept-minor-mode t
- viper-emacs-local-user-minor-mode t
- viper-emacs-global-user-minor-mode t
- viper-emacs-kbd-minor-mode t
- viper-emacs-state-modifier-minor-mode t)
- (if (eq viper-current-state 'emacs-state)
- (setq viper-emacs-intercept-minor-mode t
- viper-emacs-local-user-minor-mode t
- viper-emacs-global-user-minor-mode t
- viper-emacs-kbd-minor-mode t
- viper-emacs-state-modifier-minor-mode t))
-
-
- (if (or viper-always
- (and (< viper-expert-level 5) (> viper-expert-level 0)))
- (viper-set-hooks))
-
- ;; Let all minor modes take effect after loading.
- ;; This may not be enough, so we also set default minor-mode-alist.
- ;; Without setting the default, new buffers that come up in emacs mode have
- ;; minor-mode-map-alist = nil, unless we call viper-change-state-*
- (when (eq viper-current-state 'emacs-state)
- (viper-change-state-to-emacs))
-
- (if (viper-this-major-mode-requires-vi-state major-mode)
- (viper-mode))
-
- (add-function :after initial-major-mode #'viper-set-state-in-major-mode))
-
-(define-obsolete-function-alias 'set-viper-state-in-major-mode
- #'viper-set-state-in-major-mode "29.1")
-(define-obsolete-function-alias 'this-major-mode-requires-vi-state
- #'viper-this-major-mode-requires-vi-state "29.1")
-
-(run-hooks 'viper-load-hook) ; the last chance to change something
-
-(provide 'viper)
-
-;;; viper.el ends here
("tramp" "Variable Index" "Function Index")
("url" "Variable Index" "Function Index")
("use-package" "Index")
- ("viper" "Variable Index" "Function Index")
("vtable" "Index")
("widget" "Index")
("woman" "Variable Index" "Command Index")))
(goto-char (match-beginning 1)) ;; start of nodename as error position
(info-xref-check-node (match-string 1)))))
-(defvar viper-mode) ;; quieten the byte compiler
(defvar gnus-registry-install)
;;;###autoload
;; defvars in those files. Of course it'd be better if those files
;; didn't make interactive queries on loading at all, to allow for
;; programmatic loading like here.
- (unless (boundp 'viper-mode)
- (setq viper-mode nil)) ;; avoid viper.el ask about viperizing
(unless (boundp 'gnus-registry-install)
(setq gnus-registry-install nil)) ;; avoid gnus-registry.el querying
"org" "pcl-cvs" "pgg" "rcirc" "reftex" "remember" "sasl" "sc"
"semantic" "ses" "sieve" "smtpmail" "speedbar" "srecode"
"todo-mode" "tramp" "transient" "url" "use-package"
- "viper" "vtable" "widget" "wisent" "woman") .
+ "vtable" "widget" "wisent" "woman") .
"https://www.gnu.org/software/emacs/manual/html_node/%m/%e"))
"Alist telling `Info-mode' where manuals are accessible online.
\f
(defvar Info-file-list-for-emacs
'("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info")
- "sc" "message" ("dired" . "dired-x") "viper"
+ "sc" "message" ("dired" . "dired-x")
("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
("skeleton" . "autotype") ("auto-insert" . "autotype")
"mairix-el" "message" "modus-themes" "newsticker" "nxml-mode" "octave-mode"
"org" "pcl-cvs" "pgg" "rcirc" "reftex" "remember" "sasl" "sc" "semantic"
"ses" "sieve" "smtpmail" "speedbar" "srecode" "todo-mode" "tramp" "transient"
- "url" "use-package" "vip" "viper" "vtable" "widget" "wisent" "woman")
+ "url" "use-package" "vip" "vtable" "widget" "wisent" "woman")
"List of Emacs documents available.
Taken from <https://www.gnu.org/software/emacs/manual/html_mono/.>")
(setq remark (list "cua-mode replacement" 'cua-mode))
(setq where "Same key")
nil)
- ;; viper-mode specials:
- ((and (boundp 'viper-mode-string)
- (boundp 'viper-current-state)
- (eq viper-current-state 'vi-state)
- (or (and (eq def-fun 'isearch-forward)
- (eq key-fun 'viper-isearch-forward))
- (and (eq def-fun 'isearch-backward)
- (eq key-fun 'viper-isearch-backward))))
- ;; These bindings works as the default bindings,
- ;; return t
- t)
((when normal-erase-is-backspace
(or (and (equal key [C-delete])
(equal key-fun 'kill-word))
tutorial--default-keys
"\\|")
"\\)[[:punct:][:space:]]")))
- ;; Need the custom button face for viper buttons:
- (if (boundp 'viper-mode-string) (require 'cus-edit))
- (if (or changed-keys (boundp 'viper-mode-string))
+ (if changed-keys
(let ((head (get-lang-string tutorial--lang 'tut-chgdhead))
(head2 (get-lang-string tutorial--lang 'tut-chgdhead2)))
(when (and head head2)
position in the buffer is saved so that the tutorial may be
resumed later."
(interactive "P")
- (if (boundp 'viper-current-state)
- (let ((prompt1
- "You can not run the Emacs tutorial directly because you have \
-enabled Viper.")
- (prompt2 "\nThere is however a Viper tutorial you can run instead.
-Run the Viper tutorial? "))
- (if (fboundp 'viper-tutorial)
- (if (y-or-n-p (concat prompt1 prompt2))
- (progn (message "")
- (funcall #'viper-tutorial 0))
- (message "Tutorial aborted by user"))
- (message prompt1)))
- (let* ((lang (cond
- (arg
- (minibuffer-with-setup-hook #'minibuffer-completion-help
- (read-language-name 'tutorial "Language: " "English")))
- ((get-language-info current-language-environment 'tutorial)
- current-language-environment)
- (t "English")))
- (filename (get-language-info lang 'tutorial))
- (tut-buf-name filename)
- (old-tut-buf (get-buffer tut-buf-name))
- (old-tut-win (when old-tut-buf (get-buffer-window old-tut-buf t)))
- (old-tut-is-ok (when old-tut-buf
- (not (buffer-modified-p old-tut-buf))))
- old-tut-file
- (old-tut-point 1))
- (setq tutorial--point-after-chkeys (point-min))
- ;; Try to display the tutorial buffer before asking to revert it.
- ;; If the tutorial buffer is shown in some window make sure it is
- ;; selected and displayed:
- (if old-tut-win
- (raise-frame
- (window-frame
- (select-window (get-buffer-window old-tut-buf t))))
- ;; Else, is there an old tutorial buffer? Then display it:
- (when old-tut-buf
- (switch-to-buffer old-tut-buf)))
- ;; Use whole frame for tutorial
- (delete-other-windows)
- ;; If the tutorial buffer has been changed then ask if it should
- ;; be reverted:
- (when (and old-tut-buf
- (not old-tut-is-ok))
- (setq old-tut-is-ok
- (if dont-ask-for-revert
- nil
- (not (y-or-n-p
- "You have changed the Tutorial buffer. Revert it? ")))))
- ;; (Re)build the tutorial buffer if it is not ok
- (unless old-tut-is-ok
- (switch-to-buffer (get-buffer-create tut-buf-name))
- (setq tutorial--buffer (current-buffer))
- ;; (unless old-tut-buf (text-mode))
- (unless lang (error "Variable lang is nil"))
- (setq tutorial--lang lang)
- (setq old-tut-file (file-exists-p (tutorial--saved-file)))
- (let ((inhibit-read-only t))
- (erase-buffer))
- (message "Preparing tutorial ...") (sit-for 0)
-
- ;; Do not associate the tutorial buffer with a file. Instead use
- ;; a hook to save it when the buffer is killed.
- (setq buffer-auto-save-file-name nil)
- (add-hook 'kill-buffer-hook 'tutorial--save-tutorial nil t)
- (add-hook 'kill-emacs-query-functions 'tutorial--save-on-kill)
-
- ;; Insert the tutorial. First offer to resume last tutorial
- ;; editing session.
- (when dont-ask-for-revert
- (setq old-tut-file nil))
- (when old-tut-file
- (setq old-tut-file
- (y-or-n-p "Resume your last saved tutorial? ")))
- (if old-tut-file
- (progn
- (insert-file-contents (tutorial--saved-file))
- (let ((enable-local-variables :safe)
- (enable-local-eval nil)
- (enable-dir-local-variables nil)) ; bug#11127
- (hack-local-variables))
- (goto-char (point-min))
- (setq old-tut-point
- (string-to-number
- (buffer-substring-no-properties
- (line-beginning-position) (line-end-position))))
- (forward-line)
- (setq tutorial--point-before-chkeys
- (string-to-number
- (buffer-substring-no-properties
- (line-beginning-position) (line-end-position))))
- (forward-line)
- (delete-region (point-min) (point))
- (goto-char tutorial--point-before-chkeys)
- (setq tutorial--point-before-chkeys (point-marker)))
- (insert-file-contents (expand-file-name filename tutorial-directory))
- (let ((enable-local-variables :safe)
- (enable-local-eval nil)
- (enable-dir-local-variables nil)) ; bug#11127
- (hack-local-variables))
- (forward-line)
- (setq tutorial--point-before-chkeys (point-marker)))
-
- (tutorial--display-changes)
-
- ;; Clear message:
- (unless dont-ask-for-revert
- (message "") (sit-for 0))
-
-
- (if old-tut-file
- ;; Just move to old point in saved tutorial.
- (let ((old-point
- (if (> 0 old-tut-point)
- (- old-tut-point)
- (+ old-tut-point tutorial--point-after-chkeys))))
- (when (< old-point 1)
- (setq old-point 1))
- (goto-char old-point))
- ;; Delete the arch-tag line, so as not to confuse readers.
- (goto-char (point-max))
- (if (search-backward ";;; arch-tag: " nil t)
- (delete-region (point) (point-max)))
- (goto-char (point-min))
- (search-forward "\n<<")
- (beginning-of-line)
- ;; Convert the <<...>> line to the proper [...] line,
- ;; or just delete the <<...>> line if a [...] line follows.
- (cond ((save-excursion
- (forward-line 1)
- (looking-at-p "\\["))
- (delete-region (point) (progn (forward-line 1) (point))))
- ((looking-at "<<Blank lines inserted.*>>")
- (replace-match "[Middle of page left blank for didactic purposes. Text continues below]"))
- (t
- (looking-at "<<")
- (replace-match "[")
- (search-forward ">>")
- (replace-match "]")))
- (beginning-of-line)
- ;; FIXME: if the window is not tall, and especially if the
- ;; big red "NOTICE: The main purpose..." text has been
- ;; inserted at the start of the buffer, the "type C-v to
- ;; move to the next screen" might not be visible on the
- ;; first screen (n < 0). How will the novice know what to do?
- (let ((n (- (window-height)
- (count-lines (point-min) (point))
- 6)))
- (if (< n 8)
- (progn
- ;; For a short gap, we don't need the [...] line,
- ;; so delete it.
- (delete-region (point) (progn (end-of-line) (point)))
- (if (> n 0) (newline n)))
- ;; Some people get confused by the large gap.
- (newline (/ n 2))
-
- ;; Skip the [...] line (don't delete it).
- (forward-line 1)
- (newline (- n (/ n 2)))))
- (goto-char (point-min)))
- (setq-local tutorial--starting-point (point))
- (setq buffer-undo-list nil)
- (set-buffer-modified-p nil)))))
+ (let* ((lang (cond
+ (arg
+ (minibuffer-with-setup-hook #'minibuffer-completion-help
+ (read-language-name 'tutorial "Language: " "English")))
+ ((get-language-info current-language-environment 'tutorial)
+ current-language-environment)
+ (t "English")))
+ (filename (get-language-info lang 'tutorial))
+ (tut-buf-name filename)
+ (old-tut-buf (get-buffer tut-buf-name))
+ (old-tut-win (when old-tut-buf (get-buffer-window old-tut-buf t)))
+ (old-tut-is-ok (when old-tut-buf
+ (not (buffer-modified-p old-tut-buf))))
+ old-tut-file
+ (old-tut-point 1))
+ (setq tutorial--point-after-chkeys (point-min))
+ ;; Try to display the tutorial buffer before asking to revert it.
+ ;; If the tutorial buffer is shown in some window make sure it is
+ ;; selected and displayed:
+ (if old-tut-win
+ (raise-frame
+ (window-frame
+ (select-window (get-buffer-window old-tut-buf t))))
+ ;; Else, is there an old tutorial buffer? Then display it:
+ (when old-tut-buf
+ (switch-to-buffer old-tut-buf)))
+ ;; Use whole frame for tutorial
+ (delete-other-windows)
+ ;; If the tutorial buffer has been changed then ask if it should
+ ;; be reverted:
+ (when (and old-tut-buf
+ (not old-tut-is-ok))
+ (setq old-tut-is-ok
+ (if dont-ask-for-revert
+ nil
+ (not (y-or-n-p
+ "You have changed the Tutorial buffer. Revert it? ")))))
+ ;; (Re)build the tutorial buffer if it is not ok
+ (unless old-tut-is-ok
+ (switch-to-buffer (get-buffer-create tut-buf-name))
+ (setq tutorial--buffer (current-buffer))
+ ;; (unless old-tut-buf (text-mode))
+ (unless lang (error "Variable lang is nil"))
+ (setq tutorial--lang lang)
+ (setq old-tut-file (file-exists-p (tutorial--saved-file)))
+ (let ((inhibit-read-only t))
+ (erase-buffer))
+ (message "Preparing tutorial ...") (sit-for 0)
+
+ ;; Do not associate the tutorial buffer with a file. Instead use
+ ;; a hook to save it when the buffer is killed.
+ (setq buffer-auto-save-file-name nil)
+ (add-hook 'kill-buffer-hook 'tutorial--save-tutorial nil t)
+ (add-hook 'kill-emacs-query-functions 'tutorial--save-on-kill)
+
+ ;; Insert the tutorial. First offer to resume last tutorial
+ ;; editing session.
+ (when dont-ask-for-revert
+ (setq old-tut-file nil))
+ (when old-tut-file
+ (setq old-tut-file
+ (y-or-n-p "Resume your last saved tutorial? ")))
+ (if old-tut-file
+ (progn
+ (insert-file-contents (tutorial--saved-file))
+ (let ((enable-local-variables :safe)
+ (enable-local-eval nil)
+ (enable-dir-local-variables nil)) ; bug#11127
+ (hack-local-variables))
+ (goto-char (point-min))
+ (setq old-tut-point
+ (string-to-number
+ (buffer-substring-no-properties
+ (line-beginning-position) (line-end-position))))
+ (forward-line)
+ (setq tutorial--point-before-chkeys
+ (string-to-number
+ (buffer-substring-no-properties
+ (line-beginning-position) (line-end-position))))
+ (forward-line)
+ (delete-region (point-min) (point))
+ (goto-char tutorial--point-before-chkeys)
+ (setq tutorial--point-before-chkeys (point-marker)))
+ (insert-file-contents (expand-file-name filename tutorial-directory))
+ (let ((enable-local-variables :safe)
+ (enable-local-eval nil)
+ (enable-dir-local-variables nil)) ; bug#11127
+ (hack-local-variables))
+ (forward-line)
+ (setq tutorial--point-before-chkeys (point-marker)))
+
+ (tutorial--display-changes)
+
+ ;; Clear message:
+ (unless dont-ask-for-revert
+ (message "") (sit-for 0))
+
+
+ (if old-tut-file
+ ;; Just move to old point in saved tutorial.
+ (let ((old-point
+ (if (> 0 old-tut-point)
+ (- old-tut-point)
+ (+ old-tut-point tutorial--point-after-chkeys))))
+ (when (< old-point 1)
+ (setq old-point 1))
+ (goto-char old-point))
+ ;; Delete the arch-tag line, so as not to confuse readers.
+ (goto-char (point-max))
+ (if (search-backward ";;; arch-tag: " nil t)
+ (delete-region (point) (point-max)))
+ (goto-char (point-min))
+ (search-forward "\n<<")
+ (beginning-of-line)
+ ;; Convert the <<...>> line to the proper [...] line,
+ ;; or just delete the <<...>> line if a [...] line follows.
+ (cond ((save-excursion
+ (forward-line 1)
+ (looking-at-p "\\["))
+ (delete-region (point) (progn (forward-line 1) (point))))
+ ((looking-at "<<Blank lines inserted.*>>")
+ (replace-match "[Middle of page left blank for didactic purposes. Text continues below]"))
+ (t
+ (looking-at "<<")
+ (replace-match "[")
+ (search-forward ">>")
+ (replace-match "]")))
+ (beginning-of-line)
+ ;; FIXME: if the window is not tall, and especially if the
+ ;; big red "NOTICE: The main purpose..." text has been
+ ;; inserted at the start of the buffer, the "type C-v to
+ ;; move to the next screen" might not be visible on the
+ ;; first screen (n < 0). How will the novice know what to do?
+ (let ((n (- (window-height)
+ (count-lines (point-min) (point))
+ 6)))
+ (if (< n 8)
+ (progn
+ ;; For a short gap, we don't need the [...] line,
+ ;; so delete it.
+ (delete-region (point) (progn (end-of-line) (point)))
+ (if (> n 0) (newline n)))
+ ;; Some people get confused by the large gap.
+ (newline (/ n 2))
+
+ ;; Skip the [...] line (don't delete it).
+ (forward-line 1)
+ (newline (- n (/ n 2)))))
+ (goto-char (point-min)))
+ (setq-local tutorial--starting-point (point))
+ (setq buffer-undo-list nil)
+ (set-buffer-modified-p nil))))
;; Below is some attempt to handle language specific strings. These
+++ /dev/null
-;;; viper-tests.el --- tests for viper. -*- lexical-binding:t -*-
-
-;; Copyright (C) 2016-2025 Free Software Foundation, Inc.
-
-;; This file is part of GNU Emacs.
-
-;; GNU Emacs is free software: you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; GNU Emacs is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;;; Code:
-
-(require 'ert)
-(require 'ert-x)
-(require 'viper)
-
-(defun viper-test-undo-kmacro (kmacro)
- "In a clean viper buffer, run KMACRO and return `buffer-string'.
-
-This function makes as many attempts as possible to clean up
-after itself, although it will leave a buffer called
-*viper-test-buffer* if it fails (this is deliberate!)."
- (ert-with-temp-file viper-custom-file-name
- ;; viper loads this even with -q so make sure it's empty!
- :prefix "emacs-viper-tests" :suffix ".elc"
- (let (;; Viper just turns itself off during batch use.
- (noninteractive nil)
- ;; Switch off start up message or it will chew the key presses.
- (viper-inhibit-startup-message 't)
- ;; Select an expert-level for the same reason.
- (viper-expert-level 5)
- (before-buffer (current-buffer)))
- (unwind-protect
- (progn
- ;; viper-mode is essentially global, so set it here.
- (viper-mode)
- ;; We must switch to buffer because we are using a keyboard macro
- ;; which appears to not go to the current-buffer but what ever is
- ;; currently taking keyboard events. We use a named buffer because
- ;; then we can see what it in it if it all goes wrong.
- (switch-to-buffer
- (get-buffer-create
- "*viper-test-buffer*"))
- (erase-buffer)
- ;; The new buffer fails to enter vi state so set it.
- (viper-change-state-to-vi)
- ;; Run the macro.
- (execute-kbd-macro kmacro)
- (let ((rtn
- (buffer-substring-no-properties
- (point-min)
- (point-max))))
- ;; Kill the buffer iff the macro succeeds.
- (kill-buffer)
- rtn))
- ;; Switch everything off and restore the buffer.
- (toggle-viper-mode)
- (switch-to-buffer before-buffer)))))
-
-(ert-deftest viper-test-fix ()
- "Test that the viper kmacro fixture is working."
- (should
- (viper-test-undo-kmacro [])))
-
-(ert-deftest viper-test-undo-1 ()
- "Test for VI like undo behavior.
-
-Insert 1, then 2 on consecutive lines, followed by undo. This
-should leave just 1 in the buffer.
-
-Test for Bug #22295"
- (should
- (equal
- "1\n"
- (viper-test-undo-kmacro
- [
- ?a
- ?1
- escape
- ?o
- ?2
- escape
- ?u
- ]
- ))))
-
-(ert-deftest viper-test-undo-2 ()
- "Test for VI like undo behavior.
-
-Insert \"1 2 3 4 5\" then delete the 2, then the 4, and undo.
-Should restore the 4, but leave the 2 deleted.
-
-Test for Bug #22295"
- (should
- (equal
- "1 3 4 5\n"
- (viper-test-undo-kmacro
- [
- ?i
- ?1 ? ?2 ? ?3 ? ?4 ? ?5
- escape
- ?F ?2 ?d ?w
- ?w ?d ?w
- ?u
- ]))))
-
-(ert-deftest viper-test-undo-3 ()
- "Test for VI like undo behavior.
-
-Insert \"1 2 3 4 5 6\", delete the 2, then the 3 4 and 5.
-Should restore the 3 4 and 5 but not the 2.
-
-Test for Bug #22295"
- (should
- (equal
- "1 3 4 5 6\n"
- (viper-test-undo-kmacro
- [
- ;; Insert this lot.
- ?i ?1 ? ?2 ? ?3 ? ?4 ? ?5 ? ?6
- escape
- ;; Start of line.
- ?0
- ;; Move to 2, delete
- ?w ?d ?w
- ;; Delete 3 4 5
- ?. ?. ?.
- ;; Undo del 5, then
- ?u ?. ?.
- ]))))
-
-
-(ert-deftest viper-test-undo-4()
- (should
- (equal
- ""
- (viper-test-undo-kmacro
- [
- ?i ?1 escape
- ?o ?2 escape
- ?o ?3 escape
- ?u ?. ?.
- ])
- )))
-
-;;; viper-tests.el ends here