diff options
author | Daniel Colascione <dancol@dancol.org> | 2018-06-08 23:22:23 -0700 |
---|---|---|
committer | Daniel Colascione <dancol@dancol.org> | 2018-06-08 23:22:43 -0700 |
commit | c67befd662571a822f3183c114ce3b1ad02e0ed9 (patch) | |
tree | 7efe440a27c67f36399fbb9c1d925bb61b7ea35b /lisp/term/xterm.el | |
parent | 6fdc3fac5658a7ab142c358cddd90f3db5665ef5 (diff) | |
download | emacs-c67befd662571a822f3183c114ce3b1ad02e0ed9.tar.gz |
Avoid unnecessary readahead early in TTY frame init
We query some properties of the terminal early in initialization, and
just before we do, we perform ordinary redisplay. This redisplay can
result in unsightly flickering if we change some aspects of the
display immediately afterward and redisplay again. By avoiding
redisplay in xquery--query as long as we get timely responses from the
terminal, we can avoid this early unwanted redisplay.
* lisp/term/xterm.el:
(xterm-query-redisplay-timeout): New variable.
(xterm--read-event-for-query): New function.
(xterm--report-background-handler,xterm--version-handler,xterm--query):
Call it.
Diffstat (limited to 'lisp/term/xterm.el')
-rw-r--r-- | lisp/term/xterm.el | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el index 6410a4b83c9..06a9d443bfa 100644 --- a/lisp/term/xterm.el +++ b/lisp/term/xterm.el @@ -652,7 +652,7 @@ Return the pasted text as a string." (let ((str "") chr) ;; The reply should be: \e ] 11 ; rgb: NUMBER1 / NUMBER2 / NUMBER3 \e \\ - (while (and (setq chr (read-event nil nil 2)) (not (equal chr ?\\))) + (while (and (setq chr (xterm--read-event-for-query)) (not (equal chr ?\\))) (setq str (concat str (string chr)))) (when (string-match "rgb:\\([a-f0-9]+\\)/\\([a-f0-9]+\\)/\\([a-f0-9]+\\)" str) @@ -680,7 +680,7 @@ Return the pasted text as a string." ;; respond to this escape sequence. RMS' opinion was to remove ;; it completely. That might be right, but let's first try to ;; see if by using a longer timeout we get rid of most issues. - (while (and (setq chr (read-event nil nil 2)) (not (equal chr ?c))) + (while (and (setq chr (xterm--read-event-for-query)) (not (equal chr ?c))) (setq str (concat str (string chr)))) ;; Since xterm-280, the terminal type (NUMBER1) is now 41 instead of 0. (when (string-match "\\([0-9]+\\);\\([0-9]+\\);0" str) @@ -730,6 +730,24 @@ Return the pasted text as a string." "Seconds to wait for an answer from the terminal. Can be nil to mean \"no timeout\".") +(defvar xterm-query-redisplay-timeout 0.2 + "Seconds to wait before allowing redisplay during terminal + query." ) + +(defun xterm--read-event-for-query () + "Like read-event, but inhibit redisplay. + +By not redisplaying right away for xterm queries, we can avoid +unsightly flashing during initialization. Give up and redisplay +anyway if we've been waiting a little while." + (let ((start-time (float-time))) + (or (let ((inhibit-redisplay t)) + (read-event nil nil xterm-query-redisplay-timeout)) + (read-event nil nil + (and xterm-query-timeout + (max 0 (+ start-time xterm-query-timeout + (- (float-time))))))))) + (defun xterm--query (query handlers &optional no-async) "Send QUERY string to the terminal and watch for a response. HANDLERS is an alist with elements of the form (STRING . FUNCTION). @@ -762,7 +780,7 @@ We run the first FUNCTION whose STRING matches the input events." (let ((handler (pop handlers)) (i 0)) (while (and (< i (length (car handler))) - (let ((evt (read-event nil nil xterm-query-timeout))) + (let ((evt (xterm--read-event-for-query))) (if (and (null evt) (= i 0) (not no-async)) ;; Timeout on the first event: fallback on async. (progn |