emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Aaron Ecay <aaronecay@gmail.com>
To: Org-mode <emacs-orgmode@gnu.org>
Subject: [RFC] [PATCH] Warn about unexpanded macros on export
Date: Fri, 19 Sep 2014 15:12:48 -0400	[thread overview]
Message-ID: <87k34zqv9r.fsf@gmail.com> (raw)

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

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-warn-if-unexpanded-macros-are-found-when-exportin.patch --]
[-- Type: text/x-diff, Size: 1324 bytes --]

From 1c9f85bcb93dbc56d01b138f5a4a11ad0933b5c6 Mon Sep 17 00:00:00 2001
From: Aaron Ecay <aaronecay@gmail.com>
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.
+  "")
 
 \f
 ;;; Asynchronous Export
-- 
2.1.0


             reply	other threads:[~2014-09-19 19:13 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-19 19:12 Aaron Ecay [this message]
2014-09-19 19:29 ` [RFC] [PATCH] Warn about unexpanded macros on export Nicolas Goaziou
2014-09-23  3:25   ` Aaron Ecay
2014-09-23 16:59     ` Grant Rettke
2014-09-23 17:18       ` Aaron Ecay
2014-09-23 17:29         ` Jacob Gerlach
2014-09-23 21:10           ` Nicolas Goaziou
2014-09-23 20:24     ` Nicolas Goaziou
2014-09-28  3:53       ` Aaron Ecay
2014-09-28  6:59         ` Nicolas Goaziou
2014-10-12 15:48           ` Aaron Ecay
2014-09-23 20:26     ` Rasmus
2014-09-28  4:00       ` Aaron Ecay
2014-09-28  7:03         ` Nicolas Goaziou
2014-10-12 15:49           ` Aaron Ecay
2014-10-12 17:19             ` Nicolas Goaziou
2015-03-12  2:55           ` Jacob Gerlach
2015-03-15  8:44             ` Nicolas Goaziou
2015-03-17 16:20               ` Jacob Gerlach
2015-03-17 22:38                 ` Nicolas Goaziou
2015-03-18 20:25                   ` Jacob Gerlach

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=87k34zqv9r.fsf@gmail.com \
    --to=aaronecay@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /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).