- (when (equal (read-event nil nil 2) ?\e)
- (when (equal (read-event nil nil 2) ?\[)
- (while (not (equal (setq chr (read-event nil nil 2)) ?c))
- (setq str (concat str (string chr))))
- (when (string-match ">0;\\([0-9]+\\);0" str)
- (setq version (string-to-number
- (substring str (match-beginning 1) (match-end 1))))
- ;; xterm version 242 supports reporting the background
- ;; color, maybe earlier versions do too...
- (when (>= version 242)
- (send-string-to-terminal "\e]11;?\e\\")
- (when (equal (read-event nil nil 2) ?\e)
- (when (equal (read-event nil nil 2) ?\])
- (setq str "")
- (while (not (equal (setq chr (read-event nil nil 2)) ?\\))
- (setq str (concat str (string chr))))
- (when (string-match "11;rgb:\\([a-f0-9]+\\)/\\([a-f0-9]+\\)/\\([a-f0-9]+\\)" str)
- (setq recompute-faces
- (xterm-maybe-set-dark-background-mode
- (string-to-number (match-string 1 str) 16)
- (string-to-number (match-string 2 str) 16)
- (string-to-number (match-string 3 str) 16)))))))
- ;; NUMBER2 is the xterm version number, look for something
- ;; greater than 216, the version when modifyOtherKeys was
- ;; introduced.
- (when (>= version 216)
- ;; Make sure that the modifyOtherKeys state is restored when
- ;; suspending, resuming and exiting.
- (add-hook 'suspend-hook 'xterm-turn-off-modify-other-keys)
- (add-hook 'suspend-resume-hook 'xterm-turn-on-modify-other-keys)
- (add-hook 'kill-emacs-hook 'xterm-remove-modify-other-keys)
- (add-hook 'delete-terminal-functions 'xterm-remove-modify-other-keys)
- ;; Add the selected frame to the list of frames that
- ;; need to deal with modify-other-keys.
- (push (frame-terminal (selected-frame))
- xterm-modify-other-keys-terminal-list)
- (xterm-turn-on-modify-other-keys))
-
- ;; Recompute faces here in case the background mode was
- ;; set to dark. We used to call
- ;; `tty-set-up-initial-frame-faces' only once, but that
- ;; caused the light background faces to be computed
- ;; incorrectly. See:
- ;; http://permalink.gmane.org/gmane.emacs.devel/119627
- (when recompute-faces
- (tty-set-up-initial-frame-faces))))))
+ (when (and (equal (read-event nil nil 2) ?\e)
+ (equal (read-event nil nil 2) ?\[))
+ (while (not (equal (setq chr (read-event nil nil 2)) ?c))
+ (setq str (concat str (string chr))))
+ (if (string-match ">0;\\([0-9]+\\);0" str)
+ (setq version (string-to-number (match-string 1 str)))))
+ ;; 2. If reportBackground is known to be supported, or the
+ ;; version is 242 or higher, assume the xterm supports
+ ;; reporting the background color (TODO: maybe earlier
+ ;; versions do too...)
+ (when (or (memq 'reportBackground given-capabilities)
+ (and (memq 'reportBackground tocheck-capabilities)
+ version
+ (>= version 242)))
+ (discard-input)
+ (send-string-to-terminal "\e]11;?\e\\")
+ (when (and (equal (read-event nil nil 2) ?\e)
+ (equal (read-event nil nil 2) ?\]))
+ (setq str "")
+ (while (not (equal (setq chr (read-event nil nil 2)) ?\\))
+ (setq str (concat str (string chr))))
+ (if (string-match
+ "11;rgb:\\([a-f0-9]+\\)/\\([a-f0-9]+\\)/\\([a-f0-9]+\\)" str)
+ (setq recompute-faces
+ (xterm-maybe-set-dark-background-mode
+ (string-to-number (match-string 1 str) 16)
+ (string-to-number (match-string 2 str) 16)
+ (string-to-number (match-string 3 str) 16))))))
+
+ ;; 3. If modifyOtherKeys is known to be supported or the
+ ;; version is 216 (the version when modifyOtherKeys was
+ ;; introduced) or higher, initialize the modifyOtherKeys support.
+ (if (or (memq 'modifyOtherKeys given-capabilities)
+ (and (memq 'modifyOtherKeys tocheck-capabilities)
+ version
+ (>= version 216)))
+ (terminal-init-xterm-modify-other-keys))
+
+ ;; Recompute faces here in case the background mode was
+ ;; set to dark. We used to call
+ ;; `tty-set-up-initial-frame-faces' only once, but that
+ ;; caused the light background faces to be computed
+ ;; incorrectly. See:
+ ;; http://permalink.gmane.org/gmane.emacs.devel/119627
+ (when recompute-faces
+ (tty-set-up-initial-frame-faces))))