about summary refs log tree commit diff stats
path: root/lisp/acdw-web.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/acdw-web.el')
-rw-r--r--lisp/acdw-web.el101
1 files changed, 83 insertions, 18 deletions
diff --git a/lisp/acdw-web.el b/lisp/acdw-web.el index 36a5ba4..40e1a3d 100644 --- a/lisp/acdw-web.el +++ b/lisp/acdw-web.el
@@ -114,6 +114,9 @@ regexp that will not be regexp-quoted when matching against a url."
114 (list :tag "Regexp" regexp) 114 (list :tag "Regexp" regexp)
115 (string :tag "Literal string")))) 115 (string :tag "Literal string"))))
116 116
117(with-eval-after-load 'custom-allowed
118 (add-to-list 'custom-allowed-variables '+browse-url-external-domains))
119
117(defun +browse-url-external-url-p (url) 120(defun +browse-url-external-url-p (url)
118 "Return t if URL is a member of `+browse-url-external-domains'. 121 "Return t if URL is a member of `+browse-url-external-domains'.
119This function only tests URL's domain." 122This function only tests URL's domain."
@@ -125,6 +128,29 @@ This function only tests URL's domain."
125 host) 128 host)
126 return t))) 129 return t)))
127 130
131(defun +browse-url-external-domain-add (domain &optional regexp?)
132 "Add DOMAIN to `+browse-url-external-domains'.
133If REGEXP? is non-nil, it will note that the domain is a regexp.
134This function will also save `custom-file' with the updated value."
135 (interactive (pcase current-prefix-arg
136 (`nil
137 (list (read-from-minibuffer "Domain: ")
138 nil))
139 (`(4)
140 (list (read-from-minibuffer "Domain regex: ")
141 t))
142 (_
143 (list (read-from-minibuffer "Domain: ")
144 (y-or-n-p "Regex? ")))))
145 (let ((new (funcall (if regexp? #'list #'identity)
146 domain)))
147 (custom-set-variables
148 `(+browse-url-external-domains
149 ',(add-to-list '+browse-url-external-domains new)))
150 (with-current-buffer (find-file-noselect custom-file)
151 (custom-save-variables))
152 (message "%s added to `+browse-url-external-domains'."
153 domain)))
128 154
129;;; Downloading 155;;; Downloading
130 156
@@ -165,6 +191,34 @@ This function only tests URL's domain."
165;;; Packages 191;;; Packages
166 192
167(use-package eww 193(use-package eww
194 :preface
195 (defun bookmark-eww--make ()
196 "Make eww bookmark record."
197 `((filename . ,(plist-get eww-data :url))
198 (title . ,(plist-get eww-data :title))
199 (time . ,(current-time-string))
200 (handler . ,#'bookmark-eww-handler)
201 (defaults . (,(concat
202 ;; url without the https and path
203 (replace-regexp-in-string
204 "/.*" ""
205 (replace-regexp-in-string
206 "\\`https?://" ""
207 (plist-get eww-data :url)))
208 " - "
209 ;; page title
210 (replace-regexp-in-string
211 "\\` +\\| +\\'" ""
212 (replace-regexp-in-string
213 "[\n\t\r ]+" " "
214 (plist-get eww-data :title))))))))
215 (defun bookmark-eww-handler (bm)
216 "Handler for eww bookmarks."
217 (eww-browse-url (alist-get 'filename bm)))
218 (defun bookmark-eww--setup ()
219 "Setup eww bookmark integration."
220 (setq-local bookmark-make-record-function #'bookmark-eww--make))
221 :commands (eww eww-browse-url)
168 :config 222 :config
169 (setopt eww-use-browse-url ".") 223 (setopt eww-use-browse-url ".")
170 (add-hook 'eww-mode-hook 224 (add-hook 'eww-mode-hook
@@ -181,7 +235,12 @@ This function only tests URL's domain."
181 browse-url-secondary-browser-function 235 browse-url-secondary-browser-function
182 (or url (plist-get eww-data :url))) 236 (or url (plist-get eww-data :url)))
183 (:success (when (null url) (quit-window))) ; Interactive use 237 (:success (when (null url) (quit-window))) ; Interactive use
184 (t (signal (car e) (cdr e))))))) 238 (t (signal (car e) (cdr e))))))
239 (add-hook 'eww-mode-hook #'bookmark-eww--setup)
240 (define-key eww-mode-map "b" #'bookmark-set)
241 (define-key eww-mode-map "B" #'bookmark-jump)
242 (define-key eww-mode-map (kbd "M-n") nil)
243 (define-key eww-mode-map (kbd "M-p") nil))
185 244
186(use-package browse-url 245(use-package browse-url
187 :demand t 246 :demand t
@@ -204,7 +263,8 @@ This function only tests URL's domain."
204 . +browse-url-with-mpv) 263 . +browse-url-with-mpv)
205 ;; Images 264 ;; Images
206 (,(+browse-url-matches "pbs\\.twimg\\.com" 265 (,(+browse-url-matches "pbs\\.twimg\\.com"
207 (rx "." (or "jpeg" "jpg" "png" "bmp" "webp") 266 (rx "." (or "jpeg" "jpg" "png" "pn"
267 "bmp" "webp")
208 eos)) 268 eos))
209 . +browse-url-with-mpv-image) 269 . +browse-url-with-mpv-image)
210 ;; Blobs 270 ;; Blobs
@@ -214,16 +274,18 @@ This function only tests URL's domain."
214 (+browse-url-external-url-p 274 (+browse-url-external-url-p
215 . ,browse-url-secondary-browser-function)) 275 . ,browse-url-secondary-browser-function))
216 ;; External domains 276 ;; External domains
217 +browse-url-external-domains '("github.com" "gitlab.com" "codeberg.org" 277 ;; +browse-url-external-domains
218 "tildegit.org" "git.tilde.town" 278 ;; '("github.com" "gitlab.com" "codeberg.org"
219 "google.com" "imgur.com" "twitch.tv" 279 ;; "tildegit.org" "git.tilde.town"
220 "pixelfed" "instagram.com" 280 ;; "google.com" "imgur.com" "twitch.tv"
221 "bibliogram.art" "reddit.com" 281 ;; "pixelfed" "instagram.com"
222 "teddit.net" "libreddit.de" 282 ;; "bibliogram.art" "reddit.com"
223 "streamable.com" "spotify.com" 283 ;; "teddit.net" "libreddit.de"
224 "hetzner.cloud" "melpa.org" 284 ;; "streamable.com" "spotify.com"
225 "twitter.com" ("^t\\.co$") 285 ;; "hetzner.cloud" "melpa.org"
226 "nitter.snopyta.org" "nitter.net")) 286 ;; "twitter.com" ("^t\\.co$")
287 ;; "nitter.snopyta.org" "nitter.net")
288 )
227 ;; External browsers: firefox > chromium > chrome 289 ;; External browsers: firefox > chromium > chrome
228 (when-let ((firefox (choose-executable "firefox" 290 (when-let ((firefox (choose-executable "firefox"
229 "firefox-esr"))) 291 "firefox-esr")))
@@ -268,14 +330,16 @@ This function only tests URL's domain."
268 :bind 330 :bind
269 (("M-l M-l" . +link-hint-open-link) 331 (("M-l M-l" . +link-hint-open-link)
270 ("M-l l" . +link-hint-open-link) 332 ("M-l l" . +link-hint-open-link)
271 ("M-l M-o" . +link-hint-open-secondary) 333 ("M-l M-o" . +link-hint-open:secondary)
272 ("M-l o" . +link-hint-open-secondary) 334 ("M-l o" . +link-hint-open:secondary)
273 ("M-l M-m" . +link-hint-open-multiple-links) 335 ("M-l M-m" . +link-hint-open-multiple-links)
274 ("M-l m" . +link-hint-open-multiple-links) 336 ("M-l m" . +link-hint-open-multiple-links)
275 ("M-l M-w" . link-hint-copy-link) 337 ("M-l M-w" . link-hint-copy-link)
276 ("M-l w" . link-hint-copy-link) 338 ("M-l w" . link-hint-copy-link)
277 ("M-l M-c" . +link-hint-open-chrome) 339 ("M-l M-c" . +link-hint-open:chrome)
278 ("M-l c" . +link-hint-open-chrome)) 340 ("M-l c" . +link-hint-open:chrome)
341 ("M-l M-d" . +link-hint-open:download)
342 ("M-l d" . +link-hint-open:download))
279 :config 343 :config
280 (require '+link-hint) 344 (require '+link-hint)
281 (setopt link-hint-avy-style 'at-full 345 (setopt link-hint-avy-style 'at-full
@@ -286,8 +350,9 @@ This function only tests URL's domain."
286 ;; another package's configuration, but I don't care enough to fix it. 350 ;; another package's configuration, but I don't care enough to fix it.
287 (setq link-hint-types 351 (setq link-hint-types
288 (delq 'link-hint-completion-list-candidate link-hint-types)) 352 (delq 'link-hint-completion-list-candidate link-hint-types))
289 (+link-hint-open-secondary-setup) 353 ;; (+link-hint-open-secondary-setup)
290 (+link-hint-open-chrome-setup)) 354 ;; (+link-hint-open-chrome-setup)
355 )
291 356
292(provide 'acdw-web) 357(provide 'acdw-web)
293;;; acdw-web.el ends here 358;;; acdw-web.el ends here