2025-06-22-09-58

27 阅读1分钟

cache URL 文本。

#+name: cache-url
#+begin_src emacs-lisp
(lambda (id url title text)
  (let* ((location (org-id-find id t)))
    (cond
     (location
      (org-with-point-at location
        (funcall log "cache to %s" id)
        (goto-char
         (org-element-end
          (org-element-at-point)))
        (unless (bolp) (insert "\n"))
        (insert text)
        (unless (bolp) (insert "\n"))
        (save-buffer)))
     (t
      (with-current-buffer
          (find-file-noselect
           org-id-remap-cache-file)
        (funcall log "cache to %s"
                 org-id-remap-cache-file)
        (org-with-wide-buffer
         (goto-char (point-min))
         (save-excursion
           (insert "* " title "\n")
           (insert text)
           (unless (bolp) (insert "\n")))
         (org-entry-put nil "ID" id)
         (org-entry-put nil "URL" url))
        (save-buffer))))))
#+end_src