aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2002-06-23 22:13:15 +0000
committerStefan Monnier2002-06-23 22:13:15 +0000
commit5ef6a86d2e2b7ca23df53f216b50af87afafe6ef (patch)
treefcdf7412da5102dff94d85a5689c7beb7bb2ce70
parent2881ae982b7e807db521bae3489c767c43ab53fa (diff)
downloademacs-5ef6a86d2e2b7ca23df53f216b50af87afafe6ef.tar.gz
emacs-5ef6a86d2e2b7ca23df53f216b50af87afafe6ef.zip
(event-start, event-end, event-click-count):
Accept non-mouse events as well. (read-key): New function. (read-quoted-char): Use it. Use this-single-command-raw-keys as well.
-rw-r--r--lisp/subr.el28
1 files changed, 16 insertions, 12 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 1870e570623..6532f2da8a0 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -608,7 +608,8 @@ If EVENT is a drag, this returns the drag's starting position.
608The return value is of the form 608The return value is of the form
609 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP) 609 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
610The `posn-' functions access elements of such lists." 610The `posn-' functions access elements of such lists."
611 (nth 1 event)) 611 (if (consp event) (nth 1 event)
612 (list (selected-window) (point) '(0 . 0) 0)))
612 613
613(defsubst event-end (event) 614(defsubst event-end (event)
614 "Return the ending location of EVENT. EVENT should be a click or drag event. 615 "Return the ending location of EVENT. EVENT should be a click or drag event.
@@ -616,12 +617,13 @@ If EVENT is a click event, this function is the same as `event-start'.
616The return value is of the form 617The return value is of the form
617 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP) 618 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
618The `posn-' functions access elements of such lists." 619The `posn-' functions access elements of such lists."
619 (nth (if (consp (nth 2 event)) 2 1) event)) 620 (if (consp event) (nth (if (consp (nth 2 event)) 2 1) event)
621 (list (selected-window) (point) '(0 . 0) 0)))
620 622
621(defsubst event-click-count (event) 623(defsubst event-click-count (event)
622 "Return the multi-click count of EVENT, a click or drag event. 624 "Return the multi-click count of EVENT, a click or drag event.
623The return value is a positive integer." 625The return value is a positive integer."
624 (if (integerp (nth 2 event)) (nth 2 event) 1)) 626 (if (and (consp event) (integerp (nth 2 event))) (nth 2 event) 1))
625 627
626(defsubst posn-window (position) 628(defsubst posn-window (position)
627 "Return the window in POSITION. 629 "Return the window in POSITION.
@@ -1033,6 +1035,13 @@ Legitimate radix values are 8, 10 and 16."
1033 :type '(choice (const 8) (const 10) (const 16)) 1035 :type '(choice (const 8) (const 10) (const 16))
1034 :group 'editing-basics) 1036 :group 'editing-basics)
1035 1037
1038(defun read-key (&optional prompt)
1039 "Read a key from the keyboard.
1040Contrary to `read-event' this will not return a raw event but will
1041obey `function-key-map' and `key-translation-map' instead."
1042 (let ((overriding-terminal-local-map (make-sparse-keymap)))
1043 (aref (read-key-sequence prompt nil t) 0)))
1044
1036(defun read-quoted-char (&optional prompt) 1045(defun read-quoted-char (&optional prompt)
1037 "Like `read-char', but do not allow quitting. 1046 "Like `read-char', but do not allow quitting.
1038Also, if the first character read is an octal digit, 1047Also, if the first character read is an octal digit,
@@ -1054,16 +1063,11 @@ for numeric input."
1054or the octal character code. 1063or the octal character code.
1055RET terminates the character code and is discarded; 1064RET terminates the character code and is discarded;
1056any other non-digit terminates the character code and is then used as input.")) 1065any other non-digit terminates the character code and is then used as input."))
1057 (setq char (read-event (and prompt (format "%s-" prompt)) t)) 1066 (setq char (read-key (and prompt (format "%s-" prompt))))
1058 (if inhibit-quit (setq quit-flag nil))) 1067 (if inhibit-quit (setq quit-flag nil)))
1059 ;; Translate TAB key into control-I ASCII character, and so on.
1060 (and char
1061 (let ((translated (lookup-key function-key-map (vector char))))
1062 (if (arrayp translated)
1063 (setq char (aref translated 0)))))
1064 (cond ((null char)) 1068 (cond ((null char))
1065 ((not (integerp char)) 1069 ((not (integerp char))
1066 (setq unread-command-events (list char) 1070 (setq unread-command-events (this-single-command-raw-keys)
1067 done t)) 1071 done t))
1068 ((/= (logand char ?\M-\^@) 0) 1072 ((/= (logand char ?\M-\^@) 0)
1069 ;; Turn a meta-character into a character with the 0200 bit set. 1073 ;; Turn a meta-character into a character with the 0200 bit set.
@@ -1080,7 +1084,7 @@ any other non-digit terminates the character code and is then used as input."))
1080 ((and (not first) (eq char ?\C-m)) 1084 ((and (not first) (eq char ?\C-m))
1081 (setq done t)) 1085 (setq done t))
1082 ((not first) 1086 ((not first)
1083 (setq unread-command-events (list char) 1087 (setq unread-command-events (this-single-command-raw-keys)
1084 done t)) 1088 done t))
1085 (t (setq code char 1089 (t (setq code char
1086 done t))) 1090 done t)))
@@ -1952,7 +1956,7 @@ Return the modified alist."
1952(defun make-temp-file (prefix &optional dir-flag suffix) 1956(defun make-temp-file (prefix &optional dir-flag suffix)
1953 "Create a temporary file. 1957 "Create a temporary file.
1954The returned file name (created by appending some random characters at the end 1958The returned file name (created by appending some random characters at the end
1955of PREFIX, and expanding against `temporary-file-directory' if necessary, 1959of PREFIX, and expanding against `temporary-file-directory' if necessary),
1956is guaranteed to point to a newly created empty file. 1960is guaranteed to point to a newly created empty file.
1957You can then use `write-region' to write new data into the file. 1961You can then use `write-region' to write new data into the file.
1958 1962