-
Notifications
You must be signed in to change notification settings - Fork 20
/
org-super-links-org-ql.el
71 lines (54 loc) · 2.88 KB
/
org-super-links-org-ql.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
;;; org-super-links-org-ql.el --- Make super links -*- lexical-binding: t; -*-
;; Copyright (C) 2020 tosh
;; Author: tosh <tosh.lyons@gmail.com>
;; Version: 0.4
;; Package-Requires: ((emacs "26.1") (helm-org-ql "0.5"))
;; URL: https://github.com/toshism/org-super-links
;; Keywords: convenience, hypermedia
;; 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 <https://www.gnu.org/licenses/>.
;;; Commentary:
;; The most overly ambitiously named package to help you make links with backlinks.
;;
;; I should describe how it actually works here.
;;; Code:
(declare-function org-super-links--insert-link "org-super-links")
(declare-function helm-org-ql "ext:helm-org-ql")
(declare-function org-agenda-files "ext:org-mode")
(defvar helm-org-ql-actions)
(defun org-super-links-org-ql-buffer-mode (&optional buffer-or-name)
"Return the major mode associated with a buffer.
If BUFFER-OR-NAME is nil return current buffer's mode."
(buffer-local-value 'major-mode
(if buffer-or-name (get-buffer buffer-or-name) (current-buffer))))
(defun org-super-links-org-ql-get-search-buffers ()
"Return the buffers to provide to `helm-org-ql`.
If the current buffer is an `org-mode` buffer add it to `org-agenda-files`.
If the current buffer is a capture buffer add the target buffer to `org-agenda-files`
Else just return `org-agenda-files`"
(let ((current-or-target-buffer (or (buffer-file-name) (buffer-file-name (org-capture-get :buffer)))))
(if (and (string= (org-super-links-org-ql-buffer-mode) "org-mode")
current-or-target-buffer)
(cons current-or-target-buffer (org-agenda-files))
(org-agenda-files))))
(defun org-super-links-org-ql-link-search-interface ()
"Setup the `helm-org-ql' search interface."
(add-to-list 'helm-org-ql-actions '("super-link-temp" . org-super-links-org-ql-insert-link-action) nil)
(helm-org-ql (org-super-links-org-ql-get-search-buffers))
(pop helm-org-ql-actions))
(with-eval-after-load "helm-org-ql"
(add-to-list 'helm-org-ql-actions '("Super Link" . org-super-links-org-ql-insert-link-action) t))
(defun org-super-links-org-ql-insert-link-action (marker)
"Wrapper for `org-super-links--insert-link` for `org-ql' integration.
MARKER is the point at first char in the selected heading."
(org-super-links--insert-link marker))
(provide 'org-super-links-org-ql)
;;; org-super-links-org-ql.el ends here