From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daniel =?UTF-8?Q?Mart=C3=ADn?= via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#49731: 28.0.50; Filter xref results by filename Date: Tue, 27 Jul 2021 19:08:00 +0200 Message-ID: References: <030dbe6c-130d-e578-f50d-54e90bfa7cfa@yandex.ru> Reply-To: Daniel =?UTF-8?Q?Mart=C3=ADn?= Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23301"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (darwin) Cc: 49731@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jul 27 19:12:02 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m8Qcb-0005pQ-Ud for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 27 Jul 2021 19:12:02 +0200 Original-Received: from localhost ([::1]:38014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m8Qca-00089d-UN for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 27 Jul 2021 13:12:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58398) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8QZi-0001El-U5 for bug-gnu-emacs@gnu.org; Tue, 27 Jul 2021 13:09:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42226) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m8QZi-0001Fo-KU for bug-gnu-emacs@gnu.org; Tue, 27 Jul 2021 13:09:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m8QZi-0006sG-Fr for bug-gnu-emacs@gnu.org; Tue, 27 Jul 2021 13:09:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Daniel =?UTF-8?Q?Mart=C3=ADn?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 27 Jul 2021 17:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49731 X-GNU-PR-Package: emacs Original-Received: via spool by 49731-submit@debbugs.gnu.org id=B49731.162740569426356 (code B ref 49731); Tue, 27 Jul 2021 17:09:02 +0000 Original-Received: (at 49731) by debbugs.gnu.org; 27 Jul 2021 17:08:14 +0000 Original-Received: from localhost ([127.0.0.1]:53772 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m8QYv-0006r1-OJ for submit@debbugs.gnu.org; Tue, 27 Jul 2021 13:08:14 -0400 Original-Received: from sonic302-21.consmr.mail.ir2.yahoo.com ([87.248.110.84]:42466) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m8QYt-0006qg-5d for 49731@debbugs.gnu.org; Tue, 27 Jul 2021 13:08:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.es; s=s2048; t=1627405683; bh=Pm3yz+ZVYxAKgsq29qJNOPxohDr2Nggme5lkqZn6nj8=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From:Subject:Reply-To; b=PEE7y11YOOZYdGnCeKGY7JChv84Byrxzl5PDPmX5ANZFgmX48DGZDlG81mR1E1fyXri87u/aootHyry+5/WufnMNrrBvfoDDmG+bJyBh/SXuim5NWOKSjkzyT2kzStwMTdJQdrkJPH3nYxjTWNi6CnTB6dtdu4WCsV+C77RmJFASdmbrewo61lPBlVvERSm8V8Jpkjwb5kmR7ZoxYEpSGxQchpVVbDcZf608pWdsFH9HuucbbGpvK/dF7N4QUcVybD/uuwE1fXJBULq6jU3YvqtGq+2n+nfQ3NxMZxdceuavjRaznGqN1vuPY0Gll8yhLIa6fLrLXpuQbdiwHLz4cw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1627405683; bh=RaHf7PKDrREQiJyCz7E7In/r5XejYp5uyopx4EUIig6=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=ReSEqekfOdQH1DPhAHVpdXcxnsqpv/o/XeGN8rGLIntAGGpNcVZpBbhuEi/HxdlHiKc7DcH7nXIDMvVoJSbSKCR0HG6gzXV/fin/Plvr5bZEtti0hmTK7+8/gADzFm/EvXLvCayKtgBjrPJXnYIOuIWrjzFKCKjCMNQvYyZo11vjLWen5VR09V8hWWUlkqACToKIeJkNTfKpj9XVDgtwG2A+cRZ69X+lJ5catfIN3eBnQnoVHZn+UhmR51LkuswnanhIq1eRRcVsOExul62GKLdKB3cADj5kfpzx7CZzekWdjoPFnMOloB2G7G4W/u1hhqTWcaP6fejplUHRVCKROQ== X-YMail-OSG: YdI05fYVM1nh5ZW1gF_RcDu6LIkkhFmlY1O0zaXBSJhfX64hMiNFj1sdMZ2VNjU ReJs1yCoM2gBU1D57aD7QAqmVwxuIXVUYml2yyu28G8hINccHKiWqqLY.5N2CpEvxDaLAekUTWs6 Mx60Lndi8cX2MEYtywumXAP0DmCVucBEb.MbhxX_ZMiIgX.wBRSKHdfps0otkgza.uuJ5a0Djsmm Bu3yixaymaLzv3RR9TxyMeNIYq5xkUWnTzw2ZfOFo2yNj62J0Nt31X4ntnkLvD.B_HsqrsbhR224 CQtwIzvmGvg2WAr7AvkC_XjwZAQ2o5KuUEbn4DhwTLPDMretn.U8gN8qXStURUPLm8ZQHfExRXi8 1LpaTt0BGuOCHf3HqfuneF3bTe8Etnz4HXnGwzRkSgztKyLANdGgM43JXGaYWJQSBjTyaFunJnf3 jdRTSQEA_1e9ZB3vY_B4JCOB48NWFdAz8E1fa33c6nFVGW5ehXOWXluGoiDhRHl.2Q6YnJsPqR6J 4gSN5tLBq67zTgtD1q6BF5_CK7nFYjlSG3qngMwfIA5wYI3bNnP63J3B1yvFJvqDlfSpFKxcWgJa WXOX8y_Gxt5LEu39OIqkMO6LfjFFsVyE6C9OKyEHWS.5nZnImieuI4LCwD0khpBll2UeSh_vfnbt 63wybIpBFAhN1wYw3M9d230TukICPvg62sjp8RyX7_U.Oo4E4H6MXDWqcLrn3NEHlKxBJs7E4fJM uGHdrHk0h3tRmgkTtURZeueqX7fBdHwLlSKfWlhKSYdncLCxSlSTLSYljj.q7.wCZQA6CcJ_vgng 3hVCSdTwShND7r4PlSnK1d2VgNCXuTtZd1EC3QTe6l X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.ir2.yahoo.com with HTTP; Tue, 27 Jul 2021 17:08:03 +0000 Original-Received: by kubenode553.mail-prod1.omega.ir2.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 564fa334980f7a68168fa17decdfbe29; Tue, 27 Jul 2021 17:08:01 +0000 (UTC) In-Reply-To: <030dbe6c-130d-e578-f50d-54e90bfa7cfa@yandex.ru> (Dmitry Gutov's message of "Tue, 27 Jul 2021 02:28:58 +0300") X-Mailer: WebService/1.1.18749 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:210800 Archived-At: Dmitry Gutov writes: > > We've discussed this sort of functionality before. Here are some > approaches (not mutually exclusive): > > 1. Add the possibility to add filtering by file names, types, etc, > before the search is done. This should fit 'project-find-regexp' > well. I can point you to a previous discussion with some ideas. The > main upside is you can speed up the search. And store such settings as > a history. I think that kind of search scoping in advance can be specially useful when you are doing a grep-like search in the codebase, using either grep, rgrep, project-find-regexp, or xref-find-apropos. I see it less useful for example when you place the point in an identifier and press M-?. You'll want to see all the references first, and then filter afterwards if they are too many. But I think it's a matter of personal preferences and different workflows. > > 2. Filter in the resulting Xref buffer. The best part is it can work > with the output from any command that uses Xref. The "filtering" is > temporary. I'm assuming this is the direction you want to work in. > Yes, that's the direction that interests me the most, if it's actually a worthy feature for Emacs users. > > I've never exactly considered the option 2., but I'd be happy to talk > the details. WRT UI, maybe something along the lines of > package-menu-filter-* commands, bound inside a '/' prefix. One command > could add "inclusion filter", another - "exclusion filter", and the > third one - reset all filters. '/ /' be bound to the last one. > I didn't have in mind implementing cumulative filters. I don't know if people would need such advanced filtering of results. FTR, I've researched how other tools and IDEs implement this feature, which is less common than what I initially thought: - Xcode: In the references panel there is a filter box on the bottom so that you type and filter the results to keep those that match the pattern. - IntelliJ IDEA: I haven't seen a similar functionality. There is a button to remove references from automatically generated code, but that's all. - Sourcegraph: It doesn't seem to offer a similar functionality. - Chromium Code Search: It offers a box to filter by file path. It also offers an option to exclude tests and generated files. > > Another thing to keep an eye out for - is how the filtering will > affect n/p navigation and the xref-query-replace-in-results command. I > think they should respect the filtering as well. Here's a first quick and dirty prototype based on Juri's code snippet: diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index e2cd904a6c..27ff08f7ce 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -665,6 +665,36 @@ xref-goto-xref ;; Emacs < 27 (setq next-error-last-buffer buffer)))) +(declare-function outline-show-entry "outline" ()) +(declare-function outline-hide-body "outline" ()) + +(defun xref-filter-results-by-file (pattern) + "Filter xref results to only include those in files that match PATTERN." + (interactive (list (read-string + "Filter results in files that match pattern (regexp): " + nil nil))) + (require 'outline) + (setq-local outline-regexp + (if (eq xref-file-name-display 'abs) "/" "[^ 0-9]")) + (outline-minor-mode +1) + (outline-hide-body) + (save-excursion + (goto-char (point-min)) + (let ((count 0)) + (while (progn + (when (re-search-forward pattern (line-end-position) t) + (outline-show-entry) + (setq count (1+ count))) + (xref--search-property 'xref-group))) + (when (zerop count) + (message "No match") + (xref-exit-results-filter))))) + +(defun xref-exit-results-filter () + "Remove any xref filter and show the full list of results." + (interactive) + (outline-minor-mode -1)) + (defun xref-quit-and-goto-xref () "Quit *xref* buffer, then jump to xref on current line." (interactive) @@ -824,6 +854,8 @@ xref--xref-buffer-mode-map (define-key map (kbd ",") #'xref-prev-line) (define-key map (kbd "g") #'xref-revert-buffer) (define-key map (kbd "M-,") #'xref-quit-and-pop-marker-stack) + (define-key map (kbd "f") #'xref-filter-results-by-file) + (define-key map (kbd "q") #'xref-exit-results-filter) map)) (define-derived-mode xref--xref-buffer-mode special-mode "XREF" I've bound the new command to "f". For simplicity, each time you press "f" you'll filter the entire list (filters are not cumulative). As you said, pressing "p" and "n" navigate results that are folded, which is confusing. Perhaps a new minor mode in xref could do the outline folding and also make sure that "p" and "n" skip results that are folded.