emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r117620: * lisp/progmodes/python.el: Shell output ca


From: Fabián Ezequiel Gallina
Subject: [Emacs-diffs] trunk r117620: * lisp/progmodes/python.el: Shell output capture enhancements.
Date: Fri, 01 Aug 2014 00:18:39 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117620
revision-id: address@hidden
parent: address@hidden
committer: Fabián Ezequiel Gallina <address@hidden>
branch nick: trunk
timestamp: Thu 2014-07-31 21:18:19 -0300
message:
  * lisp/progmodes/python.el: Shell output capture enhancements.
  (python-shell-accept-process-output): New function.
  (inferior-python-mode)
  (python-shell-send-setup-code): Use it.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/progmodes/python.el       python.el-20091113204419-o5vbwnq5f7feedwu-3008
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2014-07-30 17:13:16 +0000
+++ b/lisp/ChangeLog    2014-08-01 00:18:19 +0000
@@ -1,3 +1,10 @@
+2014-07-31  Fabián Ezequiel Gallina  <address@hidden>
+
+       * progmodes/python.el: Shell output capture enhancements.
+       (python-shell-accept-process-output): New function.
+       (inferior-python-mode)
+       (python-shell-send-setup-code): Use it.
+
 2014-07-30  Christophe Deleuze  <address@hidden>  (tiny change)
 
        * calendar/icalendar.el (icalendar--decode-isodatetime): Use

=== modified file 'lisp/progmodes/python.el'
--- a/lisp/progmodes/python.el  2014-07-28 21:07:10 +0000
+++ b/lisp/progmodes/python.el  2014-08-01 00:18:19 +0000
@@ -2129,6 +2129,27 @@
     directory package package)
    (python-shell-get-process)))
 
+(defun python-shell-accept-process-output (process &optional timeout regexp)
+  "Accept PROCESS output with TIMEOUT until REGEXP is found.
+Optional argument TIMEOUT is the timeout argument to
+`accept-process-output' calls.  Optional argument REGEXP
+overrides the regexp to match the end of output, defaults to
+`comint-prompt-regexp.'.  Returns non-nil when output was
+properly captured.
+
+This utility is useful in situations where the output may be
+received in chunks, since `accept-process-output' gives no
+guarantees they will be grabbed in a single call.  An example use
+case for this would be the CPython shell start-up, where the
+banner and the initial prompt are received separetely."
+  (let ((regexp (or regexp comint-prompt-regexp)))
+    (catch 'found
+      (while t
+        (when (not (accept-process-output process timeout))
+          (throw 'found nil))
+        (when (looking-back regexp)
+          (throw 'found t))))))
+
 (defun python-shell-comint-end-of-output-p (output)
   "Return non-nil if OUTPUT is ends with input prompt."
   (string-match
@@ -2380,13 +2401,8 @@
   (when python-shell-font-lock-enable
     (python-shell-font-lock-turn-on))
   (compilation-shell-minor-mode 1)
-  ;; Ensure all the output is accepted before running any hooks.
-  (accept-process-output (get-buffer-process (current-buffer)))
-  ;; At this point, all process output should have been received, but
-  ;; on GNU/Linux, calling `python-shell-internal-send-string' without
-  ;; a running internal shell fails to grab output properly unless
-  ;; this `sit-for' is in place.
-  (sit-for 0.1 t))
+  (python-shell-accept-process-output
+   (get-buffer-process (current-buffer))))
 
 (defun python-shell-make-comint (cmd proc-name &optional pop internal)
   "Create a Python shell comint buffer.
@@ -2790,8 +2806,8 @@
                 python-shell-setup-codes
                 "\n\n")
                "\n\nprint ('python.el: sent setup code')")))
-    (python-shell-send-string code)
-    (accept-process-output process)))
+    (python-shell-send-string code process)
+    (python-shell-accept-process-output process)))
 
 (add-hook 'inferior-python-mode-hook
           #'python-shell-send-setup-code)


reply via email to

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