;; A token has a type, \(command, address, end-mark\), and a value
(defun vip-get-ex-token ()
(save-window-excursion
+ (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name))
(set-buffer vip-ex-work-buf)
(skip-chars-forward " \t|")
(cond ((looking-at "#")
"!*")))
(save-window-excursion ;; put cursor at the end of the Ex working buffer
+ (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name))
(set-buffer vip-ex-work-buf)
(goto-char (point-max)))
(cond ((vip-looking-back quit-regex1) (exit-minibuffer))
map)))
(save-window-excursion
;; just a precaution
- (or (vip-buffer-live-p vip-ex-work-buf)
- (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)))
+ (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name))
(set-buffer vip-ex-work-buf)
(delete-region (point-min) (point-max))
(insert com-str "\n")
(t
(vip-execute-ex-command)
(save-window-excursion
+ (setq vip-ex-work-buf
+ (get-buffer-create vip-ex-work-buf-name))
(set-buffer vip-ex-work-buf)
(skip-chars-forward " \t")
(cond ((looking-at "|")
;; Get a regular expression and set `ex-variant', if found
(defun vip-get-ex-pat ()
(save-window-excursion
+ (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name))
(set-buffer vip-ex-work-buf)
(skip-chars-forward " \t")
(if (looking-at "!")
;; get an ex command
(defun vip-get-ex-command ()
(save-window-excursion
+ (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name))
(set-buffer vip-ex-work-buf)
(if (looking-at "/") (forward-char 1))
(skip-chars-forward " \t")
;; Get an Ex option g or c
(defun vip-get-ex-opt-gc (c)
(save-window-excursion
+ (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name))
(set-buffer vip-ex-work-buf)
(if (looking-at (format "%c" c)) (forward-char 1))
(skip-chars-forward " \t")
(setq ex-count nil)
(setq ex-flag nil)
(save-window-excursion
+ (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name))
(set-buffer vip-ex-work-buf)
(skip-chars-forward " \t")
(if (looking-at "[a-zA-Z]")
ex-count nil
ex-flag nil)
(save-window-excursion
+ (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name))
(set-buffer vip-ex-work-buf)
(skip-chars-forward " \t")
(if (looking-at "!")
ex-cmdfile nil)
(save-excursion
(save-window-excursion
+ (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name))
(set-buffer vip-ex-work-buf)
(skip-chars-forward " \t")
(if (looking-at "!")
(if (null (setq file (get-file-buffer ex-file)))
(progn
(ex-find-file ex-file)
- (vip-change-state-to-vi)
+ (or (eq major-mode 'dired-mode)
+ (vip-change-state-to-vi))
(goto-char (point-min)))
(switch-to-buffer file))
(if ex-offset
(progn
(save-window-excursion
+ (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name))
(set-buffer vip-ex-work-buf)
(delete-region (point-min) (point-max))
(insert ex-offset "\n")
(beginning-of-line)))
(ex-fixup-history vip-last-ex-prompt ex-file))
-;; Splits the string FILESPEC into substrings separated by newlines.
+;; Find-file FILESPEC if it appears to specify a single file.
+;; Otherwise, assume that FILES{EC is a wildcard.
+;; In this case, split it into substrings separated by newlines.
;; Each line is assumed to be a file name. find-file's each file thus obtained.
(defun ex-find-file (filespec)
- (let ((nonstandard-filename-chars "[^a-zA-Z0-9_.-/,\\]"))
- (if (string-match nonstandard-filename-chars filespec)
- (funcall ex-nontrivial-find-file-function filespec)
- (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)
+ (funcall ex-nontrivial-find-file-function filespec))
+ (t (find-file filespec)))
))
(forward-line -1)
(end-of-line)))))
(save-window-excursion
+ (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name))
(set-buffer vip-ex-work-buf)
(setq com-str (buffer-substring (1+ (point)) (1- (point-max)))))
(while marks
(setq ex-addresses
(cons (point) nil)))
(save-window-excursion
+ (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name))
(set-buffer vip-ex-work-buf)
(skip-chars-forward " \t")
(if (looking-at "[a-z]")
(defun ex-quit ()
;; skip "!", if it is q!. In Viper q!, w!, etc., behave as q, w, etc.
(save-excursion
+ (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name))
(set-buffer vip-ex-work-buf)
(if (looking-at "!") (forward-char 1)))
(if (< vip-expert-level 3)
;; special meaning
(defun ex-get-inline-cmd-args (regex-forw &optional chars-back replace-str)
(save-excursion
+ (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name))
(set-buffer vip-ex-work-buf)
(goto-char (point-min))
(re-search-forward regex-forw nil t)
(defun ex-tag ()
(let (tag)
(save-window-excursion
+ (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name))
(set-buffer vip-ex-work-buf)
(skip-chars-forward " \t")
(set-mark (point))
(defun ex-command ()
(let (command)
(save-window-excursion
+ (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name))
(set-buffer vip-ex-work-buf)
(skip-chars-forward " \t")
(setq command (buffer-substring (point) (point-max)))
;;; Variables
+(defvar vip-toggle-key "\C-z"
+ "The key used to change states from emacs to Vi and back.
+In insert mode, this key also functions as Meta.
+Must be set in .vip file or prior to loading Viper.
+This setting cannot be changed interactively.")
+
+(defvar vip-ESC-key "\e"
+ "Key used to ESC.
+Must be set in .vip file or prior to loading Viper.
+This setting cannot be changed interactively.")
+
+
;;; Keymaps
;; Keymaps for vital things like \e and C-z.
(if vip-xemacs-p [(shift tab)] [S-tab]) 'vip-insert-tab)
(define-key vip-insert-basic-map "\C-v" 'quoted-insert)
(define-key vip-insert-basic-map "\C-?" 'vip-del-backward-char-in-insert)
+(define-key vip-insert-basic-map "\C-\\" 'vip-alternate-Meta-key)
+(define-key vip-insert-basic-map vip-toggle-key 'vip-escape-to-vi)
(define-key vip-insert-basic-map "\C-c\M-p"
'vip-insert-prev-from-insertion-ring)
(define-key vip-insert-basic-map "\C-c\M-n"
(define-key vip-vi-basic-map "\C-^"
(function (lambda () (interactive) (vip-ex "e#"))))
-(define-key vip-vi-basic-map "\C-b" 'vip-scroll-back)
+(define-key vip-vi-basic-map "\C-b" 'vip-scroll-screen-back)
(define-key vip-vi-basic-map "\C-d" 'vip-scroll-up)
(define-key vip-vi-basic-map "\C-e" 'vip-scroll-up-one)
-(define-key vip-vi-basic-map "\C-f" 'vip-scroll)
+(define-key vip-vi-basic-map "\C-f" 'vip-scroll-screen)
(define-key vip-vi-basic-map "\C-m" 'vip-next-line-at-bol)
(define-key vip-vi-basic-map "\C-u" 'vip-scroll-down)
(define-key vip-vi-basic-map "\C-y" 'vip-scroll-down-one)
(define-key vip-vi-basic-map "\C-s" 'vip-isearch-forward)
(define-key vip-vi-basic-map "\C-r" 'vip-isearch-backward)
-;(define-key vip-vi-basic-map "\C-\\" 'universal-argument)
(define-key vip-vi-basic-map "\C-c/" 'vip-toggle-search-style)
(define-key vip-vi-basic-map "\C-cg" 'vip-info-on-file)
(define-key vip-vi-basic-map "\\" 'vip-escape-to-emacs)
(define-key vip-vi-basic-map "[" 'vip-brac-function)
(define-key vip-vi-basic-map "]" 'vip-ket-function)
-(define-key vip-vi-basic-map "_" 'vip-alternate-ESC)
+(define-key vip-vi-basic-map "\C-\\" 'vip-alternate-Meta-key)
(define-key vip-vi-basic-map "^" 'vip-bol-and-skip-white)
(define-key vip-vi-basic-map "`" 'vip-goto-mark)
(define-key vip-vi-basic-map "}" 'vip-forward-paragraph)
(define-key vip-vi-basic-map "~" 'vip-toggle-case)
(define-key vip-vi-basic-map "\C-?" 'vip-backward-char)
+(define-key vip-vi-basic-map "_" 'vip-nil)
;;; Escape from Emacs to Vi for one command
-(global-set-key "\M-\C-z" 'vip-escape-to-vi) ;; in emacs-state
+(global-set-key "\C-c\\" 'vip-escape-to-vi) ; everywhere
;;; This is vip-vi-diehard-map. Used when vip-vi-diehard-minor-mode is on.
(define-key vip-vi-diehard-map "\C-v" 'vip-nil)
(define-key vip-vi-diehard-map "\C-w" 'vip-nil)
(define-key vip-vi-diehard-map "@" 'vip-nil)
+(define-key vip-vi-diehard-map "_" 'vip-nil)
(define-key vip-vi-diehard-map "*" 'vip-nil)
(define-key vip-vi-diehard-map "#" 'vip-nil)
(define-key vip-vi-diehard-map "\C-_" 'vip-nil)
-(define-key vip-vi-diehard-map "\C-]" 'vip-nil);; This is actually tags.
+(define-key vip-vi-diehard-map "\C-]" 'vip-nil) ; This is actually tags.
\f
;;; Minibuffer keymap
(define-key ex-read-filename-map " " 'vip-complete-filename-or-exit)
(define-key ex-read-filename-map "!" 'vip-handle-!)
+;; Some other maps
+(defvar vip-slash-and-colon-map (make-sparse-keymap)
+ "This map redefines `/' and `:' to behave as in Vi.
+Useful in some modes, such as Gnus, MH, etc.")
+(define-key vip-slash-and-colon-map ":" 'vip-ex)
+(define-key vip-slash-and-colon-map "/" 'vip-search-forward)
+
+(defvar vip-comint-mode-modifier-map (make-sparse-keymap)
+ "This map modifies comint mode.")
+(define-key vip-comint-mode-modifier-map "\C-m" 'comint-send-input)
+(define-key vip-comint-mode-modifier-map "\C-d" 'comint-delchar-or-maybe-eof)
+
+(defvar vip-dired-modifier-map (make-sparse-keymap)
+ "This map modifies Dired behavior.")
+(define-key vip-dired-modifier-map ":" 'vip-ex)
+
-
\f
;;; Code
(defun vip-zap-local-keys ()
"Unconditionally reset Viper vip-*-local-user-map's.
Rarely useful, but if u made a mistake by switching to a mode that adds
-undesirable local keys, e.g., comint-mode, then this function can return
-you to sanity."
+undesirable local keys, e.g., comint-mode, then this function can restore
+sanity."
(interactive)
(setq vip-vi-local-user-map (make-sparse-keymap)
vip-need-new-vi-local-map nil
(cdr (assoc 'cursor-color (frame-parameters)))
(color-instance-name (frame-property (selected-frame) 'cursor-color))))
+(defun vip-set-face-pixmap (face pixmap)
+ "Set face pixmap on a monochrome display."
+ (if (and (vip-window-display-p) (not (vip-color-display-p)))
+ (condition-case nil
+ (set-face-background-pixmap face pixmap)
+ (error
+ (message "Pixmap not found for %S: %s" (face-name face) pixmap)
+ (sit-for 1)))))
+
;; OS/2
(cond ((eq (vip-device-type) 'pm)
;; using cond in anticipation of further additions
(cond (ex-unix-type-shell-options)
))
- (command (cond (vip-ms-style-os-p (format "\"ls -1 %s\"" filespec))
- (t (format "ls -1 %s" filespec))))
- file-list)
+ (command (cond (vip-ms-style-os-p (format "\"ls -1 -d %s\"" filespec))
+ (t (format "ls -1 -d %s" filespec))))
+ file-list status)
(save-excursion
- (set-buffer (setq tmp-buf (get-buffer-create vip-ex-tmp-buf-name)))
+ (set-buffer (get-buffer-create vip-ex-tmp-buf-name))
(erase-buffer)
(setq status
(if gshell-options
`ex-nontrivial-find-file-function'. If this doesn't work, the user may have
to write a custom function, similar to `vip-ex-nontrivial-find-file-unix'."
(save-excursion
- (set-buffer (setq tmp-buf (get-buffer-create vip-ex-tmp-buf-name)))
+ (set-buffer (get-buffer-create vip-ex-tmp-buf-name))
(erase-buffer)
(insert filespec)
(goto-char (point-min))
;; convert MS-DOS wildcards to regexp
(defun vip-wildcard-to-regexp (wcard)
(save-excursion
- (set-buffer (setq tmp-buf (get-buffer-create vip-ex-tmp-buf-name)))
+ (set-buffer (get-buffer-create vip-ex-tmp-buf-name))
(erase-buffer)
(insert wcard)
(goto-char (point-min))
(sit-for 2)
(vip-overlay-put vip-search-overlay 'face nil))))
+
;; Replace state
(defsubst vip-move-replace-overlay (beg end)
Usually contains ` ', linefeed, TAB or formfeed.")
(defun vip-update-alphanumeric-class ()
- "Set the syntactic class of Viper alphanumeric symbols according to
-the variable `vip-ALPHA-char-class'. Should be called in order for changes to
-`vip-ALPHA-char-class' to take effect."
+ "Set the syntax class of Viper alphanumerals according to `vip-syntax-preference'.
+Must be called in order for changes to `vip-syntax-preference' to take effect."
(interactive)
(setq-default
vip-ALPHA-char-class
(defvar vip-always t
"t means, arrange that vi-state will be a default.")
-(defvar vip-custom-file-name (cond (vip-vms-os-p "sys$login:.vip")
- ((memq system-type '(emx ms-dos))
- "/_vip")
- ((memq system-type '(windows-nt windows-95))
- "~/_vip")
- (t ; Unix
- "~/.vip"))
+(defvar vip-custom-file-name (convert-standard-filename "~/.vip")
"Viper customisation file.
This variable must be set _before_ loading Viper.")