summary refs log tree commit diff stats
path: root/lisp/+link-hint.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/+link-hint.el')
-rw-r--r--lisp/+link-hint.el169
1 files changed, 0 insertions, 169 deletions
diff --git a/lisp/+link-hint.el b/lisp/+link-hint.el deleted file mode 100644 index 205e915..0000000 --- a/lisp/+link-hint.el +++ /dev/null
@@ -1,169 +0,0 @@
1;;; +link-hint.el -*- lexical-binding: t; -*-
2
3;;; Code:
4
5(require 'cl-lib)
6(require 'link-hint)
7
8(defgroup +link-hint nil
9 "Extra customizations for `link-hint'."
10 :group 'link-hint)
11
12(defcustom +link-hint-open-secondary-types '(gnus-w3m-image-url
13 gnus-w3m-url
14 markdown-link
15 mu4e-attachment
16 mu4e-url
17 notmuch-hello
18 nov-link
19 org-link
20 shr-url
21 text-url
22 w3m-link
23 w3m-message-link)
24 "Link types to define `:open-secondary' for.")
25
26(defvar +link-hint-map (make-sparse-keymap)
27 "Keymap for `link-hint' functionality.")
28
29(cl-defmacro +link-hint-define-keyword (keyword handler docstring
30 &optional (types 'link-hint-types)
31 &rest rest
32 &key multiple &allow-other-keys)
33 "Set up a `link-hint' KEYWORD, with optional TYPES.
34If TYPES is not present, use `link-hint-types'.
35
36KEYWORD defines the link-hint type. It will be used to create a
37function for opening links of the form \"link-hint-openKEYWORD\".
38
39HANDLER is the function to open a link with.
40
41DOCSTRING is the macro's documentation.
42
43Keyword arguments are passed to `link-hint-define-type' prefixed
44with the KEYWORD."
45 (declare (indent 2)
46 (doc-string 3))
47 (let ((types (symbol-value types))
48 (func-sym (intern (format "+link-hint-open%s" keyword)))
49 (mult-sym (intern (format "%s-multiple" keyword)))
50 (expr))
51 ;; Define the type
52 (push `(dolist (type ',types)
53 (link-hint-define-type type
54 ,keyword ,handler
55 ,@(mapcar (lambda (el)
56 (if (eq el :multiple)
57 mult-sym
58 el))
59 rest)))
60 expr)
61 ;; Define an opener
62 (push `(defun ,func-sym ()
63 ,(format "%s\n\nDefined by `+link-hint-define'." docstring)
64 (interactive)
65 (avy-with link-hint-open-link
66 (link-hint--one ,keyword)))
67 expr)
68 ;; Handle `:multiple'
69 (when multiple
70 (push `(defun ,(intern (format "+link-hint-open-multiple%s" keyword)) ()
71 ,(format "Open multiple links with `%s'.\n\nDefined by `+link-hint-define'."
72 func-sym)
73 (avy-with link-hint-open-multiple-links
74 (link-hint--multiple ,keyword)))
75 expr)
76 (push `(defun ,(intern (format "+link-hint-open-all%s" keyword)) ()
77 ,(format "Open all visible links with `%s'.\n\nDefined by `+link-hint-define'."
78 func-sym)
79 (avy-with link-hint-open-all-links
80 (link-hint--all ,keyword)))
81 expr))
82 ;; Return the built expression
83 `(progn ,@(nreverse expr))))
84
85(+link-hint-define-keyword :secondary browse-url-secondary-browser-function
86 "Open a link in the secondary browser."
87 +link-hint-open-secondary-types
88 :multiple t)
89
90(defun +link-hint-open-secondary-setup (&optional types)
91 "Define the `:open-secondary' link-hint type for TYPES.
92If TYPES is nil, define it for `+link-hint-open-secondary-types'."
93 (dolist (type (or types +link-hint-open-secondary-types))
94 (link-hint-define-type type
95 :open-secondary browse-url-secondary-browser-function
96 :open-secondary-multiple t)))
97
98(defun +link-hint-open-secondary ()
99 "Open a link in the secondary browser."
100 (interactive)
101 (avy-with link-hint-open-link
102 (link-hint--one :open-secondary)))
103
104(defun +link-hint-open-chrome-setup (&optional types)
105 "Define the `:open-chrome' link-hint type for TYPES.
106If TYPES is nil, define it for `+link-hint-open-secondary-types'."
107 (dolist (type (or types +link-hint-open-secondary-types))
108 (link-hint-define-type type
109 :open-chrome #'browse-url-chrome
110 :open-chrome-multiple t)))
111
112(defun +link-hint-open-chrome ()
113 "Open a link with chrome."
114 (interactive)
115 (avy-with link-hint-open-link
116 (link-hint--one :open-chrome)))
117
118;; (cl-defmacro +link-hint-add-type (keyword )
119;; "Define link-hint type KEYWORD to operate on TYPES.
120;; If TYPES is nil or absent, define KEYWORD for all
121;; `link-hint-types'."
122;; (let (forms)
123;; (dolist (type (or types link-hint-types))
124;; (push `(link-hint-define-type ,type ,keyword ,function) forms))
125;; (push `(defun ,(intern (format "+link-hint%s" ,keyword))
126;; ))))
127
128(defun +link-hint-open-link (prefix)
129 "Open a link.
130Without a PREFIX, open using `browse-url-browser-function'; with
131a PREFIX, use `browse-url-secondary-browser-function'."
132 (interactive "P")
133 (avy-with link-hint-open-link
134 (link-hint--one (if prefix :open-secondary :open))))
135
136(defun +link-hint-open-multiple-links (prefix)
137 "Open multiple links.
138Without a PREFIX, open using `browse-url-browser-function'; with
139a PREFIX, use `browse-url-secondary-browser-function'."
140 (interactive "P")
141 (avy-with link-hint-open-multiple-links
142 (link-hint--one (if prefix :open-secondary :open))))
143
144(defun +link-hint-open-all-links (prefix)
145 "Open all visible links.
146Without a PREFIX, open using `browse-url-browser-function'; with
147a PREFIX, use `browse-url-secondary-browser-function'."
148 (interactive "P")
149 (avy-with link-hint-open-all-links
150 (link-hint--one (if prefix :open-secondary :open))))
151
152;;; Pocket-reader.el integration
153
154(defun +link-hint-pocket-add-setup (&optional types)
155 "Define the `:pocket-add' link-hint type for TYPES.
156If TYPES is nil, define it for `link-hint-types'."
157 (dolist (type (or types link-hint-types))
158 (link-hint-define-type type
159 :pocket-add #'pocket-reader-generic-add-link
160 :pocket-add-multiple t)))
161
162(defun +link-hint-pocket-add ()
163 "Add a link to the Pocket reader."
164 (interactive)
165 (avy-with link-hint-open-link
166 (link-hint--one :pocket-add)))
167
168(provide '+link-hint)
169;;; +link-hint.el ends here