From 0f508efd36408fb16625b117e5470975e749f76c Mon Sep 17 00:00:00 2001 From: noa@gaiwan.org Date: Thu, 13 Jun 2024 21:12:45 +0000 Subject: Update consult, marginalia, and embark configuration --- emacs/init.el | 110 +++++++++++++++++++++------------------------------------- 1 file changed, 39 insertions(+), 71 deletions(-) diff --git a/emacs/init.el b/emacs/init.el index 7bcc64d..cd82267 100644 --- a/emacs/init.el +++ b/emacs/init.el @@ -167,80 +167,48 @@ and when JID is not in `jabber-activity-banned'." :ensure t :hook (text-mode . spell-fu-mode)) -;; consult-buffer replaces the buffer menu. as well as listing buffers, it lists bookmarks and recent files. -(use-package consult - :ensure t - :bind (([remap switch-to-buffer] . consult-buffer) ;; also contains file history, etc - ([remap yank-pop] . consult-yank-pop) ;; like normal yank-pop but with live preview - ([remap goto-line] . consult-goto-line))) +;;; Completing-read everywhere with consult -(use-package embark - :ensure t - :bind (("C-" . embark-act) - ("C-" . embark-export) - ([remap describe-bindings] . embark-bindings) - ("M-." . embark-dwim)) - :hook (eldoc-documentation-functions . embark-eldoc-first-target) - :custom - (eldoc-documentation-strategy 'eldoc-documentation-compose-eagerly) - (embark-indicators '(embark-minimal-indicator embark-highlight-indicator embark-isearch-highlight-indicator)) +;; Consult is a package to provide navigation commands that take advantage of completing-read. I set up a nice completing-read environment earlier with vertico. There are a lot of commands built in to consult, and it's possible to define more. But i use it very simply. +(use-package consult :ensure t) - ) +;; Consult buffer can be used instead of the default buffer menu. It lists recently used files and bookmarks as well as open buffers. +(global-set-key [remap switch-to-buffer] #'consult-buffer) ;; also contains file history, etc - (setq prefix-help-command #'embark-prefix-help-command) - -(defun embark-which-key-indicator () - "An embark indicator that displays keymaps using which-key. -The which-key help message will show the type and value of the -current target followed by an ellipsis if there are further -targets." - (lambda (&optional keymap targets prefix) - (if (null keymap) - (which-key--hide-popup-ignore-command) - (which-key--show-keymap - (if (eq (plist-get (car targets) :type) 'embark-become) - "Become" - (format "Act on %s '%s'%s" - (plist-get (car targets) :type) - (embark--truncate-target (plist-get (car targets) :target)) - (if (cdr targets) "…" ""))) - (if prefix - (pcase (lookup-key keymap prefix 'accept-default) - ((and (pred keymapp) km) km) - (_ (key-binding prefix 'accept-default))) - keymap) - nil nil t (lambda (binding) - (not (string-suffix-p "-argument" (cdr binding)))))))) - -;; (setopt embark-indicators -;; '(embark--vertico-indicator -;; ;; embark-which-key-indicator -;; embark-minimal-indicator -;; embark-highlight-indicator -;; embark-isearch-highlight-indicator)) - -(defun embark-hide-which-key-indicator (fn &rest args) - "Hide the which-key indicator immediately when using the completing-read prompter." - (which-key--hide-popup-ignore-command) - (let ((embark-indicators - (remq #'embark-which-key-indicator embark-indicators))) - (apply fn args))) - -;; (advice-add #'embark-completing-read-prompter -;; :around #'embark-hide-which-key-indicator) - -(use-package embark-consult - :ensure t ; only need to install it, embark loads it after consult if found - :hook - (embark-collect-mode . consult-preview-at-point-mode)) - -(use-package marginalia - :ensure t - :after vertico - :custom - (marginalia-mode t) - (marginalia-max-relative-age most-positive-fixnum) - (marginalia-align 'right)) +(global-set-key [remap yank-pop] #'consult-yank-pop) ;; like normal yank-pop but with live preview +(global-set-key [remap goto-line] #'consult-goto-line) + +;;; Embark: sort of like right click, but better + +;; I've only recently started making use of embark and i definitely need to experiment with it more. Essentially it lets you execute actions based on what kind of thing is selected, either at the point in the buffer, or in an already open completion buffer. +(use-package embark :ensure t) + +(global-set-key (kbd "C-") #'embark-act) +(global-set-key (kbd "C-") #'embark-export) +(global-set-key (kbd "M-.") #'embark-dwim) + +;; Embark indicators give us visual indication of what embark will do. The minimal indicator puts a message in the echo area. The highlight indicator highlights the region in the buffer that is being acted on. The isearch indicator does the same for when there are multiple regions to be acted on. If we want to see how we can act on the region, we can press C-h. +(setopt embark-indicators '(embark-minimal-indicator + embark-highlight-indicator + embark-isearch-highlight-indicator)) + +;; As mentioned in the vertico configuration above, we can set vertico to use a different layout when completing different things. In this case, we set embark to take control of showing bindings help and of the prefix help, which is pressing C-h after pressing a prefix. Then we ensure we get a grid layout, so that we can see more commands on screen at a time. +(global-set-key [remap describe-bindings] #'embark-bindings) +(setopt prefix-help-command #'embark-prefix-help-command) +(add-to-list 'vertico-multiform-categories '(embark-keybinding grid)) + +;; Because i use consult, it's recommended to have this package installed. +(use-package embark-consult :ensure t) +(add-hook 'embark-collect-mode-hook #'consult-preview-at-point-mode) + +;;; Annotations for completing-read + +;; Marginalia provides us with annotations for candidates in completing read functions. This is things like docstrings for functions, file permissions in find-file, and so on. It's a small quality of life improvement. +(use-package marginalia :ensure t) +(setopt marginalia-mode t) + +;; We want to always show the relative age of a file. By default, files which haven't been modified for more than two weeks will display an absolute date. +(setopt marginalia-max-relative-age most-positive-fixnum) ;; My keyboard has a tab key and an i key. For legacy reasons, by default emacs converts C-i to mean the same thing as the tab key, but i don't really want that. The tab key is called and it gets translated to TAB. C-i is TAB, but i'd rather it by C-i. That's what this decode line does. (define-key input-decode-map [?\C-i] [C-i]) -- cgit 1.4.1-2-gfad0