emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Emacs 23.1 flushes stdin on startup


From: Ted Zlatanov
Subject: Re: Emacs 23.1 flushes stdin on startup
Date: Tue, 11 Aug 2009 15:14:11 -0500
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.1.50 (gnu/linux)

On Thu, 06 Aug 2009 12:33:47 -0400 Stefan Monnier <address@hidden> 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 <address@hidden> 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 address@hidden (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 via email to

[Prev in Thread] Current Thread [Next in Thread]