From 3aec865add2b9af7ab7f730a9f3ec5f0fad078ff Mon Sep 17 00:00:00 2001 From: Jakub Czajka Date: Fri, 23 Dec 2022 19:01:17 +0100 Subject: [PATCH] [emacs] Extend the default minibuffer. Minibuffer is a special window for selecting from a set of values (e.g. a file to open). This commit extends the default emacs minibuffer with orderless (narrowing the set of values) and vertico (live preview of the set of values). --- conf/home/emacs.scm | 10 ++++ emacs/.config/emacs/conf/conf-minibuffer.el | 61 +++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 emacs/.config/emacs/conf/conf-minibuffer.el diff --git a/conf/home/emacs.scm b/conf/home/emacs.scm index 2868db1..875c43d 100644 --- a/conf/home/emacs.scm +++ b/conf/home/emacs.scm @@ -110,6 +110,15 @@ (dotfiles (list "emacs/.config/emacs/conf/conf-language.el"))))) +(define emacs-minibuffer-service + (service home-program-service-type + (home-program-configuration + (packages + (list emacs-orderless + emacs-vertico)) + (dotfiles + (list "emacs/.config/emacs/conf/conf-minibuffer.el"))))) + (define emacs-package-service (service home-program-service-type (home-program-configuration @@ -154,6 +163,7 @@ emacs-email-service emacs-keys-service emacs-language-service + emacs-minibuffer-service emacs-package-service emacs-pass-service emacs-service)) diff --git a/emacs/.config/emacs/conf/conf-minibuffer.el b/emacs/.config/emacs/conf/conf-minibuffer.el new file mode 100644 index 0000000..3e61cb5 --- /dev/null +++ b/emacs/.config/emacs/conf/conf-minibuffer.el @@ -0,0 +1,61 @@ +;; Copyright (c) 2022 Jakub Czajka +;; License: GPL-3.0 or later. +;; +;; conf-minibuffer.el - configuration for the minibuffer. + +(require 'conf-package) + +;; Use y-or-n instead of yes-or-no. +(fset 'yes-or-no-p 'y-or-n-p) + +(use-package minibuffer + ;; Allow to enter a minibuffer while in a minibuffer. + :custom + (enable-recursive-minibuffers t) + :custom-face + (minibuffer-prompt ((t :foreground "#fed065")))) + +(use-package orderless + :ensure t + :custom + ;; Interpret all input patterns as regular expressions by default. + (orderless-matching-styles '(orderless-regexp)) + ;; Dispatchers for literal and without-literal matching styles. + (orderless-style-dispatchers '(with-literal-string without-literal-string)) + ;; `basic' completion style as fallback. + (completion-styles '(orderless basic)) + (completion-category-defaults nil) + ;; `partial-completion' completion style for file name completion. + (completion-category-overrides '((file (styles partial-completion)))) + :config + (defun with-literal-string (pattern _index _total) + "Orderless dispatcher for literal matching style." + (when (string-suffix-p "=" pattern) + `(orderless-literal . ,(substring pattern 0 -1)))) + + (defun without-literal-string (pattern _index _total) + "Orderless dispatcher for without-literal matching style." + (when (string-suffix-p "!" pattern) + `(orderless-without-literal . ,(substring pattern 0 -1))))) + +(use-package vertico + :ensure t + :init + ;; Enable on startup. + ;; `vertico-mode' is an autoload. + (vertico-mode) + :custom + ;; Grow or shrink the minibuffer when possible. + (vertico-resize t) + ;; Hide the count of completion candidates + (vertico-count-format '()) + ;; Make the completion list cyclical. + (vertico-cycle t)) + +(use-package vertico-reverse + :init + ;; Enable on startup. + ;; `vertico-reverse-mode' is an autoload. + (vertico-reverse-mode)) + +(provide 'conf-minibuffer) -- 2.39.5