Skip to content

Commit

Permalink
Update backlinks jump to support multiple backlinks from the same sou…
Browse files Browse the repository at this point in the history
…rce file
  • Loading branch information
jayemar committed Dec 2, 2024
1 parent 9fb93e7 commit 270138f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions obsidian.el
Original file line number Diff line number Diff line change
Expand Up @@ -1183,11 +1183,14 @@ Template vars: {{title}}, {{date}}, and {{time}}"
(goto-char m)))

(defun obsidian--backlinks-completion-fn (hmap)
"Completion function to show file path and link text from HMAP."
(let* ((obsidian--backlinks-alist
(ht-map (lambda (k v)
(cons (obsidian-file-relative-name k) (nth 2 v)))
hmap)))
"Completion function to show file path and link text from hashmap HMAP."
(let ((obsidian--backlinks-alist
(-flatten
(ht-map (lambda (k1 v1)
(seq-map (lambda (v2)
(cons (obsidian-file-relative-name k1) (nth 2 v2)))
v1))
hmap))))
(completing-read
"Backlinks: "
(lambda (str pred flag)
Expand All @@ -1210,8 +1213,7 @@ Template vars: {{title}}, {{date}}, and {{time}}"
(let* ((choice (obsidian--backlinks-completion-fn linkmap))
(target (obsidian-expand-file-name choice))
(link-info (gethash target linkmap)))
(find-file target)
(goto-char (car link-info)))
(find-file target))
(message "No backlinks found."))))

;;;###autoload
Expand Down

0 comments on commit 270138f

Please sign in to comment.