emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Elias Kueny <elias.kueny@posteo.net>
To: emacs-orgmode@gnu.org
Subject: [PATCH] Fix :var parameter for fish shell code blocks
Date: Fri, 13 Oct 2023 22:42:52 +0000	[thread overview]
Message-ID: <877cnpwka3.fsf@posteo.net> (raw)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: 0001-lisp-ob-shell.el-Adapt-the-var-header-parameter-to-f.patch --]
[-- Type: text/x-patch, Size: 2147 bytes --]

From 0d8067348d033e159a460233773e442c0775a8bb Mon Sep 17 00:00:00 2001
From: Elias Kueny <elias.kueny@posteo.net>
Date: Sat, 14 Oct 2023 00:20:55 +0200
Subject: [PATCH] lisp/ob-shell.el: Adapt the `:var' header parameter to fish

* ob-shell.el (org-babel-variable-assignments:shell): allow the `:var'
keyword on fish code blocks to work with fish variables.

The fish shell uses the syntax `set variable value' instead of
`value=value' to set a shell variable.  This caused org-babel to
return an syntax error when attempting to execute a fish code block
with a `:var' parameter.  This change adds a helper function to use
the correct format.

TINYCHANGE
---
 lisp/ob-shell.el | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/lisp/ob-shell.el b/lisp/ob-shell.el
index fe4c7af72..9f3b614e6 100644
--- a/lisp/ob-shell.el
+++ b/lisp/ob-shell.el
@@ -167,6 +167,11 @@ defun org-babel--variable-assignments:sh-generic
   "Return a list of statements declaring the values as a generic variable."
   (format "%s=%s" varname (org-babel-sh-var-to-sh values sep hline)))

+(defun org-babel--variable-assignments:fish
+    (varname values &optional sep hline)
+  "Return a list of statements declaring the values as a fish variable."
+  (format "set %s %s" varname (org-babel-sh-var-to-sh values sep hline)))
+
 (defun org-babel--variable-assignments:bash_array
     (varname values &optional sep hline)
   "Return a list of statements declaring the values as a bash array."
@@ -212,8 +217,11 @@ defun org-babel-variable-assignments:shell
        (if (string-suffix-p "bash" shell-file-name)
 	   (org-babel--variable-assignments:bash
             (car pair) (cdr pair) sep hline)
-         (org-babel--variable-assignments:sh-generic
-	  (car pair) (cdr pair) sep hline)))
+         (if (string-suffix-p "fish" shell-file-name)
+	     (org-babel--variable-assignments:fish
+              (car pair) (cdr pair) sep hline)
+           (org-babel--variable-assignments:sh-generic
+	    (car pair) (cdr pair) sep hline))))
      (org-babel--get-vars params))))

 (defun org-babel-sh-var-to-sh (var &optional sep hline)
--
2.41.0

[-- Attachment #2: Type: text/plain, Size: 515 bytes --]

Hello,

I found an issue with fish shell code blocks, in that the `:var' parameter generates a command that is not syntaxically correct. Fish uses `set variable value' instead of `variable = value'. As a result, org-babel throws an error when executing the code block. This patch fixes this by adding an exception to org-babel-variable-assignments:shell on the model of what it already does for bash.

Example of code block triggering the error:
#+begin_src fish :var test
echo $test
#+end_src

Best regards,
Elias

             reply	other threads:[~2023-10-14 10:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-13 22:42 Elias Kueny [this message]
2023-10-15  8:35 ` [PATCH] Fix :var parameter for fish shell code blocks 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

  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=877cnpwka3.fsf@posteo.net \
    --to=elias.kueny@posteo.net \
    --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).