-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelm-org-backlinks.el
101 lines (73 loc) · 3.08 KB
/
helm-org-backlinks.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
;;; helm-org-backlinks.el --- Helm interface for Org backlinks -*- lexical-binding: t -*-
;; Copyright (C) 2022-2024 Bruno Cardoso
;; Author: Bruno Cardoso <cardoso.bc@gmail.com>
;; URL: https://github.com/bcardoso/org-backlinks
;; Version: 0.2
;; Package-Requires: ((emacs "29.1"))
;; This file is NOT part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Helm interface for Org backlinks.
;;; Code:
(require 'org-backlinks)
(require 'helm)
;;;; Custom variables
(defcustom helm-org-backlinks-actions
(helm-make-actions
"Go to heading" 'org-backlinks-goto-heading)
"Actions for `helm-org-backlinks' sources."
:group 'org-backlinks
:type 'sexp)
;;;; Sources
(defmacro helm-org-backlinks-build-source (name candidates)
"Build Helm source NAME with CANDIDATES."
(declare (indent defun))
`(when ,candidates
(helm-build-sync-source ,name
:action helm-org-backlinks-actions
:candidates ,candidates)))
(defvar helm-org-backlinks-source
(helm-org-backlinks-build-source "Backlinks"
(lambda () org-backlinks-list))
"Helm source for Org backlinks.")
(defvar helm-org-backlinks-second-order-source
(helm-org-backlinks-build-source "2nd order Backlinks"
(lambda () org-backlinks-second-list))
"Helm source for second order Org backlinks.")
(defvar helm-org-backlinks-third-order-source
(helm-org-backlinks-build-source "3rd order Backlinks"
(lambda () org-backlinks-third-list))
"Helm source for third order Org backlinks.")
(defvar helm-org-backlinks-direct-source
(helm-org-backlinks-build-source "Direct links"
(lambda () org-backlinks-direct-list))
"Helm source for the direct links from current heading.")
(defvar helm-org-backlinks-indirect-source
(helm-org-backlinks-build-source "Indirect links"
(lambda () org-backlinks-indirect-list))
"Helm source for the indirect links from current heading.")
;;;; Commands
;;;###autoload
(defun helm-org-backlinks ()
"Helm interface for `org-backlinks'."
(interactive)
(org-backlinks-setup)
(when (org-backlinks-list-all)
(helm :prompt "Go to heading: "
:truncate-lines nil
:sources '(helm-org-backlinks-source
helm-org-backlinks-second-order-source
helm-org-backlinks-third-order-source
helm-org-backlinks-direct-source
helm-org-backlinks-indirect-source))))
(provide 'helm-org-backlinks)
;;; helm-org-backlinks.el ends here