changelog shortlog graph tags branches changeset file revisions annotate raw help

Mercurial > core / emacs/lib/publish.el

revision 613: 9ffe93dbe9b9
parent 611: 57813b8ee029
child 614: f03dbf6338ed
     1.1--- a/emacs/lib/publish.el	Mon Aug 19 20:00:04 2024 -0400
     1.2+++ b/emacs/lib/publish.el	Mon Aug 19 20:24:03 2024 -0400
     1.3@@ -15,7 +15,7 @@
     1.4 (defvar vc-url "https://vc.compiler.company")
     1.5 (defvar packy-url "https://packy.compiler.company")
     1.6 (defvar html-nav (format "<div class=\"nav\" id=\"nav\"><h2 id=\"index\">*</h2><div id=\"text-index\"> (<a href = \"%s\">~</a><br> (<a href = \"%s/blog\">blog</a> <a href = \"%s/docs\">docs</a> <a href = \"%s/plan\">plan</a> <a href = \"%s/notes\">notes</a>)<br> (<a href = \"%s\">vc</a> <a href = \"%s\">packy</a>))</div></div>"
     1.7-                       url url url url url vc-url packy-url))
     1.8+                         url url url url url vc-url packy-url))
     1.9 
    1.10 (defvar html-foot "<footer><p>updated %C</p></footer>")
    1.11 
    1.12@@ -108,82 +108,82 @@
    1.13          :html-preamble ,html-nav
    1.14          :html-postamble ,html-foot)))
    1.15 
    1.16-  (defun org-export-get-reference-title (datum info)
    1.17-    "Like `org-export-get-reference', except uses heading titles instead of random numbers."
    1.18-    (let ((cache (plist-get info :internal-references)))
    1.19-      (or (car (rassq datum cache))
    1.20-          (let* ((crossrefs (plist-get info :crossrefs))
    1.21-                 (cells (org-export-search-cells datum))
    1.22-                 ;; Preserve any pre-existing association between
    1.23-                 ;; a search cell and a reference, i.e., when some
    1.24-                 ;; previously published document referenced a location
    1.25-                 ;; within current file (see
    1.26-                 ;; `org-publish-resolve-external-link').
    1.27-                 ;;
    1.28-                 ;; However, there is no guarantee that search cells are
    1.29-                 ;; unique, e.g., there might be duplicate custom ID or
    1.30-                 ;; two headings with the same title in the file.
    1.31-                 ;;
    1.32-                 ;; As a consequence, before re-using any reference to
    1.33-                 ;; an element or object, we check that it doesn't refer
    1.34-                 ;; to a previous element or object.
    1.35-                 (new (or (cl-some
    1.36-                           (lambda (cell)
    1.37-                             (let ((stored (cdr (assoc cell crossrefs))))
    1.38-                               (when stored
    1.39-                                 (let ((old (org-export-format-reference stored)))
    1.40-                                   (and (not (assoc old cache)) stored)))))
    1.41-                           cells)
    1.42-                          (when (org-element-property :raw-value datum)
    1.43-                            ;; Heading with a title
    1.44-                            (org-export-new-title-reference datum cache))
    1.45-                          ;; NOTE: This probably breaks some Org Export
    1.46-                          ;; feature, but if it does what I need, fine.
    1.47-                          (org-export-format-reference
    1.48-                           (org-export-new-reference cache))))
    1.49-                 (reference-string new))
    1.50-            ;; Cache contains both data already associated to
    1.51-            ;; a reference and in-use internal references, so as to make
    1.52-            ;; unique references.
    1.53-            (dolist (cell cells) (push (cons cell new) cache))
    1.54-            ;; Retain a direct association between reference string and
    1.55-            ;; DATUM since (1) not every object or element can be given
    1.56-            ;; a search cell (2) it permits quick lookup.
    1.57-            (push (cons reference-string datum) cache)
    1.58-            (plist-put info :internal-references cache)
    1.59-            reference-string))))
    1.60+;; (defun org-export-get-reference-title (datum info)
    1.61+;;   "Like `org-export-get-reference', except uses heading titles instead of random numbers."
    1.62+;;   (let ((cache (plist-get info :internal-references)))
    1.63+;;     (or (car (rassq datum cache))
    1.64+;;         (let* ((crossrefs (plist-get info :crossrefs))
    1.65+;;                (cells (org-export-search-cells datum))
    1.66+;;                ;; Preserve any pre-existing association between
    1.67+;;                ;; a search cell and a reference, i.e., when some
    1.68+;;                ;; previously published document referenced a location
    1.69+;;                ;; within current file (see
    1.70+;;                ;; `org-publish-resolve-external-link').
    1.71+;;                ;;
    1.72+;;                ;; However, there is no guarantee that search cells are
    1.73+;;                ;; unique, e.g., there might be duplicate custom ID or
    1.74+;;                ;; two headings with the same title in the file.
    1.75+;;                ;;
    1.76+;;                ;; As a consequence, before re-using any reference to
    1.77+;;                ;; an element or object, we check that it doesn't refer
    1.78+;;                ;; to a previous element or object.
    1.79+;;                (new (or (cl-some
    1.80+;;                          (lambda (cell)
    1.81+;;                            (let ((stored (cdr (assoc cell crossrefs))))
    1.82+;;                              (when stored
    1.83+;;                                (let ((old (org-export-format-reference stored)))
    1.84+;;                                  (and (not (assoc old cache)) stored)))))
    1.85+;;                          cells)
    1.86+;;                         (when (org-element-property :raw-value datum)
    1.87+;;                           ;; Heading with a title
    1.88+;;                           (org-export-new-title-reference datum cache))
    1.89+;;                         ;; NOTE: This probably breaks some Org Export
    1.90+;;                         ;; feature, but if it does what I need, fine.
    1.91+;;                         (org-export-format-reference
    1.92+;;                          (org-export-new-reference cache))))
    1.93+;;                (reference-string new))
    1.94+;;           ;; Cache contains both data already associated to
    1.95+;;           ;; a reference and in-use internal references, so as to make
    1.96+;;           ;; unique references.
    1.97+;;           (dolist (cell cells) (push (cons cell new) cache))
    1.98+;;           ;; Retain a direct association between reference string and
    1.99+;;           ;; DATUM since (1) not every object or element can be given
   1.100+;;           ;; a search cell (2) it permits quick lookup.
   1.101+;;           (push (cons reference-string datum) cache)
   1.102+;;           (plist-put info :internal-references cache)
   1.103+;;           reference-string))))
   1.104 
   1.105-  (defun org-export-new-title-reference (datum cache)
   1.106-    "Return new reference for DATUM that is unique in CACHE."
   1.107-    (cl-macrolet ((inc-suffixf (place)
   1.108-                               `(progn
   1.109-                                  (string-match (rx bos
   1.110-                                                    (minimal-match (group (1+ anything)))
   1.111-                                                    (optional "--" (group (1+ digit)))
   1.112-                                                    eos)
   1.113-                                                ,place)
   1.114-                                  ;; HACK: `s1' instead of a gensym.
   1.115-                                  (-let* (((s1 suffix) (list (match-string 1 ,place)
   1.116-                                                             (match-string 2 ,place)))
   1.117-                                          (suffix (if suffix
   1.118-                                                      (string-to-number suffix)
   1.119-                                                    0)))
   1.120-                                    (setf ,place (format "%s--%s" s1 (cl-incf suffix)))))))
   1.121-      (let* ((title (org-element-property :raw-value datum))
   1.122-             (ref (url-hexify-string (substring-no-properties title)))
   1.123-             (parent (org-element-property :parent datum)))
   1.124-        (while (--any (equal ref (car it))
   1.125-                      cache)
   1.126-          ;; Title not unique: make it so.
   1.127-          (if parent
   1.128-              ;; Append ancestor title.
   1.129-              (setf title (concat (org-element-property :raw-value parent)
   1.130-                                  "--" title)
   1.131-                    ref (url-hexify-string (substring-no-properties title))
   1.132-                    parent (org-element-property :parent parent))
   1.133-            ;; No more ancestors: add and increment a number.
   1.134-            (inc-suffixf ref)))
   1.135-        ref)))
   1.136+;; (defun org-export-new-title-reference (datum cache)
   1.137+;;   "Return new reference for DATUM that is unique in CACHE."
   1.138+;;   (cl-macrolet ((inc-suffixf (place)
   1.139+;;                              `(progn
   1.140+;;                                 (string-match (rx bos
   1.141+;;                                                   (minimal-match (group (1+ anything)))
   1.142+;;                                                   (optional "--" (group (1+ digit)))
   1.143+;;                                                   eos)
   1.144+;;                                               ,place)
   1.145+;;                                 ;; HACK: `s1' instead of a gensym.
   1.146+;;                                 (-let* (((s1 suffix) (list (match-string 1 ,place)
   1.147+;;                                                            (match-string 2 ,place)))
   1.148+;;                                         (suffix (if suffix
   1.149+;;                                                     (string-to-number suffix)
   1.150+;;                                                   0)))
   1.151+;;                                   (setf ,place (format "%s--%s" s1 (cl-incf suffix)))))))
   1.152+;;     (let* ((title (org-element-property :raw-value datum))
   1.153+;;            (ref (url-hexify-string (substring-no-properties title)))
   1.154+;;            (parent (org-element-property :parent datum)))
   1.155+;;       (while (--any (equal ref (car it))
   1.156+;;                     cache)
   1.157+;;         ;; Title not unique: make it so.
   1.158+;;         (if parent
   1.159+;;             ;; Append ancestor title.
   1.160+;;             (setf title (concat (org-element-property :raw-value parent)
   1.161+;;                                 "--" title)
   1.162+;;                   ref (url-hexify-string (substring-no-properties title))
   1.163+;;                   parent (org-element-property :parent parent))
   1.164+;;           ;; No more ancestors: add and increment a number.
   1.165+;;           (inc-suffixf ref)))
   1.166+;;       ref)))
   1.167 
   1.168 ;; (advice-add #'org-export-get-reference :override #'org-export-get-reference-title)
   1.169