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.
This commit is contained in:
Rahul Martim Juliato 2026-05-23 09:18:40 -03:00 committed by Sean Whitton
parent 7a17f97baa
commit eb653865c3
2 changed files with 24 additions and 17 deletions

View file

@ -3938,19 +3938,12 @@ A major mode based on 'conf-mode' for editing ".npmrc" files.
*** New major mode 'markdown-ts-mode'. *** New major mode 'markdown-ts-mode'.
A major mode based on the tree-sitter library for editing Markdown A major mode based on the tree-sitter library for editing Markdown
files. This is now the default major mode for Markdown files. If you files. Markdown files are visited using this mode when the required
don't have the necessary tree-sitter grammar libraries installed, or if tree-sitter grammars ('markdown' and 'markdown-inline') are available,
your Emacs was built without tree-sitter support, Emacs will now show a or when the user has opted in via 'treesit-enabled-modes'. Otherwise,
warning to that effect when you visit a Markdown file. If you don't Markdown files fall back to 'text-mode'.
want to use this mode and want to avoid these warnings, add the
following to your init file:
(add-to-list 'auto-mode-alist '("\\.md\\'" . fundamental-mode)) To install the grammars, use 'M-x markdown-ts-mode-install-parsers'.
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . fundamental-mode))
(add-to-list 'auto-mode-alist '("\\.mdx\\'" . fundamental-mode))
This will cause Emacs to visit Markdown files in Fundamental mode, which
was the default before this mode was added to Emacs.
*** New major mode 'mhtml-ts-mode'. *** New major mode 'mhtml-ts-mode'.
An optional major mode based on the tree-sitter library for editing HTML An optional major mode based on the tree-sitter library for editing HTML

View file

@ -5401,14 +5401,14 @@ With a prefix argument, ARG, if needed, install parsers for `html',
(cond ((treesit-ready-p '(markdown markdown-inline) t) (cond ((treesit-ready-p '(markdown markdown-inline) t)
(markdown-ts--set-up)) (markdown-ts--set-up))
(t (t
(warn "markdown-ts-mode cannot be set up; using fundamental-mode. (warn "markdown-ts-mode cannot be set up; using text-mode.
%s." %s."
(if (treesit-available-p) (if (treesit-available-p)
"The tree-sitter parsers `markdown' and `markdown-inline' were not found. "The tree-sitter parsers `markdown' and `markdown-inline' were not found.
Use the command `markdown-ts-mode-install-parsers' to install them. Use the command `markdown-ts-mode-install-parsers' to install them.
With a prefix argument, it can also install optional parsers" With a prefix argument, it can also install optional parsers"
"Emacs was built without Tree-sitter support, or could not load Tree-sitter")) "Emacs was built without Tree-sitter support, or could not load Tree-sitter"))
(fundamental-mode))))) (text-mode)))))
;;;###autoload ;;;###autoload
(define-derived-mode markdown-ts-mode text-mode "Markdown" (define-derived-mode markdown-ts-mode text-mode "Markdown"
@ -5619,11 +5619,25 @@ If non-nil and `point' is in a table, enable
(remove-hook 'post-command-hook (remove-hook 'post-command-hook
#'markdown-ts--enable-in-table-mode 'local)))) #'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 ;;;###autoload
(when (boundp 'treesit-major-mode-remap-alist) (when (boundp 'treesit-major-mode-remap-alist)
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-ts-mode)) (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-ts-mode-maybe))
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-ts-mode)) (add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-ts-mode-maybe))
(add-to-list 'auto-mode-alist '("\\.mdx\\'" . markdown-ts-mode)) (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 (add-to-list 'treesit-major-mode-remap-alist
'(markdown-mode . markdown-ts-mode))) '(markdown-mode . markdown-ts-mode)))