From eb46c6a27726d19ff73b536d985db367871a0af9 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 11 Aug 2021 22:06:46 -0500 Subject: Add lots of orderless stuff --- init.el | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'init.el') diff --git a/init.el b/init.el index c4bf72a..b848593 100644 --- a/init.el +++ b/init.el @@ -1236,7 +1236,57 @@ if ripgrep is installed, otherwise `consult-grep'." :host github :repo "oantolin/orderless")) (require 'orderless) - (:option (append completion-styles) 'orderless)) + + (:option (append completion-styles) 'orderless + orderless-component-separator #'orderless-escapable-split-on-space + orderless-style-dispatchers '(acdw/orderless-dispatch)) + + (defun fix-dollar (args) + (if (string-suffix-p "$" (car args)) + (list (concat (substring (car args) 0 -1) "[\x100000-\x10FFFD]*$")) + args)) + (advice-add #'orderless-regexp :filter-args #'fix-dollar) + + (defun acdw/orderless-dispatch (pattern _index _total) + "My custom dispatcher for `orderless'." + (cond + ;; Ensure that $ works with Consult commands, which add disambiguation + ;; suffixes -- see `fix-dollar' + ((string-suffix-p "$" pattern) + `(orderless-regexp . ,(concat (substring pattern 0 -1) + "[\x100000-\x10FFFD]*$"))) + ;; File extensions + ((string-match-p "\\`\\.." pattern) + `(orderless-regexp . ,(concat "\\." (substring pattern 1) + "[\x100000-\x10FFFD]*$"))) + ;; Ignore single ! + ((string= "!" pattern) + `(orderless-literal . "")) + ;; Character folding + ((string-prefix-p "%" pattern) + `(char-fold-to-regexp . ,(substring pattern 1))) + ((string-suffix-p "%" pattern) + `(char-fold-to-regexp . ,(substring pattern 0 -1))) + ;; Without literal + ((string-prefix-p "!" pattern) + `(orderless-without-literal . ,(substring pattern 1))) + ((string-suffix-p "!" pattern) + `(orderless-without-literal . ,(substring pattern 0 -1))) + ;; Initialism matching + ((string-prefix-p "`" pattern) + `(orderless-initialism . ,(substring pattern 1))) + ((string-suffix-p "`" pattern) + `(orderless-initialism . ,(substring pattern 0 -1))) + ;; Literal matching + ((string-prefix-p "=" pattern) + `(orderless-literal . ,(substring pattern 1))) + ((string-suffix-p "=" pattern) + `(orderless-literal . ,(substring pattern 0 -1))) + ;; Flex matching + ((string-prefix-p "~" pattern) + `(orderless-flex . ,(substring pattern 1))) + ((string-suffix-p "~" pattern) + `(orderless-flex . ,(substring pattern 0 -1)))))) (setup (:straight org) (:straight org-contrib) -- cgit 1.4.1-21-gabe81