diff options
| author | Rahul Martim Juliato <rahul.juliato@gmail.com> | 2026-05-23 09:18:40 -0300 |
|---|---|---|
| committer | Sean Whitton <spwhitton@spwhitton.name> | 2026-05-23 16:25:09 +0100 |
| commit | eb653865c3a35af115360273fb5147b4943ba2ef (patch) | |
| tree | 8c43ab03c8dd0cc910c76206b122b435568066ce /lisp | |
| parent | 7a17f97baa7d483cba5cde3cd22c34e0597e60b5 (diff) | |
markdown-ts-mode: Don't enable unconditionally by default
* lisp/textmodes/markdown-ts-mode.el (markdown-ts-mode-maybe):
New function.
(auto-mode-alist): Bind ".md", ".markdown", and ".mdx" to
'markdown-ts-mode-maybe' instead of 'markdown-ts-mode'.
* etc/NEWS: Update the 'markdown-ts-mode' entry.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/textmodes/markdown-ts-mode.el | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/lisp/textmodes/markdown-ts-mode.el b/lisp/textmodes/markdown-ts-mode.el index be2247b870e..fed6ded192c 100644 --- a/lisp/textmodes/markdown-ts-mode.el +++ b/lisp/textmodes/markdown-ts-mode.el @@ -5401,14 +5401,14 @@ With a prefix argument, ARG, if needed, install parsers for `html', (cond ((treesit-ready-p '(markdown markdown-inline) t) (markdown-ts--set-up)) (t - (warn "markdown-ts-mode cannot be set up; using fundamental-mode. + (warn "markdown-ts-mode cannot be set up; using text-mode. %s." (if (treesit-available-p) "The tree-sitter parsers `markdown' and `markdown-inline' were not found. Use the command `markdown-ts-mode-install-parsers' to install them. With a prefix argument, it can also install optional parsers" "Emacs was built without Tree-sitter support, or could not load Tree-sitter")) - (fundamental-mode))))) + (text-mode))))) ;;;###autoload (define-derived-mode markdown-ts-mode text-mode "Markdown" @@ -5620,10 +5620,24 @@ If non-nil and `point' is in a table, enable #'markdown-ts--enable-in-table-mode 'local)))) ;;;###autoload +(defun markdown-ts-mode-maybe () + "Enable `markdown-ts-mode' when its grammars are available. +Also propose to install the grammars when `treesit-enabled-modes' +is t or contains the mode name." + (declare-function treesit-language-available-p "treesit.c") + (if (or (and (treesit-language-available-p 'markdown) + (treesit-language-available-p 'markdown-inline)) + (eq treesit-enabled-modes t) + (memq 'markdown-ts-mode treesit-enabled-modes)) + (markdown-ts-mode) + (text-mode))) + +;;;###autoload (when (boundp 'treesit-major-mode-remap-alist) - (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-ts-mode)) - (add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-ts-mode)) - (add-to-list 'auto-mode-alist '("\\.mdx\\'" . markdown-ts-mode)) + (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-ts-mode-maybe)) + (add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-ts-mode-maybe)) + (add-to-list 'auto-mode-alist '("\\.mdx\\'" . markdown-ts-mode-maybe)) + ;; To be able to toggle between an external package and core ts-mode: (add-to-list 'treesit-major-mode-remap-alist '(markdown-mode . markdown-ts-mode))) |
