From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ken Mankoff Subject: Code, Sessions, and org-edit-special Date: Fri, 21 Nov 2014 18:38:56 -0500 Message-ID: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45352) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XrxnA-0001rB-CR for emacs-orgmode@gnu.org; Fri, 21 Nov 2014 18:39:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xrxn1-0004Pz-Bh for emacs-orgmode@gnu.org; Fri, 21 Nov 2014 18:39:08 -0500 Received: from mail-qa0-x22e.google.com ([2607:f8b0:400d:c00::22e]:40700) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xrxn1-0004Pq-8F for emacs-orgmode@gnu.org; Fri, 21 Nov 2014 18:38:59 -0500 Received: by mail-qa0-f46.google.com with SMTP id u7so4149658qaz.5 for ; Fri, 21 Nov 2014 15:38:58 -0800 (PST) Received: from gorgonzola (c-71-58-77-153.hsd1.pa.comcast.net. [71.58.77.153]) by mx.google.com with ESMTPSA id 15sm5938709qga.21.2014.11.21.15.38.57 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Nov 2014 15:38:58 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Hi List, I'm trying to improve my code workflow. I use python and sessions. I'd like to be able to run code in the session even if I'm editing/viewing the code via `org-edit-special`. Furthermore, when I edit code outside of Org, I'd like to have sessions, that is, optionally one Python session per source file. This allows me to edit different code for different projects in different folders on virtual desktops, etc. I've solved the non-Org part of this with the following one re-defined and one new function: #+BEGIN_SRC emacs-lisp (defun elpy-shell-get-or-create-process () "Get or create an inferior Python process for current buffer and return it." (let* ((bufname (format "*%s*" (kdm/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 kdm/python-shell-get-process-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 Now when I C-c C-c in a buffer without an associated Python session, I'm prompted for a name (defaulting to the buffer-name). I provide a session name, and then all future C-c C-c's for that buffer are executed there. This is good for Org. If I name a session "foo", I can edit code in org-edit-special, assign Python session "foo", and execute code in a session either from the org buffer or from the temp .py file. In theory. But since I've call kdm/pythons-shell-get-process-name, if I try to C-c C-c in a #+BEGIN_SRC section, it no longer works. I'm prompted for a session name (I should not be). Whatever I enter is ignored, and the code is executed either in a temporary "*Python*" if no :session, or in the :session name as it should be. How can I find out inside my `kdm/python-shell-get-process-name` if it was called from Org, in which case I would implement the original version. Thanks, -k.