From 349760402b26534bed22fe593da5a061404f2ddc Mon Sep 17 00:00:00 2001 From: bd Date: Wed, 25 Dec 2024 00:36:49 -0700 Subject: better icomplete defaults, use icomplete for passwords, bookmarks --- .config/emacs/init.el | 1 + .config/emacs/libraries/selector.el | 2 +- .config/emacs/modules/bd--browse.el | 83 +++++++++++--------- .config/emacs/modules/bd--devel.el | 6 +- .config/emacs/modules/bd--exwm-windowing.el | 116 ++++++++++++++-------------- .config/emacs/modules/bd--gpg.el | 13 +--- .config/emacs/modules/bd--minibuffer.el | 35 +++++---- .config/emacs/modules/bd--notes.el | 23 +++--- .config/emacs/modules/bd--utility.el | 22 +++--- 9 files changed, 158 insertions(+), 143 deletions(-) (limited to '.config/emacs') diff --git a/.config/emacs/init.el b/.config/emacs/init.el index d51a47a..bf36a12 100644 --- a/.config/emacs/init.el +++ b/.config/emacs/init.el @@ -77,6 +77,7 @@ (setopt package-archives nil package-enable-at-startup t) (add-to-list 'load-path (expand-file-name "~/.guix-home/profile/share/emacs/site-lisp")) + (require 'guix-autoloads) (guix-prettify-global-mode 1) diff --git a/.config/emacs/libraries/selector.el b/.config/emacs/libraries/selector.el index 64b397c..152b2c1 100644 --- a/.config/emacs/libraries/selector.el +++ b/.config/emacs/libraries/selector.el @@ -653,4 +653,4 @@ meaning as in `read-file-name'." (provide 'selector) -;;; selector ends here +;;; selector.el ends here diff --git a/.config/emacs/modules/bd--browse.el b/.config/emacs/modules/bd--browse.el index d6a09e4..fceccc3 100644 --- a/.config/emacs/modules/bd--browse.el +++ b/.config/emacs/modules/bd--browse.el @@ -2,11 +2,21 @@ ;;; Commentary: ;;; Code: -(require 'selector) -(require 'dash) (require 'fill-column) -(defvar bd/bookmarks nil) ;; in secret file -;;;; searching +(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/browse--engine-candidates () + (mapcar #'car bd/browse-engine-list)) + (defun bd/browse (url &optional pref &rest _) "Given PREF, launches URL in one of librewolf, torbrowser, icecat, or eww." @@ -18,40 +28,39 @@ icecat, or eww." (_ (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=" 2) - (bd/search-candidate "Archwiki" "https://wiki.archlinux.org/index.php?title=Special%3ASearch&search=" 2) - (bd/search-candidate "Web" "" 3)))) - -(defun bd/visit-bookmark () - "Select and `browse-url' a bookmark." +(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)) + +(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" (interactive) - (unwind-protect - (selector - (list (bd/selector-bookmarks) - (bd/selector-search))))) + (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)]]) (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 96f5bb1..37762ea 100644 --- a/.config/emacs/modules/bd--devel.el +++ b/.config/emacs/modules/bd--devel.el @@ -80,7 +80,7 @@ ("C-c f n" . #'flymake-goto-next-error) ("C-c f p" . #'flymake-goto-prev-error) ("C-c f b" . #'flymake-show-buffer-diagnostics) - ("C-c f p" . #'flymake-show-project-diagnostics)) + ("C-c f d" . #'flymake-show-project-diagnostics)) :config (setopt flymake-no-changes-timeout nil flymake-start-on-flymake-mode t @@ -116,15 +116,17 @@ :hook (ielm-mode emacs-lisp-mode eshell-mode + geiser-repl-mode lisp-mode scheme-mode lisp-interaction-mode) :config (defun bd/paredit-preserve-repl (f &rest args) - "Wrapper around F (paredit-RET, discarding ARGS." + "Wrapper around F (paredit-RET), discarding ARGS." (pcase (cons major-mode (eolp)) ('(inferior-emacs-lisp-mode . t) (ielm-return)) ('(eshell-mode . t) (eshell-send-input)) + ('(geiser-repl-mode . t) (geiser-repl-maybe-send)) (_ (funcall f)))) (advice-add #'paredit-RET :around #'bd/paredit-preserve-repl) (eldoc-add-command diff --git a/.config/emacs/modules/bd--exwm-windowing.el b/.config/emacs/modules/bd--exwm-windowing.el index 320fd3d..aee83cf 100644 --- a/.config/emacs/modules/bd--exwm-windowing.el +++ b/.config/emacs/modules/bd--exwm-windowing.el @@ -17,65 +17,65 @@ that buffer." (define-key exwm-mode-map [?\C-q] 'exwm-input-send-next-key) (exwm-enable) (setopt exwm-replace nil - exwm-input-prefix-keys - `(?\C-x - ?\C-u - ?\C-g - ?\C-h - ?\C-z - ?\C-` - ?\M-x - ?\M-` - ?\M-& - ?\M-: - ,@(mapcar (lambda (i) - (kbd (concat "s-" (number-to-string i)))) - (number-sequence 0 9))) + exwm-input-prefix-keys + `(?\C-x + ?\C-u + ?\C-g + ?\C-h + ?\C-z + ?\C-` + ?\M-x + ?\M-` + ?\M-& + ?\M-: + ,@(mapcar (lambda (i) + (kbd (concat "s-" (number-to-string i)))) + (number-sequence 0 9))) - exwm-input-global-keys - '(([?\s-n] . other-window) - ([?\s-p] . (lambda () - (interactive) - (other-window -1))) - ([?\s-L] . bd/lock) - ([f2] . bd/toggle-mute) - ([f5] . bd/decrement-volume) - ([f6] . bd/increment-volume) - ([f7] . bd/decrement-brightness) - ([f8] . bd/increment-brightness) - ([f9] . emms-previous) - ([f10] . emms-next) - ([print] . bd/shoot-part) - ([S-print] . bd/shoot-full) - ([?\s-O] . bd/visit-bookmark) - ([?\s-P] . bd/password) - ([?\s-r] . exwm-reset) - ([?\s-d] . toggle-window-dedicated) - ([?\s-q] . kill-current-buffer) - ([?\s-x] . (lambda (command) - (interactive (list (read-shell-command "s-x "))) - (start-process-shell-command command nil command)))) + exwm-input-global-keys + '(([?\s-n] . other-window) + ([?\s-p] . (lambda () + (interactive) + (other-window -1))) + ([?\s-L] . bd/lock) + ([f2] . bd/toggle-mute) + ([f5] . bd/decrement-volume) + ([f6] . bd/increment-volume) + ([f7] . bd/decrement-brightness) + ([f8] . bd/increment-brightness) + ([f9] . emms-previous) + ([f10] . emms-next) + ([print] . bd/shoot-part) + ([S-print] . bd/shoot-full) + ([?\s-O] . bd/browse-dispatcher) + ([?\s-P] . bd/password) + ([?\s-r] . exwm-reset) + ([?\s-d] . toggle-window-dedicated) + ([?\s-q] . kill-current-buffer) + ([?\s-x] . (lambda (command) + (interactive (list (read-shell-command "s-x "))) + (start-process-shell-command command nil command)))) - exwm-input-simulation-keys - '(([?\C-b] . [left]) - ([?\C-f] . [right]) - ([?\C-p] . [up]) - ([?\C-n] . [down]) - ([?\C-a] . [home]) - ([?\C-e] . [end]) - ([?\M-v] . [prior]) - ([?\C-v] . [next]) - ([?\C-d] . [delete]) - ([?\C-k] . [S-end delete]) - ([?\M-w] . [C-c]) - ([?\C-y] . [C-v]) - ([?\C-s] . [C-g]) - ([?\C-r] . [C-S-g]) - ([?\M-d] . [C-delete]) - ([?\M-b] . [C-left]) - ([?\M-f] . [C-right]) - ([?\H-b] . [M-left]) - ([?\H-f] . [M-right])))) + exwm-input-simulation-keys + '(([?\C-b] . [left]) + ([?\C-f] . [right]) + ([?\C-p] . [up]) + ([?\C-n] . [down]) + ([?\C-a] . [home]) + ([?\C-e] . [end]) + ([?\M-v] . [prior]) + ([?\C-v] . [next]) + ([?\C-d] . [delete]) + ([?\C-k] . [S-end delete]) + ([?\M-w] . [C-c]) + ([?\C-y] . [C-v]) + ([?\C-s] . [C-g]) + ([?\C-r] . [C-S-g]) + ([?\M-d] . [C-delete]) + ([?\M-b] . [C-left]) + ([?\M-f] . [C-right]) + ([?\H-b] . [M-left]) + ([?\H-f] . [M-right])))) (use-package server :defer 1 @@ -94,7 +94,7 @@ that buffer." "%" "%%" (format "[%s] [%s]" (shell-command-to-string "/home/bdunahu/.local/bin/mail-string 2>/dev/null") - (shell-command-to-string "/home/bdunahu/.local/bin/t1-string 2>/dev/null"))))) + (shell-command-to-string "/home/bdunahu/.local/bin/t1-string 2>/dev/null"))))) (defvar-local bd/external-mode-line '(:eval (when new-mode-line diff --git a/.config/emacs/modules/bd--gpg.el b/.config/emacs/modules/bd--gpg.el index 83fa4c1..827d0d0 100644 --- a/.config/emacs/modules/bd--gpg.el +++ b/.config/emacs/modules/bd--gpg.el @@ -18,7 +18,7 @@ (f-files "~/.password-store" (lambda (file) (equal (f-ext file) "gpg")) t))) (defun bd/password-store-clear (id) - "Clears the most recent password copied to the kill ring." + "Clears the most recent password copied to the kill ring, printing ID." (when bd/password-store-kill-ring-pointer (setcar bd/password-store-kill-ring-pointer nil) (kill-new "") @@ -39,19 +39,10 @@ (message "Copied password for %s to the kill ring and system clipboard. Will clear in %s seconds." id bd/password-store-time-before-clear))) -(defun bd/selector-passwords () - "Selector source for password-store passwords." - (selector-source-create - "Passwords" - :candidates - (bd/password-store-list) - :actions - (list #'bd/read-password))) - (defun bd/password () "Interactively select a password-store password." (interactive) - (selector (list (bd/selector-passwords)))) + (bd/read-password (completing-read "Yank: " (bd/password-store-list)))) (use-package pinentry :defer 1 diff --git a/.config/emacs/modules/bd--minibuffer.el b/.config/emacs/modules/bd--minibuffer.el index 205ead0..fe2ed78 100644 --- a/.config/emacs/modules/bd--minibuffer.el +++ b/.config/emacs/modules/bd--minibuffer.el @@ -7,14 +7,21 @@ (use-package icomplete + :bind + ((:map icomplete-minibuffer-map + ("RET" . icomplete-force-complete-and-exit))) :config (setopt completing-read-function #'completing-read-default - read-file-name-function #'read-file-name-default - completion-styles '(basic - substring - initials - flex) - completions-max-height '30) + read-file-name-function #'read-file-name-default + completion-styles '(basic + substring + initials + flex) + icomplete-delay-completions-threshold 0 + icomplete-compute-delay 0.10 + icomplete-show-matches-on-no-input t + icomplete-separator " | " + completions-max-height '30) (icomplete-vertical-mode)) (use-package selector @@ -56,7 +63,7 @@ selection commands.") (take bd/navigate-recent-display-number (cl-remove-if (lambda (b) (get-buffer-window b 'visible)) - (bd/buffer-list))) + (bd/buffer-list))) :actions selector-buffer-actions)) @@ -66,7 +73,7 @@ selection commands.") :candidates (let ((proj (project-current))) (when proj - (project-files proj))) + (project-files proj))) :actions selector-file-actions)) @@ -91,8 +98,6 @@ selection commands.") (bd/selector-buffer-type "IRC" #'bd/buffer-irc-p) (bd/selector-buffer-type "Ordinary" #'bd/buffer-ordinary-p) (bd/selector-project-files) - (bd/selector-bookmarks) - (bd/selector-search) (selector-recentf-source)))) (keymap-global-set "C-x b" 'bd/navigate) @@ -101,13 +106,13 @@ selection commands.") (interactive) (let ((query (read-string "rg: "))) (defun conv (x) - (cons (car x) (cons (- (string-to-number (cadr x)) 1) (caddr 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))) + (--map (to-candidate (cdr it)) (--filter (s-equals? key (car it)) list))) (defun to-candidate (x) - (selector-candidate-create (cdr x) :value (car x))) + (selector-candidate-create (cdr x) :value (car x))) (let* ((dir (expand-file-name (bd/get-directory-dwim))) - (result (with-temp-buffer + (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)))) @@ -117,7 +122,7 @@ selection commands.") :candidates (all-in-file it lines) :actions (selector-file-contents-actions it)) files))) - (when (not (null sources)) + (when (not (null sources)) (selector sources))))) (keymap-global-set "C-z s" 'bd/selector-rg)) diff --git a/.config/emacs/modules/bd--notes.el b/.config/emacs/modules/bd--notes.el index eaea365..ee17e38 100644 --- a/.config/emacs/modules/bd--notes.el +++ b/.config/emacs/modules/bd--notes.el @@ -32,10 +32,11 @@ then pastes the active region." (advice-add 'scratch-buffer :after (lambda () (setq-local scratch-buffer t))) (use-package denote + :defer 1 :hook ((dired-mode . denote-dired-mode-in-directories)) :bind (("H-d d" . 'denote) - ("H-d f" . 'denote-open-or-create) + ("H-d f" . 'denote-open-or-create) ("H-d j" . 'denote-journal-extras-new-or-existing-entry) :map org-mode-map ("C-c l" . 'denote-link)) @@ -58,15 +59,17 @@ KEYWORDS is a list of strings." (string-join keywords "\" \"")) :config (setopt denote-file-type 'org - denote-known-keywords - '("ss" "writing" "reading" "art" - "csu" "umass" "cs" "guix" - "emacs" "programs" "mem") - denote-directory (expand-file-name "~/dc/") - denote-prompts '(title file-type keywords) - denote-dired-directories (list denote-directory) - denote-journal-extras-directory (expand-file-name "~/dc/log") - denote-journal-extras-title-format 'day-date-month-year)) + denote-known-keywords + '("ss" "writing" "reading" "art" + "csu" "umass" "cs" "guix" + "emacs" "programs" "mem") + denote-directory (expand-file-name "~/dc/") + denote-prompts '(title file-type keywords) + denote-dired-directories (list denote-directory) + denote-journal-extras-directory (expand-file-name "~/dc/log") + denote-journal-extras-title-format 'day-date-month-year)) + +(use-package anki-editor) (provide 'bd--notes) diff --git a/.config/emacs/modules/bd--utility.el b/.config/emacs/modules/bd--utility.el index cdc2c7e..2733e80 100644 --- a/.config/emacs/modules/bd--utility.el +++ b/.config/emacs/modules/bd--utility.el @@ -2,8 +2,12 @@ ;;; Commentary: ;;; Code: +(require 'project) +(require 'xdg) + + (defun bd/set-frame-alpha (value) - "Sets the transparency of the frame background. 0=transparent/100=opaque." + "Set the transparency of the frame background to VALUE. 0=transparent/100=opaque." (interactive "nTransparency Value (30 - 100 opaque): ") (setq value (max 30 (min value 100))) (set-frame-parameter (selected-frame) 'alpha `(,value . ,value)) @@ -22,9 +26,9 @@ ARG can be one of the following: (cond ((file-regular-p arg) (copy-file arg wall t)) ((file-directory-p arg) - (let* ((images (f-files arg (lambda (f) (string-match-p "\\.jpeg\\'" f)))) - (rfile (nth (random (length images)) images))) - (and rfile (copy-file rfile wall t)))))) + (let* ((images (directory-files arg (lambda (f) (string-match-p "\\.jpeg\\'" f)))) + (rfile (nth (random (length images)) images))) + (and rfile (copy-file rfile wall t)))))) (start-process "set wallpaper" nil "feh" "--bg-fill" wall) (message "Set wallpaper."))) @@ -51,7 +55,7 @@ ARG can be one of the following: (start-process "sound toggle" nil "pactl" "set-sink-mute" "@DEFAULT_SINK@" "toggle")) (defun bd/set-volume (value) - "Sets the volume to VALUE." + "Set the volume to VALUE." (start-process "set volume" nil "pactl" "set-sink-volume" "@DEFAULT_SINK@" value)) (defun bd/decrement-volume () @@ -65,7 +69,7 @@ ARG can be one of the following: (bd/set-volume "+4%")) (defun bd/set-brightness (value) - "Sets the brightness to VALUE." + "Set the brightness to VALUE." (start-process "set brightness" nil "brightnessctl" "set" value)) (defun bd/decrement-brightness () @@ -79,9 +83,9 @@ ARG can be one of the following: (bd/set-brightness "5%+")) (defun bd/get-directory-dwim () - "Returns the directory you always wanted." + "Return the directory you always wanted." (or (when (project-current) - (project-root (project-current))) ;; git + (project-root (project-current))) ;; git (locate-dominating-file "." "Makefile") ;; make (locate-dominating-file "." "manifest.scm") ;; guix default-directory)) @@ -121,7 +125,7 @@ ARG can be one of the following: (not (or (bd/buffer-exwm-p buf) (bd/buffer-text-p buf) (bd/buffer-prog-p buf) - (bd/buffer-scratch-p buf) + (bd/buffer-scratch-p buf) (bd/buffer-dired-p buf) (bd/buffer-irc-p buf)))) -- cgit v1.2.3