Pedro Andres Aranda Gutierrez <paag...@gmail.com> writes:

> An alternative is to advise the user who uses org as a high-level
> alternative for LaTeX to include
> (require 'ox-latex)
> in the init.el file if (s)he uses an autocompletion framework.
>
> Maybe it might be worth adding a word in the manual. WDYT?

Hmm. I remember that manual instructs users to load ox-* libraries
explicitly. So, what you are asking about is already there, right in
"13 Exporting" section.

Reading through those section I also found one detail I missed -
`org-export-backends' option. I think that we can actually load some
export backends in `pcomplete/org-mode/file-option/options', as you
suggested in the patch. But those backends should include what is listed
in `org-export-backends'; not just ox-latex.

May you try the attached patch?

>From 24827bb6759209fd2275ca51d758c46df5eeb798 Mon Sep 17 00:00:00 2001
Message-ID: <24827bb6759209fd2275ca51d758c46df5eeb798.1744535678.git.yanta...@posteo.net>
From: Ihor Radchenko <yanta...@posteo.net>
Date: Sun, 13 Apr 2025 11:11:16 +0200
Subject: [PATCH] org-pcomplete: Autoload export backends for completion

* lisp/org.el (org-load-export-backends): New function loading
`org-export-backends'.  The function is factored out
from (eval-after-load 'ox ...) form.
* lisp/org-pcomplete.el (pcomplete/org-mode/file-option/options):
Use the new function.

Link: https://list.orgmode.org/orgmode/cao48bk-nbhy0thdj57_3omihs8nhxpoyvmycmqlao+2bd43...@mail.gmail.com/
---
 lisp/org-pcomplete.el |  2 ++
 lisp/org.el           | 15 ++++++++++-----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/lisp/org-pcomplete.el b/lisp/org-pcomplete.el
index 498a01da3c..ff03e07220 100644
--- a/lisp/org-pcomplete.el
+++ b/lisp/org-pcomplete.el
@@ -37,6 +37,7 @@ (require 'org-macs)
 (require 'org-compat)
 (require 'pcomplete)
 
+(declare-function org-load-export-backends "org" ())
 (declare-function org-at-heading-p "org" (&optional ignored))
 (declare-function org-babel-combine-header-arg-lists "ob-core" (original &rest others))
 (declare-function org-babel-get-src-block-info "ob-core" (&optional no-eval datum))
@@ -318,6 +319,7 @@ (defun pcomplete/org-mode/file-option/title ()
 
 (defun pcomplete/org-mode/file-option/options ()
   "Complete arguments for the #+OPTIONS file option."
+  (org-load-export-backends)
   (while (pcomplete-here
 	  (pcomplete-uniquify-list
 	   (append
diff --git a/lisp/org.el b/lisp/org.el
index e37ed49784..b8d687c950 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -915,11 +915,16 @@ (defcustom org-export-backends '(ascii html icalendar latex odt)
 	      (const :tag "C  s5          Export buffer to s5 presentations" s5)
 	      (const :tag "C  taskjuggler Export buffer to TaskJuggler format" taskjuggler)))
 
-(eval-after-load 'ox
-  '(dolist (backend org-export-backends)
-     (condition-case-unless-debug nil (require (intern (format "ox-%s" backend)))
-       (error (message "Problems while trying to load export backend `%s'"
-		       backend)))))
+(defun org-load-export-backends ()
+  "Load all the export backends from `org-export-backends'."
+  (unless (featurep 'ox)
+    (require 'ox)
+    (dolist (backend org-export-backends)
+      (condition-case-unless-debug nil (require (intern (format "ox-%s" backend)))
+        (error (message "Problems while trying to load export backend `%s'"
+		        backend))))))
+
+(eval-after-load 'ox '(org-load-export-backends))
 
 (defcustom org-support-shift-select nil
   "Non-nil means make shift-cursor commands select text when possible.
-- 
2.47.1

-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

Reply via email to