From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id WG1hM4T1s2PTTAAAbAwnHQ (envelope-from ) for ; Tue, 03 Jan 2023 10:29:40 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id 0KWEMoT1s2MBIwAAG6o9tA (envelope-from ) for ; Tue, 03 Jan 2023 10:29:40 +0100 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 6F5B743EE2 for ; Tue, 3 Jan 2023 10:29:40 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pCdbS-0005TE-Sw; Tue, 03 Jan 2023 04:29:02 -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 1pCdbQ-0005SA-NS for emacs-orgmode@gnu.org; Tue, 03 Jan 2023 04:29:00 -0500 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pCdbN-0005Vl-Ve for emacs-orgmode@gnu.org; Tue, 03 Jan 2023 04:29:00 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 063EA240421 for ; Tue, 3 Jan 2023 10:28:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1672738136; bh=bnL9xDTsrNWC3E7LE0252dWxblsPTd+vtZ8Z0/xPMHk=; h=From:To:Cc:Subject:Date:From; b=XEUUwCzqqMb+3pntXhXJDfLZNDbwTfc5QGPs83trKuGfmQ76epxejQXexRHLHd8bV 2nNtnHW7exphAb7K3CWFQfuxYWZTsihipMOQoa70FMGZYFwUCI6sWvQ8So1WGHAe6S l0JNDK+R8gPa52ZnM31juIvnMHClcpJIjJIKvNaffQRc/2D8GKvENHMucJWBHT6aZu XqmpPoat2yxsbqUzOoN1+N8544RqneQYzHMJ3+FyT60dLLbL+q96jBQ7o/zdEP9mce mnwzATexv3EzvRNxq8ADqNP85MdQOtkKTydllD+KTqivgauGsJwle77ezYtz0XA9h9 QNF4RkxKp9Oug== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4NmS9325Pdz6tm4; Tue, 3 Jan 2023 10:28:55 +0100 (CET) From: Ihor Radchenko To: Matt Cc: emacs-orgmode Subject: Re: Refactor org-babel-shell-initialize? (was Re: ob-shell intentions and paperwork (was Bash results broken?)) In-Reply-To: <18570c77eb9.119e6407e40169.7047396916380100893@excalamus.com> References: <878rj7s0ti.fsf@localhost> <1853354beb4.fce54d8d902653.6359367327256505471@excalamus.com> <18555580d75.d7b471f9370716.1497263973038999899@excalamus.com> <87edsiv54k.fsf@localhost> <18561866f8c.f22a62b3866025.8634474263936272339@excalamus.com> <87r0wfafzu.fsf@localhost> <18570c77eb9.119e6407e40169.7047396916380100893@excalamus.com> Date: Tue, 03 Jan 2023 09:29:15 +0000 Message-ID: <87h6x8kluc.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1672738180; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=v7jyHHSyN3pOeInMX2DOWbK9+XtuTSfqSuy8AKyrZY4=; b=BaSI5Qtizpni+Tly2uqa1GgKpNA7GRi7WSXp7CfHbt93lhohBX0pO+wGmdtu6/DmjG4J1r +SmQYACr/y1qZmx9PienSv1AKIysIHY4pcR93G3nVQ26Yk4xY1kbZkjKGGNdCgAviiiGbk lrF69lkW9xH7PfexpcFg3UseU7aQ5V2Ig2un8jD9aFnC+dUGHXsLL0wt7HwHMsVTZrBYqd 9YK8fxadFkjM+3NCbPm6PPkQVrT9zrSa/zfkjNVXIdTXP7i1/rb4Cct0qZmLGBOWW03rjt oXEptbI12mM4x+ZqREIUWQ6DRO3jE4ZneGr1UyFLKC1mA1G+wvWtIzWhFQBahQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=XEUUwCzq; 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=posteo.net ARC-Seal: i=1; s=key1; d=yhetil.org; t=1672738180; a=rsa-sha256; cv=none; b=c7r/nVadLIdXkqi2Nl1cQlbQq+Yn7OY0uIqKdIuGdLSSJLHscrVq4p+dl5WTD4ZkMoq8jT K2jz0JNjLuELZ4s+DtIeL+85IwqJAySZukZ4Buq6+zN04YEX+KF2/LBs02MDqD4NIDbVxe XMcBPaE57qLqnqLkmmkKPaWX34WmZ4hMV8XVYWTqweSRZe6a9B6sJ129HO81zA7ftSY1VZ 9KVv//WbrelH7/wwyS8m/MRXOL+rcOqhpr8SlLbw4Ni7BQBJBlVGJfgrHsN/a5SZcdHTLr vxZQe09rvHsF6qT1LVCuOPIw16SEphqMa2PEgJhc134B7dSj48I6edkFg2chog== X-Spam-Score: -5.99 X-Migadu-Queue-Id: 6F5B743EE2 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=XEUUwCzq; 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=posteo.net X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: -5.99 X-TUID: gWe/jaCmlckw Matt writes: > ---- On Sat, 31 Dec 2022 07:56:10 -0500 Ihor Radchenko wrote ---=20 > > As for being a macro, there will be not much gain - the convention is > > mostly designed for things like `cl-defun' aimed to be used in the cod= e. > > `org-babel-shell-initialize' is only used by `org-babel-shell-names'. > > I'm not sure what you mean by "to be used in code". Do you mean called w= ithin the global scope? There are certain conventions about indentation of macros with "defun" in them. They are automatically applied in emacs-lisp-mode. Also, some heuristics for imenu looks for "defun" top-level forms, AFAIR. In all these scenarios, it is assumed that "defun" macros are used in the source code to define functions during compile time. Not on runtime. > 1. The source is not explicit for a given `org-babel-execute:some-shell',= making it difficult to debug > > The benefit of using a macro is clarity of the defined functions. Here's= the core `org-babel-shell-initialize' functionality as a macro. Note that= it doesn't loop through `org-babel-shell-names'. > ... > You can expand to see the definitions: > > (pp-macroexpand-expression '(define-babel-shell-1 "csh")) > > Is there a way to see the definition of`org-babel-execute:csh' using the = current `org-babel-shell-initialize', that is, when generated by a function? https://github.com/Wilfred/helpful displays the function code in such scenario. Probably, I need to raise this problem on emacs-devel. > Looking at the expansion, I see what appears to be an error: > > (alist-get "csh" org-babel-shell-set-prompt-commands) > > `org-babel-shell-set-prompt-commands' is an alist keyed by string shell n= ames and whose values are shell commands to set the prompt. `alist-get' us= es `eq' by default which always returns nil for string comparisons. That i= s, (alist-get "csh" org-babel-shell-set-prompt-commands) returns nil, not b= ecause the corresponding alist value is nil. Rather, because the (eq "csh"= "csh") comparison evaluates as nil. The TESTFN probably should be `equal'= or `string=3D': > > (alist-get "csh" org-babel-shell-set-prompt-commands nil nil 'equal) > > Then, it will return the prompt associated with "csh". Good point. Would you mind making a patch? > 2. Source navigation gets confused when looking up help for a generated f= unction. For example, `C-h f org-babel-execute:sh' goes to the top of ob-s= hell.el This is indeed to be expected. > Generating the execute functions with a macro also has this problem. I'm= not sure there's a way around it other than defining each function with `d= efun'. Doing that would be a bad idea because of the massive code duplicat= ion/maintenance it would create. Yup. > 3. It does not adhere to the coding convention. > > I'll requote the convention here for convenience. > >> (elisp) Coding Conventions says, >> >> "=E2=80=A2 Constructs that define a function or variable should be macro= s, not >> functions, and their names should start with =E2=80=98define-=E2=80=99. = The macro >> should receive the name to be defined as the first argument. That >> will help various tools find the definition automatically. Avoid >> constructing the names in the macro itself, since that would >> confuse these tools." > > It's not clear to me why the convention exists, beyond consistency (a val= id reason). I suspected it was to make the code clearer (points 1) and to = "help various tools find the definition automatically" (point 2).=20=20 > > I'm biased by my experience into thinking a macro actually addresses poin= t 1. I could be wrong about it, though. It could just have been luck and p= ersonal preference, and I may be overlooking some hidden complexity, a comm= on problem with macros. Is there anything you see that I might be overlook= ing? Nothing substantial, AFAIK. > AFAICT, a macro doesn't help with finding the definition of the generated= function. Any idea what tools it's talking about? See above. > Also, the way I defined `define-babel-shell-1' doesn't fit the convention= . Something like this would: > > (defmacro define-babel-execute-shell-2 (name) > "Define functions and variables needed by Org Babel to execute a shell. > > NAME is a symbol of the form `org-babel-execute:my-shell'." > (declare (indent nil) (debug t)) > (let ((shell-program (cadr (split-string (symbol-name name) ":")))) Symbol argument will create awkward back-and-forth conversion between string and a symbol here. > 4. Except for using the customize interface, changing `org-babel-shell-na= mes' requires reevaluating the function generator (`org-babel-shell-initial= ize' or some variant of `define-babel-shell-1' ) > > A macro would not solve the need to re-evaluate the function generation w= hen a change is made to `org-babel-shell-names'. Either way, we need to lo= op/map over the list of shells. > > I'm curious your thoughts about removing the `:set' function from `org-ba= bel-shell-names' and using `add-variable-watcher' instead. In my explorati= ons, the watcher gets called when using customize, as well as when a new sh= ell is added to `org-babel-shell-names' using `add-to-list'. I have never seen using variable watcher for this purpose. I suggest asking on emacs-devel first to hear what they think of it. --=20 Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at