[Python-bugs-list] Python 1.6a1 - Misc/python-mode.el not updated? (PR#264)

pinard@iro.umontreal.ca pinard@iro.umontreal.ca
Sun, 2 Apr 2000 17:22:24 -0400 (EDT)


Hello.  This is for the Python 1.6a1 release.

File `Misc/python-mode.el' still has the problem that a region, part of
a some bigger structure, may not be fed to the interpreter unless it is
left-justified first.  It is cumbersome having to explicitly left-justify a
region for sending it, every time, and then undoing the left-justification
back in its normal place once sent.

I sent the following patch was sent to the Python mailing list, a while
ago, to automate this.  I was expecting it, or any similar functionality,
to be integrated by now.  So, here it is again.

--- ./python-mode.el	Tue Aug 10 17:49:00 1999
+++ /bpi/titan/home/pinard/el/python-mode.el	Tue Feb 22 14:35:02 2000
@@ -1278,11 +1278,34 @@
 			 (format "python-%d-%d" sn pid)
 		       (format "python-%d" sn)))
 		 (make-temp-name "python-")))
-	 (file (expand-file-name temp py-temp-directory)))
-    (write-region start end file nil 'nomsg)
+	 (file (expand-file-name temp py-temp-directory))
+	 input)
+    (save-excursion
+      (let ((margin -1))
+	(goto-char start)
+	(while (and (not (zerop margin)) (< (point) end))
+	  (skip-chars-forward " \t")
+	  (let ((column (current-column)))
+	    (and (not (= (following-char) ?\n))
+		 (or (< margin 0) (< column margin))
+		 (setq margin column)))
+	  (forward-line 1))
+	(if (> margin 0)
+	    (let ((buffer (current-buffer)))
+	      (setq input (get-buffer-create
+			   (generate-new-buffer-name " *Python Input*")))
+	      (set-buffer input)
+	      (insert-buffer-substring buffer start end)
+	      (indent-rigidly (point-min) (point-max) (- margin))))))
     (cond
      ;; always run the code in its own asynchronous subprocess
      (async
+      (if (not input)
+	  (write-region start end file nil 'nomsg)
+	(save-excursion
+	  (set-buffer input)
+	  (write-region (point-min) (point-max) file nil 'nomsg))
+	(kill-buffer input))
       (let* ((buf (generate-new-buffer-name py-output-buffer))
 	     ;; TBD: a horrible hack, but why create new Custom variables?
 	     (arg (if (string-equal py-which-bufname "Python")
@@ -1295,18 +1318,30 @@
      ;; execution there.
      (proc
       ;; use the existing python shell
+      (if (not input)
+	  (write-region start end file nil 'nomsg)
+	(save-excursion
+	  (set-buffer input)
+	  (write-region (point-min) (point-max) file nil 'nomsg))
+	(kill-buffer input))
       (if (not py-file-queue)
 	  (py-execute-file proc file)
 	(message "File %s queued for execution" file))
       (setq py-file-queue (append py-file-queue (list file)))
       (setq py-exception-buffer (cons file (current-buffer))))
      (t
-      ;; TBD: a horrible hack, buy why create new Custom variables?
+      ;; TBD: a horrible hack, but why create new Custom variables?
       (let ((cmd (concat py-which-shell
 			 (if (string-equal py-which-bufname "JPython")
 			     " -" ""))))
 	;; otherwise either run it synchronously in a subprocess
-	(shell-command-on-region start end cmd py-output-buffer)
+	(if (not input)
+	    (shell-command-on-region start end cmd py-output-buffer)
+	  (save-excursion
+	    (set-buffer input)
+	    (shell-command-on-region (point-min) (point-max) cmd
+				     py-output-buffer))
+	  (kill-buffer input))
 	;; shell-command-on-region kills the output buffer if it never
 	;; existed and there's no output from the command
 	(if (not (get-buffer py-output-buffer))

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard