aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2019-11-06 19:35:43 +0000
committerAlan Mackenzie2019-11-06 19:35:43 +0000
commit4ad6c932a826c2928ac82e56e5ae541eff7e5ca7 (patch)
tree796b6545124427691731938b3f9781ce5c9321e7
parente72a48ee8b412e0149a9659f49111f84dd8aa2dc (diff)
downloademacs-4ad6c932a826c2928ac82e56e5ae541eff7e5ca7.tar.gz
emacs-4ad6c932a826c2928ac82e56e5ae541eff7e5ca7.zip
Add a full set of CC Mode language variables to js.el.
This will allow js.el to work after maintenance changes in CC Mode, e.g. the fix to bug #11165. * lisp/progmodes/js.el (top level): Create a CC Mode derived language called js-mode and based on Java Mode. (js-mode): call c-init-language-vars for js-mode. Remove the direct settings of several CC Mode language variables which are now defined through the derived language mechanism. Call c-set-style and set up the needed style variables c-block-comment-prefix and c-comment-prefix-regexp.
-rw-r--r--lisp/progmodes/js.el29
1 files changed, 21 insertions, 8 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 599923dd279..5f0913470fd 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -46,6 +46,9 @@
46;;; Code: 46;;; Code:
47 47
48(require 'cc-mode) 48(require 'cc-mode)
49(eval-when-compile
50 (require 'cc-langs)
51 (require 'cc-fonts))
49(require 'newcomment) 52(require 'newcomment)
50(require 'imenu) 53(require 'imenu)
51(require 'moz nil t) 54(require 'moz nil t)
@@ -4529,12 +4532,22 @@ This function is intended for use in `after-change-functions'."
4529 (when (js-jsx--detect-and-enable 'arbitrarily) 4532 (when (js-jsx--detect-and-enable 'arbitrarily)
4530 (remove-hook 'after-change-functions #'js-jsx--detect-after-change t)))))) 4533 (remove-hook 'after-change-functions #'js-jsx--detect-after-change t))))))
4531 4534
4535;; Ensure all CC Mode "lang variables" are set to valid values.
4536;; js-mode, however, currently uses only those needed for filling.
4537(eval-and-compile
4538 (c-add-language 'js-mode 'java-mode))
4539
4540(c-lang-defconst c-paragraph-start
4541 js-mode "\\(@[[:alpha:]]+\\>\\|$\\)")
4542
4532;;; Main Function 4543;;; Main Function
4533 4544
4534;;;###autoload 4545;;;###autoload
4535(define-derived-mode js-mode prog-mode "JavaScript" 4546(define-derived-mode js-mode prog-mode "JavaScript"
4536 "Major mode for editing JavaScript." 4547 "Major mode for editing JavaScript."
4537 :group 'js 4548 :group 'js
4549 ;; Ensure all CC Mode "lang variables" are set to valid values.
4550 (c-init-language-vars js-mode)
4538 (setq-local indent-line-function #'js-indent-line) 4551 (setq-local indent-line-function #'js-indent-line)
4539 (setq-local beginning-of-defun-function #'js-beginning-of-defun) 4552 (setq-local beginning-of-defun-function #'js-beginning-of-defun)
4540 (setq-local end-of-defun-function #'js-end-of-defun) 4553 (setq-local end-of-defun-function #'js-end-of-defun)
@@ -4576,16 +4589,9 @@ This function is intended for use in `after-change-functions'."
4576 (setq imenu-create-index-function #'js--imenu-create-index) 4589 (setq imenu-create-index-function #'js--imenu-create-index)
4577 4590
4578 ;; for filling, pretend we're cc-mode 4591 ;; for filling, pretend we're cc-mode
4579 (setq c-comment-prefix-regexp "//+\\|\\**" 4592 (c-init-language-vars js-mode)
4580 c-paragraph-start "\\(@[[:alpha:]]+\\>\\|$\\)"
4581 c-paragraph-separate "$"
4582 c-block-comment-prefix "* "
4583 c-line-comment-starter "//"
4584 c-comment-start-regexp "/[*/]\\|\\s!")
4585 (setq-local comment-line-break-function #'c-indent-new-comment-line) 4593 (setq-local comment-line-break-function #'c-indent-new-comment-line)
4586 (setq-local c-block-comment-start-regexp "/\\*")
4587 (setq-local comment-multi-line t) 4594 (setq-local comment-multi-line t)
4588
4589 (setq-local electric-indent-chars 4595 (setq-local electric-indent-chars
4590 (append "{}():;," electric-indent-chars)) ;FIXME: js2-mode adds "[]*". 4596 (append "{}():;," electric-indent-chars)) ;FIXME: js2-mode adds "[]*".
4591 (setq-local electric-layout-rules 4597 (setq-local electric-layout-rules
@@ -4599,6 +4605,13 @@ This function is intended for use in `after-change-functions'."
4599 (make-local-variable 'paragraph-ignore-fill-prefix) 4605 (make-local-variable 'paragraph-ignore-fill-prefix)
4600 (make-local-variable 'adaptive-fill-mode) 4606 (make-local-variable 'adaptive-fill-mode)
4601 (make-local-variable 'adaptive-fill-regexp) 4607 (make-local-variable 'adaptive-fill-regexp)
4608 ;; While the full CC Mode style system is not yet in use, set the
4609 ;; pertinent style variables manually.
4610 (c-initialize-builtin-style)
4611 (let ((style (cc-choose-style-for-mode 'js-mode c-default-style)))
4612 (c-set-style style))
4613 (setq c-block-comment-prefix "* "
4614 c-comment-prefix-regexp "//+\\|\\**")
4602 (c-setup-paragraph-variables)) 4615 (c-setup-paragraph-variables))
4603 4616
4604 ;; Important to fontify the whole buffer syntactically! If we don't, 4617 ;; Important to fontify the whole buffer syntactically! If we don't,