-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathfountain-mode.el
4330 lines (3828 loc) · 159 KB
/
fountain-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; fountain-mode.el --- Major mode for screenwriting in Fountain markup -*- lexical-binding: t; -*-
;; Copyright (c) 2014-2024 Paul W. Rankin
;; Author: Paul W. Rankin <rnkn@rnkn.xyz>
;; Keywords: wp, text
;; Version: 3.8.0
;; Package-Requires: ((emacs "24.4") (seq "2.20"))
;; URL: https://www.fountain-mode.org
;; URL: https://github.com/rnkn/fountain-mode
;; This file is not part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or (at
;; your option) any later version.
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Fountain Mode
;; =============
;; Fountain Mode is a screenwriting program for GNU Emacs using the
;; Fountain plain text markup format.
;; For more information about the Fountain format, visit <https://fountain.io>
;; Features
;; --------
;; - Support for the Fountain 1.1 specification
;; - Export to PostScript or PDF using troff
;; - WYSIWYG auto-align elements (display only, does not modify file
;; contents) specific to script format, e.g. screenplay, stageplay or
;; user-defined formats
;; - Traditional TAB auto-completion writing style
;; - Highly accurate pagination calculation
;; - Navigation by section, scene, character name, specified character
;; name, or page
;; - Integration with outline to fold/cycle visibility of sections,
;; scenes and notes
;; - Integration with electric-pair-mode to insert emphasis delimiters
;; with single key (i.e. * or _)
;; - Integration with imenu (sections, scene headings, notes)
;; - Integration with auto-insert for title page metadata
;; - Integration with which-function-mode to display live-update of current
;; page and page count in mode-line
;; - Automatically add/remove character (CONT'D)
;; - Toggle syntax highlighting of each element
;; - Toggle visibility of emphasis and syntax markup
;; - Optionally display scene numbers in margins
;; - Intelligent insertion of page breaks
;; Most common features are accessible from the menu. For a full list of
;; functions and key-bindings, type C-h m.
;; Requirements
;; ------------
;; - Emacs 24.4
;; - seq 2.20 (part of Emacs 25 and later)
;; Exporting
;; ---------
;; Fountain Mode can export to PostScript or PDF using the troff format as
;; an intermediary. This requires only a troff program on your system,
;; such as [GNU roff](https://www.gnu.org/software/groff/).
;; Alternatively you can export using an external command-line program,
;; such as:
;; - [afterwriting](https://github.com/ifrost/afterwriting-labs/blob/master/docs/clients.md) (JavaScript)
;; - [Wrap](https://github.com/Wraparound/wrap) (Go)
;; - [screenplain](https://github.com/vilcans/screenplain) (Python 3, requires ReportLab for PDF)
;; - [Textplay](https://github.com/olivertaylor/Textplay) (Ruby, requires PrinceXML for PDF)
;; The option fountain-export-command-profiles provides some shell
;; commands to interface with these tools, but you are encouraged to edit
;; or completely replace these to suit your own needs. The format is simple
;; while still allowing for flexibility.
;; Installation
;; ------------
;; The latest stable release of Fountain Mode is available via
;; [MELPA-stable][1]. First, add MELPA-stable to your package archives:
;; M-x customize-option RET package-archives RET
;; Insert an entry named melpa-stable with URL: https://stable.melpa.org/packages/
;; Refresh the package archive and install:
;; M-x package-refresh-contents RET
;; M-x package-install RET fountain-mode RET
;; If you prefer the latest but perhaps unstable version, do the above
;; using [MELPA][2].
;; Advanced Installation
;; ---------------------
;; Download the latest tagged release, move this file into your load-path
;; and add to your init.el file:
;; (require 'fountain-mode)
;; If you wish to contribute to or alter Fountain Mode's code, clone the
;; repository into your load-path and require as above:
;; git clone https://github.com/rnkn/fountain-mode.git
;; Bugs and Feature Requests
;; -------------------------
;; Use GitHub issues or send me an email (address in the package header).
;; For bugs, please ensure you can reproduce with:
;; $ emacs -Q -l fountain-mode.el
;; [1]: https://stable.melpa.org/#/fountain-mode
;; [2]: https://melpa.org/#/fountain-mode
;; Donations
;; ---------
;; Donations are graciously accepted via [Github][3], or [Liberapay][4].
;; [3]: https://github.com/sponsors/rnkn
;; [4]: https://liberapay.com/rnkn/
;;; Code:
(eval-when-compile (require 'cl-lib))
(eval-when-compile (require 'subr-x))
(require 'seq)
;;; Top-Level Options ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defgroup fountain ()
"Major mode for screenwriting in Fountain markup."
:prefix "fountain-"
:link '(info-link "(fountain-mode) Fountain Mode")
:group 'text)
(defun fountain--set-and-refresh-font-lock (symbol value)
"Set SYMBOL to VALUE and refresh defaults.
Cycle buffers and call `font-lock-refresh-defaults' when
`fountain-mode' is active."
(set-default symbol value)
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(when (derived-mode-p 'fountain-mode)
(font-lock-refresh-defaults)))))
(defcustom fountain-mode-hook
'(visual-line-mode)
"Mode hook for `fountain-mode', run after the mode is turned on."
:group 'fountain
:type 'hook
:options '(visual-line-mode
electric-pair-local-mode
imenu-add-menubar-index
which-function-mode
fountain-completion-update
fountain-pagination-update
fountain-completion-auto-update-mode
flyspell-mode))
(defcustom fountain-insert-synopsis-hook
nil
"Hook run after command `fountain-insert-synopsis'."
:group 'fountain
:type 'hook)
(defcustom fountain-insert-note-hook
nil
"Hook run after command `fountain-insert-note'."
:group 'fountain
:type 'hook)
(defcustom fountain-insert-page-break-hook
nil
"Hook run after command `fountain-insert-page-break'."
:group 'fountain
:type 'hook)
(define-obsolete-variable-alias 'fountain-default-script-format
'fountain-script-format "`fountain-mode' 3.8")
(defcustom fountain-script-format
"screenplay"
"Default script format.
Can be overridden in metadata with, e.g.
format: teleplay"
:group 'fountain
:type 'string
:safe 'string)
(make-obsolete-variable 'fountain-add-continued-dialog
"use command `fountain-add-continued-dialog' instead."
"`fountain-mode' 3.5")
(defcustom fountain-continued-dialog-string
"(CONT'D)"
"\\<fountain-mode-map>String to append to character name speaking in succession.
Append this string to characters speaking in succession when
calling `fountain-add-continued-dialog' (\\[fountain-add-continued-dialog]).
n.b. Before changing this option, first call
`fountain-remove-continued-dialog' (\\[fountain-remove-continued-dialog])
to remove any previous continued dialogue."
:group 'fountain
:type 'string
:safe 'stringp)
(defcustom fountain-hide-emphasis-markup
nil
"If non-nil, make emphasis delimiters invisible."
:group 'fountain
:type 'boolean
:safe 'booleanp
:set (lambda (symbol value)
(set-default symbol value)
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(when (derived-mode-p 'fountain-mode)
(if fountain-hide-emphasis-markup
(add-to-invisibility-spec 'fountain-emphasis-markup)
(remove-from-invisibility-spec 'fountain-emphasis-markup))
(font-lock-refresh-defaults))))))
(defcustom fountain-hide-element-markup
nil
"If non-nil, make syntax characters invisible."
:group 'fountain
:type 'boolean
:safe 'booleanp
:set (lambda (symbol value)
(set-default symbol value)
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(when (derived-mode-p 'fountain-mode)
(if fountain-hide-element-markup
(add-to-invisibility-spec 'fountain-element-markup)
(remove-from-invisibility-spec 'fountain-element-markup))
(font-lock-refresh-defaults))))))
(defcustom fountain-auto-upcase-scene-headings
t
"If non-nil, automatically upcase scene headings as you type.
Upcases lines matching `fountain-scene-heading-regexp'."
:type 'boolean
:safe 'booleanp
:group 'fountain)
(defcustom fountain-dwim-insert-next-character
nil
"When non-nil `fountain-dwim' inserts next character after dialogue."
:type 'boolean
:safe 'booleanp
:group 'fountain)
(make-obsolete-variable 'fountain-note-template
"note templates are no longer supported."
"`fountain-mode' 3.8")
(defcustom fountain-highlight-elements
'(section-heading scene-heading character dialog synopsis note
metadata page-break)
"List of elements highlighted with `font-lock-mode'."
:type '(choice (const :tag "No Highlighting" nil)
(set (const :tag "Section Headings" section-heading)
(const :tag "Scene Headings" scene-heading)
(const :tag "Action" action)
(const :tag "Character Names" character)
(const :tag "Dialogue" dialog)
(const :tag "Parentheticals" paren)
(const :tag "Transitions" trans)
(const :tag "Synopses" synopsis)
(const :tag "Notes" note)
(const :tag "Metadata" metadata)
(const :tag "Page Breaks" page-break)))
:group 'fountain
:set #'fountain--set-and-refresh-font-lock)
(defvar fountain-highlight-elements-always
'(underline italic bold bold-italic lyrics)
"List of elements always highlighted with `font-lock-mode'.")
(defcustom fountain-double-space-scene-headings
nil
"When non-nil, display an additional newline before scene headings.
This option does not affect file contents.
n.b. This option does not affect calculation of pagination, see
instead `fountain-export-scene-heading-format'."
:type 'boolean
:safe 'booleanp
:group 'fountain
:set #'fountain--set-and-refresh-font-lock)
(define-obsolete-variable-alias 'fountain-shift-all-elements
'fountain-transpose-all-elements "`fountain-mode' 3.2")
(defcustom fountain-transpose-all-elements
t
"\\<fountain-mode-map>When non-nil, \\[fountain-forward-paragraph-or-transpose] and \\[fountain-backward-paragraph-or-transpose] should transpose all elements.
Otherwise, only transpose outline elements."
:type 'boolean
:safe 'booleanp
:group 'fountain)
;;; Key Bindings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar fountain-mode-map
(let ((map (make-sparse-keymap)))
;; Editing commands ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-key map (kbd "TAB") #'fountain-dwim)
(define-key map (kbd "C-c RET") #'fountain-upcase-line-and-newline)
(define-key map (kbd "<S-return>") #'fountain-upcase-line-and-newline)
(define-key map (kbd "C-c C-c") #'fountain-upcase-line)
(define-key map (kbd "C-c C-d") #'fountain-add-continued-dialog)
(define-key map (kbd "C-c C-z") #'fountain-insert-note)
(define-key map (kbd "C-c C-a") #'fountain-insert-synopsis)
(define-key map (kbd "C-c C-x i") #'auto-insert)
(define-key map (kbd "C-c C-x #") #'fountain-add-scene-numbers)
(define-key map (kbd "C-c C-x RET") #'fountain-insert-page-break)
(define-key map (kbd "C-c C-x a") #'fountain-completion-update)
(define-key map (kbd "C-c C-x *") #'fountain-toggle-hide-emphasis-markup)
(define-key map (kbd "C-c C-x !") #'fountain-toggle-hide-element-markup)
;; Navigation commands ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-key map [remap beginning-of-defun] #'fountain-outline-beginning)
(define-key map (kbd "M-g s") #'fountain-goto-scene)
(define-key map (kbd "M-g p") #'fountain-goto-page)
(define-key map (kbd "M-n") #'fountain-forward-character)
(define-key map (kbd "M-p") #'fountain-backward-character)
(define-key map (kbd "C-c M-n") #'fountain-forward-this-character)
(define-key map (kbd "C-c M-p") #'fountain-backward-this-character)
;; Block editing commands ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-key map (kbd "<M-down>") #'fountain-forward-paragraph-or-transpose)
(define-key map (kbd "ESC <down>") #'fountain-forward-paragraph-or-transpose)
(define-key map (kbd "<M-up>") #'fountain-backward-paragraph-or-transpose)
(define-key map (kbd "ESC <up>") #'fountain-backward-paragraph-or-transpose)
;; Outline commands ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-key map [remap forward-list] #'fountain-outline-next)
(define-key map [remap backward-list] #'fountain-outline-previous)
(define-key map [remap forward-sexp] #'fountain-outline-forward)
(define-key map [remap backward-sexp] #'fountain-outline-backward)
(define-key map [remap backward-up-list] #'fountain-outline-up)
(define-key map [remap mark-defun] #'fountain-outline-mark)
(define-key map (kbd "C-c TAB") #'fountain-outline-cycle)
(define-key map (kbd "<backtab>") #'fountain-outline-cycle-buffer)
(define-key map (kbd "S-TAB") #'fountain-outline-cycle-buffer)
(define-key map (kbd "C-M-i") #'fountain-outline-cycle-buffer)
(define-key map (kbd "M-RET") #'fountain-insert-section-heading)
(define-key map (kbd "C-c C-x b") #'fountain-outline-to-indirect-buffer)
(define-key map (kbd "C-c C-q") #'fountain-outline-hide-sublevels)
;; Pagination commands ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-key map [remap forward-page] #'fountain-forward-page)
(define-key map [remap backward-page] #'fountain-backward-page)
(define-key map (kbd "C-c C-p") #'fountain-count-pages)
(define-key map (kbd "C-c C-x p") #'fountain-pagination-update)
;; Exporting commands ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-key map (kbd "C-c C-e t") #'fountain-export-troff)
(define-key map (kbd "C-c C-e e") #'fountain-export-command)
(define-key map (kbd "C-c C-v") #'fountain-export-view)
map)
"Mode map for `fountain-mode'.")
;;; Faces ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defgroup fountain-faces ()
"Faces used in `fountain-mode'.
You can specify which elements are highlighted with the option
`fountain-highlight-elements'."
:prefix "fountain-"
:link '(info-link "(emacs) Font Lock")
:group 'fountain)
(defface fountain
'((t nil))
"Default base-level face for `fountain-mode' buffers.")
(defface fountain-action
'((t nil))
"Default face for action.")
(defface fountain-comment
'((t (:inherit shadow)))
"Default face for comments (boneyard).")
(defface fountain-non-printing
'((t (:inherit fountain-comment)))
"Default face for element and emphasis markup.")
(defface fountain-metadata-key
'((t (:inherit font-lock-keyword-face)))
"Default face for metadata keys.")
(defface fountain-metadata-value
'((t (:inherit font-lock-string-face)))
"Default face for metadata values.")
(defface fountain-page-break
'((t (:inherit font-lock-constant-face)))
"Default face for page breaks.")
(defface fountain-scene-heading
'((t (:inherit font-lock-function-name-face)))
"Default face for scene headings.")
(defface fountain-paren
'((t (:inherit font-lock-string-face)))
"Default face for parentheticals.")
(defface fountain-center
'((t nil))
"Default face for centered text.")
(defface fountain-note
'((t (:extend t :inherit font-lock-comment-face)))
"Default face for notes.")
(define-obsolete-face-alias 'fountain-section-heading
'fountain-section-heading-1 "`fountain-mode' 3.0")
(defface fountain-section-heading-1
'((t (:inherit outline-1)))
"Default face for section level 1 headings.")
(defface fountain-section-heading-2
'((t (:inherit outline-2)))
"Default face for section level 2 headings.")
(defface fountain-section-heading-3
'((t (:inherit outline-3)))
"Default face for section level 3 headings.")
(defface fountain-section-heading-4
'((t (:inherit outline-4)))
"Default face for section level 4 headings.")
(defface fountain-section-heading-5
'((t (:inherit outline-5)))
"Default face for section level 5 headings.")
(defface fountain-synopsis
'((t (:inherit font-lock-type-face)))
"Default face for synopses.")
(defface fountain-character
'((t (:inherit font-lock-variable-name-face)))
"Default face for characters.")
(defface fountain-dialog
'((t (:inherit font-lock-string-face)))
"Default face for dialogue.")
(defface fountain-character-dual-dialog
'((t (:inherit highlight)))
"Default face for dual dialogue mark.")
(defface fountain-trans
'((t nil))
"Default face for transitions.")
;;; Scene Number Options ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defgroup fountain-scene-numbers ()
"Options for scene numbers in `fountain-mode'."
:prefix "fountain-scene-numbers-"
:group 'fountain)
(defcustom fountain-display-scene-numbers-in-margin
nil
"If non-nil, display scene numbers in the right margin.
This option does not affect file contents."
:group 'fountain-scene-numbers
:type 'boolean
:safe 'booleanp
:set #'fountain--set-and-refresh-font-lock)
(defcustom fountain-prefix-revised-scene-numbers
nil
"If non-nil, revised scene numbers are prefixed.
If non-nil, when inserting new scene headings after numbering
existing scene headings, revised scene number format works as
follows:
10
A11 <- new scene
B11 <- new scene
11
If further scene headings are inserted:
10
AA11 <- new scene
BA11 <- new scene
A11
AB11 <- new scene
BB11 <- new scene
B11
11
Otherwise, when nil:
10
10A <- new scene
10B <- new scene
11
And if further scene headings are inserted:
10
10AA <- new scene
10AB <- new scene
10A
10BA <- new scene
10BB <- new scene
10B
11
10
10A <- new scene
11
n.b. Using conflicting revised scene number format in the same
script may result in errors in output."
:type 'boolean
:safe 'booleanp
:group 'fountain-scene-numbers)
(make-obsolete-variable 'fountain-scene-numbers-first-revision-char
"use \"A\" and \"B\" system." "`fountain-mode' 3.8")
(defcustom fountain-scene-numbers-separator
nil
"Character to separate scene numbers."
:type '(choice (const :tag "None" nil)
(const :tag "Dash" ?-)
(const :tag "Period" ?.))
:safe (lambda (value)
(or (null value) (characterp value)))
:group 'fountain-scene-numbers)
;;; Export Options ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defgroup fountain-export ()
"Options for exporting files in `fountain-mode'."
:prefix "fountain-export-"
:link '(info-link "(fountain-mode) Exporting")
:group 'fountain)
(defcustom fountain-export-format
'pdf
"Target format for export. Valid options are `ps' or `pdf'."
:type '(choice (const :tag "PostScript" ps)
(const :tag "PDF" pdf))
:group 'fountain-export)
(defcustom fountain-export-scene-heading-format
'(double-space)
"List of format options applied when exporting scene headings.
Options are: bold, double-space, underline."
:type '(set (const :tag "Bold" bold)
(const :tag "Double-spaced" double-space)
(const :tag "Underlined" underline))
:group 'fountain-export)
(defcustom fountain-export-title-page
t
"When non-nil, include a title page in export."
:type 'boolean
:safe 'booleanp
:group 'fountain-export)
(defcustom fountain-export-number-first-page
nil
"When non-nil, first page is numbered in export."
:type 'boolean
:safe 'booleanp
:group 'fountain-export)
(defcustom fountain-export-scene-numbers
nil
"When non-nil, include scene numbers in export."
:type 'boolean
:safe 'booleanp
:group 'fountain-export)
(defcustom fountain-export-troff-command
"groff"
"Name of troff command."
:type 'string
:safe 'stringp
:group 'fountain-export)
(defcustom fountain-export-troff-extra-options
'("-Kutf8")
"Option flags passed to `fountain-export-troff-command'.
n.b. the `-Tdev' option is calculated automatically from
`fountain-export-format' and the page size from
`fountain-page-size'."
:type '(repeat (string :tag "Option"))
:group 'fountain-export)
(defcustom fountain-export-command-profiles
'(("afterwriting-usletterpdf-doublespace" . "afterwriting \
--source %b --pdf %B.pdf --overwrite \
--setting double_space_between_scenes=true \
--setting print_profile=usletter")
("afterwriting-a4pdf-doublespace" . "afterwriting \
--source %b --pdf %B.pdf --overwrite \
--setting double_space_between_scenes=true \
--setting print_profile=a4")
("wrap-usletterpdf-cprime" . "wrap \
pdf %b --use-courier-prime --out %B.pdf")
("make-pdf" . "make %B.pdf")
("screenplain-html" . "screenplain \
--format html > %B.html")
("textplay-fdx" . "textplay --fdx < %b > %B.fdx"))
"Shell command profiles for exporting Fountain files.
n.b. The default command profiles are only intended as examples.
You are encouraged to edit/replace these to suit your own needs.
Each profile is a cons-cell of PROFILE-NAME string and the
COMMAND string.
COMMAND is passed to `format-spec' and allows for interpolation
of the following values:
%b is the variable `buffer-file-name'
%B is the variable `buffer-file-name' sans extension
%n is the variable `user-full-name'
%t is the title (from script metadata)
%a is the author (from script metadata)
%F is the current date in ISO format
%x is the current date in your locale's \"preferred\" format
If a command does not include %b, `fountain-export-command' will pass the
buffer or active region to the command via stdin.
If a command outputs to stdout, this will be redirected to
`fountain-export-output-buffer'.
The first profile is considered default.
COMMAND may be edited interactively when calling
`fountain-export-command' prefixed with \\[universal-argument]."
:type '(repeat (cons (string :tag "Name")
(string :tag "Shell command")))
:group 'fountain-export)
(defcustom fountain-export-output-buffer
"*Fountain Export*"
"Buffer name for `fountain-export' output."
:type 'string
:safe 'stringp
:group 'fountain-export)
(defcustom fountain-export-switch-to-output-buffer
t
"When non-nil, switch to `fountain-export-output-buffer' on export."
:type 'boolean
:safe 'booleanp
:group 'fountain-export)
(defcustom fountain-export-kill-output-buffer
nil
"When non-nil, kill `fountain-export-output-buffer' on export."
:type 'boolean
:safe 'booleanp
:group 'fountain-export)
(defcustom fountain-export-title-page-title-keys
'("title" "credit" "author" "authors" "source")
"Elements to include in the title page title section."
:type '(repeat string)
:safe (lambda (value)
(and (listp value) (seq-every-p 'stringp value)))
:group 'fountain-export)
(defcustom fountain-export-title-page-contact-keys
'("draft" "date" "draft date" "contact")
"Elements to include in the title page contact section."
:type '(repeat string)
:safe (lambda (value)
(and (listp value) (seq-every-p 'stringp value)))
:group 'fountain-export)
;;; Regular Expressions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar fountain-scene-heading-regexp
nil
"Regular expression for matching scene headings.
Group 1: match leading . for forced scene heading
Group 2: match whole scene heading without scene number
Group 3: match INT/EXT
Group 4: match location
Group 5: match suffix separator
Group 6: match suffix
Group 7: match space between scene heading and scene number
Group 8: match first # delimiter
Group 9: match scene number
Group 10: match last # delimiter
Constructed with `fountain-init-scene-heading-regexp'. Requires
`fountain-match-scene-heading' for preceding blank line.")
(defcustom fountain-scene-heading-prefix-list
'("INT" "EXT" "EST" "INT./EXT." "INT/EXT" "I/E")
"List of scene heading prefixes (case insensitive).
Any scene heading prefix can be followed by a dot and/or a space,
so the following are equivalent:
INT HOUSE - DAY
INT. HOUSE - DAY"
:type '(repeat (string :tag "Prefix"))
:group 'fountain
:set (lambda (symbol value)
(set-default symbol value)
(when (featurep 'fountain-mode)
(fountain-init-scene-heading-regexp)
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(when (derived-mode-p 'fountain-mode)
(fountain-init-outline-regexp)
(font-lock-refresh-defaults)))))))
(defcustom fountain-scene-heading-suffix-separator
" --? "
"Regular expression separating scene heading location from suffix.
n.b. If you change this any existing scene headings may not
be parsed correctly."
:group 'fountain
:type 'regexp
:safe 'regexp
:set #'fountain--set-and-refresh-font-lock)
(defcustom fountain-scene-heading-suffix-list
'("DAY" "NIGHT" "CONTINUOUS" "LATER" "MOMENTS LATER")
"List of scene heading suffixes (case insensitive).
These are only used for auto-completion. Any scene headings can
have whatever suffix you like.
Separated from scene heading locations with
`fountain-scene-heading-suffix-separator'."
:group 'fountain
:type '(repeat (string :tag "Suffix"))
:set #'fountain--set-and-refresh-font-lock)
(defvar fountain-trans-regexp
nil
"Regular expression for matching transitions.
Group 1: match forced transition mark
Group 2: match transition
Constructed with `fountain-init-trans-regexp'. Requires
`fountain-match-trans' for preceding and succeeding blank
lines.")
(defcustom fountain-trans-suffix-list
'("TO:" "WITH:" "FADE OUT" "TO BLACK")
"List of transition suffixes (case insensitive).
This list is used to match the endings of transitions,
e.g. `TO:' will match both the following:
CUT TO:
DISSOLVE TO:"
:type '(repeat (string :tag "Suffix"))
:group 'fountain
:set (lambda (symbol value)
(set-default symbol value)
(when (featurep 'fountain-mode)
(fountain-init-trans-regexp)
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(when (derived-mode-p 'fountain-mode)
(font-lock-refresh-defaults)))))))
(defcustom fountain-character-extension-list
'("(V.O.)" "(O.S.)" "(O.C.)")
"List of extensions after character names (case sensitive).
`fountain-continued-dialog-string' is automatically added to this
list.
These are only used for auto-completion. Any character can have
whatever extension you like."
:group 'fountain
:type '(repeat (string :tag "Extension")))
(defconst fountain-forced-action-regexp
"^\\(!\\)\\(.*\\)[\s\t]*$"
"Regular expression for forced action.")
(defconst fountain-metadata-regexp
(concat "^\\([^:\s\t\n][^:[\n]*\\):[\s\t]*\\(.+\\)?"
"\\|"
"^[\s\t]+\\(?2:.+\\)")
"Regular expression for matching multi-line metadata values.
Requires `fountain-match-metadata' for `bobp'.")
(defconst fountain-character-regexp
(concat "^[\s\t]*"
"\\(?:\\(?1:@\\)\\(?2:.+?\\)"
"\\|"
"\\(?2:[^<>\n[:lower:]]*?[[:upper:]]+[^<>\n[:lower:]]*?\\)"
"\\)"
"\\(?3:[\s\t]*\\(?4:(\\)[^)\n]*)?\\)*?"
"[\s\t]*\\(?5:[\s\t]*^\\)?"
"[\s\t]*$")
"Regular expression for matching character names.
Group 1: match leading @ for forced character
Group 2: match character name
Group 3: match parenthetical extension
Group 4: match opening parenthetical
Group 5: match trailing ^ for dual dialogue
Requires `fountain-match-character' for preceding blank line.")
(defconst fountain-dialog-regexp
"^\\(\s\s\\)$\\|^[\s\t]*\\(?2:[^<>\n]+?\\)[\s\t]*$"
"Regular expression for matching dialogue.
Group 1: omitted
Group 2: match dialogue
Requires `fountain-match-dialog' for preceding character,
parenthetical or dialogue.")
(defconst fountain-paren-regexp
"^[\s\t]*\\(?2:([^)\n]*)\\)[\s\t]*$"
"Regular expression for matching parentheticals.
Group 1: omitted
Group 2: match parenthetical
Requires `fountain-match-paren' for preceding character or
dialogue.")
(defconst fountain-page-break-regexp
"^[\s\t]*\\(=\\{3,\\}\\)[\s\t]*\\([a-z0-9\\.-]+\\)?.*$"
"Regular expression for matching page breaks.
Group 1: leading ===
Group 2: forced page number")
(defconst fountain-note-regexp
"\\[\\[[\s\t]*\\(\\(?:\s\s\n\\|.\n?\\)*?\\)[\s\t]*]]"
"Regular expression for matching notes.
Group 1: note text")
(defconst fountain-section-heading-regexp
"^\\(?1:\\(?2:#\\{1,5\\}\\)[\s\t]*\\)\\(?3:.*\\)[\s\t]*$"
"Regular expression for matching section headings.
Group 1: match leading #s and following whitespace
Group 2: match leading #s
Group 3: match heading text")
(defconst fountain-section-heading-1-regexp
"^\\(?1:\\(?2:#\\)[\s\t]*\\)\\(?3:.*\\)[\s\t]*$"
"Regular expression for matching level 1 section headings.")
(defconst fountain-section-heading-2-regexp
"^\\(?1:\\(?2:##\\)[\s\t]*\\)\\(?3:.*\\)[\s\t]*$"
"Regular expression for matching level 2 section headings.")
(defconst fountain-section-heading-3-regexp
"^\\(?1:\\(?2:###\\)[\s\t]*\\)\\(?3:.*\\)[\s\t]*$"
"Regular expression for matching level 3 section headings.")
(defconst fountain-section-heading-4-regexp
"^\\(?1:\\(?2:####\\)[\s\t]*\\)\\(?3:.*\\)[\s\t]*$"
"Regular expression for matching level 4 section headings.")
(defconst fountain-section-heading-5-regexp
"^\\(?1:\\(?2:#####\\)[\s\t]*\\)\\(?3:.*\\)[\s\t]*$"
"Regular expression for matching level 5 section headings.")
(defconst fountain-synopsis-regexp
"^\\(\\(=\\)[\s\t]*\\)\\([^=\n].*\\)"
"Regular expression for matching synopses.
Group 1: leading = and following whitespace
Group 2: leading =
Group 3: synopsis text")
(defconst fountain-center-regexp
"^[\s\t]*\\(>\\)[\s\t]*\\(.+?\\)[\s\t]*\\(<\\)[\s\t]*$"
"Regular expression for matching centered text.
Group 1: match leading >
Group 2: match center text
Group 3: match trailing <")
(defconst fountain-underline-regexp
"\\(?:^\\|[^\\]\\)\\(\\(_\\)\\([^\n\s\t_][^_\n]*?\\)\\(\\2\\)\\)"
"Regular expression for matching underlined text.")
(defconst fountain-italic-regexp
"\\(?:^\\|[^*\\]\\)\\(\\(\\*\\)\\([^\n\s\t*][^*\n]*?\\)\\(\\2\\)\\)"
"Regular expression for matching italic text.")
(defconst fountain-bold-regexp
"\\(?:^\\|[^\\]\\)\\(\\(\\*\\*\\)\\([^\n\s\t\\*][^*\n]*?\\)\\(\\2\\)\\)"
"Regular expression for matching bold text.")
(defconst fountain-bold-italic-regexp
"\\(?:^\\|[^\\]\\)\\(\\(\\*\\*\\*\\)\\([^\n\s\t*][^*\n]*?\\)\\(\\2\\)\\)"
"Regular expression for matching bold-italic text.
Due to the nature of the syntax, bold-italic-underlined text must
be specified with the bold-italic delimiters together, e.g.
This text is _***ridiculously important***_.
This text is ***_stupendously significant_***.")
(defconst fountain-lyrics-regexp
"^\\(?1:\\(~[\s\t]*\\)\\(?3:.+\\)\\)"
"Regular expression for matching lyrics.")
;;; Aligning ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defgroup fountain-align ()
"Options for visual alignment of `fountain-mode' elements.
Each element align option can be an integer representing the
align column for all formats, or a list where each element takes
the form:
(FORMAT . INT)
Where FORMAT is a script format string and INT is the align
column for that format.
To disable element alignment, see `fountain-align-elements'."
:prefix "fountain-align-"
:group 'fountain)
(defcustom fountain-align-elements
t
"If non-nil, elements will be displayed auto-aligned.
This option does not affect file contents."
:group 'fountain-align
:type 'boolean
:safe 'booleanp
:set #'fountain--set-and-refresh-font-lock)
(defcustom fountain-align-section-heading
'(("screenplay" . 0)
("stageplay" . 30))
"Column integer to which section headings should be aligned.
This option does not affect file contents."
:group 'fountain-align
:type '(choice (integer :tag "Column")
(repeat (cons (string :tag "Format")
(integer :tag "Column"))))