I searched for an existing issue, but didn't find one that seemed to
coincide with this issue.  This is a problem that impacts both user
configuration as well as the use of tree-sitter major modes in Org
source blocks.

Org source blocks don't respect the user's configuration of their
desired major mode.  As a result, the source block may use a different
major mode than what is specified in "major-mode-remap-alist"
(introduced in Emacs 29).  If the user wants a specific major mode for
a source block, they are forced to update the applicable "defcustom"
(e.g., "org-src-lang-modes") to get the desired behavior.  This
shouldn't be necessary if they have already configured
"major-mode-remap-alist".  Similarly, Org doesn't map to tree-sitter
major modes in source blocks.  A tree-sitter major mode can't tell
"org-src" about itself since modes shouldn't modify a "defcustom"
(i.e., "org-src-lang-modes"), and "org-src" doesn't look at
"major-mode-remap-defaults" (introduced in Emacs 30).  Thus, there is
no provided mechanism for a major mode to configure itself with
"org-src" without breaking etiquette, and as such is reliant on the
user to configure both "major-mode-remap-alist" for normal use and
"org-src-lang-modes" for Org source blocks.  This is even more
important if there is no built-in non-tree-sitter major mode (e.g.,
"ada-ts-mode") as the source block will not be highlighted at all if
the user hasn't explicitly configured "org-src-lang-modes".  From a
user's perspective this can be quite confusing.

Without updating "org-src-lang-modes", a user could specify the
language in the source block with the "-ts" suffix (e.g., "ada-ts"),
so that the corresponding mode is found and the tree-sitter major mode
is used for the source block, but it is not obvious without knowing
the internals of "org-src-get-lang-mode".  Furthermore, this
workaround is problematic when combined with other functionality, such
as "org-babel" and "org-babel-tangle-lang-exts", as the languages
listed there likely do not include a "-ts" suffix.  This approach
requires the user to perform configuration elsewhere (e.g.,
"org-babel-tangle-lang-exts") in order to make other functionality
work correctly.  Therefore, it is undesirable to use a non-standard
language name for the source block.

I think all of this could be automatically addressed if Org used
"major-mode-remap", back-ported for older Emacs versions (likely by
creating "org-major-mode-remap" in "org-compat.el"), and used at the
end of "org-src-get-lang-mode" to map the resultant major mode
accordingly.  For Emacs 30+, "org-major-mode-remap" could just be
aliased to "major-mode-remap", but for Emacs 29, it would look at
"major-mode-remap-alist" (since "major-mode-remap-defaults" wasn't
available until Emacs 30) and for Emacs versions before Emacs 29, it
would just return the supplied mode without any remapping.  That would
seem to automatically map the tree-sitter modes as expected.

Reply via email to