]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/textmodes/markdown-ts-mode.el: More ts-modes for code blocks.
authorJuri Linkov <juri@linkov.net>
Wed, 16 Apr 2025 18:45:40 +0000 (21:45 +0300)
committerEshel Yaron <me@eshelyaron.com>
Thu, 17 Apr 2025 07:09:45 +0000 (09:09 +0200)
(markdown-ts--code-block-language-map): Add more aliases.
(markdown-ts-code-block-source-mode-map): Add more mappings
for existing core ts-modes.
(markdown-ts--convert-code-block-language):
Check 'lang-string' with 'symbolp'.  Check 'mode' with 'fboundp'.

(cherry picked from commit f68482cbc047925d22acf687b814cb94dd7b5bf0)

lisp/textmodes/markdown-ts-mode.el

index 071d986f1ffcf5a4efe315b38e043251b63d6d98..2004738aee4072e7a276c10b0fd69d255b34c265 100644 (file)
@@ -37,7 +37,9 @@
 ;;; Helper functions
 
 (defvar markdown-ts--code-block-language-map
-  '(("c++" . cpp) ("c#" . c-sharp))
+  '(("c++" . cpp)
+    ("c#" . c-sharp)
+    ("sh" . bash))
   "Alist mapping code block language names to tree-sitter languages.
 
 Keys should be strings, and values should be language symbols.
@@ -53,7 +55,31 @@ For example, \"c++\" in
 maps to tree-sitter language `cpp'.")
 
 (defvar markdown-ts-code-block-source-mode-map
-  '((javascript . js-ts-mode))
+  '((bash . bash-ts-mode)
+    (c . c-ts-mode)
+    (c-sharp . csharp-ts-mode)
+    (cmake . cmake-ts-mode)
+    (cpp . c++-ts-mode)
+    (css . css-ts-mode)
+    (dockerfile . dockerfile-ts-mode)
+    (elixir . elixir-ts-mode)
+    (go . go-ts-mode)
+    (gomod . go-mod-ts-mode)
+    (gowork . go-work-ts-mode)
+    (heex . heex-ts-mode)
+    (html . html-ts-mode)
+    (java . java-ts-mode)
+    (javascript . js-ts-mode)
+    (json . json-ts-mode)
+    (lua . lua-ts-mode)
+    (php . php-ts-mode)
+    (python . python-ts-mode)
+    (ruby . ruby-ts-mode)
+    (rust . rust-ts-mode)
+    (toml . toml-ts-mode)
+    (tsx . tsx-ts-mode)
+    (typescript . typescript-ts-mode)
+    (yaml . yaml-ts-mode))
   "An alist of supported code block languages and their major mode.")
 
 ;;; Faces
@@ -227,12 +253,14 @@ the same features enabled in MODE."
   (let* ((lang-string (alist-get (treesit-node-text node)
                                  markdown-ts--code-block-language-map
                                  (treesit-node-text node) nil #'equal))
-         (lang (intern (downcase lang-string))))
+         (lang (if (symbolp lang-string)
+                   lang-string
+                 (intern (downcase lang-string)))))
     ;; FIXME: Kind of a hack here: we use this function as a hook for
     ;; loading up configs for the language for the code block on-demand.
     (unless (memq lang markdown-ts--configured-languages)
       (let ((mode (alist-get lang markdown-ts-code-block-source-mode-map)))
-        (when mode
+        (when (fboundp mode)
           (markdown-ts--add-config-for-mode lang mode)
           (push lang markdown-ts--configured-languages))))
     lang))