From: Ken Mankoff <mankoff@gmail.com>
To: Andreas Leha <andreas.leha@med.uni-goettingen.de>
Cc: emacs-orgmode@gnu.org
Subject: Re: named python session
Date: Wed, 12 Aug 2015 09:34:34 -0700 [thread overview]
Message-ID: <m2a8twh3dx.fsf@gmail.com> (raw)
In-Reply-To: <olur3n8lf6b.fsf@med.uni-goettingen.de>
Hi Andreas,
On 2015-08-12 at 08:06, Andreas Leha <andreas.leha@med.uni-goettingen.de> wrote:
> How do I associate that with the python process in *mypy*?
> I am asked to start python when I run python-shell-send-region.
I have set up my system so that Org asks for a buffer name every time =org-edit-special= is called. This may be helpful to you.
-k.
*** Custom Python Session Names
https://github.com/jorgenschaefer/elpy/issues/383
I want each python session to optionally have a unique name, so that I
can run multiple sessions in multiple windows/buffers/directories and
not have them interact/interfere.
Here I've copied =elpy-shell-get-or-create-process= from =elpy.el= and
modified it. I also have to modify =python-shell-get-process-name=.
This all is fairly easy, except when executing from Org it gets more
complicated, hence the special case if a function called from
=org-ctrl-c-ctrl-c=.
#+BEGIN_SRC emacs-lisp :results none
(defun elpy-shell-get-or-create-process ()
"Get or create an inferior Python process for current buffer and return it.
Customized by KDM to make dedicated sessions"
(let* ((bufname (format "*%s*" (python-shell-get-process-name t)))
(proc (get-buffer-process bufname)))
(if proc
proc
(run-python (python-shell-parse-command) t nil) ;; DEDICATED!
(get-buffer-process bufname))))
(defun python-shell-get-process-name (dedicated)
(if (equal this-command 'org-ctrl-c-ctrl-c)
(kdm/orig-py-sh-get-proc-name dedicated)
(kdm/my-py-sh-get-proc-name dedicated)))
(defun kdm/orig-py-sh-get-proc-name (dedicated)
"Calculate the appropriate process name for inferior Python process.
If DEDICATED is t returns a string with the form
`python-shell-buffer-name'[variable `buffer-name']."
(let ((process-name
(if (and dedicated
(buffer-name))
(format "%s[%s]" python-shell-buffer-name (buffer-name))
(format "%s" python-shell-buffer-name))))
process-name))
(defun kdm/my-py-sh-get-proc-name (dedicated)
(if (boundp 'py-buf-proc-name)
(format "%s" py-buf-proc-name)
(setq-local py-buf-proc-name
(format "%s"
(completing-read "Python session name: "
nil nil nil (buffer-name) nil (buffer-name)))
)))
#+END_SRC
next prev parent reply other threads:[~2015-08-12 16:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-12 15:06 named python session Andreas Leha
2015-08-12 16:34 ` Ken Mankoff [this message]
2015-08-13 13:12 ` Andreas Leha
2015-08-13 14:52 ` Ken Mankoff
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2a8twh3dx.fsf@gmail.com \
--to=mankoff@gmail.com \
--cc=andreas.leha@med.uni-goettingen.de \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).