[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/tree-sitter 7d7e9ef46a 5/6: Separate native and tree-sitter vari
From: |
Yuan Fu |
Subject: |
feature/tree-sitter 7d7e9ef46a 5/6: Separate native and tree-sitter variant of js-mode |
Date: |
Sat, 19 Nov 2022 21:36:26 -0500 (EST) |
branch: feature/tree-sitter
commit 7d7e9ef46a1b310fb3f481cdf8023082f5ec1618
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Separate native and tree-sitter variant of js-mode
* lisp/progmodes/js.el (js-base-mode): New mode.
(js-mode): Return to before tree-sitter setup is added, change to
inherit from js-base-mode.
(js-ts-mode): New mode. Now it doesn't use any cc-mode feature,
meaning it looses comment filling.
---
lisp/progmodes/js.el | 68 ++++++++++++++++++++++++++++++++++++----------------
1 file changed, 47 insertions(+), 21 deletions(-)
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index fd3737f8b6..c37cef977b 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3697,12 +3697,33 @@ definition*\"."
;;; Main Function
;;;###autoload
-(define-derived-mode js-mode prog-mode "JavaScript"
+(define-derived-mode js-base-mode prog-mode "JavaScript"
+ "Generic major mode for editing JavaScript.
+
+This mode is intended to be inherited by concrete major modes.
+Currently there are `js-mode' and `js-ts-mode'."
+ :group 'js
+ nil)
+
+;;;###autoload
+(define-derived-mode js-mode js-base-mode "JavaScript"
"Major mode for editing JavaScript."
:group 'js
;; Ensure all CC Mode "lang variables" are set to valid values.
(c-init-language-vars js-mode)
+ (setq-local indent-line-function #'js-indent-line)
+ (setq-local beginning-of-defun-function #'js-beginning-of-defun)
+ (setq-local end-of-defun-function #'js-end-of-defun)
(setq-local open-paren-in-column-0-is-defun-start nil)
+ (setq-local font-lock-defaults
+ (list js--font-lock-keywords nil nil nil nil
+ '(font-lock-syntactic-face-function
+ . js-font-lock-syntactic-face-function)))
+ (setq-local syntax-propertize-function #'js-syntax-propertize)
+ (add-hook 'syntax-propertize-extend-region-functions
+ #'syntax-propertize-multiline 'append 'local)
+ (add-hook 'syntax-propertize-extend-region-functions
+ #'js--syntax-propertize-extend-region 'append 'local)
(setq-local prettify-symbols-alist js--prettify-symbols-alist)
(setq-local parse-sexp-ignore-comments t)
@@ -3768,10 +3789,31 @@ definition*\"."
;; FIXME: We should instead do this fontification lazily by adding
;; calls to syntax-propertize wherever it's really needed.
;;(syntax-propertize (point-max))
+ )
- (cond
- ;; Tree-sitter.
- ((treesit-ready-p 'js-mode 'javascript)
+(define-derived-mode js-ts-mode js-base-mode "JavaScript"
+ "Major mode for editing JavaScript.
+
+\\<js-ts-mode-map>"
+ :group 'js
+ (when (treesit-ready-p 'js-mode 'javascript)
+ ;; Borrowed from `js-mode'.
+ (setq-local prettify-symbols-alist js--prettify-symbols-alist)
+ (setq-local parse-sexp-ignore-comments t)
+ ;; Which-func.
+ (setq-local which-func-imenu-joiner-function #'js--which-func-joiner)
+ ;; Comment.
+ (setq-local comment-start "// ")
+ (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *")
+ (setq-local comment-end "")
+ (setq-local comment-multi-line t)
+ ;; Electric-indent.
+ (setq-local electric-indent-chars
+ (append "{}():;," electric-indent-chars)) ;FIXME: js2-mode adds
"[]*".
+ (setq-local electric-layout-rules
+ '((?\; . after) (?\{ . after) (?\} . before)))
+
+ ;; Tree-sitter setup.
(treesit-parser-create 'javascript)
;; Indent.
(setq-local treesit-simple-indent-rules js--treesit-indent-rules)
@@ -3792,23 +3834,7 @@ definition*\"."
#'js--treesit-imenu)
;; Which-func (use imenu).
(setq-local which-func-functions nil)
- (treesit-major-mode-setup))
- ;; Elisp.
- (t
- ;; Ensure all CC Mode "lang variables" are set to valid values
- ;; (continued).
- (setq-local indent-line-function #'js-indent-line)
- (setq-local beginning-of-defun-function #'js-beginning-of-defun)
- (setq-local end-of-defun-function #'js-end-of-defun)
- (setq-local font-lock-defaults
- (list js--font-lock-keywords nil nil nil nil
- '(font-lock-syntactic-face-function
- . js-font-lock-syntactic-face-function)))
- (setq-local syntax-propertize-function #'js-syntax-propertize)
- (add-hook 'syntax-propertize-extend-region-functions
- #'syntax-propertize-multiline 'append 'local)
- (add-hook 'syntax-propertize-extend-region-functions
- #'js--syntax-propertize-extend-region 'append 'local))))
+ (treesit-major-mode-setup)))
(defvar js-json--treesit-font-lock-settings
(treesit-font-lock-rules
- feature/tree-sitter updated (59eaa30b07 -> ac9bc819bc), Yuan Fu, 2022/11/19
- feature/tree-sitter 655957087c 2/6: Expand css-ts-mode and merge it into css-mode, Yuan Fu, 2022/11/19
- feature/tree-sitter e41af3971d 1/6: Change tree-sitter indent preset 'match' to count on all nodes, Yuan Fu, 2022/11/19
- feature/tree-sitter 00df4566af 3/6: Split python-mode into native and tree-sitter variant, Yuan Fu, 2022/11/19
- feature/tree-sitter d6362b632e 4/6: Merge function/class-name features in python-mode, Yuan Fu, 2022/11/19
- feature/tree-sitter ac9bc819bc 6/6: Fix tree-sitter comment indentation for C-like languages, Yuan Fu, 2022/11/19
- feature/tree-sitter 7d7e9ef46a 5/6: Separate native and tree-sitter variant of js-mode,
Yuan Fu <=