From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: python-mode: make sure output is not eaten Date: Tue, 22 Aug 2006 02:10:02 -0400 Message-ID: <87lkphe20n.fsf-monnier+emacs@gnu.org> References: <20060821220052.494C.SLAWOMIR.NOWACZYK.847@student.lu.se> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1156227041 24727 80.91.229.2 (22 Aug 2006 06:10:41 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 22 Aug 2006 06:10:41 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Aug 22 08:10:37 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GFPSv-0002d5-KM for ged-emacs-devel@m.gmane.org; Tue, 22 Aug 2006 08:10:21 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GFPSu-0007AP-SR for ged-emacs-devel@m.gmane.org; Tue, 22 Aug 2006 02:10:20 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GFPSi-00079F-EW for emacs-devel@gnu.org; Tue, 22 Aug 2006 02:10:08 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GFPSg-00076D-P5 for emacs-devel@gnu.org; Tue, 22 Aug 2006 02:10:08 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GFPSg-000762-KP for emacs-devel@gnu.org; Tue, 22 Aug 2006 02:10:06 -0400 Original-Received: from [12.46.53.131] (helo=alfajor) by monty-python.gnu.org with esmtp (Exim 4.52) id 1GFPaE-0001FB-FR for emacs-devel@gnu.org; Tue, 22 Aug 2006 02:17:54 -0400 Original-Received: by alfajor (Postfix, from userid 1000) id 025DC1C159; Tue, 22 Aug 2006 02:10:02 -0400 (EDT) Original-To: Slawomir Nowaczyk In-Reply-To: <20060821220052.494C.SLAWOMIR.NOWACZYK.847@student.lu.se> (Slawomir Nowaczyk's message of "Mon, 21 Aug 2006 22:16:56 +0200") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) 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:58686 Archived-At: > the following path makes sure python-mode doesn't eat output coming > from the Python process. Without it, calling python-send-buffer on > a Python script which produces output, such as simple Does the patch below give good results as well? Stefan --- python.el 20 ao=FB 2006 14:13:46 -0400 1.41 +++ python.el 22 ao=FB 2006 02:08:00 -0400=09 @@ -1264,9 +1264,25 @@ (when python-preoutput-leftover (setq s (concat python-preoutput-leftover s)) (setq python-preoutput-leftover nil)) + (let ((start 0) + (res "")) + ;; First process whole lines. + (while (string-match "\n" s start) + (let ((line (substring s start (setq start (match-end 0))))) + (cond + ((string=3D line "_emacs_ok\n") + (when python-preoutput-continuation + (funcall python-preoutput-continuation) + (setq python-preoutput-continuation nil))) + ((string-match "\\`_emacs_out \\(.*\\)\n" line) + (setq python-preoutput-result (match-string 1 line))) + (t (setq res (concat res line)))))) + ;; Then process the remaining partial line. + (unless (zerop start) (setq s (substring s start))) (cond ((and (string-match (rx string-start (repeat 3 (any ".>")) " " string-end) - s) + s start) + ;; Isn't that just (not (bolp)) ? --Stef (/=3D (let ((inhibit-field-text-motion t)) (line-beginning-position)) (point))) @@ -1274,23 +1290,14 @@ ;; What is this all about, exactly? --Stef ;; (if (and (eq ?. (aref s 0))) ;; (accept-process-output (get-buffer-process (current-buffer)) 1)) - "") - ((string=3D s "_emacs_ok\n") - (when python-preoutput-continuation - (funcall python-preoutput-continuation) - (setq python-preoutput-continuation nil)) - "") - ((string-match "_emacs_out \\(.*\\)\n" s) - (setq python-preoutput-result (match-string 1 s)) - "") - ((string-match ".*\n" s) - s) + ;; Throw away this prompt-like thingy. + res) ((or (eq t (compare-strings s nil nil "_emacs_ok\n" nil (length s))) (let ((end (min (length "_emacs_out ") (length s)))) (eq t (compare-strings s nil end "_emacs_out " nil end)))) (setq python-preoutput-leftover s) - "") - (t s))) + res) + (t (concat res s))))) =20 (autoload 'comint-check-proc "comint") =20