git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
* [PATCH] doc/gitattributes: add Octave
@ 2019-05-10  0:47 Boxuan Li
  2019-05-10 23:09 ` Philip Oakley
  2019-05-10 23:26 ` Ævar Arnfjörð Bjarmason
  0 siblings, 2 replies; 19+ messages in thread
From: Boxuan Li @ 2019-05-10  0:47 UTC (permalink / raw)
  To: git; +Cc: Boxuan Li

`matlab` pattern is also suitable for source code
in the GNU Octave language.

Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
---
 Documentation/gitattributes.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 4fb20cd0e9..1b28381bda 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -819,7 +819,7 @@ patterns are available:
 
 - `java` suitable for source code in the Java language.
 
-- `matlab` suitable for source code in the MATLAB language.
+- `matlab` suitable for source code in the MATLAB/Octave language.
 
 - `objc` suitable for source code in the Objective-C language.
 
-- 
2.21.0.777.g83232e3864


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

* Re: [PATCH] doc/gitattributes: add Octave
  2019-05-10  0:47 [PATCH] doc/gitattributes: add Octave Boxuan Li
@ 2019-05-10 23:09 ` Philip Oakley
  2019-05-10 23:26 ` Ævar Arnfjörð Bjarmason
  1 sibling, 0 replies; 19+ messages in thread
From: Philip Oakley @ 2019-05-10 23:09 UTC (permalink / raw)
  To: Boxuan Li, git

On 10/05/2019 01:47, Boxuan Li wrote:
> `matlab` pattern is also suitable for source code
> in the GNU Octave language.
>
> Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
> ---
>   Documentation/gitattributes.txt | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
> index 4fb20cd0e9..1b28381bda 100644
> --- a/Documentation/gitattributes.txt
> +++ b/Documentation/gitattributes.txt
> @@ -819,7 +819,7 @@ patterns are available:
>   
>   - `java` suitable for source code in the Java language.
>   
> -- `matlab` suitable for source code in the MATLAB language.
> +- `matlab` suitable for source code in the MATLAB/Octave language.
>   
>   - `objc` suitable for source code in the Objective-C language.
>   
Looks good to me.
Will help Octave users searching on their name for the Open Source 
variant of Matlab.
--
Philip

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

* Re: [PATCH] doc/gitattributes: add Octave
  2019-05-10  0:47 [PATCH] doc/gitattributes: add Octave Boxuan Li
  2019-05-10 23:09 ` Philip Oakley
@ 2019-05-10 23:26 ` Ævar Arnfjörð Bjarmason
  2019-05-11  2:36   ` LI, BO XUAN
  1 sibling, 1 reply; 19+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2019-05-10 23:26 UTC (permalink / raw)
  To: Boxuan Li; +Cc: git


On Fri, May 10 2019, Boxuan Li wrote:

> `matlab` pattern is also suitable for source code
> in the GNU Octave language.
>
> Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
> ---
>  Documentation/gitattributes.txt | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
> index 4fb20cd0e9..1b28381bda 100644
> --- a/Documentation/gitattributes.txt
> +++ b/Documentation/gitattributes.txt
> @@ -819,7 +819,7 @@ patterns are available:
>
>  - `java` suitable for source code in the Java language.
>
> -- `matlab` suitable for source code in the MATLAB language.
> +- `matlab` suitable for source code in the MATLAB/Octave language.
>
>  - `objc` suitable for source code in the Objective-C language.

I've never used either, but browsing our patterns I see:

         "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",

I.e. that last bit matches ^%%, and then here:
https://en.wikibooks.org/wiki/MATLAB_Programming/Differences_between_Octave_and_MATLAB

    MATLAB uses the percent sign '%' to begin a comment. Octave uses
    both the hash symbol # and the percent sign % interchangeably.

So here we have the "function" pattern matching a comment, right? (this
doesn't have any tests) and we'd want to add "#" to Octave, but not
MATLAB.

I see both tend to use the ".m" extension. Anyway, isn't it better to
add an "octave" pattern, and document that they're mostly the same
(although it looks like we can add #-comments, to future-proof
ourselves?

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

* Re: [PATCH] doc/gitattributes: add Octave
  2019-05-10 23:26 ` Ævar Arnfjörð Bjarmason
@ 2019-05-11  2:36   ` LI, BO XUAN
  2019-05-11  4:08     ` [PATCH v2] userdiff.c & doc/gitattributes.txt: " Boxuan Li
                       ` (3 more replies)
  0 siblings, 4 replies; 19+ messages in thread
From: LI, BO XUAN @ 2019-05-11  2:36 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: git

On Sat, May 11, 2019 at 7:26 AM Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
>
>
> On Fri, May 10 2019, Boxuan Li wrote:
>
> > `matlab` pattern is also suitable for source code
> > in the GNU Octave language.
> >
> > Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
> > ---
> >  Documentation/gitattributes.txt | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
> > index 4fb20cd0e9..1b28381bda 100644
> > --- a/Documentation/gitattributes.txt
> > +++ b/Documentation/gitattributes.txt
> > @@ -819,7 +819,7 @@ patterns are available:
> >
> >  - `java` suitable for source code in the Java language.
> >
> > -- `matlab` suitable for source code in the MATLAB language.
> > +- `matlab` suitable for source code in the MATLAB/Octave language.
> >
> >  - `objc` suitable for source code in the Objective-C language.
>
> I've never used either, but browsing our patterns I see:
>
>          "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
>
> I.e. that last bit matches ^%%, and then here:
> https://en.wikibooks.org/wiki/MATLAB_Programming/Differences_between_Octave_and_MATLAB
>
>     MATLAB uses the percent sign '%' to begin a comment. Octave uses
>     both the hash symbol # and the percent sign % interchangeably.
>
> So here we have the "function" pattern matching a comment, right? (this
> doesn't have any tests) and we'd want to add "#" to Octave, but not
> MATLAB.

Thanks, that's a great catch! Actually, '%%' is used to start a code
section in Matlab
(https://www.mathworks.com/help/matlab/matlab_prog/run-sections-of-programs.html),
while Octave uses both '%%' and '##'
(https://octave.org/doc/interpreter/Sections.html).

>
> I see both tend to use the ".m" extension. Anyway, isn't it better to
> add an "octave" pattern, and document that they're mostly the same

I agree. I'll send an updated patch soon.

> (although it looks like we can add #-comments, to future-proof
> ourselves?

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

* [PATCH v2] userdiff.c & doc/gitattributes.txt: add Octave
  2019-05-11  2:36   ` LI, BO XUAN
@ 2019-05-11  4:08     ` " Boxuan Li
  2019-05-11  4:13     ` [PATCH v3] " Boxuan Li
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 19+ messages in thread
From: Boxuan Li @ 2019-05-11  4:08 UTC (permalink / raw)
  To: git; +Cc: avarab, philipoakley, Boxuan Li

Octave pattern is almost the same as matlab. Besides,
octave also uses '%%%' or '##' to begin code sections.

Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
---
v1: use matlab pattern for octave language
---
 Documentation/gitattributes.txt | 2 ++
 userdiff.c                      | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 4fb20cd0e9..45374c7dd3 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -821,6 +821,8 @@ patterns are available:
 
 - `matlab` suitable for source code in the MATLAB language.
 
+- `octave` suitable for source code in the Octave language.
+
 - `objc` suitable for source code in the Objective-C language.
 
 - `pascal` suitable for source code in the Pascal/Delphi language.
diff --git a/userdiff.c b/userdiff.c
index 3a78fbf504..6e9b56f1d6 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -60,6 +60,11 @@ PATTERNS("java",
 PATTERNS("matlab",
 	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
 	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
+PATTERNS("octave",
+     /* Mostly the same as matlab. In addition, Octave
+      * supports '##' and '%%%' for code sections */
+     "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
+     "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
 PATTERNS("objc",
 	 /* Negate C statements that can look like functions */
 	 "!^[ \t]*(do|for|if|else|return|switch|while)\n"
-- 
2.21.0.777.g83232e3864


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

* [PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave
  2019-05-11  2:36   ` LI, BO XUAN
  2019-05-11  4:08     ` [PATCH v2] userdiff.c & doc/gitattributes.txt: " Boxuan Li
@ 2019-05-11  4:13     ` " Boxuan Li
  2019-05-15  5:35       ` Junio C Hamano
  2019-05-15  5:57       ` Johannes Sixt
  2019-05-15  5:55     ` [PATCH v4] " Boxuan Li
  2019-05-18  3:46     ` [PATCH v5] userdiff: " Boxuan Li
  3 siblings, 2 replies; 19+ messages in thread
From: Boxuan Li @ 2019-05-11  4:13 UTC (permalink / raw)
  To: git; +Cc: avarab, philipoakley, Boxuan Li

Octave pattern is almost the same as matlab. Besides,
octave also uses '%%%' or '##' to begin code sections.

Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
---
Update from v2: fix indentation
---
 Documentation/gitattributes.txt | 2 ++
 userdiff.c                      | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 4fb20cd0e9..45374c7dd3 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -821,6 +821,8 @@ patterns are available:
 
 - `matlab` suitable for source code in the MATLAB language.
 
+- `octave` suitable for source code in the Octave language.
+
 - `objc` suitable for source code in the Objective-C language.
 
 - `pascal` suitable for source code in the Pascal/Delphi language.
diff --git a/userdiff.c b/userdiff.c
index 3a78fbf504..7d07b82116 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -60,6 +60,11 @@ PATTERNS("java",
 PATTERNS("matlab",
 	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
 	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
+PATTERNS("octave",
+	 /* Mostly the same as matlab. In addition, Octave
+	  * supports '##' and '%%%' for code sections */
+	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
+	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
 PATTERNS("objc",
 	 /* Negate C statements that can look like functions */
 	 "!^[ \t]*(do|for|if|else|return|switch|while)\n"
-- 
2.21.0.777.g83232e3864


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

* Re: [PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave
  2019-05-11  4:13     ` [PATCH v3] " Boxuan Li
@ 2019-05-15  5:35       ` Junio C Hamano
  2019-05-15  5:57       ` Johannes Sixt
  1 sibling, 0 replies; 19+ messages in thread
From: Junio C Hamano @ 2019-05-15  5:35 UTC (permalink / raw)
  To: Boxuan Li; +Cc: git, avarab, philipoakley

Boxuan Li <liboxuan@connect.hku.hk> writes:

> Octave pattern is almost the same as matlab. Besides,
> octave also uses '%%%' or '##' to begin code sections.

My reading of the above hiccupped at around "Besides, octave also
uses...".

Checking the differences in patterns, I think

	... the same as matlab, except that '%%%' and '##' can also
	be used to begin code sections, in addition to '%%' that is
	understood by both.

may be easier to read. It makes it clear that you'd want to stay
away from %%% and ## if you want to be compatible.

Thanks.

> Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
> ---
> Update from v2: fix indentation
> ---
>  Documentation/gitattributes.txt | 2 ++
>  userdiff.c                      | 5 +++++
>  2 files changed, 7 insertions(+)
>
> diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
> index 4fb20cd0e9..45374c7dd3 100644
> --- a/Documentation/gitattributes.txt
> +++ b/Documentation/gitattributes.txt
> @@ -821,6 +821,8 @@ patterns are available:
>  
>  - `matlab` suitable for source code in the MATLAB language.
>  
> +- `octave` suitable for source code in the Octave language.
> +
>  - `objc` suitable for source code in the Objective-C language.
>  
>  - `pascal` suitable for source code in the Pascal/Delphi language.
> diff --git a/userdiff.c b/userdiff.c
> index 3a78fbf504..7d07b82116 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -60,6 +60,11 @@ PATTERNS("java",
>  PATTERNS("matlab",
>  	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
>  	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
> +PATTERNS("octave",
> +	 /* Mostly the same as matlab. In addition, Octave
> +	  * supports '##' and '%%%' for code sections */
> +	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
> +	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
>  PATTERNS("objc",
>  	 /* Negate C statements that can look like functions */
>  	 "!^[ \t]*(do|for|if|else|return|switch|while)\n"

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

* [PATCH v4] userdiff.c & doc/gitattributes.txt: add Octave
  2019-05-11  2:36   ` LI, BO XUAN
  2019-05-11  4:08     ` [PATCH v2] userdiff.c & doc/gitattributes.txt: " Boxuan Li
  2019-05-11  4:13     ` [PATCH v3] " Boxuan Li
@ 2019-05-15  5:55     ` " Boxuan Li
  2019-05-18  3:46     ` [PATCH v5] userdiff: " Boxuan Li
  3 siblings, 0 replies; 19+ messages in thread
From: Boxuan Li @ 2019-05-15  5:55 UTC (permalink / raw)
  To: git; +Cc: avarab, philipoakley, gitster, Boxuan Li

Octave pattern is almost the same as matlab, except
that '%%%' and '##' can also be used to begin code sections,
in addition to '%%' that is understood by both.

Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
---
Thanks to all the reviewers above, this is the fourth version:
v1: use matlab pattern for octave
v2: add a new octave pattern
v3: fix indentation problem of v2
v4: improve doc and commit message
---
 Documentation/gitattributes.txt | 2 ++
 userdiff.c                      | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 4fb20cd0e9..45374c7dd3 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -821,6 +821,8 @@ patterns are available:
 
 - `matlab` suitable for source code in the MATLAB language.
 
+- `octave` suitable for source code in the Octave language.
+
 - `objc` suitable for source code in the Objective-C language.
 
 - `pascal` suitable for source code in the Pascal/Delphi language.
diff --git a/userdiff.c b/userdiff.c
index 3a78fbf504..1127a4c6b1 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -60,6 +60,11 @@ PATTERNS("java",
 PATTERNS("matlab",
 	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
 	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
+PATTERNS("octave",
+	 /* Mostly the same as matlab, except that '%%%' and '##' can also be used
+	  * to begin code sections, in addition to '%%' that is understood by both. */
+	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
+	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
 PATTERNS("objc",
 	 /* Negate C statements that can look like functions */
 	 "!^[ \t]*(do|for|if|else|return|switch|while)\n"
-- 
2.21.0.777.g83232e3864


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

* Re: [PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave
  2019-05-11  4:13     ` [PATCH v3] " Boxuan Li
  2019-05-15  5:35       ` Junio C Hamano
@ 2019-05-15  5:57       ` Johannes Sixt
  2019-05-15  6:15         ` LI, BO XUAN
  1 sibling, 1 reply; 19+ messages in thread
From: Johannes Sixt @ 2019-05-15  5:57 UTC (permalink / raw)
  To: Boxuan Li; +Cc: git, avarab, philipoakley

Am 11.05.19 um 06:13 schrieb Boxuan Li:
> Octave pattern is almost the same as matlab. Besides,
> octave also uses '%%%' or '##' to begin code sections.
> 

> @@ -60,6 +60,11 @@ PATTERNS("java",
>  PATTERNS("matlab",
>  	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
>  	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
> +PATTERNS("octave",
> +	 /* Mostly the same as matlab. In addition, Octave
> +	  * supports '##' and '%%%' for code sections */
> +	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
> +	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
>  PATTERNS("objc",
>  	 /* Negate C statements that can look like functions */
>  	 "!^[ \t]*(do|for|if|else|return|switch|while)\n"
> 

In Matlab, are %%% and ## valid syntax? If not, instead of introducing a
new language, please just extend the Matlab rule to treat %%% and ## as
you need for Octave and mark your Octave files as Matlab.

-- Hannes

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

* Re: [PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave
  2019-05-15  5:57       ` Johannes Sixt
@ 2019-05-15  6:15         ` LI, BO XUAN
  2019-05-15 17:46           ` Johannes Sixt
  0 siblings, 1 reply; 19+ messages in thread
From: LI, BO XUAN @ 2019-05-15  6:15 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: git, Ævar Arnfjörð Bjarmason, philipoakley

On Wed, May 15, 2019 at 1:57 PM Johannes Sixt <j6t@kdbg.org> wrote:
>
> Am 11.05.19 um 06:13 schrieb Boxuan Li:
> > Octave pattern is almost the same as matlab. Besides,
> > octave also uses '%%%' or '##' to begin code sections.
> >
>
> > @@ -60,6 +60,11 @@ PATTERNS("java",
> >  PATTERNS("matlab",
> >        "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
> >        "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
> > +PATTERNS("octave",
> > +      /* Mostly the same as matlab. In addition, Octave
> > +       * supports '##' and '%%%' for code sections */
> > +      "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
> > +      "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
> >  PATTERNS("objc",
> >        /* Negate C statements that can look like functions */
> >        "!^[ \t]*(do|for|if|else|return|switch|while)\n"
> >
>
> In Matlab, are %%% and ## valid syntax? If not, instead of introducing a
> new language, please just extend the Matlab rule to treat %%% and ## as
> you need for Octave and mark your Octave files as Matlab.
>
> -- Hannes

Hi Hannes,

'##' is not valid syntax in Matlab scripts.

'%%%' is valid syntax in Matlab. However, it is not used as a section divider.

ref: https://www.mathworks.com/help/matlab/matlab_prog/run-sections-of-programs.html
ref: https://octave.org/doc/interpreter/Sections.html

Best regards,
Boxuan

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

* Re: [PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave
  2019-05-15  6:15         ` LI, BO XUAN
@ 2019-05-15 17:46           ` Johannes Sixt
  2019-05-16  9:19             ` Junio C Hamano
  0 siblings, 1 reply; 19+ messages in thread
From: Johannes Sixt @ 2019-05-15 17:46 UTC (permalink / raw)
  To: LI, BO XUAN; +Cc: git, Ævar Arnfjörð Bjarmason, philipoakley

Am 15.05.19 um 08:15 schrieb LI, BO XUAN:
> On Wed, May 15, 2019 at 1:57 PM Johannes Sixt <j6t@kdbg.org> wrote:
>>
>> Am 11.05.19 um 06:13 schrieb Boxuan Li:
>>> Octave pattern is almost the same as matlab. Besides,
>>> octave also uses '%%%' or '##' to begin code sections.
>>>
>>
>>> @@ -60,6 +60,11 @@ PATTERNS("java",
>>>  PATTERNS("matlab",
>>>        "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
>>>        "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
>>> +PATTERNS("octave",
>>> +      /* Mostly the same as matlab. In addition, Octave
>>> +       * supports '##' and '%%%' for code sections */
>>> +      "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
>>> +      "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
>>>  PATTERNS("objc",
>>>        /* Negate C statements that can look like functions */
>>>        "!^[ \t]*(do|for|if|else|return|switch|while)\n"
>>>
>>
>> In Matlab, are %%% and ## valid syntax? If not, instead of introducing a
>> new language, please just extend the Matlab rule to treat %%% and ## as
>> you need for Octave and mark your Octave files as Matlab.
> 
> '##' is not valid syntax in Matlab scripts.
> 
> '%%%' is valid syntax in Matlab. However, it is not used as a section divider.

In Matlab, is %%% followed by space at the beginning of a line
*commonly* used for something different? If I were to make a guess, I
would say no. If I'm right, it does not hurt to merge the Octave rules
into the Matlab rules.

-- Hannes

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

* Re: [PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave
  2019-05-15 17:46           ` Johannes Sixt
@ 2019-05-16  9:19             ` Junio C Hamano
  2019-05-16 19:20               ` Johannes Sixt
  0 siblings, 1 reply; 19+ messages in thread
From: Junio C Hamano @ 2019-05-16  9:19 UTC (permalink / raw)
  To: Johannes Sixt
  Cc: LI\, BO XUAN, git, Ævar Arnfjörð Bjarmason, philipoakley

Johannes Sixt <j6t@kdbg.org> writes:

> In Matlab, is %%% followed by space at the beginning of a line
> *commonly* used for something different? If I were to make a guess, I
> would say no. If I'm right, it does not hurt to merge the Octave rules
> into the Matlab rules.

That is true because we are not syntax-aware and error-highlighting
text editor.  If we were, I'd suspect that your stance may probably
be different.  But instead we apply these patterns to a program that
is assumed to be correctly written.

And from that point of view, I agree with you that it would not hurt
to make the existing patterns for Matlab slightly more receptive so
that a correctly written programs in either language would be matched
appropriately.

But would it hurt to have two similar entries, with a clear
description on how they are different, in our code there, given how
infrequently individual entries have historically been updated?

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

* Re: [PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave
  2019-05-16  9:19             ` Junio C Hamano
@ 2019-05-16 19:20               ` Johannes Sixt
  2019-05-16 23:33                 ` Junio C Hamano
  0 siblings, 1 reply; 19+ messages in thread
From: Johannes Sixt @ 2019-05-16 19:20 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: LI, BO XUAN, git, Ævar Arnfjörð Bjarmason, philipoakley

Am 16.05.19 um 11:19 schrieb Junio C Hamano:
> Johannes Sixt <j6t@kdbg.org> writes:
> 
>> In Matlab, is %%% followed by space at the beginning of a line
>> *commonly* used for something different? If I were to make a guess, I
>> would say no. If I'm right, it does not hurt to merge the Octave rules
>> into the Matlab rules.
> 
> That is true because we are not syntax-aware and error-highlighting
> text editor.  If we were, I'd suspect that your stance may probably
> be different.  But instead we apply these patterns to a program that
> is assumed to be correctly written.

Correct!

> And from that point of view, I agree with you that it would not hurt
> to make the existing patterns for Matlab slightly more receptive so
> that a correctly written programs in either language would be matched
> appropriately.
> 
> But would it hurt to have two similar entries, with a clear
> description on how they are different, in our code there, given how
> infrequently individual entries have historically been updated?

Would it hurt? Probably not. Should we open the door for everybody's
favorite dialect? Probably not, either.

See, we do not even have separate entries for C and C++. Heck, we don't
have an XML entry, because the HTML entry is good enough, and there are
probably many more XML users than Matlab and Octave users together.

I'd prefer to keep this list at the minimum necessary as long as it is
hard-coded in C. I would take a different stance if this were some
configuration file that we ship.

-- Hannes

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

* Re: [PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave
  2019-05-16 19:20               ` Johannes Sixt
@ 2019-05-16 23:33                 ` Junio C Hamano
  2019-05-17 12:19                   ` LI, BO XUAN
  0 siblings, 1 reply; 19+ messages in thread
From: Junio C Hamano @ 2019-05-16 23:33 UTC (permalink / raw)
  To: Johannes Sixt
  Cc: LI\, BO XUAN, git, Ævar Arnfjörð Bjarmason, philipoakley

Johannes Sixt <j6t@kdbg.org> writes:

> I'd prefer to keep this list at the minimum necessary as long as it is
> hard-coded in C.

Yeah, I know that feeling.

> I would take a different stance if this were some
> configuration file that we ship.

Hmm, now you reminded me of my ancient wish.

Perhaps it is not too bad to ship $(sharedir)/git-core/userdiff that
can be read using git_config_from_file() interface, using a very
narrow callback function that understands only diff.*.xfuncname and
diff.*.wordregex and discards everything else, without even
following the include/includeIf stuff?  As long as that can be done
safely and without too much overhead, we could get rid of the
hardcoded patterns in userdiff.c::builtin_drivers[] and that would
be wonderful ;-)


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

* Re: [PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave
  2019-05-16 23:33                 ` Junio C Hamano
@ 2019-05-17 12:19                   ` LI, BO XUAN
  2019-05-17 19:47                     ` Johannes Sixt
  0 siblings, 1 reply; 19+ messages in thread
From: LI, BO XUAN @ 2019-05-17 12:19 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Johannes Sixt, git, Ævar Arnfjörð Bjarmason, philipoakley

On Fri, May 17, 2019 at 7:34 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Johannes Sixt <j6t@kdbg.org> writes:
>
> > I'd prefer to keep this list at the minimum necessary as long as it is
> > hard-coded in C.
>
> Yeah, I know that feeling.
>

So do we reach a consensus? Should I merge the Octave rules into Matlab rules?

Best regards,
Boxuan

> > I would take a different stance if this were some
> > configuration file that we ship.
>
> Hmm, now you reminded me of my ancient wish.
>
> Perhaps it is not too bad to ship $(sharedir)/git-core/userdiff that
> can be read using git_config_from_file() interface, using a very
> narrow callback function that understands only diff.*.xfuncname and
> diff.*.wordregex and discards everything else, without even
> following the include/includeIf stuff?  As long as that can be done
> safely and without too much overhead, we could get rid of the
> hardcoded patterns in userdiff.c::builtin_drivers[] and that would
> be wonderful ;-)
>

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

* Re: [PATCH v3] userdiff.c & doc/gitattributes.txt: add Octave
  2019-05-17 12:19                   ` LI, BO XUAN
@ 2019-05-17 19:47                     ` Johannes Sixt
  0 siblings, 0 replies; 19+ messages in thread
From: Johannes Sixt @ 2019-05-17 19:47 UTC (permalink / raw)
  To: LI, BO XUAN
  Cc: Junio C Hamano, git, Ævar Arnfjörð Bjarmason,
	philipoakley

Am 17.05.19 um 14:19 schrieb LI, BO XUAN:
> On Fri, May 17, 2019 at 7:34 AM Junio C Hamano <gitster@pobox.com> wrote:
>>
>> Johannes Sixt <j6t@kdbg.org> writes:
>>
>>> I'd prefer to keep this list at the minimum necessary as long as it is
>>> hard-coded in C.
>>
>> Yeah, I know that feeling.
> 
> So do we reach a consensus? Should I merge the Octave rules into Matlab rules?

Yes, please, that would be very much appreciated. Bonus points if you
add some test cases for the hunk header patterns to the t/t4018 directory.

-- Hannes

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

* [PATCH v5] userdiff: add Octave
  2019-05-11  2:36   ` LI, BO XUAN
                       ` (2 preceding siblings ...)
  2019-05-15  5:55     ` [PATCH v4] " Boxuan Li
@ 2019-05-18  3:46     ` " Boxuan Li
  2019-05-20 19:26       ` Johannes Sixt
  3 siblings, 1 reply; 19+ messages in thread
From: Boxuan Li @ 2019-05-18  3:46 UTC (permalink / raw)
  To: git; +Cc: avarab, philipoakley, gitster, j6t, Boxuan Li

Octave pattern is almost the same as matlab, except
that '%%%' and '##' can also be used to begin code sections,
in addition to '%%' that is understood by both. Octave
pattern is merged into Matlab pattern. Test cases for
the hunk header patterns of matlab and octave under
t/t4018 are added.

Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
---
v1: use matlab pattern for octave
v2: add a new octave pattern
v3: fix indentation problem of v2
v4: improve doc and commit message
v5: merge octave pattern into matlab and add test cases
---
 Documentation/gitattributes.txt | 2 +-
 t/t4018/matlab-class-definition | 5 +++++
 t/t4018/matlab-function         | 4 ++++
 t/t4018/matlab-octave-section-1 | 3 +++
 t/t4018/matlab-octave-section-2 | 3 +++
 t/t4018/matlab-section          | 3 +++
 userdiff.c                      | 5 ++++-
 7 files changed, 23 insertions(+), 2 deletions(-)
 create mode 100644 t/t4018/matlab-class-definition
 create mode 100644 t/t4018/matlab-function
 create mode 100644 t/t4018/matlab-octave-section-1
 create mode 100644 t/t4018/matlab-octave-section-2
 create mode 100644 t/t4018/matlab-section

diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 4fb20cd0e9..e657a6b7b7 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -819,7 +819,7 @@ patterns are available:
 
 - `java` suitable for source code in the Java language.
 
-- `matlab` suitable for source code in the MATLAB language.
+- `matlab` suitable for source code in the MATLAB and Octave language.
 
 - `objc` suitable for source code in the Objective-C language.
 
diff --git a/t/t4018/matlab-class-definition b/t/t4018/matlab-class-definition
new file mode 100644
index 0000000000..84daedfb4e
--- /dev/null
+++ b/t/t4018/matlab-class-definition
@@ -0,0 +1,5 @@
+classdef RIGHT
+    properties
+        ChangeMe
+    end
+end
diff --git a/t/t4018/matlab-function b/t/t4018/matlab-function
new file mode 100644
index 0000000000..897a9b13ff
--- /dev/null
+++ b/t/t4018/matlab-function
@@ -0,0 +1,4 @@
+function y = RIGHT()
+x = 5;
+y = ChangeMe + x;
+end
diff --git a/t/t4018/matlab-octave-section-1 b/t/t4018/matlab-octave-section-1
new file mode 100644
index 0000000000..3bb6c4670e
--- /dev/null
+++ b/t/t4018/matlab-octave-section-1
@@ -0,0 +1,3 @@
+%%% RIGHT section
+# this is octave script
+ChangeMe = 1;
diff --git a/t/t4018/matlab-octave-section-2 b/t/t4018/matlab-octave-section-2
new file mode 100644
index 0000000000..ab2980f7f2
--- /dev/null
+++ b/t/t4018/matlab-octave-section-2
@@ -0,0 +1,3 @@
+## RIGHT section
+# this is octave script
+ChangeMe = 1;
diff --git a/t/t4018/matlab-section b/t/t4018/matlab-section
new file mode 100644
index 0000000000..5ea59a5de0
--- /dev/null
+++ b/t/t4018/matlab-section
@@ -0,0 +1,3 @@
+%% RIGHT section
+% this is understood by both matlab and octave
+ChangeMe = 1;
diff --git a/userdiff.c b/userdiff.c
index 3a78fbf504..bcae006abe 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -58,7 +58,10 @@ PATTERNS("java",
 	 "|[-+*/<>%&^|=!]="
 	 "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
 PATTERNS("matlab",
-	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
+	 /* Octave pattern is mostly the same as matlab, except that '%%%' and
+	  * '##' can also be used to begin code sections, in addition to '%%'
+	  * that is understood by both. */
+	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
 	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
 PATTERNS("objc",
 	 /* Negate C statements that can look like functions */
-- 
2.21.0.777.g83232e3864


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

* Re: [PATCH v5] userdiff: add Octave
  2019-05-18  3:46     ` [PATCH v5] userdiff: " Boxuan Li
@ 2019-05-20 19:26       ` Johannes Sixt
  2019-05-21 14:57         ` [PATCH v6] " Boxuan Li
  0 siblings, 1 reply; 19+ messages in thread
From: Johannes Sixt @ 2019-05-20 19:26 UTC (permalink / raw)
  To: Boxuan Li; +Cc: git, avarab, philipoakley, gitster

Am 18.05.19 um 05:46 schrieb Boxuan Li:
> Octave pattern is almost the same as matlab, except
> that '%%%' and '##' can also be used to begin code sections,
> in addition to '%%' that is understood by both. Octave
> pattern is merged into Matlab pattern. Test cases for
> the hunk header patterns of matlab and octave under
> t/t4018 are added.

Thank you! This patch looks good. With or without the grammar and style
fixes below:

Acked-by: Johannes Sixt <j6t@kdbg.org>

Junio will very likely appreciate if you resend with these fixes applied.

> 
> Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
> ---
> v1: use matlab pattern for octave
> v2: add a new octave pattern
> v3: fix indentation problem of v2
> v4: improve doc and commit message
> v5: merge octave pattern into matlab and add test cases
> ---

> diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
> index 4fb20cd0e9..e657a6b7b7 100644
> --- a/Documentation/gitattributes.txt
> +++ b/Documentation/gitattributes.txt
> @@ -819,7 +819,7 @@ patterns are available:
>  
>  - `java` suitable for source code in the Java language.
>  
> -- `matlab` suitable for source code in the MATLAB language.
> +- `matlab` suitable for source code in the MATLAB and Octave language.

s/language/languages/

>  
>  - `objc` suitable for source code in the Objective-C language.
>  

> diff --git a/userdiff.c b/userdiff.c
> index 3a78fbf504..bcae006abe 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -58,7 +58,10 @@ PATTERNS("java",
>  	 "|[-+*/<>%&^|=!]="
>  	 "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
>  PATTERNS("matlab",
> -	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
> +	 /* Octave pattern is mostly the same as matlab, except that '%%%' and
> +	  * '##' can also be used to begin code sections, in addition to '%%'
> +	  * that is understood by both. */

	/*
	 * We write multi-line
	 * comments like this.
	 */

> +	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
>  	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
>  PATTERNS("objc",
>  	 /* Negate C statements that can look like functions */
> 

-- Hannes

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

* [PATCH v6] userdiff: add Octave
  2019-05-20 19:26       ` Johannes Sixt
@ 2019-05-21 14:57         ` " Boxuan Li
  0 siblings, 0 replies; 19+ messages in thread
From: Boxuan Li @ 2019-05-21 14:57 UTC (permalink / raw)
  To: git; +Cc: avarab, philipoakley, gitster, j6t, Boxuan Li

Octave pattern is almost the same as matlab, except
that '%%%' and '##' can also be used to begin code sections,
in addition to '%%' that is understood by both. Octave
pattern is merged into Matlab pattern. Test cases for
the hunk header patterns of matlab and octave under
t/t4018 are added.

Signed-off-by: Boxuan Li <liboxuan@connect.hku.hk>
Acked-by: Johannes Sixt <j6t@kdbg.org>
---
Thanks to review from Johannes, update from v5:
Fix grammar and style
---
 Documentation/gitattributes.txt | 2 +-
 t/t4018/matlab-class-definition | 5 +++++
 t/t4018/matlab-function         | 4 ++++
 t/t4018/matlab-octave-section-1 | 3 +++
 t/t4018/matlab-octave-section-2 | 3 +++
 t/t4018/matlab-section          | 3 +++
 userdiff.c                      | 7 ++++++-
 7 files changed, 25 insertions(+), 2 deletions(-)
 create mode 100644 t/t4018/matlab-class-definition
 create mode 100644 t/t4018/matlab-function
 create mode 100644 t/t4018/matlab-octave-section-1
 create mode 100644 t/t4018/matlab-octave-section-2
 create mode 100644 t/t4018/matlab-section

diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 4fb20cd0e9..e387cc6dda 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -819,7 +819,7 @@ patterns are available:
 
 - `java` suitable for source code in the Java language.
 
-- `matlab` suitable for source code in the MATLAB language.
+- `matlab` suitable for source code in the MATLAB and Octave languages.
 
 - `objc` suitable for source code in the Objective-C language.
 
diff --git a/t/t4018/matlab-class-definition b/t/t4018/matlab-class-definition
new file mode 100644
index 0000000000..84daedfb4e
--- /dev/null
+++ b/t/t4018/matlab-class-definition
@@ -0,0 +1,5 @@
+classdef RIGHT
+    properties
+        ChangeMe
+    end
+end
diff --git a/t/t4018/matlab-function b/t/t4018/matlab-function
new file mode 100644
index 0000000000..897a9b13ff
--- /dev/null
+++ b/t/t4018/matlab-function
@@ -0,0 +1,4 @@
+function y = RIGHT()
+x = 5;
+y = ChangeMe + x;
+end
diff --git a/t/t4018/matlab-octave-section-1 b/t/t4018/matlab-octave-section-1
new file mode 100644
index 0000000000..3bb6c4670e
--- /dev/null
+++ b/t/t4018/matlab-octave-section-1
@@ -0,0 +1,3 @@
+%%% RIGHT section
+# this is octave script
+ChangeMe = 1;
diff --git a/t/t4018/matlab-octave-section-2 b/t/t4018/matlab-octave-section-2
new file mode 100644
index 0000000000..ab2980f7f2
--- /dev/null
+++ b/t/t4018/matlab-octave-section-2
@@ -0,0 +1,3 @@
+## RIGHT section
+# this is octave script
+ChangeMe = 1;
diff --git a/t/t4018/matlab-section b/t/t4018/matlab-section
new file mode 100644
index 0000000000..5ea59a5de0
--- /dev/null
+++ b/t/t4018/matlab-section
@@ -0,0 +1,3 @@
+%% RIGHT section
+% this is understood by both matlab and octave
+ChangeMe = 1;
diff --git a/userdiff.c b/userdiff.c
index 3a78fbf504..04270fb4d7 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -58,7 +58,12 @@ PATTERNS("java",
 	 "|[-+*/<>%&^|=!]="
 	 "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
 PATTERNS("matlab",
-	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
+	 /*
+	  * Octave pattern is mostly the same as matlab, except that '%%%' and
+	  * '##' can also be used to begin code sections, in addition to '%%'
+	  * that is understood by both.
+	  */
+	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
 	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
 PATTERNS("objc",
 	 /* Negate C statements that can look like functions */
-- 
2.21.0.777.g83232e3864


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

end of thread, back to index

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-10  0:47 [PATCH] doc/gitattributes: add Octave Boxuan Li
2019-05-10 23:09 ` Philip Oakley
2019-05-10 23:26 ` Ævar Arnfjörð Bjarmason
2019-05-11  2:36   ` LI, BO XUAN
2019-05-11  4:08     ` [PATCH v2] userdiff.c & doc/gitattributes.txt: " Boxuan Li
2019-05-11  4:13     ` [PATCH v3] " Boxuan Li
2019-05-15  5:35       ` Junio C Hamano
2019-05-15  5:57       ` Johannes Sixt
2019-05-15  6:15         ` LI, BO XUAN
2019-05-15 17:46           ` Johannes Sixt
2019-05-16  9:19             ` Junio C Hamano
2019-05-16 19:20               ` Johannes Sixt
2019-05-16 23:33                 ` Junio C Hamano
2019-05-17 12:19                   ` LI, BO XUAN
2019-05-17 19:47                     ` Johannes Sixt
2019-05-15  5:55     ` [PATCH v4] " Boxuan Li
2019-05-18  3:46     ` [PATCH v5] userdiff: " Boxuan Li
2019-05-20 19:26       ` Johannes Sixt
2019-05-21 14:57         ` [PATCH v6] " Boxuan Li

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox