emacs-devel
[Top][All Lists]
Advanced

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

Re: python-mode: make sure output is not eaten


From: Stefan Monnier
Subject: Re: python-mode: make sure output is not eaten
Date: Tue, 22 Aug 2006 02:10:02 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

> 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û 2006 14:13:46 -0400      1.41
+++ python.el   22 aoû 2006 02:08:00 -0400      
@@ -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= 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
               (/= (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= 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)))))
 
 (autoload 'comint-check-proc "comint")
 




reply via email to

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