From e99b8d991bfb5f3467305c19461767ec6b320350 Mon Sep 17 00:00:00 2001 From: Madeleine Sydney Date: Sun, 2 Feb 2025 14:51:04 -0700 Subject: [PATCH] feat: Bind SPC f r - Additionally, fixed a bug where consult-recent-file would be called before recentf-mdoe was enabled --- .../programs/emacs/modules/syd-completion.el | 48 +++++++++++++++---- .../programs/emacs/modules/syd-keybinds.el | 3 +- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/users/crumb/programs/emacs/modules/syd-completion.el b/users/crumb/programs/emacs/modules/syd-completion.el index 0b32ac0..6ea2a64 100755 --- a/users/crumb/programs/emacs/modules/syd-completion.el +++ b/users/crumb/programs/emacs/modules/syd-completion.el @@ -14,24 +14,52 @@ ;; Consult adds various search and navigation tools using Emacs' completing-read ;; function; i.e., in our case, Vertico. (use-package consult - :defer t) + :defer t + :config + (advice-add #'consult-recent-file + :before #'syd-enable-recentf-mode-a)) (use-package embark-consult :after (embark consult)) +;;;###autoload +(defun syd-vertico-embark-preview () + "Previews candidate in vertico buffer, unless it's a consult command" + (interactive) + (unless (bound-and-true-p consult--preview-function) + (if (fboundp 'embark-dwim) + (save-selected-window + (let (embark-quit-after-action) + (embark-dwim))) + (user-error "Embark not installed, aborting...")))) + +;;;###autoload +(defun syd-enable-recentf-mode-a () + "Used as :before advice for `consult-recent-file' to ensure recentf mode is +enabled." + ;; REVIEW: Shall we take any extra precautions to only enable `recentf-mode' + ;; if it was going to be enabled anyway? + (recentf-mode 1)) + ;; Vertico is a simple completion engine that replaces Emacs' built-in ;; completion engine, achieving Just Works™ compatibility. This is in contrast ;; to e.g. Helm and Ivy, which spawn ecosystems orthogonal to Emacs, and ;; diametrically-opposed to each other. (use-package vertico :hook (on-first-input . vertico-mode) - :general (:keymaps 'vertico-map - "DEL" #'vertico-directory-delete-char - "C-SPC" #'+vertico/embark-preview - "C-j" #'vertico-next - "C-k" #'vertico-previous - "C-M-j" #'vertico-next-group - "C-M-k" #'vertico-previous-group) + :general + (:keymaps 'vertico-map + "DEL" #'vertico-directory-delete-char + "C-SPC" #'syd-vertico-embark-preview + "C-j" #'vertico-next + "C-k" #'vertico-previous + "C-M-j" #'vertico-next-group + "C-M-k" #'vertico-previous-group) + (:keymaps 'vertico-map + :states 'normal + "j" #'vertico-next + "k" #'vertico-previous + "RET" #'vertico-exit) :custom ((vertico-resize nil) (vertico-count 17) (vertico-cycle t)) @@ -41,7 +69,7 @@ ;; cleans ~/foo/bar/// to /, and ~/foo/bar/~/ to ~/. (add-hook 'rfn-eshadow-update-overlay-hook #'vertico-directory-tidy)) -(defun +vertico-orderless-dispatch (pattern _index _total) +(defun syd-vertico-orderless-dispatch (pattern _index _total) "Like `orderless-affix-dispatch', but allows affixes to be escaped. Shamelessly stolen from Doom. }:3" @@ -72,7 +100,7 @@ Shamelessly stolen from Doom. }:3" '((file (styles ;basic-remote orderless partial-completion)))) - (orderless-style-dispatchers '(+vertico-orderless-dispatch)) + (orderless-style-dispatchers '(syd-vertico-orderless-dispatch)) ;; TODO: See Doom's `+vertico-orderless-dispatch'. (orderless-affix-dispatch-alist '((?! . orderless-without-literal) diff --git a/users/crumb/programs/emacs/modules/syd-keybinds.el b/users/crumb/programs/emacs/modules/syd-keybinds.el index af32c48..d4489b3 100755 --- a/users/crumb/programs/emacs/modules/syd-keybinds.el +++ b/users/crumb/programs/emacs/modules/syd-keybinds.el @@ -147,7 +147,8 @@ all hooks after it are ignored.") "P" `("Browse Emacs config" . ,#'syd/find-file-in-emacs-user-directory) "u" `("Find file as root" . ,#'syd/find-file-as-root) "U" `("Open this file as root" . ,#'syd/open-this-file-as-root) - "y" `("Yank buffer path" . ,#'syd/yank-buffer-path)) + "y" `("Yank buffer path" . ,#'syd/yank-buffer-path) + "r" `("Browse recent file" . ,#'consult-recent-file)) ;; Window (require 'syd-window)