diff options
Diffstat (limited to '.config/emacs/modules/bd--browse.el')
-rw-r--r-- | .config/emacs/modules/bd--browse.el | 58 |
1 files changed, 54 insertions, 4 deletions
diff --git a/.config/emacs/modules/bd--browse.el b/.config/emacs/modules/bd--browse.el index 1dd5b4a..83bf0a2 100644 --- a/.config/emacs/modules/bd--browse.el +++ b/.config/emacs/modules/bd--browse.el @@ -2,10 +2,60 @@ ;;; Commentary: ;;; Code: +(require 'selector) +(require 'dash) -;; do not use an external browser -(setopt browse-url-browser-function 'eww-browse-url - shr-use-fonts t +(defvar bd/bookmarks nil) ;; in secret file +;;;; searching +(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 "icecat" nil "icecat" "--new-window" url)) + (2 (start-process "torbrowser" nil "torbrowser" "--new-window" url)) + (_ (start-process "librewolf" nil "librewolf" "--new-window" url)))) +(setopt browse-url-browser-function 'bd/browse) + +(defun bd/selector-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) + `(selector-candidate-create + ,(concat "Search " name) + :type 'dummy + :action (lambda (_) (browse-url (concat ,url (selector-input)) ,pref)))) + +(defun bd/selector-search () + (selector-source-create + "Browser" + :candidates + (list (bd/search-candidate "DuckDuckGo" "https://www.duckduckgo.com/?q=" 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=" 1) + (bd/search-candidate "Archwiki" "https://wiki.archlinux.org/index.php?title=Special%3ASearch&search=" 1) + (bd/search-candidate "Web" "" 3)))) + +(defun bd/visit-bookmark () + "Select and `browse-url' a bookmark." + (interactive) + (unwind-protect + (selector + (list (bd/selector-bookmarks) + (bd/selector-search))))) + + +;;;; eww +(setopt shr-use-fonts t shr-cookie-policy nil shr-max-width 85 ;; send only user agent @@ -16,7 +66,7 @@ "youtube.com" "youtu.be")) browse-url-handlers - `((,(regexp-opt'("youtube.com" "youtu.be")) . + `((,(regexp-opt '("youtube.com" "youtu.be")) . (lambda (url &rest _) (message "Ludu %s" url) (start-process-shell-command "rip-video" nil (concat "rip-video " url)))))) |