emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r110300: Shell output catching a la g


From: Fabián Ezequiel Gallina
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r110300: Shell output catching a la gud-gdb.
Date: Sun, 30 Sep 2012 21:53:44 -0300
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 110300
committer: Fabián Ezequiel Gallina <address@hidden>
branch nick: trunk
timestamp: Sun 2012-09-30 21:53:44 -0300
message:
  Shell output catching a la gud-gdb.
  * progmodes/python.el (python-shell-fetch-lines-in-progress)
  (python-shell-fetch-lines-string, python-shell-fetched-lines): New
  Vars.
  (python-shell-fetch-lines-filter): New function.
  (python-shell-send-string-no-output): Use them.
modified:
  lisp/ChangeLog
  lisp/progmodes/python.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-09-30 22:21:25 +0000
+++ b/lisp/ChangeLog    2012-10-01 00:53:44 +0000
@@ -1,3 +1,12 @@
+2012-10-01  Fabián Ezequiel Gallina  <address@hidden>
+
+       Shell output catching a la gud-gdb.
+       * progmodes/python.el (python-shell-fetch-lines-in-progress)
+       (python-shell-fetch-lines-string, python-shell-fetched-lines): New
+       Vars.
+       (python-shell-fetch-lines-filter): New function.
+       (python-shell-send-string-no-output): Use them.
+
 2012-09-30  Tomohiro Matsuyama  <address@hidden>
 
        * profiler.el (profiler-sampling-interval): Rename from

=== modified file 'lisp/progmodes/python.el'
--- a/lisp/progmodes/python.el  2012-09-30 20:14:02 +0000
+++ b/lisp/progmodes/python.el  2012-10-01 00:53:44 +0000
@@ -1867,31 +1867,45 @@
                 (string-match "\n[ \t].*\n?$" string))
         (comint-send-string process "\n")))))
 
+;; Shell output catching stolen from gud-gdb
+(defvar python-shell-fetch-lines-in-progress nil)
+(defvar python-shell-fetch-lines-string nil)
+(defvar python-shell-fetched-lines nil)
+
+(defun python-shell-fetch-lines-filter (string)
+  "Filter used to read the list of lines output by a command.
+STRING is the output to filter."
+  (setq string (concat python-shell-fetch-lines-string string))
+  (while (string-match "\n" string)
+    (push (substring string 0 (match-beginning 0))
+          python-shell-fetched-lines)
+    (setq string (substring string (match-end 0))))
+  (if (equal (string-match comint-prompt-regexp string) 0)
+      (progn
+        (setq python-shell-fetch-lines-in-progress nil)
+        string)
+    (progn
+      (setq python-shell-fetch-lines-string string)
+      "")))
+
 (defun python-shell-send-string-no-output (string &optional process msg)
   "Send STRING to PROCESS and inhibit output.
 When MSG is non-nil messages the first line of STRING.  Return
 the output."
-  (let* ((output-buffer "")
-         (process (or process (python-shell-get-or-create-process)))
-         (comint-preoutput-filter-functions
-          (append comint-preoutput-filter-functions
-                  '(ansi-color-filter-apply
-                    (lambda (string)
-                      (setq output-buffer (concat output-buffer string))
-                      ""))))
-         (inhibit-quit t))
+  (let ((process (or process (python-shell-get-or-create-process)))
+        (comint-preoutput-filter-functions
+         '(python-shell-fetch-lines-filter))
+        (python-shell-fetch-lines-in-progress t)
+        (inhibit-quit t))
     (or
      (with-local-quit
        (python-shell-send-string string process msg)
-       (accept-process-output process)
-       (replace-regexp-in-string
-        (if (> (length python-shell-prompt-output-regexp) 0)
-            (format "\n*%s$\\|^%s\\|\n$"
-                    python-shell-prompt-regexp
-                    (or python-shell-prompt-output-regexp ""))
-          (format "\n*$\\|^%s\\|\n$"
-                  python-shell-prompt-regexp))
-        "" output-buffer))
+       (while python-shell-fetch-lines-in-progress
+         (accept-process-output process))
+       (prog1
+           (mapconcat #'identity
+                      (reverse python-shell-fetched-lines) "\n")
+         (setq python-shell-fetched-lines nil)))
      (with-current-buffer (process-buffer process)
        (comint-interrupt-subjob)))))
 


reply via email to

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