Problem with Emacs mode, at start only
Alex
alex at somewhere.round.here
Wed Feb 23 17:25:26 EST 2000
Maybe this will work a little better. The py-execute-file procedure
gets the interpreter to create a file "file.executed" just before
execfile'ing "file". Then the output filter only deletes "file" if
"file.executed" exists, and in that case cleans up py-file-queue and
deletes "file.executed, as well.
Open-source-means-you-get-to-see-more-of-my-trial-and-error-than-
you-want-to'ly yrs
Alex.
;; Python subprocess utilities and filters
(defun py-execute-file (proc filename)
"Send to Python interpreter process PROC \"execfile('FILENAME')\".
Make that process's buffer visible and force display. Also make
comint believe the user typed this string so that
`kill-output-from-shell' does The Right Thing."
(let ((curbuf (current-buffer))
(procbuf (process-buffer proc))
; (comint-scroll-to-bottom-on-output t)
(msg (format "## working on region in file %s...\n" filename))
(cmd (format (concat
"open('%s.executed', 'w').write(''); "
"execfile('%s')\n")
filename filename)))
(unwind-protect
(save-excursion
(set-buffer procbuf)
(goto-char (point-max))
(move-marker (process-mark proc) (point))
(funcall (process-filter proc) proc msg))
(set-buffer curbuf))
(process-send-string proc cmd)))
(defun py-comint-output-filter-function (string)
"Watch output for Python prompt and exec next file waiting in queue.
This function is appropriate for `comint-output-filter-functions'."
;; TBD: this should probably use split-string
(when (and (or (string-equal string ">>> ")
(and (>= (length string) 5)
(string-equal (substring string -5) "\n>>> ")))
py-file-queue)
;; (py-safe (delete-file (car py-file-queue)))
(let* ((current-file (car py-file-queue))
(execution-flag-file (concat current-file ".executed")))
(if (file-exists-p execution-flag-file)
(progn
(py-safe (delete-file current-file))
(py-safe (delete-file execution-flag-file)
(setq py-file-queue (cdr py-file-queue))
(if py-file-queue
(let ((pyproc (get-buffer-process (current-buffer))))
(py-execute-file pyproc (car py-file-queue))))
))
))))
More information about the Python-list
mailing list