Babel zip after exporting file

2023-03-16 Thread suarezmiguelc
Hello Emacs org-mode community, I’m trying this example:

** index.js
:PROPERTIES:
:header-args: :tangle index.js :post-tangle (shell-command-to-string "zip 
index.js.zip index.js && rm index.js")
:END:

First endpoint example:

#+begin_src js
exports.handler = async (event, context) => {
  console.log('Received event:', JSON.stringify(event, null, 2));
  return {
statusCode: 200,
headers: {
  'Content-Type': 'application/json'
},
body: JSON.stringify({
  message: 'Hello, world!'
})
  };
};
#+end_src

What I want is to:
1. Tangle the index.js file
2. Zip it as index.js.zip
3. Delete the raw code index.js

The thing is that, the command inserted in :post-tangle is executed before the 
creation of the file, so it only works if the file already exists, so:
- First run, file doesn’t exist, only index.js is generated.
- Second run, zip file appears, index.js is intact since the rm index.js 
command ran but then index.js was generated again.

How should I debug this?


Re: org-agenda on Mac M1

2023-03-16 Thread Henrik Frisk
Den tors 16 mars 2023 kl 14:58 skrev Ruijie Yu :

> Henrik Frisk  writes:
>
> > When I run org-agenda I get the sub menu but if I hit 'a' emacs hangs,
> > though I can get it back if I hit C-g.  [...]
> >
> > I have no experience in debugging, but I tried to run debug-on-error
> > with org-agenda and I got the following, which is not so helpful (to
> > me):
> >
> > [...]
> >
> > Anyone else has a suggestion on a next step here?
>
> What happens when you run `M-x toggle-debug-on-quit RET' right after you
> run `emacs -Q', and do your usual steps to reproduce the issue?  That
> might provide a more detailed backtrace for investigation.
>
> Well, with emacs -Q there hasn't been a problem so far, so it's in my
configuration or in one of the agenda files, but it appears to happen on
random: taking out one agenda file may make it work, but then after a
restart it doesn't work, etc.


> In addition, what version of Emacs and of org are you using?  Posting
> the results of these two commands would help a lot:
>
Ah yes, sorry!


> - `M-: emacs-repository-version RET'
>
That evaluates to nil. M-x emacs-version is GNU Emacs 28.2 (build 1,
aarch64-apple-darwin21.6.0, Carbon Version 165 AppKit 2113.6) of 2023-02-12

> - `M-x org-version RET'
>
9.6.1


[PATCH v4] lisp/ob-screen.el: Support ~:var~ header args for babel blocks

2023-03-16 Thread Max Nikulin

On 16/03/2023 17:22, Ihor Radchenko wrote:

Canceled.


Anyway it does not work.

I have tried to "fix" `org-babel-variable-assignments:screen' by an 
extra patch. Perhaps executable name aka :cmd and babel language should 
not be rigidly coupled and it may be subject for further improvement.


Ken, you wrote that you have other patches for ob-screen.el. Do you plan 
to sent them?From a654876c33a13dafac865fa9ea88176302d810c2 Mon Sep 17 00:00:00 2001
From: "Kenneth D. Mankoff" 
Date: Mon, 20 Feb 2023 21:40:39 -0800
Subject: [PATCH v4 1/2] ob-screen.el: Support var for screen source blocks

* lisp/ob-screen.el (org-babel-execute:screen): Parse header params
for `:var', then inject into screen session.
* etc/ORG-NEWS: Document as New Feature
---
 etc/ORG-NEWS  | 10 ++
 lisp/ob-screen.el |  8 
 2 files changed, 18 insertions(+)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 4ca13af17..3f70dc99a 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -131,6 +131,16 @@ selection.
 TODO state, priority, tags, statistics cookies, and COMMENT keywords
 are allowed in the tree structure.
 
+*** ob-screen now supports :var header arguments
+
+The ~:var~ header arg is now supported.
+
+#+BEGIN_SRC org
+,#+BEGIN_SRC screen :var x=42
+,echo $x
+,#+END_SRC
+#+END_SRC
+
 ** Miscellaneous
 *** Remove undocumented ~:target~ header parameter in ~ob-clojure~
 
diff --git a/lisp/ob-screen.el b/lisp/ob-screen.el
index 269538e79..6e6a31ea6 100644
--- a/lisp/ob-screen.el
+++ b/lisp/ob-screen.el
@@ -40,6 +40,10 @@ (org-assert-version)
 
 (require 'ob)
 
+;; Reuse the variable assignment code from ob-shell
+(defalias 'org-babel-variable-assignments:screen
+  'org-babel-variable-assignments:shell)
+
 (defvar org-babel-screen-location "screen"
   "The command location for screen.
 In case you want to use a different screen than one selected by your $PATH")
@@ -55,8 +59,12 @@ (defun org-babel-execute:screen (body params)
   (message "Sending source code block to interactive terminal session...")
   (save-window-excursion
 (let* ((session (cdr (assq :session params)))
+   (var-lines (org-babel-variable-assignments:screen params))
(socket (org-babel-screen-session-socketname session)))
   (unless socket (org-babel-prep-session:screen session params))
+  (mapcar (lambda (var)
+(org-babel-screen-session-execute-string session var))
+  var-lines)
   (org-babel-screen-session-execute-string
session (org-babel-expand-body:generic body params)
 
-- 
2.25.1

From 1781c8986346a7ea894269f827cce80bfd5cfa70 Mon Sep 17 00:00:00 2001
From: Max Nikulin 
Date: Thu, 16 Mar 2023 21:50:24 +0700
Subject: [PATCH v4 2/2] ob-screen.el: Do not rely on
 `org-babel-variable-assignments:shell'

* lisp/ob-screen.el (org-babel-variable-assignments:screen): Use `defun'
instead of `defalias' to call variable assignment function specific
to language obtained from the `:cmd' header argument.

`org-babel-variable-assignments:shell' might be considered as
implementation detail, see

Ihor Radchenko to emacs-orgmode. Re: [PATCH] lisp/ob-screen.el: Support
~:var~ header args for babel blocks. Sun, 26 Feb 2023 12:18:14 +.


The implemented approach is not optimal since it does not allow
to decouple interpreter executable (for example python3) and babel
language (for example python).
---
 lisp/ob-screen.el | 21 +
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/lisp/ob-screen.el b/lisp/ob-screen.el
index 6e6a31ea6..5d09fe585 100644
--- a/lisp/ob-screen.el
+++ b/lisp/ob-screen.el
@@ -39,10 +39,23 @@ (require 'org-macs)
 (org-assert-version)
 
 (require 'ob)
-
-;; Reuse the variable assignment code from ob-shell
-(defalias 'org-babel-variable-assignments:screen
-  'org-babel-variable-assignments:shell)
+(require 'ob-shell)
+
+(defun org-babel-variable-assignments:screen (params)
+  "Return list of statements to assign block variables.
+
+This is an experimental feature, `:cmd' property from PARAMS
+treated as language while actually it is command (executable) name.
+It works at least for shell interpreters."
+  (and
+   (alist-get :var params)
+   (let* ((cmd (alist-get :cmd params))
+  (lang (and cmd (file-name-base cmd)))
+  (func (and lang (intern
+   (concat "org-babel-variable-assignments:" lang)
+ (if (not (fboundp func))
+ (error "Babel language support for %s is not loaded" lang)
+   (funcall func params)
 
 (defvar org-babel-screen-location "screen"
   "The command location for screen.
-- 
2.25.1



Re: org-agenda on Mac M1

2023-03-16 Thread General discussions about Org-mode.
Henrik Frisk  writes:

> When I run org-agenda I get the sub menu but if I hit 'a' emacs hangs,
> though I can get it back if I hit C-g.  [...]
>
> I have no experience in debugging, but I tried to run debug-on-error
> with org-agenda and I got the following, which is not so helpful (to
> me):
>
> [...]
>
> Anyone else has a suggestion on a next step here?

What happens when you run `M-x toggle-debug-on-quit RET' right after you
run `emacs -Q', and do your usual steps to reproduce the issue?  That
might provide a more detailed backtrace for investigation.

In addition, what version of Emacs and of org are you using?  Posting
the results of these two commands would help a lot:
- `M-: emacs-repository-version RET'
- `M-x org-version RET'

--
Best,


RY



org-agenda on Mac M1

2023-03-16 Thread Henrik Frisk
Hi,

I have rrecently had to move from Linux to MacOS and setting up on an M1
computer I have run inte to ann issue I can't figure out. When I run
org-agenda I get the sub menu but if I hit 'a' emacs hangs, though I can
get it back if I hit C-g. Without my init file it works. I have gone
through all my claendar files, adding the one at a time and I have gone
through my init file using this method:

1. Remove everything except the org-agenda stuff: org-agenda works as
expected
2. Adding one piece of the config file at a time: org-agenda works after
eache addition
3. After a emacs restart org agenda fails.

I have no experience in debugging, but I tried to run debug-on-error with
org-agenda and I got the following, which is not so helpful (to me):

* org-agenda(nil)
  funcall-interactively(org-agenda nil)
  call-interactively(org-agenda record nil)
  command-execute(org-agenda record)
  execute-extended-command(nil "org-agenda" "org-agenda")
  funcall-interactively(execute-extended-command nil "org-agenda"
"org-agenda")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)

Anyone else has a suggestion on a next step here?

/Henrik


Re: [PATCH] lisp/ob-screen.el: Support ~:var~ header args for babel blocks

2023-03-16 Thread Ihor Radchenko
Ken Mankoff  writes:

> Just a follow-up note that I am unlikely to be able to complete this patch 
> anytime soon. Re-alignment of priorities because my need for :var header 
> support in Org Babel is mitigated by a different method of injecting 
> variables into Org Babel sections: Use noweb.

Ok.
Canceled.


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [patch] ob-clojure: Fix results output

2023-03-16 Thread Ihor Radchenko
Daniel Kraus  writes:

> Attached a new patch.

Thanks!
I have no further comments.
Feel free to push.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: Noweb Function's body without evaluation

2023-03-16 Thread suarezmiguelc
Hello Ken, thank you for your message,

After reading the very interesting get_property function, I found that even 
though I will probably use it for some cases, it doesn’t apply directly, to my 
case.

For more examples, if I have 1 source code block:

>> #+name: greeting
>> #+begin_src sh :var name="world" :results output :session testing
>> 
>> echo "hello, $name\!"
>> #+end_src


I have three options in noweb to use this:
- Use its body into another begin_src source code block with <>
- Use its result “hello, world!” Into another code block, which results in 
babel trying to execute the hello, command, which doesn’t exist, this with 
<>
- Use its result, the same as above, but with another parameter, results in the 
same but the variable name is different, so <>

I’m trying to do the first, but with another parameter, so Use its body into 
another begin_src source code block with, get the resulting body after changing 
the variable without it being evaluated, so that I get a valid command to get 
to bash, like with <>, but I can specify a different name variable.

I found the [:body] param but, even though it lets me change the variable as I 
want, it then tries to evaluate it, so I get a different value but the same 
hello, command doesn’t exist. Even though what I would want is to get echo 
“hello, $name\!” but, $name is different.

Thank you for your response Ken, I hope I gave a clearer example with the above.


> 16/3/23 5:16、Ken Mankoff のメール:
> 
> Hi,
> 
> I'm not sure that I understand your issue or needs from the provided 
> examples, but I wonder if the example I provide here would be helpful. It 
> bypasses :var an lets you inject a PROPERTY value anywhere. It is also 
> language agnostic. You can use it to execute commands (that are set as 
> PROPERTY values) or set variables to values.
> 
> https://lists.gnu.org/archive/html/emacs-orgmode/2023-03/msg00251.html
> 
>  -k.
> 
> On 2023-03-15 at 18:54 -04, suarezmigu...@icloud.com wrote...
>> Hello Org-mode community. I’m using Emacs Doom Framework, specifically:
>> 
>> Emacs 28.2 (build 1, aarch64-apple-darwin22.3.0, Carbon Version 169
>> AppKit 2299.4) of 2023-02-23.
>> 
>> I use heavily org-mode for Literate DevOps, so I have a lot of shell
>> commands that connect through SSH and do some things later, for
>> example:
>> 
>> #+name: initSSH
>> #+begin_src shell :var connection=“admin@somehost"
>> 
>> ssh -t miguel@host "sudo -u someuser ssh -t $connection 'sudo su'"
>> #+end_src
>> 
>> So then I can call:
>> 
>> #+call: initSSH(connection=“admin@anotherhost”)
>> 
>> With any other header parameters or session, the above works
>> correctly. I cannot use tramp due to network latency issues, so this
>> is the most performance way for me, since I also have to do some
>> multi-hops which are indeed supported in tramp, but it is too slow for
>> me, so I rather only commands.
>> 
>> The thing is that, I then would like to call these not with a #+call
>> function, but add them into a bigger script, let’s say that I define
>> another command:
>> 
>> #+name: getStorage
>> #+begin_src shell
>> 
>> df
>> #+end_src
>> 
>> Which has to be run in a remote server, could be any remote server as
>> I have to connect to several. So I would like to be able to:
>> 
>> #+begin_src shell
>> <>
>> <>
>> #+end_src
>> 
>> 
>> The first doesn’t work as org-mode runs the code and passes the
>> resulting string to bash, which isn’t a command. The latter works
>> normally. So the issue here are the parameters.
>> 
>> So I made another simple example for this:
>> 
>> #+name: greeting
>> #+begin_src sh :var name="world" :results output :session testing
>> 
>> echo "hello, $name\!"
>> #+end_src
>> 
>> #+results: greeting
>> #+begin_src sh
>> 
>> hello, world\!
>> #+end_src
>> 
>> #+begin_src shell
>> <>
>> #+end_src
>> 
>> 
>> This results in sh: hello,: command not found, as it is executing the 
>> function. I see in the documentation that I can:
>> - Call a function’s body with <>
>> - Execute a function and return its results with <>
>> - Execute a function and return its results even with different params with 
>> <>
>> 
>> So right now, the one that’s missing is, call a function’s body with 
>> different parameters. So the
>> function <> is not evaluated.
>> 
>> After searching a lot, I came across:
>> 
>> #+begin_src shell :session testing
>> <>
>> #+end_src
>> 
>> Which results in:
>> 
>> sh-3.2$ PS1="org_babel_sh_prompt> "
>> org_babel_sh_prompt> name='Testin'
>> org_babel_sh_prompt> echo "hello, $name\!"
>> hello, Testin\!
>> org_babel_sh_prompt> echo 'org_babel_sh_eoe'
>> org_babel_sh_eoe
>> org_babel_sh_prompt> hello, Testin\!
>> sh: hello,: command not found
>> org_babel_sh_prompt> echo 'org_babel_sh_eoe'
>> org_babel_sh_eoe
>> org_babel_sh_prompt> 
>> 
>> Which is somewhat what I need since at least the variable is changed,
>> but the result of this execution is also passed to shell so, same
>> error.
>> 
>> I can’t find much documentation about