From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#12354: 24.2; garbage inserted at the beginning of the buffer even when xterm-extra-capabilities is t Date: Tue, 30 Jun 2015 23:19:11 -0400 Message-ID: References: <87txvcen36.fsf@xvii.vinc17.org> <20120905184424.GQ4846@xvii.vinc17.org> <20150527112723.GA23516@ypig.lip.ens-lyon.fr> <20150629023519.GA7712@xvii.vinc17.org> <20150629134704.GD32461@ypig.lip.ens-lyon.fr> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1435720828 15981 80.91.229.3 (1 Jul 2015 03:20:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 1 Jul 2015 03:20:28 +0000 (UTC) Cc: 12354@debbugs.gnu.org To: Vincent Lefevre Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jul 01 05:20:17 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZA8ZM-0007w3-8k for geb-bug-gnu-emacs@m.gmane.org; Wed, 01 Jul 2015 05:20:16 +0200 Original-Received: from localhost ([::1]:49485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZA8ZL-0000Om-C1 for geb-bug-gnu-emacs@m.gmane.org; Tue, 30 Jun 2015 23:20:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50456) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZA8ZG-0000OW-FM for bug-gnu-emacs@gnu.org; Tue, 30 Jun 2015 23:20:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZA8ZB-0003AX-DN for bug-gnu-emacs@gnu.org; Tue, 30 Jun 2015 23:20:10 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:33557) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZA8ZB-00037R-AM for bug-gnu-emacs@gnu.org; Tue, 30 Jun 2015 23:20:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZA8ZA-00062Z-Du for bug-gnu-emacs@gnu.org; Tue, 30 Jun 2015 23:20:04 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 01 Jul 2015 03:20:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12354 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 12354-submit@debbugs.gnu.org id=B12354.143572076023162 (code B ref 12354); Wed, 01 Jul 2015 03:20:04 +0000 Original-Received: (at 12354) by debbugs.gnu.org; 1 Jul 2015 03:19:20 +0000 Original-Received: from localhost ([127.0.0.1]:35003 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZA8YR-00061V-MK for submit@debbugs.gnu.org; Tue, 30 Jun 2015 23:19:20 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:27101) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZA8YP-00061I-Rv for 12354@debbugs.gnu.org; Tue, 30 Jun 2015 23:19:19 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CgDQA731xV/2cGNJ1cgxCEAsYTgk0EAgKBPD0QAQEBAQEBAYEKQQWDXQEBAwFWIwULCzQHCxQYDSSINwjPIwEBAQEBBQEBAQEeizqFBQeELQWYO4ZchmmLK4NZI4FmIR8VgVkigngBAQE X-IPAS-Result: A0CgDQA731xV/2cGNJ1cgxCEAsYTgk0EAgKBPD0QAQEBAQEBAYEKQQWDXQEBAwFWIwULCzQHCxQYDSSINwjPIwEBAQEBBQEBAQEeizqFBQeELQWYO4ZchmmLK4NZI4FmIR8VgVkigngBAQE X-IronPort-AV: E=Sophos;i="5.13,465,1427774400"; d="scan'208";a="128926524" Original-Received: from 157-52-6-103.cpe.teksavvy.com (HELO pastel.home) ([157.52.6.103]) by ironport2-out.teksavvy.com with ESMTP; 30 Jun 2015 23:19:12 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id E48515FE1B; Tue, 30 Jun 2015 23:19:11 -0400 (EDT) In-Reply-To: (Stefan Monnier's message of "Tue, 30 Jun 2015 10:04:39 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:104558 Archived-At: > If you look at the code, you'll hopefully see that there are 2 code > paths (one synchronous with a timeout, and one asynchronous), and > a comment saying that the two should be merged. > I.e. when using the synchronous path, after hitting the timeout, we > should switch to the async path. > Or simply just "always" use the async path. I installed the patch below which switches to the async method in case of a timeout. That should hopefully solve your use case. Stefan diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el index f7f8007..350ab3c 100644 --- a/lisp/term/xterm.el +++ b/lisp/term/xterm.el @@ -688,6 +688,10 @@ string bytes that can be copied is 3/4 of this value." ;;(xterm--init-activate-get-selection) (xterm--init-activate-set-selection)))))) +(defvar xterm-query-timeout 2 + "Seconds to wait for an answer from the terminal. +Can be nil to mean \"no timeout\".") + (defun xterm--query (query handlers &optional no-async) "Send QUERY string to the terminal and watch for a response. HANDLERS is an alist with elements of the form (STRING . FUNCTION). @@ -696,25 +696,37 @@ ;; rather annoying (bug#6758). Maybe we could always use the asynchronous ;; approach, but it's less tested. ;; FIXME: Merge the two branches. - (if (and (input-pending-p) (not no-async)) - (progn + (let ((register + (lambda (handlers) (dolist (handler handlers) (define-key input-decode-map (car handler) (lambda (&optional _prompt) - ;; Unregister the handler, since we don't expect further answers. + ;; Unregister the handler, since we don't expect + ;; further answers. (dolist (handler handlers) (define-key input-decode-map (car handler) nil)) (funcall (cdr handler)) - []))) + [])))))) + (if (and (or (null xterm-query-timeout) (input-pending-p)) + (not no-async)) + (progn + (funcall register handlers) (send-string-to-terminal query)) ;; Pending input can be mistakenly returned by the calls to - ;; read-event below. Discard it. + ;; read-event below: discard it. + (discard-input) (send-string-to-terminal query) (while handlers (let ((handler (pop handlers)) (i 0)) (while (and (< i (length (car handler))) - (let ((evt (read-event nil nil 2))) + (let ((evt (read-event nil nil xterm-query-timeout))) + (if (and (null evt) (= i 0) (not no-async)) + ;; Timeout on the first event: fallback on async. + (progn + (funcall register (cons handler handlers)) + (setq handlers nil) + nil) (or (eq evt (aref (car handler) i)) (progn (if evt (push evt unread-command-events)) nil)))) @@ -724,7 +736,7 @@ (funcall (cdr handler))) (while (> i 0) (push (aref (car handler) (setq i (1- i))) - unread-command-events))))))) + unread-command-events))))))))) (defun xterm--push-map (map basemap) ;; Use inheritance to let the main keymaps override those defaults.