浏览代码

ox.el: Issue error for unresolved fuzzy link

* lisp/ox.el (org-export-resolve-fuzzy-link): Throw an error instead
  of returning nil when link can't be resolved.

* testing/lisp/test-ox.el (test-org-export/resolve-fuzzy-link): Change
  last test from should-not to should-error

In addition to throwing an error, don't store the failed match in the
link cache.

TINYCHANGE
Jacob Gerlach 10 年之前
父节点
当前提交
dc08e98885
共有 2 个文件被更改,包括 6 次插入6 次删除
  1. 4 4
      lisp/ox.el
  2. 2 2
      testing/lisp/test-ox.el

+ 4 - 4
lisp/ox.el

@@ -4023,7 +4023,7 @@ Return value can be an object, an element, or nil:
   will be given to the one with the closest common ancestor, if
   will be given to the one with the closest common ancestor, if
   any, or the first one in the parse tree otherwise.
   any, or the first one in the parse tree otherwise.
 
 
-- Otherwise, return nil.
+- Otherwise, throw an error.
 
 
 Assume LINK type is \"fuzzy\".  White spaces are not
 Assume LINK type is \"fuzzy\".  White spaces are not
 significant."
 significant."
@@ -4070,7 +4070,7 @@ significant."
      ;; Last case: link either points to a headline or to nothingness.
      ;; Last case: link either points to a headline or to nothingness.
      ;; Try to find the source, with priority given to headlines with
      ;; Try to find the source, with priority given to headlines with
      ;; the closest common ancestor.  If such candidate is found,
      ;; the closest common ancestor.  If such candidate is found,
-     ;; return it, otherwise return nil.
+     ;; return it, otherwise signal an error.
      (t
      (t
       (let ((find-headline
       (let ((find-headline
 	     (function
 	     (function
@@ -4096,8 +4096,8 @@ significant."
 		       (org-element-lineage parent-hl nil t))))
 		       (org-element-lineage parent-hl nil t))))
 	    (let ((foundp (funcall find-headline path parent)))
 	    (let ((foundp (funcall find-headline path parent)))
 	      (when foundp (throw 'exit foundp))))
 	      (when foundp (throw 'exit foundp))))
-	  ;; No destination found: return nil.
-	  (and (not match-title-p) (puthash path nil link-cache))))))))
+	  ;; No destination found: error.
+	  (user-error "Unable to resolve link \"%s\"" raw-path)))))))
 
 
 (defun org-export-resolve-id-link (link info)
 (defun org-export-resolve-id-link (link info)
   "Return headline referenced as LINK destination.
   "Return headline referenced as LINK destination.

+ 2 - 2
testing/lisp/test-ox.el

@@ -2503,8 +2503,8 @@ Another text. (ref:text)
 	 (org-element-type
 	 (org-element-type
 	  (org-export-resolve-fuzzy-link
 	  (org-export-resolve-fuzzy-link
 	   (org-element-map tree 'link 'identity info t) info)))))
 	   (org-element-map tree 'link 'identity info t) info)))))
-  ;; Return nil if no match.
-  (should-not
+  ;; Error if no match.
+  (should-error
    (org-test-with-parsed-data "[[target]]"
    (org-test-with-parsed-data "[[target]]"
      (org-export-resolve-fuzzy-link
      (org-export-resolve-fuzzy-link
       (org-element-map tree 'link 'identity info t) info)))
       (org-element-map tree 'link 'identity info t) info)))