aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/emulation
diff options
context:
space:
mode:
authorMichael Kifer2013-07-07 15:35:54 -0400
committerMichael Kifer2013-07-07 15:35:54 -0400
commitf1e6674bb32058c7ef683d5f8f8ac67f99e96dd2 (patch)
tree6cc51c44045bdbbd5ec28d52f4d212cb52ebaa49 /lisp/emulation
parent1d44267275efdcee3c3584eaa79baccad54266b3 (diff)
downloademacs-f1e6674bb32058c7ef683d5f8f8ac67f99e96dd2.tar.gz
emacs-f1e6674bb32058c7ef683d5f8f8ac67f99e96dd2.zip
* faces.el (tty-run-terminal-initialization): function changed (Stefan
Monnier's patch). * viper.el (viper-emacs-state-mode-list): add egg-status-buffer-mode. (viper-version): version update. (viper-go-away,viper-setup-hooks): function changed (Stefan Monnier's patch). (viper--lookup-key,viper-catch-tty-ESC,viper-uncatch-tty-ESC, viper-setup-ESC-to-escape): new functions (Stefan Monnier's patch). * viper-cmd.el: (viper-del-forward-char-in-insert): new function. (viper-save-kill-buffer): check if buffer is modified. (viper-envelop-ESC-key): function deleted (Stefan Monnier's patch). (viper-intercept-ESC-key): function changed (Stefan Monnier's patch). * viper-keym.el (viper-ESC-key): constant changed (Stefan Monnier's patch). * ediff.el (ediff-files-command,ediff3-files-command): new functions. (ediff-merge-command,ediff-merge-with-ancestor-command): new functions. (ediff-directories-command,ediff-directories3-command): new functions. (ediff-merge-directories-command): new function. (ediff-merge-directories-with-ancestor-command): new function. All the above are command-line interfaces to ediff: facilitate calling Emacs with the appropriate ediff functions invoked. (ediff-version): version update.
Diffstat (limited to 'lisp/emulation')
-rw-r--r--lisp/emulation/viper-cmd.el101
-rw-r--r--lisp/emulation/viper-keym.el2
-rw-r--r--lisp/emulation/viper.el66
3 files changed, 65 insertions, 104 deletions
diff --git a/lisp/emulation/viper-cmd.el b/lisp/emulation/viper-cmd.el
index e7b371365e4..c39d896f3d3 100644
--- a/lisp/emulation/viper-cmd.el
+++ b/lisp/emulation/viper-cmd.el
@@ -996,93 +996,7 @@ as a Meta key and any number of multiple escapes are allowed."
996 (suspend-emacs)) 996 (suspend-emacs))
997 (viper-change-state-to-emacs))) 997 (viper-change-state-to-emacs)))
998 998
999
1000;; Intercept ESC sequences on dumb terminals.
1001;; Based on the idea contributed by Marcelino Veiga Tuimil <mveiga@dit.upm.es>
1002
1003;; Check if last key was ESC and if so try to reread it as a function key.
1004;; But only if there are characters to read during a very short time.
1005;; Returns the last event, if any.
1006(defun viper-envelop-ESC-key ()
1007 (let ((event last-input-event)
1008 (keyseq [nil])
1009 (inhibit-quit t))
1010 (if (viper-ESC-event-p event)
1011 (progn
1012 ;; Some versions of Emacs (eg., 22.50.8 (?)) have a bug, which makes
1013 ;; even a single ESC into a fast keyseq. To guard against this, we
1014 ;; added a check if there are other events as well. Keep the next
1015 ;; line for the next time the bug reappears, so that will remember to
1016 ;; report it.
1017 ;;(if (and (viper-fast-keysequence-p) unread-command-events)
1018 (if (viper-fast-keysequence-p) ;; for Emacsen without the above bug
1019 (progn
1020 (let (minor-mode-map-alist emulation-mode-map-alists)
1021 (viper-set-unread-command-events event)
1022 (setq keyseq (read-key-sequence nil 'continue-echo))
1023 ) ; let
1024 ;; If keyseq translates into something that still has ESC
1025 ;; at the beginning, separate ESC from the rest of the seq.
1026 ;; In XEmacs we check for events that are keypress meta-key
1027 ;; and convert them into [escape key]
1028 ;;
1029 ;; This is needed for the following reason:
1030 ;; If ESC is the first symbol, we interpret it as if the
1031 ;; user typed ESC and then quickly some other symbols.
1032 ;; If ESC is not the first one, then the key sequence
1033 ;; entered was apparently translated into a function key or
1034 ;; something (e.g., one may have
1035 ;; (define-key function-key-map "\e[192z" [f11])
1036 ;; which would translate the escape-sequence generated by
1037 ;; f11 in an xterm window into the symbolic key f11.
1038 ;;
1039 ;; If `first-key' is not an ESC event, we make it into the
1040 ;; last-command-event in order to pretend that this key was
1041 ;; pressed. This is needed to allow arrow keys to be bound to
1042 ;; macros. Otherwise, viper-exec-mapped-kbd-macro will think
1043 ;; that the last event was ESC and so it'll execute whatever is
1044 ;; bound to ESC. (Viper macros can't be bound to
1045 ;; ESC-sequences).
1046 (let* ((first-key (elt keyseq 0))
1047 (key-mod (event-modifiers first-key)))
1048 (cond ((and (viper-ESC-event-p first-key)
1049 (not (viper-translate-all-ESC-keysequences)))
1050 ;; put keys following ESC on the unread list
1051 ;; and return ESC as the key-sequence
1052 (viper-set-unread-command-events (viper-subseq keyseq 1))
1053 (setq last-input-event event
1054 keyseq (if (featurep 'emacs)
1055 "\e"
1056 (vector (character-to-event ?\e)))))
1057 ((and (featurep 'xemacs)
1058 (key-press-event-p first-key)
1059 (equal '(meta) key-mod))
1060 (viper-set-unread-command-events
1061 (vconcat (vector
1062 (character-to-event (event-key first-key)))
1063 (viper-subseq keyseq 1)))
1064 (setq last-input-event event
1065 keyseq (vector (character-to-event ?\e))))
1066 ((eventp first-key)
1067 (setq last-command-event
1068 (viper-copy-event first-key)))
1069 ))
1070 ) ; end progn
1071
1072 ;; this is escape event with nothing after it
1073 ;; put in unread-command-event and then re-read
1074 (viper-set-unread-command-events event)
1075 (setq keyseq (read-key-sequence nil))
1076 ))
1077 ;; not an escape event
1078 (setq keyseq (vector event)))
1079 keyseq))
1080
1081
1082
1083;; Listen to ESC key. 999;; Listen to ESC key.
1084;; If a sequence of keys starting with ESC is issued with very short delays,
1085;; interpret these keys in Emacs mode, so ESC won't be interpreted as a Vi key.
1086(defun viper-intercept-ESC-key () 1000(defun viper-intercept-ESC-key ()
1087 "Function that implements ESC key in Viper emulation of Vi." 1001 "Function that implements ESC key in Viper emulation of Vi."
1088 (interactive) 1002 (interactive)
@@ -1090,13 +1004,7 @@ as a Meta key and any number of multiple escapes are allowed."
1090 ;; minor-mode map(s) have been temporarily disabled so the ESC 1004 ;; minor-mode map(s) have been temporarily disabled so the ESC
1091 ;; binding to viper-intercept-ESC-key doesn't hide the binding we're 1005 ;; binding to viper-intercept-ESC-key doesn't hide the binding we're
1092 ;; looking for (Bug#9146): 1006 ;; looking for (Bug#9146):
1093 (let* ((event (viper-envelop-ESC-key)) 1007 (let* ((cmd 'viper-intercept-ESC-key))
1094 (cmd (cond ((equal event viper-ESC-key)
1095 'viper-intercept-ESC-key)
1096 ((let ((emulation-mode-map-alists nil))
1097 (key-binding event)))
1098 (t
1099 (error "Viper bell")))))
1100 1008
1101 ;; call the actual function to execute ESC (if no other symbols followed) 1009 ;; call the actual function to execute ESC (if no other symbols followed)
1102 ;; or the key bound to the ESC sequence (if the sequence was issued 1010 ;; or the key bound to the ESC sequence (if the sequence was issued
@@ -4289,6 +4197,11 @@ cursor move past the beginning of line."
4289 (t 4197 (t
4290 (backward-char 1)))) 4198 (backward-char 1))))
4291 4199
4200(defun viper-del-forward-char-in-insert ()
4201 "Delete 1 char forward if in insert or replace state."
4202 (interactive)
4203 ;; don't put on kill ring
4204 (delete-char 1 nil))
4292 4205
4293 4206
4294;; join lines. 4207;; join lines.
@@ -4947,7 +4860,7 @@ Please, specify your level now: ")
4947 (interactive) 4860 (interactive)
4948 (if (< viper-expert-level 2) 4861 (if (< viper-expert-level 2)
4949 (save-buffers-kill-emacs) 4862 (save-buffers-kill-emacs)
4950 (save-buffer) 4863 (if (buffer-modified-p) (save-buffer))
4951 (kill-buffer (current-buffer)))) 4864 (kill-buffer (current-buffer))))
4952 4865
4953 4866
diff --git a/lisp/emulation/viper-keym.el b/lisp/emulation/viper-keym.el
index 0d9d300ab1a..d33b5f4ed58 100644
--- a/lisp/emulation/viper-keym.el
+++ b/lisp/emulation/viper-keym.el
@@ -192,7 +192,7 @@ Enter as a sexp. Examples: \"\\C-z\", [(control ?z)]."
192 :type 'string 192 :type 'string
193 :group 'viper) 193 :group 'viper)
194 194
195(defvar viper-ESC-key (kbd "ESC") 195(defconst viper-ESC-key [escape]
196 "Key used to ESC.") 196 "Key used to ESC.")
197 197
198 198
diff --git a/lisp/emulation/viper.el b/lisp/emulation/viper.el
index 7f432cdc143..266af1abf2b 100644
--- a/lisp/emulation/viper.el
+++ b/lisp/emulation/viper.el
@@ -14,7 +14,7 @@
14;; filed in the Emacs bug reporting system against this file, a copy 14;; filed in the Emacs bug reporting system against this file, a copy
15;; of the bug report be sent to the maintainer's email address. 15;; of the bug report be sent to the maintainer's email address.
16 16
17(defconst viper-version "3.14.1 of August 15, 2009" 17(defconst viper-version "3.14.2 of July 4, 2013"
18 "The current version of Viper") 18 "The current version of Viper")
19 19
20;; This file is part of GNU Emacs. 20;; This file is part of GNU Emacs.
@@ -411,6 +411,7 @@ widget."
411 dired-mode 411 dired-mode
412 efs-mode 412 efs-mode
413 tar-mode 413 tar-mode
414 egg-status-buffer-mode
414 415
415 browse-kill-ring-mode 416 browse-kill-ring-mode
416 recentf-mode 417 recentf-mode
@@ -660,7 +661,7 @@ user customization, unrelated to Viper. For instance, if the user advised
660undone. 661undone.
661It also can't undo some Viper settings." 662It also can't undo some Viper settings."
662 (interactive) 663 (interactive)
663 664 (viper-setup-ESC-to-escape nil)
664 ;; restore non-viper vars 665 ;; restore non-viper vars
665 (setq-default 666 (setq-default
666 next-line-add-newlines 667 next-line-add-newlines
@@ -825,6 +826,58 @@ It also can't undo some Viper settings."
825 (add-hook 'viper-post-command-hooks 'set-viper-state-in-major-mode t)) 826 (add-hook 'viper-post-command-hooks 'set-viper-state-in-major-mode t))
826 827
827 828
829;;; Handling of tty's ESC event
830
831;; On a tty, an ESC event can either be the user hitting the escape key, or
832;; some element of a byte sequence used to encode for example cursor keys.
833;; So we try to recognize those events that correspond to the escape key and
834;; turn them into `escape' events (same as used under GUIs). The heuristic we
835;; use to distinguish the two cases is based, as usual, on a timeout, and on
836;; the fact that the special ESC=>escape mapping only takes place if the whole
837;; last key-sequence so far is just [?\e], i.e. either we're still in
838;; read-key-sequence, or the last read-key-sequence only read [?\e], which
839;; should ideally never happen because it should have been mapped to [escape].
840
841(defun viper--tty-ESC-filter (map)
842 (if (and (equal (this-single-command-keys) [?\e])
843 (sit-for (/ viper-fast-keyseq-timeout 1000)))
844 [escape] map))
845
846(defun viper--lookup-key (map key)
847 "Kind of like `lookup-key'.
848Two differences:
849- KEY is a single key, not a sequence.
850- the result is the \"raw\" binding, so it can be a `menu-item', rather than the
851 binding contained in that menu item."
852 (catch 'found
853 (map-keymap (lambda (k b) (if (equal key k) (throw 'found b))) map)))
854
855(defun viper-catch-tty-ESC ()
856 "Setup key mappings of current terminal to turn a tty's ESC into `escape'."
857 (when (memq (terminal-live-p (frame-terminal)) '(t pc))
858 (let ((esc-binding (viper-uncatch-tty-ESC)))
859 (define-key input-decode-map
860 [?\e] `(menu-item "" ,esc-binding :filter viper--tty-ESC-filter)))))
861
862(defun viper-uncatch-tty-ESC ()
863 "Don't hack ESC into `escape' any more."
864 (let ((b (viper--lookup-key input-decode-map ?\e)))
865 (and (eq 'menu-item (car-safe b))
866 (eq 'viper--tty-ESC-filter (nth 4 b))
867 (define-key input-decode-map [?\e] (setq b (nth 2 b))))
868 b))
869
870(defun viper-setup-ESC-to-escape (enable)
871 (if enable
872 (add-hook 'tty-setup-hook 'viper-catch-tty-ESC)
873 (remove-hook 'tty-setup-hook 'viper-catch-tty-ESC))
874 (let ((seen ()))
875 (dolist (frame (frame-list))
876 (let ((terminal (frame-terminal frame)))
877 (unless (memq terminal seen)
878 (push terminal seen)
879 (with-selected-frame frame
880 (if enable (viper-catch-tty-ESC) (viper-uncatch-tty-ESC))))))))
828 881
829;; This sets major mode hooks to make them come up in vi-state. 882;; This sets major mode hooks to make them come up in vi-state.
830(defun viper-set-hooks () 883(defun viper-set-hooks ()
@@ -837,6 +890,8 @@ It also can't undo some Viper settings."
837 (if (eq (default-value 'major-mode) 'fundamental-mode) 890 (if (eq (default-value 'major-mode) 'fundamental-mode)
838 (setq-default major-mode 'viper-mode)) 891 (setq-default major-mode 'viper-mode))
839 892
893 (viper-setup-ESC-to-escape t)
894
840 (add-hook 'change-major-mode-hook 'viper-major-mode-change-sentinel) 895 (add-hook 'change-major-mode-hook 'viper-major-mode-change-sentinel)
841 (add-hook 'find-file-hooks 'set-viper-state-in-major-mode) 896 (add-hook 'find-file-hooks 'set-viper-state-in-major-mode)
842 897
@@ -847,13 +902,6 @@ It also can't undo some Viper settings."
847 (defvar emerge-startup-hook) 902 (defvar emerge-startup-hook)
848 (add-hook 'emerge-startup-hook 'viper-change-state-to-emacs) 903 (add-hook 'emerge-startup-hook 'viper-change-state-to-emacs)
849 904
850 ;; Zap bad bindings in flyspell-mouse-map, which prevent ESC from working
851 ;; over misspelled words (due to the overlay keymaps)
852 (defvar flyspell-mode-hook)
853 (defvar flyspell-mouse-map)
854 (add-hook 'flyspell-mode-hook
855 (lambda ()
856 (define-key flyspell-mouse-map viper-ESC-key nil)))
857 ;; if viper is started from .emacs, it might be impossible to get certain 905 ;; if viper is started from .emacs, it might be impossible to get certain
858 ;; info about the display and windows until emacs initialization is complete 906 ;; info about the display and windows until emacs initialization is complete
859 ;; So do it via the window-setup-hook 907 ;; So do it via the window-setup-hook