Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Comments

Xref support for Agda2-mode#8181

Merged
jespercockx merged 2 commits intoagda:masterfrom
phikal:emacs/xref
Jan 29, 2026
Merged

Xref support for Agda2-mode#8181
jespercockx merged 2 commits intoagda:masterfrom
phikal:emacs/xref

Conversation

@phikal
Copy link
Contributor

@phikal phikal commented Nov 1, 2025

This was initially proposed in #6540, but I have now rebased it onto master with no additional dependencies (there might be merge-conflicts with the other PRs tough, not sure).

The idea here is the same as before, Xref is a standard Emacs UI for jumping to definition. Having a separate UI for the same thing inevitably runs up against minor paper cuts that annoy the user. As Xref supports a superset of what the annotation-based implementation provided, I hope that the approach is satisfactory and will not annoy anyone. IIRC new features we get for free include C-u M-. supporting prompting of identifiers and a grep-based backend to search for occurrences (eventually it would be better if we could replace this with a proper backend). A new feature is C-M-. (xref-find-apropos) that searches all open buffers for their identifiers and allows you to issue queries involving subphrases that might occur in an identifier in any order or regular expressions.

See #5917.

As mentioned in #6123 (comment) this merges annotations.el into agda2-highlight.el, as this changes makes the former become an unnecessary indirection.

@phikal phikal force-pushed the emacs/xref branch 2 times, most recently from 6505583 to 2d37c8e Compare November 1, 2025 16:26
@phikal phikal added the ux: emacs Issues relating to the Emacs agda2-mode label Nov 3, 2025
@phikal
Copy link
Contributor Author

phikal commented Nov 3, 2025

@jespercockx I think you missed this commit.

@jespercockx jespercockx added this to the 2.9.0 milestone Nov 4, 2025
@phikal phikal force-pushed the emacs/xref branch 2 times, most recently from 8a61254 to 1869e66 Compare November 6, 2025 21:14
@andreasabel
Copy link
Member

Agda dev 2025-11-12: This PR should be tested by several users for the look-and-feel of the new behavior.
Volunteers:

@nad
Copy link
Collaborator

nad commented Nov 12, 2025

Emacs complained when I tried to compile your code (make install-bin compile-emacs-mode):

In toplevel form:
[…]/Agda-2.9.0/emacs-mode/agda2-mode.el:2257:1:Error: the function ‘xref-apropos-regexp’ is not known to be defined.
Unable to compile the following Emacs Lisp files:
  […]/Agda-2.9.0/emacs-mode/agda2-mode.el

I'm using Emacs 27.1.

@AndrasKovacs
Copy link
Collaborator

I have tried this PR with Emacs 30.2 and it seems to work fine. The basic jump-to-definition function seems to behave the same as before.

@phikal
Copy link
Contributor Author

phikal commented Nov 12, 2025

@nad Can you try upgrading xref from ELPA? I am not sure if the Makefile uses local packages when compiling. Otherwise I can look to redefine/backport the necessary definitions.

@jespercockx
Copy link
Member

There's a conflict here now after merging some of your other PRs @phikal, could you please take a look?

@phikal
Copy link
Contributor Author

phikal commented Nov 24, 2025

Should be resolved.

@jespercockx
Copy link
Member

I still cannot do a clean rebase, I could squash and merge but then that would defeat the purpose of splitting it in three commits.

@phikal
Copy link
Contributor Author

phikal commented Nov 26, 2025

I've now manually rebased the commit onto agda/master, lets see if that makes a difference.

@jespercockx
Copy link
Member

I've now manually rebased the commit onto agda/master, lets see if that makes a difference.

Yes, that seems to have done the trick!

@nad did you have a chance to try out the suggestion of @phikal ?

@nad
Copy link
Collaborator

nad commented Nov 27, 2025

@nad Can you try upgrading xref from ELPA?

I don't think we should require users of Agda to do that.

@phikal
Copy link
Contributor Author

phikal commented Nov 27, 2025

I don't think we should require users of Agda to do that.

While I don't think that it is much to impose (especially if users install Agda via their package manager, then that can also install the newer version of Xref for them as well; but I'd also expect that most people are using releases of Emacs newer than 27), I can look into back-porting the newer definitions if you think that is the right way to go ahead.

@phikal
Copy link
Contributor Author

phikal commented Nov 28, 2025

I can look into back-porting the newer definitions if you think that is the right way to go ahead.

I pushed a commit doing this. The code is directly from Emacs, but as it is does not constitute a significant contribution, it shouldn't pose a copyright issue.

@jespercockx
Copy link
Member

@phikal the CI now gives an error on the elisp files:

In toplevel form:
.stack-work/install/x86_64-linux/1a3b758b945daa5d5a60949a822a32163a9ac421ebdac3111388f9237428b53b/9.12.2/share/x86_64-linux-ghc-9.12.2-9b33/Agda-2.9.0/emacs-mode/agda2-mode.el: Error: the function ‘apropos-parse-pattern’ is not known to be defined.
Unable to compile the following Emacs Lisp files:
  /home/runner/work/agda/agda/.stack-work/install/x86_64-linux/1a3b758b945daa5d5a60949a822a32163a9ac421ebdac3111388f9237428b53b/9.12.2/share/x86_64-linux-ghc-9.12.2-9b33/Agda-2.9.0/emacs-mode/agda2-mode.el
make: *** [Makefile:664: testing-emacs-mode] Error 1

Could you take a look please?

@phikal
Copy link
Contributor Author

phikal commented Dec 1, 2025

Looks like I just forgot to declare and require the right function, sorry about that!

@jespercockx
Copy link
Member

@nad could you check again if this PR works for you now?

@VojtechStep
Copy link

I'm pretty sure this broke the interactive highlight level for me, the highlighting does not go away. I'll keep testing and digging further

@phikal
Copy link
Contributor Author

phikal commented Dec 1, 2025

The CI failures appear to be unrelated to my change, right?

Either way, I have built a local Emacs 27 instance to check it myself, and while the byte-compiler doesn't complain, it appears I have some issue with resolving the Xref method... I cannot say if this is my mistake or not, so I'll have to take another look at this.

@mergify mergify bot mentioned this pull request Jan 17, 2026
@phikal phikal force-pushed the emacs/xref branch 4 times, most recently from ce2ab8a to e4e14bc Compare January 17, 2026 20:54
@phikal
Copy link
Contributor Author

phikal commented Jan 17, 2026

I have revised the PR onto master, throwing out the changes to annotation.el to make it less controversial (I recall that @nad was not happy with that) and change as little code as necessary. As the commit mostly just adds new code, the issues that @VojtechStep observed are also gone.

@phikal phikal force-pushed the emacs/xref branch 4 times, most recently from 1226e6e to 3a961f6 Compare January 17, 2026 23:03
@jespercockx
Copy link
Member

@phikal thank you for the update! Could you please fix the whitespace issue?

@nad are you happy with the expanation of @phikal or would you like to test it again on your system?

@phikal
Copy link
Contributor Author

phikal commented Jan 18, 2026

Fixed, was not aware that tabs were forbidden everywhere. BTW, has adding a EditorConfig ever been discussed?

@jespercockx
Copy link
Member

jespercockx commented Jan 18, 2026

Fixed, was not aware that tabs were forbidden everywhere. BTW, has adding a EditorConfig ever been discussed?

Not as far as I know, currently we just use fix-whitespace by @andreasabel but if we could replicate its functionality with a standard tool such as EditorConfig then I'd support that.

The main question would be whether we can also integrate it into CI.

@nad
Copy link
Collaborator

nad commented Jan 22, 2026

I tested this PR now. I used the following code:

A : Set₁
A = Set

B : Set₁
B = A

If I load the file, go to the final occurrence of A, and type M-., then I get the following error message:

cl-no-applicable-method: No applicable method: xref-backend-definitions, agda2, "A"

Output from M-x emacs-version:

GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33, cairo version 1.16.0) of 2024-09-17, modified by Debian

Philip Kaludercic and others added 2 commits January 23, 2026 11:27
By replacing the custom go-to-definition implementation with the
standard Xref interface, users may user familiar key bindings that
also support searching for definitions via an apropos-like interface.
By default Xref doesn't have a binding for mouse-clicks, so this
change adds that to the 'agda2-mode-map' by hand.
@phikal
Copy link
Contributor Author

phikal commented Jan 23, 2026

I could reproduce that issue and debug it on a local Emacs 27 build. Turns out that in Emacs 27's cl-generic the specializer (eql 'agda2) is not the same as (eql agda2), which we should have used. Interestingly cl-typep doesn't work this way even on later versions? So I have adjusted that in my last force push and it works as intended (on my machine).

@jespercockx
Copy link
Member

@nad do you want to test again or are you happy with @phikal 's explanation?

@TOTBWF
Copy link
Contributor

TOTBWF commented Jan 26, 2026

Is there a backwards compatibility policy for how many versions of emacs agda-mode ought to support? I know emacs 27 is what debian ships with, but it is nearly 5 years old at this point.

@phikal
Copy link
Contributor Author

phikal commented Jan 26, 2026

Is there a backwards compatibility policy for how many versions of emacs agda-mode ought to support? I know emacs 27 is what debian ships with, but it is nearly 5 years old at this point.

Debian stable has Emacs 30.1, Ubuntu LTS has 29.3, but according to this site there still are supported distributions like Rocky Linux 8 that have 26.1.

@nad
Copy link
Collaborator

nad commented Jan 29, 2026

@nad do you want to test again or are you happy with @phikal 's explanation?

Now the code seems to work for me.

@jespercockx jespercockx merged commit 496f495 into agda:master Jan 29, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ux: emacs Issues relating to the Emacs agda2-mode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants