Compare commits
No commits in common. "341dec6a6a326814ae903e4926016d74117e4889" and "5576b363cb8b8a3b7c41cb2da3f0aa485e93c331" have entirely different histories.
341dec6a6a
...
5576b363cb
@ -16,7 +16,6 @@
|
|||||||
(require 'hydra)
|
(require 'hydra)
|
||||||
(require 'db-customize)
|
(require 'db-customize)
|
||||||
(require 'ox-icalendar)
|
(require 'ox-icalendar)
|
||||||
(require 'org-ql)
|
|
||||||
|
|
||||||
(autoload 'counsel-org-goto-all "counsel")
|
(autoload 'counsel-org-goto-all "counsel")
|
||||||
(autoload 'which-function "which-func")
|
(autoload 'which-function "which-func")
|
||||||
@ -814,11 +813,11 @@ not."
|
|||||||
(defun db/org-get-location (&optional arg)
|
(defun db/org-get-location (&optional arg)
|
||||||
"Interactively query for location and return mark.
|
"Interactively query for location and return mark.
|
||||||
|
|
||||||
Searches through the current buffer if that one is an Org buffer
|
Searches through the current buffer if that one is associated
|
||||||
and is associated with a file, or `db/org-default-org-file'.
|
with a file, or `db/org-default-org-file'. When ARG is non-nil,
|
||||||
When ARG is non-nil, search through all files in the variables
|
search through all files in the variables `org-agenda-files',
|
||||||
`org-agenda-files', `org-agenda-text-search-extra-files', and the
|
`org-agenda-text-search-extra-files', and the current file or
|
||||||
current file or `db/org-default-org-file'.
|
`db/org-default-org-file'.
|
||||||
|
|
||||||
Search is always conducted up to level 9. If the selected
|
Search is always conducted up to level 9. If the selected
|
||||||
location does not have an associated point or mark, error out.
|
location does not have an associated point or mark, error out.
|
||||||
@ -826,10 +825,9 @@ Disable refile cache and any active refile filter hooks to allow
|
|||||||
linking to any item."
|
linking to any item."
|
||||||
(let ((org-refile-target-verify-function nil)
|
(let ((org-refile-target-verify-function nil)
|
||||||
(org-refile-use-cache nil)
|
(org-refile-use-cache nil)
|
||||||
;; If the current buffer is an Org buffer and is associated with a file,
|
;; If the current buffer is associated with a file, search through it;
|
||||||
;; search through it; otherwise, use the default Org Mode file as
|
;; otherwise, use the default Org Mode file as default buffer
|
||||||
;; default buffer
|
(default-buffer (if (buffer-file-name)
|
||||||
(default-buffer (if (and (buffer-file-name) (derived-mode-p 'org-mode))
|
|
||||||
(current-buffer)
|
(current-buffer)
|
||||||
(find-file-noselect db/org-default-org-file))))
|
(find-file-noselect db/org-default-org-file))))
|
||||||
(when (null default-buffer)
|
(when (null default-buffer)
|
||||||
@ -860,23 +858,19 @@ Only links using the ID or CUSTOM_ID property are considered.
|
|||||||
|
|
||||||
If ARG is given, or if neither in an Org Mode buffer nor on a
|
If ARG is given, or if neither in an Org Mode buffer nor on a
|
||||||
headline in an Org Agenda buffer, interactively prompt for an
|
headline in an Org Agenda buffer, interactively prompt for an
|
||||||
item using `db/org-get-location', which see."
|
item."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(apply #'db/org-find-items-linking-by-id
|
(apply #'db/org-find-items-linking-by-id
|
||||||
;; Determine the current item interactively based on where we are: when
|
(cond ((and (not arg) (derived-mode-p 'org-mode))
|
||||||
;; in an Org buffer or in Org agenda view, indeed use the item at
|
(list (org-id-get) (org-entry-get nil "CUSTOM_ID")))
|
||||||
;; point; otherwise, and when ARG is given, query the user for the item
|
((and (not arg)
|
||||||
;; to look for.
|
(derived-mode-p 'org-agenda-mode)
|
||||||
(org-with-point-at (cond ((and (not arg)
|
(org-get-at-bol 'org-hd-marker))
|
||||||
(derived-mode-p 'org-mode))
|
(org-with-point-at (org-get-at-bol 'org-hd-marker)
|
||||||
(point))
|
(list (org-id-get) (org-entry-get nil "CUSTOM_ID"))))
|
||||||
((and (not arg)
|
(t
|
||||||
(derived-mode-p 'org-agenda-mode)
|
(org-with-point-at (db/org-get-location)
|
||||||
(org-get-at-bol 'org-hd-marker))
|
(list (org-id-get) (org-entry-get nil "CUSTOM_ID")))))))
|
||||||
(org-get-at-bol 'org-hd-marker))
|
|
||||||
(t
|
|
||||||
(db/org-get-location)))
|
|
||||||
(list (org-id-get) (org-entry-get nil "CUSTOM_ID")))))
|
|
||||||
|
|
||||||
(defun db/org-insert-link-to-pom (pom)
|
(defun db/org-insert-link-to-pom (pom)
|
||||||
"Insert an Org link to headline at POM.
|
"Insert an Org link to headline at POM.
|
||||||
@ -955,41 +949,6 @@ Show _b_acklinks to current item."
|
|||||||
("O" (db/org-add-link-to-other-item t))
|
("O" (db/org-add-link-to-other-item t))
|
||||||
("b" db/org-find-links-to-current-item))
|
("b" db/org-find-links-to-current-item))
|
||||||
|
|
||||||
(defun db/org-backlinks-to-item-at-point (&optional org-ql-match archives)
|
|
||||||
"Return list of Org links to item at point.
|
|
||||||
|
|
||||||
The links are grouped in singleton lists to allow easy formatting
|
|
||||||
in Org mode source blocks with “:reslts value table”. If the
|
|
||||||
optional ORG-QL-MATCH is given and is a valid `org-ql' query in
|
|
||||||
sexp syntax, filter the list for all items matching this query.
|
|
||||||
If ARCHIVES is given, also include archive files.
|
|
||||||
|
|
||||||
The search is conducted over all files returned by
|
|
||||||
`org-agenda-files' including archives, as well as all files
|
|
||||||
referenced in `org-agenda-text-search-extra-files'."
|
|
||||||
(let ((id-of-item-at-point (org-id-get))
|
|
||||||
(org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
|
|
||||||
files)
|
|
||||||
|
|
||||||
(unless id-of-item-at-point
|
|
||||||
(user-error "Item at point does not have an ID property set, cannot determine backlinks"))
|
|
||||||
|
|
||||||
;; Determine files to search through; ignore `agenda-archive' in
|
|
||||||
;; `org-agenda-text-search-extra-files', as we already handle this when
|
|
||||||
;; calling `org-agenda-files'.
|
|
||||||
(setq files (org-agenda-files t archives))
|
|
||||||
(when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
|
|
||||||
(pop org-agenda-text-search-extra-files))
|
|
||||||
(setq files (nconc files org-agenda-text-search-extra-files))
|
|
||||||
|
|
||||||
(org-ql-query :select '(list (org-link-make-string (format "id:%s" (org-id-get-create))
|
|
||||||
(org-entry-get (point) "ITEM")))
|
|
||||||
:from files
|
|
||||||
:where (let ((link-expression `(link :target ,id-of-item-at-point)))
|
|
||||||
(if org-ql-match
|
|
||||||
`(and ,link-expression ,org-ql-match)
|
|
||||||
link-expression)))))
|
|
||||||
|
|
||||||
|
|
||||||
;;; End
|
;;; End
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user