Update to Org 9.6-49-g47d129

This commit is contained in:
Kyle Meyer 2022-12-17 17:18:40 -05:00
parent 4a8ff671b0
commit 3e02029642
8 changed files with 173 additions and 144 deletions

View file

@ -20021,11 +20021,16 @@ changes.
| =nofnadjust= | Do not renumber and sort automatically. | | =nofnadjust= | Do not renumber and sort automatically. |
#+vindex: org-hide-block-startup #+vindex: org-hide-block-startup
To hide blocks on startup, use these keywords. The #+vindex: org-hide-drawer-startup
corresponding variable is ~org-hide-block-startup~. To hide blocks or drawers on startup, use these keywords. The
corresponding variables are ~org-hide-block-startup~ and
~org-hide-drawer-startup~.
| =hideblocks= | Hide all begin/end blocks on startup. |
| =nohideblocks= | Do not hide blocks on startup. |
| =hidedrawers= | Hide all begin/end blocks on startup. |
| =nohidedrawers= | Do not hide blocks on startup. |
| =hideblocks= | Hide all begin/end blocks on startup. |
| =nohideblocks= | Do not hide blocks on startup. |
#+vindex: org-pretty-entities #+vindex: org-pretty-entities
The display of entities as UTF-8 characters is governed by the The display of entities as UTF-8 characters is governed by the

View file

@ -241,11 +241,11 @@ This function is called by `org-babel-execute-src-block'."
(defun org-babel-R-assign-elisp (name value colnames-p rownames-p) (defun org-babel-R-assign-elisp (name value colnames-p rownames-p)
"Construct R code assigning the elisp VALUE to a variable named NAME." "Construct R code assigning the elisp VALUE to a variable named NAME."
(if (listp value) (if (listp value)
(let* ((lengths (mapcar 'length (cl-remove-if-not 'sequencep value))) (let* ((lengths (mapcar 'length (cl-remove-if-not 'listp value)))
(max (if lengths (apply 'max lengths) 0)) (max (if lengths (apply 'max lengths) 0))
(min (if lengths (apply 'min lengths) 0))) (min (if lengths (apply 'min lengths) 0)))
;; Ensure VALUE has an orgtbl structure (depth of at least 2). ;; Ensure VALUE has an orgtbl structure (depth of at least 2).
(unless (listp (car value)) (setq value (list value))) (unless (listp (car value)) (setq value (mapcar 'list value)))
(let ((file (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field))) (let ((file (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field)))
(header (if (or (eq (nth 1 value) 'hline) colnames-p) (header (if (or (eq (nth 1 value) 'hline) colnames-p)
"TRUE" "FALSE")) "TRUE" "FALSE"))

View file

@ -91,7 +91,7 @@ end")
(list (list
"set (0, \"defaultfigurevisible\", \"off\");" "set (0, \"defaultfigurevisible\", \"off\");"
full-body full-body
(format "print -dpng %s" gfx-file)) (format "print -dpng %S\nans=%S" gfx-file gfx-file))
"\n") "\n")
full-body) full-body)
result-type matlabp))) result-type matlabp)))

View file

@ -5295,6 +5295,7 @@ indentation removed from its contents."
;; `org-element--cache-diagnostics-ring-size', `org-element--cache-map-statistics', ;; `org-element--cache-diagnostics-ring-size', `org-element--cache-map-statistics',
;; `org-element--cache-map-statistics-threshold'. ;; `org-element--cache-map-statistics-threshold'.
;;;###autoload
(defvar org-element-use-cache t (defvar org-element-use-cache t
"Non-nil when Org parser should cache its results.") "Non-nil when Org parser should cache its results.")

View file

@ -222,8 +222,11 @@ function will be called with a single argument - collection."
(defconst org-persist-index-file "index" (defconst org-persist-index-file "index"
"File name used to store the data index.") "File name used to store the data index.")
(defvar org-persist-disable-when-emacs-Q t (defvar org-persist--disable-when-emacs-Q t
"Disable persistence when Emacs is called with -Q command line arg.") "Disable persistence when Emacs is called with -Q command line arg.
When non-nil, this sets `org-persist-directory' to temporary directory.
This variable must be set before loading org-persist library.")
(defvar org-persist-before-write-hook nil (defvar org-persist-before-write-hook nil
"Abnormal hook ran before saving data. "Abnormal hook ran before saving data.
@ -662,12 +665,13 @@ COLLECTION is the plist holding data collection."
(file-copy (org-file-name-concat (file-copy (org-file-name-concat
org-persist-directory org-persist-directory
(format "%s-%s.%s" persist-file (md5 path) ext)))) (format "%s-%s.%s" persist-file (md5 path) ext))))
(unless (file-exists-p (file-name-directory file-copy)) (unless (file-exists-p file-copy)
(make-directory (file-name-directory file-copy) t)) (unless (file-exists-p (file-name-directory file-copy))
(if (org--should-fetch-remote-resource-p path) (make-directory (file-name-directory file-copy) t))
(url-copy-file path file-copy 'overwrite) (if (org--should-fetch-remote-resource-p path)
(error "The remote resource %S is considered unsafe, and will not be downloaded." (url-copy-file path file-copy 'overwrite)
path)) (error "The remote resource %S is considered unsafe, and will not be downloaded."
path)))
(format "%s-%s.%s" persist-file (md5 path) ext))))) (format "%s-%s.%s" persist-file (md5 path) ext)))))
(defun org-persist-write:index (container _) (defun org-persist-write:index (container _)
@ -771,43 +775,39 @@ ASSOCIATED can be a plist, a buffer, or a string.
A buffer is treated as (:buffer ASSOCIATED). A buffer is treated as (:buffer ASSOCIATED).
A string is treated as (:file ASSOCIATED). A string is treated as (:file ASSOCIATED).
When LOAD? is non-nil, load the data instead of reading." When LOAD? is non-nil, load the data instead of reading."
(unless org-persist--index (org-persist--load-index))
(setq associated (org-persist--normalize-associated associated)) (setq associated (org-persist--normalize-associated associated))
(setq container (org-persist--normalize-container container)) (setq container (org-persist--normalize-container container))
(unless (and org-persist-disable-when-emacs-Q (let* ((collection (org-persist--find-index `(:container ,container :associated ,associated)))
;; FIXME: This is relying on undocumented fact that (persist-file
;; Emacs sets `user-init-file' to nil when loaded with (when collection
;; "-Q" argument. (org-file-name-concat
(not user-init-file)) org-persist-directory
(let* ((collection (org-persist--find-index `(:container ,container :associated ,associated))) (plist-get collection :persist-file))))
(persist-file (data nil))
(when collection (when (and collection
(org-file-name-concat (file-exists-p persist-file)
org-persist-directory (or (not (plist-get collection :expiry)) ; current session
(plist-get collection :persist-file)))) (not (org-persist--gc-expired-p
(data nil)) (plist-get collection :expiry) collection)))
(when (and collection (or (not hash-must-match)
(file-exists-p persist-file) (and (plist-get associated :hash)
(or (not (plist-get collection :expiry)) ; current session (equal (plist-get associated :hash)
(not (org-persist--gc-expired-p (plist-get (plist-get collection :associated) :hash)))))
(plist-get collection :expiry) collection))) (unless (seq-find (lambda (v)
(or (not hash-must-match) (run-hook-with-args-until-success 'org-persist-before-read-hook v associated))
(and (plist-get associated :hash) (plist-get collection :container))
(equal (plist-get associated :hash) (setq data (or (gethash persist-file org-persist--write-cache)
(plist-get (plist-get collection :associated) :hash))))) (org-persist--read-elisp-file persist-file)))
(unless (seq-find (lambda (v) (when data
(run-hook-with-args-until-success 'org-persist-before-read-hook v associated)) (cl-loop for container in (plist-get collection :container)
(plist-get collection :container)) with result = nil
(setq data (or (gethash persist-file org-persist--write-cache) do
(org-persist--read-elisp-file persist-file))) (if load?
(when data (push (org-persist-load:generic container (alist-get container data nil nil #'equal) collection) result)
(cl-loop for container in (plist-get collection :container) (push (org-persist-read:generic container (alist-get container data nil nil #'equal) collection) result))
with result = nil (run-hook-with-args 'org-persist-after-read-hook container associated)
do finally return (if (= 1 (length result)) (car result) result)))))))
(if load?
(push (org-persist-load:generic container (alist-get container data nil nil #'equal) collection) result)
(push (org-persist-read:generic container (alist-get container data nil nil #'equal) collection) result))
(run-hook-with-args 'org-persist-after-read-hook container associated)
finally return (if (= 1 (length result)) (car result) result))))))))
(defun org-persist-load (container &optional associated hash-must-match) (defun org-persist-load (container &optional associated hash-must-match)
"Load CONTAINER data for ASSOCIATED. "Load CONTAINER data for ASSOCIATED.
@ -843,62 +843,66 @@ The return value is nil when writing fails and the written value (as
returned by `org-persist-read') on success. returned by `org-persist-read') on success.
When IGNORE-RETURN is non-nil, just return t on success without calling When IGNORE-RETURN is non-nil, just return t on success without calling
`org-persist-read'." `org-persist-read'."
(unless (and org-persist-disable-when-emacs-Q (setq associated (org-persist--normalize-associated associated))
;; FIXME: This is relying on undocumented fact that ;; Update hash
;; Emacs sets `user-init-file' to nil when loaded with (when (and (plist-get associated :file)
;; "-Q" argument. (plist-get associated :hash)
(not user-init-file)) (get-file-buffer (plist-get associated :file)))
(setq associated (org-persist--normalize-associated associated)) (setq associated (org-persist--normalize-associated (get-file-buffer (plist-get associated :file)))))
;; Update hash (let ((collection (org-persist--get-collection container associated)))
(when (and (plist-get associated :file) (setf collection (plist-put collection :associated associated))
(plist-get associated :hash) (unless (or
(get-file-buffer (plist-get associated :file))) ;; Prevent data leakage from encrypted files.
(setq associated (org-persist--normalize-associated (get-file-buffer (plist-get associated :file))))) ;; We do it in somewhat paranoid manner and do not
(let ((collection (org-persist--get-collection container associated))) ;; allow anything related to encrypted files to be
(setf collection (plist-put collection :associated associated)) ;; written.
(unless (or (and (plist-get associated :file)
;; Prevent data leakage from encrypted files. (string-match-p epa-file-name-regexp (plist-get associated :file)))
;; We do it in somewhat paranoid manner and do not (seq-find (lambda (v)
;; allow anything related to encrypted files to be (run-hook-with-args-until-success 'org-persist-before-write-hook v associated))
;; written. (plist-get collection :container)))
(and (plist-get associated :file) (when (or (file-exists-p org-persist-directory) (org-persist--save-index))
(string-match-p epa-file-name-regexp (plist-get associated :file))) (let ((file (org-file-name-concat org-persist-directory (plist-get collection :persist-file)))
(seq-find (lambda (v) (data (mapcar (lambda (c) (cons c (org-persist-write:generic c collection)))
(run-hook-with-args-until-success 'org-persist-before-write-hook v associated)) (plist-get collection :container))))
(plist-get collection :container))) (puthash file data org-persist--write-cache)
(when (or (file-exists-p org-persist-directory) (org-persist--save-index)) (org-persist--write-elisp-file file data)
(let ((file (org-file-name-concat org-persist-directory (plist-get collection :persist-file))) (or ignore-return (org-persist-read container associated)))))))
(data (mapcar (lambda (c) (cons c (org-persist-write:generic c collection)))
(plist-get collection :container))))
(puthash file data org-persist--write-cache)
(org-persist--write-elisp-file file data)
(or ignore-return (org-persist-read container associated))))))))
(defun org-persist-write-all (&optional associated) (defun org-persist-write-all (&optional associated)
"Save all the persistent data. "Save all the persistent data.
When ASSOCIATED is non-nil, only save the matching data." When ASSOCIATED is non-nil, only save the matching data."
(unless org-persist--index (org-persist--load-index)) (unless org-persist--index (org-persist--load-index))
(setq associated (org-persist--normalize-associated associated)) (setq associated (org-persist--normalize-associated associated))
(let (all-containers) (unless
(dolist (collection org-persist--index) (and (equal 1 (length org-persist--index))
(if associated ;; The single collection only contains a single container
(when collection ;; in the container list.
(cl-pushnew (plist-get collection :container) all-containers :test #'equal)) (equal 1 (length (plist-get (car org-persist--index) :container)))
(condition-case err ;; The container is an `index' container.
(org-persist-write (plist-get collection :container) (plist-get collection :associated) t) (eq 'index (caar (plist-get (car org-persist--index) :container)))
(error ;; No `org-persist-directory' exists yet.
(message "%s. Deleting bad index entry." err) (not (file-exists-p org-persist-directory)))
(org-persist--remove-from-index collection) (let (all-containers)
nil)))) (dolist (collection org-persist--index)
(dolist (container all-containers) (if associated
(let ((collection (org-persist--find-index `(:container ,container :associated ,associated)))) (when collection
(when collection (cl-pushnew (plist-get collection :container) all-containers :test #'equal))
(condition-case err (condition-case err
(org-persist-write container associated t) (org-persist-write (plist-get collection :container) (plist-get collection :associated) t)
(error (error
(message "%s. Deleting bad index entry." err) (message "%s. Deleting bad index entry." err)
(org-persist--remove-from-index collection) (org-persist--remove-from-index collection)
nil))))))) nil))))
(dolist (container all-containers)
(let ((collection (org-persist--find-index `(:container ,container :associated ,associated))))
(when collection
(condition-case err
(org-persist-write container associated t)
(error
(message "%s. Deleting bad index entry." err)
(org-persist--remove-from-index collection)
nil))))))))
(defun org-persist-write-all-buffer () (defun org-persist-write-all-buffer ()
"Call `org-persist-write-all' in current buffer. "Call `org-persist-write-all' in current buffer.
@ -931,45 +935,40 @@ Do nothing in an indirect buffer."
(defun org-persist-gc () (defun org-persist-gc ()
"Remove expired or unregistered containers. "Remove expired or unregistered containers.
Also, remove containers associated with non-existing files." Also, remove containers associated with non-existing files."
(unless (and org-persist-disable-when-emacs-Q (let (new-index (remote-files-num 0))
;; FIXME: This is relying on undocumented fact that (dolist (collection org-persist--index)
;; Emacs sets `user-init-file' to nil when loaded with (let* ((file (plist-get (plist-get collection :associated) :file))
;; "-Q" argument. (file-remote (when file (file-remote-p file)))
(not user-init-file)) (persist-file (when (plist-get collection :persist-file)
(let (new-index (remote-files-num 0)) (org-file-name-concat
(dolist (collection org-persist--index) org-persist-directory
(let* ((file (plist-get (plist-get collection :associated) :file)) (plist-get collection :persist-file))))
(file-remote (when file (file-remote-p file))) (expired? (org-persist--gc-expired-p
(persist-file (when (plist-get collection :persist-file) (plist-get collection :expiry) collection)))
(org-file-name-concat (when persist-file
org-persist-directory (when file
(plist-get collection :persist-file)))) (when file-remote (cl-incf remote-files-num))
(expired? (org-persist--gc-expired-p (unless (if (not file-remote)
(plist-get collection :expiry) collection))) (file-exists-p file)
(when persist-file (pcase org-persist-remote-files
(when file ('t t)
(when file-remote (cl-incf remote-files-num)) ('check-existence
(unless (if (not file-remote) (file-exists-p file))
(file-exists-p file) ((pred numberp)
(pcase org-persist-remote-files (<= org-persist-remote-files remote-files-num))
('t t) (_ nil)))
('check-existence (setq expired? t)))
(file-exists-p file)) (if expired?
((pred numberp) (org-persist--gc-persist-file persist-file)
(<= org-persist-remote-files remote-files-num)) (push collection new-index)))))
(_ nil))) (setq org-persist--index (nreverse new-index))))
(setq expired? t)))
(if expired?
(org-persist--gc-persist-file persist-file)
(push collection new-index)))))
(setq org-persist--index (nreverse new-index)))))
;; Automatically write the data, but only when we have write access. ;; Automatically write the data, but only when we have write access.
(let ((dir (directory-file-name (let ((dir (directory-file-name
(file-name-as-directory org-persist-directory)))) (file-name-as-directory org-persist-directory))))
(while (and (not (file-exists-p dir)) (while (and (not (file-exists-p dir))
(not (equal dir (setq dir (directory-file-name (not (equal dir (setq dir (directory-file-name
(file-name-directory dir))))))) (file-name-directory dir)))))))
(if (not (file-writable-p dir)) (if (not (file-writable-p dir))
(message "Missing write access rights to org-persist-directory: %S" (message "Missing write access rights to org-persist-directory: %S"
org-persist-directory) org-persist-directory)
@ -978,6 +977,15 @@ Also, remove containers associated with non-existing files."
;; So we are adding the hook after `org-persist-write-all'. ;; So we are adding the hook after `org-persist-write-all'.
(add-hook 'kill-emacs-hook #'org-persist-gc))) (add-hook 'kill-emacs-hook #'org-persist-gc)))
;; Point to temp directory when `org-persist--disable-when-emacs-Q' is set.
(if (and org-persist--disable-when-emacs-Q
;; FIXME: This is relying on undocumented fact that
;; Emacs sets `user-init-file' to nil when loaded with
;; "-Q" argument.
(not user-init-file))
(setq org-persist-directory
(make-temp-file "org-persist-" 'dir)))
(add-hook 'after-init-hook #'org-persist-load-all) (add-hook 'after-init-hook #'org-persist-load-all)
(provide 'org-persist) (provide 'org-persist)

View file

@ -11,7 +11,7 @@ Inserted by installing Org mode or when a release is made."
(defun org-git-version () (defun org-git-version ()
"The Git version of Org mode. "The Git version of Org mode.
Inserted by installing Org or when a release is made." Inserted by installing Org or when a release is made."
(let ((org-git-version "release_9.6-31-g954a95")) (let ((org-git-version "release_9.6-49-g47d129"))
org-git-version)) org-git-version))
(provide 'org-version) (provide 'org-version)

View file

@ -102,6 +102,7 @@
(require 'org-cycle) (require 'org-cycle)
(defvaralias 'org-hide-block-startup 'org-cycle-hide-block-startup) (defvaralias 'org-hide-block-startup 'org-cycle-hide-block-startup)
(defvaralias 'org-hide-drawer-startup 'org-cycle-hide-drawer-startup)
(defvaralias 'org-pre-cycle-hook 'org-cycle-pre-hook) (defvaralias 'org-pre-cycle-hook 'org-cycle-pre-hook)
(defvaralias 'org-tab-first-hook 'org-cycle-tab-first-hook) (defvaralias 'org-tab-first-hook 'org-cycle-tab-first-hook)
(defalias 'org-global-cycle #'org-cycle-global) (defalias 'org-global-cycle #'org-cycle-global)
@ -4596,8 +4597,8 @@ is available. This option applies only if FILE is a URL."
This checks every pattern in `org-safe-remote-resources', and This checks every pattern in `org-safe-remote-resources', and
returns non-nil if any of them match." returns non-nil if any of them match."
(let ((uri-patterns org-safe-remote-resources) (let ((uri-patterns org-safe-remote-resources)
(file-uri (and buffer-file-name (file-uri (and (buffer-file-name (buffer-base-buffer))
(concat "file://" (file-truename buffer-file-name)))) (concat "file://" (file-truename (buffer-file-name (buffer-base-buffer))))))
match-p) match-p)
(while (and (not match-p) uri-patterns) (while (and (not match-p) uri-patterns)
(setq match-p (or (string-match-p (car uri-patterns) uri) (setq match-p (or (string-match-p (car uri-patterns) uri)
@ -4608,7 +4609,8 @@ returns non-nil if any of them match."
(defun org--confirm-resource-safe (uri) (defun org--confirm-resource-safe (uri)
"Ask the user if URI should be considered safe, returning non-nil if so." "Ask the user if URI should be considered safe, returning non-nil if so."
(unless noninteractive (unless noninteractive
(let ((current-file (and buffer-file-name (file-truename buffer-file-name))) (let ((current-file (and (buffer-file-name (buffer-base-buffer))
(file-truename (buffer-file-name (buffer-base-buffer)))))
(domain (and (string-match (domain (and (string-match
(rx (seq "http" (? "s") "://") (rx (seq "http" (? "s") "://")
(optional (+ (not (any "@/\n"))) "@") (optional (+ (not (any "@/\n"))) "@")
@ -16399,6 +16401,10 @@ buffer boundaries with possible narrowing."
"Remove inline-display overlay if a corresponding region is modified." "Remove inline-display overlay if a corresponding region is modified."
(when (and ov after) (when (and ov after)
(delete ov org-inline-image-overlays) (delete ov org-inline-image-overlays)
;; Clear image from cache to avoid image not updating upon
;; changing on disk. See Emacs bug#59902.
(when (overlay-get ov 'org-image-overlay)
(image-flush (overlay-get ov 'display)))
(delete-overlay ov))) (delete-overlay ov)))
(defun org-remove-inline-images (&optional beg end) (defun org-remove-inline-images (&optional beg end)

View file

@ -4612,12 +4612,17 @@ If LINK refers to a remote resource, modify it to point to a local
downloaded copy. Otherwise, return unchanged LINK." downloaded copy. Otherwise, return unchanged LINK."
(when (org-export-link-remote-p link) (when (org-export-link-remote-p link)
(let* ((local-path (org-export-link--remote-local-copy link))) (let* ((local-path (org-export-link--remote-local-copy link)))
(setcdr link (if local-path
(thread-first (cadr link) (setcdr link
(plist-put :type "file") (thread-first (cadr link)
(plist-put :path local-path) (plist-put :type "file")
(plist-put :raw-link (concat "file:" local-path)) (plist-put :path local-path)
list)))) (plist-put :raw-link (concat "file:" local-path))
list))
(display-warning
'(org export)
(format "unable to obtain local copy of %s"
(org-element-property :raw-link link))))))
link) link)
;;;; For References ;;;; For References
@ -4753,23 +4758,27 @@ objects of the same type."
(let ((counter 0)) (let ((counter 0))
;; Increment counter until ELEMENT is found again. ;; Increment counter until ELEMENT is found again.
(org-element-map (plist-get info :parse-tree) (org-element-map (plist-get info :parse-tree)
(or types (org-element-type element)) (or (and types (cons (org-element-type element) types))
(org-element-type element))
(lambda (el) (lambda (el)
(let ((cached (org-element-property :org-export--counter el))) (let ((cached (org-element-property :org-export--counter el)))
(cond (cond
((eq element el) (1+ counter)) ((eq element el) (1+ counter))
;; Use cached result. ;; Use cached result.
((and cached (equal predicate (car cached))) ((and cached
(cdr cached)) (equal predicate (car cached))
(equal types (cadr cached)))
(setq counter (nth 2 cached))
nil)
((not predicate) ((not predicate)
(cl-incf counter) (cl-incf counter)
(org-element-put-property (org-element-put-property
el :org-export--counter (cons predicate counter)) el :org-export--counter (list predicate types counter))
nil) nil)
((funcall predicate el info) ((funcall predicate el info)
(cl-incf counter) (cl-incf counter)
(org-element-put-property (org-element-put-property
el :org-export--counter (cons predicate counter)) el :org-export--counter (list predicate types counter))
nil)))) nil))))
info 'first-match))))) info 'first-match)))))