Skip to content

Question: How to change default-directory when in consult-ripgrep #596

@lynnux

Description

@lynnux

Hi @minad, I use consult-ripgrep only search current dir not the whole project, code by this:

(defun my-consult-ripgrep(&optional dir)
             (interactive "P") 
             (require 'consult)
             (let  ((consult-ripgrep-args (concat consult-ripgrep-args " --no-ignore")))
               (consult-ripgrep (or dir default-directory)))
             )

and there is a function binding to C-l to change the directory to parent, code like this:

           (defun is-consult-ripgrep()
             (eq 'consult-grep
                 (completion-metadata-get
                  (completion-metadata (minibuffer-contents)
                                       minibuffer-completion-table
                                       minibuffer-completion-predicate)
                  'category)))
           (defun is-consult-line()
             (eq 'consult-location ;; 
                 (completion-metadata-get
                  (completion-metadata (minibuffer-contents)
                                       minibuffer-completion-table
                                       minibuffer-completion-predicate)
                  'category)))
           (defun my/vertico-C-l ()
	     (interactive)
             (if (is-consult-ripgrep)
                 (progn
                   (setq default-directory (file-name-directory (directory-file-name default-directory)))
                   (let ((text (substring-no-properties (or (car-safe vertico--input) ""))))
                     (delete-minibuffer-contents)
                     (insert text)
                     ))
               (call-interactively 'vertico-directory-delete-word)))
(define-key vertico-map (kbd "C-l") 'my/vertico-C-l)

When I invoke C-l, the search result is fine, but the C-n(vertico-next) not work as expect, and RET also not work.
22

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions