aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2025-04-16 21:45:40 +0300
committerJuri Linkov2025-04-16 21:45:40 +0300
commitf68482cbc047925d22acf687b814cb94dd7b5bf0 (patch)
tree08fe82a88b664e85aaf239678458b1907df93473
parenta6d746400cdf237b58c60920f4cb9a38db12951d (diff)
downloademacs-f68482cbc047925d22acf687b814cb94dd7b5bf0.tar.gz
emacs-f68482cbc047925d22acf687b814cb94dd7b5bf0.zip
* lisp/textmodes/markdown-ts-mode.el: More ts-modes for code blocks.
(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'.
-rw-r--r--lisp/textmodes/markdown-ts-mode.el36
1 files changed, 32 insertions, 4 deletions
diff --git a/lisp/textmodes/markdown-ts-mode.el b/lisp/textmodes/markdown-ts-mode.el
index 86507ae6858..dddeede1e29 100644
--- a/lisp/textmodes/markdown-ts-mode.el
+++ b/lisp/textmodes/markdown-ts-mode.el
@@ -37,7 +37,9 @@
37;;; Helper functions 37;;; Helper functions
38 38
39(defvar markdown-ts--code-block-language-map 39(defvar markdown-ts--code-block-language-map
40 '(("c++" . cpp) ("c#" . c-sharp)) 40 '(("c++" . cpp)
41 ("c#" . c-sharp)
42 ("sh" . bash))
41 "Alist mapping code block language names to tree-sitter languages. 43 "Alist mapping code block language names to tree-sitter languages.
42 44
43Keys should be strings, and values should be language symbols. 45Keys should be strings, and values should be language symbols.
@@ -53,7 +55,31 @@ For example, \"c++\" in
53maps to tree-sitter language `cpp'.") 55maps to tree-sitter language `cpp'.")
54 56
55(defvar markdown-ts-code-block-source-mode-map 57(defvar markdown-ts-code-block-source-mode-map
56 '((javascript . js-ts-mode)) 58 '((bash . bash-ts-mode)
59 (c . c-ts-mode)
60 (c-sharp . csharp-ts-mode)
61 (cmake . cmake-ts-mode)
62 (cpp . c++-ts-mode)
63 (css . css-ts-mode)
64 (dockerfile . dockerfile-ts-mode)
65 (elixir . elixir-ts-mode)
66 (go . go-ts-mode)
67 (gomod . go-mod-ts-mode)
68 (gowork . go-work-ts-mode)
69 (heex . heex-ts-mode)
70 (html . html-ts-mode)
71 (java . java-ts-mode)
72 (javascript . js-ts-mode)
73 (json . json-ts-mode)
74 (lua . lua-ts-mode)
75 (php . php-ts-mode)
76 (python . python-ts-mode)
77 (ruby . ruby-ts-mode)
78 (rust . rust-ts-mode)
79 (toml . toml-ts-mode)
80 (tsx . tsx-ts-mode)
81 (typescript . typescript-ts-mode)
82 (yaml . yaml-ts-mode))
57 "An alist of supported code block languages and their major mode.") 83 "An alist of supported code block languages and their major mode.")
58 84
59;;; Faces 85;;; Faces
@@ -228,12 +254,14 @@ the same features enabled in MODE."
228 (let* ((lang-string (alist-get (treesit-node-text node) 254 (let* ((lang-string (alist-get (treesit-node-text node)
229 markdown-ts--code-block-language-map 255 markdown-ts--code-block-language-map
230 (treesit-node-text node) nil #'equal)) 256 (treesit-node-text node) nil #'equal))
231 (lang (intern (downcase lang-string)))) 257 (lang (if (symbolp lang-string)
258 lang-string
259 (intern (downcase lang-string)))))
232 ;; FIXME: Kind of a hack here: we use this function as a hook for 260 ;; FIXME: Kind of a hack here: we use this function as a hook for
233 ;; loading up configs for the language for the code block on-demand. 261 ;; loading up configs for the language for the code block on-demand.
234 (unless (memq lang markdown-ts--configured-languages) 262 (unless (memq lang markdown-ts--configured-languages)
235 (let ((mode (alist-get lang markdown-ts-code-block-source-mode-map))) 263 (let ((mode (alist-get lang markdown-ts-code-block-source-mode-map)))
236 (when mode 264 (when (fboundp mode)
237 (markdown-ts--add-config-for-mode lang mode) 265 (markdown-ts--add-config-for-mode lang mode)
238 (push lang markdown-ts--configured-languages)))) 266 (push lang markdown-ts--configured-languages))))
239 lang)) 267 lang))