From 1f5be956ef77ebaaf425bc7a4de5a49f5a8e63ca Mon Sep 17 00:00:00 2001 From: Guangxiong Lin Date: Sat, 19 Mar 2022 22:07:30 +0800 Subject: Improve minibuffer related commands (emacs) --- .emacs.d/lisp/init-minibuffer.el | 46 +++++++++++++++++++++++++++++++++++++++- .emacs.d/lisp/init-projectile.el | 6 ++---- 2 files changed, 47 insertions(+), 5 deletions(-) (limited to '.emacs.d') diff --git a/.emacs.d/lisp/init-minibuffer.el b/.emacs.d/lisp/init-minibuffer.el index a0a5c98..83a2498 100644 --- a/.emacs.d/lisp/init-minibuffer.el +++ b/.emacs.d/lisp/init-minibuffer.el @@ -1,3 +1,5 @@ +;; -*- lexical-binding: t -*- + (gx/maybe-require-package 'consult) (when (gx/maybe-require-package 'vertico) @@ -8,6 +10,22 @@ vertico-cycle t) (when (gx/maybe-require-package 'orderless) + (setq orderless-matching-styles '(orderless-literal orderless-regexp)) + + (defun gx/orderless-without-if-bang (pattern _index _total) + (cond + ((equal "!" pattern) + '(orderless-literal . "")) + ((string-prefix-p "!" pattern) + `(orderless-without-literal . ,(substring pattern 1))))) + + (defun gx/orderless-flex-if-twiddle (pattern _index _total) + (when (string-suffix-p "~" pattern) + `(orderless-flex . ,(substring pattern 0 -1)))) + + (setq orderless-style-dispatchers '(gx/orderless-without-if-bang + gx/orderless-flex-if-twiddle)) + (defun gx/setup-completion-in-minibuffer () (setq-local completion-styles '(substring orderless) completion-category-defaults nil @@ -21,10 +39,36 @@ (kbd "fm") 'consult-recent-file (kbd "fc") 'execute-extended-command (kbd "fl") 'consult-line - (kbd "fs") 'consult-imenu) + (kbd "fs") 'consult-imenu + (kbd "fa") 'consult-org-agenda) (evil-define-key 'normal 'eglot--managed-mode (kbd "fS") 'consult-eglot-symbols))) +(when (executable-find "rg") + (setq affe-grep-command + "rg --null --line-buffered --color=never --max-columns=1000 \ +--path-separator / -v ^$ \ +--smart-case --no-heading --line-number --hidden --glob !.git .")) + +(when (executable-find "fd") + (setq affe-find-command + "fd --type f --hidden --follow --exclude .git")) + +(when (gx/maybe-require-package 'affe) + (with-eval-after-load 'evil + (evil-define-key 'normal 'global + (kbd "ff") 'affe-find + (kbd "fr") 'affe-grep)) + (with-eval-after-load 'orderless + (defun gx/affe-orderless-regexp-compiler (input _type _ignorecase) + (setq input (orderless-pattern-compiler input)) + (cons input (lambda (str) (orderless--highlight input str)))) + (setq affe-regexp-compiler #'gx/affe-orderless-regexp-compiler)) + (with-eval-after-load 'consult + (consult-customize + affe-grep affe-find + :preview-key (kbd "C-c C-p")))) + (setq consult-preview-key (kbd "C-c C-p")) (when (gx/maybe-require-package 'savehist) diff --git a/.emacs.d/lisp/init-projectile.el b/.emacs.d/lisp/init-projectile.el index 08c1124..4169387 100644 --- a/.emacs.d/lisp/init-projectile.el +++ b/.emacs.d/lisp/init-projectile.el @@ -1,5 +1,5 @@ (when (gx/maybe-require-package 'projectile) - (add-hook 'after-init-hook (lambda () (projectile-mode 1)))) + (add-hook 'after-init-hook #'projectile-mode)) (with-eval-after-load 'projectile (gx/diminish 'projectile-mode)) @@ -9,8 +9,6 @@ (with-eval-after-load 'evil (evil-define-key 'normal projectile-mode-map - (kbd "fp") 'projectile-switch-project - (kbd "ff") 'projectile-find-file - (kbd "fr") 'projectile-ripgrep)) + (kbd "fp") 'projectile-switch-project)) (provide 'init-projectile) -- cgit v1.2.3