From 7361700a83590ae0293e9d346c809d3af9f9575a Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sat, 18 Sep 2021 12:17:17 +0100 Subject: Setup different completion framework --- doom/config.el | 192 +++++++++++++++++++++++++++++++++++++++++++++---------- doom/init.el | 2 +- doom/packages.el | 61 +++--------------- 3 files changed, 169 insertions(+), 86 deletions(-) diff --git a/doom/config.el b/doom/config.el index ea2df57..5612237 100644 --- a/doom/config.el +++ b/doom/config.el @@ -1,35 +1,11 @@ -;;; $DOOMDIR/config.el -*- lexical-binding: t; -*- - -;; Some functionality uses this to identify you, e.g. GPG configuration, email -;; clients, file templates and snippets. -(setq user-full-name "Yann Herklotz" - user-mail-address "yann@yannherklotz.com") - -;; Doom exposes five (optional) variables for controlling fonts in Doom. Here -;; are the three important ones: -;; -;; + `doom-font' -;; + `doom-variable-pitch-font' -;; + `doom-big-font' -- used for `doom-big-font-mode'; use this for -;; presentations or streaming. -;; -;; They all accept either a font-spec, font string ("Input Mono-12"), or xlfd -;; font string. You generally only need these two: -(setq doom-font (font-spec :family "Iosevka" :size 16) -;; doom-variable-pitch-font (font-spec :family "Alegreya" :size 12) -;; doom-serif-font (font-spec :family "Alegreya" :size 12)) -) -;; There are two ways to load a theme. Both assume the theme is installed and -;; available. You can either set `doom-theme' or manually load a theme with the -;; `load-theme' function. This is the default: +(setq doom-font (font-spec :family "Iosevka" :size 16)) +(setq doom-variable-pitch-font (font-spec :family "Alegreya" :size 12)) +(setq doom-serif-font (font-spec :family "Alegreya" :size 12)) + (setq doom-theme 'modus-operandi) -;; If you use `org' and don't want your org files in the default location below, -;; change `org-directory'. It must be set before org loads! (setq org-directory "~/Dropbox/org/") -;; This determines the style of line numbers in effect. If set to `nil', line -;; numbers are disabled. For relative line numbers, set this to `relative'. (setq display-line-numbers-type nil) ;; Disable stuff @@ -835,8 +811,158 @@ https://yannherklotz.com") '(("yann@yannherklotz.com" . "mailbox/Sent -inbox +sent -unread +mailbox -new") ("yann.herklotz15@imperial.ac.uk" . "\"imperial/Sent Items\" -inbox +sent -unread +imperial -new")))) -;;(use-package! ox-ssh -;; :after org -;; :config -;; (when (eq system-type 'darwin) -;; (setq org-ssh-header "XAuthLocation /opt/X11/bin/xauth"))) +(use-package! orderless + :custom (completion-styles '(substring orderless))) + +(use-package! vertico + :init + (vertico-mode)) + +(use-package! savehist + :init + (savehist-mode)) + +;; Enable richer annotations using the Marginalia package +(use-package! marginalia + ;; Either bind `marginalia-cycle` globally or only in the minibuffer + :bind (("M-A" . marginalia-cycle) + :map minibuffer-local-map + ("M-A" . marginalia-cycle)) + + ;; The :init configuration is always executed (Not lazy!) + :init + + ;; Must be in the :init section of use-package such that the mode gets + ;; enabled right away. Note that this forces loading the package. + (marginalia-mode)) + + +(use-package! embark + :bind + (("C-." . embark-act) ;; pick some comfortable binding + ("C-;" . embark-dwim) ;; good alternative: M-. + ("C-h B" . embark-bindings)) ;; alternative for `describe-bindings' + :init + ;; Optionally replace the key help with a completing-read interface + (setq prefix-help-command #'embark-prefix-help-command) + :config + (add-to-list 'display-buffer-alist + '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*" + nil + (window-parameters (mode-line-format . none))))) + +(use-package! embark-consult + :after (embark consult) + :demand t ; only necessary if you have the hook below + ;; if you want to have consult previews as you move around an + ;; auto-updating embark collect buffer + :hook + (embark-collect-mode . consult-preview-at-point-mode)) + +;; Example configuration for Consult +(use-package! consult + ;; Replace bindings. Lazily loaded due by `use-package'. + :bind (;; C-c bindings (mode-specific-map) + ("C-c h" . consult-history) + ("C-c m" . consult-mode-command) + ("C-c b" . consult-bookmark) + ("C-c k" . consult-kmacro) + ;; C-x bindings (ctl-x-map) + ("C-x M-:" . consult-complex-command) ;; orig. repeat-complex-command + ("C-x b" . consult-buffer) ;; orig. switch-to-buffer + ("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window + ("C-x 5 b" . consult-buffer-other-frame) ;; orig. switch-to-buffer-other-frame + ;; Custom M-# bindings for fast register access + ("M-#" . consult-register-load) + ("M-'" . consult-register-store) ;; orig. abbrev-prefix-mark (unrelated) + ("C-M-#" . consult-register) + ;; Other custom bindings + ("M-y" . consult-yank-pop) ;; orig. yank-pop + (" a" . consult-apropos) ;; orig. apropos-command + ;; M-g bindings (goto-map) + ("M-g e" . consult-compile-error) + ("M-g f" . consult-flymake) ;; Alternative: consult-flycheck + ("M-g g" . consult-goto-line) ;; orig. goto-line + ("M-g M-g" . consult-goto-line) ;; orig. goto-line + ("M-g o" . consult-outline) ;; Alternative: consult-org-heading + ("M-g m" . consult-mark) + ("M-g k" . consult-global-mark) + ("M-g i" . consult-imenu) + ("M-g I" . consult-imenu-multi) + ;; M-s bindings (search-map) + ("M-s f" . consult-find) + ("M-s F" . consult-locate) + ("M-s g" . consult-grep) + ("M-s G" . consult-git-grep) + ("M-s r" . consult-ripgrep) + ("M-s l" . consult-line) + ("M-s L" . consult-line-multi) + ("M-s m" . consult-multi-occur) + ("M-s k" . consult-keep-lines) + ("M-s u" . consult-focus-lines) + ;; Isearch integration + ("M-s e" . consult-isearch) + :map isearch-mode-map + ("M-e" . consult-isearch) ;; orig. isearch-edit-string + ("M-s e" . consult-isearch) ;; orig. isearch-edit-string + ("M-s l" . consult-line) ;; needed by consult-line to detect isearch + ("M-s L" . consult-line-multi)) ;; needed by consult-line to detect isearch + + ;; Enable automatic preview at point in the *Completions* buffer. + ;; This is relevant when you use the default completion UI, + ;; and not necessary for Vertico, Selectrum, etc. + :hook (completion-list-mode . consult-preview-at-point-mode) + + ;; The :init configuration is always executed (Not lazy) + :init + + (setq register-preview-delay 0 + register-preview-function #'consult-register-format) + + (advice-add #'register-preview :override #'consult-register-window) + + ;; Optionally replace `completing-read-multiple' with an enhanced version. + (advice-add #'completing-read-multiple :override #'consult-completing-read-multiple) + + ;; Use Consult to select xref locations with preview + (setq xref-show-xrefs-function #'consult-xref + xref-show-definitions-function #'consult-xref) + :config + + (consult-customize + consult-theme + :preview-key '(:debounce 0.2 any) + consult-ripgrep consult-git-grep consult-grep + consult-bookmark consult-recent-file consult-xref + consult--source-file consult--source-project-file consult--source-bookmark + :preview-key (kbd "M-.")) + + ;; Optionally configure the narrowing key. + ;; Both < and C-+ work reasonably well. + (setq consult-narrow-key "<") ;; (kbd "C-+") + + (setq consult-project-root-function + (lambda () + (when-let (project (project-current)) + (car (project-roots project)))))) + +(use-package! emacs + :init + ;; Add prompt indicator to `completing-read-multiple'. + ;; Alternatively try `consult-completing-read-multiple'. + (defun crm-indicator (args) + (cons (concat "[CRM] " (car args)) (cdr args))) + (advice-add #'completing-read-multiple :filter-args #'crm-indicator) + + ;; Do not allow the cursor in the minibuffer prompt + (setq minibuffer-prompt-properties + '(read-only t cursor-intangible t face minibuffer-prompt)) + (add-hook 'minibuffer-setup-hook #'cursor-intangible-mode) + + ;; Emacs 28: Hide commands in M-x which do not work in the current mode. + ;; Vertico commands are hidden in normal buffers. + (setq read-extended-command-predicate + #'command-completion-default-include-p) + + ;; Enable recursive minibuffers + (setq enable-recursive-minibuffers t)) diff --git a/doom/init.el b/doom/init.el index e94bdde..5348f13 100644 --- a/doom/init.el +++ b/doom/init.el @@ -30,7 +30,7 @@ ;;doom-dashboard ; a nifty splash screen for Emacs ;;doom-quit ; DOOM quit-message prompts when you quit Emacs ;;fill-column ; a `fill-column' indicator - hl-todo ; highlight TODO/FIXME/NOTE/DEPRECATED/HACK/REVIEW + ;;hl-todo ; highlight TODO/FIXME/NOTE/DEPRECATED/HACK/REVIEW hydra ;;indent-guides ; highlighted in dent columns modeline ; snazzy, Atom-inspired modeline, plus API diff --git a/doom/packages.el b/doom/packages.el index 3298904..ef8bff7 100644 --- a/doom/packages.el +++ b/doom/packages.el @@ -1,55 +1,3 @@ -;; -*- no-byte-compile: t; -*- -;;; $DOOMDIR/packages.el - -;; To install a package with Doom you must declare them here, run 'doom sync' on -;; the command line, then restart Emacs for the changes to take effect. -;; Alternatively, use M-x doom/reload. -;; -;; WARNING: Disabling core packages listed in ~/.emacs.d/core/packages.el may -;; have nasty side-effects and is not recommended. - - -;; All of Doom's packages are pinned to a specific commit, and updated from -;; release to release. To un-pin all packages and live on the edge, do: -;(unpin! t) - -;; ...but to unpin a single package: -;(unpin! pinned-package) -;; Use it to unpin multiple packages -;(unpin! pinned-package another-pinned-package) - - -;; To install SOME-PACKAGE from MELPA, ELPA or emacsmirror: -;(package! some-package) - -;; To install a package directly from a particular repo, you'll need to specify -;; a `:recipe'. You'll find documentation on what `:recipe' accepts here: -;; https://github.com/raxod502/straight.el#the-recipe-format -;(package! another-package -; :recipe (:host github :repo "username/repo")) - -;; If the package you are trying to install does not contain a PACKAGENAME.el -;; file, or is located in a subdirectory of the repo, you'll need to specify -;; `:files' in the `:recipe': -;(package! this-package -; :recipe (:host github :repo "username/repo" -; :files ("some-file.el" "src/lisp/*.el"))) - -;; If you'd like to disable a package included with Doom, for whatever reason, -;; you can do so here with the `:disable' property: -;(package! builtin-package :disable t) - -;; You can override the recipe of a built in package without having to specify -;; all the properties for `:recipe'. These will inherit the rest of its recipe -;; from Doom or MELPA/ELPA/Emacsmirror: -;(package! builtin-package :recipe (:nonrecursive t)) -;(package! builtin-package-2 :recipe (:repo "myfork/package")) - -;; Specify a `:branch' to install a package from a particular branch or tag. -;; This is required for some packages whose default branch isn't 'master' (which -;; our package manager can't deal with; see raxod502/straight.el#279) -;(package! builtin-package :recipe (:branch "develop")) - ;; Disabling packages (disable-packages! undo-tree org-bullets helm pretty-code company-coq) @@ -70,6 +18,15 @@ ;; Haskell stuff (package! ormolu) +;; completion +(package! orderless) +(package! vertico) +(package! marginalia) +(package! embark) +(package! consult) +(package! embark-consult) +(package! ripgrep) + (package! direnv) (package! yaml-mode) -- cgit