From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: David Fussner via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#53749: 29.0.50; [PATCH] Xref backend for TeX buffers Date: Mon, 21 Feb 2022 09:48:30 +0000 Message-ID: References: <1de34060-e93b-0a42-fff5-20e283abe0dc@yandex.ru> Reply-To: David Fussner Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39778"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 53749@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 21 11:08:41 2022 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 1nM5cW-000AE7-Su for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 21 Feb 2022 11:08:40 +0100 Original-Received: from localhost ([::1]:52344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nM5cV-00054D-FF for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 21 Feb 2022 05:08:39 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:48230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nM5JW-0004se-U5 for bug-gnu-emacs@gnu.org; Mon, 21 Feb 2022 04:49:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41187) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nM5JW-0004G0-Jj for bug-gnu-emacs@gnu.org; Mon, 21 Feb 2022 04:49:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nM5JW-0004Im-I1 for bug-gnu-emacs@gnu.org; Mon, 21 Feb 2022 04:49:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: David Fussner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 21 Feb 2022 09:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53749 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 53749-submit@debbugs.gnu.org id=B53749.164543693016501 (code B ref 53749); Mon, 21 Feb 2022 09:49:02 +0000 Original-Received: (at 53749) by debbugs.gnu.org; 21 Feb 2022 09:48:50 +0000 Original-Received: from localhost ([127.0.0.1]:35082 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nM5JK-0004I5-5o for submit@debbugs.gnu.org; Mon, 21 Feb 2022 04:48:50 -0500 Original-Received: from mail-qv1-f53.google.com ([209.85.219.53]:46035) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nM5JI-0004Hl-Be for 53749@debbugs.gnu.org; Mon, 21 Feb 2022 04:48:48 -0500 Original-Received: by mail-qv1-f53.google.com with SMTP id c14so30666733qvl.12 for <53749@debbugs.gnu.org>; Mon, 21 Feb 2022 01:48:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=I2hDIlzhuQa9wnxxeda3KakJlY/Clx5R1MusA5yU4R4=; b=MWBIoAm3edGHHgO/IgOxHeU1eQyGX4M7BGzcjwD4YYhxb/LjNt5LWSFmDUk69Y8sQJ EeFTZ+auiSzU7X1SHF70OVSpah9f+TKwfjUKd/ASgse3sVxMJDWTW6FIHZpZhFyGYxCD 0nijgeL8gkLWiCRd36mMUKEEWN4LeGUElInEn/4At0/ulugXl8hU46Yxjt+nhtrhW5A+ xufMDazRVgboYbtyRYzgnfbCLgpyk60C2IhRE2ed+x5Vr+oxwMo6/RP5nkgeLpPQtg79 9cXKMzLubcG9Wyu66lVPKOH36Me9QEdQnPt4PMOxPkWDbc2Ak52KCy+1Qu+8YMizHt+6 CSXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=I2hDIlzhuQa9wnxxeda3KakJlY/Clx5R1MusA5yU4R4=; b=WJXaVtdE8syCv6zjdu2TmFxo43fbcJlVlBsGPBWLIBndhHlhRxd7GKihSDsgDJd/N/ WNpsdnqR9WDAtnE6AXcfG82q/APkx4O5QFtpFdsTdtKChaui6sjgqhFZ/valFCrj5TB1 IGn4FWjRkTic40tI9vFaUYmepa4+lROAnAsCE2XRwVZYzLtYrg4bC5e6xgOCT+XJ7Bzl KZZqw7OOZ5VchG1gMSBUQq0k6pJ8Bji9Mg8vxEGFw1VCr9FjjzCwSaaS4oHPrWMRklmV TnJMIXggUA6qe6c2zmL+phXYwya87KZdTHSYUseY6Mkv+/CPnyd2cNvQLy0DJizqa2co hgvw== X-Gm-Message-State: AOAM532PSM/HSM1NIfmLGmUWNnKAZKWA1n3r6mn0jrl7buJWmM3qWlEh vn2csasdGxJfqUPRIEvuv81gtiZiHyx6XDOPOx0YtyRRL5m+Zg== X-Google-Smtp-Source: ABdhPJy05b+mq+hgv21tkaFsmTC7wxpcWy3TGrDZtbJ3TXr2hgPaWgCIg6dV/via3YEQ3VM0aW4mqLMJ7iHW6SE5RuE= X-Received: by 2002:a05:622a:1a16:b0:2de:37ad:25ef with SMTP id f22-20020a05622a1a1600b002de37ad25efmr1047861qtb.131.1645436922612; Mon, 21 Feb 2022 01:48:42 -0800 (PST) In-Reply-To: <1de34060-e93b-0a42-fff5-20e283abe0dc@yandex.ru> 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:227315 Archived-At: (Resending to include the mailing list -- sorry!) Hi Dmitry, Many thanks for looking into this. > > So if your main goal was to alter which string gets searched for (based > on text around point), you can define a function which returns the > necessary string (as you did in the patch) and then either set > 'find-tag-default-function' to that function, or put it on the > 'find-tag-default-function' property for the respective major mode > functions. > > > There are many other behaviors that are suboptimal, as well, so in the > > end I wrote a new xref backend for TeX buffers (cloning large portions > > of the default etags backend), and wondered whether it might be welcome > > in GNU Emacs. > > Could you point out the other changes which were required? As you've noticed, I tried at first to get by without a new backend, but I ran into a few issues that I couldn't solve that way, hence the current patch. A couple of examples: 1. TeX is very generous with the characters it includes in its symbols, so what looks like a standard symbol to it can look like a regexp either to grep or to emacs, so I needed to changes things in xref-find-apropos and in xref-find-references to take this into account. (See tex-xref-apropos-regexp and tex-xref-references-in-directory.) Sometimes using a search string that had been put through regexp-quote was wrong, as when a user provided their own regexp in the minibuffer, so in both those cases I provided fallbacks to a different search in case the default search came up empty. I couldn't see how to do this without a new backend. 2. A package like biblatex creates what amounts to a separate namespace using the \newbibmacro mechanism, so pretty much every biblatex style has both a \cite command and a cite bibmacro, and I wanted to allow emacs to differentiate between them when using xref-find-definitions. Because users of the etoolbox package (like biblatex) may well mix commands with and without the escape char "\", I also provided a variable to allow users to find when a \command is called using \csuse{command} instead. Again, this required a fallback search (see xref-backend-definitions) which I couldn't see how to provide without a new backend. Does this make any sense? I can give more specific examples if you like -- try running xref-find-references on a TeX command with "@" in it. (If memory serves, that behaved badly here on an unpatched emacs, but maybe I'm misremembering.) David. On Mon, 21 Feb 2022 at 02:11, Dmitry Gutov wrote: > > Hi! > > Let us first discuss whether we could make do without an additional Xref > backend. Just to make sure. > > On 03.02.2022 17:09, David Fussner via Bug reports for GNU Emacs, the > Swiss army knife of text editors wrote: > > Similarly, any xref command on 'my:citekey' will only search by default > > for the half of the symbol under point, stopping at the colon. > > etags's implementation of 'xref-backend-identifier-at-point' calls > 'find-tag--default', which consults 'find-tag-default-function' and > (get major-mode 'find-tag-default-function). > > So if your main goal was to alter which string gets searched for (based > on text around point), you can define a function which returns the > necessary string (as you did in the patch) and then either set > 'find-tag-default-function' to that function, or put it on the > 'find-tag-default-function' property for the respective major mode > functions. > > > There are many other behaviors that are suboptimal, as well, so in the > > end I wrote a new xref backend for TeX buffers (cloning large portions > > of the default etags backend), and wondered whether it might be welcome > > in GNU Emacs. > > Could you point out the other changes which were required?