Skip to content

Commit

Permalink
fix: Set the starting position to search for EXPORT_OPTIONS
Browse files Browse the repository at this point in the history
When the target file is not open, the start position defaults to 1 and
so the EXPORT_OPTIONS in the heading where we intend to search is
never found.
  • Loading branch information
kaushalmodi committed Mar 18, 2022
1 parent a5a110b commit c8c9cb8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
18 changes: 14 additions & 4 deletions ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -1910,12 +1910,15 @@ This function will never return nil."
"")))
(substring (md5 title) 0 hash-len)))

(defun org-hugo--get-elem-with-prop (prop &optional _info)
(defun org-hugo--get-elem-with-prop (prop &optional pom _info)
"Find the first element with PROP property in the current tree.
PROP is a property symbol with a : prefix, example:
`:EXPORT_FILE_NAME'.
Optional argument POM is the position or marker from which the
upward search for PROP should begin.
Return a cons of type (ELEM . PVAL) where ELEM is the element
containing the property PROP and PVAL is the property's value.
Expand All @@ -1926,13 +1929,17 @@ versions for the issue that `org-element-at-point' does not
return an element with all the inherited properties. That issue
is fixed in Org main branch at least as of 2022-03-17."
(org-with-wide-buffer
;; (message (format "[search prop DBG] point 1 : %S" (point)))
(when pom
(goto-char pom))
;; (message (format "[search prop DBG] point 2 : %S" (point)))
(org-back-to-heading-or-point-min :invisible-ok)
(let ((elem (org-element-at-point))
(level t)
pval)
(catch :found
(while elem
;; (message (format "[search prop DBG] elem : %S" elem ))
;; (message (format "[search prop DBG] prop %S, elem : %S" prop elem))
(setq pval (org-element-property prop elem))
;; (message "[search prop DBG] level %S, pval %S" level pval)
(when (or pval (null level))
Expand Down Expand Up @@ -1973,7 +1980,7 @@ INFO is a plist used as a communication channel.
Return nil if none of the above are true."
(org-with-wide-buffer
(let ((heading-begin (org-element-property :begin heading)))
(when (numberp heading-begin)
(when heading-begin
(goto-char heading-begin)))
(let ((file (org-string-nw-p (org-export-get-node-property :EXPORT_FILE_NAME heading inherit-export-file-name)))
bundle slug)
Expand Down Expand Up @@ -4489,7 +4496,10 @@ links."
;; in a parent heading.
(plist-get
(org-export--parse-option-keyword
(or (cdr (org-hugo--get-elem-with-prop :EXPORT_OPTIONS)) ""))
(or (cdr (org-hugo--get-elem-with-prop
:EXPORT_OPTIONS
(org-element-property :begin el)))
""))
:with-broken-links))
(user-error "Unable to resolve link: %S" (nth 1 err))))))
(org-export-resolve-id-link el (org-export--collect-tree-properties ast info))))
Expand Down
28 changes: 28 additions & 0 deletions test/ert/telement.el
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,33 @@
<point>"
(cdr (org-hugo--get-elem-with-prop :EXPORT_HUGO_SECTION))))))

(ert-deftest test-elem/starting-position ()
"Test property lookup by specifying the starting position."

;; Here, the needed property is not found because the starting
;; position for search is set to the beginning of the buffer.
(should
(equal nil
(org-test-with-parsed-data
"
* Heading 1<point>
:PROPERTIES:
:EXPORT_OPTIONS: toc:t
:END:"
(cdr (org-hugo--get-elem-with-prop :EXPORT_OPTIONS 1)))))

;; Here, the needed property *is* found because the starting
;; position for search is set correctly, and that overrides the init
;; position set by <point> in this test.
(should
(string= "toc:t"
(org-test-with-parsed-data
"<point>
* Heading 2
:PROPERTIES:
:EXPORT_OPTIONS: toc:t
:END:"
(cdr (org-hugo--get-elem-with-prop :EXPORT_OPTIONS 2))))))


(provide 'telement)

0 comments on commit c8c9cb8

Please sign in to comment.