From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.devel Subject: Re: Emacs 23.1 flushes stdin on startup Date: Wed, 5 Aug 2009 09:00:23 -0500 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <87r5vquzrc.fsf@jumptrading.com> References: <4A789738.8090008@roaringpenguin.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1249481004 7209 80.91.229.12 (5 Aug 2009 14:03:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 5 Aug 2009 14:03:24 +0000 (UTC) Cc: Emacs Development Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Aug 05 16:03:16 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MYh2n-0002hl-36 for ged-emacs-devel@m.gmane.org; Wed, 05 Aug 2009 16:00:43 +0200 Original-Received: from localhost ([127.0.0.1]:49373 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MYh2m-00013v-Mk for ged-emacs-devel@m.gmane.org; Wed, 05 Aug 2009 10:00:40 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MYh2g-00011E-M9 for emacs-devel@gnu.org; Wed, 05 Aug 2009 10:00:34 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MYh2b-0000xp-Iq for emacs-devel@gnu.org; Wed, 05 Aug 2009 10:00:33 -0400 Original-Received: from [199.232.76.173] (port=35378 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MYh2b-0000xi-BD for emacs-devel@gnu.org; Wed, 05 Aug 2009 10:00:29 -0400 Original-Received: from chirelay1o.jumptrading.com ([38.98.147.153]:33594 helo=chirelay1.jumptrading.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MYh2a-0006Ew-JR for emacs-devel@gnu.org; Wed, 05 Aug 2009 10:00:28 -0400 Original-Received: from chirelay1.jumptrading.com (unknown [127.0.0.1]) by chirelay1.jumptrading.com (Symantec Mail Security) with ESMTP id 2883F320038 for ; Wed, 5 Aug 2009 08:58:33 -0500 (CDT) X-AuditID: 26629395-a61c9bb000001b95-76-4a7990082e86 Original-Received: from chiexchange02.w2k.jumptrading.com (unknown [38.98.147.140]) by chirelay1.jumptrading.com (Symantec Mail Security) with ESMTP id E23AA2DC003 for ; Wed, 5 Aug 2009 08:58:32 -0500 (CDT) Original-Received: from internalsmtp.w2k.jumptrading.com (10.2.4.29) by chiexchange02.w2k.jumptrading.com (10.2.4.71) with Microsoft SMTP Server id 8.1.291.1; Wed, 5 Aug 2009 09:00:27 -0500 Original-Received: from tzlatanov-ubuntu-desktop.jumptrading.com ([10.2.21.147]) by internalsmtp.w2k.jumptrading.com with Microsoft SMTPSVC(6.0.3790.1830); Wed, 5 Aug 2009 09:00:27 -0500 Original-Newsgroups: gnu.emacs.help X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.1.50 (gnu/linux) Cancel-Lock: sha1:jAj7Kp0PzkD3FiDsN8cjvJV+Fbg= Posted-To: gnu.emacs.help X-OriginalArrivalTime: 05 Aug 2009 14:00:27.0224 (UTC) FILETIME=[15D8FD80:01CA15D5] X-Brightmail-Tracker: AAAAAA== X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.4-2.6 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:113720 Archived-At: 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= =E5rd) wrote:=20 JB> "David F. Skoll" writes: >> I've noticed a behavior change in 23.1 that doesn't seem to be documente= d: >> 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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 ---- =20=20 ;;; Code: =20=20 + (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))) +=20 (defvar xterm-function-map (let ((map (make-sparse-keymap))) =20=20 *************** *** 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") !=20 ! ;; The reply should be of the form: \e [ > NUMBER1 ; NUMBER2 ; NUMB= ER3 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 (>=3D (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-ke= ys) ! ;; 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)))))) =20=20 (run-hooks 'terminal-init-xterm-hook)) =20=20 ;; 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") !=20 ! ;; 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 (>=3D (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)))) =20=20 (run-hooks 'terminal-init-xterm-hook)) =20=20 + (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)) +=20 ;; 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