Fix use of treesit-ready-p in c/c++-ts-mode

* lisp/progmodes/c-ts-mode.el:
(c-ts-mode)
(c++-ts-mode): Put setup code in a when form.
This commit is contained in:
Yuan Fu 2023-01-07 17:26:26 -08:00
parent cc1de953d4
commit ef7f3c6388
No known key found for this signature in database
GPG key ID: 56E19BC57664A442

View file

@ -805,22 +805,17 @@ This mode is independent from the classic cc-mode.el based
`c-basic-offset', don't affect this mode." `c-basic-offset', don't affect this mode."
:group 'c :group 'c
(unless (treesit-ready-p 'c) (when (treesit-ready-p 'c)
(error "Tree-sitter for C isn't available")) (treesit-parser-create 'c)
;; Comments.
(treesit-parser-create 'c) (setq-local comment-start "/* ")
(setq-local comment-end " */")
;; Comments. ;; Indent.
(setq-local comment-start "/* ") (setq-local treesit-simple-indent-rules
(setq-local comment-end " */") (c-ts-mode--set-indent-style 'c))
;; Font-lock.
(setq-local treesit-simple-indent-rules (setq-local treesit-font-lock-settings (c-ts-mode--font-lock-settings 'c))
(c-ts-mode--set-indent-style 'c)) (treesit-major-mode-setup)))
;; Font-lock.
(setq-local treesit-font-lock-settings (c-ts-mode--font-lock-settings 'c))
(treesit-major-mode-setup))
;;;###autoload ;;;###autoload
(define-derived-mode c++-ts-mode c-ts-base-mode "C++" (define-derived-mode c++-ts-mode c-ts-base-mode "C++"
@ -831,20 +826,17 @@ This mode is independent from the classic cc-mode.el based
`c-basic-offset', don't affect this mode." `c-basic-offset', don't affect this mode."
:group 'c++ :group 'c++
(unless (treesit-ready-p 'cpp) (when (treesit-ready-p 'cpp)
(error "Tree-sitter for C++ isn't available")) (treesit-parser-create 'cpp)
;; Syntax.
(treesit-parser-create 'cpp) (setq-local syntax-propertize-function
(setq-local syntax-propertize-function #'c-ts-mode--syntax-propertize)
#'c-ts-mode--syntax-propertize) ;; Indent.
(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)) ;; Font-lock.
(setq-local treesit-font-lock-settings (c-ts-mode--font-lock-settings 'cpp))
;; Font-lock. (treesit-major-mode-setup)))
(setq-local treesit-font-lock-settings (c-ts-mode--font-lock-settings 'cpp))
(treesit-major-mode-setup))
;; We could alternatively use parsers, but if this works well, I don't ;; We could alternatively use parsers, but if this works well, I don't
;; see the need to change. This is copied verbatim from cc-guess.el. ;; see the need to change. This is copied verbatim from cc-guess.el.