lin Sun <sunl...@yahoo.com> writes:
> Hi, > The function `org-babel-execute-src-block' will emit an error message > if the language is not loaded. > > Before the error message, the patch will give a try to load the > associated babel language. > > Why does the language exist in the `lang org-babel-load-languages' but > not be loaded? > Because the `org-babel-load-languages' are defined as a customer > variable with :set 'org-babel-do-load-languages, the ":set" function > can only be triggered with function `custom-set-variables`. > While setq/cl-pushnew `org-babel-load-languages' won't trigger the > `:set' function, then the error message will be displayed if I run the > code in the org file. > > Please help review that patch. Thanks. Regards > > [2. text/x-patch; > 0001-lisp-ob-core.el-load-lang-in-org-babel-execute-src-b.patch]... I think this patch slightly modifies the logic of the error. --8<---------------cut here---------------start------------->8--- (unless (fboundp cmd) - (error "No org-babel-execute function for %s!" lang)) + (if (alist-get lang org-babel-load-languages) + (require (intern (concat "ob-" lang))) + (error "No org-babel-execute function for %s!" lang))) --8<---------------cut here---------------end--------------->8--- You are saying, that when (fboundp cmd) returns nil, and when (alist-get ...) returns non-nil, then perform the `require', and assume this function is now available. 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--- This preserves the logic of the message: when we cannot get "org-babel-execute" immediately, we then try to require the module and try again. Then, we check the function again and conclude that the org-babel-execute function is not found for this language. Thoughts? -- Best, RY [Please note that this mail might go to spam due to some misconfiguration in my mail server -- still investigating.]