The patch appends userdiff.c file in order to support R programming language function header. This will be useful for those who use Git for versioning .R files. Also, add three userdiff tests for R programming language files. These files define simple function and nested function, with and without indentation. Signed-off-by: Rodrigo Carvalho <rodrigorsdc@xxxxxxxxx> --- Changes in v2: - Add support for function defined by '=' - Replace word regex to '[^ \t'] - Add new test that handles with nested function t/t4018/r-indent | 6 ++++++ t/t4018/r-indent-nested | 10 ++++++++++ t/t4018/r-noindent | 6 ++++++ userdiff.c | 4 ++++ 4 files changed, 26 insertions(+) create mode 100644 t/t4018/r-indent create mode 100644 t/t4018/r-indent-nested create mode 100644 t/t4018/r-noindent diff --git a/t/t4018/r-indent b/t/t4018/r-indent new file mode 100644 index 0000000000..9df440f2a4 --- /dev/null +++ b/t/t4018/r-indent @@ -0,0 +1,6 @@ +RIGHT <- function(a, b) { + c = mean(a, b) + d = c + 2 + ChangeMe() + return (d) +} diff --git a/t/t4018/r-indent-nested b/t/t4018/r-indent-nested new file mode 100644 index 0000000000..30412e6c79 --- /dev/null +++ b/t/t4018/r-indent-nested @@ -0,0 +1,10 @@ +LEFT = function(a, b) { + c = mean(a, b) + RIGHT = function(d, e) { + f = var(d, e) + g = f + 1 + ChangeMe() + return (g) + } + return (RIGHT(2, 3)) +} diff --git a/t/t4018/r-noindent b/t/t4018/r-noindent new file mode 100644 index 0000000000..6d9b01ffe3 --- /dev/null +++ b/t/t4018/r-noindent @@ -0,0 +1,6 @@ +RIGHT <- function(a, b) { +c = mean(a, b) +d = c + 2 +ChangeMe() +return (c) +} diff --git a/userdiff.c b/userdiff.c index da75625020..64e5005682 100644 --- a/userdiff.c +++ b/userdiff.c @@ -317,6 +317,10 @@ PATTERNS("python", "|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?" "|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\*\\*=?"), /* -- */ +PATTERNS("r", + "^[ \t]*([a-zA-z][a-zA-Z0-9_.]*[ \t]*(<-|=)[ \t]*function.*)$", + /* -- */ + "[^ \t]+"), PATTERNS("ruby", "^[ \t]*((class|module|def)[ \t].*)$", /* -- */ -- 2.43.0