forked from mirrors/org-mode
ob-python: Remove python-mode.el support
* lisp/ob-python.el (org-babel-python-mode): Moved to ob-compat.el, and changed to a constant. (org-babel-python-initiate-session-by-key): Remove code to support python-mode.el. (org-babel-python-send-string): Renamed from `org-babel-python--send-string', turning it into a public function to accommodate ob-python-mode-mode which advises this function. Also, remove some code for python-mode.el. (org-babel-python-evaluate-session): Update calls to renamed function `org-babel-python-send-string'. * lisp/ob-compat.el (org-babel-python-mode): Moved from ob-python.el, and changed to a constant.
This commit is contained in:
parent
265e4a5747
commit
aa48c80fe1
11
etc/ORG-NEWS
11
etc/ORG-NEWS
|
@ -12,6 +12,17 @@ See the end of the file for license conditions.
|
|||
Please send Org bug reports to mailto:emacs-orgmode@gnu.org.
|
||||
|
||||
* Version 9.7 (not released yet)
|
||||
** Important announcements and breaking changes
|
||||
*** =python-mode.el (MELPA)= support in =ob-python.el= is removed
|
||||
|
||||
=python-mode.el= support has been removed from =ob-python.el=. The
|
||||
related customization =org-babel-python-mode= has been changed to a
|
||||
constant.
|
||||
|
||||
If you still want to use python-mode with ob-python, you might
|
||||
consider [[https://gitlab.com/jackkamm/ob-python-mode-mode][ob-python-mode-mode]], where the code to support python-mode
|
||||
has been ported to.
|
||||
|
||||
** New and changed options
|
||||
*** ~org-clock-x11idle-program-name~ now defaults to =xprintidle=, when available
|
||||
|
||||
|
|
|
@ -36,10 +36,6 @@
|
|||
(require 'org-macs)
|
||||
(require 'python)
|
||||
|
||||
(declare-function py-shell "ext:python-mode" (&rest args))
|
||||
(declare-function py-choose-shell "ext:python-mode" (&optional shell))
|
||||
(declare-function py-shell-send-string "ext:python-mode" (strg &optional process))
|
||||
|
||||
(defvar org-babel-tangle-lang-exts)
|
||||
(add-to-list 'org-babel-tangle-lang-exts '("python" . "py"))
|
||||
|
||||
|
@ -52,16 +48,6 @@
|
|||
:group 'org-babel
|
||||
:type 'string)
|
||||
|
||||
;; FIXME: Remove third-party `python-mode' package support in the next release.
|
||||
(defcustom org-babel-python-mode
|
||||
(if (featurep 'python-mode) 'python-mode 'python)
|
||||
"Preferred python mode for use in running python interactively.
|
||||
This will typically be either `python' or `python-mode'."
|
||||
:group 'org-babel
|
||||
:version "24.4"
|
||||
:package-version '(Org . "8.0")
|
||||
:type 'symbol)
|
||||
|
||||
(defcustom org-babel-python-hline-to "None"
|
||||
"Replace hlines in incoming tables with this when translating to python."
|
||||
:group 'org-babel
|
||||
|
@ -183,7 +169,6 @@ Emacs-lisp table, otherwise return the results as a string."
|
|||
(substring name 1 (- (length name) 1))
|
||||
name)))
|
||||
|
||||
(defvar py-which-bufname)
|
||||
(defvar python-shell-buffer-name)
|
||||
(defvar-local org-babel-python--initialized nil
|
||||
"Flag used to mark that python session has been initialized.")
|
||||
|
@ -197,8 +182,6 @@ then create. Return the initialized session."
|
|||
(cmd (if (member system-type '(cygwin windows-nt ms-dos))
|
||||
(concat org-babel-python-command " -i")
|
||||
org-babel-python-command)))
|
||||
(cond
|
||||
((eq 'python org-babel-python-mode) ; python.el
|
||||
(unless py-buffer
|
||||
(setq py-buffer (org-babel-python-with-earmuffs session)))
|
||||
(let ((python-shell-buffer-name
|
||||
|
@ -210,34 +193,14 @@ then create. Return the initialized session."
|
|||
(lambda ()
|
||||
(setq-local org-babel-python--initialized t)
|
||||
(message "I am running!!!"))
|
||||
nil 'local))))
|
||||
((and (eq 'python-mode org-babel-python-mode)
|
||||
(fboundp 'py-shell)) ; python-mode.el
|
||||
(require 'python-mode)
|
||||
;; Make sure that py-which-bufname is initialized, as otherwise
|
||||
;; it will be overwritten the first time a Python buffer is
|
||||
;; created.
|
||||
(py-choose-shell)
|
||||
;; `py-shell' creates a buffer whose name is the value of
|
||||
;; `py-which-bufname' with '*'s at the beginning and end
|
||||
(let* ((bufname (if (and py-buffer (buffer-live-p py-buffer))
|
||||
(replace-regexp-in-string ;; zap surrounding *
|
||||
"^\\*\\([^*]+\\)\\*$" "\\1" py-buffer)
|
||||
(concat "Python-" (symbol-name session))))
|
||||
(py-which-bufname bufname))
|
||||
(setq py-buffer (org-babel-python-with-earmuffs bufname))
|
||||
(py-shell nil nil t org-babel-python-command py-buffer nil nil t nil)))
|
||||
(t
|
||||
(error "No function available for running an inferior Python")))
|
||||
nil 'local)))
|
||||
;; Wait until Python initializes.
|
||||
(if (eq 'python org-babel-python-mode) ; python.el
|
||||
;; This is more reliable compared to
|
||||
;; `org-babel-comint-wait-for-output' as python may emit
|
||||
;; multiple prompts during initialization.
|
||||
(with-current-buffer py-buffer
|
||||
(while (not org-babel-python--initialized)
|
||||
(org-babel-comint-wait-for-output py-buffer)))
|
||||
(org-babel-comint-wait-for-output py-buffer))
|
||||
(setq org-babel-python-buffers
|
||||
(cons (cons session py-buffer)
|
||||
(assq-delete-all session org-babel-python-buffers)))
|
||||
|
@ -352,7 +315,7 @@ last statement in BODY, as elisp."
|
|||
raw
|
||||
(org-babel-python-table-or-string (org-trim raw)))))
|
||||
|
||||
(defun org-babel-python--send-string (session body)
|
||||
(defun org-babel-python-send-string (session body)
|
||||
"Pass BODY to the Python process in SESSION.
|
||||
Return output."
|
||||
(with-current-buffer session
|
||||
|
@ -370,12 +333,9 @@ finally:
|
|||
print('%s')"
|
||||
(org-babel-python--shift-right body 4)
|
||||
org-babel-python-eoe-indicator)))
|
||||
(if (not (eq 'python-mode org-babel-python-mode))
|
||||
(let ((python-shell-buffer-name
|
||||
(org-babel-python-without-earmuffs session)))
|
||||
(python-shell-send-string body))
|
||||
(require 'python-mode)
|
||||
(py-shell-send-string body (get-buffer-process session)))
|
||||
;; same as `python-shell-comint-end-of-output-p' in emacs-25.1+
|
||||
(while (not (string-match
|
||||
org-babel-python-eoe-indicator
|
||||
|
@ -398,12 +358,12 @@ last statement in BODY, as elisp."
|
|||
(let ((body (format org-babel-python--exec-tmpfile
|
||||
(org-babel-process-file-name
|
||||
tmp-src-file 'noquote))))
|
||||
(org-babel-python--send-string session body)))
|
||||
(org-babel-python-send-string session body)))
|
||||
(`value
|
||||
(let* ((tmp-results-file (org-babel-temp-file "python-"))
|
||||
(body (org-babel-python-format-session-value
|
||||
tmp-src-file tmp-results-file result-params)))
|
||||
(org-babel-python--send-string session body)
|
||||
(org-babel-python-send-string session body)
|
||||
(sleep-for 0 10)
|
||||
(org-babel-eval-read-file tmp-results-file)))))))
|
||||
(org-babel-result-cond result-params
|
||||
|
|
|
@ -1117,6 +1117,14 @@ context. See the individual commands for more information."
|
|||
(make-obsolete-variable 'org-latex-polyglossia-language-alist
|
||||
"set `org-latex-language-alist' instead." "9.6")
|
||||
|
||||
(defconst org-babel-python-mode 'python
|
||||
"Python mode for use in running python interactively.")
|
||||
|
||||
(make-obsolete-variable
|
||||
'org-babel-python-mode
|
||||
"Only the built-in Python mode is supported in ob-python now."
|
||||
"9.7")
|
||||
|
||||
;;;; Obsolete link types
|
||||
|
||||
(eval-after-load 'ol
|
||||
|
|
Loading…
Reference in New Issue