unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#11165: 24.0.95; c-indent-new-comment-line bug or feature?
@ 2012-04-03 18:30 Leo
  2012-04-17 10:53 ` Alan Mackenzie
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Leo @ 2012-04-03 18:30 UTC (permalink / raw)
  To: 11165; +Cc: bug-cc-mode

1. Emacs -q
2. M-x c-mode
3. customise the indentation for syntactic symbol c to 4
4. Enter /* and then M-j (c-indent-new-comment-line)

you should see point located at column 2 instead of 4, which is a wrong
indentation position for that line and unlike indent-new-comment-line or
newline-and-indent.

Is this a bug or feature? Thanks.

Leo





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#11165: 24.0.95; c-indent-new-comment-line bug or feature?
  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
  2019-10-25 20:34 ` Alan Mackenzie
       [not found] ` <20191025203405.GA24064@ACM>
  2 siblings, 1 reply; 12+ messages in thread
From: Alan Mackenzie @ 2012-04-17 10:53 UTC (permalink / raw)
  To: 11165

> 1. Emacs -q
> 2. M-x c-mode
> 3. customise the indentation for syntactic symbol c to 4
> 4. Enter /* and then M-j (c-indent-new-comment-line)

I think you've missed out some steps here.  When I do exactly that, I do
M-x c-mode on the opening splash screen (which isn't sensible), which is
read-only, preventing step 4.

What I tried was, instead of your step 4, creating a new buffer with C-x
b asdf.c, then setting the mode with M-x c-mode.

> you should see point located at column 2 instead of 4, which is a wrong
> indentation position for that line and unlike indent-new-comment-line
> or newline-and-indent.

I do indeed see point at column 2, which is correct.  I think you might
have set the offset for "c" to 4 before creating the empty C buffer.
Indentation configuration is buffer local.

When I then repeat the C-c C-o c <ret> 4 <ret> I then get the second line
at offset 4, where it ought to be.

> Is this a bug or feature? Thanks.

Could you please indicate exactly what you did.  I suspect this is
neither bug nor feature.  :-)  It would be good to get this bug report
closed off.

Leo

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#11165: 24.0.95; c-indent-new-comment-line bug or feature?
  2012-04-17 10:53 ` Alan Mackenzie
@ 2012-04-17 13:57   ` Leo
  2012-05-15 16:50     ` Alan Mackenzie
  0 siblings, 1 reply; 12+ messages in thread
From: Leo @ 2012-04-17 13:57 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 11165

On 2012-04-17 18:53 +0800, Alan Mackenzie wrote:
> I think you've missed out some steps here.  When I do exactly that, I do
> M-x c-mode on the opening splash screen (which isn't sensible), which is
> read-only, preventing step 4.
>
> What I tried was, instead of your step 4, creating a new buffer with C-x
> b asdf.c, then setting the mode with M-x c-mode.

Sorry for the splash screen. What you did instead is correct.

> I do indeed see point at column 2, which is correct.  I think you might
> have set the offset for "c" to 4 before creating the empty C buffer.
> Indentation configuration is buffer local.
>
> When I then repeat the C-c C-o c <ret> 4 <ret> I then get the second line
> at offset 4, where it ought to be.

I customise "c" after entering C mode so the customisation is effective.
If you type M-j after /*, point is moved to the newline with 2 leading
spaces. Now if you type TAB, it will go to column 4. so M-j is
misbehaving i.e. it doesn't go to the right indentation.

In contrast, M-x indent-new-comment-line following /* will move point to
column 4 in the next line.

Leo





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#11165: 24.0.95; c-indent-new-comment-line bug or feature?
  2012-04-17 13:57   ` Leo
@ 2012-05-15 16:50     ` Alan Mackenzie
  2012-05-17  7:19       ` Leo
  0 siblings, 1 reply; 12+ messages in thread
From: Alan Mackenzie @ 2012-05-15 16:50 UTC (permalink / raw)
  To: Leo; +Cc: 11165

Hello, Leo.

On Tue, Apr 17, 2012 at 09:57:52PM +0800, Leo wrote:
> On 2012-04-17 18:53 +0800, Alan Mackenzie wrote:
> > I think you've missed out some steps here.  When I do exactly that, I do
> > M-x c-mode on the opening splash screen (which isn't sensible), which is
> > read-only, preventing step 4.

> > What I tried was, instead of your step 4, creating a new buffer with C-x
> > b asdf.c, then setting the mode with M-x c-mode.

> Sorry for the splash screen. What you did instead is correct.

> > I do indeed see point at column 2, which is correct.  I think you might
> > have set the offset for "c" to 4 before creating the empty C buffer.
> > Indentation configuration is buffer local.

> > When I then repeat the C-c C-o c <ret> 4 <ret> I then get the second line
> > at offset 4, where it ought to be.

> I customise "c" after entering C mode so the customisation is effective.
> If you type M-j after /*, point is moved to the newline with 2 leading
> spaces. Now if you type TAB, it will go to column 4. so M-j is
> misbehaving i.e. it doesn't go to the right indentation.

> In contrast, M-x indent-new-comment-line following /* will move point to
> column 4 in the next line.

This is getting confusing.  I'm asking you at this point to read the
chapter "Config Basics" of the CC Mode manual.  About 36 lines down from
the top, it explains how setq'ing/customizing CC Mode's style variables
interacts with loading a buffer.

I don't think this is a bug.  When you've read that manual page, would
you please check exactly what you've done, and whether your buffer
indents as we both would like.

If it still seems wrong, could you give the exact description of how to
create the problem starting from emacs -Q (yes, I know this'll involve
some repetition).

Thanks!

> Leo

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#11165: 24.0.95; c-indent-new-comment-line bug or feature?
  2012-05-15 16:50     ` Alan Mackenzie
@ 2012-05-17  7:19       ` Leo
  2012-05-17 10:12         ` Alan Mackenzie
  0 siblings, 1 reply; 12+ messages in thread
From: Leo @ 2012-05-17  7:19 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 11165

[-- Attachment #1: Type: text/plain, Size: 565 bytes --]

On 2012-05-16 00:50 +0800, Alan Mackenzie wrote:
> I don't think this is a bug.  When you've read that manual page, would
> you please check exactly what you've done, and whether your buffer
> indents as we both would like.

I have read the manual before and I just read it again. Here is a
detailed recipe to reproduce:

1. Emacs -q
2. Make a new buffer named BUG and enable c-mode in it
3. C-c C-o and customise syntactic 'c' to 4 in BUG buffer
4. Now typing in the BUG buffer slash star /*, then press M-j
5. type TAB to indent

In step 4 the buffer looks like:

[-- Attachment #2: bug1.png --]
[-- Type: image/png, Size: 8322 bytes --]

[-- Attachment #3: Type: text/plain, Size: 34 bytes --]


In step 5 the buffer looks like:

[-- Attachment #4: bug2.png --]
[-- Type: image/png, Size: 8301 bytes --]

[-- Attachment #5: Type: text/plain, Size: 73 bytes --]


The bug is M-j (c-indent-new-comment-line) indents to the wrong column.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#11165: 24.0.95; c-indent-new-comment-line bug or feature?
  2012-05-17  7:19       ` Leo
@ 2012-05-17 10:12         ` Alan Mackenzie
  0 siblings, 0 replies; 12+ messages in thread
From: Alan Mackenzie @ 2012-05-17 10:12 UTC (permalink / raw)
  To: Leo; +Cc: 11165

Hi, Leo.

On Thu, May 17, 2012 at 03:19:56PM +0800, Leo wrote:
> On 2012-05-16 00:50 +0800, Alan Mackenzie wrote:
> > I don't think this is a bug.  When you've read that manual page, would
> > you please check exactly what you've done, and whether your buffer
> > indents as we both would like.

> I have read the manual before and I just read it again. Here is a
> detailed recipe to reproduce:

> 1. Emacs -q
> 2. Make a new buffer named BUG and enable c-mode in it
> 3. C-c C-o and customise syntactic 'c' to 4 in BUG buffer
> 4. Now typing in the BUG buffer slash star /*, then press M-j
> 5. type TAB to indent

Thanks for this clarification.

[ .... ]

> The bug is M-j (c-indent-new-comment-line) indents to the wrong column.

Yes, indeed.  In c-indent-new-comment-line there are some lines of code
which prevent point ending up further to the right than its starting
point.  This was to fix a bug in which, after M-; M-j, point ended up
too far to the right.  The fix was erroneous.

This code was committed on 2007-02-15, so it doesn't count as a
regression in the sense of the Emacs 24 release.  So even though the fix
shouldn't be too difficult, it isn't the most urgent thing at the
moment.  I'll get it fixed in CC Mode standalone and the Emacs trunk
sometime.

In the meantime, a workaround is to type <tab> after each M-j,
irritating though this may be.

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#11165: 24.0.95; c-indent-new-comment-line bug or feature?
  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
@ 2019-10-25 20:34 ` Alan Mackenzie
  2019-10-26 13:08   ` Leo Liu
       [not found] ` <20191025203405.GA24064@ACM>
  2 siblings, 1 reply; 12+ messages in thread
From: Alan Mackenzie @ 2019-10-25 20:34 UTC (permalink / raw)
  To: Leo; +Cc: bug-cc-mode, 11165-done

Hello, Leo.

On Wed, Apr 04, 2012 at 02:30:32 +0800, Leo wrote:
> 1. Emacs -q
> 2. M-x c-mode
> 3. customise the indentation for syntactic symbol c to 4
> 4. Enter /* and then M-j (c-indent-new-comment-line)

> you should see point located at column 2 instead of 4, which is a wrong
> indentation position for that line and unlike indent-new-comment-line
> or newline-and-indent.

> Is this a bug or feature? Thanks.

It was a bug.  Now, at long last, it has been fixed, specifically in
commit 25ed447b7bec3af66cf0322239cfabbaf71bef26 of today, "CC Mode: Fix
positioning of point whilst inserting comments without non-ws".

The fix is also in the head of the default branch of stand alone CC Mode
at Sourceforge.

I am closing the bug with this post.  Sorry it was ignored for so long.

> Leo

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#11165: 24.0.95; c-indent-new-comment-line bug or feature?
  2019-10-25 20:34 ` Alan Mackenzie
@ 2019-10-26 13:08   ` Leo Liu
  0 siblings, 0 replies; 12+ messages in thread
From: Leo Liu @ 2019-10-26 13:08 UTC (permalink / raw)
  To: 11165; +Cc: acm

On 2019-10-25 20:34 +0000, Alan Mackenzie wrote:
> It was a bug.  Now, at long last, it has been fixed, specifically in
> commit 25ed447b7bec3af66cf0322239cfabbaf71bef26 of today, "CC Mode: Fix
> positioning of point whilst inserting comments without non-ws".
>
> The fix is also in the head of the default branch of stand alone CC Mode
> at Sourceforge.

Excellent thanks for fixing it.

> I am closing the bug with this post. Sorry it was ignored for so long.

No worries. I am glad it is fixed ;)

Leo





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#11165: 24.0.95; c-indent-new-comment-line bug or feature?
       [not found] ` <20191025203405.GA24064@ACM>
@ 2019-10-26 17:08   ` Glenn Morris
  2019-10-27 11:32     ` Alan Mackenzie
  0 siblings, 1 reply; 12+ messages in thread
From: Glenn Morris @ 2019-10-26 17:08 UTC (permalink / raw)
  To: 11165; +Cc: acm, sdl.web

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





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#11165: 24.0.95; c-indent-new-comment-line bug or feature?
  2019-10-26 17:08   ` Glenn Morris
@ 2019-10-27 11:32     ` Alan Mackenzie
  2019-11-06 16:43       ` Glenn Morris
       [not found]       ` <dpv9rxez0a.fsf@fencepost.gnu.org>
  0 siblings, 2 replies; 12+ messages in thread
From: Alan Mackenzie @ 2019-10-27 11:32 UTC (permalink / raw)
  To: Daniel Colascione, Glenn Morris; +Cc: 11165, sdl.web

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).





^ permalink raw reply related	[flat|nested] 12+ messages in thread

* bug#11165: 24.0.95; c-indent-new-comment-line bug or feature?
  2019-10-27 11:32     ` Alan Mackenzie
@ 2019-11-06 16:43       ` Glenn Morris
       [not found]       ` <dpv9rxez0a.fsf@fencepost.gnu.org>
  1 sibling, 0 replies; 12+ messages in thread
From: Glenn Morris @ 2019-11-06 16:43 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 11165, sdl.web


> 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.

It's inconvenient to have the test suite fail for an extended period of
time, so, in the absence of any other comments, could I encourage you to
apply this? TIA.






^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#11165: 24.0.95; c-indent-new-comment-line bug or feature?
       [not found]       ` <dpv9rxez0a.fsf@fencepost.gnu.org>
@ 2019-11-06 20:33         ` Alan Mackenzie
  0 siblings, 0 replies; 12+ messages in thread
From: Alan Mackenzie @ 2019-11-06 20:33 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 11165, sdl.web

Hello, Glenn.

On Wed, Nov 06, 2019 at 11:43:49 -0500, Glenn Morris wrote:

> > 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.

> It's inconvenient to have the test suite fail for an extended period of
> time, so, in the absence of any other comments, could I encourage you to
> apply this? TIA.

Yes, it's been 10 days with no comment from Daniel.  I've thus committed
the patch.

Thanks for the reminder.

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-11-06 20:33 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2019-11-06 16:43       ` Glenn Morris
     [not found]       ` <dpv9rxez0a.fsf@fencepost.gnu.org>
2019-11-06 20:33         ` Alan Mackenzie

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).