* Re: Python code block hangs with :session if python-mode is loaded
@ 2012-04-01 16:19 Rustom Mody
0 siblings, 0 replies; 5+ messages in thread
From: Rustom Mody @ 2012-04-01 16:19 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 248 bytes --]
At some point I tried IPython under emacs in windows and had some problems.
From what Eric is saying they may be similar to this
http://lists.gnu.org/archive/html/help-gnu-emacs/2011-05/msg00291.html
https://bugs.launchpad.net/ipython/+bug/290228
[-- Attachment #2: Type: text/html, Size: 413 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Python code block hangs with :session if python-mode is loaded
@ 2012-03-31 23:02 Richard Stanton
0 siblings, 0 replies; 5+ messages in thread
From: Richard Stanton @ 2012-03-31 23:02 UTC (permalink / raw)
To: 'emacs-orgmode@gnu.org'
> If I do not have (require 'python-mode) in my init.el, the following also
> works fine:
>
> #+begin_src python :results output :session print "%d + %d = %d" % (2, 3,
> 2+3)
> 2**5
> #+end_src
>
> #+RESULTS:
> : 2 + 3 = 5
> : 32
>
> However, if (require 'python-mode) is in my init.el file, pressing C-c C-c in
> the second code block causes Emacs to hang with the message "Executing
> python code block". I can get out by pressing C-g, but it never returns
> otherwise.
A quick follow-up, in case it's useful:
1) This is with org-mode 7.8.07, but the same occurred with 7.8.06, in both cases running under Emacs 23.0.94, and I get the same behavior under both OS X and Windows.
2) If I toggle debug-on-quit, here's what I see when I press C-g:
Debugger entered--Lisp error: (quit)
accept-process-output(#<process Python>)
(while (progn (goto-char comint-last-input-end) (not (save-excursion (and (re-search-forward (regexp-quote org-babel-python-eoe-indicator) nil t) (re-search-forward comint-prompt-regexp nil t))))) (accept-process-output (get-buffer-process (current-buffer))))
(progn (goto-char (process-mark (get-buffer-process (current-buffer)))) (let ((start (point)) (end (point-max))) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait) (while (progn (goto-char comint-last-input-end) (not (save-excursion (and (re-search-forward (regexp-quote org-babel-python-eoe-indicator) nil t) (re-search-forward comint-prompt-regexp nil t))))) (accept-process-output (get-buffer-process (current-buffer)))) (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert dangling-text))
(unwind-protect (progn (goto-char (process-mark (get-buffer-process (current-buffer)))) (let ((start (point)) (end (point-max))) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait) (while (progn (goto-char comint-last-input-end) (not (save-excursion (and (re-search-forward ... nil t) (re-search-forward comint-prompt-regexp nil t))))) (accept-process-output (get-buffer-process (current-buffer)))) (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))
(progn (fset (quote my-filt) (function* (lambda (text) (block my-filt (setq string-buffer (concat string-buffer text)))))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process (current-buffer)))) (let ((start (point)) (end (point-max))) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait) (while (progn (goto-char comint-last-input-end) (not (save-excursion (and ... ...)))) (accept-process-output (get-buffer-process (current-buffer)))) (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt))))
(unwind-protect (progn (fset (quote my-filt) (function* (lambda (text) (block my-filt (setq string-buffer (concat string-buffer text)))))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process (current-buffer)))) (let ((start (point)) (end (point-max))) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait) (while (progn (goto-char comint-last-input-end) (not (save-excursion ...))) (accept-process-output (get-buffer-process (current-buffer)))) (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))) (if --cl-letf-bound-- (fset (quote my-filt) --cl-letf-save--) (fmakunbound (quote my-filt))))
(let* ((--cl-letf-bound-- (fboundp (quote my-filt))) (--cl-letf-save-- (and --cl-letf-bound-- (symbol-function (quote my-filt))))) (unwind-protect (progn (fset (quote my-filt) (function* (lambda (text) (block my-filt (setq string-buffer ...))))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process ...))) (let ((start ...) (end ...)) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait) (while (progn (goto-char comint-last-input-end) (not ...)) (accept-process-output (get-buffer-process ...))) (goto-char (process-mark (get-buffer-process ...))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))) (if --cl-letf-bound-- (fset (quote my-filt) --cl-letf-save--) (fmakunbound (quote my-filt)))))
(letf (((symbol-function (quote my-filt)) (function* (lambda (text) (block my-filt (setq string-buffer (concat string-buffer text))))))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process (current-buffer)))) (let ((start (point)) (end (point-max))) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait) (while (progn (goto-char comint-last-input-end) (not (save-excursion (and ... ...)))) (accept-process-output (get-buffer-process (current-buffer)))) (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt))))
(letf* (((symbol-function (quote my-filt)) (function* (lambda (text) (block my-filt (setq string-buffer (concat string-buffer text))))))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process (current-buffer)))) (let ((start (point)) (end (point-max))) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait) (while (progn (goto-char comint-last-input-end) (not (save-excursion (and ... ...)))) (accept-process-output (get-buffer-process (current-buffer)))) (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt))))
(flet ((my-filt (text) (setq string-buffer (concat string-buffer text)))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process (current-buffer)))) (let ((start (point)) (end (point-max))) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait) (while (progn (goto-char comint-last-input-end) (not (save-excursion (and ... ...)))) (accept-process-output (get-buffer-process (current-buffer)))) (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt))))
(let ((string-buffer "") dangling-text raw) (flet ((my-filt (text) (setq string-buffer (concat string-buffer text)))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process (current-buffer)))) (let ((start (point)) (end (point-max))) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait) (while (progn (goto-char comint-last-input-end) (not (save-excursion ...))) (accept-process-output (get-buffer-process (current-buffer)))) (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))) (if (and t body (string-match (replace-regexp-in-string "\n" "[
\n]+" (regexp-quote (or body ""))) string-buffer)) (setq raw (substring string-buffer (match-end 0)))) (split-string string-buffer comint-prompt-regexp))
(progn (unless (org-babel-comint-buffer-livep session) (error "buffer %s doesn't exist or has no process" session)) (set-buffer session) (let ((string-buffer "") dangling-text raw) (flet ((my-filt (text) (setq string-buffer (concat string-buffer text)))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process ...))) (let ((start ...) (end ...)) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait) (while (progn (goto-char comint-last-input-end) (not ...)) (accept-process-output (get-buffer-process ...))) (goto-char (process-mark (get-buffer-process ...))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))) (if (and t body (string-match (replace-regexp-in-string "\n" "[
\n]+" (regexp-quote (or body ""))) string-buffer)) (setq raw (substring string-buffer (match-end 0)))) (split-string string-buffer comint-prompt-regexp)))
(unwind-protect (progn (unless (org-babel-comint-buffer-livep session) (error "buffer %s doesn't exist or has no process" session)) (set-buffer session) (let ((string-buffer "") dangling-text raw) (flet ((my-filt (text) (setq string-buffer (concat string-buffer text)))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark ...)) (let (... ...) (setq dangling-text ...) (delete-region start end)) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait) (while (progn ... ...) (accept-process-output ...)) (goto-char (process-mark ...)) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))) (if (and t body (string-match (replace-regexp-in-string "\n" "[
\n]+" (regexp-quote ...)) string-buffer)) (setq raw (substring string-buffer (match-end 0)))) (split-string string-buffer comint-prompt-regexp))) (set-match-data save-match-data-internal (quote evaporate)))
(let ((save-match-data-internal (match-data))) (unwind-protect (progn (unless (org-babel-comint-buffer-livep session) (error "buffer %s doesn't exist or has no process" session)) (set-buffer session) (let ((string-buffer "") dangling-text raw) (flet ((my-filt (text) (setq string-buffer ...))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char ...) (let ... ... ...) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait) (while ... ...) (goto-char ...) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))) (if (and t body (string-match (replace-regexp-in-string "\n" "[
\n]+" ...) string-buffer)) (setq raw (substring string-buffer (match-end 0)))) (split-string string-buffer comint-prompt-regexp))) (set-match-data save-match-data-internal (quote evaporate))))
(save-match-data (unless (org-babel-comint-buffer-livep session) (error "buffer %s doesn't exist or has no process" session)) (set-buffer session) (let ((string-buffer "") dangling-text raw) (flet ((my-filt (text) (setq string-buffer (concat string-buffer text)))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process ...))) (let ((start ...) (end ...)) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait) (while (progn (goto-char comint-last-input-end) (not ...)) (accept-process-output (get-buffer-process ...))) (goto-char (process-mark (get-buffer-process ...))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))) (if (and t body (string-match (replace-regexp-in-string "\n" "[
\n]+" (regexp-quote (or body ""))) string-buffer)) (setq raw (substring string-buffer (match-end 0)))) (split-string string-buffer comint-prompt-regexp)))
(save-excursion (save-match-data (unless (org-babel-comint-buffer-livep session) (error "buffer %s doesn't exist or has no process" session)) (set-buffer session) (let ((string-buffer "") dangling-text raw) (flet ((my-filt (text) (setq string-buffer (concat string-buffer text)))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark ...)) (let (... ...) (setq dangling-text ...) (delete-region start end)) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait) (while (progn ... ...) (accept-process-output ...)) (goto-char (process-mark ...)) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))) (if (and t body (string-match (replace-regexp-in-string "\n" "[
\n]+" (regexp-quote ...)) string-buffer)) (setq raw (substring string-buffer (match-end 0)))) (split-string string-buffer comint-prompt-regexp))))
(org-babel-comint-in-buffer session (let ((string-buffer "") dangling-text raw) (flet ((my-filt (text) (setq string-buffer (concat string-buffer text)))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process ...))) (let ((start ...) (end ...)) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait) (while (progn (goto-char comint-last-input-end) (not ...)) (accept-process-output (get-buffer-process ...))) (goto-char (process-mark (get-buffer-process ...))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))) (if (and t body (string-match (replace-regexp-in-string "\n" "[
\n]+" (regexp-quote (or body ""))) string-buffer)) (setq raw (substring string-buffer (match-end 0)))) (split-string string-buffer comint-prompt-regexp)))
(org-babel-comint-with-output (session org-babel-python-eoe-indicator t body) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait))
(butlast (org-babel-comint-with-output (session org-babel-python-eoe-indicator t body) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait)) 2)
(mapconcat (function org-babel-trim) (butlast (org-babel-comint-with-output (session org-babel-python-eoe-indicator t body) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait)) 2) "\n")
(cond ((eql result-type (quote output)) (mapconcat (function org-babel-trim) (butlast (org-babel-comint-with-output (session org-babel-python-eoe-indicator t body) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait)) 2) "\n")) ((eql result-type (quote value)) (let ((tmp-file (org-babel-temp-file "python-"))) (org-babel-comint-with-output (session org-babel-python-eoe-indicator nil body) (let ((comint-process-echoes nil)) (input-body body) (dump-last-value tmp-file (member "pp" result-params)) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait))) (org-babel-eval-read-file tmp-file))))
(case result-type (output (mapconcat (function org-babel-trim) (butlast (org-babel-comint-with-output (session org-babel-python-eoe-indicator t body) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait)) 2) "\n")) (value (let ((tmp-file (org-babel-temp-file "python-"))) (org-babel-comint-with-output (session org-babel-python-eoe-indicator nil body) (let ((comint-process-echoes nil)) (input-body body) (dump-last-value tmp-file (member "pp" result-params)) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait))) (org-babel-eval-read-file tmp-file))))
((lambda (results) (unless (string= (substring org-babel-python-eoe-indicator 1 -1) results) (if (or (member "code" result-params) (member "pp" result-params) (and (member "output" result-params) (not (member "table" result-params)))) results (org-babel-python-table-or-string results)))) (case result-type (output (mapconcat (function org-babel-trim) (butlast (org-babel-comint-with-output (session org-babel-python-eoe-indicator t body) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait)) 2) "\n")) (value (let ((tmp-file (org-babel-temp-file "python-"))) (org-babel-comint-with-output (session org-babel-python-eoe-indicator nil body) (let ((comint-process-echoes nil)) (input-body body) (dump-last-value tmp-file (member "pp" result-params)) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait))) (org-babel-eval-read-file tmp-file)))))
(progn (fset (quote input-body) (function* (lambda (body) (block input-body (mapc (lambda (line) (insert line) (send-wait)) (split-string body "[
\n]")) (send-wait))))) ((lambda (results) (unless (string= (substring org-babel-python-eoe-indicator 1 -1) results) (if (or (member "code" result-params) (member "pp" result-params) (and (member "output" result-params) (not ...))) results (org-babel-python-table-or-string results)))) (case result-type (output (mapconcat (function org-babel-trim) (butlast (org-babel-comint-with-output (session org-babel-python-eoe-indicator t body) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait)) 2) "\n")) (value (let ((tmp-file (org-babel-temp-file "python-"))) (org-babel-comint-with-output (session org-babel-python-eoe-indicator nil body) (let (...) (input-body body) (dump-last-value tmp-file ...) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait))) (org-babel-eval-read-file tmp-file))))))
(unwind-protect (progn (fset (quote input-body) (function* (lambda (body) (block input-body (mapc (lambda ... ... ...) (split-string body "[
\n]")) (send-wait))))) ((lambda (results) (unless (string= (substring org-babel-python-eoe-indicator 1 -1) results) (if (or (member "code" result-params) (member "pp" result-params) (and ... ...)) results (org-babel-python-table-or-string results)))) (case result-type (output (mapconcat (function org-babel-trim) (butlast (org-babel-comint-with-output ... ... ... ... ... ...) 2) "\n")) (value (let ((tmp-file ...)) (org-babel-comint-with-output (session org-babel-python-eoe-indicator nil body) (let ... ... ... ... ... ... ...)) (org-babel-eval-read-file tmp-file)))))) (if --cl-letf-bound-- (fset (quote input-body) --cl-letf-save--) (fmakunbound (quote input-body))))
(let* ((--cl-letf-bound-- (fboundp (quote input-body))) (--cl-letf-save-- (and --cl-letf-bound-- (symbol-function (quote input-body))))) (unwind-protect (progn (fset (quote input-body) (function* (lambda (body) (block input-body (mapc ... ...) (send-wait))))) ((lambda (results) (unless (string= (substring org-babel-python-eoe-indicator 1 -1) results) (if (or ... ... ...) results (org-babel-python-table-or-string results)))) (case result-type (output (mapconcat (function org-babel-trim) (butlast ... 2) "\n")) (value (let (...) (org-babel-comint-with-output ... ...) (org-babel-eval-read-file tmp-file)))))) (if --cl-letf-bound-- (fset (quote input-body) --cl-letf-save--) (fmakunbound (quote input-body)))))
(letf (((symbol-function (quote input-body)) (function* (lambda (body) (block input-body (mapc (lambda ... ... ...) (split-string body "[
\n]")) (send-wait)))))) ((lambda (results) (unless (string= (substring org-babel-python-eoe-indicator 1 -1) results) (if (or (member "code" result-params) (member "pp" result-params) (and (member "output" result-params) (not ...))) results (org-babel-python-table-or-string results)))) (case result-type (output (mapconcat (function org-babel-trim) (butlast (org-babel-comint-with-output (session org-babel-python-eoe-indicator t body) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait)) 2) "\n")) (value (let ((tmp-file (org-babel-temp-file "python-"))) (org-babel-comint-with-output (session org-babel-python-eoe-indicator nil body) (let (...) (input-body body) (dump-last-value tmp-file ...) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait))) (org-babel-eval-read-file tmp-file))))))
(progn (fset (quote dump-last-value) (function* (lambda (tmp-file pp) (block dump-last-value (mapc (lambda (statement) (insert statement) (send-wait)) (if pp (list "import pprint" ...) (list ...))))))) (letf (((symbol-function (quote input-body)) (function* (lambda (body) (block input-body (mapc ... ...) (send-wait)))))) ((lambda (results) (unless (string= (substring org-babel-python-eoe-indicator 1 -1) results) (if (or (member "code" result-params) (member "pp" result-params) (and ... ...)) results (org-babel-python-table-or-string results)))) (case result-type (output (mapconcat (function org-babel-trim) (butlast (org-babel-comint-with-output ... ... ... ... ... ...) 2) "\n")) (value (let ((tmp-file ...)) (org-babel-comint-with-output (session org-babel-python-eoe-indicator nil body) (let ... ... ... ... ... ... ...)) (org-babel-eval-read-file tmp-file)))))))
(unwind-protect (progn (fset (quote dump-last-value) (function* (lambda (tmp-file pp) (block dump-last-value (mapc (lambda ... ... ...) (if pp ... ...)))))) (letf (((symbol-function (quote input-body)) (function* (lambda (body) (block input-body ... ...))))) ((lambda (results) (unless (string= (substring org-babel-python-eoe-indicator 1 -1) results) (if (or ... ... ...) results (org-babel-python-table-or-string results)))) (case result-type (output (mapconcat (function org-babel-trim) (butlast ... 2) "\n")) (value (let (...) (org-babel-comint-with-output ... ...) (org-babel-eval-read-file tmp-file))))))) (if --cl-letf-bound-- (fset (quote dump-last-value) --cl-letf-save--) (fmakunbound (quote dump-last-value))))
(let* ((--cl-letf-bound-- (fboundp (quote dump-last-value))) (--cl-letf-save-- (and --cl-letf-bound-- (symbol-function (quote dump-last-value))))) (unwind-protect (progn (fset (quote dump-last-value) (function* (lambda (tmp-file pp) (block dump-last-value (mapc ... ...))))) (letf (((symbol-function (quote input-body)) (function* (lambda ... ...)))) ((lambda (results) (unless (string= ... results) (if ... results ...))) (case result-type (output (mapconcat ... ... "\n")) (value (let ... ... ...)))))) (if --cl-letf-bound-- (fset (quote dump-last-value) --cl-letf-save--) (fmakunbound (quote dump-last-value)))))
(letf (((symbol-function (quote dump-last-value)) (function* (lambda (tmp-file pp) (block dump-last-value (mapc (lambda ... ... ...) (if pp ... ...))))))) (letf (((symbol-function (quote input-body)) (function* (lambda (body) (block input-body (mapc ... ...) (send-wait)))))) ((lambda (results) (unless (string= (substring org-babel-python-eoe-indicator 1 -1) results) (if (or (member "code" result-params) (member "pp" result-params) (and ... ...)) results (org-babel-python-table-or-string results)))) (case result-type (output (mapconcat (function org-babel-trim) (butlast (org-babel-comint-with-output ... ... ... ... ... ...) 2) "\n")) (value (let ((tmp-file ...)) (org-babel-comint-with-output (session org-babel-python-eoe-indicator nil body) (let ... ... ... ... ... ... ...)) (org-babel-eval-read-file tmp-file)))))))
(progn (fset (quote send-wait) (function* (lambda nil (block send-wait (comint-send-input nil t) (sleep-for 0 5))))) (letf (((symbol-function (quote dump-last-value)) (function* (lambda (tmp-file pp) (block dump-last-value (mapc ... ...)))))) (letf (((symbol-function (quote input-body)) (function* (lambda (body) (block input-body ... ...))))) ((lambda (results) (unless (string= (substring org-babel-python-eoe-indicator 1 -1) results) (if (or ... ... ...) results (org-babel-python-table-or-string results)))) (case result-type (output (mapconcat (function org-babel-trim) (butlast ... 2) "\n")) (value (let (...) (org-babel-comint-with-output ... ...) (org-babel-eval-read-file tmp-file))))))))
(unwind-protect (progn (fset (quote send-wait) (function* (lambda nil (block send-wait (comint-send-input nil t) (sleep-for 0 5))))) (letf (((symbol-function (quote dump-last-value)) (function* (lambda (tmp-file pp) (block dump-last-value ...))))) (letf (((symbol-function (quote input-body)) (function* (lambda ... ...)))) ((lambda (results) (unless (string= ... results) (if ... results ...))) (case result-type (output (mapconcat ... ... "\n")) (value (let ... ... ...))))))) (if --cl-letf-bound-- (fset (quote send-wait) --cl-letf-save--) (fmakunbound (quote send-wait))))
(let* ((--cl-letf-bound-- (fboundp (quote send-wait))) (--cl-letf-save-- (and --cl-letf-bound-- (symbol-function (quote send-wait))))) (unwind-protect (progn (fset (quote send-wait) (function* (lambda nil (block send-wait (comint-send-input nil t) (sleep-for 0 5))))) (letf (((symbol-function (quote dump-last-value)) (function* (lambda ... ...)))) (letf (((symbol-function ...) (function* ...))) ((lambda (results) (unless ... ...)) (case result-type (output ...) (value ...)))))) (if --cl-letf-bound-- (fset (quote send-wait) --cl-letf-save--) (fmakunbound (quote send-wait)))))
(letf (((symbol-function (quote send-wait)) (function* (lambda nil (block send-wait (comint-send-input nil t) (sleep-for 0 5)))))) (letf (((symbol-function (quote dump-last-value)) (function* (lambda (tmp-file pp) (block dump-last-value (mapc ... ...)))))) (letf (((symbol-function (quote input-body)) (function* (lambda (body) (block input-body ... ...))))) ((lambda (results) (unless (string= (substring org-babel-python-eoe-indicator 1 -1) results) (if (or ... ... ...) results (org-babel-python-table-or-string results)))) (case result-type (output (mapconcat (function org-babel-trim) (butlast ... 2) "\n")) (value (let (...) (org-babel-comint-with-output ... ...) (org-babel-eval-read-file tmp-file))))))))
(letf* (((symbol-function (quote send-wait)) (function* (lambda nil (block send-wait (comint-send-input nil t) (sleep-for 0 5))))) ((symbol-function (quote dump-last-value)) (function* (lambda (tmp-file pp) (block dump-last-value (mapc (lambda ... ... ...) (if pp ... ...)))))) ((symbol-function (quote input-body)) (function* (lambda (body) (block input-body (mapc (lambda ... ... ...) (split-string body "[
\n]")) (send-wait)))))) ((lambda (results) (unless (string= (substring org-babel-python-eoe-indicator 1 -1) results) (if (or (member "code" result-params) (member "pp" result-params) (and (member "output" result-params) (not ...))) results (org-babel-python-table-or-string results)))) (case result-type (output (mapconcat (function org-babel-trim) (butlast (org-babel-comint-with-output (session org-babel-python-eoe-indicator t body) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait)) 2) "\n")) (value (let ((tmp-file (org-babel-temp-file "python-"))) (org-babel-comint-with-output (session org-babel-python-eoe-indicator nil body) (let (...) (input-body body) (dump-last-value tmp-file ...) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait))) (org-babel-eval-read-file tmp-file))))))
(flet ((send-wait nil (comint-send-input nil t) (sleep-for 0 5)) (dump-last-value (tmp-file pp) (mapc (lambda (statement) (insert statement) (send-wait)) (if pp (list "import pprint" (format "open('%s', 'w').write(pprint.pformat(_))" (org-babel-process-file-name tmp-file ...))) (list (format "open('%s', 'w').write(str(_))" (org-babel-process-file-name tmp-file ...)))))) (input-body (body) (mapc (lambda (line) (insert line) (send-wait)) (split-string body "[
\n]")) (send-wait))) ((lambda (results) (unless (string= (substring org-babel-python-eoe-indicator 1 -1) results) (if (or (member "code" result-params) (member "pp" result-params) (and (member "output" result-params) (not ...))) results (org-babel-python-table-or-string results)))) (case result-type (output (mapconcat (function org-babel-trim) (butlast (org-babel-comint-with-output (session org-babel-python-eoe-indicator t body) (input-body body) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait)) 2) "\n")) (value (let ((tmp-file (org-babel-temp-file "python-"))) (org-babel-comint-with-output (session org-babel-python-eoe-indicator nil body) (let (...) (input-body body) (dump-last-value tmp-file ...) (send-wait) (send-wait) (insert org-babel-python-eoe-indicator) (send-wait))) (org-babel-eval-read-file tmp-file))))))
org-babel-python-evaluate-session(#<buffer *Python*> "print \"%d + %d = %d\" % (2, 3, 2+3)\n2**5" output ("output" "replace"))
(if session (org-babel-python-evaluate-session session body result-type result-params) (org-babel-python-evaluate-external-process body result-type result-params preamble))
org-babel-python-evaluate(#<buffer *Python*> "print \"%d + %d = %d\" % (2, 3, 2+3)\n2**5" output ("output" "replace") nil)
(let* ((session (org-babel-python-initiate-session (cdr (assoc :session params)))) (result-params (cdr (assoc :result-params params))) (result-type (cdr (assoc :result-type params))) (return-val (when (and (eq result-type (quote value)) (not session)) (cdr (assoc :return params)))) (preamble (cdr (assoc :preamble params))) (full-body (org-babel-expand-body:generic (concat body (if return-val (format "return %s" return-val) "")) params (org-babel-variable-assignments:python params))) (result (org-babel-python-evaluate session full-body result-type result-params preamble))) (org-babel-reassemble-table result (org-babel-pick-name (cdr (assoc :colname-names params)) (cdr (assoc :colnames params))) (org-babel-pick-name (cdr (assoc :rowname-names params)) (cdr (assoc :rownames params)))))
org-babel-execute:python("print \"%d + %d = %d\" % (2, 3, 2+3)\n2**5" ((:comments . "") (:shebang . "") (:cache . "no") (:padline . "") (:noweb . "no") (:tangle . "no") (:exports . "code") (:results . "replace output") (:hlines . "no") (:padnewline . "yes") (:session) (:result-type . output) (:result-params "output" "replace") (:rowname-names) (:colname-names)))
funcall(org-babel-execute:python "print \"%d + %d = %d\" % (2, 3, 2+3)\n2**5" ((:comments . "") (:shebang . "") (:cache . "no") (:padline . "") (:noweb . "no") (:tangle . "no") (:exports . "code") (:results . "replace output") (:hlines . "no") (:padnewline . "yes") (:session) (:result-type . output) (:result-params "output" "replace") (:rowname-names) (:colname-names)))
((lambda (result) (if (and (eq (cdr (assoc :result-type params)) (quote value)) (or (member "vector" result-params) (member "table" result-params)) (not (listp result))) (list (list result)) result)) (funcall cmd body params))
(setq result ((lambda (result) (if (and (eq (cdr (assoc :result-type params)) (quote value)) (or (member "vector" result-params) (member "table" result-params)) (not (listp result))) (list (list result)) result)) (funcall cmd body params)))
(if (and (not arg) new-hash (equal new-hash old-hash)) (save-excursion (goto-char (org-babel-where-is-src-block-result nil info)) (end-of-line 1) (forward-char 1) (setq result (org-babel-read-result)) (message (replace-regexp-in-string "%" "%%" (format "%S" result))) result) (message "executing %s code block%s..." (capitalize lang) (if (nth 4 info) (format " (%s)" (nth 4 info)) "")) (setq result ((lambda (result) (if (and (eq (cdr ...) (quote value)) (or (member "vector" result-params) (member "table" result-params)) (not (listp result))) (list (list result)) result)) (funcall cmd body params))) (when (cdr (assoc :file params)) (when result (with-temp-file (cdr (assoc :file params)) (insert (org-babel-format-result result (cdr (assoc :sep ...)))))) (setq result (cdr (assoc :file params)))) (org-babel-insert-result result result-params info new-hash indent lang) (run-hooks (quote org-babel-after-execute-hook)) result)
(progn (fset (quote call-process-region) (function* (lambda (&rest args) (block call-process-region (apply (quote org-babel-tramp-handle-call-process-region) args))))) (flet ((lang-check (f) (let ((f (intern ...))) (when (fboundp f) f)))) (setq cmd (or (lang-check lang) (lang-check (symbol-name (cdr (assoc lang org-src-lang-modes)))) (error "No org-babel-execute function for %s!" lang)))) (if (and (not arg) new-hash (equal new-hash old-hash)) (save-excursion (goto-char (org-babel-where-is-src-block-result nil info)) (end-of-line 1) (forward-char 1) (setq result (org-babel-read-result)) (message (replace-regexp-in-string "%" "%%" (format "%S" result))) result) (message "executing %s code block%s..." (capitalize lang) (if (nth 4 info) (format " (%s)" (nth 4 info)) "")) (setq result ((lambda (result) (if (and (eq ... ...) (or ... ...) (not ...)) (list (list result)) result)) (funcall cmd body params))) (when (cdr (assoc :file params)) (when result (with-temp-file (cdr (assoc :file params)) (insert (org-babel-format-result result (cdr ...))))) (setq result (cdr (assoc :file params)))) (org-babel-insert-result result result-params info new-hash indent lang) (run-hooks (quote org-babel-after-execute-hook)) result))
(unwind-protect (progn (fset (quote call-process-region) (function* (lambda (&rest args) (block call-process-region (apply (quote org-babel-tramp-handle-call-process-region) args))))) (flet ((lang-check (f) (let ((f ...)) (when (fboundp f) f)))) (setq cmd (or (lang-check lang) (lang-check (symbol-name (cdr ...))) (error "No org-babel-execute function for %s!" lang)))) (if (and (not arg) new-hash (equal new-hash old-hash)) (save-excursion (goto-char (org-babel-where-is-src-block-result nil info)) (end-of-line 1) (forward-char 1) (setq result (org-babel-read-result)) (message (replace-regexp-in-string "%" "%%" (format "%S" result))) result) (message "executing %s code block%s..." (capitalize lang) (if (nth 4 info) (format " (%s)" (nth 4 info)) "")) (setq result ((lambda (result) (if (and ... ... ...) (list ...) result)) (funcall cmd body params))) (when (cdr (assoc :file params)) (when result (with-temp-file (cdr (assoc :file params)) (insert (org-babel-format-result result ...)))) (setq result (cdr (assoc :file params)))) (org-babel-insert-result result result-params info new-hash indent lang) (run-hooks (quote org-babel-after-execute-hook)) result)) (if --cl-letf-bound-- (fset (quote call-process-region) --cl-letf-save--) (fmakunbound (quote call-process-region))))
(let* ((--cl-letf-bound-- (fboundp (quote call-process-region))) (--cl-letf-save-- (and --cl-letf-bound-- (symbol-function (quote call-process-region))))) (unwind-protect (progn (fset (quote call-process-region) (function* (lambda (&rest args) (block call-process-region (apply ... args))))) (flet ((lang-check (f) (let (...) (when ... f)))) (setq cmd (or (lang-check lang) (lang-check (symbol-name ...)) (error "No org-babel-execute function for %s!" lang)))) (if (and (not arg) new-hash (equal new-hash old-hash)) (save-excursion (goto-char (org-babel-where-is-src-block-result nil info)) (end-of-line 1) (forward-char 1) (setq result (org-babel-read-result)) (message (replace-regexp-in-string "%" "%%" (format "%S" result))) result) (message "executing %s code block%s..." (capitalize lang) (if (nth 4 info) (format " (%s)" (nth 4 info)) "")) (setq result ((lambda (result) (if ... ... result)) (funcall cmd body params))) (when (cdr (assoc :file params)) (when result (with-temp-file (cdr ...) (insert ...))) (setq result (cdr (assoc :file params)))) (org-babel-insert-result result result-params info new-hash indent lang) (run-hooks (quote org-babel-after-execute-hook)) result)) (if --cl-letf-bound-- (fset (quote call-process-region) --cl-letf-save--) (fmakunbound (quote call-process-region)))))
(letf (((symbol-function (quote call-process-region)) (function* (lambda (&rest args) (block call-process-region (apply (quote org-babel-tramp-handle-call-process-region) args)))))) (flet ((lang-check (f) (let ((f (intern ...))) (when (fboundp f) f)))) (setq cmd (or (lang-check lang) (lang-check (symbol-name (cdr (assoc lang org-src-lang-modes)))) (error "No org-babel-execute function for %s!" lang)))) (if (and (not arg) new-hash (equal new-hash old-hash)) (save-excursion (goto-char (org-babel-where-is-src-block-result nil info)) (end-of-line 1) (forward-char 1) (setq result (org-babel-read-result)) (message (replace-regexp-in-string "%" "%%" (format "%S" result))) result) (message "executing %s code block%s..." (capitalize lang) (if (nth 4 info) (format " (%s)" (nth 4 info)) "")) (setq result ((lambda (result) (if (and (eq ... ...) (or ... ...) (not ...)) (list (list result)) result)) (funcall cmd body params))) (when (cdr (assoc :file params)) (when result (with-temp-file (cdr (assoc :file params)) (insert (org-babel-format-result result (cdr ...))))) (setq result (cdr (assoc :file params)))) (org-babel-insert-result result result-params info new-hash indent lang) (run-hooks (quote org-babel-after-execute-hook)) result))
(letf* (((symbol-function (quote call-process-region)) (function* (lambda (&rest args) (block call-process-region (apply (quote org-babel-tramp-handle-call-process-region) args)))))) (flet ((lang-check (f) (let ((f (intern ...))) (when (fboundp f) f)))) (setq cmd (or (lang-check lang) (lang-check (symbol-name (cdr (assoc lang org-src-lang-modes)))) (error "No org-babel-execute function for %s!" lang)))) (if (and (not arg) new-hash (equal new-hash old-hash)) (save-excursion (goto-char (org-babel-where-is-src-block-result nil info)) (end-of-line 1) (forward-char 1) (setq result (org-babel-read-result)) (message (replace-regexp-in-string "%" "%%" (format "%S" result))) result) (message "executing %s code block%s..." (capitalize lang) (if (nth 4 info) (format " (%s)" (nth 4 info)) "")) (setq result ((lambda (result) (if (and (eq ... ...) (or ... ...) (not ...)) (list (list result)) result)) (funcall cmd body params))) (when (cdr (assoc :file params)) (when result (with-temp-file (cdr (assoc :file params)) (insert (org-babel-format-result result (cdr ...))))) (setq result (cdr (assoc :file params)))) (org-babel-insert-result result result-params info new-hash indent lang) (run-hooks (quote org-babel-after-execute-hook)) result))
(flet ((call-process-region (&rest args) (apply (quote org-babel-tramp-handle-call-process-region) args))) (flet ((lang-check (f) (let ((f (intern ...))) (when (fboundp f) f)))) (setq cmd (or (lang-check lang) (lang-check (symbol-name (cdr (assoc lang org-src-lang-modes)))) (error "No org-babel-execute function for %s!" lang)))) (if (and (not arg) new-hash (equal new-hash old-hash)) (save-excursion (goto-char (org-babel-where-is-src-block-result nil info)) (end-of-line 1) (forward-char 1) (setq result (org-babel-read-result)) (message (replace-regexp-in-string "%" "%%" (format "%S" result))) result) (message "executing %s code block%s..." (capitalize lang) (if (nth 4 info) (format " (%s)" (nth 4 info)) "")) (setq result ((lambda (result) (if (and (eq ... ...) (or ... ...) (not ...)) (list (list result)) result)) (funcall cmd body params))) (when (cdr (assoc :file params)) (when result (with-temp-file (cdr (assoc :file params)) (insert (org-babel-format-result result (cdr ...))))) (setq result (cdr (assoc :file params)))) (org-babel-insert-result result result-params info new-hash indent lang) (run-hooks (quote org-babel-after-execute-hook)) result))
(unwind-protect (flet ((call-process-region (&rest args) (apply (quote org-babel-tramp-handle-call-process-region) args))) (flet ((lang-check (f) (let ((f ...)) (when (fboundp f) f)))) (setq cmd (or (lang-check lang) (lang-check (symbol-name (cdr ...))) (error "No org-babel-execute function for %s!" lang)))) (if (and (not arg) new-hash (equal new-hash old-hash)) (save-excursion (goto-char (org-babel-where-is-src-block-result nil info)) (end-of-line 1) (forward-char 1) (setq result (org-babel-read-result)) (message (replace-regexp-in-string "%" "%%" (format "%S" result))) result) (message "executing %s code block%s..." (capitalize lang) (if (nth 4 info) (format " (%s)" (nth 4 info)) "")) (setq result ((lambda (result) (if (and ... ... ...) (list ...) result)) (funcall cmd body params))) (when (cdr (assoc :file params)) (when result (with-temp-file (cdr (assoc :file params)) (insert (org-babel-format-result result ...)))) (setq result (cdr (assoc :file params)))) (org-babel-insert-result result result-params info new-hash indent lang) (run-hooks (quote org-babel-after-execute-hook)) result)) (setq call-process-region (quote org-babel-call-process-region-original)))
(let* ((lang (nth 0 info)) (params (if params (org-babel-process-params (org-babel-merge-params (nth 2 info) params)) (nth 2 info))) (cache\? (and (not arg) (cdr (assoc :cache params)) (string= "yes" (cdr (assoc :cache params))))) (result-params (cdr (assoc :result-params params))) (new-hash (when cache\? (org-babel-sha1-hash info))) (old-hash (when cache\? (org-babel-current-result-hash))) (body (setf (nth 1 info) (if (org-babel-noweb-p params :eval) (org-babel-expand-noweb-references info) (nth 1 info)))) (dir (cdr (assoc :dir params))) (default-directory (or (and dir (file-name-as-directory dir)) default-directory)) (org-babel-call-process-region-original (if (boundp (quote org-babel-call-process-region-original)) org-babel-call-process-region-original (symbol-function (quote call-process-region)))) (indent (car (last info))) result cmd) (unwind-protect (flet ((call-process-region (&rest args) (apply (quote org-babel-tramp-handle-call-process-region) args))) (flet ((lang-check (f) (let (...) (when ... f)))) (setq cmd (or (lang-check lang) (lang-check (symbol-name ...)) (error "No org-babel-execute function for %s!" lang)))) (if (and (not arg) new-hash (equal new-hash old-hash)) (save-excursion (goto-char (org-babel-where-is-src-block-result nil info)) (end-of-line 1) (forward-char 1) (setq result (org-babel-read-result)) (message (replace-regexp-in-string "%" "%%" (format "%S" result))) result) (message "executing %s code block%s..." (capitalize lang) (if (nth 4 info) (format " (%s)" (nth 4 info)) "")) (setq result ((lambda (result) (if ... ... result)) (funcall cmd body params))) (when (cdr (assoc :file params)) (when result (with-temp-file (cdr ...) (insert ...))) (setq result (cdr (assoc :file params)))) (org-babel-insert-result result result-params info new-hash indent lang) (run-hooks (quote org-babel-after-execute-hook)) result)) (setq call-process-region (quote org-babel-call-process-region-original))))
(progn (let* ((lang (nth 0 info)) (params (if params (org-babel-process-params (org-babel-merge-params (nth 2 info) params)) (nth 2 info))) (cache\? (and (not arg) (cdr (assoc :cache params)) (string= "yes" (cdr (assoc :cache params))))) (result-params (cdr (assoc :result-params params))) (new-hash (when cache\? (org-babel-sha1-hash info))) (old-hash (when cache\? (org-babel-current-result-hash))) (body (setf (nth 1 info) (if (org-babel-noweb-p params :eval) (org-babel-expand-noweb-references info) (nth 1 info)))) (dir (cdr (assoc :dir params))) (default-directory (or (and dir (file-name-as-directory dir)) default-directory)) (org-babel-call-process-region-original (if (boundp (quote org-babel-call-process-region-original)) org-babel-call-process-region-original (symbol-function (quote call-process-region)))) (indent (car (last info))) result cmd) (unwind-protect (flet ((call-process-region (&rest args) (apply (quote org-babel-tramp-handle-call-process-region) args))) (flet ((lang-check (f) (let ... ...))) (setq cmd (or (lang-check lang) (lang-check ...) (error "No org-babel-execute function for %s!" lang)))) (if (and (not arg) new-hash (equal new-hash old-hash)) (save-excursion (goto-char (org-babel-where-is-src-block-result nil info)) (end-of-line 1) (forward-char 1) (setq result (org-babel-read-result)) (message (replace-regexp-in-string "%" "%%" ...)) result) (message "executing %s code block%s..." (capitalize lang) (if (nth 4 info) (format " (%s)" ...) "")) (setq result ((lambda ... ...) (funcall cmd body params))) (when (cdr (assoc :file params)) (when result (with-temp-file ... ...)) (setq result (cdr ...))) (org-babel-insert-result result result-params info new-hash indent lang) (run-hooks (quote org-babel-after-execute-hook)) result)) (setq call-process-region (quote org-babel-call-process-region-original)))))
(if (org-babel-confirm-evaluate (let ((i info)) (setf (nth 2 i) (org-babel-merge-params (nth 2 info) params)) i)) (progn (let* ((lang (nth 0 info)) (params (if params (org-babel-process-params (org-babel-merge-params ... params)) (nth 2 info))) (cache\? (and (not arg) (cdr (assoc :cache params)) (string= "yes" (cdr ...)))) (result-params (cdr (assoc :result-params params))) (new-hash (when cache\? (org-babel-sha1-hash info))) (old-hash (when cache\? (org-babel-current-result-hash))) (body (setf (nth 1 info) (if (org-babel-noweb-p params :eval) (org-babel-expand-noweb-references info) (nth 1 info)))) (dir (cdr (assoc :dir params))) (default-directory (or (and dir (file-name-as-directory dir)) default-directory)) (org-babel-call-process-region-original (if (boundp (quote org-babel-call-process-region-original)) org-babel-call-process-region-original (symbol-function (quote call-process-region)))) (indent (car (last info))) result cmd) (unwind-protect (flet ((call-process-region (&rest args) (apply ... args))) (flet ((lang-check ... ...)) (setq cmd (or ... ... ...))) (if (and (not arg) new-hash (equal new-hash old-hash)) (save-excursion (goto-char ...) (end-of-line 1) (forward-char 1) (setq result ...) (message ...) result) (message "executing %s code block%s..." (capitalize lang) (if ... ... "")) (setq result (... ...)) (when (cdr ...) (when result ...) (setq result ...)) (org-babel-insert-result result result-params info new-hash indent lang) (run-hooks (quote org-babel-after-execute-hook)) result)) (setq call-process-region (quote org-babel-call-process-region-original))))))
(when (org-babel-confirm-evaluate (let ((i info)) (setf (nth 2 i) (org-babel-merge-params (nth 2 info) params)) i)) (let* ((lang (nth 0 info)) (params (if params (org-babel-process-params (org-babel-merge-params (nth 2 info) params)) (nth 2 info))) (cache\? (and (not arg) (cdr (assoc :cache params)) (string= "yes" (cdr (assoc :cache params))))) (result-params (cdr (assoc :result-params params))) (new-hash (when cache\? (org-babel-sha1-hash info))) (old-hash (when cache\? (org-babel-current-result-hash))) (body (setf (nth 1 info) (if (org-babel-noweb-p params :eval) (org-babel-expand-noweb-references info) (nth 1 info)))) (dir (cdr (assoc :dir params))) (default-directory (or (and dir (file-name-as-directory dir)) default-directory)) (org-babel-call-process-region-original (if (boundp (quote org-babel-call-process-region-original)) org-babel-call-process-region-original (symbol-function (quote call-process-region)))) (indent (car (last info))) result cmd) (unwind-protect (flet ((call-process-region (&rest args) (apply (quote org-babel-tramp-handle-call-process-region) args))) (flet ((lang-check (f) (let ... ...))) (setq cmd (or (lang-check lang) (lang-check ...) (error "No org-babel-execute function for %s!" lang)))) (if (and (not arg) new-hash (equal new-hash old-hash)) (save-excursion (goto-char (org-babel-where-is-src-block-result nil info)) (end-of-line 1) (forward-char 1) (setq result (org-babel-read-result)) (message (replace-regexp-in-string "%" "%%" ...)) result) (message "executing %s code block%s..." (capitalize lang) (if (nth 4 info) (format " (%s)" ...) "")) (setq result ((lambda ... ...) (funcall cmd body params))) (when (cdr (assoc :file params)) (when result (with-temp-file ... ...)) (setq result (cdr ...))) (org-babel-insert-result result result-params info new-hash indent lang) (run-hooks (quote org-babel-after-execute-hook)) result)) (setq call-process-region (quote org-babel-call-process-region-original)))))
(let ((info (or info (org-babel-get-src-block-info)))) (when (org-babel-confirm-evaluate (let ((i info)) (setf (nth 2 i) (org-babel-merge-params (nth 2 info) params)) i)) (let* ((lang (nth 0 info)) (params (if params (org-babel-process-params (org-babel-merge-params ... params)) (nth 2 info))) (cache\? (and (not arg) (cdr (assoc :cache params)) (string= "yes" (cdr ...)))) (result-params (cdr (assoc :result-params params))) (new-hash (when cache\? (org-babel-sha1-hash info))) (old-hash (when cache\? (org-babel-current-result-hash))) (body (setf (nth 1 info) (if (org-babel-noweb-p params :eval) (org-babel-expand-noweb-references info) (nth 1 info)))) (dir (cdr (assoc :dir params))) (default-directory (or (and dir (file-name-as-directory dir)) default-directory)) (org-babel-call-process-region-original (if (boundp (quote org-babel-call-process-region-original)) org-babel-call-process-region-original (symbol-function (quote call-process-region)))) (indent (car (last info))) result cmd) (unwind-protect (flet ((call-process-region (&rest args) (apply ... args))) (flet ((lang-check ... ...)) (setq cmd (or ... ... ...))) (if (and (not arg) new-hash (equal new-hash old-hash)) (save-excursion (goto-char ...) (end-of-line 1) (forward-char 1) (setq result ...) (message ...) result) (message "executing %s code block%s..." (capitalize lang) (if ... ... "")) (setq result (... ...)) (when (cdr ...) (when result ...) (setq result ...)) (org-babel-insert-result result result-params info new-hash indent lang) (run-hooks (quote org-babel-after-execute-hook)) result)) (setq call-process-region (quote org-babel-call-process-region-original))))))
org-babel-execute-src-block(nil ("python" "print \"%d + %d = %d\" % (2, 3, 2+3)\n2**5" ((:comments . "") (:shebang . "") (:cache . "no") (:padline . "") (:noweb . "no") (:tangle . "no") (:exports . "code") (:results . "replace output") (:hlines . "no") (:padnewline . "yes") (:session) (:result-type . output) (:result-params "output" "replace") (:rowname-names) (:colname-names)) "" nil 0))
(progn (org-babel-eval-wipe-error-buffer) (org-babel-execute-src-block current-prefix-arg info) t)
(if info (progn (org-babel-eval-wipe-error-buffer) (org-babel-execute-src-block current-prefix-arg info) t) nil)
(let ((info (org-babel-get-src-block-info))) (if info (progn (org-babel-eval-wipe-error-buffer) (org-babel-execute-src-block current-prefix-arg info) t) nil))
org-babel-execute-src-block-maybe()
(or (org-babel-execute-src-block-maybe) (org-babel-lob-execute-maybe))
org-babel-execute-maybe()
(if org-babel-no-eval-on-ctrl-c-ctrl-c nil (org-babel-execute-maybe))
(unless org-babel-no-eval-on-ctrl-c-ctrl-c (org-babel-execute-maybe))
org-babel-execute-safely-maybe()
run-hook-with-args-until-success(org-babel-execute-safely-maybe)
(cond ((or (and (boundp (quote org-clock-overlays)) org-clock-overlays) org-occur-highlights org-latex-fragment-image-overlays) (and (boundp (quote org-clock-overlays)) (org-clock-remove-overlays)) (org-remove-occur-highlights) (org-remove-latex-fragment-image-overlays) (message "Temporary highlights/overlays removed from current buffer")) ((and (local-variable-p (quote org-finish-function) (current-buffer)) (fboundp org-finish-function)) (funcall org-finish-function)) ((run-hook-with-args-until-success (quote org-ctrl-c-ctrl-c-hook))) ((org-in-regexp org-ts-regexp-both) (org-timestamp-change 0 (quote day))) ((or (looking-at org-property-start-re) (org-at-property-p)) (call-interactively (quote org-property-action))) ((org-at-target-p) (call-interactively (quote org-update-radio-target-regexp))) ((and (org-in-regexp "\\[\\([0-9]*%\\|[0-9]*/[0-9]*\\)\\]") (or (org-at-heading-p) (org-at-item-p))) (call-interactively (quote org-update-statistics-cookies))) ((org-at-heading-p) (call-interactively (quote org-set-tags))) ((org-at-table\.el-p) (message "Use C-c ' to edit table.el tables")) ((org-at-table-p) (org-table-maybe-eval-formula) (if arg (call-interactively (quote org-table-recalculate)) (org-table-maybe-recalculate-line)) (call-interactively (quote org-table-align)) (orgtbl-send-table (quote maybe))) ((or (org-footnote-at-reference-p) (org-footnote-at-definition-p)) (call-interactively (quote org-footnote-action))) ((org-at-item-checkbox-p) (let* ((cbox (match-string 1)) (struct (org-list-struct)) (old-struct (copy-tree struct)) (parents (org-list-parents-alist struct)) (orderedp (org-entry-get nil "ORDERED")) (firstp (= (org-list-get-top-point struct) (point-at-bol))) block-item) (let ((new-box (cond (... "[-]") (... nil) (... "[ ]") (t "[X]")))) (if (and firstp arg) (mapc (lambda (pos) (org-list-set-checkbox pos struct new-box)) (org-list-get-all-items (point-at-bol) struct (org-list-prevs-alist struct))) (org-list-set-checkbox (point-at-bol) struct new-box))) (org-list-struct-fix-ind struct parents 2) (org-list-struct-fix-item-end struct) (let ((prevs (org-list-prevs-alist struct))) (org-list-struct-fix-bul struct prevs) (org-list-struct-fix-ind struct parents) (setq block-item (org-list-struct-fix-box struct parents prevs orderedp))) (org-list-struct-apply-struct struct old-struct) (org-update-checkbox-count-maybe) (when block-item (message "Checkboxes were removed due to unchecked box at line %d" (org-current-line block-item))) (when firstp (org-list-send-list (quote maybe))))) ((org-at-item-p) (let* ((struct (org-list-struct)) (firstp (= (org-list-get-top-point struct) (point-at-bol))) old-struct) (when arg (setq old-struct (copy-tree struct)) (if firstp (mapc (lambda (pos) (unless ... ...)) (org-list-get-all-items (point-at-bol) struct (org-list-prevs-alist struct))) (org-list-set-checkbox (point-at-bol) struct "[ ]"))) (org-list-write-struct struct (org-list-parents-alist struct) old-struct) (when arg (org-update-checkbox-count-maybe)) (when firstp (org-list-send-list (quote maybe))))) ((save-excursion (beginning-of-line 1) (looking-at org-dblock-start-re)) (beginning-of-line 1) (save-excursion (org-update-dblock))) ((save-excursion (beginning-of-line 1) (looking-at "[ ]*#\\+\\([A-Z]+\\)")) (cond ((equal (match-string 1) "TBLFM") (save-excursion (beginning-of-line 1) (skip-chars-backward "
\n ") (if (org-at-table-p) (org-call-with-arg (quote org-table-recalculate) (or arg t))))) (t (let ((org-inhibit-startup-visibility-stuff t) (org-startup-align-all-tables nil)) (when (boundp (quote org-table-coordinate-overlays)) (mapc (quote delete-overlay) org-table-coordinate-overlays) (setq org-table-coordinate-overlays nil)) (org-save-outline-visibility (quote use-markers) (org-mode-restart))) (message "Local setup has been refreshed")))) ((org-clock-update-time-maybe)) (t (or (run-hook-with-args-until-success (quote org-ctrl-c-ctrl-c-final-hook)) (error "C-c C-c can do nothing useful at this location"))))
(let ((org-enable-table-editor t)) (cond ((or (and (boundp (quote org-clock-overlays)) org-clock-overlays) org-occur-highlights org-latex-fragment-image-overlays) (and (boundp (quote org-clock-overlays)) (org-clock-remove-overlays)) (org-remove-occur-highlights) (org-remove-latex-fragment-image-overlays) (message "Temporary highlights/overlays removed from current buffer")) ((and (local-variable-p (quote org-finish-function) (current-buffer)) (fboundp org-finish-function)) (funcall org-finish-function)) ((run-hook-with-args-until-success (quote org-ctrl-c-ctrl-c-hook))) ((org-in-regexp org-ts-regexp-both) (org-timestamp-change 0 (quote day))) ((or (looking-at org-property-start-re) (org-at-property-p)) (call-interactively (quote org-property-action))) ((org-at-target-p) (call-interactively (quote org-update-radio-target-regexp))) ((and (org-in-regexp "\\[\\([0-9]*%\\|[0-9]*/[0-9]*\\)\\]") (or (org-at-heading-p) (org-at-item-p))) (call-interactively (quote org-update-statistics-cookies))) ((org-at-heading-p) (call-interactively (quote org-set-tags))) ((org-at-table\.el-p) (message "Use C-c ' to edit table.el tables")) ((org-at-table-p) (org-table-maybe-eval-formula) (if arg (call-interactively (quote org-table-recalculate)) (org-table-maybe-recalculate-line)) (call-interactively (quote org-table-align)) (orgtbl-send-table (quote maybe))) ((or (org-footnote-at-reference-p) (org-footnote-at-definition-p)) (call-interactively (quote org-footnote-action))) ((org-at-item-checkbox-p) (let* ((cbox (match-string 1)) (struct (org-list-struct)) (old-struct (copy-tree struct)) (parents (org-list-parents-alist struct)) (orderedp (org-entry-get nil "ORDERED")) (firstp (= (org-list-get-top-point struct) (point-at-bol))) block-item) (let ((new-box (cond ... ... ... ...))) (if (and firstp arg) (mapc (lambda ... ...) (org-list-get-all-items ... struct ...)) (org-list-set-checkbox (point-at-bol) struct new-box))) (org-list-struct-fix-ind struct parents 2) (org-list-struct-fix-item-end struct) (let ((prevs (org-list-prevs-alist struct))) (org-list-struct-fix-bul struct prevs) (org-list-struct-fix-ind struct parents) (setq block-item (org-list-struct-fix-box struct parents prevs orderedp))) (org-list-struct-apply-struct struct old-struct) (org-update-checkbox-count-maybe) (when block-item (message "Checkboxes were removed due to unchecked box at line %d" (org-current-line block-item))) (when firstp (org-list-send-list (quote maybe))))) ((org-at-item-p) (let* ((struct (org-list-struct)) (firstp (= (org-list-get-top-point struct) (point-at-bol))) old-struct) (when arg (setq old-struct (copy-tree struct)) (if firstp (mapc (lambda ... ...) (org-list-get-all-items ... struct ...)) (org-list-set-checkbox (point-at-bol) struct "[ ]"))) (org-list-write-struct struct (org-list-parents-alist struct) old-struct) (when arg (org-update-checkbox-count-maybe)) (when firstp (org-list-send-list (quote maybe))))) ((save-excursion (beginning-of-line 1) (looking-at org-dblock-start-re)) (beginning-of-line 1) (save-excursion (org-update-dblock))) ((save-excursion (beginning-of-line 1) (looking-at "[ ]*#\\+\\([A-Z]+\\)")) (cond ((equal (match-string 1) "TBLFM") (save-excursion (beginning-of-line 1) (skip-chars-backward "
\n ") (if (org-at-table-p) (org-call-with-arg ... ...)))) (t (let ((org-inhibit-startup-visibility-stuff t) (org-startup-align-all-tables nil)) (when (boundp ...) (mapc ... org-table-coordinate-overlays) (setq org-table-coordinate-overlays nil)) (org-save-outline-visibility (quote use-markers) (org-mode-restart))) (message "Local setup has been refreshed")))) ((org-clock-update-time-maybe)) (t (or (run-hook-with-args-until-success (quote org-ctrl-c-ctrl-c-final-hook)) (error "C-c C-c can do nothing useful at this location")))))
org-ctrl-c-ctrl-c(nil)
call-interactively(org-ctrl-c-ctrl-c nil nil)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Python code block hangs with :session if python-mode is loaded
@ 2012-03-31 22:40 Richard Stanton
2012-04-01 12:50 ` Eric Schulte
0 siblings, 1 reply; 5+ messages in thread
From: Richard Stanton @ 2012-03-31 22:40 UTC (permalink / raw)
To: 'emacs-orgmode@gnu.org'
I have python-mode (latest version from Launchpad) set up to handle python editing in Emacs.
Using orgmode, the following code block runs fine if Ipress C-c C-c, producing the (correct) output shown:
#+begin_src python :results output
print "%d + %d = %d" % (2, 3, 2+3)
2**5
#+end_src
#+RESULTS:
: 2 + 3 = 5
If I do not have (require 'python-mode) in my init.el, the following also works fine:
#+begin_src python :results output :session
print "%d + %d = %d" % (2, 3, 2+3)
2**5
#+end_src
#+RESULTS:
: 2 + 3 = 5
: 32
However, if (require 'python-mode) is in my init.el file, pressing C-c C-c in the second code block causes Emacs to hang with the message "Executing python code block". I can get out by pressing C-g, but it never returns otherwise.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Python code block hangs with :session if python-mode is loaded
2012-03-31 22:40 Richard Stanton
@ 2012-04-01 12:50 ` Eric Schulte
2012-04-01 15:37 ` Richard Stanton
0 siblings, 1 reply; 5+ messages in thread
From: Eric Schulte @ 2012-04-01 12:50 UTC (permalink / raw)
To: Richard Stanton; +Cc: 'emacs-orgmode@gnu.org'
Richard Stanton <stanton@haas.berkeley.edu> writes:
> I have python-mode (latest version from Launchpad) set up to handle python editing in Emacs.
>
> Using orgmode, the following code block runs fine if Ipress C-c C-c, producing the (correct) output shown:
>
> #+begin_src python :results output
> print "%d + %d = %d" % (2, 3, 2+3)
> 2**5
> #+end_src
>
> #+RESULTS:
> : 2 + 3 = 5
>
> If I do not have (require 'python-mode) in my init.el, the following also works fine:
>
> #+begin_src python :results output :session
> print "%d + %d = %d" % (2, 3, 2+3)
> 2**5
> #+end_src
>
> #+RESULTS:
> : 2 + 3 = 5
> : 32
>
> However, if (require 'python-mode) is in my init.el file, pressing C-c
> C-c in the second code block causes Emacs to hang with the message
> "Executing python code block". I can get out by pressing C-g, but it
> never returns otherwise.
>
Hi Richard,
The above executes without problem for me regardless of whether
python-mode has been explicitly loaded. I have python mode py-version
"5.1.0" on my machine. My guess is that python-mode changed the session
prompt in such a way that Babel can not tell when execution has
completed. I have the following in my *Python* session buffer after
execution [1], what are the contents of your *Python* session buffer
after you have C-g'd out of the loop?
Best,
Footnotes:
[1] *Python*
>>> print "%d + %d = %d" % (2, 3, 2+3)
2 + 3 = 5
2**5
>>>
32
>>>
>>>
>>> 'org_babel_python_eoe'
>>> 'org_babel_python_eoe'
>>> print "%d + %d = %d" % (2, 3, 2+3)
2 + 3 = 5
>>> 2**5
32
>>>
>>>
>>>
>>> 'org_babel_python_eoe'
'org_babel_python_eoe'
>>>
--
Eric Schulte
http://cs.unm.edu/~eschulte/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Python code block hangs with :session if python-mode is loaded
2012-04-01 12:50 ` Eric Schulte
@ 2012-04-01 15:37 ` Richard Stanton
0 siblings, 0 replies; 5+ messages in thread
From: Richard Stanton @ 2012-04-01 15:37 UTC (permalink / raw)
To: Eric Schulte; +Cc: 'emacs-orgmode@gnu.org'
> The above executes without problem for me regardless of whether python-
> mode has been explicitly loaded. I have python mode py-version "5.1.0" on
> my machine. My guess is that python-mode changed the session prompt in
> such a way that Babel can not tell when execution has completed. I have
> the following in my *Python* session buffer after execution [1], what are
> the contents of your *Python* session buffer after you have C-g'd out of the
> loop?
>
> Best,
>
> Footnotes:
> [1] *Python*
> >>> print "%d + %d = %d" % (2, 3, 2+3)
> 2 + 3 = 5
> 2**5
> >>>
> 32
> >>>
> >>>
> >>> 'org_babel_python_eoe'
> >>> 'org_babel_python_eoe'
> >>> print "%d + %d = %d" % (2, 3, 2+3)
> 2 + 3 = 5
> >>> 2**5
> 32
> >>>
> >>>
> >>>
> >>> 'org_babel_python_eoe'
> 'org_babel_python_eoe'
> >>>
> --
> Eric Schulte
> http://cs.unm.edu/~eschulte/
Hi Eric.
I'm using python-mode 6.0.6, and have it set up to use ipython as the default python shell. Here's what I see:
--------------
Enthought Python Distribution -- www.enthought.com
Python 2.7.2 |EPD 7.2-2 (32-bit)| (default, Sep 14 2011, 11:02:05) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.
IPython 0.12 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]:
In [2]: print "%d + %d = %d" % (2, 3, 2+3)
2**5
2 + 3 = 5
In [3]: Out[3]: 32
In [4]:
In [4]:
In [4]: 'org_babel_python_eoe'
In [4]: Out[4]: 'org_babel_python_eoe'
In [5]:
----------------
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-04-01 16:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-01 16:19 Python code block hangs with :session if python-mode is loaded Rustom Mody
-- strict thread matches above, loose matches on Subject: below --
2012-03-31 23:02 Richard Stanton
2012-03-31 22:40 Richard Stanton
2012-04-01 12:50 ` Eric Schulte
2012-04-01 15:37 ` Richard Stanton
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).