diff options
| author | Michael Kifer | 1995-07-27 19:40:33 +0000 |
|---|---|---|
| committer | Michael Kifer | 1995-07-27 19:40:33 +0000 |
| commit | 4702a4202710fb3fe0a5770627ba1a499d628331 (patch) | |
| tree | 78696497b4bef881b7f3760eac39478cde19dee5 | |
| parent | 6dce198413831af074fe9b2254c38a6d9898154d (diff) | |
| download | emacs-4702a4202710fb3fe0a5770627ba1a499d628331.tar.gz emacs-4702a4202710fb3fe0a5770627ba1a499d628331.zip | |
(vip-add-hook,vip-remove-hook): new functions.
| -rw-r--r-- | lisp/emulation/viper-util.el | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/lisp/emulation/viper-util.el b/lisp/emulation/viper-util.el index 31233a6f0da..6b15ca97eb8 100644 --- a/lisp/emulation/viper-util.el +++ b/lisp/emulation/viper-util.el | |||
| @@ -219,6 +219,32 @@ | |||
| 219 | (error "%S: Invalid op in vip-check-version" op)))) | 219 | (error "%S: Invalid op in vip-check-version" op)))) |
| 220 | (cond ((memq op '(= > >=)) nil) | 220 | (cond ((memq op '(= > >=)) nil) |
| 221 | ((memq op '(< <=)) t)))) | 221 | ((memq op '(< <=)) t)))) |
| 222 | |||
| 223 | ;;;; warn if it is a wrong version of emacs | ||
| 224 | ;;(if (or (vip-check-version '< 19 29 'emacs) | ||
| 225 | ;; (vip-check-version '< 19 12 'xemacs)) | ||
| 226 | ;; (progn | ||
| 227 | ;; (with-output-to-temp-buffer " *vip-info*" | ||
| 228 | ;; (switch-to-buffer " *vip-info*") | ||
| 229 | ;; (insert | ||
| 230 | ;; (format " | ||
| 231 | ;; | ||
| 232 | ;;This version of Viper requires | ||
| 233 | ;; | ||
| 234 | ;;\t Emacs 19.29 and higher | ||
| 235 | ;;\t OR | ||
| 236 | ;;\t XEmacs 19.12 and higher | ||
| 237 | ;; | ||
| 238 | ;;It is unlikely to work under Emacs version %s | ||
| 239 | ;;that you are using... " emacs-version)) | ||
| 240 | ;; | ||
| 241 | ;; (if noninteractive | ||
| 242 | ;; () | ||
| 243 | ;; (beep 1) | ||
| 244 | ;; (beep 1) | ||
| 245 | ;; (insert "\n\nType any key to continue... ") | ||
| 246 | ;; (vip-read-event))) | ||
| 247 | ;; (kill-buffer " *vip-info*"))) | ||
| 222 | 248 | ||
| 223 | 249 | ||
| 224 | (defun vip-get-visible-buffer-window (wind) | 250 | (defun vip-get-visible-buffer-window (wind) |
| @@ -665,6 +691,50 @@ | |||
| 665 | (setq elt (nconc elt (list form))))) | 691 | (setq elt (nconc elt (list form))))) |
| 666 | form | 692 | form |
| 667 | )) | 693 | )) |
| 694 | |||
| 695 | ;; This is here because Emacs changed the way local hooks work. | ||
| 696 | ;; | ||
| 697 | ;;Add to the value of HOOK the function FUNCTION. | ||
| 698 | ;;FUNCTION is not added if already present. | ||
| 699 | ;;FUNCTION is added (if necessary) at the beginning of the hook list | ||
| 700 | ;;unless the optional argument APPEND is non-nil, in which case | ||
| 701 | ;;FUNCTION is added at the end. | ||
| 702 | ;; | ||
| 703 | ;;HOOK should be a symbol, and FUNCTION may be any valid function. If | ||
| 704 | ;;HOOK is void, it is first set to nil. If HOOK's value is a single | ||
| 705 | ;;function, it is changed to a list of functions." | ||
| 706 | (defun vip-add-hook (hook function &optional append) | ||
| 707 | (if (not (boundp hook)) (set hook nil)) | ||
| 708 | ;; If the hook value is a single function, turn it into a list. | ||
| 709 | (let ((old (symbol-value hook))) | ||
| 710 | (if (or (not (listp old)) (eq (car old) 'lambda)) | ||
| 711 | (setq old (list old))) | ||
| 712 | (if (member function old) | ||
| 713 | nil | ||
| 714 | (set hook (if append | ||
| 715 | (append old (list function)) ; don't nconc | ||
| 716 | (cons function old)))))) | ||
| 717 | |||
| 718 | ;; This is here because of Emacs's changes in the semantics of add/remove-hooks | ||
| 719 | ;; and due to the bugs they introduced. | ||
| 720 | ;; | ||
| 721 | ;; Remove from the value of HOOK the function FUNCTION. | ||
| 722 | ;; HOOK should be a symbol, and FUNCTION may be any valid function. If | ||
| 723 | ;; FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the | ||
| 724 | ;; list of hooks to run in HOOK, then nothing is done. See `vip-add-hook'." | ||
| 725 | (defun vip-remove-hook (hook function) | ||
| 726 | (if (or (not (boundp hook)) ;unbound symbol, or | ||
| 727 | (null (symbol-value hook)) ;value is nil, or | ||
| 728 | (null function)) ;function is nil, then | ||
| 729 | nil ;Do nothing. | ||
| 730 | (let ((hook-value (symbol-value hook))) | ||
| 731 | (if (consp hook-value) | ||
| 732 | ;; don't side-effect the list | ||
| 733 | (setq hook-value (delete function (copy-sequence hook-value))) | ||
| 734 | (if (equal hook-value function) | ||
| 735 | (setq hook-value nil))) | ||
| 736 | (set hook hook-value)))) | ||
| 737 | |||
| 668 | 738 | ||
| 669 | 739 | ||
| 670 | ;; like read-event, but in XEmacs also try to convert to char, if possible | 740 | ;; like read-event, but in XEmacs also try to convert to char, if possible |
| @@ -677,6 +747,18 @@ | |||
| 677 | event)) | 747 | event)) |
| 678 | )) | 748 | )) |
| 679 | 749 | ||
| 750 | ;; This function lets function-key-map convert key sequences into logical | ||
| 751 | ;; keys. This does a better job than vip-read-event when it comes to kbd | ||
| 752 | ;; macros, since it enables certain macros to be shared between X and TTY | ||
| 753 | ;; modes. | ||
| 754 | (defun vip-read-key () | ||
| 755 | (let ((overriding-local-map vip-overriding-map) | ||
| 756 | key) | ||
| 757 | (use-global-map vip-overriding-map) | ||
| 758 | (setq key (elt (read-key-sequence nil) 0)) | ||
| 759 | (use-global-map global-map) | ||
| 760 | key)) | ||
| 761 | |||
| 680 | 762 | ||
| 681 | ;; Emacs has a bug in eventp, which causes (eventp nil) to return (nil) | 763 | ;; Emacs has a bug in eventp, which causes (eventp nil) to return (nil) |
| 682 | ;; instead of nil, if '(nil) was previously inadvertantly assigned to | 764 | ;; instead of nil, if '(nil) was previously inadvertantly assigned to |