# [PATCH] userdiff: add support for Fountain documents

4 messages from 2015-07-17 to 2015-07-19. Participants: Zoë Blade, Junio C Hamano, Zoë Blade.
Thread: https://gitlist.dev/t/39872

## Zoë Blade, 2015-07-17 14:21

Subject: [PATCH] userdiff: add support for Fountain documents
Message-ID: <1437142912-25380-1-git-send-email-zoe@bytenoise.co.uk>
URL: https://gitlist.dev/e/1437142912-25380-1-git-send-email-zoe%40bytenoise.co.uk

```
Add support for Fountain, a plain text screenplay format.  Git
facilitates not just programming specifically, but creative writing
in general, so it makes sense to also support other plain text
documents besides source code.

In the structure of a screenplay specifically, scenes are roughly
analogous to functions, in the sense that it makes your job easier
if you can see which ones were changed in a given range of patches.

More information about the Fountain format can be found on its
official website, at http://fountain.io .

Signed-off-by: Zoë Blade <zoe@bytenoise.co.uk>
---
 Documentation/gitattributes.txt | 2 ++
 t/t4018-diff-funcname.sh        | 1 +
 t/t4018/fountain-scene          | 4 ++++
 userdiff.c                      | 2 ++
 4 files changed, 9 insertions(+)
 create mode 100644 t/t4018/fountain-scene

diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 81fe586..e3b1de8 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -527,6 +527,8 @@ patterns are available:
 
 - `fortran` suitable for source code in the Fortran language.
 
+- `fountain` suitable for Fountain documents.
+
 - `html` suitable for HTML/XHTML documents.
 
 - `java` suitable for source code in the Java language.
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index 1dbaa38..67373dc 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -31,6 +31,7 @@ diffpatterns="
 	cpp
 	csharp
 	fortran
+	fountain
 	html
 	java
 	matlab
diff --git a/t/t4018/fountain-scene b/t/t4018/fountain-scene
new file mode 100644
index 0000000..6b3257d
--- /dev/null
+++ b/t/t4018/fountain-scene
@@ -0,0 +1,4 @@
+EXT. STREET RIGHT OUTSIDE - DAY
+
+CHARACTER
+You didn't say the magic phrase, "ChangeMe".
diff --git a/userdiff.c b/userdiff.c
index 2ccbee5..5316b48 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -35,6 +35,8 @@ IPATTERN("fortran",
 	  * they would have been matched above as a variable anyway. */
 	 "|[-+]?[0-9.]+([AaIiDdEeFfLlTtXx][Ss]?[-+]?[0-9.]*)?(_[a-zA-Z0-9][a-zA-Z0-9_]*)?"
 	 "|//|\\*\\*|::|[/<>=]="),
+PATTERNS("fountain", "^((INT|EST|EXT)?\\.[A-Z0-9' -]+)$",
+	 "[^ \t-]+"),
 PATTERNS("html", "^[ \t]*(<[Hh][1-6][ \t].*>.*)$",
 	 "[^<>= \t]+"),
 PATTERNS("java",
-- 
2.5.0.rc2.28.g6003e7f.dirty

```

## Junio C Hamano, 2015-07-17 17:12

Subject: Re: [PATCH] userdiff: add support for Fountain documents
Message-ID: <xmqq1tg63dzv.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqq1tg63dzv.fsf%40gitster.dls.corp.google.com
In-Reply-To: <1437142912-25380-1-git-send-email-zoe@bytenoise.co.uk>

```
Zoë Blade <zoe@bytenoise.co.uk> writes:

> Add support for Fountain, a plain text screenplay format.  Git
> facilitates not just programming specifically, but creative writing
> in general, so it makes sense to also support other plain text
> documents besides source code.
>
> In the structure of a screenplay specifically, scenes are roughly
> analogous to functions, in the sense that it makes your job easier
> if you can see which ones were changed in a given range of patches.
>
> More information about the Fountain format can be found on its
> official website, at http://fountain.io .
>
> Signed-off-by: Zoë Blade <zoe@bytenoise.co.uk>
> ---

The test looks a bit too brief (i.e. there is only one obvious
candidate to be picked as the funcname header in the input, so it is
very hard to break the expectation of the test even when the code or
pattern is modified incorrectly), but it would do for now.
Everything else looks trivially OK ;-)

Thanks, will queue.


>  Documentation/gitattributes.txt | 2 ++
>  t/t4018-diff-funcname.sh        | 1 +
>  t/t4018/fountain-scene          | 4 ++++
>  userdiff.c                      | 2 ++
>  4 files changed, 9 insertions(+)
>  create mode 100644 t/t4018/fountain-scene
>
> diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
> index 81fe586..e3b1de8 100644
> --- a/Documentation/gitattributes.txt
> +++ b/Documentation/gitattributes.txt
> @@ -527,6 +527,8 @@ patterns are available:
>  
>  - `fortran` suitable for source code in the Fortran language.
>  
> +- `fountain` suitable for Fountain documents.
> +
>  - `html` suitable for HTML/XHTML documents.
>  
>  - `java` suitable for source code in the Java language.
> diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
> index 1dbaa38..67373dc 100755
> --- a/t/t4018-diff-funcname.sh
> +++ b/t/t4018-diff-funcname.sh
> @@ -31,6 +31,7 @@ diffpatterns="
>  	cpp
>  	csharp
>  	fortran
> +	fountain
>  	html
>  	java
>  	matlab
> diff --git a/t/t4018/fountain-scene b/t/t4018/fountain-scene
> new file mode 100644
> index 0000000..6b3257d
> --- /dev/null
> +++ b/t/t4018/fountain-scene
> @@ -0,0 +1,4 @@
> +EXT. STREET RIGHT OUTSIDE - DAY
> +
> +CHARACTER
> +You didn't say the magic phrase, "ChangeMe".
> diff --git a/userdiff.c b/userdiff.c
> index 2ccbee5..5316b48 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -35,6 +35,8 @@ IPATTERN("fortran",
>  	  * they would have been matched above as a variable anyway. */
>  	 "|[-+]?[0-9.]+([AaIiDdEeFfLlTtXx][Ss]?[-+]?[0-9.]*)?(_[a-zA-Z0-9][a-zA-Z0-9_]*)?"
>  	 "|//|\\*\\*|::|[/<>=]="),
> +PATTERNS("fountain", "^((INT|EST|EXT)?\\.[A-Z0-9' -]+)$",
> +	 "[^ \t-]+"),
>  PATTERNS("html", "^[ \t]*(<[Hh][1-6][ \t].*>.*)$",
>  	 "[^<>= \t]+"),
>  PATTERNS("java",

```

## Junio C Hamano, 2015-07-17 22:43

Subject: Re: [PATCH] userdiff: add support for Fountain documents
Message-ID: <xmqq380m1k3g.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqq380m1k3g.fsf%40gitster.dls.corp.google.com
In-Reply-To: <xmqq1tg63dzv.fsf@gitster.dls.corp.google.com>

```
Junio C Hamano <gitster@pobox.com> writes:

> Zoë Blade <zoe@bytenoise.co.uk> writes:
>
>> More information about the Fountain format can be found on its
>> official website, at http://fountain.io .

So I visited there.

>> +PATTERNS("fountain", "^((INT|EST|EXT)?\\.[A-Z0-9' -]+)$",
>> +	 "[^ \t-]+"),

After skimming http://fountain.io/syntax I am getting the impression
that this might be a bit too limiting.

 * Although uppercase is recommended for Scene Headings to increase
   readability, it is not required.

 * A line beginning with any of the following, followed by either a
   dot or a space, is considered a Scene Heading (unless the line is
   preceded by an exclamation point !). Case insensitive.

      INT
      EXT
      EST
      INT./EXT
      INT/EXT
      I/E

 * You can "force" a Scene Heading by starting the line with a
   single period.

 * Scene Headings can optionally be appended with Scene
   Numbers. Scene numbers are any alphanumerics (plus dashes and
   periods), wrapped in #.

So, it appears wrong to insist on capital letters in the patterns.
The pattern in the patch does not even accept punctuations on the
line other than apostrophe.  I won't judge if it is OK to limit to
US-ASCII ;-)

IPATTERNS("fountain",
    "^([.][^.]|(INT|EXT|EST|INT./EXT|INT/EXT|I/E)[. ]",
    "[^ \t-]+"),

or something like this, perhaps?

```

## Zoë Blade, 2015-07-19 12:30

Subject: Re: [PATCH] userdiff: add support for Fountain documents
Message-ID: <562D4AFF-BFC1-4234-8362-656D1F54DFD0@bytenoise.co.uk>
URL: https://gitlist.dev/e/562D4AFF-BFC1-4234-8362-656D1F54DFD0%40bytenoise.co.uk
In-Reply-To: <xmqq380m1k3g.fsf@gitster.dls.corp.google.com>

```
On 17 Jul 2015, at 23:43, Junio C Hamano <gitster@pobox.com> wrote:

> * Although uppercase is recommended for Scene Headings to increase
>   readability, it is not required.
> 
> * A line beginning with any of the following, followed by either a
>   dot or a space, is considered a Scene Heading (unless the line is
>   preceded by an exclamation point !). Case insensitive.
> 
>      INT
>      EXT
>      EST
>      INT./EXT
>      INT/EXT
>      I/E
> 
> * You can "force" a Scene Heading by starting the line with a
>   single period.
> 
> * Scene Headings can optionally be appended with Scene
>   Numbers. Scene numbers are any alphanumerics (plus dashes and
>   periods), wrapped in #.
> 
> So, it appears wrong to insist on capital letters in the patterns.
> The pattern in the patch does not even accept punctuations on the
> line other than apostrophe.  I won't judge if it is OK to limit to
> US-ASCII ;-)
> 
> IPATTERNS("fountain",
>    "^([.][^.]|(INT|EXT|EST|INT./EXT|INT/EXT|I/E)[. ]",
>    "[^ \t-]+"),
> 
> or something like this, perhaps?

Good points, thanks!

This regex should be a bit sturdier:

$ cat scenes.txt 
int. yes - day
INT. YES - DAY #1A#
EXT. YES - DAY
.YES TOO
!EXT. NO
INT/EXT YES - DAY
INT./EXT YES - DAY
I/E YES - DAY
no
NO
NO.
!.NO.
int yes - day
est yes - day
!EXT. NO - DAY

$ grep -E "^((\.|(([Ii][Nn][Tt]|[Ee][Ss][Tt]|[Ee][Xx][Tt])?\\.?|[Ii]([Nn][Tt])?\.?/[Ee]([Xx][Tt])?\.?) ).+)$" scenes.txt 
int. yes - day
INT. YES - DAY #1A#
EXT. YES - DAY
.YES TOO
INT/EXT YES - DAY
INT./EXT YES - DAY
I/E YES - DAY
int yes - day
est yes - day

Revised version of patch incoming...
```
