mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-16 19:00:55 -08:00
Fix syntax for < and > in c++-ts-mode (bug#60351)
< and > are usually punctuation, e.g., in ->. But when used for templates, they should be considered pairs. Right now we always consider them as pairs which is incorrect. * lisp/progmodes/c-ts-mode.el (c++-ts-mode--syntax-table): Remove variable. (c-ts-mode--syntax-propertize): New function. (c++-ts-mode): Remove syntax table. Setup syntax-propertize-function.
This commit is contained in:
parent
f509246ba1
commit
19b8733aa2
1 changed files with 25 additions and 8 deletions
|
|
@ -63,6 +63,8 @@ follows the form of `treesit-simple-indent-rules'."
|
||||||
(function :tag "A function for user customized style" ignore))
|
(function :tag "A function for user customized style" ignore))
|
||||||
:group 'c)
|
:group 'c)
|
||||||
|
|
||||||
|
;;; Syntax table
|
||||||
|
|
||||||
(defvar c-ts-mode--syntax-table
|
(defvar c-ts-mode--syntax-table
|
||||||
(let ((table (make-syntax-table)))
|
(let ((table (make-syntax-table)))
|
||||||
;; Taken from the cc-langs version
|
;; Taken from the cc-langs version
|
||||||
|
|
@ -85,13 +87,27 @@ follows the form of `treesit-simple-indent-rules'."
|
||||||
table)
|
table)
|
||||||
"Syntax table for `c-ts-mode'.")
|
"Syntax table for `c-ts-mode'.")
|
||||||
|
|
||||||
(defvar c++-ts-mode--syntax-table
|
(defun c-ts-mode--syntax-propertize (beg end)
|
||||||
(let ((table (make-syntax-table c-ts-mode--syntax-table)))
|
"Apply syntax text property to template delimiters between BEG and END.
|
||||||
;; Template delimiters.
|
|
||||||
(modify-syntax-entry ?< "(" table)
|
< and > are usually punctuation, e.g., in ->. But when used for
|
||||||
(modify-syntax-entry ?> ")" table)
|
templates, they should be considered pairs.
|
||||||
table)
|
|
||||||
"Syntax table for `c++-ts-mode'.")
|
This function checks for < and > in the changed RANGES and apply
|
||||||
|
appropriate text property to alter the syntax of template
|
||||||
|
delimiters < and >'s."
|
||||||
|
(goto-char beg)
|
||||||
|
(while (re-search-forward (rx (or "<" ">")) end t)
|
||||||
|
(pcase (treesit-node-type
|
||||||
|
(treesit-node-parent
|
||||||
|
(treesit-node-at (match-beginning 0))))
|
||||||
|
("template_argument_list"
|
||||||
|
(put-text-property (match-beginning 0)
|
||||||
|
(match-end 0)
|
||||||
|
'syntax-table
|
||||||
|
(pcase (char-before)
|
||||||
|
(?< '(4 . ?>))
|
||||||
|
(?> '(5 . ?<))))))))
|
||||||
|
|
||||||
;;; Indent
|
;;; Indent
|
||||||
|
|
||||||
|
|
@ -751,12 +767,13 @@ Set up:
|
||||||
(define-derived-mode c++-ts-mode c-ts-base-mode "C++"
|
(define-derived-mode c++-ts-mode c-ts-base-mode "C++"
|
||||||
"Major mode for editing C++, powered by tree-sitter."
|
"Major mode for editing C++, powered by tree-sitter."
|
||||||
:group 'c++
|
:group 'c++
|
||||||
:syntax-table c++-ts-mode--syntax-table
|
|
||||||
|
|
||||||
(unless (treesit-ready-p 'cpp)
|
(unless (treesit-ready-p 'cpp)
|
||||||
(error "Tree-sitter for C++ isn't available"))
|
(error "Tree-sitter for C++ isn't available"))
|
||||||
|
|
||||||
(treesit-parser-create 'cpp)
|
(treesit-parser-create 'cpp)
|
||||||
|
(setq-local syntax-propertize-function
|
||||||
|
#'c-ts-mode--syntax-propertize)
|
||||||
|
|
||||||
(setq-local treesit-simple-indent-rules
|
(setq-local treesit-simple-indent-rules
|
||||||
(c-ts-mode--set-indent-style 'cpp))
|
(c-ts-mode--set-indent-style 'cpp))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue