Move known links to front of link list only in older Org versions
This behavior became the default in Org 9.7.
This commit is contained in:
parent
de68fc30b2
commit
01a71c93d2
72
init.el
72
init.el
@ -827,45 +827,49 @@
|
|||||||
:autoload (org-link-set-parameters)
|
:autoload (org-link-set-parameters)
|
||||||
:config (progn
|
:config (progn
|
||||||
|
|
||||||
(define-advice org-store-link (:around
|
(when (version< (org-version) "9.7")
|
||||||
(orig-func &rest args)
|
;; Pushing already stored links to the front of `org-stored-links' became default
|
||||||
db/org--push-new-links-to-beginning)
|
;; behavior in Org 9.7, the below code is thus only needed for older versions.
|
||||||
"Ensure that new links in `org-store-link' are always at the beginning."
|
|
||||||
;; The idea here is to store the list of already known links,
|
|
||||||
;; stored in `org-stored-links', and call `org-store-link' with an
|
|
||||||
;; empty value of `org-stored-links'. This way, the link to the
|
|
||||||
;; current item is store in any case, and we prepend these new
|
|
||||||
;; values (can be more than one if CUSTOM_ID is set) to the old
|
|
||||||
;; list of links. We also remove the newly prepended links from
|
|
||||||
;; the list of already known links.
|
|
||||||
|
|
||||||
(let ((org-stored-links--original org-stored-links)
|
(define-advice org-store-link (:around
|
||||||
(org-stored-links--new nil)
|
(orig-func &rest args)
|
||||||
(org-store-link--return-value nil))
|
db/org--push-new-links-to-beginning)
|
||||||
|
"Ensure that new links in `org-store-link' are always at the beginning."
|
||||||
|
;; The idea here is to store the list of already known links,
|
||||||
|
;; stored in `org-stored-links', and call `org-store-link' with an
|
||||||
|
;; empty value of `org-stored-links'. This way, the link to the
|
||||||
|
;; current item is store in any case, and we prepend these new
|
||||||
|
;; values (can be more than one if CUSTOM_ID is set) to the old
|
||||||
|
;; list of links. We also remove the newly prepended links from
|
||||||
|
;; the list of already known links.
|
||||||
|
|
||||||
(let ((org-stored-links nil))
|
(let ((org-stored-links--original org-stored-links)
|
||||||
;; This is the actual call to `org-store-link', which may (and
|
(org-stored-links--new nil)
|
||||||
;; usually will) update `org-stored-links'. Note that the new
|
(org-store-link--return-value nil))
|
||||||
;; value of `org-stored-links' is only available after
|
|
||||||
;; `org-store-link' as finished, which is why we make two
|
|
||||||
;; separate calls to `setq' here instead of only one.
|
|
||||||
(setq org-store-link--return-value (apply orig-func args))
|
|
||||||
(setq org-stored-links--new org-stored-links))
|
|
||||||
|
|
||||||
;; Note: `org-stored-links--new' might still be nil after
|
(let ((org-stored-links nil))
|
||||||
;; calling `org-store-link', as under some circumstances (and
|
;; This is the actual call to `org-store-link', which may (and
|
||||||
;; only when the `interactive?' argument to `org-store-link' is
|
;; usually will) update `org-stored-links'. Note that the new
|
||||||
;; non-nil), `org-store-link' may only return a link and not
|
;; value of `org-stored-links' is only available after
|
||||||
;; update `org-stored-links'; in this case, we do not have to
|
;; `org-store-link' as finished, which is why we make two
|
||||||
;; touch the original value of `org-stored-links' at all.
|
;; separate calls to `setq' here instead of only one.
|
||||||
|
(setq org-store-link--return-value (apply orig-func args))
|
||||||
|
(setq org-stored-links--new org-stored-links))
|
||||||
|
|
||||||
(unless (null org-stored-links--new)
|
;; Note: `org-stored-links--new' might still be nil after
|
||||||
(setq org-stored-links (nconc org-stored-links--new
|
;; calling `org-store-link', as under some circumstances (and
|
||||||
(cl-remove-if #'(lambda (x)
|
;; only when the `interactive?' argument to `org-store-link' is
|
||||||
(member x org-stored-links--new))
|
;; non-nil), `org-store-link' may only return a link and not
|
||||||
org-stored-links--original))))
|
;; update `org-stored-links'; in this case, we do not have to
|
||||||
|
;; touch the original value of `org-stored-links' at all.
|
||||||
|
|
||||||
org-store-link--return-value))
|
(unless (null org-stored-links--new)
|
||||||
|
(setq org-stored-links (nconc org-stored-links--new
|
||||||
|
(cl-remove-if #'(lambda (x)
|
||||||
|
(member x org-stored-links--new))
|
||||||
|
org-stored-links--original))))
|
||||||
|
|
||||||
|
org-store-link--return-value)))
|
||||||
|
|
||||||
(define-advice org-link-make-string (:around
|
(define-advice org-link-make-string (:around
|
||||||
(orig-func link &optional description)
|
(orig-func link &optional description)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user