So escape sequences and keyboard encoding are taken into account.
When there's an ambiguity because the key looks like the prefix of
some sort of escape sequence, the ambiguity is resolved via `read-key-delay'."
- (with-no-threads
- (let ((overriding-terminal-local-map read-key-empty-map)
- (overriding-local-map nil)
- (old-global-map (current-global-map))
- (timer (run-with-idle-timer
- ;; Wait long enough that Emacs has the time to receive and
- ;; process all the raw events associated with the single-key.
- ;; But don't wait too long, or the user may find the delay
- ;; annoying (or keep hitting more keys which may then get
- ;; lost or misinterpreted).
- ;; This is only relevant for keys which Emacs perceives as
- ;; "prefixes", such as C-x (because of the C-x 8 map in
- ;; key-translate-table and the C-x @ map in function-key-map)
- ;; or ESC (because of terminal escape sequences in
- ;; input-decode-map).
- read-key-delay t
- (lambda ()
- (let ((keys (this-command-keys-vector)))
- (unless (zerop (length keys))
- ;; `keys' is non-empty, so the user has hit at least
- ;; one key; there's no point waiting any longer, even
- ;; though read-key-sequence thinks we should wait
- ;; for more input to decide how to interpret the
- ;; current input.
- (throw 'read-key keys)))))))
- (unwind-protect
- (progn
- (use-global-map read-key-empty-map)
- (aref (catch 'read-key (read-key-sequence prompt nil t)) 0))
- (cancel-timer timer)
- (use-global-map old-global-map)))))
+ (let ((overriding-terminal-local-map read-key-empty-map)
+ (overriding-local-map nil)
+ (old-global-map (current-global-map))
+ (with-no-threads
+ (timer (run-with-idle-timer
+ ;; Wait long enough that Emacs has the time to receive and
+ ;; process all the raw events associated with the single-key.
+ ;; But don't wait too long, or the user may find the delay
+ ;; annoying (or keep hitting more keys which may then get
+ ;; lost or misinterpreted).
+ ;; This is only relevant for keys which Emacs perceives as
+ ;; "prefixes", such as C-x (because of the C-x 8 map in
+ ;; key-translate-table and the C-x @ map in function-key-map)
+ ;; or ESC (because of terminal escape sequences in
+ ;; input-decode-map).
+ read-key-delay t
+ (lambda ()
+ (let ((keys (this-command-keys-vector)))
+ (unless (zerop (length keys))
+ ;; `keys' is non-empty, so the user has hit at least
+ ;; one key; there's no point waiting any longer, even
+ ;; though read-key-sequence thinks we should wait
+ ;; for more input to decide how to interpret the
+ ;; current input.
+ (throw 'read-key keys))))))))
+ (unwind-protect
+ (progn
+ (use-global-map read-key-empty-map)
+ (aref (catch 'read-key (read-key-sequence prompt nil t)) 0))
+ (cancel-timer timer)
+ (use-global-map old-global-map))))
(defun read-quoted-char (&optional prompt)
"Like `read-char', but do not allow quitting.
(defmacro with-no-threads (&rest body)
"Disable temporarily other threads to be executed."
+ (declare (indent 1) (debug t))
`(unwind-protect
(progn (inhibit-yield t)
,@body)