bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#11165: 24.0.95; c-indent-new-comment-line bug or feature?


From: Alan Mackenzie
Subject: bug#11165: 24.0.95; c-indent-new-comment-line bug or feature?
Date: Sun, 27 Oct 2019 11:32:16 +0000
User-agent: Mutt/1.10.1 (2018-07-13)

Hello, Daniel and Glenn.

On Sat, Oct 26, 2019 at 13:08:30 -0400, Glenn Morris wrote:
> Alan Mackenzie wrote:

> > commit 25ed447b7bec3af66cf0322239cfabbaf71bef26 of today, "CC Mode: Fix
> > positioning of point whilst inserting comments without non-ws".

> This change causes some test failures, ref eg
> https://hydra.nixos.org/build/104351524

The failures were in js-mode (.../lisp/progmodes/js.el).

The reason for the failures was js-mode failing completely to initialise
a set of CC Mode "language variables", instead manually setting the few
that have been used in the past.

The lastest fix to CC Mode used another language variable, one that had
not been explicitly set by js-mode.  Thus js-mode's filling failed.

I think the best way to fix this is, rather than adding an ad hoc setq
for this variable, initialising a full set of language variables for
js-mode (based on Java Mode).  The following patch does this.  It passes
the Emacs test suite completely.

Daniel, what do you think?



diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 599923dd27..5f0913470f 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -46,6 +46,9 @@
 ;;; Code:
 
 (require 'cc-mode)
+(eval-when-compile
+  (require 'cc-langs)
+  (require 'cc-fonts))
 (require 'newcomment)
 (require 'imenu)
 (require 'moz nil t)
@@ -4529,12 +4532,22 @@ js-jsx--detect-after-change
         (when (js-jsx--detect-and-enable 'arbitrarily)
           (remove-hook 'after-change-functions #'js-jsx--detect-after-change 
t))))))
 
+;; Ensure all CC Mode "lang variables" are set to valid values.
+;; js-mode, however, currently uses only those needed for filling.
+(eval-and-compile
+  (c-add-language 'js-mode 'java-mode))
+
+(c-lang-defconst c-paragraph-start
+  js-mode "\\(@[[:alpha:]]+\\>\\|$\\)")
+
 ;;; Main Function
 
 ;;;###autoload
 (define-derived-mode js-mode prog-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)
@@ -4576,16 +4589,9 @@ js-mode
   (setq imenu-create-index-function #'js--imenu-create-index)
 
   ;; for filling, pretend we're cc-mode
-  (setq c-comment-prefix-regexp "//+\\|\\**"
-        c-paragraph-start "\\(@[[:alpha:]]+\\>\\|$\\)"
-        c-paragraph-separate "$"
-        c-block-comment-prefix "* "
-        c-line-comment-starter "//"
-        c-comment-start-regexp "/[*/]\\|\\s!")
+  (c-init-language-vars js-mode)
   (setq-local comment-line-break-function #'c-indent-new-comment-line)
-  (setq-local c-block-comment-start-regexp "/\\*")
   (setq-local comment-multi-line t)
-
   (setq-local electric-indent-chars
              (append "{}():;," electric-indent-chars)) ;FIXME: js2-mode adds 
"[]*".
   (setq-local electric-layout-rules
@@ -4599,6 +4605,13 @@ js-mode
     (make-local-variable 'paragraph-ignore-fill-prefix)
     (make-local-variable 'adaptive-fill-mode)
     (make-local-variable 'adaptive-fill-regexp)
+    ;; While the full CC Mode style system is not yet in use, set the
+    ;; pertinent style variables manually.
+    (c-initialize-builtin-style)
+    (let ((style (cc-choose-style-for-mode 'js-mode c-default-style)))
+      (c-set-style style))
+    (setq c-block-comment-prefix "* "
+          c-comment-prefix-regexp "//+\\|\\**")
     (c-setup-paragraph-variables))
 
   ;; Important to fontify the whole buffer syntactically! If we don't,



-- 
Alan Mackenzie (Nuremberg, Germany).





reply via email to

[Prev in Thread] Current Thread [Next in Thread]