threads / patch / 39905

patchuserdiff: add support for Fountain documents

Subject: [PATCH] userdiff: add support for Fountain documents

## tl;dr

4 messages between Jul 21, 2015 and Jul 29, 2015. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Zoë Blade· Jul 21, 2015, 13:22 UTC · lore

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: Zoë 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
Show changes to 4 files +9 −0

Documentation/gitattributes.txt, t/t4018-diff-funcname.sh, t/t4018/fountain-scene, userdiff.c

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· Jul 21, 2015, 19:33 UTC · re: Zoë Blade · lore

Re: [PATCH] userdiff: add support for Fountain documents

Zoë 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(+)
Show changes to t/t4018/fountain-scene +3 −0
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· Jul 22, 2015, 16:31 UTC · re: Junio C Hamano · lore

Re: [PATCH] userdiff: add support for Fountain documents

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· Jul 29, 2015, 11:19 UTC · re: Zoë Blade · lore

Re: [PATCH] userdiff: add support for Fountain documents

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ë.

← back to recent threads