GNU bug report logs - #14332
24.3; Octave indentation bug

Previous Next

Package: emacs;

Reported by: Leo Liu <sdl.web <at> gmail.com>

Date: Thu, 2 May 2013 04:06:02 UTC

Severity: normal

Found in version 24.3

Done: Leo Liu <sdl.web <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 14332 in the body.
You can then email your comments to 14332 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org:
bug#14332; Package emacs. (Thu, 02 May 2013 04:06:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Leo Liu <sdl.web <at> gmail.com>:
New bug report received and forwarded. Copy sent to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org. (Thu, 02 May 2013 04:06:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3; Octave indentation bug
Date: Thu, 02 May 2013 12:04:44 +0800
Indent the following lines in octave mode

if (true)
  a = (1 \(2-3));
else
  a = 0;
endif

gives me

if (true)
  a = (1 \(2-3));
                else
                  a = 0;
                endif


It seems treating \ as escape outside strings is incorrect. Is the
following fix is correct?


diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el
index a58fdefb..1e2c2425 100644
--- a/lisp/progmodes/octave.el
+++ b/lisp/progmodes/octave.el
@@ -233,7 +233,7 @@ (defvar octave-mode-syntax-table
     (modify-syntax-entry ?& "."   table)
     (modify-syntax-entry ?| "."   table)
     (modify-syntax-entry ?! "."   table)
-    (modify-syntax-entry ?\\ "\\" table)
+    (modify-syntax-entry ?\\ "." table)
     (modify-syntax-entry ?\' "."  table)
     ;; Was "w" for abbrevs, but now that it's not necessary any more,
     (modify-syntax-entry ?\` "."  table)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14332; Package emacs. (Sun, 05 May 2013 05:31:01 GMT) Full text and rfc822 format available.

Message #8 received at 14332 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 14332 <at> debbugs.gnu.org
Subject: Re: bug#14332: 24.3; Octave indentation bug
Date: Sun, 05 May 2013 01:29:45 -0400
> It seems treating \ as escape outside strings is incorrect. Is the
> following fix is correct?
[..]
> -    (modify-syntax-entry ?\\ "\\" table)
> +    (modify-syntax-entry ?\\ "." table)

Wouldn't that mess up the case of

  a = "hello\"there";

?

        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14332; Package emacs. (Sun, 05 May 2013 05:37:01 GMT) Full text and rfc822 format available.

Message #11 received at 14332 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 14332 <at> debbugs.gnu.org
Subject: Re: bug#14332: 24.3; Octave indentation bug
Date: Sun, 05 May 2013 13:35:49 +0800
On 2013-05-05 13:29 +0800, Stefan Monnier wrote:
> Wouldn't that mess up the case of
>
>   a = "hello\"there";

Yes it does. How to fix this bug properly?

Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14332; Package emacs. (Sun, 05 May 2013 07:19:01 GMT) Full text and rfc822 format available.

Message #14 received at 14332 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 14332 <at> debbugs.gnu.org
Subject: Re: bug#14332: 24.3; Octave indentation bug
Date: Sun, 05 May 2013 03:17:11 -0400
>> Wouldn't that mess up the case of
>> a = "hello\"there";
> Yes it does. How to fix this bug properly?

You'll probably need to add some syntax-propertize case.
What does "(1 \(2-3))" mean in Octave?  Where else can \ appear in
Octave code?


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14332; Package emacs. (Sun, 05 May 2013 07:30:03 GMT) Full text and rfc822 format available.

Message #17 received at 14332 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 14332 <at> debbugs.gnu.org
Subject: Re: bug#14332: 24.3; Octave indentation bug
Date: Sun, 05 May 2013 15:28:13 +0800
On 2013-05-05 15:17 +0800, Stefan Monnier wrote:
> You'll probably need to add some syntax-propertize case.
> What does "(1 \(2-3))" mean in Octave?  Where else can \ appear in
> Octave code?

A \ 1 ≡ inv(A) # one over matrix A, with some optimisation

if A is a scalar, A \ 1 = 1 / A.

so \ is an operator.

Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14332; Package emacs. (Mon, 06 May 2013 01:06:02 GMT) Full text and rfc822 format available.

Message #20 received at 14332 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 14332 <at> debbugs.gnu.org
Subject: Re: bug#14332: 24.3; Octave indentation bug
Date: Sun, 05 May 2013 21:04:14 -0400
>> You'll probably need to add some syntax-propertize case.
>> What does "(1 \(2-3))" mean in Octave?  Where else can \ appear in
>> Octave code?

> A \ 1 ≡ inv(A) # one over matrix A, with some optimisation

> if A is a scalar, A \ 1 = 1 / A.

> so \ is an operator.

Then your best bet is probably to put in the mode's syntax-table the
syntax corresponding to the most common use of \ (either as an escape
char in strings or as an operator), and then use syntax-propertize to
put the other syntax on the other case (where you can check (nth
3 (syntax-ppss (math-beginning 0))) to see if you're within a string).


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14332; Package emacs. (Mon, 06 May 2013 03:31:04 GMT) Full text and rfc822 format available.

Message #23 received at 14332 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 14332 <at> debbugs.gnu.org
Subject: Re: bug#14332: 24.3; Octave indentation bug
Date: Mon, 06 May 2013 11:29:42 +0800
[Message part 1 (text/plain, inline)]
On 2013-05-06 09:04 +0800, Stefan Monnier wrote:
> Then your best bet is probably to put in the mode's syntax-table the
> syntax corresponding to the most common use of \ (either as an escape
> char in strings or as an operator), and then use syntax-propertize to
> put the other syntax on the other case (where you can check (nth
> 3 (syntax-ppss (math-beginning 0))) to see if you're within a string).

What I would like is to have \ mean "." unless it is in double-quoted
strings where it should be "\\". I have the following non-working patch.
Ideas?

diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el
index 2e848600..d5a1af2b 100644
--- a/lisp/progmodes/octave.el
+++ b/lisp/progmodes/octave.el
@@ -137,6 +137,8 @@ (defun octave-syntax-propertize-function (start end)
   (goto-char start)
   (octave-syntax-propertize-sqs end)
   (funcall (syntax-propertize-rules
+            ("\\\\" (0 (when (eq (nth 3 (syntax-ppss (match-beginning 0))) ?\")
+                         "\\")))
             ;; Try to distinguish the string-quotes from the transpose-quotes.
             ("\\(?:^\\|[[({,; ]\\)\\('\\)"
              (1 (prog1 "\"'" (octave-syntax-propertize-sqs end)))))
@@ -242,7 +244,7 @@ (defvar octave-mode-syntax-table
     (modify-syntax-entry ?& "."   table)
     (modify-syntax-entry ?| "."   table)
     (modify-syntax-entry ?! "."   table)
-    (modify-syntax-entry ?\\ "\\" table)
+    (modify-syntax-entry ?\\ "."  table)
     (modify-syntax-entry ?\' "."  table)
     ;; Was "w" for abbrevs, but now that it's not necessary any more,
     (modify-syntax-entry ?\` "."  table)

[oct_ind.m (text/plain, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14332; Package emacs. (Mon, 06 May 2013 08:28:02 GMT) Full text and rfc822 format available.

Message #26 received at 14332 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 14332 <at> debbugs.gnu.org
Subject: Re: bug#14332: 24.3; Octave indentation bug
Date: Mon, 06 May 2013 16:26:13 +0800
On 2013-05-06 11:29 +0800, Leo Liu wrote:
> What I would like is to have \ mean "." unless it is in double-quoted
> strings where it should be "\\".

This patch seems working. This is the first time I am using the
syntax-table property. Stefan, do you see any problem with the patch?

diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el
index 2e848600..66fda302 100644
--- a/lisp/progmodes/octave.el
+++ b/lisp/progmodes/octave.el
@@ -134,6 +134,12 @@ (defvar octave-font-lock-keywords
   "Additional Octave expressions to highlight.")
 
 (defun octave-syntax-propertize-function (start end)
+  (funcall (syntax-propertize-rules
+            ("\\\\" (0 (when (eq (nth 3 (save-excursion
+                                          (syntax-ppss (match-beginning 0))))
+                                 ?\")
+                         (string-to-syntax "\\")))))
+           start end)
   (goto-char start)
   (octave-syntax-propertize-sqs end)
   (funcall (syntax-propertize-rules
@@ -242,7 +248,7 @@ (defvar octave-mode-syntax-table
     (modify-syntax-entry ?& "."   table)
     (modify-syntax-entry ?| "."   table)
     (modify-syntax-entry ?! "."   table)
-    (modify-syntax-entry ?\\ "\\" table)
+    (modify-syntax-entry ?\\ "."  table)
     (modify-syntax-entry ?\' "."  table)
     ;; Was "w" for abbrevs, but now that it's not necessary any more,
     (modify-syntax-entry ?\` "."  table)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14332; Package emacs. (Mon, 06 May 2013 14:50:02 GMT) Full text and rfc822 format available.

Message #29 received at 14332 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 14332 <at> debbugs.gnu.org
Subject: Re: bug#14332: 24.3; Octave indentation bug
Date: Mon, 06 May 2013 10:48:18 -0400
> +            ("\\\\" (0 (when (eq (nth 3 (save-excursion
> +                                          (syntax-ppss (match-beginning 0))))
> +                                 ?\")
> +                         (string-to-syntax "\\")))))

The rule looks OK, but why not put it inside the subsequent
`syntax-propertize-rules'?


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14332; Package emacs. (Mon, 06 May 2013 15:59:01 GMT) Full text and rfc822 format available.

Message #32 received at 14332 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 14332 <at> debbugs.gnu.org
Subject: Re: bug#14332: 24.3; Octave indentation bug
Date: Mon, 06 May 2013 23:57:20 +0800
On 2013-05-06 22:48 +0800, Stefan Monnier wrote:
> The rule looks OK, but why not put it inside the subsequent
> `syntax-propertize-rules'?

Wouldn't this (octave-syntax-propertize-sqs end) before the
syntax-propertize-rules form causes some \'s to be missed?

Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14332; Package emacs. (Mon, 06 May 2013 21:39:01 GMT) Full text and rfc822 format available.

Message #35 received at 14332 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 14332 <at> debbugs.gnu.org
Subject: Re: bug#14332: 24.3; Octave indentation bug
Date: Mon, 06 May 2013 17:37:39 -0400
>> The rule looks OK, but why not put it inside the subsequent
>> `syntax-propertize-rules'?
> Wouldn't this (octave-syntax-propertize-sqs end) before the
> syntax-propertize-rules form causes some \'s to be missed?

No, octave-syntax-propertize-sqs just skips over the contents of
single-quoted strings and from what you say you only want to handle
backslash in double-quoted strings.


        Stefan




Reply sent to Leo Liu <sdl.web <at> gmail.com>:
You have taken responsibility. (Tue, 07 May 2013 00:00:02 GMT) Full text and rfc822 format available.

Notification sent to Leo Liu <sdl.web <at> gmail.com>:
bug acknowledged by developer. (Tue, 07 May 2013 00:00:02 GMT) Full text and rfc822 format available.

Message #40 received at 14332-done <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 14332-done <at> debbugs.gnu.org
Subject: Re: bug#14332: 24.3; Octave indentation bug
Date: Tue, 07 May 2013 07:58:10 +0800
Fixed in trunk.

On 2013-05-07 05:37 +0800, Stefan Monnier wrote:
> No, octave-syntax-propertize-sqs just skips over the contents of
> single-quoted strings and from what you say you only want to handle
> backslash in double-quoted strings.

Thank you, Stefan, for the help. Much appreciated.

Leo




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 04 Jun 2013 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 328 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.