From: Ted Zlatanov <tzz@lifelogs.com>
Cc: Emacs Development <emacs-devel@gnu.org>
Subject: Re: Emacs 23.1 flushes stdin on startup
Date: Wed, 5 Aug 2009 09:00:23 -0500 [thread overview]
Message-ID: <87r5vquzrc.fsf@jumptrading.com> (raw)
In-Reply-To: mailman.3892.1249425263.2239.help-gnu-emacs@gnu.org
The following message is a courtesy copy of an article
that has been posted to gnu.emacs.help as well.
On Wed, 05 Aug 2009 00:33:56 +0200 bojohan+news@dd.chalmers.se (Johan Bockgård) wrote:
JB> "David F. Skoll" <dfs@roaringpenguin.com> writes:
>> I've noticed a behavior change in 23.1 that doesn't seem to be documented:
>> If I start Emacs in text mode (eg: "emacs -nw") and type stuff before
>> Emacs has started up, the stuff I type is lost. Version 22 would not
>> flush the input, and my pre-startup stuff would appear in the buffer.
JB> It's caused by the xterm init code (info "(elisp) Terminal-Specific")
JB> for finding out if the terminal is modern enough to support the
JB> `modifyOtherKeys' feature; see term/xterm.el.
JB> [...]
JB> ;; Pending input can be mistakenly returned by the calls to
JB> ;; read-event below. Discard it.
JB> (discard-input)
JB> ;; Try to find out the type of terminal by sending a "Secondary
JB> ;; Device Attributes (DA)" query.
JB> (send-string-to-terminal "\e[>0c")
>> I really miss the old behavior. Is there any way to convince Emacs 23.1
>> not to flush stdin on startup?
JB> There's no simple knob, unfortunately, but there's always some way.
How about adding a variable xterm-modify-other-keys-supported with
values t, nil, and 'check? It would make the startup slightly faster,
too.
Small untested patch attached to illustrate.
Ted
Index: xterm.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/term/xterm.el,v
retrieving revision 1.62
diff -c -r1.62 xterm.el
*** xterm.el 5 Jan 2009 03:23:59 -0000 1.62
--- xterm.el 5 Aug 2009 13:59:26 -0000
***************
*** 25,30 ****
--- 25,36 ----
;;; Code:
+ (defcustom xterm-modify-other-keys-supported 'check
+ "Whether the XTerm supports modifyOtherKeys."
+ :type '(choice (const :tag "No" nil)
+ (const :tag "Yes" t)
+ (const :tag "Check" check)))
+
(defvar xterm-function-map
(let ((map (make-sparse-keymap)))
***************
*** 470,515 ****
;; C-. C-, etc.
;; To do that we need to find out if the current terminal supports
;; modifyOtherKeys. At this time only xterm does.
! (let ((coding-system-for-read 'binary)
! (chr nil)
! (str nil))
! ;; Pending input can be mistakenly returned by the calls to
! ;; read-event below. Discard it.
! (discard-input)
! ;; Try to find out the type of terminal by sending a "Secondary
! ;; Device Attributes (DA)" query.
! (send-string-to-terminal "\e[>0c")
!
! ;; The reply should be of the form: \e [ > NUMBER1 ; NUMBER2 ; NUMBER3 c
! ;; If the timeout is completely removed for read-event, this
! ;; might hang for terminals that pretend to be xterm, but don't
! ;; 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.
! (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)
! ;; NUMBER2 is the xterm version number, look for something
! ;; greater than 216, the version when modifyOtherKeys was
! ;; introduced.
! (when (>= (string-to-number
! (substring str (match-beginning 1) (match-end 1))) 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))))))
(run-hooks 'terminal-init-xterm-hook))
;; Set up colors, for those versions of xterm that support it.
(defvar xterm-standard-colors
;; The names in the comments taken from XTerm-col.ad in the xterm
--- 476,529 ----
;; C-. C-, etc.
;; To do that we need to find out if the current terminal supports
;; modifyOtherKeys. At this time only xterm does.
! (when xterm-modify-other-keys-supported
! (cond
! ((eq xterm-modify-other-keys-supported 'check)
! (let ((coding-system-for-read 'binary)
! (chr nil)
! (str nil))
! ;; Pending input can be mistakenly returned by the calls to
! ;; read-event below. Discard it.
! (discard-input)
! ;; Try to find out the type of terminal by sending a "Secondary
! ;; Device Attributes (DA)" query.
! (send-string-to-terminal "\e[>0c")
!
! ;; The reply should be of the form: \e [ > NUMBER1 ; NUMBER2 ; NUMBER3 c
! ;; If the timeout is completely removed for read-event, this
! ;; might hang for terminals that pretend to be xterm, but don't
! ;; 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.
! (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)
! ;; NUMBER2 is the xterm version number, look for something
! ;; greater than 216, the version when modifyOtherKeys was
! ;; introduced.
! (when (>= (string-to-number
! (substring str (match-beginning 1) (match-end 1))) 216)
! (terminal-init-xterm-modify-other-keys)))))))
! (t (terminal-init-xterm-modify-other-keys))))
(run-hooks 'terminal-init-xterm-hook))
+ (defun terminal-init-xterm-modify-other-keys ()
+ "Terminal initialization for xterm's modifyOtherKeys support."
+ ;; 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))
+
;; Set up colors, for those versions of xterm that support it.
(defvar xterm-standard-colors
;; The names in the comments taken from XTerm-col.ad in the xterm
next prev parent reply other threads:[~2009-08-05 14:00 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-04 20:16 Emacs 23.1 flushes stdin on startup David F. Skoll
2009-08-04 22:33 ` Johan Bockgård
2009-08-05 6:20 ` Kevin Rodgers
[not found] ` <mailman.3892.1249425263.2239.help-gnu-emacs@gnu.org>
2009-08-05 14:00 ` Ted Zlatanov [this message]
2009-08-06 16:33 ` Stefan Monnier
2009-08-11 20:14 ` Ted Zlatanov
2009-08-28 14:21 ` Ted Zlatanov
2009-08-28 16:27 ` Ulrich Mueller
2009-08-29 2:19 ` Ted Zlatanov
2009-08-29 9:12 ` Ulrich Mueller
2009-08-29 14:19 ` Chong Yidong
2009-08-28 16:42 ` Stefan Monnier
2009-08-28 18:09 ` Dan Nicolaescu
2009-08-29 0:48 ` Stefan Monnier
2009-08-29 2:07 ` Ted Zlatanov
2009-08-29 4:10 ` Dan Nicolaescu
2009-08-30 6:10 ` Dan Nicolaescu
2009-08-06 16:35 ` Stefan Monnier
2009-08-07 21:02 ` Johan Bockgård
2009-08-05 14:00 ` Ted Zlatanov
-- strict thread matches above, loose matches on Subject: below --
2009-08-05 15:42 David F. Skoll
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r5vquzrc.fsf@jumptrading.com \
--to=tzz@lifelogs.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.