emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: lin Sun <sunlin7@yahoo.com>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>,
	Timothy <tecosaur@gmail.com>, Bastien Guerry <bzg@gnu.org>
Subject: Re: [PATCH] before emit an error message, try to load the babel language
Date: Sun, 23 Apr 2023 06:19:27 +0000	[thread overview]
Message-ID: <CABCREdoxPNi4PBqZNqCv4cXP6BayKzhJgJqB94=sWPguoMjPMw@mail.gmail.com> (raw)
In-Reply-To: <87354suluu.fsf@localhost>

[-- Attachment #1: Type: text/plain, Size: 1048 bytes --]

On Sat, Apr 22, 2023 at 12:42 PM Ihor Radchenko <yantar92@posteo.net> wrote:
> the cleanest way will be using `add-variable-watcher'.
Hi Ihor,
The "add-variable-watcher" may not be able to deal with the
local/global variable `org-babel-load-languages' correctly.

On Sat, Apr 22, 2023 at 8:33 AM Ruijie Yu <ruijie@netyu.xyz> wrote:
> Instead of that, I think you should have some sort of conditional in the
> `unless' condition.  Something like:
> --8<---------------cut here---------------start------------->8---
> (unless (or (fboundp cmd)
>             (ignore (and (alist-get lang org-babel-load-languages)
>                          (require (intern (concat "ob-" lang)))))
>             (fboundp cmd))
>   (error "... %s" lang))
> --8<---------------cut here---------------end--------------->8---
The logic in the patch will follow the function
`org-babel-do-load-languages' to load the ob-LANG without capturing
the error.
I changed the patch to follow your comments.
Please review the new patch I attached. Thanks.

[-- Attachment #2: 0001-lisp-ob-core.el-load-lang-in-org-babel-execute-src-b.patch --]
[-- Type: text/x-patch, Size: 1542 bytes --]

From acc72f9f42120d07cc728eeebb9dd976b4568c1f Mon Sep 17 00:00:00 2001
From: Lin Sun <sunlin7@hotmail.com>
Date: Sat, 22 Apr 2023 00:00:39 +0000
Subject: [PATCH] *lisp/ob-core.el: load lang in (org-babel-execute-src-block)

---
 lisp/ob-core.el | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 471887a3a..0fc4cbe9f 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -714,6 +714,8 @@ a list with the following pattern:
 (defvar *this*) ; Dynamically bound in `org-babel-execute-src-block'
                 ; and `org-babel-read'
 
+(defvar org-babel-load-languages)
+
 ;;;###autoload
 (defun org-babel-execute-src-block (&optional arg info params executor-type)
   "Execute the current source code block and return the result.
@@ -794,7 +796,9 @@ guess will be made."
 		       d))))
 		 (cmd (intern (concat "org-babel-execute:" lang)))
 		 result exec-start-time)
-	    (unless (fboundp cmd)
+	    (unless (or (fboundp cmd)
+			(and (alist-get (intern lang) org-babel-load-languages)
+			     (require (intern (concat "ob-" lang)) nil t)))
 	      (error "No org-babel-execute function for %s!" lang))
 	    (message "Executing %s %s %s..."
 		     (capitalize lang)
@@ -1952,8 +1956,6 @@ With optional prefix argument ARG, jump backward ARG many source blocks."
   (interactive "p")
   (org-previous-block arg org-babel-src-block-regexp))
 
-(defvar org-babel-load-languages)
-
 ;;;###autoload
 (defun org-babel-mark-block ()
   "Mark current source block."
-- 
2.20.5


  reply	other threads:[~2023-04-23  6:20 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <388850760.3644614.1634354740816.ref@mail.yahoo.com>
2021-10-16  3:25 ` Subject: [PATCH] Fix DISPLAY error on exporting org with plantuml to html Sun Lin
2021-10-18  1:39   ` Sun Lin
2021-10-18  5:07     ` Bastien Guerry
2021-10-20 12:02       ` Sun Lin
2021-11-18  5:42         ` Sun Lin
2021-11-18  7:38   ` Timothy
2021-11-18  7:47     ` Sun Lin
2021-11-30  1:41       ` Sun Lin
2021-11-30  4:18         ` Timothy
2021-11-30  6:05           ` Sun Lin
2022-06-07  5:48             ` lin Sun via General discussions about Org-mode.
2022-06-07  6:34               ` Dr. Arne Babenhauserheide
2022-06-07 14:49                 ` Max Nikulin
2022-06-07 15:30                 ` lin Sun
2022-06-08  1:45               ` Ihor Radchenko
2022-06-08  4:35                 ` lin Sun
2023-04-22  7:21                   ` [PATCH] before emit an error message, try to load the babel language lin Sun
2023-04-22  8:25                     ` Ruijie Yu via General discussions about Org-mode.
2023-04-22 12:45                     ` Ihor Radchenko
2023-04-23  6:19                       ` lin Sun [this message]
2023-04-23  7:45                         ` Ihor Radchenko
2023-04-25  2:50                           ` lin Sun
2023-04-25  8:12                             ` Ihor Radchenko
2023-04-25 14:30                               ` Ruijie Yu via General discussions about Org-mode.
2023-04-25 14:48                                 ` Ihor Radchenko
2023-04-26  2:33                                   ` Ruijie Yu via General discussions about Org-mode.
2023-04-26  4:15                                     ` lin Sun
2023-04-26  7:00                                       ` Ihor Radchenko
2023-04-26 16:43                                         ` lin Sun
2023-04-26 16:59                                           ` Ihor Radchenko
2023-04-26  6:59                                     ` 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='CABCREdoxPNi4PBqZNqCv4cXP6BayKzhJgJqB94=sWPguoMjPMw@mail.gmail.com' \
    --to=sunlin7@yahoo.com \
    --cc=bzg@gnu.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=tecosaur@gmail.com \
    --cc=yantar92@posteo.net \
    /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).