From 14b2700fb84cc2dd86b6eca355bf036b63ae7195 Mon Sep 17 00:00:00 2001 From: Levi Neely <141506390+lneely@users.noreply.github.com> Date: Sat, 31 Aug 2024 16:11:13 +0200 Subject: [PATCH] finally got search / projectile working as i want it to --- emacs/init.el | 149 ++++++++++++++++++++++++++++---------------------- 1 file changed, 83 insertions(+), 66 deletions(-) diff --git a/emacs/init.el b/emacs/init.el index 078eb76..8de4755 100644 --- a/emacs/init.el +++ b/emacs/init.el @@ -18,21 +18,6 @@ (add-hook 'emacs-lisp-mode-hook #'my/setup-elisp-formatting-key) -(defun my/swiper-query-replace () - "Run `query-replace-regexp' on Swiper results." - (interactive) - (if (not (window-minibuffer-p)) - (user-error "Call this from swiper") - (let* ((enable-recursive-minibuffers t) - (from (ivy--regex ivy-text)) - (to (query-replace-read-to from - (concat "Query replace (regexp " from ") with: ") - t))) - (ivy-exit-with-action - (lambda (_) - (let ((case-fold-search (ivy--case-fold-p ivy-text))) - (query-replace-regexp from to))))))) - (defun my/visit-todo () "Visit TODO.org in home" (interactive) @@ -55,10 +40,10 @@ (get-text-property 0 'org-hd-marker item))) (line (when marker (org-with-point-at marker - (buffer-substring (line-beginning-position) (line-end-position))))) + (buffer-substring (line-beginning-position) (line-end-position))))) (todo-keyword (when marker (org-with-point-at marker - (org-get-todo-state)))) + (org-get-todo-state)))) (truncated-line (when line (replace-regexp-in-string "^\\[#[A-Z]\\] " "" line)))) (if truncated-line @@ -183,9 +168,6 @@ (global-set-key (kbd "") 'speedbar) (global-set-key (kbd "M-/") 'dabbrev-expand) - - (with-eval-after-load 'swiper - (define-key swiper-map (kbd "M-%") #'my/swiper-query-replace)) (global-set-key (kbd "C-=") 'multi-vterm-dedicated-toggle) (global-set-key (kbd "C-x r") 'replace-regexp) (global-set-key (kbd "C-x R") 'replace-string) @@ -391,7 +373,6 @@ (add-hook 'after-save-hook #'my-compile-init-file) -;; fuzzy find (use-package orderless :ensure t :custom @@ -488,51 +469,87 @@ ;;(add-to-list 'completion-at-point-functions #'cape-line) ))) - ;; better search - (use-package consult - :ensure t - :bind (("C-s" . consult-line) - ("C-r" . consult-line-multi) - ("C-c h" . consult-history) - ("C-c m" . consult-mode-command) - ("C-c k" . consult-kmacro) - ("C-c C-h" . consult-mode-histories) - ;; Add keybindings for ripgrep-related commands - ("C-c s" . consult-ripgrep) - ("C-c C-s" . consult-ripgrep-multi)) - :custom - (consult-preview-key nil) ; Disable preview - - :config - ;; Configure ripgrep for consult - (setq consult-ripgrep-command "rg --null --line-buffered --color=ansi --max-columns=1000 --no-heading --line-number . -e ARG OPTS") - - ;; Use ripgrep for `consult-grep` as well - (setq consult-grep-command "rg --null --line-buffered --color=ansi --max-columns=1000 --no-heading --line-number . -e ARG OPTS") - - ;; Configure mode-specific histories - (setq consult-mode-histories - '((comint-mode . comint-input-ring) - (eshell-mode . eshell-history-ring) - (geiser-repl-mode . geiser-repl--history) - (inferior-python-mode . comint-input-ring) - (minibuffer-local-map . consult-history))) +;; better search +(use-package consult + :ensure t + :demand t + :bind (("C-s" . consult-line) + ("C-r" . consult-line-multi) + ("C-c h" . consult-history) + ("C-c m" . consult-mode-command) + ("C-c k" . consult-kmacro) + ("C-c C-h" . consult-mode-histories) + ;; Add keybindings for ripgrep-related commands + ("C-c s" . consult-ripgrep) + ("C-c C-s" . consult-ripgrep-multi)) + :custom + (consult-preview-key nil) ; Disable preview + + :config + ;; Configure ripgrep for consult + (setq consult-ripgrep-command "rg --null --line-buffered --color=ansi --max-columns=1000 --no-heading --line-number . -e ARG OPTS") + + ;; Use ripgrep for `consult-grep` as well + (setq consult-grep-command "rg --null --line-buffered --color=ansi --max-columns=1000 --no-heading --line-number . -e ARG OPTS") + + ;; Configure mode-specific histories + (setq consult-mode-histories + '((comint-mode . comint-input-ring) + (eshell-mode . eshell-history-ring) + (geiser-repl-mode . geiser-repl--history) + (inferior-python-mode . comint-input-ring) + (minibuffer-local-map . consult-history))) - (consult-customize - consult-theme - :preview-key '(:debounce 0.2 any) - consult-ripgrep consult-git-grep consult-grep - consult-bookmark consult-recent-file consult-xref - consult--source-bookmark consult--source-recent-file - consult--source-project-recent-file - :preview-key '(:debounce 0.4 any)) + (consult-customize + consult-theme + :preview-key '(:debounce 0.2 any) + consult-ripgrep consult-git-grep consult-grep + consult-bookmark consult-recent-file consult-xref + consult--source-bookmark consult--source-recent-file + consult--source-project-recent-file + :preview-key '(:debounce 0.4 any)) - ;; Configure async search for better performance - (setq consult-async-min-input 2) - (setq consult-async-refresh-delay 0.15) - (setq consult-async-input-throttle 0.2) - (setq consult-async-input-debounce 0.1) + ;; Configure async search for better performance + (setq consult-async-min-input 2) + (setq consult-async-refresh-delay 0.15) + (setq consult-async-input-throttle 0.2) + (setq consult-async-input-debounce 0.1) - ;; Use Consult to select xref locations with preview - (setq xref-show-xrefs-function #'consult-xref - xref-show-definitions-function #'consult-xref)) + ;; Use Consult to select xref locations with preview + (setq xref-show-xrefs-function #'consult-xref + xref-show-definitions-function #'consult-xref)) + +(use-package projectile + :ensure t + :config + (projectile-mode +1) + :bind-keymap + ("C-x p" . projectile-command-map) + :bind (:map projectile-command-map + ("f" . consult-projectile-find-file) + ("d" . consult-projectile-find-dir) + ("b" . consult-projectile-switch-to-buffer) + ("s" . consult-projectile-switch-project) + ("p" . consult-projectile) + ("g" . consult-ripgrep))) + +(use-package consult-projectile + :ensure t + :after (consult projectile) + :config + ;; Override projectile functions with consult-projectile functions + (advice-add 'projectile-find-file :override #'consult-projectile-find-file) + (advice-add 'projectile-find-dir :override #'consult-projectile-find-dir) + (advice-add 'projectile-switch-to-buffer :override #'consult-projectile-switch-to-buffer) + (advice-add 'projectile-switch-project :override #'consult-projectile-switch-project) + + ;; Custom function to always use consult-projectile-find-file + (defun my-consult-projectile-find-file () + "Use consult-projectile-find-file, falling back to consult-projectile if not in a project." + (interactive) + (if (projectile-project-p) + (consult-projectile-find-file) + (consult-projectile))) + + ;; Replace the keybinding in projectile-command-map + (define-key projectile-command-map (kbd "f") #'my-consult-projectile-find-file))