summary refs log tree commit diff stats
path: root/init.el
diff options
context:
space:
mode:
Diffstat (limited to 'init.el')
-rw-r--r--init.el75
1 files changed, 75 insertions, 0 deletions
diff --git a/init.el b/init.el index f7dcd7e..0bd11d4 100644 --- a/init.el +++ b/init.el
@@ -17,6 +17,7 @@
17 read-file-name-completion-ignore-case t 17 read-file-name-completion-ignore-case t
18 comment-auto-fill-only-comments t 18 comment-auto-fill-only-comments t
19 password-cache t 19 password-cache t
20 eww-use-browse-url "." ; use `browse-url' in every link
20 password-cache-expiry (* 60 60) 21 password-cache-expiry (* 60 60)
21 initial-buffer-choice (defun +initial-buffer-choose () 22 initial-buffer-choice (defun +initial-buffer-choose ()
22 (cond 23 (cond
@@ -904,3 +905,77 @@ CAPES defaults to `+capes'. CAPF will be made un-exclusive."
904 (spinner "https://github.com/Malabarba/spinner.el") 905 (spinner "https://github.com/Malabarba/spinner.el")
905 (sesman "https://github.com/vspinu/sesman")) 906 (sesman "https://github.com/vspinu/sesman"))
906 :when (executable-find "clojure")) 907 :when (executable-find "clojure"))
908
909(yoke browse-url
910 (require '+browse-url)
911 (setf browse-url-browser-function #'eww-browse-url
912 browse-url-chrome-program (seq-some #'executable-find
913 '("chromium" "chrome" "google-chrome-stable"))
914 browse-url-firefox-program (seq-some #'executable-find
915 '("firefox" "firefox-esr"))
916 browse-url-generic-program (or browse-url-firefox-program
917 browse-url-chrome-program)
918 browse-url-firefox-new-window-is-tab t
919 browse-url-firefox-arguments "-new-tab"
920 browse-url-handlers `((video-url-p . +browse-url-with-mpv)
921 (music-url-p . +browse-url-with-mpv)
922 (image-url-p . +browse-image-with-mpv)
923 (blobp . +browse-url-download)
924 (external-url-p . ,browse-url-secondary-browser-function)))
925 (+browse-url-make-external-viewer-handler "mpv" '("--cache-pause-wait=30"
926 "--cache-pause-initial=yes")
927 "Video URL: "
928 :fallback browse-url-secondary-browser-function)
929 (+browse-url-make-external-viewer-handler "mpv" '("--image-display-duration=inf")
930 "Image URL: "
931 :name +browse-image-with-mpv)
932 (defun video-url-p (url) "Is URL a video?"
933 (string-match-p (rx (or "youtube.com" "youtu.be" "invidious" "yewtu.be"
934 (seq "." (or "mp4" "gif" "mov" "MOV" "webm") eos)))
935 url))
936 (defun music-url-p (url) "Is URL music?"
937 (string-match-p (rx "soundcloud.com" "bandcamp.com"
938 (seq "." (or "ogg" "mp3" "opus" "m4a") eos))
939 url))
940 (defun image-url-p (url) "Is URL an image?"
941 (string-match-p (rx "." (or "jpeg" "jpg" "png" "bmp" "webp") eos)
942 url))
943 (defun external-url-p (url) "Should URL open in an external browser?"
944 (string-match-p (rx (or "github.com" "gitlab.com" "codeberg.org"
945 "tildegit.org" "git.tilde.town" "google.com"
946 "imgur.com" "twitch.tv" "pixelfed" "instagram.com"
947 "bibliogram.art" "reddit.com" "teddit.net"
948 "twitter.com" "nitter" "t.co"
949 "streamable.com" "spotify.com"
950 "hetzner.cloud" "melpa.org"))
951 url))
952 (defun blobp (url) "Is URL some other blob that can't open in Emacs?"
953 (string-match-p (rx (or (: (or ".tar.gz" ".pdf")
954 eos)))
955 url))
956 (eval-after chd
957 (add-to-list 'browse-url-handlers (cons chd/url-regexps #'browse-url-chrome)))
958 (require 'browse-url-transform)
959 (setf browse-url-transform-alist `(("twitter\\.com" . "nitter.net")
960 ("\\(?:\\(?:old\\.\\)?reddit\\.com\\)"
961 . "libreddit.de")
962 ("medium\\.com" . "scribe.rip")
963 ("www\\.npr\\.org" . "text.npr.org")))
964 (browse-url-transform-mode))
965
966(yoke eww
967 (defun +eww-browse-with-external-browser (&optional url)
968 "Browse URL with an external browser and close eww."
969 (interactive nil eww-mode)
970 (condition-case e
971 ;; This is wrapped in a `condition-case' so that the eww window won't
972 ;; close if there's an error calling the browser.
973 (funcall browse-url-secondary-browser-function
974 (or url (plist-get eww-data :url)))
975 (:success
976 (when (null url) ; interactive
977 (quit-window)))
978 (t (signal (car e) (cdr e)))))
979 (define-key* eww-mode-map
980 "&" #'+eww-browse-with-external-browser))
981