aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorMichael Kifer1995-08-20 04:32:54 +0000
committerMichael Kifer1995-08-20 04:32:54 +0000
commitd695b318397389a7ecb34c91e626d5462e170182 (patch)
tree010df0bdfdedc7331234ce9bcaa2905b878b1bce /lisp
parentdd7c19d4920312e99cacc05555cd37cf38356554 (diff)
downloademacs-d695b318397389a7ecb34c91e626d5462e170182.tar.gz
emacs-d695b318397389a7ecb34c91e626d5462e170182.zip
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
(vip-read-string-with-history): minibuffer-setup-hook no longer waits for the user to type, if there are unread events. Harnessed view-minor-mode. Added (vip-leave-region-active) to all simple movement commands.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/emulation/viper.el101
1 files changed, 70 insertions, 31 deletions
diff --git a/lisp/emulation/viper.el b/lisp/emulation/viper.el
index 4787149a129..bb1ed4b90b6 100644
--- a/lisp/emulation/viper.el
+++ b/lisp/emulation/viper.el
@@ -6,7 +6,7 @@
6;; Keywords: emulations 6;; Keywords: emulations
7;; Author: Michael Kifer <kifer@cs.sunysb.edu> 7;; Author: Michael Kifer <kifer@cs.sunysb.edu>
8 8
9(defconst viper-version "2.80 of July 7, 1995" 9(defconst viper-version "2.81 of August 7, 1995"
10 "The current version of Viper") 10 "The current version of Viper")
11 11
12;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. 12;; Copyright (C) 1994, 1995 Free Software Foundation, Inc.
@@ -114,7 +114,7 @@
114;; default. 114;; default.
115;; However, some modes do not appear in the right mode in the beginning, 115;; However, some modes do not appear in the right mode in the beginning,
116;; usually because they neglect to follow Emacs conventions (e.g., they don't 116;; usually because they neglect to follow Emacs conventions (e.g., they don't
117;; use (kill-all-local-variables) when they start). Some major modes 117;; use kill-all-local-variables when they start). Some major modes
118;; may fail to come up in emacs-state if they call hooks, such as 118;; may fail to come up in emacs-state if they call hooks, such as
119;; text-hook, for no good reason. 119;; text-hook, for no good reason.
120;; 120;;
@@ -1278,7 +1278,7 @@ This startup message appears whenever you load Viper, unless you type `y' now."
1278 ) 1278 )
1279 1279
1280;; This also takes care of the annoying incomplete lines in files. 1280;; This also takes care of the annoying incomplete lines in files.
1281;; Also, this fixed 'undo' to work vi-style for complex commands. 1281;; Also, this fixes `undo' to work vi-style for complex commands.
1282(defun vip-change-state-to-vi () 1282(defun vip-change-state-to-vi ()
1283 "Change Viper state to Vi." 1283 "Change Viper state to Vi."
1284 (interactive) 1284 (interactive)
@@ -1298,8 +1298,11 @@ This startup message appears whenever you load Viper, unless you type `y' now."
1298 (vip-add-newline-at-eob-if-necessary) 1298 (vip-add-newline-at-eob-if-necessary)
1299 (if vip-undo-needs-adjustment (vip-adjust-undo)) 1299 (if vip-undo-needs-adjustment (vip-adjust-undo))
1300 (vip-change-state 'vi-state) 1300 (vip-change-state 'vi-state)
1301 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode)) 1301
1302 (iso-accents-mode -1)) ; turn off iso accents 1302 ;; always turn off iso-accents-mode, or else we won't be able to use the
1303 ;; keys `,',^ in Vi state, as they will do accents instead of Vi actions.
1304 (if (and (boundp 'iso-accents-mode) iso-accents-mode)
1305 (iso-accents-mode -1))
1303 1306
1304 ;; Protection against user errors in hooks 1307 ;; Protection against user errors in hooks
1305 (condition-case conds 1308 (condition-case conds
@@ -1571,7 +1574,7 @@ behaves as in Emacs, any number of multiple escapes is allowed."
1571 1574
1572 1575
1573(defadvice read-key-sequence (around vip-read-keyseq-ad activate) 1576(defadvice read-key-sequence (around vip-read-keyseq-ad activate)
1574 "Harness to work for Viper. This advice is harmless---don't panic!" 1577 "Harness to work for Viper. This advice is harmless---don't worry!"
1575 (let (inhibit-quit event keyseq) 1578 (let (inhibit-quit event keyseq)
1576 (setq keyseq ad-do-it) 1579 (setq keyseq ad-do-it)
1577 (setq event (if vip-xemacs-p 1580 (setq event (if vip-xemacs-p
@@ -1733,6 +1736,7 @@ behaves as in Emacs, any number of multiple escapes is allowed."
1733(defun vip-digit-argument (arg) 1736(defun vip-digit-argument (arg)
1734 "Begin numeric argument for the next command." 1737 "Begin numeric argument for the next command."
1735 (interactive "P") 1738 (interactive "P")
1739 (vip-leave-region-active)
1736 (vip-prefix-arg-value last-command-char 1740 (vip-prefix-arg-value last-command-char
1737 (if (consp arg) (cdr arg) nil))) 1741 (if (consp arg) (cdr arg) nil)))
1738 1742
@@ -2484,7 +2488,9 @@ Undo previous insertion and inserts new."
2484 '(lambda () 2488 '(lambda ()
2485 (if (stringp initial) 2489 (if (stringp initial)
2486 (progn 2490 (progn
2487 (sit-for 840) 2491 ;; don't wait if we have unread events
2492 (or unread-command-events
2493 (sit-for 840))
2488 (erase-buffer) 2494 (erase-buffer)
2489 (insert initial))) 2495 (insert initial)))
2490 (vip-minibuffer-setup-sentinel))) 2496 (vip-minibuffer-setup-sentinel)))
@@ -3028,6 +3034,7 @@ These keys are ESC, RET, and LineFeed"
3028 "Move point right ARG characters (left if ARG negative). 3034 "Move point right ARG characters (left if ARG negative).
3029On reaching end of line, stop and signal error." 3035On reaching end of line, stop and signal error."
3030 (interactive "P") 3036 (interactive "P")
3037 (vip-leave-region-active)
3031 (let ((val (vip-p-val arg)) 3038 (let ((val (vip-p-val arg))
3032 (com (vip-getcom arg))) 3039 (com (vip-getcom arg)))
3033 (if com (vip-move-marker-locally 'vip-com-point (point))) 3040 (if com (vip-move-marker-locally 'vip-com-point (point)))
@@ -3049,6 +3056,7 @@ On reaching end of line, stop and signal error."
3049 "Move point left ARG characters (right if ARG negative). 3056 "Move point left ARG characters (right if ARG negative).
3050On reaching beginning of line, stop and signal error." 3057On reaching beginning of line, stop and signal error."
3051 (interactive "P") 3058 (interactive "P")
3059 (vip-leave-region-active)
3052 (let ((val (vip-p-val arg)) 3060 (let ((val (vip-p-val arg))
3053 (com (vip-getcom arg))) 3061 (com (vip-getcom arg)))
3054 (if com (vip-move-marker-locally 'vip-com-point (point))) 3062 (if com (vip-move-marker-locally 'vip-com-point (point)))
@@ -3142,6 +3150,7 @@ On reaching beginning of line, stop and signal error."
3142(defun vip-forward-word (arg) 3150(defun vip-forward-word (arg)
3143 "Forward word." 3151 "Forward word."
3144 (interactive "P") 3152 (interactive "P")
3153 (vip-leave-region-active)
3145 (let ((val (vip-p-val arg)) 3154 (let ((val (vip-p-val arg))
3146 (com (vip-getcom arg))) 3155 (com (vip-getcom arg)))
3147 (if com (vip-move-marker-locally 'vip-com-point (point))) 3156 (if com (vip-move-marker-locally 'vip-com-point (point)))
@@ -3160,6 +3169,7 @@ On reaching beginning of line, stop and signal error."
3160(defun vip-forward-Word (arg) 3169(defun vip-forward-Word (arg)
3161 "Forward word delimited by white characters." 3170 "Forward word delimited by white characters."
3162 (interactive "P") 3171 (interactive "P")
3172 (vip-leave-region-active)
3163 (let ((val (vip-p-val arg)) 3173 (let ((val (vip-p-val arg))
3164 (com (vip-getcom arg))) 3174 (com (vip-getcom arg)))
3165 (if com (vip-move-marker-locally 'vip-com-point (point))) 3175 (if com (vip-move-marker-locally 'vip-com-point (point)))
@@ -3233,6 +3243,7 @@ On reaching beginning of line, stop and signal error."
3233(defun vip-end-of-word (arg &optional careful) 3243(defun vip-end-of-word (arg &optional careful)
3234 "Move point to end of current word." 3244 "Move point to end of current word."
3235 (interactive "P") 3245 (interactive "P")
3246 (vip-leave-region-active)
3236 (let ((val (vip-p-val arg)) 3247 (let ((val (vip-p-val arg))
3237 (com (vip-getcom arg))) 3248 (com (vip-getcom arg)))
3238 (if com (vip-move-marker-locally 'vip-com-point (point))) 3249 (if com (vip-move-marker-locally 'vip-com-point (point)))
@@ -3245,6 +3256,7 @@ On reaching beginning of line, stop and signal error."
3245(defun vip-end-of-Word (arg) 3256(defun vip-end-of-Word (arg)
3246 "Forward to end of word delimited by white character." 3257 "Forward to end of word delimited by white character."
3247 (interactive "P") 3258 (interactive "P")
3259 (vip-leave-region-active)
3248 (let ((val (vip-p-val arg)) 3260 (let ((val (vip-p-val arg))
3249 (com (vip-getcom arg))) 3261 (com (vip-getcom arg)))
3250 (if com (vip-move-marker-locally 'vip-com-point (point))) 3262 (if com (vip-move-marker-locally 'vip-com-point (point)))
@@ -3282,6 +3294,7 @@ On reaching beginning of line, stop and signal error."
3282(defun vip-backward-word (arg) 3294(defun vip-backward-word (arg)
3283 "Backward word." 3295 "Backward word."
3284 (interactive "P") 3296 (interactive "P")
3297 (vip-leave-region-active)
3285 (let ((val (vip-p-val arg)) 3298 (let ((val (vip-p-val arg))
3286 (com (vip-getcom arg))) 3299 (com (vip-getcom arg)))
3287 (if com 3300 (if com
@@ -3296,6 +3309,7 @@ On reaching beginning of line, stop and signal error."
3296(defun vip-backward-Word (arg) 3309(defun vip-backward-Word (arg)
3297 "Backward word delimited by white character." 3310 "Backward word delimited by white character."
3298 (interactive "P") 3311 (interactive "P")
3312 (vip-leave-region-active)
3299 (let ((val (vip-p-val arg)) 3313 (let ((val (vip-p-val arg))
3300 (com (vip-getcom arg))) 3314 (com (vip-getcom arg)))
3301 (if com 3315 (if com
@@ -3317,6 +3331,7 @@ On reaching beginning of line, stop and signal error."
3317(defun vip-beginning-of-line (arg) 3331(defun vip-beginning-of-line (arg)
3318 "Go to beginning of line." 3332 "Go to beginning of line."
3319 (interactive "P") 3333 (interactive "P")
3334 (vip-leave-region-active)
3320 (let ((val (vip-p-val arg)) 3335 (let ((val (vip-p-val arg))
3321 (com (vip-getcom arg))) 3336 (com (vip-getcom arg)))
3322 (if com (vip-move-marker-locally 'vip-com-point (point))) 3337 (if com (vip-move-marker-locally 'vip-com-point (point)))
@@ -3326,6 +3341,7 @@ On reaching beginning of line, stop and signal error."
3326(defun vip-bol-and-skip-white (arg) 3341(defun vip-bol-and-skip-white (arg)
3327 "Beginning of line at first non-white character." 3342 "Beginning of line at first non-white character."
3328 (interactive "P") 3343 (interactive "P")
3344 (vip-leave-region-active)
3329 (let ((val (vip-p-val arg)) 3345 (let ((val (vip-p-val arg))
3330 (com (vip-getcom arg))) 3346 (com (vip-getcom arg)))
3331 (if com (vip-move-marker-locally 'vip-com-point (point))) 3347 (if com (vip-move-marker-locally 'vip-com-point (point)))
@@ -3335,6 +3351,7 @@ On reaching beginning of line, stop and signal error."
3335(defun vip-goto-eol (arg) 3351(defun vip-goto-eol (arg)
3336 "Go to end of line." 3352 "Go to end of line."
3337 (interactive "P") 3353 (interactive "P")
3354 (vip-leave-region-active)
3338 (let ((val (vip-p-val arg)) 3355 (let ((val (vip-p-val arg))
3339 (com (vip-getcom arg))) 3356 (com (vip-getcom arg)))
3340 (if com (vip-move-marker-locally 'vip-com-point (point))) 3357 (if com (vip-move-marker-locally 'vip-com-point (point)))
@@ -3351,6 +3368,7 @@ On reaching beginning of line, stop and signal error."
3351(defun vip-goto-col (arg) 3368(defun vip-goto-col (arg)
3352 "Go to ARG's column." 3369 "Go to ARG's column."
3353 (interactive "P") 3370 (interactive "P")
3371 (vip-leave-region-active)
3354 (let ((val (vip-p-val arg)) 3372 (let ((val (vip-p-val arg))
3355 (com (vip-getcom arg))) 3373 (com (vip-getcom arg)))
3356 (save-excursion 3374 (save-excursion
@@ -3365,6 +3383,7 @@ On reaching beginning of line, stop and signal error."
3365(defun vip-next-line (arg) 3383(defun vip-next-line (arg)
3366 "Go to next line." 3384 "Go to next line."
3367 (interactive "P") 3385 (interactive "P")
3386 (vip-leave-region-active)
3368 (let ((val (vip-p-val arg)) 3387 (let ((val (vip-p-val arg))
3369 (com (vip-getCom arg))) 3388 (com (vip-getCom arg)))
3370 (if com (vip-move-marker-locally 'vip-com-point (point))) 3389 (if com (vip-move-marker-locally 'vip-com-point (point)))
@@ -3377,6 +3396,7 @@ On reaching beginning of line, stop and signal error."
3377(defun vip-next-line-at-bol (arg) 3396(defun vip-next-line-at-bol (arg)
3378 "Next line at beginning of line." 3397 "Next line at beginning of line."
3379 (interactive "P") 3398 (interactive "P")
3399 (vip-leave-region-active)
3380 (save-excursion 3400 (save-excursion
3381 (end-of-line) 3401 (end-of-line)
3382 (if (eobp) (error "Last line in buffer"))) 3402 (if (eobp) (error "Last line in buffer")))
@@ -3390,6 +3410,7 @@ On reaching beginning of line, stop and signal error."
3390(defun vip-previous-line (arg) 3410(defun vip-previous-line (arg)
3391 "Go to previous line." 3411 "Go to previous line."
3392 (interactive "P") 3412 (interactive "P")
3413 (vip-leave-region-active)
3393 (let ((val (vip-p-val arg)) 3414 (let ((val (vip-p-val arg))
3394 (com (vip-getCom arg))) 3415 (com (vip-getCom arg)))
3395 (if com (vip-move-marker-locally 'vip-com-point (point))) 3416 (if com (vip-move-marker-locally 'vip-com-point (point)))
@@ -3403,6 +3424,7 @@ On reaching beginning of line, stop and signal error."
3403(defun vip-previous-line-at-bol (arg) 3424(defun vip-previous-line-at-bol (arg)
3404 "Previous line at beginning of line." 3425 "Previous line at beginning of line."
3405 (interactive "P") 3426 (interactive "P")
3427 (vip-leave-region-active)
3406 (save-excursion 3428 (save-excursion
3407 (beginning-of-line) 3429 (beginning-of-line)
3408 (if (bobp) (error "First line in buffer"))) 3430 (if (bobp) (error "First line in buffer")))
@@ -5318,6 +5340,9 @@ Mail anyway (y or n)? ")
5318 (defvar emacs-lisp-mode-hook nil) 5340 (defvar emacs-lisp-mode-hook nil)
5319 (add-hook 'emacs-lisp-mode-hook 'viper-mode) 5341 (add-hook 'emacs-lisp-mode-hook 'viper-mode)
5320 5342
5343 (defvar html-mode-hook nil)
5344 (add-hook 'html-mode-hook 'viper-mode)
5345
5321 (defvar lisp-mode-hook nil) 5346 (defvar lisp-mode-hook nil)
5322 (add-hook 'lisp-mode-hook 'viper-mode) 5347 (add-hook 'lisp-mode-hook 'viper-mode)
5323 5348
@@ -5382,9 +5407,17 @@ Mail anyway (y or n)? ")
5382 ;; This is only necessary when the user uses vip-modify-major-mode 5407 ;; This is only necessary when the user uses vip-modify-major-mode
5383 (add-hook 'dired-mode-hook 'vip-change-state-to-emacs) 5408 (add-hook 'dired-mode-hook 'vip-change-state-to-emacs)
5384 5409
5385 (defvar view-mode-hook nil 5410 (if vip-emacs-p
5386 "View hook. Run after view mode.") 5411 (progn
5387 (add-hook 'view-mode-hook 'vip-change-state-to-emacs) 5412 (defvar view-mode-hook nil
5413 "View hook. Run after view mode.")
5414 (add-hook 'view-mode-hook 'vip-change-state-to-emacs))
5415 (defadvice view-minor-mode (after vip-view-ad activate)
5416 "Switch to Emacs state in View mode."
5417 (vip-change-state-to-emacs))
5418 (defvar view-hook nil
5419 "View hook. Run after view mode.")
5420 (add-hook 'view-hook 'vip-change-state-to-emacs))
5388 5421
5389 ;; For VM users. 5422 ;; For VM users.
5390 ;; Put summary and other VM buffers in Emacs state. 5423 ;; Put summary and other VM buffers in Emacs state.
@@ -5408,6 +5441,27 @@ Mail anyway (y or n)? ")
5408 (vip-change-state-to-emacs)) 5441 (vip-change-state-to-emacs))
5409 ) ; vip-set-hooks 5442 ) ; vip-set-hooks
5410 5443
5444;; Set some useful macros
5445;; These must be before we load .vip, so the user can unrecord them.
5446
5447;; repeat the 2nd previous command without rotating the command history
5448(vip-record-kbd-macro
5449 (vector vip-repeat-from-history-key '\1) 'vi-state
5450 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't)
5451;; repeat the 3d previous command without rotating the command history
5452(vip-record-kbd-macro
5453 (vector vip-repeat-from-history-key '\2) 'vi-state
5454 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't)
5455
5456;; toggle case sensitivity in search
5457(vip-record-kbd-macro
5458 "//" 'vi-state
5459 [1 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 't)
5460;; toggle regexp/vanila search
5461(vip-record-kbd-macro
5462 "///" 'vi-state
5463 [2 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 't)
5464
5411 5465
5412;; ~/.vip is loaded if it exists 5466;; ~/.vip is loaded if it exists
5413(if (and (file-exists-p vip-custom-file-name) 5467(if (and (file-exists-p vip-custom-file-name)
@@ -5437,6 +5491,8 @@ Mail anyway (y or n)? ")
5437(vip-set-minibuffer-style) 5491(vip-set-minibuffer-style)
5438(vip-set-minibuffer-faces) 5492(vip-set-minibuffer-faces)
5439(vip-set-search-face) 5493(vip-set-search-face)
5494(if vip-buffer-search-char
5495 (vip-buffer-search-enable))
5440 5496
5441;;; Familiarize Viper with some minor modes that have their own keymaps 5497;;; Familiarize Viper with some minor modes that have their own keymaps
5442(vip-harness-minor-mode "compile") 5498(vip-harness-minor-mode "compile")
@@ -5447,6 +5503,9 @@ Mail anyway (y or n)? ")
5447(vip-harness-minor-mode "vc") 5503(vip-harness-minor-mode "vc")
5448(vip-harness-minor-mode "ltx-math") ; LaTeX-math-mode in AUC-TeX 5504(vip-harness-minor-mode "ltx-math") ; LaTeX-math-mode in AUC-TeX
5449(vip-harness-minor-mode "latex") ; which is in one of these two files 5505(vip-harness-minor-mode "latex") ; which is in one of these two files
5506(vip-harness-minor-mode "cyrillic")
5507(vip-harness-minor-mode "russian")
5508(vip-harness-minor-mode "view-less")
5450 5509
5451 5510
5452;; Intercept maps could go in viper-keym.el 5511;; Intercept maps could go in viper-keym.el
@@ -5484,28 +5543,8 @@ Mail anyway (y or n)? ")
5484 (setq-default minor-mode-map-alist minor-mode-map-alist) 5543 (setq-default minor-mode-map-alist minor-mode-map-alist)
5485 )) 5544 ))
5486 5545
5487;; set some useful macros
5488
5489;; repeat the 2nd previous command without rotating the command history
5490(vip-record-kbd-macro
5491 (vector vip-repeat-from-history-key '\1) 'vi-state
5492 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't)
5493;; repeat the 3d previous command without rotating the command history
5494(vip-record-kbd-macro
5495 (vector vip-repeat-from-history-key '\2) 'vi-state
5496 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't)
5497
5498;; toggle case sensitivity in search
5499(vip-record-kbd-macro
5500 "//" 'vi-state
5501 [1 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 't)
5502;; toggle regexp/vanila search
5503(vip-record-kbd-macro
5504 "///" 'vi-state
5505 [2 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 't)
5506
5507 5546
5508(run-hooks 'vip-load-hooks) ; the last chance to change anything 5547(run-hooks 'vip-load-hooks) ; the last chance to change something
5509 5548
5510(provide 'viper) 5549(provide 'viper)
5511(provide 'vip19) 5550(provide 'vip19)