From 286f04c6ef5c1985ea7548d26ed09b1d76f8ee8b Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 13 Sep 2025 18:00:36 -0400 Subject: [PATCH] module: add :lang ada --- modules/lang/ada/README.org | 68 ++++++++++++++++++++++++++++++++++++ modules/lang/ada/auoload.el | 27 ++++++++++++++ modules/lang/ada/config.el | 44 +++++++++++++++++++++++ modules/lang/ada/doctor.el | 8 +++++ modules/lang/ada/packages.el | 6 ++++ static/init.example.el | 1 + 6 files changed, 154 insertions(+) create mode 100644 modules/lang/ada/README.org create mode 100644 modules/lang/ada/auoload.el create mode 100644 modules/lang/ada/config.el create mode 100644 modules/lang/ada/doctor.el create mode 100644 modules/lang/ada/packages.el diff --git a/modules/lang/ada/README.org b/modules/lang/ada/README.org new file mode 100644 index 000000000..78b4ddb2f --- /dev/null +++ b/modules/lang/ada/README.org @@ -0,0 +1,68 @@ +:PROPERTIES: +:ID: 0903d239-7eab-47d7-8b88-00420fe6a50f +:END: +#+title: :lang ada +#+subtitle: In strong typing we (blindly) trust +#+created: September 13, 2025 +#+since: 25.10.0 + +* Description :unfold: +This module adds support for the Ada and SPARK programming languages. + +- Syntax highlighting (optionally via tree-sitter) +- Code completion (via company or corfu) +- LSP support (with [[https://github.com/AdaCore/ada_language_server][ada_language_server]]) +- Alire integration (alr build, alr run, alr clean) + +** Maintainers +*This module needs a maintainer.* [[doom-contrib-maintainer:][Become a maintainer?]] + +** Module flags +# Flags should be in alphanumerical order. +- +lsp :: + Enable LSP support for ~ada-mode~ / ~ada-ts-mode~. Requires [[doom-module::tools lsp]] + and a langserver (supports [[https://github.com/AdaCore/ada_language_server][ada_language_server]]). +- +tree-sitter :: + Leverages tree-sitter for better syntax highlighting and structural text + editing. Requires [[doom-module::tools tree-sitter]] and Emacs 29.1+. + +** Packages +- [[doom-package:ada-mode]] +- [[doom-package:ada-ts-mode]] if [[doom-module:+tree-sitter]] + +** Hacks +- ~ada-ts-mode~ has been advised not to set ~treesit-language-source-alist~ and + ~eglot-server-programs~ buffer-locally, because this overrides global settings + (by the user or Doom modules) in a non-standard way. + +** TODO Changelog +# This section will be machine generated. Don't edit it by hand. +/This module does not have a changelog yet./ + +* Installation +[[id:01cffea4-3329-45e2-a892-95a384ab2338][Enable this module in your ~doom!~ block.]] + +#+begin_quote +󱌣 /No installation steps have been documented./ [[doom-contrib-module:][Document them?]] +#+end_quote + +* Usage +#+begin_quote +󱌣 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]] +#+end_quote + +* TODO Configuration +#+begin_quote +󱌣 This module has no configuration documentation yet. [[doom-contrib-module:][Write some?]] +#+end_quote + +* Troubleshooting +/There are no known problems with this module./ [[doom-report:][Report one?]] + +* Frequently asked questions +/This module has no FAQs yet./ [[doom-suggest-faq:][Ask one?]] + +* TODO Appendix +#+begin_quote +󱌣 This module has no appendix yet. [[doom-contrib-module:][Write one?]] +#+end_quote diff --git a/modules/lang/ada/auoload.el b/modules/lang/ada/auoload.el new file mode 100644 index 000000000..5d92233c7 --- /dev/null +++ b/modules/lang/ada/auoload.el @@ -0,0 +1,27 @@ +;;; lang/ada/auoload.el -*- lexical-binding: t; -*- + +(defun +ada--barf-unless-project () + (unless (locate-dominating-file defaul-directory "alire.toml") + (user-error "Not inside an Alire project"))) + + +;;;###autoload +(defun +ada/alr-build () + "Run 'alr build' in the current project." + (interactive) + (+ada--barf-unless-project) + (compile "alr build")) + +;;;###autoload +(defun +ada/alr-run () + "Run 'alr run' in the current project." + (interactive) + (+ada--barf-unless-project) + (compile "alr run")) + +;;;###autoload +(defun +ada/alr-clean () + "Run 'alr clean' in the current project." + (interactive) + (+ada--barf-unless-project) + (compile "alr clean")) diff --git a/modules/lang/ada/config.el b/modules/lang/ada/config.el new file mode 100644 index 000000000..106e85adc --- /dev/null +++ b/modules/lang/ada/config.el @@ -0,0 +1,44 @@ +;;; lang/ada/config.el -*- lexical-binding: t; -*- + +;; +;;; Packages + +(defun +ada-common-config (mode) + (when (modulep! +lsp) + (add-hook (intern (format "%s-local-vars-hook" mode)) #'lsp! 'append)) + + (map! :map ,(intern (format "%s-map" mode)) + :localleader + :desc "Build Alire Project" "b" #'+ada/alr-build + :desc "Run Alire Project" "r" #'+ada/alr-run + :desc "Clean Alire Project" "c" #'+ada/alr-clean)) + + +(use-package! ada-mode + :mode "\\.gpr\\'" + :config + (+ada-common-config 'ada-mode)) + + +(use-package! ada-ts-mode + :when (modulep! +tree-sitter) + :defer t + :init + (set-tree-sitter! 'ada-mode 'ada-ts-mode + '((ada :url "https://github.com/briot/tree-sitter-ada"))) + :config + (+ada-common-config 'ada-ts-mode) + + (setq ada-ts-mode-grammar-install nil) ; redundant w/ `treesit-auto-install-grammar' + + ;; HACK: `ada-ts-mode' sets buffer-local values for + ;; `treesit-language-source-alist' and `eglot-server-program' during major + ;; mode activation. This is poor ettiquite, overshadowing any user changes + ;; to the global values of these variables. Not to mention, it's redundant + ;; with ~set-tree-sitter!~ and ~eglot~ already handling support for + ;; ada-ts-mode. + ;; REVIEW: Undo buffer-local changes to these variables upstream. + (defadvice! +ada--suppress-side-effects-a (&rest _) + :after #'ada-ts-mode + (kill-local-variable 'treesit-language-source-alist) + (kill-local-variable 'eglot-server-programs))) diff --git a/modules/lang/ada/doctor.el b/modules/lang/ada/doctor.el new file mode 100644 index 000000000..0ea910176 --- /dev/null +++ b/modules/lang/ada/doctor.el @@ -0,0 +1,8 @@ +;;; lang/ada/doctor.el -*- lexical-binding: t; -*- + +(unless (executable-find "alr") + (warn! "Alire (alr) not found in $PATH")) + +(when (modulep! +lsp) + (unless (executable-find "ada_language_server") + (warn! "ada_language_server not found in $PATH; LSP support won't work"))) diff --git a/modules/lang/ada/packages.el b/modules/lang/ada/packages.el new file mode 100644 index 000000000..f00714251 --- /dev/null +++ b/modules/lang/ada/packages.el @@ -0,0 +1,6 @@ +;; -*- no-byte-compile: t; -*- +;;; lang/ada/packages.el + +(package! ada-mode :pin "ce8a2dfebc2b738f32b61dbe2668f7acb885db93") +(when (and (modulep! +tree-sitter) (treesit-available-p)) + (package! ada-ts-mode :pin "d0c1c124b236b402b884188948cb1f3502ef8779")) diff --git a/static/init.example.el b/static/init.example.el index bd1a08975..eafbb7f36 100644 --- a/static/init.example.el +++ b/static/init.example.el @@ -113,6 +113,7 @@ ;;tty ; improve the terminal Emacs experience :lang + ;;ada ; In strong typing we (blindly) trust ;;agda ; types of types of types of types... ;;beancount ; mind the GAAP ;;(cc +lsp) ; C > C++ == 1