diff --git a/Eask b/Eask index ce22870..8abadc4 100644 --- a/Eask +++ b/Eask @@ -20,5 +20,6 @@ (depends-on "f") (depends-on "ht") (depends-on "mbs") +(depends-on "s") (setq network-security-level 'low) ; see https://github.com/jcs090218/setup-emacs-windows/issues/156#issuecomment-932956432 diff --git a/vertico-flx.el b/vertico-flx.el index ea6e996..280b249 100644 --- a/vertico-flx.el +++ b/vertico-flx.el @@ -6,7 +6,7 @@ ;; Author: Shen, Jen-Chieh ;; URL: https://github.com/jcs-elpa/vertico-flx ;; Version: 0.1.0 -;; Package-Requires: ((emacs "27.1") (vertico "0.22") (flx "0.5") (flx-style "0.1.1") (ht "2.0") (f "0.20.0") (mbs "0.1.0")) +;; Package-Requires: ((emacs "27.1") (vertico "0.22") (flx "0.5") (flx-style "0.1.1") (ht "2.0") (f "0.20.0") (mbs "0.1.0") (s "1.12.0")) ;; Keywords: convenience vertico flx ;; This file is NOT part of GNU Emacs. @@ -34,6 +34,7 @@ (require 'f) (require 'ht) (require 'mbs) +(require 's) (require 'vertico) (require 'flx) @@ -45,7 +46,10 @@ :group 'convenience :link '(url-link :tag "Repository" "https://github.com/jcs-elpa/vertico-flx")) -(defvar vertico-flx--old-completion-style nil +(defconst vertico-flx-completion-styles '(flx) + "Completion styles to set when completing.") + +(defvar vertico-flx--old-completion-styles nil "Different completion style when completing using minbuffer.") (defvar vertico-flx--sorting nil @@ -143,15 +147,23 @@ If optional argument FLIP is non-nil, reverse query and pattern order." (defun vertico-flx--minibuffer-setup (&rest _) "Hook for minibuffer setup." (unless vertico-flx--minibuffer-setup-p - (setq vertico-flx--old-completion-style completion-styles - completion-styles '(flx) - vertico-flx--minibuffer-setup-p t))) + (setq vertico-flx--old-completion-styles completion-styles + completion-styles vertico-flx-completion-styles + vertico-flx--minibuffer-setup-p t) + (add-hook 'post-command-hook #'vertico-flx--post-command nil t))) (defun vertico-flx--minibuffer-exit (&rest _) "Hook for minibuffer exit." - (setq completion-styles vertico-flx--old-completion-style + (setq completion-styles vertico-flx--old-completion-styles vertico-flx--minibuffer-setup-p nil)) +(defun vertico-flx--post-command (&rest _) + "Hook for minibuffer post command." + (when (mbs-finding-file-p) + (setq completion-styles (if (s-contains-p ":" (minibuffer-contents)) + '(basic flx) + vertico-flx-completion-styles)))) + (defun vertico-flx--enable () "Enable `vertico-flx-mode'." (add-hook 'minibuffer-setup-hook #'vertico-flx--minibuffer-setup 100)