userdiff: add Octave
authorBoxuan Li <liboxuan@connect.hku.hk>
Sat, 18 May 2019 03:46:23 +0000 (11:46 +0800)
committerJunio C Hamano <gitster@pobox.com>
Sun, 19 May 2019 01:45:28 +0000 (10:45 +0900)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/gitattributes.txt
t/t4018/matlab-class-definition [new file with mode: 0644]
t/t4018/matlab-function [new file with mode: 0644]
t/t4018/matlab-octave-section-1 [new file with mode: 0644]
t/t4018/matlab-octave-section-2 [new file with mode: 0644]
t/t4018/matlab-section [new file with mode: 0644]
userdiff.c
index 4fb20cd0e963b6cf52c07c6ae7492adbf35f6cbf..e657a6b7b783c7d0d18eb64dde16010b0a223a27 100644 (file)
@@ -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 (file)
index 0000000..84daedf
--- /dev/null
@@ -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 (file)
index 0000000..897a9b1
--- /dev/null
@@ -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 (file)
index 0000000..3bb6c46
--- /dev/null
@@ -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 (file)
index 0000000..ab2980f
--- /dev/null
@@ -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 (file)
index 0000000..5ea59a5
--- /dev/null
@@ -0,0 +1,3 @@
+%% RIGHT section
+% this is understood by both matlab and octave
+ChangeMe = 1;
index 3a78fbf5044fbc5d5624ce94e54eb4ab325e2cf1..bcae006abe70641fa732590eef0638c10de2b237 100644 (file)
@@ -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 */