unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Daniel Colascione <dancol@dancol.org>, Glenn Morris <rgm@gnu.org>
Cc: 11165@debbugs.gnu.org, sdl.web@gmail.com
Subject: bug#11165: 24.0.95; c-indent-new-comment-line bug or feature?
Date: Sun, 27 Oct 2019 11:32:16 +0000	[thread overview]
Message-ID: <20191027113216.GA27491@ACM> (raw)
In-Reply-To: <ktftjf1lkh.fsf@fencepost.gnu.org>

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	other threads:[~2019-10-27 11:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-03 18:30 bug#11165: 24.0.95; c-indent-new-comment-line bug or feature? Leo
2012-04-17 10:53 ` Alan Mackenzie
2012-04-17 13:57   ` Leo
2012-05-15 16:50     ` Alan Mackenzie
2012-05-17  7:19       ` Leo
2012-05-17 10:12         ` Alan Mackenzie
2019-10-25 20:34 ` Alan Mackenzie
2019-10-26 13:08   ` Leo Liu
     [not found] ` <20191025203405.GA24064@ACM>
2019-10-26 17:08   ` Glenn Morris
2019-10-27 11:32     ` Alan Mackenzie [this message]
2019-11-06 16:43       ` Glenn Morris
     [not found]       ` <dpv9rxez0a.fsf@fencepost.gnu.org>
2019-11-06 20:33         ` Alan Mackenzie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191027113216.GA27491@ACM \
    --to=acm@muc.de \
    --cc=11165@debbugs.gnu.org \
    --cc=dancol@dancol.org \
    --cc=rgm@gnu.org \
    --cc=sdl.web@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).