Getting Emacs ada-mode working

This is probably because Gentoo is not supported, so Alire cannot know if the external dependency is installed or not. You should answer Yes to the question, since re2c is indeed available and should work.

I guess this is the issue for supporting Gentoo: gentoo portage · Issue #23 · alire-project/alire · GitHub

1 Like

I’ve managed to build an AppImage of the ada-mode executables. All the ada-mode executables are inside the AppImage, so using it a an usual executable AppImage doesn’t make much sense.

The AppImage acts as ada_mode_wisi_lalr_parse, but all the executables are inside and can be extracted and directly used, since they are mostly statically linked.

There’s probably a better way to bundle this, so that it is more plug-and-play, but I guess it’s already an improvement for people not building their own copy of the executables.

More details in GitHub - mgrojo/emacs-ada-mode-binaries: AppImages of the Emacs ada-mode executables

By the way, the install command builds some of the Ada files again, I don’t know why. Consequently, I’m not entirely sure if all the files are being compiled in the release profile.

1 Like

This is probably because Gentoo is not supported, so Alire cannot know if the external dependency is installed or not.

Ah, indeed, that would explain it. :slight_smile:

You should answer Yes to the question, since re2c is indeed available and should work.

It did! Thanks. :slight_smile: Nice. i’ll update the Gentoo wiki Ada page accordingly.

I guess this is the issue for supporting Gentoo: gentoo portage · Issue #23 · alire-project/alire · GitHub

i’ve just subscribed to that issue; if i might be able to help with adding/testing Gentoo support, please let me know.

Oh also, a significant contributor to the overall amount of time taken by the installation process was the deep/full cloning of repositories. Are there any design-level issues that require Alire to use deep clones? Could a setting be added to only clone to a certain depth, both globally and locally-overridable? i couldn’t seem to find such a setting in the docs, nor in the output of alr settings [--global] --list

Are you using Alire 2.0? I’d say it does shallow cloning.

Edit: indeed, it passes --depth 1, see "un-git" the releases deployed from git repos · Issue #1455 · alire-project/alire · GitHub

Sorry i’ve taken so long to get back to you on this! i have had a lot on my plate, and i do actually have adhd, but, still …

So. i’m definitely using alr 2.0, and alr is definitely being used by the ada-mode build.sh script. But when i do a fresh install of ada-mode (via ELPA) and then do ./build.sh, i get output like:

Cloning into '/home/alexis/.config/emacs/elpa/ada-mode-8.1.0/alr-iran.tmp'...
[...]
Receiving objects: 100% (48758/48758), 240.39 MiB | 1.59 MiB/s, done.

which seems oddly large for a --depth=1 clone. i tried to manually clone the ada-mode git repo (cgit interface to it), but with --depth=1 added, following the “anonymous clone” instructions on this page, so that i could compare it to the output of build.sh, but that resulted in:

$ git clone --depth=1 https://git.savannah.nongnu.org/git/ada-mode.git
Cloning into 'ada-mode'...
warning: You appear to have cloned an empty repository.

And indeed, the cloned directory is empty.

The --depth=1 appears to result in a useless clone in this case - because there’s no master branch??

Leave out the --depth=1 & re-clone. Now you have the repo, you can git switch org.emacs.ada-mode to get the contents you’re after.

It’s a monorepo, with many branches, see git_checkout.sh for the designed worktree setup.

What I’ve done is

  • make a parent directory, e.g.ada-mode.
  • in ada-mode, clone the repo into org.emacs.ada-mode.
  • in org.emacs.ada-mode, git switch org.emacs.ada-mode, then git_checkout.sh. This results in a load of parallel directories, org.emacs.gpr-mode etc.

The reason the download is so large is that it contains some branches for Stephe’s work-in-progress and some very large historical objects, and hasn’t been garbage-collected for a long time. While I was trying to find why we were having so much trouble using ada-mode, I managed to get the repo down to under 30 MB!

I’ve saved that as a private repo on Github; private because I’m far from expert at elisp and I wouldn’t want to be the only maintainer (I’m at the same stage of life as Stephe), and Github because I find it much more friendly than savannah.gnu.org. I’d be happy to make it public, for informational use.

1 Like

Oh, sorry, i wasn’t clear.

The reason i was specifically trying to manually clone with --depth=1 was to check whether it resulted in the same (large) download done when alr cloned the repo as part of the build.sh script; and the reason i was doing that was because that large download had made me assume that alr didn’t use --depth=1 by default.

But the rest of your message explains what was going on: alr was almost certainly using --depth=1 when cloning, but the repo in its entirety involves a large download for even a shallow clone. So that’s that mystery solved. :slightly_smiling_face: Thanks!

On the topic of Elisp, i wouldn’t claim to be an expert, but i have created a number of Elisp packages, the most recent of which is Ebuku (which i still actively use and maintain). As i already have too many things on my plate, i’m in no position to become a maintainer, but i might be able to help with some ELisp-related issues …

Pity, but Emacs 29.3 locks up in a 100% loop on loading an ada source file.

I started it in lisp debug mode with minimal X. Then it loads the file at least , but inserting a skel. wants to start the wisi parser and locks up.

Also I noticed lots of full-stops in the loaded adb file, when I looked afterwards. Like it was done in the first step of some scan for reformatting…
j.

Welcome to the forum!

Pity, but Emacs 29.3 locks up in a 100% loop on loading an ada source file.

i’ve spent some time wrangling ada-mode in an attempt to get it working, as i describe starting in this comment in another thread:

Interesting: trying to open the body file in Emacs causes Emacs to pause seemingly indefinitely, with the following message in the echo area, until i C-g.

waiting for wisi parser Ada start in buffer less_trivial_trie.adb

After the C-g, i can switch to that buffer without issues.

As i’m on Emacs 29.3 myself, with tree-sitter support having been added to Emacs in 29.1 (released 30 July 2023), i tried ada-ts-mode, and had a much better experience than i did with ada-mode:

[W]hat i did just now was install ada-ts-mode via Emacs’ package manager, without uninstalling ada-mode. It installed without issues. i then opened less_trivial_trie.adb - in doing so, i was informed that there was no tree-sitter grammar installed, and would i like to install one from <url>? i answered yes, it installed without issues, and the file was syntax-highlighted. :slight_smile: A very quick and painless process …

Looking at the source of ada-ts-mode.el, it doesn’t depend on ada-mode. It does, however, basically make itself the provider of ada-mode.

All in all, i’d say ada-ts-mode feels very promising indeed

One issue with ada-ts-mode at this point is its lack of indentation support, although that’s something the mode’s author is working on. However, one can nevertheless use the Ada Language Server for indentation; refer to this issue in the ada-ts-mode repo, in which the ada-ts-mode dev helped me get that set up.

Given the preceding, i’d say that, unless one can’t move to Emacs 29.1 or later for some reason, people should definitely give ada-ts-mode a go.

For all those lusting after new ada-mode for emacs this is what worked
for me on debian trixie on an x86_64 box and I guess it will work on
other distributions with emacs version ±29. :

binaries from here:

then (as per readme):
chmod +x emacs_ada_mode-8.1.0-x86_64.AppImage
./emacs_ada_mode-8.1.0-x86_64.AppImage --appimage-extract
mv squashfs-root/usr/bin/* ~/.local/bin
mv squashfs-root/usr/lib/* ~/.local/lib

.el files and manual from here:

and here:

and here:

Happy hacking.
j.

1 Like

I found a real Ada-mode torture file. Old Ada-95 stuff with lots of nesting and difficult constructions.
So I got lots of “I don’t love you”'s in the message buffer. And even data loss because of my impatience with the beast while re-tabbing.

These settings in .emacs took care of the issues:
under:
(custom-set-variables
'(jit-lock-defer-time 1.5)
'(wisi-incremental-parse-enable t)
'(wisi-process-time-out 10.0))

Do read the write-up in the manual on slow machines.
j.

1 Like

A couple of weeks ago, I started with https://github.com/sebastianpoeplau/ada-light-mode/blob/dbba0a397905ecc39fc78d7d2df043cda902de3b/ada-light-mode.el, stripped out the parts I didn’t need, & have been happy with it. In particular, I was happy to forgo the language server problems. (However, I’m new to Ada & write only very basic Ada code at this time. The solution might not work for more experienced Ada programmers.)

I’ve been testing both ada-light-mode and ada-mode with Eglot and company-mode, and the light version is better integrated than the other. But ada-mode has many features that are missing in ada-light-mode. It would be nice if someone with experience in Emacs Lisp would be able to improve the eglot mode in ada-mode and simplify other parts of ada-mode.

1 Like

i’ve developed several Emacs Lisp packages, including Ebuku and a simple mode for PicoLisp (which i created because i was unaware of the PicoLisp distribution providing a library for such a mode - it was undocumented).

As per my adventures described earlier in this thread, i found getting ada-mode working to be significantly more complex than any other language mode i’ve tried/used in my 25+ years of using Emacs; and when i looked at the contents of the ada-mode package, i felt that trying to understand how it all works would probably involve a steep learning curve. Finally, Leake has retired as a project maintainer; has/have any new maintainer(s) been found?

Given my preexisting FOSS commitments, i’m not in any place to take on work in this area. But i wonder if, given the complexity of ada-mode (and, possibly, its maintainership status), a number of people might actually find it more time- and energy-efficient to instead try to build missing functionality around ada-ts-mode, which was a much more pleasant experience for me than ada-mode, and which (i believe) is still actively maintained. (Although i’m aware that ada-ts-mode requires the Emacs 29.x series - first released over a year ago - but there are probably people stuck on older versions, for various reasions.)

i’m wondering if it might be helpful to explicitly list the functionality provided by ada-mode whose absence was felt when trying to use the other modes?

There’s no project maintainer for ada-mode as far as I know.

What I miss when using ada-light-mode or ada-ts-mode is:

  • Ada menu including useful commands provided by the mode for better discoverability of commands and their key bindings.
  • Command for building the project.
  • Show all references to an entity.
  • Find file in project.
  • Find other file (from ads to adb and viceversa). I know that ada-ts-mode provides a command, but why not in the menu and with a C-c ... key binding?
  • And the most important point: indentation working out of the box. In fact, I was unable to make indentation work for ada-ts-mode (even with eglot, when the info in an issue says it is supported. And for ada-light-mode it worked with eglot, but you cannot force the line breaks where you want, even after setting this in my project:
   package Pretty_Printer is
      for Default_Switches ("Ada") use ("-i3", "--spaces-only");
   end Pretty_Printer;

On the other hand, I was unable to use ada-mode with Ada Language Server, when it is supported according to the manual.

The best experience with eglot was using ada-light-mode and company-mode so I’m not sure in which area ada-ts-mode is actually better, besides a bit more syntax highlighting. Ideally, all the functionality provided by the Ada Language Server should be exploited, as it is clearly the future.

But i wonder if, given the complexity of ada-mode (and, possibly, its maintainership status), a number of people might actually find it more time- and energy-efficient to instead try to build missing functionality around ada-ts-mode, which was a much more pleasant experience for me than ada-mode, and which (i believe) is still actively maintained.

Well, in fact that is more or less what Leake proposed in his points 3 and 4 as a way ahead reducing maintenance burden. One option is trimming ada-mode and the other is merging ada-ts-mode and ada-light-mode and build on top of that base.

Unfortunately, my knowledge of Emacs Lisp is minimal, so I would only could help in this effort with beta testing.

1 Like

Hi, I’m the author of ada-ts-mode. I’ll try to speak to each of your concerns and am open to making changes that improves the user experience. I apologize in advance that this response ended up being rather lengthy.

One of the problems I had with ada-mode is that it was too opinionated for my liking, so it became difficult to disable or change the way some of it was setup. I was trying to avoid the same mistakes (or what I perceived as mistakes) with ada-ts-mode, but maybe the pendulum swung too far in the opposite direction, lol.

I do believe in discoverability, that is why I have the entire manual for ada-ts-mode also as the README in the GitHub repository. I didn’t want to duplicate information and I also didn’t want to leave anything out, so I have the README converted into the Info manual and installed with the package. I also made sure that you can get help on user options and also go directly to the manual from the help buffer (pressing “i” in the help buffer for a user configuration will take you directly to the relevant section of the Info manual).

I wrestled a bit with where to draw the line with regards to the mode overstepping vs. not providing enough out-of-the-box configuration. What I settled on (at least for the moment), was to try and document what I thought someone might want to configure in the example configuration section of the README. This includes LSP-based indentation, key bindings for commands, etc. Maybe this is insufficient, or maybe there is a better approach. I’m open to suggestions on how to improve this.

When you say menu, are you just talking about a menu for commands? What about Imenu as well? I’ll have to look at what commands ada-mode has listed on their menu, as it’s been a long time since I’ve looked and I don’t think I personally ever used it that way.

For Imenu at least, you are just a M-x imenu-add-menubar-index away. You could also add this to the mode hook. I can add this to the example configuration if it would help. Personally, I use consult-imenu (and imenu in Emacs 30 with the imenu-flatten setting), so this is another case where people may use different approaches to solve their problem. I typically bind consult-imenu to C-c C-m. I don’t like choosing people’s key bindings, because everyone has different key chord styles they prefer, especially when it comes to the Control key and where it resides on their keyboard.

One thing I also tried to avoid was reinventing the wheel. If there is something built-in to Emacs outside the mode that supports the desired functionality, I didn’t see a need to supply it within ada-ts-mode. For project-based functionality, I lean on the built-in project.el. For building the project, does project-compile (i.e., C-x p c) not work for you?

Not being too opinionated also means not forcing a specific compilation command. Do you use Alire, gprbuild, gnatmake, a Makefile, or some other non-GNAT build command? Because this is vastly different (especially in production systems), I think it makes sense for people to customize compile-command, likely in a .dir-locals.el.

If the above does not work for you, please let me know.

This is a job for the Language Server, since you need to know about the entire project. When using Eglot, it will hook into Emacs Xref, so xref-find-references (mapped to M-? by default) should provide this for you. If I’m using lsp-mode, I typically map lsp-ui-peek-find-references to this key binding.

What about project-find-file (i.e., C-x p f)?

Yes, as mentioned above, I didn’t want to be opinionated about people’s preferred key bindings, so I have an example of how to bind ada-ts-mode-find-other-file in the example configuration in the README.

See below for updating Eglot, as the version shipped with Emacs 29 is immature, missing features and contains some bugs. I don’t know the details of your specific issue, but feel free to file an issue on the ada-ts-mode GitHub page. LSP-based Indentation is supported and does work with Eglot, but you probably need to configure the language server (which I’ve sent a patch upstream to automatically do), but isn’t in the current Emacs 29 release of Eglot (it is in the Eglot development version though).

As far as the Pretty_Printer settings, I find the following configuration to be useful to support indentation, and I do mention it in the “Ada Language Server Indentation” section of the README. I’ve been told the formatting engine is supposed to be overhauled in the next ALS release, so hopefully this will get better.

   package Pretty_Printer is
      for Default_Switches ("Ada") use ("--source-line-breaks");
   end Pretty_Printer;

Put please log a GitHub issue if you are struggling with this and I can help you there.

I need to get back to working on the tree-sitter based indentation. I’ll at least add a feature branch of my work-in-progress in the near future.

I took a quick look at ada-light-mode and it appears they are patching Eglot, where it was missing functionality, within the mode. This is because the version of Eglot shipped in Emacs 29 is immature at best. I’ve preferred to avoid applying patches for other modes within ada-ts-mode.

I’ve also discovered and reported issues upstream to the Eglot author and some of the bugs have now been fixed, but you’ll need to upgrade Eglot to get these. Also, it’s best if you can use the GNU devel ELPA, since the stable version of Eglot hasn’t been updated since March. I can share my current Eglot use-package configuration with you if that would help. If you don’t upgrade Eglot to the latest stable version, ada-ts-mode-find-project-file won’t work due to missing functionality in Eglot. You can find out how to upgrade in the Eglot manual (M-x eglot-upgrade-eglot).

I personally prefer to use lsp-mode with ada-ts-mode because it supports semantic highlighting and Eglot doesn’t, but either LSP client should work with ada-ts-mode. Eglot does keep getting better and better over time though, but the release cycle is much longer than lsp-mode whose updates are available almost immediately from MELPA. I do use Eglot with gpr-ts-mode though, since there is no semantic highlight support in the language server for GPR files.

I agree completely with this. If you have ideas on how to exploit it that haven’t been achieved, please share them with me. You can file an issue on the GitHub page if you like. I don’t want ada-ts-mode to be dependent on a Language Server (hence the reason I want to add intrinsic indentation support), but I do want the mode to take advantage of the Language Server if you’ve enabled it, to enhance the experience. A good example of this is ada-ts-mode-find-other-file which will query the Language Server if an LSP client is active in the buffer, and then fallback to the Emacs ff-find-other-file functionality if LSP is not active.

5 Likes

Welcome to the forum, and thanks for chiming in! i’d been planning to write a post with some of the points you mentioned, e.g. i was going to mention xref, and Projectile (albeit not project.el; here’s a relatively recent Reddit thread comparing both), but i’m glad you’ve beaten me to it. :slight_smile:

On the topic of keybindings in particular, i’m of the opinion that not providing a set of default keybindings, and forcing users to have to manually set up keybindings, makes for a Less Than Awesome OOTB experience. On the other hand, i also agree with not forcing users to accept a particular set of keybindings, particularly given those keybindings might clash with their existing setup.

i faced this issue when developing the pulseaudio-control package, and what i ended up doing was creating a pulseaudio-control-default-keybindings command that users can run if they want a “just give me at least some keybindings to use” experience .

1 Like

I am terrible at Emacs so I apologize if this is a silly quesiton, but if an ada mode package set a bunch of keybindings out of the box, is it not possible for a user to override those later in a setting (or is that not a thing in emacs?)?

Yes, you can override keybindings in Emacs. You’ll probably need to use Emacs Lisp for this, but you can do it by issuing commands interactively as well. Here’s a good place to look for the details: Key Bindings (GNU Emacs Manual)

1 Like