Switching to vertico, corfu, orderless instead of sel, comp, presc.
This commit is contained in:
parent
940d93d262
commit
2ea83b0a00
7 changed files with 515 additions and 112 deletions
318
init.el
318
init.el
|
@ -300,57 +300,81 @@
|
|||
(use-package toc-org
|
||||
:after org)
|
||||
|
||||
(use-package selectrum
|
||||
(use-package vertico
|
||||
:init
|
||||
(selectrum-mode +1)
|
||||
:config
|
||||
(setq selectrum-max-window-height 8)
|
||||
(add-hook 'selectrum-mode-hook 'selectrum-exhibit)
|
||||
(vertico-mode)
|
||||
|
||||
;; We need to fix selectrums minibuffer handling for Emacs 28
|
||||
(defun selectrum--set-window-height (window &optional height)
|
||||
"Set window height of WINDOW to HEIGHT pixel.
|
||||
If HEIGHT is not given WINDOW will be updated to fit its content
|
||||
vertically."
|
||||
(let* ((lines (length
|
||||
(split-string
|
||||
(overlay-get selectrum--candidates-overlay 'after-string)
|
||||
"\n" t)))
|
||||
(dheight (or height
|
||||
(* lines selectrum--line-height)))
|
||||
(wheight (window-pixel-height window))
|
||||
(window-resize-pixelwise t))
|
||||
(window-resize
|
||||
window (- dheight wheight) nil nil 'pixelwise)))
|
||||
;; Different scroll margin
|
||||
;; (setq vertico-scroll-margin 0)
|
||||
|
||||
|
||||
;; Show more candidates
|
||||
(setq vertico-count 10)
|
||||
|
||||
;; Grow and shrink the Vertico minibuffer
|
||||
(setq vertico-resize t)
|
||||
|
||||
;; Optionally enable cycling for `vertico-next' and `vertico-previous'.
|
||||
(setq vertico-cycle t)
|
||||
:general
|
||||
('selectrum-minibuffer-map
|
||||
"C-j" 'selectrum-next-candidate
|
||||
"C-k" 'selectrum-previous-candidate
|
||||
"C-S-j" 'selectrum-goto-end
|
||||
"C-S-k" 'selectrum-goto-beginning
|
||||
"TAB" 'selectrum-insert-current-candidate)
|
||||
:commands completing-read)
|
||||
(general-def 'vertico-map
|
||||
"C-j" 'vertico-next
|
||||
"C-k" 'vertico-previous)
|
||||
)
|
||||
|
||||
(use-package prescient
|
||||
:config
|
||||
(prescient-persist-mode +1)
|
||||
:after selectrum)
|
||||
|
||||
(use-package selectrum-prescient
|
||||
;; Persist history over Emacs restarts. Vertico sorts by history position.
|
||||
(use-package savehist
|
||||
:init
|
||||
(selectrum-prescient-mode +1)
|
||||
:after selectrum)
|
||||
(savehist-mode))
|
||||
|
||||
;; A few more useful configurations...
|
||||
(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))
|
||||
|
||||
(use-package consult
|
||||
:after selectrum
|
||||
:after vertico
|
||||
:config
|
||||
(setq consult-narrow-key "'"
|
||||
consult-project-root-function 'projectile-project-root)
|
||||
|
||||
(defun chris/consult-ripgrep-file
|
||||
(interactive "P"))
|
||||
(defun chris/consult-ripgrep-for-stepdata ()
|
||||
"Make ripgrep search hidden files for stepdata"
|
||||
(interactive)
|
||||
(let ((consult-ripgrep-args
|
||||
(concat "rg "
|
||||
"--null "
|
||||
"--line-buffered "
|
||||
"--color=never "
|
||||
"--max-columns=1000 "
|
||||
"--path-separator / "
|
||||
"--no-heading "
|
||||
"--line-number "
|
||||
;; adding these to default
|
||||
"--smart-case "
|
||||
"--hidden "
|
||||
;; defaults
|
||||
"."
|
||||
)))
|
||||
(consult-ripgrep)))
|
||||
|
||||
|
||||
:general
|
||||
(chris/leader-keys
|
||||
:states 'normal
|
||||
|
@ -375,44 +399,170 @@ vertically."
|
|||
(marginalia-mode)
|
||||
|
||||
;; When using Selectrum, ensure that Selectrum is refreshed when cycling annotations.
|
||||
(advice-add #'marginalia-cycle :after
|
||||
(lambda () (when (bound-and-true-p selectrum-mode) (selectrum-exhibit))))
|
||||
;; (advice-add #'marginalia-cycle :after
|
||||
;; (lambda () (when (bound-and-true-p selectrum-mode) (selectrum-exhibit))))
|
||||
|
||||
;; Prefer richer, more heavy, annotations over the lighter default variant.
|
||||
(setq marginalia-annotators '(marginalia-annotators-heavy marginalia-annotators-light nil))
|
||||
:after selectrum
|
||||
:after vertico
|
||||
:config
|
||||
(setq marginalia--cache-size 60000))
|
||||
|
||||
(use-package embark
|
||||
:after selectrum
|
||||
:ensure t
|
||||
:general
|
||||
('selectrum-minibuffer-map
|
||||
"C-'" 'embark-act)
|
||||
('normal
|
||||
"C-'" 'embark-act))
|
||||
('vertico-map
|
||||
"C-'" 'embark-act)
|
||||
('normal 'org-mode-map
|
||||
"C-'" 'embark-act)
|
||||
|
||||
:config
|
||||
(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))))))))
|
||||
|
||||
(setq embark-indicators
|
||||
'(embark-which-key-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)
|
||||
|
||||
(use-package company
|
||||
:config
|
||||
(global-company-mode +1)
|
||||
(use-package corfu
|
||||
:ensure t
|
||||
;; Optional customizations
|
||||
:custom
|
||||
(company-dabbrev-other-buffers t)
|
||||
(company-minimum-prefix-length 1)
|
||||
(company-idle-delay 0.1)
|
||||
(corfu-cycle t) ;; Enable cycling for `corfu-next/previous'
|
||||
(corfu-auto t) ;; Enable auto completion
|
||||
(corfu-separator ?\s) ;; Orderless field separator
|
||||
(corfu-quit-no-match 'separator) ;; Never quit, even if there is no match
|
||||
(corfu-preview-current 'insert) ;; Enable current candidate preview
|
||||
(corfu-preselect-first nil) ;; Enable candidate preselection
|
||||
(corfu-on-exact-match 'insert) ;; Configure handling of exact matches
|
||||
(corfu-echo-documentation '(1.0 . 0.2)) ;; Disable documentation in the echo area
|
||||
(corfu-scroll-margin 5) ;; Use scroll margin
|
||||
(corfu-count 15)
|
||||
(corfu-auto-prefix 2)
|
||||
|
||||
;; You may want to enable Corfu only for certain modes.
|
||||
;; :hook ((prog-mode . corfu-mode)
|
||||
;; (shell-mode . corfu-mode)
|
||||
;; (eshell-mode . corfu-mode))
|
||||
|
||||
;; Recommended: Enable Corfu globally.
|
||||
;; This is recommended since dabbrev can be used globally (M-/).
|
||||
:init
|
||||
(corfu-global-mode)
|
||||
:general
|
||||
(general-def '(normal insert) company-active-map
|
||||
"TAB" 'company-complete-selection
|
||||
"RET" 'company-complete-selection)
|
||||
(general-def '(normal insert) lsp-mode-map
|
||||
"TAB" 'company-indent-or-complete-common))
|
||||
('corfu-map
|
||||
"C-j" 'corfu-next
|
||||
"C-k" 'corfu-previous
|
||||
"M-SPC" 'corfu-insert-separator))
|
||||
|
||||
;; (use-package company-box
|
||||
;; :hook (company-mode . company-box-mode))
|
||||
;; Optionally use the `orderless' completion style. See `+orderless-dispatch'
|
||||
;; in the Consult wiki for an advanced Orderless style dispatcher.
|
||||
;; Enable `partial-completion' for files to allow path expansion.
|
||||
;; You may prefer to use `initials' instead of `partial-completion'.
|
||||
(use-package orderless
|
||||
:ensure t
|
||||
:init
|
||||
;; Configure a custom style dispatcher (see the Consult wiki)
|
||||
;; (setq orderless-style-dispatchers '(+orderless-dispatch)
|
||||
;; orderless-component-separator #'orderless-escapable-split-on-space)
|
||||
(setq completion-styles '(orderless)
|
||||
completion-category-defaults nil
|
||||
completion-category-overrides '((file (styles . (partial-completion)))))
|
||||
|
||||
(use-package company-dict
|
||||
:after company)
|
||||
(defun flex-if-twiddle (pattern _index _total)
|
||||
(when (string-suffix-p "~" pattern)
|
||||
`(orderless-flex . ,(substring pattern 0 -1))))
|
||||
|
||||
(defun first-initialism (pattern index _total)
|
||||
(if (= index 0) 'orderless-initialism))
|
||||
|
||||
(defun without-if-bang (pattern _index _total)
|
||||
(cond
|
||||
((equal "!" pattern)
|
||||
'(orderless-literal . ""))
|
||||
((string-prefix-p "!" pattern)
|
||||
`(orderless-without-literal . ,(substring pattern 1)))))
|
||||
|
||||
(setq orderless-matching-styles '(orderless-literal orderless-regexp)
|
||||
orderless-style-dispatchers '(flex-if-twiddle
|
||||
without-if-bang))
|
||||
)
|
||||
|
||||
;; Use dabbrev with Corfu!
|
||||
(use-package dabbrev
|
||||
:after corfu
|
||||
;; Swap M-/ and C-M-/
|
||||
:bind (("M-/" . dabbrev-completion)
|
||||
("C-M-/" . dabbrev-expand)))
|
||||
|
||||
(use-package cape
|
||||
:ensure t
|
||||
;; Bind dedicated completion commands
|
||||
:bind (("C-c p p" . completion-at-point) ;; capf
|
||||
("C-c p t" . complete-tag) ;; etags
|
||||
("C-c p d" . cape-dabbrev) ;; or dabbrev-completion
|
||||
("C-c p f" . cape-file)
|
||||
("C-c p k" . cape-keyword)
|
||||
("C-c p s" . cape-symbol)
|
||||
("C-c p a" . cape-abbrev)
|
||||
("C-c p i" . cape-ispell)
|
||||
("C-c p l" . cape-line)
|
||||
("C-c p w" . cape-dict)
|
||||
("C-c p \\" . cape-tex)
|
||||
("C-c p _" . cape-tex)
|
||||
("C-c p ^" . cape-tex)
|
||||
("C-c p &" . cape-sgml)
|
||||
("C-c p r" . cape-rfc1345))
|
||||
:init
|
||||
;; Add `completion-at-point-functions', used by `completion-at-point'.
|
||||
(add-to-list 'completion-at-point-functions #'cape-file)
|
||||
;; (add-to-list 'completion-at-point-functions #'cape-tex)
|
||||
(add-to-list 'completion-at-point-functions #'cape-dabbrev)
|
||||
(add-to-list 'completion-at-point-functions #'cape-keyword)
|
||||
;;(add-to-list 'completion-at-point-functions #'cape-sgml)
|
||||
;;(add-to-list 'completion-at-point-functions #'cape-rfc1345)
|
||||
;;(add-to-list 'completion-at-point-functions #'cape-abbrev)
|
||||
(add-to-list 'completion-at-point-functions #'cape-ispell)
|
||||
;;(add-to-list 'completion-at-point-functions #'cape-dict)
|
||||
;; (add-to-list 'completion-at-point-functions #'cape-symbol)
|
||||
;;(add-to-list 'completion-at-point-functions #'cape-line)
|
||||
:config
|
||||
(setq cape-dabbrev-min-length 2)
|
||||
)
|
||||
|
||||
(use-package yasnippet
|
||||
:config
|
||||
|
@ -514,9 +664,16 @@ vertically."
|
|||
|
||||
(use-package lsp-mode
|
||||
:commands (lsp lsp-deferred)
|
||||
:hook ((c++-mode qml-mode) . lsp-deferred)
|
||||
:custom
|
||||
(lsp-completion-provider :none)
|
||||
:hook
|
||||
(c++-mode . lsp-deferred)
|
||||
(lsp-completion-mode . my/lsp-mode-setup-completion)
|
||||
:init
|
||||
(setq lsp-keymap-prefix "C-c l")
|
||||
(defun my/lsp-mode-setup-completion ()
|
||||
(setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults))
|
||||
'(flex)))
|
||||
:config
|
||||
(setq lsp-lens-enable t
|
||||
lsp-signature-auto-activate nil
|
||||
|
@ -566,6 +723,23 @@ vertically."
|
|||
:config
|
||||
(setq markdown-fontify-code-blocks-natively t))
|
||||
|
||||
(use-package qml-mode
|
||||
:mode ("\\.qml\\'" . qml-mode))
|
||||
|
||||
;; (use-package company-qml
|
||||
;; :after qml-mode
|
||||
;; :config
|
||||
;; ;; (add-to-list 'company-backends 'company-qml)
|
||||
;; )
|
||||
|
||||
;; (setq company-backends
|
||||
;; '(company-bbdb company-semantic company-cmake company-capf company-clang company-files
|
||||
;; (company-dabbrev-code company-gtags company-etags company-keywords)
|
||||
;; company-oddmuse company-dabbrev))
|
||||
|
||||
;; (use-package qt-pro-mode
|
||||
;; :after qml-mode)
|
||||
|
||||
(use-package csv-mode
|
||||
:mode ("\\.csv\\'" . csv-mode))
|
||||
|
||||
|
@ -619,7 +793,8 @@ vertically."
|
|||
"oD" '(dired :which-key "open dired select"))
|
||||
(general-def 'normal dired-mode-map
|
||||
"q" 'kill-this-buffer
|
||||
"C-<return>" 'chris/dired-open-xdg))
|
||||
"C-<return>" 'chris/dired-open-xdg
|
||||
"C-'" 'embark-act))
|
||||
|
||||
(defun chris/dired-yank-filename ()
|
||||
"Get the full filename from file at point and put into kill-ring"
|
||||
|
@ -1775,18 +1950,3 @@ interfere with the default `bongo-playlist-buffer'."
|
|||
gcmh-verbose nil))
|
||||
|
||||
(setq warning-suppress-types '((comp)))
|
||||
(custom-set-variables
|
||||
;; custom-set-variables was added by Custom.
|
||||
;; If you edit it by hand, you could mess it up, so be careful.
|
||||
;; Your init file should contain only one such instance.
|
||||
;; If there is more than one, they won't work right.
|
||||
'(pdf-misc-print-program "/usr/bin/lpr" t)
|
||||
'(pdf-misc-print-program-args '("-o media=Letter" "-o fitplot") t)
|
||||
'(safe-local-variable-values
|
||||
'((eval org-odt-styles-file "/home/chris/org/tfcexpenses2020.odt"))))
|
||||
(custom-set-faces
|
||||
;; custom-set-faces was added by Custom.
|
||||
;; If you edit it by hand, you could mess it up, so be careful.
|
||||
;; Your init file should contain only one such instance.
|
||||
;; If there is more than one, they won't work right.
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue