summaryrefslogtreecommitdiff
path: root/.config/emacs
diff options
context:
space:
mode:
Diffstat (limited to '.config/emacs')
-rw-r--r--.config/emacs/modules/bd--browse.el87
-rw-r--r--.config/emacs/modules/bd--devel.el2
-rw-r--r--.config/emacs/modules/bd--minibuffer.el101
3 files changed, 137 insertions, 53 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."
diff --git a/.config/emacs/modules/bd--devel.el b/.config/emacs/modules/bd--devel.el
index 78d8985..75466f9 100644
--- a/.config/emacs/modules/bd--devel.el
+++ b/.config/emacs/modules/bd--devel.el
@@ -60,7 +60,7 @@
(display-buffer-in-side-window)
(side . bottom)
(slot . -1)
- (width . 0.2)))
+ (width . 0.15)))
(keymap-set prog-mode-map
"C-," #'(lambda ()
diff --git a/.config/emacs/modules/bd--minibuffer.el b/.config/emacs/modules/bd--minibuffer.el
index 4a928e3..bca9985 100644
--- a/.config/emacs/modules/bd--minibuffer.el
+++ b/.config/emacs/modules/bd--minibuffer.el
@@ -25,6 +25,107 @@
completions-max-height '30)
(icomplete-vertical-mode t))
+(use-package selector
+ :demand t
+ :config
+ (defvar bd/navigate-recent-display-number 6
+ "The number of recent buffers that show up in bd/navigate.")
+ (defvar bd/blacklisted-buffer-regexp-list
+ '(
+ "\\*Async Shell Command\\*"
+ "\\*http"
+ "\\magit-process"
+ "\\*Minibuf"
+ "\\*Echo Area"
+ "\\*newsticker"
+ "\\*Org Preview LaTeX Output\\*"
+ "\\*Shell Command Output\\*"
+ "\\*tramp"
+ "\\*eldoc"
+ "\\*server\\*"
+ )
+ "Buffers that should not show up in buffer-related
+selection commands.")
+
+ (defun bd/buffer-blacklisted-p (buf)
+ "Return non-nil if BUF is blacklisted."
+ (cl-reduce (lambda (x y) (or x y)) (mapcar (lambda (r) (string-match r buf))
+ bd/blacklisted-buffer-regexp-list)))
+
+ (defun bd/buffer-list ()
+ "Return a list of non-blacklisted buffers."
+ (cl-remove-if #'bd/buffer-blacklisted-p (mapcar 'buffer-name (buffer-list))))
+
+ (defun bd/selector-recent-buffers ()
+ (selector-source-create
+ "Recent"
+ :candidates
+ (take bd/navigate-recent-display-number
+ (cl-remove-if (lambda (b)
+ (get-buffer-window b 'visible))
+ (bd/buffer-list)))
+ :actions
+ selector-buffer-actions))
+
+ (defun bd/selector-project-files ()
+ (selector-source-create
+ "Project Files"
+ :candidates
+ (let ((proj (project-current)))
+ (when proj
+ (project-files proj)))
+ :actions
+ selector-file-actions))
+
+ (defmacro bd/selector-buffer-type (name c)
+ `(selector-source-create
+ ,name
+ :candidates
+ (cl-remove-if-not ,c (bd/buffer-list))
+ :actions
+ selector-buffer-actions))
+
+ (defun bd/navigate ()
+ (interactive)
+ (selector
+ (list
+ (bd/selector-recent-buffers)
+ (bd/selector-buffer-type "EXWM" #'bd/buffer-exwm-p)
+ (bd/selector-buffer-type "Text" #'bd/buffer-text-p)
+ (bd/selector-buffer-type "Source" #'bd/buffer-prog-p)
+ (bd/selector-buffer-type "Scratch" #'bd/buffer-scratch-p)
+ (bd/selector-buffer-type "Directories" #'bd/buffer-dired-p)
+ (bd/selector-buffer-type "IRC" #'bd/buffer-irc-p)
+ (bd/selector-buffer-type "Ordinary" #'bd/buffer-ordinary-p)
+ (bd/selector-project-files)
+ (selector-recentf-source))))
+ (keymap-global-set "C-x b" 'bd/navigate)
+
+ (defun bd/selector-rg ()
+ "Sources for lines found via grep (or a clone)."
+ (interactive)
+ (let ((query (read-string "rg: ")))
+ (defun conv (x)
+ (cons (car x) (cons (- (string-to-number (cadr x)) 1) (caddr x))))
+ (defun all-in-file (key list)
+ (--map (to-candidate (cdr it)) (--filter (s-equals? key (car it)) list)))
+ (defun to-candidate (x)
+ (selector-candidate-create (cdr x) :value (car x)))
+ (let* ((dir (expand-file-name (bd/get-directory-dwim)))
+ (result (with-temp-buffer
+ (call-process "rg" nil t nil "-n" "-." query dir)
+ (buffer-string)))
+ (lines (--map (conv (s-split-up-to ":" it 2)) (--filter (not (s-blank? it)) (s-split "\n" result))))
+ (files (-uniq (-map #'car lines)))
+ (sources (--map (selector-source-create
+ it
+ :candidates (all-in-file it lines)
+ :actions (selector-file-contents-actions it))
+ files)))
+ (when (not (null sources))
+ (selector sources)))))
+ (keymap-global-set "C-z s" 'bd/selector-rg))
+
(defun bd/selector-rg ()
"Sources for lines found via grep (or a clone)."
(interactive)