aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuan Fu2023-01-07 17:26:26 -0800
committerYuan Fu2023-01-07 18:44:16 -0800
commitef7f3c6388be1299e3834f7c96889f0e17745c24 (patch)
tree058d2073da13fe5ec013e6c50a530ff987de253b
parentcc1de953d4fa203b3a0c58a63e0251b515be991d (diff)
downloademacs-ef7f3c6388be1299e3834f7c96889f0e17745c24.tar.gz
emacs-ef7f3c6388be1299e3834f7c96889f0e17745c24.zip
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.
-rw-r--r--lisp/progmodes/c-ts-mode.el52
1 files changed, 22 insertions, 30 deletions
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index ae50c0ef991..d2280f1d382 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -805,22 +805,17 @@ This mode is independent from the classic cc-mode.el based
805`c-basic-offset', don't affect this mode." 805`c-basic-offset', don't affect this mode."
806 :group 'c 806 :group 'c
807 807
808 (unless (treesit-ready-p 'c) 808 (when (treesit-ready-p 'c)
809 (error "Tree-sitter for C isn't available")) 809 (treesit-parser-create 'c)
810 810 ;; Comments.
811 (treesit-parser-create 'c) 811 (setq-local comment-start "/* ")
812 812 (setq-local comment-end " */")
813 ;; Comments. 813 ;; Indent.
814 (setq-local comment-start "/* ") 814 (setq-local treesit-simple-indent-rules
815 (setq-local comment-end " */") 815 (c-ts-mode--set-indent-style 'c))
816 816 ;; Font-lock.
817 (setq-local treesit-simple-indent-rules 817 (setq-local treesit-font-lock-settings (c-ts-mode--font-lock-settings 'c))
818 (c-ts-mode--set-indent-style 'c)) 818 (treesit-major-mode-setup)))
819
820 ;; Font-lock.
821 (setq-local treesit-font-lock-settings (c-ts-mode--font-lock-settings 'c))
822
823 (treesit-major-mode-setup))
824 819
825;;;###autoload 820;;;###autoload
826(define-derived-mode c++-ts-mode c-ts-base-mode "C++" 821(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
831`c-basic-offset', don't affect this mode." 826`c-basic-offset', don't affect this mode."
832 :group 'c++ 827 :group 'c++
833 828
834 (unless (treesit-ready-p 'cpp) 829 (when (treesit-ready-p 'cpp)
835 (error "Tree-sitter for C++ isn't available")) 830 (treesit-parser-create 'cpp)
836 831 ;; Syntax.
837 (treesit-parser-create 'cpp) 832 (setq-local syntax-propertize-function
838 (setq-local syntax-propertize-function 833 #'c-ts-mode--syntax-propertize)
839 #'c-ts-mode--syntax-propertize) 834 ;; Indent.
840 835 (setq-local treesit-simple-indent-rules
841 (setq-local treesit-simple-indent-rules 836 (c-ts-mode--set-indent-style 'cpp))
842 (c-ts-mode--set-indent-style 'cpp)) 837 ;; Font-lock.
843 838 (setq-local treesit-font-lock-settings (c-ts-mode--font-lock-settings 'cpp))
844 ;; Font-lock. 839 (treesit-major-mode-setup)))
845 (setq-local treesit-font-lock-settings (c-ts-mode--font-lock-settings 'cpp))
846
847 (treesit-major-mode-setup))
848 840
849;; We could alternatively use parsers, but if this works well, I don't 841;; We could alternatively use parsers, but if this works well, I don't
850;; see the need to change. This is copied verbatim from cc-guess.el. 842;; see the need to change. This is copied verbatim from cc-guess.el.