From 2d2cab9d97d3e84e5b7158181523fe2c5bbffe85 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 16 Apr 2023 17:06:41 -0500 Subject: uhhh --- lisp/acdw-web.el | 101 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 83 insertions(+), 18 deletions(-) (limited to 'lisp/acdw-web.el') 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." (list :tag "Regexp" regexp) (string :tag "Literal string")))) +(with-eval-after-load 'custom-allowed + (add-to-list 'custom-allowed-variables '+browse-url-external-domains)) + (defun +browse-url-external-url-p (url) "Return t if URL is a member of `+browse-url-external-domains'. This function only tests URL's domain." @@ -125,6 +128,29 @@ This function only tests URL's domain." host) return t))) +(defun +browse-url-external-domain-add (domain &optional regexp?) + "Add DOMAIN to `+browse-url-external-domains'. +If REGEXP? is non-nil, it will note that the domain is a regexp. +This function will also save `custom-file' with the updated value." + (interactive (pcase current-prefix-arg + (`nil + (list (read-from-minibuffer "Domain: ") + nil)) + (`(4) + (list (read-from-minibuffer "Domain regex: ") + t)) + (_ + (list (read-from-minibuffer "Domain: ") + (y-or-n-p "Regex? "))))) + (let ((new (funcall (if regexp? #'list #'identity) + domain))) + (custom-set-variables + `(+browse-url-external-domains + ',(add-to-list '+browse-url-external-domains new))) + (with-current-buffer (find-file-noselect custom-file) + (custom-save-variables)) + (message "%s added to `+browse-url-external-domains'." + domain))) ;;; Downloading @@ -165,6 +191,34 @@ This function only tests URL's domain." ;;; Packages (use-package eww + :preface + (defun bookmark-eww--make () + "Make eww bookmark record." + `((filename . ,(plist-get eww-data :url)) + (title . ,(plist-get eww-data :title)) + (time . ,(current-time-string)) + (handler . ,#'bookmark-eww-handler) + (defaults . (,(concat + ;; url without the https and path + (replace-regexp-in-string + "/.*" "" + (replace-regexp-in-string + "\\`https?://" "" + (plist-get eww-data :url))) + " - " + ;; page title + (replace-regexp-in-string + "\\` +\\| +\\'" "" + (replace-regexp-in-string + "[\n\t\r ]+" " " + (plist-get eww-data :title)))))))) + (defun bookmark-eww-handler (bm) + "Handler for eww bookmarks." + (eww-browse-url (alist-get 'filename bm))) + (defun bookmark-eww--setup () + "Setup eww bookmark integration." + (setq-local bookmark-make-record-function #'bookmark-eww--make)) + :commands (eww eww-browse-url) :config (setopt eww-use-browse-url ".") (add-hook 'eww-mode-hook @@ -181,7 +235,12 @@ This function only tests URL's domain." browse-url-secondary-browser-function (or url (plist-get eww-data :url))) (:success (when (null url) (quit-window))) ; Interactive use - (t (signal (car e) (cdr e))))))) + (t (signal (car e) (cdr e)))))) + (add-hook 'eww-mode-hook #'bookmark-eww--setup) + (define-key eww-mode-map "b" #'bookmark-set) + (define-key eww-mode-map "B" #'bookmark-jump) + (define-key eww-mode-map (kbd "M-n") nil) + (define-key eww-mode-map (kbd "M-p") nil)) (use-package browse-url :demand t @@ -204,7 +263,8 @@ This function only tests URL's domain." . +browse-url-with-mpv) ;; Images (,(+browse-url-matches "pbs\\.twimg\\.com" - (rx "." (or "jpeg" "jpg" "png" "bmp" "webp") + (rx "." (or "jpeg" "jpg" "png" "pn" + "bmp" "webp") eos)) . +browse-url-with-mpv-image) ;; Blobs @@ -214,16 +274,18 @@ This function only tests URL's domain." (+browse-url-external-url-p . ,browse-url-secondary-browser-function)) ;; External domains - +browse-url-external-domains '("github.com" "gitlab.com" "codeberg.org" - "tildegit.org" "git.tilde.town" - "google.com" "imgur.com" "twitch.tv" - "pixelfed" "instagram.com" - "bibliogram.art" "reddit.com" - "teddit.net" "libreddit.de" - "streamable.com" "spotify.com" - "hetzner.cloud" "melpa.org" - "twitter.com" ("^t\\.co$") - "nitter.snopyta.org" "nitter.net")) + ;; +browse-url-external-domains + ;; '("github.com" "gitlab.com" "codeberg.org" + ;; "tildegit.org" "git.tilde.town" + ;; "google.com" "imgur.com" "twitch.tv" + ;; "pixelfed" "instagram.com" + ;; "bibliogram.art" "reddit.com" + ;; "teddit.net" "libreddit.de" + ;; "streamable.com" "spotify.com" + ;; "hetzner.cloud" "melpa.org" + ;; "twitter.com" ("^t\\.co$") + ;; "nitter.snopyta.org" "nitter.net") + ) ;; External browsers: firefox > chromium > chrome (when-let ((firefox (choose-executable "firefox" "firefox-esr"))) @@ -268,14 +330,16 @@ This function only tests URL's domain." :bind (("M-l M-l" . +link-hint-open-link) ("M-l l" . +link-hint-open-link) - ("M-l M-o" . +link-hint-open-secondary) - ("M-l o" . +link-hint-open-secondary) + ("M-l M-o" . +link-hint-open:secondary) + ("M-l o" . +link-hint-open:secondary) ("M-l M-m" . +link-hint-open-multiple-links) ("M-l m" . +link-hint-open-multiple-links) ("M-l M-w" . link-hint-copy-link) ("M-l w" . link-hint-copy-link) - ("M-l M-c" . +link-hint-open-chrome) - ("M-l c" . +link-hint-open-chrome)) + ("M-l M-c" . +link-hint-open:chrome) + ("M-l c" . +link-hint-open:chrome) + ("M-l M-d" . +link-hint-open:download) + ("M-l d" . +link-hint-open:download)) :config (require '+link-hint) (setopt link-hint-avy-style 'at-full @@ -286,8 +350,9 @@ This function only tests URL's domain." ;; another package's configuration, but I don't care enough to fix it. (setq link-hint-types (delq 'link-hint-completion-list-candidate link-hint-types)) - (+link-hint-open-secondary-setup) - (+link-hint-open-chrome-setup)) + ;; (+link-hint-open-secondary-setup) + ;; (+link-hint-open-chrome-setup) + ) (provide 'acdw-web) ;;; acdw-web.el ends here -- cgit 1.4.1-21-gabe81