emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] [RFC] [PATCH] Warn about unexpanded macros on export


From: Aaron Ecay
Subject: [O] [RFC] [PATCH] Warn about unexpanded macros on export
Date: Fri, 19 Sep 2014 15:12:48 -0400
User-agent: Notmuch/0.18.1+51~gbbbdf04 (http://notmuchmail.org) Emacs/24.4.50.2 (x86_64-unknown-linux-gnu)

Hello all,

Currently, if a macro is not defined, it will silently produce an empty
string while exporting.  This situation could arise for example if a
macro name is acidentally mistyped.  I think it’s desirable to warn the
user in this case.  The attached patch introduces a function to do so,
and shows how it would be integrated in the latex backend.  This raises
several questions:

1. Should the warning be a “message” (allows the export process to
   continue) or a “user-error” (stops the export process)?  Or, should
   this be configurable?

2. Since this is a feature that many backends will want to use, should
   we introduce a new “abstract” backend from which other backends can
   inherit, which incorporates this feature, and others like it in the
   future?  The idea would be similar to prog-mode in emacs, the major
   mode from which programming-language modes can derive.  The
   alternative is adding the (macro . org-export-macro-warn) entry
   manually to all the relevant backends, and relying on future backend
   authors to do the same.

3. Should this even be implemented as part of the backend’s
   translate-alist, or at a lower level?

Thanks,

-- 
Aaron Ecay
>From 1c9f85bcb93dbc56d01b138f5a4a11ad0933b5c6 Mon Sep 17 00:00:00 2001
From: Aaron Ecay <address@hidden>
Date: Fri, 19 Sep 2014 14:46:37 -0400
Subject: [PATCH] ox: warn if unexpanded macros are found when exporting

* lisp/ox.el (org-export-macro-warn): New function.
* lisp/ox-latex.el: Use it.
---
 lisp/ox-latex.el | 1 +
 lisp/ox.el       | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index f59d6b2..7670ccb 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -65,6 +65,7 @@
     (latex-fragment . org-latex-latex-fragment)
     (line-break . org-latex-line-break)
     (link . org-latex-link)
+    (macro . org-export-macro-warn)
     (node-property . org-latex-node-property)
     (paragraph . org-latex-paragraph)
     (plain-list . org-latex-plain-list)
diff --git a/lisp/ox.el b/lisp/ox.el
index f01f951..a4988f4 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -5619,6 +5619,11 @@ to `:default' encoding. If it fails, return S."
        (plist-get translations :default)
        s)))
 
+(defun org-export-macro-warn (macro contents info)
+  ;; TODO: should this be a user-error?
+  (message "WARNING: undefined macro %s" (org-element-property :key macro))
+  ;; Return empty string to avoid interfering with the export output.
+  "")
 
 
 ;;; Asynchronous Export
-- 
2.1.0


reply via email to

[Prev in Thread] Current Thread [Next in Thread]