kaushalmodi / ox-hugo

A carefully crafted Org exporter back-end for Hugo
https://ox-hugo.scripter.co
GNU General Public License v3.0
867 stars 130 forks source link

broken-links handling only for fuzzy not id-type links #715

Open cpbotha opened 1 year ago

cpbotha commented 1 year ago

Actual Behavior

With #+OPTIONS: broken-links:t I could still get the 'Unable to resolve link; aborting: "4b133a7a-a81c-44d4-9bea-8e1c72ed5847"' in spite of all the work related to #587 -- if that broken link was in one of the org-id-location files.

Expected Behavior

With #+OPTIONS: broken-links:t an ox-hugo export should ignore any broken links, and run to completion.

Prposed fix

It looks like the handling of the org-link-broken signal was only on the fuzzy-type link. When I change the code like the diff below to broaden the org-link-broken handling to span all link types (note that I've only moved the link type check to inside the condition-case), I am able to export successfully.

This could have been an oversight be the original implementor?

diff -u /Users/charlbotha/.emacs.d/elpa/ox-hugo-20221028.1631/ox-hugo.el.orig /Users/charlbotha/.emacs.d/elpa/ox-hugo-20221028.1631/ox-hugo.el
--- /Users/charlbotha/.emacs.d/elpa/ox-hugo-20221028.1631/ox-hugo.el.orig   2023-06-29 14:34:42
+++ /Users/charlbotha/.emacs.d/elpa/ox-hugo-20221028.1631/ox-hugo.el    2023-06-29 21:02:53
@@ -4619,25 +4619,25 @@
               (let ((type (org-element-property :type el)))
                 (when (member type '("custom-id" "id" "fuzzy"))
                   (let* ((raw-link (org-element-property :raw-link el))
-                         (destination (if (string= type "fuzzy")
-                                          (progn
-                                            ;; Derived from ox.el -> `org-export-data'.  If a broken link is seen
-                                            ;; and if `broken-links' option is not nil, ignore the error.
-                                            (condition-case err
-                                                (org-export-resolve-fuzzy-link el info)
-                                              (org-link-broken
-                                               (unless (or (plist-get info :with-broken-links)
-                                                           ;; Parse the `:EXPORT_OPTIONS' property if set
-                                                           ;; in a parent heading.
-                                                           (plist-get
-                                                            (org-export--parse-option-keyword
-                                                             (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))))
+                         (destination 
+                          ;; Derived from ox.el -> `org-export-data'.  If a broken link is seen
+                          ;; and if `broken-links' option is not nil, ignore the error.
+                          (condition-case err
+                              (if (string= type "fuzzy")
+                                  (org-export-resolve-fuzzy-link el info)
+                                (org-export-resolve-id-link el (org-export--collect-tree-properties ast info)))
+                            (org-link-broken
+                             (unless (or (plist-get info :with-broken-links)
+                                         ;; Parse the `:EXPORT_OPTIONS' property if set
+                                         ;; in a parent heading.
+                                         (plist-get
+                                          (org-export--parse-option-keyword
+                                           (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))))))
                          (source-path (org-hugo--heading-get-slug el info :inherit-export-file-name))
                          (destination-path (org-hugo--heading-get-slug destination info :inherit-export-file-name))
                          (destination-type (org-element-type destination)))

Diff finished.  Thu Jun 29 21:04:21 2023

Ox-Hugo Debug Information

Backtrace:

Debugger entered--Lisp error: (org-link-broken "4b133a7a-a81c-44d4-9bea-8e1c72ed5847")
  signal(org-link-broken ("4b133a7a-a81c-44d4-9bea-8e1c72ed5847"))
  (or (let ((local-ids (or (plist-get info :id-local-cache) (let ((table ...)) (org-element-map (plist-get info :parse-tree) 'headline #'... info) (plist-put info :id-local-cache table) table)))) (gethash id local-ids)) (cdr (assoc id (plist-get info :id-alist))) (signal 'org-link-broken (list id)))
  (let ((id (org-element-property :path link))) (or (let ((local-ids (or (plist-get info :id-local-cache) (let (...) (org-element-map ... ... ... info) (plist-put info :id-local-cache table) table)))) (gethash id local-ids)) (cdr (assoc id (plist-get info :id-alist))) (signal 'org-link-broken (list id))))
  org-export-resolve-id-link((link (:type "id" :path "4b133a7a-a81c-44d4-9bea-8e1c72ed5847" :format bracket :raw-link "id:4b133a7a-a81c-44d4-9bea-8e1c72ed5847" :application nil :search-option nil :begin 239 :end 309 :contents-begin 282 :contents-end 307 :post-blank 0 :parent (paragraph (:begin 239 :end 310 :contents-begin 239 :contents-end 310 :post-blank 0 :post-affiliated 239 :mode planning :granularity nil :parent (section (:begin 239 :end 311 :contents-begin 239 :contents-end 310 :robust-begin 239 :robust-end 308 :post-blank 1 :post-affiliated 239 :mode section :granularity nil :parent (headline (:raw-value "Vitals" :begin 229 :end 311 :pre-blank 1 :contents-begin 239 :contents-end 310 :robust-begin 241 :robust-end 308 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 1 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 229 :title ... :mode nil :granularity nil :parent ...) #47)) #27)) #1 #("\n" 0 1 (:parent #27)))) ...) (:parse-tree ... :export-options nil :back-end hugo :translate-alist ... :exported-data #<hash-table eq 0/4001 0x49d869f9> :input-buffer "2023-06-Jun.or..." :input-file "/Users/charlbo..." ...))
  (if (string= type "fuzzy") (progn (condition-case err (org-export-resolve-fuzzy-link el info) (org-link-broken (if (or (plist-get info :with-broken-links) (plist-get (org-export--parse-option-keyword ...) :with-broken-links)) nil (user-error "Unable to resolve link: %S" (nth 1 err)))))) (org-export-resolve-id-link el (org-export--collect-tree-properties ast info)))
  (let* ((raw-link (org-element-property :raw-link el)) (destination (if (string= type "fuzzy") (progn (condition-case err (org-export-resolve-fuzzy-link el info) (org-link-broken (if ... nil ...)))) (org-export-resolve-id-link el (org-export--collect-tree-properties ast info)))) (source-path (org-hugo--heading-get-slug el info :inherit-export-file-name)) (destination-path (org-hugo--heading-get-slug destination info :inherit-export-file-name)) (destination-type (org-element-type destination))) (if (equal source-path destination-path) nil (let ((link-desc (org-element-contents el))) (org-element-put-property el :type "file") (org-element-put-property el :path (cond ((org-element-property :EXPORT_FILE_NAME destination) (concat destination-path org-hugo--preprocessed-buffer-dummy-file-suffix)) ((and (string= type "fuzzy") (not ...)) (concat destination-path org-hugo--preprocessed-buffer-dummy-file-suffix)) ((string= type "custom-id") (concat destination-path org-hugo--preprocessed-buffer-dummy-file-suffix "::" raw-link)) (t (let (...) (concat destination-path org-hugo--preprocessed-buffer-dummy-file-suffix "::#" anchor))))) (if (and (null link-desc) (equal 'headline destination-type)) (progn (let ((heading-title ...)) (org-element-set-contents el heading-title)))))))
  (progn (let* ((raw-link (org-element-property :raw-link el)) (destination (if (string= type "fuzzy") (progn (condition-case err (org-export-resolve-fuzzy-link el info) (org-link-broken ...))) (org-export-resolve-id-link el (org-export--collect-tree-properties ast info)))) (source-path (org-hugo--heading-get-slug el info :inherit-export-file-name)) (destination-path (org-hugo--heading-get-slug destination info :inherit-export-file-name)) (destination-type (org-element-type destination))) (if (equal source-path destination-path) nil (let ((link-desc (org-element-contents el))) (org-element-put-property el :type "file") (org-element-put-property el :path (cond ((org-element-property :EXPORT_FILE_NAME destination) (concat destination-path org-hugo--preprocessed-buffer-dummy-file-suffix)) ((and ... ...) (concat destination-path org-hugo--preprocessed-buffer-dummy-file-suffix)) ((string= type "custom-id") (concat destination-path org-hugo--preprocessed-buffer-dummy-file-suffix "::" raw-link)) (t (let ... ...)))) (if (and (null link-desc) (equal 'headline destination-type)) (progn (let (...) (org-element-set-contents el heading-title))))))))
  (if (member type '("custom-id" "id" "fuzzy")) (progn (let* ((raw-link (org-element-property :raw-link el)) (destination (if (string= type "fuzzy") (progn (condition-case err ... ...)) (org-export-resolve-id-link el (org-export--collect-tree-properties ast info)))) (source-path (org-hugo--heading-get-slug el info :inherit-export-file-name)) (destination-path (org-hugo--heading-get-slug destination info :inherit-export-file-name)) (destination-type (org-element-type destination))) (if (equal source-path destination-path) nil (let ((link-desc (org-element-contents el))) (org-element-put-property el :type "file") (org-element-put-property el :path (cond (... ...) (... ...) (... ...) (t ...))) (if (and (null link-desc) (equal ... destination-type)) (progn (let ... ...))))))))
  (let ((type (org-element-property :type el))) (if (member type '("custom-id" "id" "fuzzy")) (progn (let* ((raw-link (org-element-property :raw-link el)) (destination (if (string= type "fuzzy") (progn ...) (org-export-resolve-id-link el ...))) (source-path (org-hugo--heading-get-slug el info :inherit-export-file-name)) (destination-path (org-hugo--heading-get-slug destination info :inherit-export-file-name)) (destination-type (org-element-type destination))) (if (equal source-path destination-path) nil (let ((link-desc ...)) (org-element-put-property el :type "file") (org-element-put-property el :path (cond ... ... ... ...)) (if (and ... ...) (progn ...))))))))
  (cond ((equal 'link el-type) (let ((type (org-element-property :type el))) (if (member type '("custom-id" "id" "fuzzy")) (progn (let* ((raw-link ...) (destination ...) (source-path ...) (destination-path ...) (destination-type ...)) (if (equal source-path destination-path) nil (let ... ... ... ...))))))) ((equal 'special-block el-type) (if (org-element-contents el) nil (org-element-adopt-elements el ""))))
  (let ((el-type (org-element-type el))) (cond ((equal 'link el-type) (let ((type (org-element-property :type el))) (if (member type '("custom-id" "id" "fuzzy")) (progn (let* (... ... ... ... ...) (if ... nil ...)))))) ((equal 'special-block el-type) (if (org-element-contents el) nil (org-element-adopt-elements el "")))))
  (closure (... ...) (el) (let ... ...) nil)((link (:type "id" :path "4b133a7a-a81c-44d4-9bea-8e1c72ed5847" :format bracket :raw-link "id:4b133a7a-a81c-44d4-9bea-8e1c72ed5847" :application nil :search-option nil :begin 239 :end 309 :contents-begin 282 :contents-end 307 :post-blank 0 :parent (paragraph (:begin 239 :end 310 :contents-begin 239 :contents-end 310 :post-blank 0 :post-affiliated 239 :mode planning :granularity nil :parent (section (:begin 239 :end 311 :contents-begin 239 :contents-end 310 :robust-begin 239 :robust-end 308 :post-blank 1 :post-affiliated 239 :mode section :granularity nil :parent (headline ... #47)) #27)) #1 #("\n" 0 1 (:parent #27)))) #("Life systems 2022 edition" 0 25 (:parent #1))))
  #f(compiled-function (--data) #<bytecode -0x1d67f749fb6659bf>)((link (:type "id" :path "4b133a7a-a81c-44d4-9bea-8e1c72ed5847" :format bracket :raw-link "id:4b133a7a-a81c-44d4-9bea-8e1c72ed5847" :application nil :search-option nil :begin 239 :end 309 :contents-begin 282 :contents-end 307 :post-blank 0 :parent (paragraph (:begin 239 :end 310 :contents-begin 239 :contents-end 310 :post-blank 0 :post-affiliated 239 :mode planning :granularity nil :parent (section (:begin 239 :end 311 :contents-begin 239 :contents-end 310 :robust-begin 239 :robust-end 308 :post-blank 1 :post-affiliated 239 :mode section :granularity nil :parent (headline ... #47)) #27)) #1 #("\n" 0 1 (:parent #27)))) #("Life systems 2022 edition" 0 25 (:parent #1))))
  mapc(#f(compiled-function (--data) #<bytecode -0x1d67f749fb6659bf>) ((link (:type "id" :path "4b133a7a-a81c-44d4-9bea-8e1c72ed5847" :format bracket :raw-link "id:4b133a7a-a81c-44d4-9bea-8e1c72ed5847" :application nil :search-option nil :begin 239 :end 309 :contents-begin 282 :contents-end 307 :post-blank 0 :parent (paragraph (:begin 239 :end 310 :contents-begin 239 :contents-end 310 :post-blank 0 :post-affiliated 239 :mode planning :granularity nil :parent (section (:begin 239 :end 311 :contents-begin 239 :contents-end 310 :robust-begin 239 :robust-end 308 :post-blank 1 :post-affiliated 239 :mode section :granularity nil :parent ...) #29)) . #2)) #("Life systems 2022 edition" 0 25 (:parent #3))) #("\n" 0 1 (:parent (paragraph (:begin 239 :end 310 :contents-begin 239 :contents-end 310 :post-blank 0 :post-affiliated 239 :mode planning :granularity nil :parent (section (:begin 239 :end 311 :contents-begin 239 :contents-end 310 :robust-begin 239 :robust-end 308 :post-blank 1 :post-affiliated 239 :mode section :granularity nil :parent ...) #7)) . #2)))))
  #f(compiled-function (--data) #<bytecode -0x1d67f749fb6659bf>)((paragraph (:begin 239 :end 310 :contents-begin 239 :contents-end 310 :post-blank 0 :post-affiliated 239 :mode planning :granularity nil :parent (section (:begin 239 :end 311 :contents-begin 239 :contents-end 310 :robust-begin 239 :robust-end 308 :post-blank 1 :post-affiliated 239 :mode section :granularity nil :parent (headline (:raw-value "Vitals" :begin 229 :end 311 :pre-blank 1 :contents-begin 239 :contents-end 310 :robust-begin 241 :robust-end 308 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 1 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 229 :title (...) :mode nil :granularity nil :parent (org-data ... ... #45 ... ... ...)) #21)) #1)) (link (:type "id" :path "4b133a7a-a81c-44d4-9bea-8e1c72ed5847" :format bracket :raw-link "id:4b133a7a-a81c-44d4-9bea-8e1c72ed5847" :application nil :search-option nil :begin 239 :end 309 :contents-begin 282 :contents-end 307 :post-blank 0 :parent #1) #("Life systems 2022 edition" 0 25 (:parent #4))) #("\n" 0 1 (:parent #1))))
  mapc(#f(compiled-function (--data) #<bytecode -0x1d67f749fb6659bf>) ((paragraph (:begin 239 :end 310 :contents-begin 239 :contents-end 310 :post-blank 0 :post-affiliated 239 :mode planning :granularity nil :parent (section (:begin 239 :end 311 :contents-begin 239 :contents-end 310 :robust-begin 239 :robust-end 308 :post-blank 1 :post-affiliated 239 :mode section :granularity nil :parent (headline (:raw-value "Vitals" :begin 229 :end 311 :pre-blank 1 :contents-begin 239 :contents-end 310 :robust-begin 241 :robust-end 308 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 1 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 229 :title ... :mode nil :granularity nil :parent ...) #23)) . #2)) (link (:type "id" :path "4b133a7a-a81c-44d4-9bea-8e1c72ed5847" :format bracket :raw-link "id:4b133a7a-a81c-44d4-9bea-8e1c72ed5847" :application nil :search-option nil :begin 239 :end 309 :contents-begin 282 :contents-end 307 :post-blank 0 :parent #3) #("Life systems 2022 edition" 0 25 (:parent #6))) #("\n" 0 1 (:parent #3)))))
  #f(compiled-function (--data) #<bytecode -0x1d67f749fb6659bf>)((section (:begin 239 :end 311 :contents-begin 239 :contents-end 310 :robust-begin 239 :robust-end 308 :post-blank 1 :post-affiliated 239 :mode section :granularity nil :parent (headline (:raw-value "Vitals" :begin 229 :end 311 :pre-blank 1 :contents-begin 239 :contents-end 310 :robust-begin 241 :robust-end 308 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 1 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 229 :title (#("Vitals" 0 6 (:parent #25))) :mode nil :granularity nil :parent (org-data (:begin 1 :contents-begin 1 :contents-end 35337 :end 35338 :robust-begin 3 :robust-end 35335 :post-blank 1 :post-affiliated 1 :path "/Users/charlbotha/OneDrive/notes/pkb4000/journals/..." :mode org-data :CATEGORY "2023-06-Jun" :granularity nil) (section (:begin 1 :end 229 :contents-begin 1 :contents-end 228 :robust-begin 1 :robust-end 226 :post-blank 1 :post-affiliated 1 :mode first-section :granularity nil :parent #71) (keyword ...) (keyword ...) (keyword ...) (keyword ...) (keyword ...) (keyword ...) (keyword ...)) #25 (headline (:raw-value "clock table" :begin 311 :end 507 :pre-blank 1 :contents-begin 326 :contents-end 506 :robust-begin 328 :robust-end 504 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 1 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 311 :title ... :mode nil :granularity nil :parent #71) (section ... ... ...)) (headline (:raw-value "Tasks" :begin 507 :end 12916 :pre-blank 1 :contents-begin 516 :contents-end 12915 :robust-begin 518 :robust-end 12913 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 1 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 507 :title ... :parent #71 :cached t :org-element--cache-sync-key nil :granularity nil) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ... ... ...) (headline ... ... ...) (headline ... ...) (headline ... ...) (headline ... ... ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...)) (headline (:raw-value "2023" :begin 12916 :end 35338 :pre-blank 0 :contents-begin 12923 :contents-end 35337 :robust-begin 12925 :robust-end 35335 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 1 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 12916 :title ... :parent #71 :cached t :org-element--cache-sync-key nil :granularity nil) (headline ... ... ... ...) (headline ... ... ... ... ... ... ...) (headline ... ... ... ... ...) (headline ... ... ... ... ...) (headline ... ...)))) #1)) (paragraph (:begin 239 :end 310 :contents-begin 239 :contents-end 310 :post-blank 0 :post-affiliated 239 :mode planning :granularity nil :parent #1) (link (:type "id" :path "4b133a7a-a81c-44d4-9bea-8e1c72ed5847" :format bracket :raw-link "id:4b133a7a-a81c-44d4-9bea-8e1c72ed5847" :application nil :search-option nil :begin 239 :end 309 :contents-begin 282 :contents-end 307 :post-blank 0 :parent #4) #("Life systems 2022 edition" 0 25 (:parent #7))) #("\n" 0 1 (:parent #4)))))
  mapc(#f(compiled-function (--data) #<bytecode -0x1d67f749fb6659bf>) ((section (:begin 239 :end 311 :contents-begin 239 :contents-end 310 :robust-begin 239 :robust-end 308 :post-blank 1 :post-affiliated 239 :mode section :granularity nil :parent (headline (:raw-value "Vitals" :begin 229 :end 311 :pre-blank 1 :contents-begin 239 :contents-end 310 :robust-begin 241 :robust-end 308 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 1 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 229 :title (#("Vitals" 0 6 ...)) :mode nil :granularity nil :parent (org-data (:begin 1 :contents-begin 1 :contents-end 35337 :end 35338 :robust-begin 3 :robust-end 35335 :post-blank 1 :post-affiliated 1 :path "/Users/charlbotha/OneDrive/notes/pkb4000/journals/..." :mode org-data :CATEGORY "2023-06-Jun" :granularity nil) (section ... ... ... ... ... ... ... ...) #27 (headline ... ...) (headline ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...) (headline ... ... ... ... ... ...))) . #2)) (paragraph (:begin 239 :end 310 :contents-begin 239 :contents-end 310 :post-blank 0 :post-affiliated 239 :mode planning :granularity nil :parent #3) (link (:type "id" :path "4b133a7a-a81c-44d4-9bea-8e1c72ed5847" :format bracket :raw-link "id:4b133a7a-a81c-44d4-9bea-8e1c72ed5847" :application nil :search-option nil :begin 239 :end 309 :contents-begin 282 :contents-end 307 :post-blank 0 :parent #6) #("Life systems 2022 edition" 0 25 (:parent #9))) #("\n" 0 1 (:parent #6))))))
  #f(compiled-function (--data) #<bytecode -0x1d67f749fb6659bf>)((headline ... ...))
  mapc(#f(compiled-function (--data) #<bytecode -0x1d67f749fb6659bf>) (... ... ... ... ...))
  #f(compiled-function (--data) #<bytecode -0x1d67f749fb6659bf>)((org-data ... ... ... ... ... ...))
  org-element-map((org-data ... ... ... ... ... ...) (link special-block) (closure ... ... ... nil))
  (let* ((ast (org-element-parse-buffer)) (org-use-property-inheritance (org-hugo--selective-property-inheritance)) (info (org-combine-plists (list :parse-tree ast) (org-export--get-export-attributes 'hugo) (org-export--get-buffer-attributes) (org-export-get-environment 'hugo)))) (org-element-map ast '(link special-block) #'(lambda (el) (let ((el-type (org-element-type el))) (cond ((equal ... el-type) (let ... ...)) ((equal ... el-type) (if ... nil ...)))) nil)) (if (version< "25.99" emacs-version) (progn (kill-matching-buffers (regexp-quote pre-processed-buffer-prefix) :internal-too :no-ask))) (let ((local-variables (buffer-local-variables)) (bound-variables (org-export--list-bound-variables)) (buffer (generate-new-buffer (concat pre-processed-buffer-prefix (buffer-name) " *")))) (save-current-buffer (set-buffer buffer) (let (vars) (org-hugo--org-mode-light) (let ((tail local-variables)) (while tail (let (...) (if ... ...) (setq tail ...))) vars) (insert (org-element-interpret-data ast)) (set-buffer-modified-p nil))) buffer))
  (let ((pre-processed-buffer-prefix "*Ox-hugo Pre-processed ")) (let* ((ast (org-element-parse-buffer)) (org-use-property-inheritance (org-hugo--selective-property-inheritance)) (info (org-combine-plists (list :parse-tree ast) (org-export--get-export-attributes 'hugo) (org-export--get-buffer-attributes) (org-export-get-environment 'hugo)))) (org-element-map ast '(link special-block) #'(lambda (el) (let ((el-type ...)) (cond (... ...) (... ...))) nil)) (if (version< "25.99" emacs-version) (progn (kill-matching-buffers (regexp-quote pre-processed-buffer-prefix) :internal-too :no-ask))) (let ((local-variables (buffer-local-variables)) (bound-variables (org-export--list-bound-variables)) (buffer (generate-new-buffer (concat pre-processed-buffer-prefix (buffer-name) " *")))) (save-current-buffer (set-buffer buffer) (let (vars) (org-hugo--org-mode-light) (let ((tail local-variables)) (while tail (let ... ... ...)) vars) (insert (org-element-interpret-data ast)) (set-buffer-modified-p nil))) buffer)))
  org-hugo--get-pre-processed-buffer()
  (or org-hugo--preprocessed-buffer (org-hugo--get-pre-processed-buffer))
  (let ((pre-proc-buf (or org-hugo--preprocessed-buffer (org-hugo--get-pre-processed-buffer)))) (if org-hugo--preprocessed-buffer nil (setq org-hugo--preprocessed-buffer pre-proc-buf) (add-to-list 'org-hugo--opened-buffers pre-proc-buf)) pre-proc-buf)
  (if org-hugo--preprocess-buffer (let ((pre-proc-buf (or org-hugo--preprocessed-buffer (org-hugo--get-pre-processed-buffer)))) (if org-hugo--preprocessed-buffer nil (setq org-hugo--preprocessed-buffer pre-proc-buf) (add-to-list 'org-hugo--opened-buffers pre-proc-buf)) pre-proc-buf) (current-buffer))
  (let ((buffer (if org-hugo--preprocess-buffer (let ((pre-proc-buf (or org-hugo--preprocessed-buffer ...))) (if org-hugo--preprocessed-buffer nil (setq org-hugo--preprocessed-buffer pre-proc-buf) (add-to-list 'org-hugo--opened-buffers pre-proc-buf)) pre-proc-buf) (current-buffer)))) (save-current-buffer (set-buffer buffer) (goto-char (org-find-olp current-outline-path :this-buffer)) (setq ret (org-hugo-export-to-md async :subtreep visible-only))))
  (cond (is-commented (if (string= title commented-heading) (message "[ox-hugo] `%s' was not exported as it is commented..." title) (message "[ox-hugo] `%s' was not exported as one of its pare..." title commented-heading))) (is-excluded (message "[ox-hugo] `%s' was not exported as it is tagged wi..." title matched-exclude-tag)) (t (if all-subtrees (progn (setq org-hugo--subtree-count (1+ org-hugo--subtree-count)) (message "[ox-hugo] %d/ Exporting `%s' .." org-hugo--subtree-count title)) (message "[ox-hugo] Exporting `%s' .." title)) (if (or (or (org-entry-get nil "EXPORT_HUGO_MENU" :inherit) (save-excursion (goto-char (point-min)) (let (...) (re-search-forward "^#\\+hugo_menu:.*:menu" nil :noerror)))) (or (let ((page-or-taxonomy-weight ...)) (and (stringp page-or-taxonomy-weight) (string-match-p "auto" page-or-taxonomy-weight))) (save-excursion (goto-char (point-min)) (let (...) (re-search-forward "^#\\+hugo_weight:.*auto" nil :noerror))))) (progn (setq org-hugo--subtree-coord (org-hugo--get-post-subtree-coordinates subtree)))) (let ((buffer (if org-hugo--preprocess-buffer (let (...) (if org-hugo--preprocessed-buffer nil ... ...) pre-proc-buf) (current-buffer)))) (save-current-buffer (set-buffer buffer) (goto-char (org-find-olp current-outline-path :this-buffer)) (setq ret (org-hugo-export-to-md async :subtreep visible-only))))))
  (let ((title (org-element-property :title subtree)) (current-outline-path (cl-delete-if #'(lambda (el) (string= el "")) (org-get-outline-path :with-self))) (org-hugo--disable-after-all-exports-hook all-subtrees)) (cond (is-commented (if (string= title commented-heading) (message "[ox-hugo] `%s' was not exported as it is commented..." title) (message "[ox-hugo] `%s' was not exported as one of its pare..." title commented-heading))) (is-excluded (message "[ox-hugo] `%s' was not exported as it is tagged wi..." title matched-exclude-tag)) (t (if all-subtrees (progn (setq org-hugo--subtree-count (1+ org-hugo--subtree-count)) (message "[ox-hugo] %d/ Exporting `%s' .." org-hugo--subtree-count title)) (message "[ox-hugo] Exporting `%s' .." title)) (if (or (or (org-entry-get nil "EXPORT_HUGO_MENU" :inherit) (save-excursion (goto-char ...) (let ... ...))) (or (let (...) (and ... ...)) (save-excursion (goto-char ...) (let ... ...)))) (progn (setq org-hugo--subtree-coord (org-hugo--get-post-subtree-coordinates subtree)))) (let ((buffer (if org-hugo--preprocess-buffer (let ... ... pre-proc-buf) (current-buffer)))) (save-current-buffer (set-buffer buffer) (goto-char (org-find-olp current-outline-path :this-buffer)) (setq ret (org-hugo-export-to-md async :subtreep visible-only)))))))
  (let* ((info (org-combine-plists (org-export--get-export-attributes 'hugo subtree visible-only) (org-export--get-buffer-attributes) (org-export-get-environment 'hugo subtree))) (exclude-tags (plist-get info :exclude-tags)) (is-commented (cdr (org-hugo--get-elem-with-prop :commentedp))) (commented-heading (if is-commented (progn (org-element-property :title (car (org-hugo--get-elem-with-prop :commentedp)))))) is-excluded matched-exclude-tag ret) (let ((all-tags (let ((org-use-tag-inheritance t)) (org-hugo--get-tags)))) (if all-tags (progn (let ((tail exclude-tags)) (while tail (let (...) (if ... ...) (setq tail ...))))))) (let ((title (org-element-property :title subtree)) (current-outline-path (cl-delete-if #'(lambda (el) (string= el "")) (org-get-outline-path :with-self))) (org-hugo--disable-after-all-exports-hook all-subtrees)) (cond (is-commented (if (string= title commented-heading) (message "[ox-hugo] `%s' was not exported as it is commented..." title) (message "[ox-hugo] `%s' was not exported as one of its pare..." title commented-heading))) (is-excluded (message "[ox-hugo] `%s' was not exported as it is tagged wi..." title matched-exclude-tag)) (t (if all-subtrees (progn (setq org-hugo--subtree-count (1+ org-hugo--subtree-count)) (message "[ox-hugo] %d/ Exporting `%s' .." org-hugo--subtree-count title)) (message "[ox-hugo] Exporting `%s' .." title)) (if (or (or (org-entry-get nil "EXPORT_HUGO_MENU" :inherit) (save-excursion ... ...)) (or (let ... ...) (save-excursion ... ...))) (progn (setq org-hugo--subtree-coord (org-hugo--get-post-subtree-coordinates subtree)))) (let ((buffer (if org-hugo--preprocess-buffer ... ...))) (save-current-buffer (set-buffer buffer) (goto-char (org-find-olp current-outline-path :this-buffer)) (setq ret (org-hugo-export-to-md async :subtreep visible-only))))))) ret)
  (if subtree (let* ((info (org-combine-plists (org-export--get-export-attributes 'hugo subtree visible-only) (org-export--get-buffer-attributes) (org-export-get-environment 'hugo subtree))) (exclude-tags (plist-get info :exclude-tags)) (is-commented (cdr (org-hugo--get-elem-with-prop :commentedp))) (commented-heading (if is-commented (progn (org-element-property :title (car ...))))) is-excluded matched-exclude-tag ret) (let ((all-tags (let ((org-use-tag-inheritance t)) (org-hugo--get-tags)))) (if all-tags (progn (let ((tail exclude-tags)) (while tail (let ... ... ...)))))) (let ((title (org-element-property :title subtree)) (current-outline-path (cl-delete-if #'(lambda ... ...) (org-get-outline-path :with-self))) (org-hugo--disable-after-all-exports-hook all-subtrees)) (cond (is-commented (if (string= title commented-heading) (message "[ox-hugo] `%s' was not exported as it is commented..." title) (message "[ox-hugo] `%s' was not exported as one of its pare..." title commented-heading))) (is-excluded (message "[ox-hugo] `%s' was not exported as it is tagged wi..." title matched-exclude-tag)) (t (if all-subtrees (progn (setq org-hugo--subtree-count ...) (message "[ox-hugo] %d/ Exporting `%s' .." org-hugo--subtree-count title)) (message "[ox-hugo] Exporting `%s' .." title)) (if (or (or ... ...) (or ... ...)) (progn (setq org-hugo--subtree-coord ...))) (let ((buffer ...)) (save-current-buffer (set-buffer buffer) (goto-char ...) (setq ret ...)))))) ret) (let ((valid-subtree-found (org-hugo--buffer-has-valid-post-subtree-p))) (if valid-subtree-found (progn (message "Point is not in a valid Hugo post subtree; move to..."))) valid-subtree-found))
  (let ((subtree (org-hugo--get-valid-subtree))) (if subtree (let* ((info (org-combine-plists (org-export--get-export-attributes 'hugo subtree visible-only) (org-export--get-buffer-attributes) (org-export-get-environment 'hugo subtree))) (exclude-tags (plist-get info :exclude-tags)) (is-commented (cdr (org-hugo--get-elem-with-prop :commentedp))) (commented-heading (if is-commented (progn (org-element-property :title ...)))) is-excluded matched-exclude-tag ret) (let ((all-tags (let (...) (org-hugo--get-tags)))) (if all-tags (progn (let (...) (while tail ...))))) (let ((title (org-element-property :title subtree)) (current-outline-path (cl-delete-if #'... (org-get-outline-path :with-self))) (org-hugo--disable-after-all-exports-hook all-subtrees)) (cond (is-commented (if (string= title commented-heading) (message "[ox-hugo] `%s' was not exported as it is commented..." title) (message "[ox-hugo] `%s' was not exported as one of its pare..." title commented-heading))) (is-excluded (message "[ox-hugo] `%s' was not exported as it is tagged wi..." title matched-exclude-tag)) (t (if all-subtrees (progn ... ...) (message "[ox-hugo] Exporting `%s' .." title)) (if (or ... ...) (progn ...)) (let (...) (save-current-buffer ... ... ...))))) ret) (let ((valid-subtree-found (org-hugo--buffer-has-valid-post-subtree-p))) (if valid-subtree-found (progn (message "Point is not in a valid Hugo post subtree; move to..."))) valid-subtree-found)))
  org-hugo--export-subtree-to-md(nil nil)
  (setq ret (org-hugo--export-subtree-to-md async visible-only))
  (cond ((and buf-has-subtree all-subtrees) (let ((start-time (current-time))) (let ((tail org-hugo--all-subtrees-export--functions-to-silence)) (while tail (let ((fn ...)) (advice-add fn :around #'org-hugo--advice-silence-messages) (setq tail (cdr tail))))) (setq ret (org-map-entries #'(lambda nil (org-hugo--export-subtree-to-md async visible-only :all-subtrees)) "EXPORT_FILE_NAME<>\"\"")) (let* ((elapsed-time (float-time (time-since start-time))) (avg-time (/ elapsed-time org-hugo--subtree-count))) (message "[ox-hugo] Exported %d subtree%s from %s in %0.3fs ..." org-hugo--subtree-count (if (= 1 org-hugo--subtree-count) "" "s") f-or-b-name elapsed-time avg-time)) (org-hugo--after-all-exports-function))) ((and buf-has-subtree (not all-subtrees)) (setq ret (org-hugo--export-subtree-to-md async visible-only))) (t (setq ret (org-hugo--export-file-to-md f-or-b-name async visible-only noerror))))
  (save-restriction (widen) (cond ((and buf-has-subtree all-subtrees) (let ((start-time (current-time))) (let ((tail org-hugo--all-subtrees-export--functions-to-silence)) (while tail (let (...) (advice-add fn :around ...) (setq tail ...)))) (setq ret (org-map-entries #'(lambda nil ...) "EXPORT_FILE_NAME<>\"\"")) (let* ((elapsed-time (float-time ...)) (avg-time (/ elapsed-time org-hugo--subtree-count))) (message "[ox-hugo] Exported %d subtree%s from %s in %0.3fs ..." org-hugo--subtree-count (if (= 1 org-hugo--subtree-count) "" "s") f-or-b-name elapsed-time avg-time)) (org-hugo--after-all-exports-function))) ((and buf-has-subtree (not all-subtrees)) (setq ret (org-hugo--export-subtree-to-md async visible-only))) (t (setq ret (org-hugo--export-file-to-md f-or-b-name async visible-only noerror)))))
  (save-excursion (save-restriction (widen) (cond ((and buf-has-subtree all-subtrees) (let ((start-time (current-time))) (let ((tail org-hugo--all-subtrees-export--functions-to-silence)) (while tail (let ... ... ...))) (setq ret (org-map-entries #'... "EXPORT_FILE_NAME<>\"\"")) (let* ((elapsed-time ...) (avg-time ...)) (message "[ox-hugo] Exported %d subtree%s from %s in %0.3fs ..." org-hugo--subtree-count (if ... "" "s") f-or-b-name elapsed-time avg-time)) (org-hugo--after-all-exports-function))) ((and buf-has-subtree (not all-subtrees)) (setq ret (org-hugo--export-subtree-to-md async visible-only))) (t (setq ret (org-hugo--export-file-to-md f-or-b-name async visible-only noerror))))))
  (progn (save-excursion (save-restriction (widen) (cond ((and buf-has-subtree all-subtrees) (let ((start-time ...)) (let (...) (while tail ...)) (setq ret (org-map-entries ... "EXPORT_FILE_NAME<>\"\"")) (let* (... ...) (message "[ox-hugo] Exported %d subtree%s from %s in %0.3fs ..." org-hugo--subtree-count ... f-or-b-name elapsed-time avg-time)) (org-hugo--after-all-exports-function))) ((and buf-has-subtree (not all-subtrees)) (setq ret (org-hugo--export-subtree-to-md async visible-only))) (t (setq ret (org-hugo--export-file-to-md f-or-b-name async visible-only noerror)))))))
  (unwind-protect (progn (save-excursion (save-restriction (widen) (cond ((and buf-has-subtree all-subtrees) (let (...) (let ... ...) (setq ret ...) (let* ... ...) (org-hugo--after-all-exports-function))) ((and buf-has-subtree (not all-subtrees)) (setq ret (org-hugo--export-subtree-to-md async visible-only))) (t (setq ret (org-hugo--export-file-to-md f-or-b-name async visible-only noerror))))))) (set-window-configuration wconfig))
  (let ((wconfig (current-window-configuration))) (unwind-protect (progn (save-excursion (save-restriction (widen) (cond ((and buf-has-subtree all-subtrees) (let ... ... ... ... ...)) ((and buf-has-subtree ...) (setq ret ...)) (t (setq ret ...)))))) (set-window-configuration wconfig)))
  (let ((f-or-b-name (if (buffer-file-name) (file-name-nondirectory (buffer-file-name)) (buffer-name))) (buf-has-subtree (org-hugo--buffer-has-valid-post-subtree-p)) ret) (setq org-id-locations nil) (org-hugo--cleanup) (let ((wconfig (current-window-configuration))) (unwind-protect (progn (save-excursion (save-restriction (widen) (cond (... ...) (... ...) (t ...))))) (set-window-configuration wconfig))) ret)
  org-hugo-export-wim-to-md(nil nil nil)
  (lambda (a _s v _b) (org-hugo-export-wim-to-md nil a v))(nil nil nil nil)
  funcall((lambda (a _s v _b) (org-hugo-export-wim-to-md nil a v)) nil nil nil nil)
  (save-excursion (if arg (progn (if (eq (marker-buffer org-export-dispatch-last-position) (org-base-buffer (current-buffer))) (goto-char org-export-dispatch-last-position) (move-marker org-export-dispatch-last-position nil)))) (funcall action (and (memq 'async optns) t) (and (memq 'subtree optns) t) (and (memq 'visible optns) t) (and (memq 'body optns) t)))
  (cond ((eql action 'template) (org-export-insert-default-template nil optns)) ((eql action 'stack) (org-export-stack)) ((eql action 'publish-current-file) (org-publish-current-file (memq 'force optns) (memq 'async optns))) ((eql action 'publish-current-project) (org-publish-current-project (memq 'force optns) (memq 'async optns))) ((eql action 'publish-choose-project) (org-publish (assoc (completing-read "Publish project: " org-publish-project-alist nil t) org-publish-project-alist) (memq 'force optns) (memq 'async optns))) ((eql action 'publish-all) (org-publish-all (memq 'force optns) (memq 'async optns))) (t (save-excursion (if arg (progn (if (eq (marker-buffer org-export-dispatch-last-position) (org-base-buffer ...)) (goto-char org-export-dispatch-last-position) (move-marker org-export-dispatch-last-position nil)))) (funcall action (and (memq 'async optns) t) (and (memq 'subtree optns) t) (and (memq 'visible optns) t) (and (memq 'body optns) t)))))
  (let* ((input (cond ((equal arg '(16)) '(stack)) ((and arg org-export-dispatch-last-action)) (t (let ((wconfig ...)) (unwind-protect (progn ...) (set-window-configuration wconfig)))))) (action (car input)) (optns (cdr input))) (if (memq 'subtree optns) nil (move-marker org-export-dispatch-last-position nil)) (cond ((eql action 'template) (org-export-insert-default-template nil optns)) ((eql action 'stack) (org-export-stack)) ((eql action 'publish-current-file) (org-publish-current-file (memq 'force optns) (memq 'async optns))) ((eql action 'publish-current-project) (org-publish-current-project (memq 'force optns) (memq 'async optns))) ((eql action 'publish-choose-project) (org-publish (assoc (completing-read "Publish project: " org-publish-project-alist nil t) org-publish-project-alist) (memq 'force optns) (memq 'async optns))) ((eql action 'publish-all) (org-publish-all (memq 'force optns) (memq 'async optns))) (t (save-excursion (if arg (progn (if (eq ... ...) (goto-char org-export-dispatch-last-position) (move-marker org-export-dispatch-last-position nil)))) (funcall action (and (memq 'async optns) t) (and (memq 'subtree optns) t) (and (memq 'visible optns) t) (and (memq 'body optns) t))))))
  org-export-dispatch(nil)
  funcall-interactively(org-export-dispatch nil)
  command-execute(org-export-dispatch)
kaushalmodi commented 1 year ago

Yes, this looks like my oversight.

Your suggestion makes sense. Can you please create a PR?

Thanks!

cpbotha commented 11 months ago

Thanks @kaushalmodi -- it took a while, but PR #724 has been created.