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.el175
1 files changed, 0 insertions, 175 deletions
diff --git a/lisp/+link-hint.el b/lisp/+link-hint.el deleted file mode 100644 index 0e0b9b1..0000000 --- a/lisp/+link-hint.el +++ /dev/null
@@ -1,175 +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(progn
91 (dolist
92 (type
93 '(gnus-w3m-image-url gnus-w3m-url markdown-link mu4e-attachment mu4e-url notmuch-hello nov-link org-link shr-url text-url w3m-link w3m-message-link))
94 (link-hint-define-type type :download
95 (function +browse-url-download)
96 :download-multiple t))
97 (defun +link-hint-open:download nil "Download a link to `eww-download-directory'.
98
99Defined by `+link-hint-define'."
100 (interactive)
101 (avy-with link-hint-open-link
102 (link-hint--one :download)))
103 (defun +link-hint-open-multiple:download nil "Open multiple links with `+link-hint-open:download'.
104
105Defined by `+link-hint-define'."
106 (avy-with link-hint-open-multiple-links
107 (link-hint--multiple :download)))
108 (defun +link-hint-open-all:download nil "Open all visible links with `+link-hint-open:download'.
109
110Defined by `+link-hint-define'."
111 (avy-with link-hint-open-all-links
112 (link-hint--all :download))))
113
114;; (defun +link-hint-open-secondary-setup (&optional types)
115;; "Define the `:open-secondary' link-hint type for TYPES.
116;; If TYPES is nil, define it for `+link-hint-open-secondary-types'."
117;; (dolist (type (or types +link-hint-open-secondary-types))
118;; (link-hint-define-type type
119;; :open-secondary browse-url-secondary-browser-function
120;; :open-secondary-multiple t)))
121
122;; (defun +link-hint-open-secondary ()
123;; "Open a link in the secondary browser."
124;; (interactive)
125;; (avy-with link-hint-open-link
126;; (link-hint--one :open-secondary)))
127
128(+link-hint-define-keyword :chrome #'browse-url-chrome
129 "Open a link with `browse-url-chrome'."
130 +link-hint-open-secondary-types
131 :multiple t)
132
133;; (defun +link-hint-open-chrome-setup (&optional types)
134;; "Define the `:open-chrome' link-hint type for TYPES.
135;; If TYPES is nil, define it for `+link-hint-open-secondary-types'."
136;; (dolist (type (or types +link-hint-open-secondary-types))
137;; (link-hint-define-type type
138;; :open-chrome #'browse-url-chrome
139;; :open-chrome-multiple t)))
140
141;; (defun +link-hint-open-chrome ()
142;; "Open a link with chrome."
143;; (interactive)
144;; (avy-with link-hint-open-link
145;; (link-hint--one :open-chrome)))
146
147(defun +link-hint-open-link (prefix)
148 "Open a link.
149Without a PREFIX, open using `browse-url-browser-function'; with
150a PREFIX, use `browse-url-secondary-browser-function'."
151 (interactive "P")
152 (let ((current-prefix-arg nil))
153 (avy-with link-hint-open-link
154 (link-hint--one (if prefix :open-secondary :open)))))
155
156;; test: https://www.acdw.net
157
158(defun +link-hint-open-multiple-links (prefix)
159 "Open multiple links.
160Without a PREFIX, open using `browse-url-browser-function'; with
161a PREFIX, use `browse-url-secondary-browser-function'."
162 (interactive "P")
163 (avy-with link-hint-open-multiple-links
164 (link-hint--one (if prefix :open-secondary :open))))
165
166(defun +link-hint-open-all-links (prefix)
167 "Open all visible links.
168Without a PREFIX, open using `browse-url-browser-function'; with
169a PREFIX, use `browse-url-secondary-browser-function'."
170 (interactive "P")
171 (avy-with link-hint-open-all-links
172 (link-hint--one (if prefix :open-secondary :open))))
173
174(provide '+link-hint)
175;;; +link-hint.el ends here