;;; -*- lexical-binding: t; -*- ;;; Commentary: ;;; Code: (require 'selector) (require 'dash) (require 'fill-column) (defun bd/browse (url &optional pref &rest _) "Given PREF, launches URL in one of librewolf, torbrowser, icecat, or eww." (interactive) (pcase pref (0 (eww url)) (1 (start-process "torbrowser" nil "torbrowser" "--new-window" url)) (2 (start-process "icecat" nil "icecat" "--new-window" url)) (_ (start-process "librewolf" nil "librewolf" "--new-window" url)))) (setopt browse-url-browser-function 'bd/browse) (defun bd/selector-bookmarks () "Selector source for all bookmarks." (selector-source-create "Bookmarks" :candidates (-map (lambda (b) (selector-candidate-create (car b) :value (cdr b))) bd/bookmarks) :actions (list (lambda (x) (apply #'bd/browse x))))) (defmacro bd/search-candidate (name url pref) "Syntax for a search candidate given NAME, URL, and PREF." `(selector-candidate-create ,(concat "Search " name) :type 'dummy :action (lambda (_) (browse-url (concat ,url (selector-input)) ,pref)))) (defun bd/selector-search () "Selector source for all search engines." (selector-source-create "Browser" :candidates (list (bd/search-candidate "DuckDuckGo" "https://www.duckduckgo.com/?q=-site:\"reddit.com\" " 3) (bd/search-candidate "Wikipedia" "https://en.wikipedia.org/w/index.php?search=" 3) (bd/search-candidate "Invidious" "https://yewtu.be/search?q=" 0) (bd/search-candidate "Urban Dictionary" "https://www.urbandictionary.com/define.php?term=" 2) (bd/search-candidate "Archwiki" "https://wiki.archlinux.org/index.php?title=Special%3ASearch&search=" 2) (bd/search-candidate "Web" "" 3)))) (defun bd/browse-dispatcher () "Select and `browse-url' a bookmark." (interactive) (unwind-protect (selector (list (bd/selector-bookmarks) (bd/selector-search))))) (defun rip (url) "Play URL (or search string) in mpv." (interactive "sURL or search string: ") (message "Ludu %s" url) (start-process "rip" nil "mpv" "--force-window=yes" (concat (if (string-match "https://.*" url) "ytdl://" "ytdl://ytsearch:") url))) (setopt browse-url-handlers `((,(regexp-opt '("youtube.com" "youtu.be" "vid.puffyan.us" "deezer.page")) . (lambda (url &rest _) (rip url)))) url-privacy-level '(email os emacs lastloc cookies)) (use-package shr :defer t :config (setopt shr-use-fonts t shr-cookie-policy nil shr-max-width 85)) (use-package elpher :bind (:map elpher-mode-map ("l" . #'elpher-back) ("d" . #'elpher-download) ("w" . #'elpher-copy-current-url) ("A" . #'elpher-copy-link-url) ("E" . #'elpher-bookmark-current) ("TAB" . #'elpher-next-link) ("g" . #'elpher-reload) ("G" . #'elpher-go)) :config (defun bd/elpher (original url &optional new-window) "Handle gemini links." (cond ((string-match-p "\\`\\(gemini\\|gopher\\)://" url) (elpher-go url)) (t (funcall original url new-window)))) (advice-add 'eww :around 'bd/elpher) (setopt elpher-default-url-type "gemini" elpher-connection-timeout 120 elpher-gemini-max-fill-width 85 elpher-use-emacs-bookmark-menu t)) (use-package eww :hook ((eww-after-render . (lambda () (setq-local fill-column-desired-width 90) (fill-column-mode)))) :config (setopt eww-search-prefix "https://duckduckgo.com/html/?q=" eww-auto-rename-buffer 'title eww-use-browse-url (regexp-opt '("mailto:" "youtube.com" "youtu.be")))) (provide 'bd--browse) ;;; bd--browse.el ends here