Re: [O] [PATCH] session with python-mode.el complains of void py-toggle-shells
Hi Andreas, Andreas Röhler writes: > ob-python.el patch again I applied a more complete patch, turning `org-babel-python-command' and `org-babel-python-mode' into defcustoms. `org-babel-python-mode' will not default to 'python-mode until 'python-mode is featured, so users will typically want to set this variable, exposing it as a defcustom is useful IMO. Thanks for the patch! -- Bastien
Re: [O] [PATCH] session with python-mode.el complains of void py-toggle-shells
Am 24.01.2013 15:10, schrieb Bastien: Hi Andreas, Andreas Röhler writes: Okay, I'll dig into. For the moment: assume this code should not be needed, python-mode.el should act that all. But let me have a closer look, Great, thanks a lot! ob-python.el patch again better provision for XEmacs users commit 0fd2ac7ede3d7c8602a0a71fe1dc1678773baee4 Author: Andreas Roehler Date: Fri Feb 22 09:08:28 2013 +0100 Depend default python-mode from existing feature The former (if (featurep 'xemacs) 'python-mode 'python) makes a wrong assumption, as python-mode.el provides 'python-mode which does not depend from use of XEmacs python-mode.el should provide a defcustom still to choose environment TINYCHANGE diff --git a/lisp/ob-python.el b/lisp/ob-python.el index 02d762c..c9118e9 100644 --- a/lisp/ob-python.el +++ b/lisp/ob-python.el @@ -43,7 +43,7 @@ (defvar org-babel-python-command "python" "Name of the command for executing Python code.") -(defvar org-babel-python-mode (if (featurep 'xemacs) 'python-mode 'python) +(defvar org-babel-python-mode (if (or (featurep 'python-mode)(featurep 'xemacs)) 'python-mode 'python) "Preferred python mode for use in running python interactively. This will typically be either 'python or 'python-mode.")
Re: [O] [PATCH] session with python-mode.el complains of void py-toggle-shells
Am 24.01.2013 15:10, schrieb Bastien: Hi Andreas, Andreas Röhler writes: Okay, I'll dig into. For the moment: assume this code should not be needed, python-mode.el should act that all. But let me have a closer look, Great, thanks a lot! So let's start with this... BTW, being deeply impressed by org-mode and babel in special. commit e7a5839b5a10d0a27e26b8f1d16296f4c20a1350 Author: Andreas Roehler Date: Thu Feb 21 20:46:49 2013 +0100 Depend default python-mode from existing feature The former (if (featurep 'xemacs) 'python-mode 'python) makes a wrong assumption, as python-mode.el provides 'python-mode which does not depend from use of XEmacs A next step should enable users to choose environment via defcustom diff --git a/lisp/ob-python.el b/lisp/ob-python.el index 02d762c..1b3b892 100644 --- a/lisp/ob-python.el +++ b/lisp/ob-python.el @@ -43,7 +43,7 @@ (defvar org-babel-python-command "python" "Name of the command for executing Python code.") -(defvar org-babel-python-mode (if (featurep 'xemacs) 'python-mode 'python) +(defvar 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.")
Re: [O] [PATCH] session with python-mode.el complains of void py-toggle-shells
Hi Andreas, Andreas Röhler writes: > Okay, I'll dig into. > > For the moment: assume this code should not be needed, > python-mode.el should act that all. But let me have a closer look, Great, thanks a lot! -- Bastien
Re: [O] [PATCH] session with python-mode.el complains of void py-toggle-shells
Am 23.01.2013 14:04, schrieb Bastien: Hi Myles, thanks for digging into this. I'm copying Andreas as the maintainer of python-mode.el. Myles English writes: --- lisp/ob-python.el +++ lisp/ob-python.el @@ -32,7 +32,7 @@ (declare-function org-remove-indentation "org" ) (declare-function py-shell "ext:python-mode" (&optional argprompt)) -(declare-function py-toggle-shells "ext:python-mode" (arg)) +(declare-function py-toggle-shell "ext:python-mode" (arg)) Hi Bastien, If this function's name changed, there should be an alias in python-mode.el. right (declare-function run-python "ext:python" (&optional cmd noshow new)) (defvar org-babel-tangle-lang-exts) @@ -162,16 +162,17 @@ then create. Return the initialized session." ;; Make sure that py-which-bufname is initialized, as otherwise ;; it will be overwritten the first time a Python buffer is ;; created. - (py-toggle-shells py-default-interpreter) + (py-toggle-shell py-default-interpreter) ;; `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 python-buffer (buffer-live-p python-buffer)) (replace-regexp-in-string ;; zap surrounding * "^\\*\\([^*]+\\)\\*$" "\\1" python-buffer) (concat "Python-" (symbol-name session - (py-which-bufname bufname)) - (py-shell) - (setq python-buffer (concat "*" bufname "*" + (py-buffer-name bufname)) + (setq python-buffer (concat "*" bufname "*")) + (py-shell nil nil nil nil nil python-buffer) + )) The docstring of py-shell doesn't say much about why python-buffer would be needed as an argument here. Is it so? If yes, we need to make this compatible with previous versions of python-mode.el. (The argument PY-BUFFER-NAME is not documented in latest python-mode.el) Andreas, can you help sorting this out? Thanks, Okay, I'll dig into. For the moment: assume this code should not be needed, python-mode.el should act that all. But let me have a closer look, Cheers, Andreas
Re: [O] [PATCH] session with python-mode.el complains of void py-toggle-shells
Hi Myles, thanks for digging into this. I'm copying Andreas as the maintainer of python-mode.el. Myles English writes: > --- lisp/ob-python.el > +++ lisp/ob-python.el > @@ -32,7 +32,7 @@ > > (declare-function org-remove-indentation "org" ) > (declare-function py-shell "ext:python-mode" (&optional argprompt)) > -(declare-function py-toggle-shells "ext:python-mode" (arg)) > +(declare-function py-toggle-shell "ext:python-mode" (arg)) If this function's name changed, there should be an alias in python-mode.el. > (declare-function run-python "ext:python" (&optional cmd noshow new)) > > (defvar org-babel-tangle-lang-exts) > @@ -162,16 +162,17 @@ then create. Return the initialized session." > ;; Make sure that py-which-bufname is initialized, as otherwise > ;; it will be overwritten the first time a Python buffer is > ;; created. > - (py-toggle-shells py-default-interpreter) > + (py-toggle-shell py-default-interpreter) > ;; `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 python-buffer (buffer-live-p python-buffer)) > (replace-regexp-in-string ;; zap surrounding * > "^\\*\\([^*]+\\)\\*$" "\\1" python-buffer) > (concat "Python-" (symbol-name session > - (py-which-bufname bufname)) > - (py-shell) > - (setq python-buffer (concat "*" bufname "*" > + (py-buffer-name bufname)) > + (setq python-buffer (concat "*" bufname "*")) > + (py-shell nil nil nil nil nil python-buffer) > + )) The docstring of py-shell doesn't say much about why python-buffer would be needed as an argument here. Is it so? If yes, we need to make this compatible with previous versions of python-mode.el. (The argument PY-BUFFER-NAME is not documented in latest python-mode.el) Andreas, can you help sorting this out? Thanks, -- Bastien
Re: [O] [PATCH] session with python-mode.el complains of void py-toggle-shells
Hi Nick, Nick Dokos writes: > Myles English wrote: >> I think it should be possible to execute a python block in a session >> using python-mode.el but get this message: >> >> "Symbol's function definition is void: py-toggle-shells" I have made a bit of progress with the patch below. The breakage may have been due to changes in python-mode.el . The patch works for versions 6.0.10 and 6.1.0. > I get in trouble much sooner than you do: when evaluating the first code > block. The error in my case was that run-python was called with the > wrong number of args (from the same function: it's a couple of lines > before py-toggle-shells is called). I'm running > > GNU Emacs 24.3.50.2 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.4) of > 2012-12-29 > > and run-python does indeed need a required arg in this version: > > , > | run-python is an interactive autoloaded compiled Lisp function in > | `python.el'. > | > | (run-python CMD &optional DEDICATED SHOW) > | > | Run an inferior Python process. > | Input and output via buffer named after > | `python-shell-buffer-name'. If there is a process already > | running in that buffer, just switch to it. > ` > > So I changed the call to > > > (run-python py-python-command) > > and then all the code blocks could execute with no problem. Has > run-python changed signature recently? Doing git blame ob-python.el shows that not much has changed in that file over the last couple of years. > This may or may not be the problem you are running into however. I have made some progress and the patch below passes this test: #+BEGIN_SRC emacs-lisp (add-to-list 'load-path "~/.emacs.d/plugins/org-mode/lisp") (require 'org) (org-babel-do-load-languages 'org-babel-load-languages '((python . t))) (setq org-babel-python-mode 'python-mode) #+END_SRC #+begin_src python :results output :session a import sys #+end_src #+begin_src python :results output :session a print(sys.path) #+end_src Patch: --- lisp/ob-python.el +++ lisp/ob-python.el @@ -32,7 +32,7 @@ (declare-function org-remove-indentation "org" ) (declare-function py-shell "ext:python-mode" (&optional argprompt)) -(declare-function py-toggle-shells "ext:python-mode" (arg)) +(declare-function py-toggle-shell "ext:python-mode" (arg)) (declare-function run-python "ext:python" (&optional cmd noshow new)) (defvar org-babel-tangle-lang-exts) @@ -162,16 +162,17 @@ then create. Return the initialized session." ;; Make sure that py-which-bufname is initialized, as otherwise ;; it will be overwritten the first time a Python buffer is ;; created. - (py-toggle-shells py-default-interpreter) + (py-toggle-shell py-default-interpreter) ;; `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 python-buffer (buffer-live-p python-buffer)) (replace-regexp-in-string ;; zap surrounding * "^\\*\\([^*]+\\)\\*$" "\\1" python-buffer) (concat "Python-" (symbol-name session - (py-which-bufname bufname)) - (py-shell) - (setq python-buffer (concat "*" bufname "*" + (py-buffer-name bufname)) + (setq python-buffer (concat "*" bufname "*")) + (py-shell nil nil nil nil nil python-buffer) + )) (t (error "No function available for running an inferior Python"))) (setq org-babel-python-buffers Myles