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: Juri Linkov
Subject: bug#47012: xref copies keymap properties to minibuffer
Date: Fri, 02 Apr 2021 11:25:59 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

>>>>> Please try (setq xref-file-name-display 'project-relative).
>>>> Thanks, I didn't know about this.  Shouldn't this be the default value
>>>> since this is what's displayed by grep and ripgrep.
>>>
>>> I wouldn't mind, personally.
>> This is added to the patch below too.
>
> LGTM.

Pushed now.

>> What is the real problem for me is that after navigating to
>> a project's subdirectory (with e.g. dired) and typing 'C-u C-x p g',
>> it doesn't provide the current directory as the default value.
>> It inserts the project root by default, not its subdirectory:
>>    Base directory: /project/root/
>> whereas 'M-x rgrep' conveniently provides default-directory as default.
>
> Makes sense, fixed in 4798dc0c51, please check it out.

Thanks, now it's more handy.

>> BTW, is it possible to make 'project-find-regexp' more compatible with 
>> 'rgrep'
>> in other features too?  What is missing is a way to modify the constructed
>> command line.  For example, often I need to add "-w" to the constructed 
>> command
>> to match words only.  In 'C-u M-x rgrep', this is easy to do,
>> but not in 'C-u C-x p g'.
>
> That's not so easy to do: the exact command is concealed inside the helper
> function in another package (xref). I suppose it's possible to rearrange
> things such that command creation and its execution are two different
> phases, but TBH I wouldn't love the result. Though I agree it might
> be handy.

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

It has one minor issue:
while it correctly filters out lines without word matches,
when a line with a word match contains also the same string
that is not a complete word, then both are highlighted as matches.
There is no such problem in grep where matches are highlighted
by the grep program itself.

BTW, the above implementation was based on a similar command for rgrep:

#+begin_src emacs-lisp
(defun wrgrep ()
  "Word-based version of ‘rgrep’.
Modifies the grep-find template to add the option ‘-w’ that matches whole 
words."
  (interactive)
  (let ((grep-host-defaults-alist nil)
        (grep-find-template
         (replace-regexp-in-string "<C>" "-w \\&" grep-find-template)))
    (call-interactively 'rgrep)))
#+end_src

> What I've been thinking we should have instead, is some kind of graphical
> prompt with multiple fields, where you can by default input the regexp and
> press RET, but you can also see the other options (like the file name glob
> to filter by, whether to search the "external roots" or not, whether to
> search only a particular directory, whether to ignore case, whether to
> search in the project-ignored files as well; options which modify the
> regexp or matching logic like your -w could be added too).
>
> Note that several of the options enumerated above are not something we
> could expose in the "edit the command" interface, because the command gets
> the list of files from stdin.
>
> Maybe it would be presented like one-line prompt where you can reach
> further fields using TAB, and maybe expand into some multiline pane (still
> inside the minibuffer) if some options can't fit on the same line, and you
> reach the end of that line by TAB-bing.
>
> To sum up, if we managed to create some visual interface for specifying the
> options that project-find-regexp has control over, maybe it would both
> result in a less complex interaction between packages, as well as in a more
> powerful UI which more people will be happy with.

Sounds like a widget-based form-filling with fields.  Actually, such fields
already exist in xref-search-program-alist template with placeholders
<D>, <X>, <F>, <C>, <R> that are expanded by grep-expand-template.





reply via email to

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