Files
doomemacs/modules/tools/tree-sitter/autoload/compat-30.el
Henrik Lissner d9fd5cb8f3 fix(tree-sitter): treesit-enabled-modes: sort arity in <30
`sort`s signature changed in Emacs 30 from:

  (sort SEQ PREDICATE)

To

  (sort SEQ &key KEY LESSP REVERSE IN-PLACE)

Amend: 6009c2b838
2025-08-31 14:34:45 +02:00

75 lines
3.1 KiB
EmacsLisp

;;; tools/tree-sitter/autoload/compat-30.el -*- lexical-binding: t; -*-
;;;###if (and (fboundp 'treesit-available-p) (version< emacs-version "31.1"))
;;
;; Backported from 31.1
;;
;;; Code:
(autoload 'treesit-ready-p "treesit")
;;;###autoload
(defcustom treesit-auto-install-grammar 'ask
"Whether to install tree-sitter language grammar libraries when needed.
This controls whether Emacs will install missing grammar libraries
when they are needed by some tree-sitter based mode.
If `ask', ask for confirmation before installing the required grammar library.
If `always', install the grammar library without asking.
If nil or `never' or anything else, don't install the grammar library
even while visiting a file in the mode that requires such grammar; this
might display a warning and/or fail to turn on the mode."
:type '(choice (const :tag "Never install grammar libraries" never)
(const :tag "Always automatically install grammar libraries"
always)
(const :tag "Ask whether to install missing grammar libraries"
ask))
:version "31.1"
:group 'treesit)
;;;###autoload
(defun treesit-ensure-installed (lang)
"Ensure that the grammar library for the language LANG is installed.
The option `treesit-auto-install-grammar' defines whether to install
the grammar library if it's unavailable."
(or (treesit-ready-p lang t)
(when (or (eq treesit-auto-install-grammar 'always)
(and (eq treesit-auto-install-grammar 'ask)
(y-or-n-p (format "\
Tree-sitter grammar for `%s' is missing; install it?"
lang))))
(treesit-install-language-grammar lang)
;; Check that the grammar was installed successfully
(treesit-ready-p lang))))
;;; Introduced in later commits of 31.X
;;;###autoload
(unless (boundp 'treesit-major-mode-remap-alist)
(defvar treesit-major-mode-remap-alist nil))
;;;###autoload
(defcustom treesit-enabled-modes nil
"Specify what treesit modes to enable by default.
The value can be either a list of ts-modes to enable,
or t to enable all ts-modes."
:type `(choice
(const :tag "Disable all automatic associations" nil)
(const :tag "Enable all available ts-modes" t)
(set :tag "List of enabled ts-modes"
,@(when (treesit-available-p)
(let ((items (mapcar (lambda (m) `(function-item ,m))
(seq-uniq (mapcar #'cdr treesit-major-mode-remap-alist)))))
(if (= (car (func-arity 'sort)) 1)
(sort items)
(sort items #'value<))))))
:initialize #'custom-initialize-default
:set (lambda (sym val)
(set-default sym val)
(when (treesit-available-p)
(dolist (m treesit-major-mode-remap-alist)
(setq major-mode-remap-alist
(if (or (eq val t) (memq (cdr m) val))
(cons m major-mode-remap-alist)
(delete m major-mode-remap-alist))))))
:version "31.1")
;;; compat-30.el ends here