Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: setq-local python-shell-buffer-name after calling org-edit-src-code #183

Closed
dangom opened this issue Mar 18, 2018 · 2 comments

Comments

@dangom
Copy link
Sponsor Contributor

dangom commented Mar 18, 2018

So far loving the refreshed scimax-ipython. One little thing I'd like to add is to have calls to org-edit-src-code automatically change the python-shell-buffer-name variable for the editing buffer. This would allow directing python.el's python-shell-send-region and python-shell-send-buffer to the appropriate inferior python. Quite convenient if dealing with multiple files/sessions.

Currently I do this manually by copying the auto-generated session name, and evaluating (setq-local python-shell-buffer-name "Python:ipython-session-name"). Would there be a simple/clean way to do this programatically?

@jkitchin
Copy link
Owner

I think this is the place to do it. Can you try it out and let me know if it solves the problem. Ideally this would go upstream to ob-ipython.

(defun org-babel-edit-prep:ipython (info)
  ;; TODO: based on kernel, should change the major mode
  (ob-ipython--create-kernel (->> info (nth 2) (assoc :session) cdr
                                  ob-ipython--normalize-session)
                             (->> info (nth 2) (assoc :kernel) cdr))
  (setq-local python-shell-buffer-name
	      (format "Python:%s" (->> info (nth 2) (assoc :session) cdr
				       ob-ipython--normalize-session)))
  (ob-ipython-mode +1))

@dangom
Copy link
Sponsor Contributor Author

dangom commented Mar 19, 2018

This works just fine, thank you.

Calls to python-shell-send-region will send code to the appropriate processes unless the inferior Python buffer does not exist yet (but this is another issue), i.e., one has to first org-babel-switch-to-session to create the buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants