From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:1008:1e59::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id 0KaDBew/mmU8iQAAkFu2QA (envelope-from ) for ; Sun, 07 Jan 2024 07:08:44 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id CA4pAuw/mmWLVQEA62LTzQ (envelope-from ) for ; Sun, 07 Jan 2024 07:08:44 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Nq8m5+I2; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1704607724; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=FVpO9dEf6uZS9PVFafBpOlwaH6D9AV36jvw3Jn2lIPU=; b=NpwUkn55hYgS8oVu/nNJoY4ofw7eBHv4+5mxUXVBsFMwFf3smXyv+Njyrr5oQXfbz0L2Vd 2vurVQ5uDzHqW6zPrw2YTEHAtF9Zd2Xl9CycF0utEfQSneuDjCNNqIz5WnCxWLxq/ONvcg S6G+/h2IRmVDcDQHUzTHzhISqFRdR0WNPU8fw//ijccOB92XPMHiOrxY3nXYZMNKT6ZKIz I7d+GkVMqmzjswHJMHl1oCp3XQC05BmljAPKof2gFNMgH7xRMzkn4EotIC1c6oRf1k4rfd 6yaWkXwMvGJVMXF1DXphzUyFS5CnzgnOXEkMVCIlGO9tKoQpG7tV+SOdcWJVkA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Nq8m5+I2; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=key1; d=yhetil.org; t=1704607724; a=rsa-sha256; cv=none; b=bruEEXZe3hCVa6RWNqtSyT35JnRHsl6++5uFgD5o11XfFQLBVxTQo6G4nSqtQZKr8p95mq 2536gZb2cWm7I6TwNXvuG2n3GJ3ERB/MWOdavjXeHdM2Y54LpCQDFf59hHPxEQcEgWtjIg XFt/2nzZPCWO5uHbuLaLT6KC1va6Y0JLiM6hLNXolVuvpojn68QrvCgzp2oz6kKzJMgaGQ eWXrE10TJorljgf3E7SbpBJS8ixLvNgdxgmqOx2B1149Tw998oIiXDesE/EyCyW1LFlPHt QdIju/i2sM55U6lN62ZNGJFDa84K8Qv0WS3NVd1qK3kwn/O6IMQCP3s7VSmSsg== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6114C50CFE for ; Sun, 7 Jan 2024 07:08:43 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rMMK3-0004ot-0s; Sun, 07 Jan 2024 01:07:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rMMK0-0004oc-Qw for emacs-orgmode@gnu.org; Sun, 07 Jan 2024 01:07:44 -0500 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rMMJz-0000nl-3p for emacs-orgmode@gnu.org; Sun, 07 Jan 2024 01:07:44 -0500 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-5bdbe2de25fso675737a12.3 for ; Sat, 06 Jan 2024 22:07:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704607661; x=1705212461; darn=gnu.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=FVpO9dEf6uZS9PVFafBpOlwaH6D9AV36jvw3Jn2lIPU=; b=Nq8m5+I2K+BJASwx3MWcrEN8WeHN4zp3NCaIFm9BjSFzfRIw/3UM8l4g0jmd+AGcrD ouY88y+EVMzMoL6LDkvBT/rNv7oNerugihqiHFapF+/6IrNgJYFFruQuBAYGpHtP/mls OaDL80qlNSofExdDJuWpSmJHr27aC8N0UKlCkTDf4qdbkttrL2wFSkTE4pqcHH5R0j61 lEEHKBLoR6oILxd9gf9k5vO/w41pWzp3gLeb2DDH8ZxHhAmlv9QD7BZnId8XDj8tv2aP r8rh8gxza4bmWzWRmD53oTcXolujR4MbTAaLwoV94nLUfDLCvVwWAX3oIXrv4k4HH3r/ fHaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704607661; x=1705212461; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FVpO9dEf6uZS9PVFafBpOlwaH6D9AV36jvw3Jn2lIPU=; b=TBalwThuoBHEf2gb0Q7Z97Qq2m08d1zJsa0rNJJrYWzhpJKsFDxBEaHTTV9FayXl3d 2f5EOLFUxGWadg+CG9myZgTVSFBwTs0dIDEmyr3H23VTQ4kji8AyP39yDJXKkE9GEciA g6i1l2RqD9DfbhPXkPx7v83ghIG5+WmmvV+Sr4rPwqYNPWCPe/VleXch99oN/cCZzGQz mtPcvzM64Jp2y9AhEFC2Z7vuiRx6elQD4Mrk8Awg1pY1I6ZgURwtXGFb7zrv/TxZPMIu SkvUdu1P3cYnNCgvFrmUP2IeL/vuQaXjdbaQWjERfc53psC9WAB2ZN7L5sLw0NuvFJxL KjLg== X-Gm-Message-State: AOJu0YzLwnwnSh9JZVg4k/LwG5uqAWmLmHIbUXatWMy/y4Fej9Y8xdZN BHnpriqFHTVbFLYOYJnMYChegeTupwE= X-Google-Smtp-Source: AGHT+IEgjsQ/WwkHl/T62G1S6N1Z6d0nTgPw5OGwlQK2gAGAyPbmZgy7uEAkLxWHW5rWstWTytYm3g== X-Received: by 2002:a05:6a20:432b:b0:199:6a8d:4b47 with SMTP id h43-20020a056a20432b00b001996a8d4b47mr2647612pzk.92.1704607660803; Sat, 06 Jan 2024 22:07:40 -0800 (PST) Received: from localhost (157-131-78-143.fiber.dynamic.sonic.net. [157.131.78.143]) by smtp.gmail.com with ESMTPSA id q26-20020a63f95a000000b005c6bd30ea57sm3891594pgk.47.2024.01.06.22.07.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jan 2024 22:07:39 -0800 (PST) From: Jack Kamm To: Ihor Radchenko Cc: Liu Hui , emacs-orgmode@gnu.org Subject: Re: [PATCH] Set Python shell in Org edit buffer In-Reply-To: <87wmsn6ghw.fsf@localhost> References: <87zfyosw8n.fsf@localhost> <87ttovlb1u.fsf@localhost> <878r6647vv.fsf@localhost> <87bkb2rqer.fsf@localhost> <87edfwsuvx.fsf@localhost> <87sf4bsm1w.fsf@localhost> <87mstw18r4.fsf@gmail.com> <87bkaak0ol.fsf@localhost> <87ttnyz0jv.fsf@gmail.com> <87wmsn6ghw.fsf@localhost> Date: Sat, 06 Jan 2024 22:07:38 -0800 Message-ID: <87o7dxu15h.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=jackkamm@gmail.com; helo=mail-pg1-x52f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -7.48 X-Spam-Score: -7.48 X-Migadu-Queue-Id: 6114C50CFE X-TUID: /TV4qs1DHnlH Ihor Radchenko writes: > Now, the question is what to do with the existing implementation of > `org-src-associate-babel-session'. It only runs > org-babel--associate-session when > > (and session (not (string= session "none")) > (org-babel-comint-buffer-livep session) > (let ((f (intern (format "org-babel-%s-associate-session" > (nth 0 info))))) > (and (fboundp f) (funcall f session)))) > > The questionable check here is (org-babel-comint-buffer-livep session) - > it only triggers when session is already initiated, while ob-python and > some other backends do not necessarily need to start a new session to > "associate" it with Org Src buffer. > > I am tentatively inclined to change this check to > > (or (org-babel-comint-buffer-livep session) > (eq org-src-auto-initiate-session t) > (alist-get (nth 0 info) org-src-auto-initiate-session) > (alist-get 'default org-src-auto-initiate-session)) > > With `org-src-auto-initiate-session' being a customization that controls > whether to associate session for a given babel backend. > > We may set the default value to something like > > ((default . t) ("R" . nil)) I think there are 2 aspects of the session+editing behavior that I'd like to disentangle: 1. Whether to create session when editing (if it doesn't exist yet) 2. If session exists, whether to "associate" it so that evaluation commands (e.g. python-shell-send-region, ess-eval-region) and autocompletion use it. Personally, I prefer to disable #1 while enabling #2. For ob-R, it seems like #1 happens in `org-babel-edit-prep:R' while #2 happens in `org-babel-R-associate-session', so adding an option to disable the latter isn't useful for me, and it's not clear to me whether it'd be useful generally for others either. (I realize #2 hasn't worked properly for some time now until you fixed it in this thread. I wasn't too badly affected because I usually only use one session at a time, and ess-eval-region is able to figure out the session in this case. But I did sometimes have to manually call `ess-force-buffer-current' to get completion working, which it seems I no longer have to do now that you've fixed this). As an aside, I just noticed some inconsistent behavior in ob-R. It seems it only auto-creates the session when ":session *foo*" (i.e. the session name has "earmuffs"). But when ":session foo" (no earmuffs), ob-R doesn't autostart the session. While this is probably accidental, it doesn't seem to cause any problems, which makes me question whether it's really needful for ob-R to initiate a session on edit. In particular, if ":session foo" already exists, then ess-eval-region still works fine in the src block. Which is exactly my desired behavior -- don't create the session if it doesn't exist yet, but if it already exists then play nicely with it. Another thing to note is that ob-R works fine with sessions externally created with "M-x R". (similar to how ob-python works fine with "M-x run-python"). In fact, I sometimes use ob-R with manual "M-x R" sessions when I need to use a different R binary/environment than my usual one. So, it is not necessary for the R session to be started through ob-R. As for ob-python; I think it's best to set `python-shell-buffer-name' in `org-babel-edit-prep:python' rather than `org-babel-python-associate-session'. While both work for `python-shell-send-region' if the session already exists, `org-babel-edit-prep:python' has the advantage that it will run even if the session doesn't exist yet, so then "M-x run-python" in the src block will create a session with the correct name.