all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: Octave comments in emacs
@ 2008-08-12  2:36 Rosen Diankov
  2008-08-12 20:07 ` Rosen Diankov
  2011-03-10  7:06 ` bug#697: " Glenn Morris
  0 siblings, 2 replies; 10+ messages in thread
From: Rosen Diankov @ 2008-08-12  2:36 UTC (permalink / raw)
  To: Olivier Lefevre; +Cc: bug-gnu-emacs, help

The % also messes up formatting when seen in strings, ie 'my value: %d'

For some reason, the octave syntax does not recognize that single
quotes are strings (it might be because the transpose character is
also ' and it is hard to differentiate between a string and the
transposing).

In any case, writing the above example will treat the % as a comment.
The indenting engine will skip the closing parenthesis )... resulting
in all the rest of the indents looking like garbage.

To fix the weird positioning of single % comments and the following
problems, go tino octave-mod.el and

in octave-mode-syntax-table change
(modify-syntax-entry ?\' "." table)
to
(modify-syntax-entry ?\' "\"" table)

in calculate-octave-indent at the bottom change
((looking-at "\\s<\\S<")
to
((and (looking-at "\\s<\\S<") (not (looking-at "%")))

i use (looking-at octave-comment-char) instead since some people use #
for comments


I'm not sure what the consequences of these changes are. From the
testing I've done, emacs formatting is running more like how the
matlab editor would format. Now if someone can fix the indentation
problems with "end", we'll have perfect indenting.

rosen diankov,


2007/12/28 Olivier Lefevre <lefevrol@yahoo.com>:
> Ah OK. I had read about % vs. %% and %%% but it hadn't registered, perhaps
> because it smelled perl-ish and thus went in one ear, out the other.
> In the brain-damaged language(s) the other gentleman was referring to,
> emacs will automatically indent the comment line according to its position
>  in the code, without need for any of that %% or %%% flummery ;-) That is
> both more natural and more practical, I think. But I can live with %%.
>
> Thanks again,
>
> -- O.L.
>
> _______________________________________________
> Help-octave mailing list
> Help-octave@octave.org
> https://www.cae.wisc.edu/mailman/listinfo/help-octave
>

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

* Re: Octave comments in emacs
  2008-08-12  2:36 Octave comments in emacs Rosen Diankov
@ 2008-08-12 20:07 ` Rosen Diankov
  2008-08-14 20:31   ` bug#703: " Stefan Monnier
  2011-03-10  7:06 ` bug#697: " Glenn Morris
  1 sibling, 1 reply; 10+ messages in thread
From: Rosen Diankov @ 2008-08-12 20:07 UTC (permalink / raw)
  To: Olivier Lefevre; +Cc: bug-gnu-emacs, help

Small corrections:

In calculate-octave-indent, just delete the entire expression

((looking-at "\\s<\\S<")
       (setq icol (list comment-column icol)))

that forces comments to comment-column (which is 32). Was there a
reason for this?

Also, it should be noted that forcing single quotes to act like double
quotes in the syntax table really messes up the transposing of
matrices with the ' operator. If you care more about using single
quotes in your scripts (because of matlab compatibility), then just
use the transpose function instead of '

Is there a way to assign two different syntax rules for the same
character in emacs? Ie, one where ' is treated as a string quote (and
suppresses the syntax elements inside the quotes), and one where it is
treated as a suffix operator.

rosen,

2008/8/11 Rosen Diankov <rdiankov@cs.cmu.edu>:
> The % also messes up formatting when seen in strings, ie 'my value: %d'
>
> For some reason, the octave syntax does not recognize that single
> quotes are strings (it might be because the transpose character is
> also ' and it is hard to differentiate between a string and the
> transposing).
>
> In any case, writing the above example will treat the % as a comment.
> The indenting engine will skip the closing parenthesis )... resulting
> in all the rest of the indents looking like garbage.
>
> To fix the weird positioning of single % comments and the following
> problems, go tino octave-mod.el and
>
> in octave-mode-syntax-table change
> (modify-syntax-entry ?\' "." table)
> to
> (modify-syntax-entry ?\' "\"" table)
>
> in calculate-octave-indent at the bottom change
> ((looking-at "\\s<\\S<")
> to
> ((and (looking-at "\\s<\\S<") (not (looking-at "%")))
>
> i use (looking-at octave-comment-char) instead since some people use #
> for comments
>
>
> I'm not sure what the consequences of these changes are. From the
> testing I've done, emacs formatting is running more like how the
> matlab editor would format. Now if someone can fix the indentation
> problems with "end", we'll have perfect indenting.
>
> rosen diankov,
>
>
> 2007/12/28 Olivier Lefevre <lefevrol@yahoo.com>:
>> Ah OK. I had read about % vs. %% and %%% but it hadn't registered, perhaps
>> because it smelled perl-ish and thus went in one ear, out the other.
>> In the brain-damaged language(s) the other gentleman was referring to,
>> emacs will automatically indent the comment line according to its position
>>  in the code, without need for any of that %% or %%% flummery ;-) That is
>> both more natural and more practical, I think. But I can live with %%.
>>
>> Thanks again,
>>
>> -- O.L.
>>
>> _______________________________________________
>> Help-octave mailing list
>> Help-octave@octave.org
>> https://www.cae.wisc.edu/mailman/listinfo/help-octave
>>
>

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

* bug#703: Octave comments in emacs
@ 2008-08-13 22:18 Chong Yidong
  2008-08-20 16:55 ` Kurt Hornik
  0 siblings, 1 reply; 10+ messages in thread
From: Chong Yidong @ 2008-08-13 22:18 UTC (permalink / raw)
  To: Kurt Hornik; +Cc: Rosen Diankov, 703

Hi Kurt,

Could you take a look at this bug report?

http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=697
http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=703

Thanks.

2008/8/11 Rosen Diankov <rdiankov@cs.cmu.edu>:

> The % also messes up formatting when seen in strings, ie
> 'my value: %d'
>
> For some reason, the octave syntax does not recognize that single
> quotes are strings (it might be because the transpose character is
> also ' and it is hard to differentiate between a string and the
> transposing).
>
> In any case, writing the above example will treat the % as a comment.
> The indenting engine will skip the closing parenthesis )... resulting
> in all the rest of the indents looking like garbage.
>
....
>
> In calculate-octave-indent, just delete the entire expression
>
> ((looking-at "\\s<\\S<")
>        (setq icol (list comment-column icol)))
>
> that forces comments to comment-column (which is 32). Was there a
> reason for this?






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

* bug#703: Octave comments in emacs
  2008-08-12 20:07 ` Rosen Diankov
@ 2008-08-14 20:31   ` Stefan Monnier
  0 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2008-08-14 20:31 UTC (permalink / raw)
  To: Rosen Diankov; +Cc: Olivier Lefevre, bug-gnu-emacs, 703, help

> Is there a way to assign two different syntax rules for the same
> character in emacs? Ie, one where ' is treated as a string quote (and
> suppresses the syntax elements inside the quotes), and one where it is
> treated as a suffix operator.

Yes, there is, using the `syntax-table' property.
A common way to set this property is via the
font-lock-syntactic-keywords variable.

So all it takes is a regexp good enough to distinguish the two cases ;-)


        Stefan







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

* bug#703: Octave comments in emacs
  2008-08-13 22:18 bug#703: " Chong Yidong
@ 2008-08-20 16:55 ` Kurt Hornik
  2008-08-20 23:21   ` Rosen Diankov
  0 siblings, 1 reply; 10+ messages in thread
From: Kurt Hornik @ 2008-08-20 16:55 UTC (permalink / raw)
  To: Chong Yidong; +Cc: Kurt Hornik, Rosen Diankov, 703

>>>>> Chong Yidong writes:

> Hi Kurt,
> Could you take a look at this bug report?

> http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=697
> http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=703

> Thanks.

Sure.

I am not quite sure I understand what the issue is.

Octave mode has never provided syntax support for single quoted strings
because there is no way (short of actually parsing the code) of telling
these apart from single quotes used for transposition.

The comment style provided by Octave mode is the same as for Lisp mode,
so a single comment char is aligned at the comment column.

Best
-k

> 2008/8/11 Rosen Diankov <rdiankov@cs.cmu.edu>:

>> The % also messes up formatting when seen in strings, ie
>> 'my value: %d'
>> 
>> For some reason, the octave syntax does not recognize that single
>> quotes are strings (it might be because the transpose character is
>> also ' and it is hard to differentiate between a string and the
>> transposing).
>> 
>> In any case, writing the above example will treat the % as a comment.
>> The indenting engine will skip the closing parenthesis )... resulting
>> in all the rest of the indents looking like garbage.
>> 
> ....
>> 
>> In calculate-octave-indent, just delete the entire expression
>> 
>> ((looking-at "\\s<\\S<")
>> (setq icol (list comment-column icol)))
>> 
>> that forces comments to comment-column (which is 32). Was there a
>> reason for this?







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

* bug#703: Octave comments in emacs
  2008-08-20 16:55 ` Kurt Hornik
@ 2008-08-20 23:21   ` Rosen Diankov
  2008-08-20 23:27     ` Rosen Diankov
  0 siblings, 1 reply; 10+ messages in thread
From: Rosen Diankov @ 2008-08-20 23:21 UTC (permalink / raw)
  To: Kurt.Hornik; +Cc: Chong Yidong, 703

Hi all,

Coming from Matlab, I feel much more comfortable if the single quotes
were treated like double quotes (transposing is not as important), and
if the comments were aligned to the start of the next line (like the
// in C++). Given that a lot of people use Octave as a free
alternative to Matlab, I think a lot would expect the same formatting
rules as the matlab editor.

At least it would be great to expose these options to the user like
'octave-auto-indent' instead of having people hunt through
octave-mod.el to get the behavior they want.

Rosen,

2008/8/20 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>:
>>>>>> Chong Yidong writes:
>
>> Hi Kurt,
>> Could you take a look at this bug report?
>
>> http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=697
>> http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=703
>
>> Thanks.
>
> Sure.
>
> I am not quite sure I understand what the issue is.
>
> Octave mode has never provided syntax support for single quoted strings
> because there is no way (short of actually parsing the code) of telling
> these apart from single quotes used for transposition.
>
> The comment style provided by Octave mode is the same as for Lisp mode,
> so a single comment char is aligned at the comment column.
>
> Best
> -k
>
>> 2008/8/11 Rosen Diankov <rdiankov@cs.cmu.edu>:
>
>>> The % also messes up formatting when seen in strings, ie
>>> 'my value: %d'
>>>
>>> For some reason, the octave syntax does not recognize that single
>>> quotes are strings (it might be because the transpose character is
>>> also ' and it is hard to differentiate between a string and the
>>> transposing).
>>>
>>> In any case, writing the above example will treat the % as a comment.
>>> The indenting engine will skip the closing parenthesis )... resulting
>>> in all the rest of the indents looking like garbage.
>>>
>> ....
>>>
>>> In calculate-octave-indent, just delete the entire expression
>>>
>>> ((looking-at "\\s<\\S<")
>>> (setq icol (list comment-column icol)))
>>>
>>> that forces comments to comment-column (which is 32). Was there a
>>> reason for this?
>
>






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

* bug#703: Octave comments in emacs
  2008-08-20 23:21   ` Rosen Diankov
@ 2008-08-20 23:27     ` Rosen Diankov
  0 siblings, 0 replies; 10+ messages in thread
From: Rosen Diankov @ 2008-08-20 23:27 UTC (permalink / raw)
  To: Kurt.Hornik; +Cc: Chong Yidong, 703

And one other question, what would it take to get the Abstract Syntax
Tree for an Octave expression through elisp? Like Kurt said, we'll
need to parse the code in order to actually differentiate between the
transposing operator ' and a string. Isn't there anything in elisp
that will allow you to do this?

I'm willing to put some time into this if someone can start me off in
the right direction.

rosen,

2008/8/20 Rosen Diankov <rdiankov@cs.cmu.edu>:
> Hi all,
>
> Coming from Matlab, I feel much more comfortable if the single quotes
> were treated like double quotes (transposing is not as important), and
> if the comments were aligned to the start of the next line (like the
> // in C++). Given that a lot of people use Octave as a free
> alternative to Matlab, I think a lot would expect the same formatting
> rules as the matlab editor.
>
> At least it would be great to expose these options to the user like
> 'octave-auto-indent' instead of having people hunt through
> octave-mod.el to get the behavior they want.
>
> Rosen,
>
> 2008/8/20 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>:
>>>>>>> Chong Yidong writes:
>>
>>> Hi Kurt,
>>> Could you take a look at this bug report?
>>
>>> http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=697
>>> http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=703
>>
>>> Thanks.
>>
>> Sure.
>>
>> I am not quite sure I understand what the issue is.
>>
>> Octave mode has never provided syntax support for single quoted strings
>> because there is no way (short of actually parsing the code) of telling
>> these apart from single quotes used for transposition.
>>
>> The comment style provided by Octave mode is the same as for Lisp mode,
>> so a single comment char is aligned at the comment column.
>>
>> Best
>> -k
>>
>>> 2008/8/11 Rosen Diankov <rdiankov@cs.cmu.edu>:
>>
>>>> The % also messes up formatting when seen in strings, ie
>>>> 'my value: %d'
>>>>
>>>> For some reason, the octave syntax does not recognize that single
>>>> quotes are strings (it might be because the transpose character is
>>>> also ' and it is hard to differentiate between a string and the
>>>> transposing).
>>>>
>>>> In any case, writing the above example will treat the % as a comment.
>>>> The indenting engine will skip the closing parenthesis )... resulting
>>>> in all the rest of the indents looking like garbage.
>>>>
>>> ....
>>>>
>>>> In calculate-octave-indent, just delete the entire expression
>>>>
>>>> ((looking-at "\\s<\\S<")
>>>> (setq icol (list comment-column icol)))
>>>>
>>>> that forces comments to comment-column (which is 32). Was there a
>>>> reason for this?
>>
>>
>






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

* bug#703: Octave comments in emacs
@ 2008-08-21 15:55 Chong Yidong
  2008-08-21 18:26 ` Rosen Diankov
  0 siblings, 1 reply; 10+ messages in thread
From: Chong Yidong @ 2008-08-21 15:55 UTC (permalink / raw)
  To: Kurt Hornik; +Cc: Rosen Diankov, 703

Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> > Is there a way to assign two different syntax rules for the same
> > character in emacs? Ie, one where ' is treated as a string quote
> > (and suppresses the syntax elements inside the quotes), and one
> > where it is treated as a suffix operator.
>
> Yes, there is, using the `syntax-table' property.  A common way to set
> this property is via the font-lock-syntactic-keywords variable.
>
> So all it takes is a regexp good enough to distinguish the two cases

Kurt Hornik <Kurt.Hornik@wu-wien.ac.at> wrote:

> Octave mode has never provided syntax support for single quoted
> strings because there is no way (short of actually parsing the code)
> of telling these apart from single quotes used for transposition.

Maybe we could use a rough heuristic to handle most of the cases.  A '
character that occurs before "[=(] *" is probably the beginning of a
single quoted string, not a transpose operator.  WDYT?






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

* bug#703: Octave comments in emacs
  2008-08-21 15:55 Chong Yidong
@ 2008-08-21 18:26 ` Rosen Diankov
  0 siblings, 0 replies; 10+ messages in thread
From: Rosen Diankov @ 2008-08-21 18:26 UTC (permalink / raw)
  To: Chong Yidong; +Cc: lefevrol, Kurt Hornik, 703

> Maybe we could use a rough heuristic to handle most of the cases.  A '
> character that occurs before "[=(] *" is probably the beginning of a
> single quoted string, not a transpose operator.  WDYT?
I can think of a lot of cases where this would break.

The proper way of doing it is to tokenize a line and emulate a simple
parser. Although the rules that will be used to parse octave
expressions don't need to be thourough, they have to be sufficient
enough to detect transposition vs strings.

As far as I know, context free grammars are strictly more powerful
than regular expressions. A simple example is keeping track of [] and
(). So it might be impossible to generate a regular expression doing
what we want it to do.

Environments like Visual Studio and Eclipse do dynamic code analysis
all the time, so I would be surprised if emacs doesn't have some
equivalent parsing functionality.

Rosen,

2008/8/21 Chong Yidong <cyd@stupidchicken.com>:
> Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>
>> > Is there a way to assign two different syntax rules for the same
>> > character in emacs? Ie, one where ' is treated as a string quote
>> > (and suppresses the syntax elements inside the quotes), and one
>> > where it is treated as a suffix operator.
>>
>> Yes, there is, using the `syntax-table' property.  A common way to set
>> this property is via the font-lock-syntactic-keywords variable.
>>
>> So all it takes is a regexp good enough to distinguish the two cases
>
> Kurt Hornik <Kurt.Hornik@wu-wien.ac.at> wrote:
>
>> Octave mode has never provided syntax support for single quoted
>> strings because there is no way (short of actually parsing the code)
>> of telling these apart from single quotes used for transposition.
>
> Maybe we could use a rough heuristic to handle most of the cases.  A '
> character that occurs before "[=(] *" is probably the beginning of a
> single quoted string, not a transpose operator.  WDYT?
>






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

* bug#697: Octave comments in emacs
  2008-08-12  2:36 Octave comments in emacs Rosen Diankov
  2008-08-12 20:07 ` Rosen Diankov
@ 2011-03-10  7:06 ` Glenn Morris
  1 sibling, 0 replies; 10+ messages in thread
From: Glenn Morris @ 2011-03-10  7:06 UTC (permalink / raw)
  To: 697-done


Octave mode has undergone considerable changes in the Emacs trunk.
Please open new reports for any issues that may occur.





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

end of thread, other threads:[~2011-03-10  7:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-12  2:36 Octave comments in emacs Rosen Diankov
2008-08-12 20:07 ` Rosen Diankov
2008-08-14 20:31   ` bug#703: " Stefan Monnier
2011-03-10  7:06 ` bug#697: " Glenn Morris
  -- strict thread matches above, loose matches on Subject: below --
2008-08-13 22:18 bug#703: " Chong Yidong
2008-08-20 16:55 ` Kurt Hornik
2008-08-20 23:21   ` Rosen Diankov
2008-08-20 23:27     ` Rosen Diankov
2008-08-21 15:55 Chong Yidong
2008-08-21 18:26 ` Rosen Diankov

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.