From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#68958: [PATCH] Support bookmarking Xref results buffers Date: Thu, 15 Feb 2024 19:57:08 +0200 Message-ID: <622b208a-6e2a-4f47-b243-40846ec48df1@gutov.dev> References: <86le7wzcjj.fsf@gnu.org> <0b3f4669-180e-466f-96f3-7eeae994581f@gutov.dev> <1bea3fe4-51aa-418b-a55f-f09d0a4c558e@gutov.dev> <653af486-3b3b-4270-8385-ee3af6639eb5@gutov.dev> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36960"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: Eli Zaretskii , 68958@debbugs.gnu.org To: Eshel Yaron Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Feb 15 18:58:09 2024 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 1rafzr-0009Jp-Et for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 15 Feb 2024 18:58:08 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rafzV-000156-06; Thu, 15 Feb 2024 12:57:45 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rafzT-00014i-Jw for bug-gnu-emacs@gnu.org; Thu, 15 Feb 2024 12:57:43 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rafzT-0001No-Bp for bug-gnu-emacs@gnu.org; Thu, 15 Feb 2024 12:57:43 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rafzl-00089r-Ju for bug-gnu-emacs@gnu.org; Thu, 15 Feb 2024 12:58:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 15 Feb 2024 17:58:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68958 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 68958-submit@debbugs.gnu.org id=B68958.170801985931324 (code B ref 68958); Thu, 15 Feb 2024 17:58:01 +0000 Original-Received: (at 68958) by debbugs.gnu.org; 15 Feb 2024 17:57:39 +0000 Original-Received: from localhost ([127.0.0.1]:56921 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rafzP-000899-6S for submit@debbugs.gnu.org; Thu, 15 Feb 2024 12:57:39 -0500 Original-Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:51727) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rafzM-00088p-V1 for 68958@debbugs.gnu.org; Thu, 15 Feb 2024 12:57:37 -0500 Original-Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id C64A23200A01; Thu, 15 Feb 2024 12:57:11 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 15 Feb 2024 12:57:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1708019831; x=1708106231; bh=EBggH70Wz8oBC0PisZUMw8QOX5jOJn9RnLtuDXVCISM=; b= ZNJ8P30rdf3lcmPDCWZCHqiEFkdn96/OfCI0mRrcBjGwq7BgRSzWId2M7UPIFQGh G7L4LlMKLqU08qLcATwarZN12zKoMvEbc2KvOxszXblZdypxex+3Gv077r4tiDKb 6xJ/bX0D+XwrLOvtnt9fAdnxyvfoNXhHstpBvMfrysiwVDXV5F3IVGCfjRaYW2y6 wP2DMSwQJBBjEL8hmPOhRfS5QP8oVoZEcqE0Pn1JthIzUQP9YlhP+9TUlfU7gY6x r85CH4ZeS42r9US60XzPvYNBVhfwMJonRYLaMi8a6CFi9AjdObdWR4J1JTJQ3S1L 8zxD/vF7umAmVjVylxh+7w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1708019831; x= 1708106231; bh=EBggH70Wz8oBC0PisZUMw8QOX5jOJn9RnLtuDXVCISM=; b=N TFc7xz3GGX8CLM6rjWJtp0wIOLmpq+HD8vyoq7IsXce8HutiOG/tC3mR0BkUBhBF hf1r2d641DtK0MlCIGtuCBtZQl4nTCyHiTdu6h5YcGiILHslgKGmeXTUsAtmzDId w20RUnkE1O35mVzdU+WNE3+MXMFcPl8bdL22qfPHwAgaStuBCo4ujDgmL++R3/VF u5zIiJF5HAETnSv+mgPKD0MAN6D9YgnT9Xc+rxRWfC6cHwHIlRmJDiYNPkFARwJ5 YD4RNv2/GQ4UBM9TPJRbmQfZGokm+WwJXvGfHdEl3nE4kO/yZNL0w93YMt+tWJMA A7Wu6+xhXJHWwdHBg3t6A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddtgddutdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtvdejnecuhfhrohhmpeffmhhi thhrhicuifhuthhovhcuoegumhhithhrhiesghhuthhovhdruggvvheqnecuggftrfgrth htvghrnhepteduleejgeehtefgheegjeekueehvdevieekueeftddvtdevfefhvdevgedu jeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepug hmihhtrhihsehguhhtohhvrdguvghv X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 15 Feb 2024 12:57:10 -0500 (EST) Content-Language: en-US In-Reply-To: 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:280070 Archived-At: On 13/02/2024 09:10, Eshel Yaron wrote: > Dmitry Gutov writes: > >> On 12/02/2024 13:45, Eshel Yaron wrote: >> >>> I agree that redundant complexity is better avoided, but this is the >>> simplest compatible extension to the API I came up with to implement >>> this feature. >> >> If we're going to recommend the callers use the new capability, I'd >> rather they didn't have to be redundant every time. > > Often callers can use xref-make-fetcher to make the fetcher function, > and that takes care of the redundant work for them. That's was I did > for project-find-regexp and friends in my working branch, works well :) > > [ BTW, while at it, I noticed that the docstring for > project-or-external-find-regexp mentions a prefix argument, but the > function doesn't actually handle one. ] Thank you for noting, now fixed. >> Though I'm not sure whether the fetcher should reach >> xref-show-xrefs-function intact (simpler code, but a breakage in the >> interface, which could be mended with catching >> wrong-number-of-arguments), or like in this example, both the original >> fetcher and the arguments should be passed through alist. >> >> Otherwise, the requirements on the arguments are the same (fetcher -- >> named function, args -- printability). > > That might work, although it seems rather difficult to explain such > requirements, and it's difficult for callers to ensure or even check > whether they're kept (how do you know if your argument is too big > without printing it in advance?) You can usually track that on the level of user input. A good rule of thumb would be not to pass a generated list of files. And if some user's interactive input string is veeeeeery long, well, whatever disk space is wasted as a result is their own doing. What's the alternative, though? Writing a separate bookmark storage function for every sort of search? For project, lsp-mode/eglot (they both have additional commands doing extra searches), etc? And the return value of xref-backend-context (from your proposal) must likewise be print-able and compact enough, right? > Furthermore, IIUC, what you get is an opaque function and argument list, > and the frontend cannot reason about these, it can only apply the > function to these arguments to get a list of xrefs. In contrast, > xref-fetcher-alist provides clear (documented) semantics. Which will only work for Xref's own commands but not for any external callers of xref-show-xrefs. Right? > We use it for > bookmarking first and foremost, but the frontend can legitimately use it > for other stuff too, like showing some info in the mode line. > >> Also, I'm not sure how we're supposed to guarantee that >> xref--original-buffer is live. > > In my patch, we don't guarantee that (see xref-bookmark-make-record). > And that's fine, it's a best effort to give the backend all the context > it might need. If there's no original buffer, we just don't save and > restore that bit of context. Okay, I see that. Basically, you bookmark the "original point" and then restore it from xref-backend-restore. So this would work, most of the time. > The backend can handle a nil CONTEXT > argument in xref-backend-restore however it sees fit. By default, it > does nothing. I don't any LSP backend could handle nil, though. It would need additional data, like the origin file name, the value of point, etc. >> Is that for use with desktop-mode only? > > What do you mean? To be clear, this is unrelated to desktop-mode, or at > least I didn't design/implement any of this with desktop-mode in mind. I meant that if you require the original buffer to be available when the bookmark is loaded, the easiest way to satisfy that is for desktop-mode to be used. But I see you solved that in a different way. >> And it seems like as soon as the buffer has some new changes, the >> bookmark is likely to become invalid (the same value of point will >> point to a different identifier). > > We don't keep the value of point as such, we use the standard bookmark > facilities to save some context around point so we can relocate to the > right place if something changes. If we can't find that context when > restoring the bookmark, point is just left at the beginning of the > *xref* buffer. That's also fine. Does that make sense? I meant the position of point in the original buffer, not in the Xref buffer, which is required for the Xref searches to work in LSP backends. I suppose the same bookmark mechanism would be used, too, though.