Re: Async Python src block behavior with :dir header property

2024-02-13 Thread Ihor Radchenko
Nasser Alkmim writes: > On the same note, it would be convenient to have a hook to run after the > async execution returns the output. Similar to > 'org-babel-after-execute-hook'. So I could, for instance, redisplay the > inline image previews. Is there an easy way to do that? Maybe we can

Re: Async Python src block behavior with :dir header property

2024-02-13 Thread Nasser Alkmim
Excellent job Ihor and Jack. On the same note, it would be convenient to have a hook to run after the async execution returns the output. Similar to 'org-babel-after-execute-hook'. So I could, for instance, redisplay the inline image previews. Is there an easy way to do that? -- Nasser

Re: Async Python src block behavior with :dir header property

2024-02-10 Thread Ihor Radchenko
Jack Kamm writes: >> See the attached updated version of the patch set. > > Looks good, thanks. I tested it out it works without errors/warnings > now. Applied, onto main. https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=13d0f8bf8

Re: Async Python src block behavior with :dir header property

2024-02-10 Thread Jack Kamm
Ihor Radchenko writes: >> Compiling >> /home/jack/src/org-mode/2024-01-async-file-results-dir/lisp/ob-core.el... >> >> In org-babel-session-buffer: >> ob-core.el:785:15: Warning: reference to free variable ‘buffer-name’ > > But this is a real problem. > See the attached updated version

Re: Async Python src block behavior with :dir header property

2024-02-08 Thread Bruno Barbier
Ihor Radchenko writes: > Jack Kamm writes: > >> On executing any python session block I am getting the following error >> which I think is caused by the above: >> >> Debugger entered--Lisp error: (void-variable buffer-name) > > That's a mystery. It looks like 'when-let*' doesn't accept

Re: Async Python src block behavior with :dir header property

2024-02-08 Thread Ihor Radchenko
Jack Kamm writes: > On executing any python session block I am getting the following error > which I think is caused by the above: > > Debugger entered--Lisp error: (void-variable buffer-name) That's a mystery. > Also, make shows a byte-compiler warning about this: > > Compiling >

Re: Async Python src block behavior with :dir header property

2024-02-07 Thread Jack Kamm
Ihor Radchenko writes: > +(defun org-babel-session-buffer ( info) > + "Return buffer name for session associated with current code block. > +Return nil when no such live buffer with process exists. > +When INFO is non-nil, it should be a list returned by > +`org-babel-get-src-block-info'. >

Re: Async Python src block behavior with :dir header property

2024-02-06 Thread Ihor Radchenko
Jack Kamm writes: > Ihor Radchenko writes: > >> What we can do is to introduce a new backend template function >> org-babel-session-buffer: that will be passed a session name and >> src block params and return the session buffer name. >> >> If such function is not defined, we fall back to

Re: Async Python src block behavior with :dir header property

2024-02-05 Thread Jack Kamm
Ihor Radchenko writes: > What we can do is to introduce a new backend template function > org-babel-session-buffer: that will be passed a session name and > src block params and return the session buffer name. > > If such function is not defined, we fall back to assumption that session > buffer

Re: Async Python src block behavior with :dir header property

2024-02-05 Thread Ihor Radchenko
Jack Kamm writes: > It's because ob-python starts the session in buffer "*pysession*" (it > adds earmuffs around the session name when missing). So the following > doesn't find the inferior Python: Good point. Some backends indeed do not have comint buffer named the same as :session name. What

Re: Async Python src block behavior with :dir header property

2024-02-04 Thread Jack Kamm
Ihor Radchenko writes: > Thanks! > Attaching the two patches combined with some fixed to my patch. > > Please check if these two patches solve the discussed bug. The original bug for async sessions looks fixed. But I encountered a complication regarding the non-async bug of changing :dir. In

Re: Async Python src block behavior with :dir header property

2024-02-04 Thread Ihor Radchenko
Jack Kamm writes: > I updated the patch for `org-babel-comint-async-filter' to follow the > same approach, setting default-directory based on the session buffer's > value rather than the :dir header arg. Thanks! Attaching the two patches combined with some fixed to my patch. Please check if

Re: Async Python src block behavior with :dir header property

2024-02-03 Thread Jack Kamm
Ihor Radchenko writes: >> I agree it's a problem -- if there are multiple blocks with the same >> session but different ":dir" arguments, then a ":file" result of the >> second block will be relative to the wrong :dir. >> >> This seems like a longstanding problem, and affects both async and >>

Re: Async Python src block behavior with :dir header property

2024-02-03 Thread Ihor Radchenko
Jack Kamm writes: > Ihor Radchenko writes: > >> The patch generally looks reasonable, although I am slightly concerned >> about interaction between :dir and session we describe in the manual: >> >> When ‘dir’ is used with ‘session’, Org sets the starting directory >> for a new session.

Re: Async Python src block behavior with :dir header property

2024-02-02 Thread Jack Kamm
Ihor Radchenko writes: > The patch generally looks reasonable, although I am slightly concerned > about interaction between :dir and session we describe in the manual: > > When ‘dir’ is used with ‘session’, Org sets the starting directory > for a new session. But Org does not alter the

Re: Async Python src block behavior with :dir header property

2024-02-01 Thread Ihor Radchenko
Jack Kamm writes: >> Confirmed. > > Does the attached patch fix the issue? > > It seems the problem is with async sessions generally (not just > ob-python), and happens because `org-babel-comint-async-filter' does not > set `default-directory' before calling `org-babel-insert-result', unlike >

Re: Async Python src block behavior with :dir header property

2024-02-01 Thread Nasser Alkmim
Jack Kamm writes: > > Does the attached patch fix the issue? > I briefly tested it here and it works. Thanks for taking a look into it. -- Nasser Alkmim +43 677 6408 9171

Re: Async Python src block behavior with :dir header property

2024-01-31 Thread Jack Kamm
Ihor Radchenko writes: > [ CCing ob-python maintainer ] > > Nasser Alkmim writes: > >> Here is a clearer description of the unwanted behavior: >> >> 1. emacs -Q ~/Desktop/testasync.org >> >> Then evaluate (require 'ob-python) and paste this source block: >> >> #+begin_src python :dir otherdir

Re: Async Python src block behavior with :dir header property

2024-01-31 Thread Ihor Radchenko
[ CCing ob-python maintainer ] Nasser Alkmim writes: > Here is a clearer description of the unwanted behavior: > > 1. emacs -Q ~/Desktop/testasync.org > > Then evaluate (require 'ob-python) and paste this source block: > > #+begin_src python :dir otherdir :async yes :session pysession :return

Re: Async Python src block behavior with :dir header property

2024-01-31 Thread Nasser Alkmim
Ihor Radchenko writes: > Do you mean that you have no problem after you add :mkdirp yes? No. Just that I can reproduce the examples in the first message. Here is a clearer description of the unwanted behavior: 1. emacs -Q ~/Desktop/testasync.org Then evaluate (require 'ob-python) and paste

Re: Async Python src block behavior with :dir header property

2024-01-31 Thread Ihor Radchenko
Nasser Alkmim writes: >>> #+begin_src python :dir asyncpy :async :session :return figname :results >>> file value >> >> These header arguments are not correctly formatted. >> Try M-x org-lint > > I tried org-lint and it says that the header argument is "unknown". You should have got 1 low

Re: Async Python src block behavior with :dir header property

2024-01-31 Thread Nasser Alkmim
Ihor Radchenko writes: > Nasser Alkmim writes: > >> This does not work. >> Even though the python execution is in the right directory and the file is >> saved >> correctly. >> The =return= does not produces the right file path considering the directory. >> >> #+begin_src python :dir asyncpy

Re: Async Python src block behavior with :dir header property

2024-01-31 Thread Ihor Radchenko
Nasser Alkmim writes: > This does not work. > Even though the python execution is in the right directory and the file is > saved correctly. > The =return= does not produces the right file path considering the directory. > > #+begin_src python :dir asyncpy :async :session :return figname

Async Python src block behavior with :dir header property

2024-01-31 Thread Nasser Alkmim
Hi, I'm in the latest Emacs GUI. This works, the =return figname= apparently can recognizee that we are in the =:dir=. #+begin_src python :dir asyncpy :return figname :results file value import matplotlib.pyplot as plt plt.figure(figsize=(4*.5, 3*.5)) plt.plot([1, 2]) figname = 'fig.svg'