unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Ted Zlatanov <tzz@lifelogs.com>
To: emacs-devel@gnu.org
Subject: Re: Emacs 23.1 flushes stdin on startup
Date: Tue, 11 Aug 2009 15:14:11 -0500	[thread overview]
Message-ID: <87vdkukt0s.fsf@lifelogs.com> (raw)
In-Reply-To: jwv1vnooqdo.fsf-monnier+emacs@gnu.org

On Thu, 06 Aug 2009 12:33:47 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

SM> Please merge the when and the cond into a single cond (which will give
SM> meaning to this `cond', since as it stands it only has two arms and
SM> could hence as well use `if').

On Thu, 06 Aug 2009 12:35:05 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

SM> One more thing: terminal-init-<foo> should only be used for "the setup
SM> code for terminal FOO".  Since there aren't any terminal named
SM> "xterm-modify-other-keys" and this function doesn't treat them, better
SM> use some other name, such as just `xterm-modify-other-keys'.

OK, I did both.

On Fri, 07 Aug 2009 23:02:03 +0200 bojohan+news@dd.chalmers.se (Johan Bockgård) wrote: 

JB> Yes. I just don't like the name. I would set this new variable to nil,
JB> but not because the feature is not supported in my terminal, but rather
JB> that it is already enabled there without having Emacs turn it on.

I don't know how to choose a better name, sorry.  Feel free to suggest
alternatives.

Another version lies below.  Let me know if it looks OK.  My change is
minor but I may have missed something.

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	11 Aug 2009 20:11:29 -0000
***************
*** 25,30 ****
--- 25,36 ----
  
  ;;; Code:
  
+ (defcustom xterm-supported-modify-other-keys '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,528 ----
      ;; C-. C-, etc.
      ;; To do that we need to find out if the current terminal supports
      ;; modifyOtherKeys. At this time only xterm does.
!     (cond
!      ((eq xterm-supported-modify-other-keys '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)
! 		(xterm-modify-other-keys)))))))
!      (xterm-supported-modify-other-keys (xterm-modify-other-keys)))
  
      (run-hooks 'terminal-init-xterm-hook))
  
+ (defun 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





  reply	other threads:[~2009-08-11 20:14 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4A789738.8090008@roaringpenguin.com>
     [not found] ` <mailman.3892.1249425263.2239.help-gnu-emacs@gnu.org>
2009-08-05 14:00   ` Emacs 23.1 flushes stdin on startup Ted Zlatanov
2009-08-06 16:33     ` Stefan Monnier
2009-08-11 20:14       ` Ted Zlatanov [this message]
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

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vdkukt0s.fsf@lifelogs.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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).