* bug#14332: 24.3; Octave indentation bug
@ 2013-05-02 4:04 Leo Liu
2013-05-05 5:29 ` Stefan Monnier
0 siblings, 1 reply; 12+ messages in thread
From: Leo Liu @ 2013-05-02 4:04 UTC (permalink / raw)
To: 14332
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)
^ permalink raw reply related [flat|nested] 12+ messages in thread
* bug#14332: 24.3; Octave indentation bug
2013-05-02 4:04 bug#14332: 24.3; Octave indentation bug Leo Liu
@ 2013-05-05 5:29 ` Stefan Monnier
2013-05-05 5:35 ` Leo Liu
0 siblings, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2013-05-05 5:29 UTC (permalink / raw)
To: Leo Liu; +Cc: 14332
> 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
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#14332: 24.3; Octave indentation bug
2013-05-05 5:29 ` Stefan Monnier
@ 2013-05-05 5:35 ` Leo Liu
2013-05-05 7:17 ` Stefan Monnier
0 siblings, 1 reply; 12+ messages in thread
From: Leo Liu @ 2013-05-05 5:35 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 14332
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#14332: 24.3; Octave indentation bug
2013-05-05 5:35 ` Leo Liu
@ 2013-05-05 7:17 ` Stefan Monnier
2013-05-05 7:28 ` Leo Liu
0 siblings, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2013-05-05 7:17 UTC (permalink / raw)
To: Leo Liu; +Cc: 14332
>> 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
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#14332: 24.3; Octave indentation bug
2013-05-05 7:17 ` Stefan Monnier
@ 2013-05-05 7:28 ` Leo Liu
2013-05-06 1:04 ` Stefan Monnier
0 siblings, 1 reply; 12+ messages in thread
From: Leo Liu @ 2013-05-05 7:28 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 14332
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#14332: 24.3; Octave indentation bug
2013-05-05 7:28 ` Leo Liu
@ 2013-05-06 1:04 ` Stefan Monnier
2013-05-06 3:29 ` Leo Liu
0 siblings, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2013-05-06 1:04 UTC (permalink / raw)
To: Leo Liu; +Cc: 14332
>> 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
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#14332: 24.3; Octave indentation bug
2013-05-06 1:04 ` Stefan Monnier
@ 2013-05-06 3:29 ` Leo Liu
2013-05-06 8:26 ` Leo Liu
0 siblings, 1 reply; 12+ messages in thread
From: Leo Liu @ 2013-05-06 3:29 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 14332
[-- Attachment #1: Type: text/plain, Size: 1611 bytes --]
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)
[-- Attachment #2: oct_ind.m --]
[-- Type: text/plain, Size: 83 bytes --]
## -*-Octave-*-
"abc\"abc"
if (true)
a = (1 \(2-3));
else
a = 0;
endif
^ permalink raw reply related [flat|nested] 12+ messages in thread
* bug#14332: 24.3; Octave indentation bug
2013-05-06 3:29 ` Leo Liu
@ 2013-05-06 8:26 ` Leo Liu
2013-05-06 14:48 ` Stefan Monnier
0 siblings, 1 reply; 12+ messages in thread
From: Leo Liu @ 2013-05-06 8:26 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 14332
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)
^ permalink raw reply related [flat|nested] 12+ messages in thread
* bug#14332: 24.3; Octave indentation bug
2013-05-06 8:26 ` Leo Liu
@ 2013-05-06 14:48 ` Stefan Monnier
2013-05-06 15:57 ` Leo Liu
0 siblings, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2013-05-06 14:48 UTC (permalink / raw)
To: Leo Liu; +Cc: 14332
> + ("\\\\" (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
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#14332: 24.3; Octave indentation bug
2013-05-06 14:48 ` Stefan Monnier
@ 2013-05-06 15:57 ` Leo Liu
2013-05-06 21:37 ` Stefan Monnier
0 siblings, 1 reply; 12+ messages in thread
From: Leo Liu @ 2013-05-06 15:57 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 14332
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#14332: 24.3; Octave indentation bug
2013-05-06 15:57 ` Leo Liu
@ 2013-05-06 21:37 ` Stefan Monnier
2013-05-06 23:58 ` Leo Liu
0 siblings, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2013-05-06 21:37 UTC (permalink / raw)
To: Leo Liu; +Cc: 14332
>> 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
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#14332: 24.3; Octave indentation bug
2013-05-06 21:37 ` Stefan Monnier
@ 2013-05-06 23:58 ` Leo Liu
0 siblings, 0 replies; 12+ messages in thread
From: Leo Liu @ 2013-05-06 23:58 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 14332-done
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
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2013-05-06 23:58 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-02 4:04 bug#14332: 24.3; Octave indentation bug Leo Liu
2013-05-05 5:29 ` Stefan Monnier
2013-05-05 5:35 ` Leo Liu
2013-05-05 7:17 ` Stefan Monnier
2013-05-05 7:28 ` Leo Liu
2013-05-06 1:04 ` Stefan Monnier
2013-05-06 3:29 ` Leo Liu
2013-05-06 8:26 ` Leo Liu
2013-05-06 14:48 ` Stefan Monnier
2013-05-06 15:57 ` Leo Liu
2013-05-06 21:37 ` Stefan Monnier
2013-05-06 23:58 ` Leo Liu
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.