;;; viper-init.el --- some common definitions for Viper
-;; Copyright (C) 1997, 98, 99, 2000, 01, 02 Free Software Foundation, Inc.
+;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+;; 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; 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 2, or (at your option)
-;; any later version.
+;; 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
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
-(provide 'viper-init)
-
;; compiler pacifier
(defvar mark-even-if-inactive)
(defvar quail-mode)
(defvar default-input-method)
(defvar describe-current-input-method-function)
(defvar bar-cursor)
-(defvar default-cursor-type)
(defvar cursor-type)
;; end pacifier
(interactive)
(message "Viper version is %s" viper-version))
-;; Is it XEmacs?
-(defconst viper-xemacs-p (string-match "XEmacs" emacs-version))
-;; Is it Emacs?
-(defconst viper-emacs-p (not viper-xemacs-p))
;; Tell whether we are running as a window application or on a TTY
-;; This is used to avoid compilation warnings. When emacs/xemacs forms can
-;; generate compile time warnings, we use this macro.
-;; In this case, the macro will expand into the form that is appropriate to the
-;; compiler at hand.
-;; Suggested by rms.
-(defmacro viper-cond-compile-for-xemacs-or-emacs (xemacs-form emacs-form)
- (if (string-match "XEmacs" emacs-version)
- xemacs-form emacs-form))
-
-
(defsubst viper-device-type ()
- (viper-cond-compile-for-xemacs-or-emacs
- (device-type (selected-device))
- window-system
- ))
+ (if (featurep 'xemacs)
+ (device-type (selected-device))
+ window-system))
+
+(defun viper-color-display-p ()
+ (condition-case nil
+ (if (featurep 'xemacs)
+ (eq (device-class (selected-device)) 'color)
+ (display-color-p))
+ (error nil)))
;; in XEmacs: device-type is tty on tty and stream in batch.
(defun viper-window-display-p ()
:type 'boolean
:tag "Is it Microsoft-made OS?"
:group 'viper-misc)
-(defcustom viper-vms-os-p (memq system-type '(vax-vms axp-vms))
- "Tells if Emacs is running under VMS."
+
+(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
- :tag "Is it VMS?"
:group 'viper-misc)
(defcustom viper-force-faces nil
(defun viper-has-face-support-p ()
(cond ((viper-window-display-p))
(viper-force-faces)
- (viper-emacs-p (memq (viper-device-type) '(nil pc)))
- (viper-xemacs-p (memq (viper-device-type) '(tty pc)))))
+ ((viper-color-display-p))
+ ((featurep 'emacs) (memq (viper-device-type) '(pc)))
+ ((featurep 'xemacs) (memq (viper-device-type) '(tty pc)))))
\f
;;; Macros
;; turn off special input methods in vi-state
(if (eq viper-current-state 'vi-state)
(viper-set-input-method nil))
- (if (memq viper-current-state '(vi-state insert-state replace-state))
+ (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"
(if (null viper-mule-hook-flag)
()
(setq viper-special-input-method nil)
- (if (memq viper-current-state '(vi-state insert-state replace-state))
+ (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"
"")))))
(defun viper-inactivate-input-method ()
- (cond ((and viper-emacs-p (fboundp 'inactivate-input-method))
+ (cond ((and (featurep 'emacs) (fboundp 'inactivate-input-method))
(inactivate-input-method))
- ((and viper-xemacs-p (boundp 'current-input-method))
- ;; XEmacs had broken quil-mode for some time, so we are working around
+ ((and (featurep 'xemacs) (boundp 'current-input-method))
+ ;; XEmacs had broken quail-mode for some time, so we are working around
;; it here
(setq quail-mode nil)
(if (featurep 'quail)
(force-mode-line-update))
))
(defun viper-activate-input-method ()
- (cond ((and viper-emacs-p (fboundp 'activate-input-method))
+ (cond ((and (featurep 'emacs) (fboundp 'activate-input-method))
(activate-input-method default-input-method))
- ((and viper-xemacs-p (fboundp 'quail-mode))
- (quail-mode 1))))
+ ((featurep 'xemacs)
+ (if (fboundp 'quail-mode) (quail-mode 1)))))
;; 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 inactivate viper mule hooks
+ (let (viper-mule-hook-flag) ; temporarily deactivate viper mule hooks
(cond ((and arg (> (prefix-numeric-value arg) 0) default-input-method)
;; activate input method
(viper-activate-input-method))
"*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 'string
+ :group 'viper)
+
;; internal var, used to remember the default cursor color of emacs frames
(defvar viper-vi-state-cursor-color nil)
+;; Frame-local variables are obsolete from Emacs 22.2 onwards, so we
+;; do it by hand with viper-frame-value (qv).
+(when (and (featurep 'xemacs)
+ (fboundp 'make-variable-frame-local))
+ (make-variable-frame-local 'viper-replace-overlay-cursor-color)
+ (make-variable-frame-local 'viper-insert-state-cursor-color)
+ (make-variable-frame-local 'viper-emacs-state-cursor-color)
+ (make-variable-frame-local 'viper-vi-state-cursor-color))
+
(viper-deflocalvar viper-replace-overlay nil "")
(put 'viper-replace-overlay 'permanent-local t)
:group 'viper)
(defcustom viper-use-replace-region-delimiters
(or (not (viper-has-face-support-p))
- (and viper-xemacs-p (eq (viper-device-type) 'tty)))
+ (and (featurep 'xemacs) (eq (viper-device-type) 'tty)))
"*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."
:group 'viper)
;; XEmacs requires glyphs
-(viper-cond-compile-for-xemacs-or-emacs
- (progn ; xemacs
- (or (glyphp viper-replace-region-end-delimiter)
- (setq viper-replace-region-end-delimiter
- (make-glyph viper-replace-region-end-delimiter)))
- (or (glyphp viper-replace-region-start-delimiter)
- (setq viper-replace-region-start-delimiter
- (make-glyph viper-replace-region-start-delimiter)))
- )
- nil ; emacs
- )
-
-
+(when (featurep 'xemacs)
+ (or (glyphp viper-replace-region-end-delimiter)
+ (setq viper-replace-region-end-delimiter
+ (make-glyph viper-replace-region-end-delimiter)))
+ (or (glyphp viper-replace-region-start-delimiter)
+ (setq viper-replace-region-start-delimiter
+ (make-glyph viper-replace-region-start-delimiter))))
;; These are local marker that must be initialized to nil and moved with
;; `viper-move-marker-locally'
:type 'integer
:group 'viper-misc)
-(defcustom viper-ESC-keyseq-timeout (if (viper-window-display-p)
- 0 viper-fast-keyseq-timeout)
- "*Key sequence beginning with ESC and separated by no more than this many milliseconds is 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."
- :type 'integer
- :group 'viper-misc)
-
-(defcustom viper-translate-all-ESC-keysequences (not (viper-window-display-p))
- "Allow translation of all key sequences into commands.
-Normally, Viper lets Emacs translate only those ESC key sequences that are
-defined in the low-level key-translation-map or function-key-map, such as those
-emitted by the arrow and function keys. Other sequences, e.g., \\e/, are
-treated as ESC command followed by a `/'. This is done for people who type fast
-and tend to hit other characters right after they hit ESC. Other people like
-Emacs to translate ESC sequences all the time.
-The default is to translate all sequences only when using a dumb terminal.
-This permits you to use ESC as a meta key in insert mode."
- :type 'boolean
- :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
:type '(choice (const nil) character)
:group 'viper-search)
-(defcustom viper-search-wrap-around-t t
+(defcustom viper-search-wrap-around t
"*If t, search wraps around."
:type 'boolean
:tag "Search Wraps Around"
\f
;;; Face-saving tricks
-(defun viper-hide-face (face)
- (if (and (viper-has-face-support-p) viper-emacs-p)
- (add-to-list 'facemenu-unlisted-faces face)))
-
-
(defgroup viper-highlighting nil
"Hilighting of replace region, search pattern, minibuffer, etc."
:prefix "viper-"
:group 'viper)
-(defface viper-search-face
+(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
+(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-face'
+to customize the actual face object `viper-search'
this variable represents.")
-(viper-hide-face 'viper-search-face)
-
-(defface viper-replace-overlay-face
+(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
+(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-face'
+to customize the actual face object `viper-replace-overlay'
this variable represents.")
-(viper-hide-face 'viper-replace-overlay-face)
-
-(defface viper-minibuffer-emacs-face
+(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
+(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-face'
+to customize the actual face object `viper-minibuffer-emacs'
this variable represents.")
-(viper-hide-face 'viper-minibuffer-emacs-face)
-
-(defface viper-minibuffer-insert-face
+(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
+(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-face'
+to customize the actual face object `viper-minibuffer-insert'
this variable represents.")
-(viper-hide-face 'viper-minibuffer-insert-face)
-
-(defface viper-minibuffer-vi-face
+(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
+(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-face'
+to customize the actual face object `viper-minibuffer-vi'
this variable represents.")
-(viper-hide-face 'viper-minibuffer-vi-face)
;; the current face to be used in the minibuffer
(viper-deflocalvar
(defun viper-restore-cursor-type ()
(condition-case nil
- (if viper-xemacs-p
- (setq bar-cursor nil)
- (setq cursor-type default-cursor-type))
+ (if (featurep 'xemacs)
+ (set (make-local-variable 'bar-cursor) nil)
+ (setq cursor-type (default-value 'cursor-type)))
(error nil)))
(defun viper-set-insert-cursor-type ()
- (if viper-xemacs-p
- (setq bar-cursor 2)
+ (if (featurep 'xemacs)
+ (set (make-local-variable 'bar-cursor) 2)
(setq cursor-type '(bar . 2))))
+(defun viper-ESC-keyseq-timeout ()
+ "*Key sequence beginning with ESC and separated by no more than this many milliseconds is 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)
+
-;;; Local Variables:
-;;; eval: (put 'viper-deflocalvar 'lisp-indent-hook 'defun)
-;;; End:
+;; Local Variables:
+;; eval: (put 'viper-deflocalvar 'lisp-indent-hook 'defun)
+;; End:
-;;; arch-tag: 4efa2416-1fcb-4690-be10-1a2a0248d250
+;; arch-tag: 4efa2416-1fcb-4690-be10-1a2a0248d250
;;; viper-init.el ends here