Skip to content

Commit 91bf382

Browse files
li-boxuangitster
authored andcommitted
userdiff: add Octave
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ab15ad1 commit 91bf382

File tree

7 files changed

+23
-2
lines changed

7 files changed

+23
-2
lines changed

Documentation/gitattributes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ patterns are available:
819819

820820
- `java` suitable for source code in the Java language.
821821

822-
- `matlab` suitable for source code in the MATLAB language.
822+
- `matlab` suitable for source code in the MATLAB and Octave language.
823823

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

t/t4018/matlab-class-definition

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
classdef RIGHT
2+
properties
3+
ChangeMe
4+
end
5+
end

t/t4018/matlab-function

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function y = RIGHT()
2+
x = 5;
3+
y = ChangeMe + x;
4+
end

t/t4018/matlab-octave-section-1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%%% RIGHT section
2+
# this is octave script
3+
ChangeMe = 1;

t/t4018/matlab-octave-section-2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## RIGHT section
2+
# this is octave script
3+
ChangeMe = 1;

t/t4018/matlab-section

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%% RIGHT section
2+
% this is understood by both matlab and octave
3+
ChangeMe = 1;

userdiff.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ PATTERNS("java",
5858
"|[-+*/<>%&^|=!]="
5959
"|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
6060
PATTERNS("matlab",
61-
"^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
61+
/* Octave pattern is mostly the same as matlab, except that '%%%' and
62+
* '##' can also be used to begin code sections, in addition to '%%'
63+
* that is understood by both. */
64+
"^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
6265
"[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
6366
PATTERNS("objc",
6467
/* Negate C statements that can look like functions */

0 commit comments

Comments
 (0)