# [PATCH] userdiff: add support for Fountain documents

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

## Zoë Blade, 2015-07-21 13:22

Subject: [PATCH] userdiff: add support for Fountain documents
Message-ID: <1437484966-664-1-git-send-email-zoe@bytenoise.co.uk>
URL: https://gitlist.dev/e/1437484966-664-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..eec939a 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_]*)?"
 	 "|//|\\*\\*|::|[/<>=]="),
+IPATTERN("fountain", "^((\\.|((int|est|ext)?\\.?|i(nt)?\\.?/e(xt)?\\.?) ).+)$",
+	 "[^ \t-]+"),
 PATTERNS("html", "^[ \t]*(<[Hh][1-6][ \t].*>.*)$",
 	 "[^<>= \t]+"),
 PATTERNS("java",
-- 
1.9.5 (Apple Git-50.3)

```

## Junio C Hamano, 2015-07-21 19:33

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

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

Hmmmm, the pattern has too many question marks to make a simple
panda brain spin.

> "^((\\.|((int|est|ext)?\\.?|i(nt)?\\.?/e(xt)?\\.?) ).+)$"

it can start with a dot, or match "something" at the beginning,
followed by a SP (is a tab allowed there instead of SP, I have to
wonder).

One problem I noticed immediately: this allows a line that begins
with "...", which I learned in http://fountain.io/syntax when I
wrote $gmane/274127 is explicitly excluded.  A line that begin with
a dot followed by a non-dot is a forced scene heading.

Now disecting that "something" (i.e. not a forced scene heading),
which is this part ...

> ((int|est|ext)?\\.?|i(nt)?\\.?/e(xt)?\\.?)

... that gives us largely two choices:

 - It can begin with zero or one int/est/ext and can optionally be
   followed by a dot, or

 - It can be one of (i, int), optionally followed by a dot, followed
   by slash, followed by one of (e, ext), optionally followed by a
   dot.

Second problem.  Doesn't the early part of this "something" pattern
allow an empty string to match by having zero "int" and zero "."?

With this edit to the test vector (add either one of these two,
removing the other, before you run this test twice), you can see
that these over-eager matches in action.
----------------------------------------------------------------

 t/t4018/fountain-scene | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/t/t4018/fountain-scene b/t/t4018/fountain-scene
index 6b3257d..94f0513 100644
--- a/t/t4018/fountain-scene
+++ b/t/t4018/fountain-scene
@@ -1,4 +1,7 @@
 EXT. STREET RIGHT OUTSIDE - DAY
 
+ An indented line is WRONG.
+...we do not want ellipses.
+
 CHARACTER
 You didn't say the magic phrase, "ChangeMe".

----------------------------------------------------------------

Perhaps the pattern is trying to be too clever for its own good.
I'd prefer to see us doing simple, stupid and obviously correct.

That "syntax" page says:

    You can "force" a Scene Heading by starting the line with a
    single period. ... Note that only a single leading period
    followed by an alphanumeric character will force a Scene
    Heading. This allows the writer to begin Action and Dialogue
    elements with ellipses ...

which would give us the first part, i.e. the line may start with a
dot and then an alnum

\\.[a-z0-9]

And then

    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

which translates to

(int|ext|est|int\\.?/ext|i/e)[. ]

So taking these all together, something like this?

^((\\.[a-z0-9]|(int|ext|est|int\\.?/ext|i/e)[. ]).*)$

I personally prefer to make it slightly lenient to exclude dot
instead of forcing US-ASCII view of alnum, i.e.

^((\\.[^.]|(int|ext|est|int\\.?/ext|i/e)[. ]).*)$

I'll queue a SQUASH??? on top while waiting for a response.

Thanks.

```

## Zoë Blade, 2015-07-22 16:31

Subject: Re: [PATCH] userdiff: add support for Fountain documents
Message-ID: <FCF96FC6-2DCB-42F2-9B75-A97F84ED2D94@bytenoise.co.uk>
URL: https://gitlist.dev/e/FCF96FC6-2DCB-42F2-9B75-A97F84ED2D94%40bytenoise.co.uk
In-Reply-To: <xmqqk2ttuwyy.fsf@gitster.dls.corp.google.com>

```
Hi again Junio!

Yes, your more elegant and accurate regex sounds much better than the way I was trying it. :)  Please, go ahead and use yours instead.  Thank you for your help!

Thanks,
Zoë.
```

## Zoë Blade, 2015-07-29 11:19

Subject: Re: [PATCH] userdiff: add support for Fountain documents
Message-ID: <0B100A08-4387-4BDE-A3E5-049303343C8D@bytenoise.co.uk>
URL: https://gitlist.dev/e/0B100A08-4387-4BDE-A3E5-049303343C8D%40bytenoise.co.uk
In-Reply-To: <FCF96FC6-2DCB-42F2-9B75-A97F84ED2D94@bytenoise.co.uk>

```
Hi again!

Where's this at?  Your last regex looks perfect to me:

^((\\.[^.]|(int|ext|est|int\\.?/ext|i/e)[. ]).*)$

Do you need anything else from me?

Thanks,
Zoë.
```
