bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#47012: xref copies keymap properties to minibuffer


From: Dmitry Gutov
Subject: bug#47012: xref copies keymap properties to minibuffer
Date: Mon, 5 Apr 2021 05:15:52 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1

On 05.04.2021 01:55, Juri Linkov wrote:
This is the simplest implementation:
#+begin_src emacs-lisp
(defun project-find-word (regexp)
    "Word-based version of ‘project-find-regexp’.
Modifies the ‘xref-search-program-alist’ template
to add the option ‘-w’ that matches whole words."
    (interactive (list (project--read-regexp)))
    (let ((xref-search-program-alist
           (mapcar (lambda (p)
                     (cons (car p) (replace-regexp-in-string "<C>" "-w \\&" 
(cdr p))))
                   xref-search-program-alist)))
      (project-find-regexp regexp)))
#+end_src

Wouldn't it work the same if you instead modify the regexp to be surrounded
with \b...\b?

Indeed, with more typing.

I meant that your project-find-word would do that to the regexp, instead of trying to alter the template.

Ideally, there should be an isearch command
that will send the constructed regexp to 'project-find-regexp' from
isearch word-mode, symbol-mode like:

#+begin_src emacs-lisp
(define-key isearch-mode-map "\C-xpg" 'isearch-project-find-regexp)

(defun isearch-project-find-regexp ()
   (interactive)
   (let ((isearch-recursive-edit nil))
     (isearch-done nil t)
     (isearch-clean-overlays))
   (let ((regexp (cond ((functionp isearch-regexp-function)
                        (funcall isearch-regexp-function isearch-string))
                      (isearch-regexp-function (word-search-regexp 
isearch-string))
                      (isearch-regexp isearch-string)
                      (t (regexp-quote isearch-string)))))
     (project-find-regexp regexp))
   (and isearch-recursive-edit (exit-recursive-edit)))
#+end_src

But unfortunately it fails on ripgrep with:

   Search failed with status 123: regex parse error

Maybe because ripgrep can't swallow Emacs regexps.

That's right: it doesn't understand constructs like "\\<ChangeLog\\>".

I've been meaning to experiment with removing Emacs-specific instructions from the regexp, using the result in a search, and then postprocessing with "correct" regexp later, but still haven't gotten around to that.

FIXME in xref--regexp-to-extended is somewhat related.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]