summaryrefslogtreecommitdiff
path: root/.config/emacs/modules/bd--browse.el
diff options
context:
space:
mode:
Diffstat (limited to '.config/emacs/modules/bd--browse.el')
-rw-r--r--.config/emacs/modules/bd--browse.el87
1 files changed, 35 insertions, 52 deletions
diff --git a/.config/emacs/modules/bd--browse.el b/.config/emacs/modules/bd--browse.el
index 3ba024a..1d97760 100644
--- a/.config/emacs/modules/bd--browse.el
+++ b/.config/emacs/modules/bd--browse.el
@@ -2,65 +2,48 @@
;;; Commentary:
;;; Code:
+(require 'selector)
+(require 'dash)
(require 'fill-column)
-(require 'transient)
(defconst bd/bookmarks nil)
-(defconst bd/browse-engine-list
- '(("ddg" . ("https://www.duckduckgo.com/?q=" 3))
- ("web" . ("" 3))
- ("wkpa" . ("https://en.wikipedia.org/w/index.php?search=" 3))
- ("inv" . ("https://yewtu.be/search?q=" 0))
- ("ud" . ("https://www.urbandictionary.com/define.php?term=" 2))
- ("arch" . ("https://wiki.archlinux.org/index.php?title=Special%3ASearch&search=" 2))))
+(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)))))
-(defun bd/browse--engine-candidates ()
- (mapcar #'car bd/browse-engine-list))
+(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/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)
-
-(transient-define-argument bd/browse--engines ()
- "Toggles which search engine to use."
- :description "engine"
- :key "C-n"
- :class 'transient-option
- :unsavable t
- :allow-empty nil
- :always-read t
- :argument "candidate="
- :init-value (lambda (obj) (oset obj value (car (bd/browse--engine-candidates))))
- :choices (bd/browse--engine-candidates))
+(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=" 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))))
-(transient-define-suffix bd/browse--search (i)
- :description "search"
- :key "s"
- (interactive "sstring: ")
- (let ((engine (cdr (assoc (transient-arg-value "candidate=" (transient-args 'bd/browse-dispatcher))
- bd/browse-engine-list))))
- (browse-url (concat (car engine) i) (cadr engine))))
-
-(transient-define-suffix bd/browse--bookmark ()
- :description "bookmarks"
- :key "b"
+(defun bd/browse-dispatcher ()
+ "Select and `browse-url' a bookmark."
(interactive)
- (let ((choice (completing-read "goto: " (mapcar #'car bd/bookmarks))))
- (apply #'bd/browse (cdr (assoc choice bd/bookmarks)))))
-
-(transient-define-prefix bd/browse-dispatcher ()
- ["Dispatcher > Browse\n"
- [(bd/browse--engines)
- ""
- (bd/browse--search)
- (bd/browse--bookmark)]])
+ (unwind-protect
+ (selector
+ (list (bd/selector-bookmarks)
+ (bd/selector-search)))))
(defun rip (url)
"Play URL (or search string) in mpv."