* lisp/treesit.el:
(treesit-language-display-name-alist): New variable.
(treesit-language-display-name): New function.
* doc/lispref/parsing.texi (Language Grammar): Add to manual.
* etc/NEWS: Add to NEWS.
(cherry picked from commit
251b4c8c39535fee9f6da89420483304274ac03e)
is unavailable, this function returns @code{nil}.
@end defun
+@vindex treesit-language-display-name-alist
+@defun treesit-language-display-name language
+This function translates @var{language} to an appropriate display name.
+For example, it translates @code{ruby} to ``Ruby'', @code{cpp} to
+``C++''.
+
+Most languages has ``regular'' names, and their display name is simply
+the symbol name with first letter capitalized. For languages that has
+``irregular'' names, @var{treesit-language-display-name-alist} maps
+language symbols to their display names.
+
+If a major mode package uses a langauge with ``irregular'' name, they
+should add a mapping into @var{treesit-language-display-name-alist} on
+load.
+@end defun
+
@heading Concrete syntax tree
@cindex syntax tree, concrete
to move across lists. But to move across atoms inside the list
it uses `forward-sexp-default-function'.
++++
+*** New function 'treesit-language-display-name'.
+New function that returns the display name given the language symbol.
+For example, 'cpp' is translated to "C++". Also adds a new variable
+'treesit-language-display-name-alist' that the function uses to
+translate display names.
+
+++
** New optional BUFFER argument for 'string-pixel-width'.
If supplied, 'string-pixel-width' will use any face remappings from
return rng
finally return nil))))
+;;; Language display name
+
+;; The entries are sorted by `sort-lines'.
+(defvar treesit-language-display-name-alist
+ '(
+ (charp . "C#")
+ (cmake . "CMake")
+ (cpp . "C++")
+ (gomod . "Go Mod")
+ (heex . "HEEx")
+ (json . "JSON")
+ (php . "PHP")
+ (tsx . "TSX")
+ )
+ "An alist mapping language symbols to their display names.
+
+Used by `treesit-language-display-name'. If there's no mapping in this
+alist, `treesit-language-display-name' converts the symbol to display
+name by capitalizing the first letter. So languages like Java,
+Javascript, Rust don't need an entry in this variable.")
+
+(defun treesit-language-display-name (language)
+ "Returns the display name (a string) of LANGUAGE.
+
+If LANGUAGE has an entry in `treesit-language-display-name-alist', use
+the display name in their. Otherwise, capitalize the first letter of
+LANGUAGE and return the string."
+ (or (alist-get language treesit-language-display-name-alist)
+ (capitalize (symbol-name language))))
+
;;; Fontification
(define-error 'treesit-font-lock-error