Lacking Natural Simplicity

Random musings on books, code, and tabletop games.

Maintaining the old ada-mode.el formerly distributed with Emacs

I wrote a post about using the old ada-mode.el that used to be distributed with Emacs because I couldn't get the newer, separate package version to work for me.

Well, this morning when I pulled up an Ada file in Emacs version 28 there were two problems:

  1. The information to invoke ada-mode on Ada files was not in the auto-mode-alist variable in Emacs. That was easy enough to fix: add .ada, .ads, and .adb to auto-mode-alist (and .gpr, too, since Ada mode works for gprbuild files as well):

    (cl-loop for ext in '("\\.gpr$" "\\.ada$" "\\.ads$" "\\.adb$")
      do (add-to-list 'auto-mode-alist (cons ext 'ada-mode)))
    

    That was easy enough.

  2. When I tried to do any indentation emacs reported an error, with the error message “End position is smaller than start position”. Eventually I tracked this down to a call to parse-partial-sexp in ada-in-open-paren-p. It turns out that somewhere after Emacs version 27.2 was released the Emacs developers added a check to parse-partial-sexp to ensure that the FROM argument (which indicates where in the buffer to start parsing) was less than the TO argument (which indicates where in the buffer to stop parsing).

Drat. Drat. Drat. Well, looking at the code it was clear that since ada-in-open-paren-p is explicitly searching backwards that TO would always be smaller than FROM. So I could just transpose the s-expressions that found those two values. I tried it, and it worked!

At that point I realized that I had committed to maintain the old version of ada-mode, at least for myself, and that I'd already talked about it on my blog and it was small step from there to setting up a GitHub repository with the old code, adding an issue describing the problem, adding a commit with the fix, and then writing this blog post.

Somewhere, someone is laughing and enjoying the schadenfreude. Maybe this will help someone else.

And since I already have a GitHub repository, I ought to document the first problem and since it is a documentation problem, put a mention in the README.

Print Friendly and PDF

Comments

Comments powered by Disqus