1

When switching projects, there's a few commands available off the bat that can be selected from the mini-buffer after selecting a project.

[f] Find file [g] Find regexp [d] Find directory ...

Both find file and find directory and interactive. i.e., live results are shown as you type search terms.

However, Find regexp (project-find-regexp from project.el) does not. The prompt is simply: Find regexp: and as you type there's no live results shown and therefore no immediate feedback as to whether the regex provided as matching any results.

How might I define use-package for project and/or consult to adjust this initial behaviour of project-find-regexp?

Some relevant snippets of my init.el are as follows:


(use-package consult
  :bind (
          ("C-s" . consult-line)
          ("C-x b" . consult-buffer)
          ("M-g M-g" . consult-goto-line)
          ("M-g g" . consult-goto-line)
          ("M-s f" . consult-find)
          ("M-s r" . consult-ripgrep)
          ("M-y" . consult-yank-pop)
          )
  :commands (consult-completing-read-multiple)
  :config
  (setq consult-project-root-function
    (lambda ()
      (let ((p (project-current)))
        (when p (project-root p)))))

  (defvar rah/consult-line-map
    (let ((map (make-sparse-keymap)))
      (define-key map "\C-s" #'vertico-next)
      map))

  (advice-add #'completing-read-multiple
    :override #'consult-completing-read-multiple)

  (consult-customize
    consult-line
    :history t ;; disable history
    :keymap rah/consult-line-map
    consult-buffer consult-find consult-ripgrep
    :preview-key (kbd "M-.")
    consult-theme
    :preview-key '(:debounce 1 any)
    )
  )

(use-package consult-dir
  :bind (
          ("C-x C-d" . consult-dir)
          )
  :bind (:map minibuffer-local-completion-map
          ("C-x C-d" . consult-dir)
          ("C-x C-j" . consult-dir-jump-file)
          ))

(use-package consult-project-extra
  :bind (
          ("C-c p f" . consult-project-extra-find)
          ("C-c p o" . consult-project-extra-find-other-window)
          ))

(use-package consult-xref
  :after (consult xref)
  :commands (consult-xref)
  :init
  (setq xref-show-definitions-function #'consult-xref
    xref-show-xrefs-function #'consult-xref)
  )

(use-package project
  :bind-keymap (
                 ("C-x p" . project-prefix-map)
                 )
  :bind (:map project-prefix-map
          ("m" . magit-project-status)
          )
  :commands (project-root)
  :config
  (add-to-list 'project-switch-commands '(magit-project-status "Magit") t)
  )

1 Answer 1

2

You cat just use consult-ripgrep to override project-find-regexp through:

(advice-add #'project-find-regexp :override #'consult-ripgrep)
1
  • 1
    Thanks @tianshu-wang that's perfect!
    – ldeck
    Jun 10, 2022 at 2:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.