[Python-bugs-list] Python 1.6a1 - Misc/python-mode.el not updated? (PR#264)
bwarsaw@python.org
bwarsaw@python.org
Tue, 23 May 2000 01:39:26 -0400 (EDT)
>>>>> <pinard@iro.umontreal.ca> writes:
>> My suggestion is that `C-c |' be made clever enough to discover
>> the left margin of the region under consideration, and that it
>> removes that margin while transmitting the region to the Python
>> interpreter. That would allow for using that command in a much
>> wider variety of (smaller :-) contexts.
>>>>> "SM" =3D=3D Skip Montanaro <skip@mojam.com> writes:
SM> Wouldn't it be easier to have python-mode simply insert
SM> if 1:
SM> in front of any indented block of code being sent to the
SM> interpreter?
Just goes to show you that if Guido sends me noodges me enough, I
finally respond. :)
Anyway to recap: Fran=E7ois posted a patch which fixed an annoying
behavior in python-mode when using C-c | on an indented region. Skip
countered with a proposal to just insert "if 1:" if the executing
region is indented. I think Guido liked this approach better because
it preserves stuff like triple quoted strings. I also like it better
because of TQSs and commented out regions (which may have a comment
character in column zero, but for all intents and purposes is still
indented).
In any event, here's the patch I plan to check in.
-Barry
-------------------- snip snip --------------------
Index: python-mode.el
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/python/python/dist/src/Misc/python-mode.el,v
retrieving revision 3.105
diff -c -r3.105 python-mode.el
*** python-mode.el=091999/08/10 21:49:00=093.105
--- python-mode.el=092000/05/23 05:38:07
***************
*** 1278,1288 ****
=09=09=09 (format "python-%d-%d" sn pid)
=09=09 (format "python-%d" sn)))
=09=09 (make-temp-name "python-")))
! =09 (file (expand-file-name temp py-temp-directory)))
! (write-region start end file nil 'nomsg)
(cond
;; always run the code in its own asynchronous subprocess
(async
(let* ((buf (generate-new-buffer-name py-output-buffer))
=09 ;; TBD: a horrible hack, but why create new Custom variables?=
=09 (arg (if (string-equal py-which-bufname "Python")
--- 1278,1300 ----
=09=09=09 (format "python-%d-%d" sn pid)
=09=09 (format "python-%d" sn)))
=09=09 (make-temp-name "python-")))
! =09 (file (expand-file-name temp py-temp-directory))
! =09 (cur (current-buffer))
! =09 (buf (get-buffer-create file)))
! ;; Write the contents of the buffer, watching out for indented re=
gions.
! (save-excursion
! (goto-char start)
! (when (/=3D (py-point 'bol) (py-point 'boi))
! =09(set-buffer buf)
! =09(insert "if 1:\n"))
! (insert-buffer-substring cur start end))
(cond
;; always run the code in its own asynchronous subprocess
(async
+ ;; User explicitly wants this to run in its own async subproces=
s
+ (save-excursion
+ =09(set-buffer buf)
+ =09(write-region (point-min) (point-max) file nil 'nomsg))
(let* ((buf (generate-new-buffer-name py-output-buffer))
=09 ;; TBD: a horrible hack, but why create new Custom variables?=
=09 (arg (if (string-equal py-which-bufname "Python")
***************
*** 1290,1300 ****
--- 1302,1316 ----
=09(start-process py-which-bufname buf py-which-shell arg file)
=09(pop-to-buffer buf)
=09(py-postprocess-output-buffer buf)
+ =09;; TBD: clean up the temporary file!
=09))
;; if the Python interpreter shell is running, queue it up for
;; execution there.
(proc
;; use the existing python shell
+ (save-excursion
+ =09(set-buffer buf)
+ =09(write-region (point-min) (point-max) file nil 'nomsg))
(if (not py-file-queue)
=09 (py-execute-file proc file)
=09(message "File %s queued for execution" file))
***************
*** 1306,1312 ****
=09=09=09 (if (string-equal py-which-bufname "JPython")
=09=09=09 " -" ""))))
=09;; otherwise either run it synchronously in a subprocess
! =09(shell-command-on-region start end cmd py-output-buffer)
=09;; shell-command-on-region kills the output buffer if it never
=09;; existed and there's no output from the command
=09(if (not (get-buffer py-output-buffer))
--- 1322,1331 ----
=09=09=09 (if (string-equal py-which-bufname "JPython")
=09=09=09 " -" ""))))
=09;; otherwise either run it synchronously in a subprocess
! =09(save-excursion
! =09 (set-buffer buf)
! =09 (shell-command-on-region (point-min) (point-max)
! =09=09=09=09 cmd py-output-buffer))
=09;; shell-command-on-region kills the output buffer if it never
=09;; existed and there's no output from the command
=09(if (not (get-buffer py-output-buffer))
***************
*** 1316,1322 ****
=09 (pop-to-buffer py-output-buffer)
=09 (if err-p
=09=09(pop-to-buffer py-exception-buffer)))
! =09 )))
)))
=20
=0C
--- 1335,1343 ----
=09 (pop-to-buffer py-output-buffer)
=09 (if err-p
=09=09(pop-to-buffer py-exception-buffer)))
! =09 ))
! ;; TBD: delete the buffer
! )
)))
=20
=0C