all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Matt <matt@excalamus.com>
Cc: bastien <bzg@gnu.org>, emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: ob-shell intentions and paperwork (was Bash results broken?)
Date: Sat, 31 Dec 2022 12:56:37 +0000	[thread overview]
Message-ID: <87r0wfafzu.fsf@localhost> (raw)
In-Reply-To: <18561866f8c.f22a62b3866025.8634474263936272339@excalamus.com>

Matt <matt@excalamus.com> writes:

>  > > +;; TODO refactor into macro.  Currently violates (elisp) Coding
>  > > +;; Conventions and is hard to debug.
>  > >  (defun org-babel-shell-initialize ()
>  > >    "Define execution functions associated to shell names.
>  > 
>  > Could you please elaborate? Which particular convention does it violate?
>  > What is hard to debug?
>
> (elisp) Coding Conventions says,
>
> "• Constructs that define a function or variable should be macros, not
>      functions, and their names should start with ‘define-’.  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."
>
> The `org-babel-shell-initialize' function defines *all* the `org-babel-execute:XXX' functions given by `org-babel-shell-names' (sh, bash, zsh, etc.).

I agree that `org-babel-shell-initialize' could use a better name.

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 code.
`org-babel-shell-initialize' is only used by `org-babel-shell-names'.

I do not have objections if it were a macro though. (But I do not see
how it would help debugging).

> Because `org-babel-shell-initialize' is a function factory, you can't easily examine or modify their definitions.  `C-h f org-babel-execute:sh' jumps to the top of lisp/ob-shell.el.  Changing the definition requires reevaluating the definition for all the execute functions (or first changing `org-babel-shell-names').

This is indeed a downside. Any better ideas?
ob-core dictates that we must have org-babel-execute:lang functions to
make things work.

> This was a problem for me when I wanted to make the session name string for `test-ob-shell/session' the test name (mentioned above).  In the test, when I replaced the session name string with a variable containing the string, `org-babel-execute:sh' failed with a type error.  I couldn't get the variable to evaluate (with backquote and comma or otherwise).  Without an explicit function definition or a macro to expand, I found it hard to debug/experiment with (and so left the test name as a hard coded string).

Could you please explain a bit more about the problem? I do not see how
macro would help in this situation.

> I probably don't need it and am happy to remove it.    An older version of the function was more complex and made sense as a separate function (or so I thought).  My aim was to make the test strings easy to read so that it's clearer what's being tested (i.e. not write multi-line strings on a single line).  I could use concat and add "\n" to the end of each line.  Or, simply write out the string-join.  Maybe there's another way to write multi-line strings that I'm not aware of in Elisp, maybe something like Python's triple-quote?

We write multi-line docstrings all the time without extra macros. I
recommend using paredit or similar packages to auto-escape things that
need to be escaped.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


  parent reply	other threads:[~2022-12-31 12:57 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-16 16:22 Bash results broken? Rudolf Adamkovič
2022-12-16 17:41 ` Ihor Radchenko
2022-12-18 11:19   ` Ihor Radchenko
2022-12-20  0:44     ` Rudolf Adamkovič
2022-12-20  3:40       ` Matt
2022-12-25 11:23         ` Ihor Radchenko
2022-12-26  2:25           ` Matt
2022-12-26  9:26             ` Ihor Radchenko
2022-12-21  6:17   ` ob-shell intentions and paperwork (was Bash results broken?) Matt
2022-12-27 20:48     ` Matt
2022-12-29 11:08       ` Ihor Radchenko
2022-12-29 14:20         ` Bastien Guerry
2022-12-30  5:34         ` Matt
2022-12-30  8:06           ` Bastien Guerry
2022-12-30 18:46           ` Matt
2022-12-31 14:31             ` Ihor Radchenko
2023-01-01 23:55               ` Matt
2023-01-02  9:47                 ` Ihor Radchenko
2023-01-02 16:40                   ` Matt
2023-01-03 10:50                     ` Ihor Radchenko
2023-01-03 13:00                       ` Matt
2023-01-05 10:31                         ` Ihor Radchenko
2023-01-05 11:21                           ` Bastien Guerry
2023-01-10  2:31                             ` Matt
2023-01-11 11:53                               ` Ihor Radchenko
2023-01-11 16:18                                 ` Matt
2023-01-11 17:02                                   ` Ihor Radchenko
2023-01-11 19:34                                     ` Matt
2023-01-12  8:26                                       ` Ihor Radchenko
2023-01-12 14:43                                     ` Max Nikulin
2023-01-13  9:36                                       ` Ihor Radchenko
2023-01-13 15:18                                         ` Matt
2023-01-13 15:23                                           ` Ihor Radchenko
2023-01-14  7:41                                             ` Max Nikulin
2023-01-14 10:35                                               ` Ihor Radchenko
2023-01-14 15:09                                                 ` cgit and merge commit Max Nikulin
2023-01-24 20:16                                                   ` Ihor Radchenko
2022-12-31 12:56           ` Ihor Radchenko [this message]
2023-01-02  4:40             ` Refactor org-babel-shell-initialize? (was Re: ob-shell intentions and paperwork (was Bash results broken?)) Matt
2023-01-03  9:29               ` Ihor Radchenko
2023-01-05  8:32                 ` Ihor Radchenko

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r0wfafzu.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=bzg@gnu.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=matt@excalamus.com \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.