From aebd4d72544f1265ba2be9a0755b824b69e69f8a Mon Sep 17 00:00:00 2001 From: jao Date: Thu, 20 Jan 2022 20:27:09 +0000 Subject: completion cleansing, and bringing vertico back --- attic/misc.org | 118 ++++++++++++++++++++++++++++++++++++------------ completion.org | 138 ++++++++++++++++++++++++--------------------------------- 2 files changed, 149 insertions(+), 107 deletions(-) diff --git a/attic/misc.org b/attic/misc.org index 3aac8c7..a5bc802 100644 --- a/attic/misc.org +++ b/attic/misc.org @@ -848,41 +848,103 @@ #+end_src * vertico #+begin_src emacs-lisp - (use-package vertico - :ensure t - :init - (setq vertico-count 10 - vertico-cycle t - vertico-resize t - org-refile-use-outline-path t - resize-mini-windows nil) - - (vertico-mode) - - :bind (:map vertico-map (("RET" . vertico-directory-enter) - ("M-" . vertico-directory-delete-word) - ("" . vertico-directory-delete-char)))) - - (use-package vertico-directory - :after vertico) - - (use-package vertico-reverse - :after vertico - :init (vertico-reverse-mode)) - (use-package vertico-repeat :after vertico :config (add-hook 'minibuffer-setup-hook #'vertico-repeat-save) :bind (("M-R" . vertico-repeat))) - ;; (use-package vertico-buffer - ;; :after vertico - ;; :init - ;; (setq vertico-buffer-display-action - ;; '(display-buffer-at-bottom (window-height . ,(+ 3 vertico-count)))) - ;; (vertico-buffer-mode -1)) + (use-package vertico-buffer + :after vertico + :init + (setq vertico-buffer-display-action + '(display-buffer-at-bottom (window-height . ,(+ 3 vertico-count)))) + (vertico-buffer-mode -1)) + #+end_src +* orderless + #+begin_src emacs-lisp + (defun orderless--strict-*-initialism (component &optional anchored) + (orderless--separated-by + '(seq (zero-or-more alpha) word-end (zero-or-more (not alpha))) + (cl-loop for char across component collect `(seq word-start ,char)) + (when anchored '(seq (group buffer-start) (zero-or-more (not alpha)))) + (when (eq anchored 'both) + '(seq (zero-or-more alpha) word-end (zero-or-more (not alpha)) eol)))) + + (defun orderless-strict-initialism (component) + (orderless--strict-*-initialism component)) + + (defun orderless-strict-leading-initialism (component) + (orderless--strict-*-initialism component 'start)) + + (defun orderless-strict-full-initialism (component) + (orderless--strict-*-initialism component 'both)) + + (defun jao-orderless--dispatch (pattern index _total) + (cond ((and (zerop index) (string-prefix-p "-" pattern)) + `(orderless-strict-full-initialism . ,(substring pattern 1))) + ((string-suffix-p "%" pattern) + `(orderless-regexp . ,(substring pattern 0 -1))) + ((string-equal "!" pattern) + '(orderless-literal . "")) + ((string-prefix-p "!" pattern) + `(orderless-without-literal . ,(substring pattern 1))))) + (setq orderless-style-dispatchers '(jao-orderless--dispatch)) #+end_src +* consult dir + #+begin_src emacs-lisp :tangle no + (use-package consult-dir + :ensure t + :bind (("C-x C-d" . consult-dir) + :map minibuffer-local-completion-map + (("C-x C-d" . consult-dir) + ("C-x C-j" . consult-dir-jump-file)))) + #+end_src +* embark +*** prompt format + #+begin_src emacs-lisp + (defvar jao-embark--brx + "^\\(\\([^ ] \\)+\\|RET\\|TAB\\|SPC\\)\\( *\\)\\([^ ]+ +\\)\\(.*\\)$") + + (defun jao-embark--cmp (x y) + (let* ((lxk (get-text-property 0 'kbd x)) + (lyk (get-text-property 0 'kbd y))) + (if (= lxk lyk) (string< x y) (< lxk lyk)))) + + (defun jao-embark--cmd-doc (cmd) + (propertize (car (split-string (or (embark--function-doc cmd) "") "\n")) + 'face 'embark-verbose-indicator-documentation)) + + (defun jao--max-len (strs) + (seq-reduce (lambda (m x) (max m (length x))) strs 0)) + + (cl-defun jao-embark--other (&key shadowed-targets &allow-other-keys) + (propertize (format "%s" (or shadowed-targets "")) + 'face 'embark-verbose-indicator-shadowed)) + + (cl-defun jao-embark--bindings (&key bindings &allow-other-keys) + (let* ((cmds (mapcar #'caddr bindings)) + (docs (mapcar #'jao-embark--cmd-doc cmds)) + (keys (mapcar (lambda (b) + (propertize (car (last b)) + 'face 'embark-keybinding)) + bindings)) + (cmds (mapcar (lambda (b) + (propertize (cadr b) 'face 'embark-command)) + bindings)) + (fmt (format "%%-%ds %%-%ds %%s\n" + (jao--max-len cmds) (jao--max-len keys))) + (res (seq-mapn (lambda (c k d) + (let ((n (if (string-prefix-p "embark-" c) + 10 + (length k)))) + (propertize (format fmt c k d) 'kbd n))) + cmds keys docs))) + (apply #'concat (seq-sort #'jao-embark--cmp res)))) + + (setq embark-verbose-indicator-buffer-sections + '(jao-embark--bindings "\n" target " " jao-embark--other)) + #+end_src * window config persistence #+begin_src emacs-lisp (use-package bookmark-view diff --git a/completion.org b/completion.org index 6f09336..af9bca4 100644 --- a/completion.org +++ b/completion.org @@ -2,6 +2,16 @@ #+title: Completion configuration #+auto_tangle: t +* imenu + #+begin_src emacs-lisp + (use-package imenu + :init (setq org-imenu-depth 7) + :config + (defun jao-imenu-hook () + (cond ((derived-mode-p 'org-mode) (org-reveal t)) + (outline-minor-mode (outline-show-entry)))) + (add-hook 'imenu-after-jump-hook #'jao-imenu-hook)) + #+end_src * completion styles #+begin_src emacs-lisp (setq tab-always-indent 'complete @@ -14,43 +24,62 @@ completion-ignore-case t completion-wrap-movement t completion-auto-select nil - completion-styles '(basic partial-completion substring emacs22) + completions-format 'one-column + completion-styles '(basic substring partial-completion emacs22) completion-category-overrides '((file (styles partial-completion)) (command (styles initials substring partial-completion)) (symbol (styles initials substring partial-completion)) (variable (styles initials substring partial-completion)))) #+end_src -* imenu +* orderless #+begin_src emacs-lisp - (use-package imenu - :init (setq org-imenu-depth 7) + (use-package orderless + :ensure t + :init + (setq completion-styles '(orderless)) :config - (defun jao-imenu-hook () - (cond ((derived-mode-p 'org-mode) (org-reveal t)) - (outline-minor-mode (outline-show-entry)))) - (add-hook 'imenu-after-jump-hook #'jao-imenu-hook)) + (orderless-define-completion-style orderless+initialism + (orderless-matching-styles '(orderless-initialism + orderless-prefixes + orderless-literal + orderless-regexp))) + (setq completion-category-overrides + '((command (styles orderless+initialism)) + (symbol (styles orderless+initialism)) + (variable (styles orderless+initialism))) + orderless-matching-styles + '(orderless-literal orderless-regexp orderless-prefixes))) #+end_src -* orderless +* vertico #+begin_src emacs-lisp - (use-package orderless + (use-package vertico :ensure t :init - (defun jao-orderless--dispatch (pattern _index _total) - (cond ((string-suffix-p "-" pattern) - `(orderless-strict-full-initialism . ,(substring pattern 0 -1))) - ((string-suffix-p "%" pattern) - `(orderless-regexp . ,(substring pattern 0 -1))) - ((string-equal "!" pattern) - '(orderless-literal . "")) - ((string-prefix-p "!" pattern) - `(orderless-without-literal . ,(substring pattern 1))))) - - (setq completion-styles '(orderless) - orderless-skip-highlighting nil - orderless-component-separator " +" - orderless-matching-styles '(orderless-literal orderless-prefixes) - orderless-style-dispatchers '(jao-orderless--dispatch))) + (setq vertico-count 10 + vertico-cycle t + vertico-resize t + org-refile-use-outline-path t + resize-mini-windows t) + + :config + + (defun jao-vertico--display-candidates (lines) + (move-overlay vertico--candidates-ov (point-min) (point-min)) + (overlay-put vertico--candidates-ov 'after-string (apply #'concat lines)) + (vertico--resize-window (length lines))) + + (advice-add 'vertico--display-candidates + :override #'jao-vertico--display-candidates)) + + (use-package vertico-directory + :after vertico + :bind (:map vertico-map (("RET" . vertico-directory-enter) + ("M-" . vertico-directory-delete-word) + ("" . vertico-directory-delete-char)))) + + (vertico-mode) + #+end_src * mct #+begin_src emacs-lisp @@ -73,7 +102,7 @@ jao-buffer-same-mode vc-retrieve-tag))) - (mct-minibuffer-mode 1) + ;; (mct-minibuffer-mode 1) ;; (mct-region-mode 1) #+end_src @@ -139,7 +168,9 @@ (defun corfu-in-minibuffer () "Enable Corfu in the minibuffer only if Mct/Vertico are not active." - (unless (bound-and-true-p mct--active) (corfu-mode 1))) + (unless (or (bound-and-true-p mct--active) + (bound-and-true-p vertico--input)) + (corfu-mode 1))) (add-hook 'minibuffer-setup-hook #'corfu-in-minibuffer 1) @@ -301,25 +332,14 @@ (jao-consult-add-buffer-source 'jao-chat-buffer-source) #+end_src -* consult dir - #+begin_src emacs-lisp :tangle no - (use-package consult-dir - :ensure t - :bind (("C-x C-d" . consult-dir) - :map minibuffer-local-completion-map - (("C-x C-d" . consult-dir) - ("C-x C-j" . consult-dir-jump-file)))) - #+end_src * embark -*** packages +*** package #+begin_src emacs-lisp (use-package embark :ensure t :demand t :init (setq embark-quit-after-action nil - embark-verbose-indicator-buffer-sections - '(jao-embark--bindings "\n" target " " jao-embark--other) embark-indicator #'embark-mixed-indicator embark-mixed-indicator-both nil embark-verbose-indicator-excluded-commands @@ -330,48 +350,8 @@ (window-parameters (mode-line-format . none)) (window-height . fit-window-to-buffer))) - (defvar jao-embark--brx - "^\\(\\([^ ] \\)+\\|RET\\|TAB\\|SPC\\)\\( *\\)\\([^ ]+ +\\)\\(.*\\)$") - - (defun jao-embark--cmp (x y) - (let* ((lxk (get-text-property 0 'kbd x)) - (lyk (get-text-property 0 'kbd y))) - (if (= lxk lyk) (string< x y) (< lxk lyk)))) - - (defun jao-embark--cmd-doc (cmd) - (propertize (car (split-string (or (embark--function-doc cmd) "") "\n")) - 'face 'embark-verbose-indicator-documentation)) - - (defun jao--max-len (strs) - (seq-reduce (lambda (m x) (max m (length x))) strs 0)) - - (cl-defun jao-embark--other (&key shadowed-targets &allow-other-keys) - (propertize (format "%s" (or shadowed-targets "")) - 'face 'embark-verbose-indicator-shadowed)) - - (cl-defun jao-embark--bindings (&key bindings &allow-other-keys) - (let* ((cmds (mapcar #'caddr bindings)) - (docs (mapcar #'jao-embark--cmd-doc cmds)) - (keys (mapcar (lambda (b) - (propertize (car (last b)) - 'face 'embark-keybinding)) - bindings)) - (cmds (mapcar (lambda (b) - (propertize (cadr b) 'face 'embark-command)) - bindings)) - (fmt (format "%%-%ds %%-%ds %%s\n" - (jao--max-len cmds) (jao--max-len keys))) - (res (seq-mapn (lambda (c k d) - (let ((n (if (string-prefix-p "embark-" c) - 10 - (length k)))) - (propertize (format fmt c k d) 'kbd n))) - cmds keys docs))) - (apply #'concat (seq-sort #'jao-embark--cmp res)))) - :bind (("C-;" . embark-act) ("C-'" . embark-dwim) - ;; ("C-h b" . embark-bindings) (:map minibuffer-local-map (("C-'" . embark-dwim) ("C-," . embark-become) -- cgit v1.2.3