[elpa] externals/fountain-mode fff47c4 2/2: Add fountain-completion-additional-(characters|locations)

2019-08-10 Thread Paul W. Rankin
branch: externals/fountain-mode
commit fff47c484cff9daab5dbf081358d6856590a88e3
Author: Paul W. Rankin 
Commit: Paul W. Rankin 

Add fountain-completion-additional-(characters|locations)

Useful when working with multiple files. Must satisfy (and (listp LIST)
(seq-every-p 'stringp LIST)).

Also reworked fountain-completion-get-characters to only return a list
of characters, moving completion login into fountain-completion-at-point.
---
 fountain-mode.el | 138 +--
 1 file changed, 94 insertions(+), 44 deletions(-)

diff --git a/fountain-mode.el b/fountain-mode.el
index 04210a1..5044956 100644
--- a/fountain-mode.el
+++ b/fountain-mode.el
@@ -1018,9 +1018,6 @@ buffers."
   (setq-local page-delimiter fountain-page-break-regexp)
   (setq-local outline-level #'fountain-outline-level)
   (setq-local require-final-newline mode-require-final-newline)
-  ;; FIXME: `completion-cycle-threshold' is a user option, so
-  ;; hard-coding it to non-nil is dubious. On the other hand,
-  ;; completion without cycling in screenwriting is weird.
   (setq-local completion-cycle-threshold t)
   (setq-local completion-at-point-functions
   '(fountain-completion-at-point))
@@ -1278,54 +1275,90 @@ Each element is a cons (NAME . OCCUR) where NAME is a 
string, and
 OCCUR is an integer representing the character's number of
 occurrences. ")
 
+(defcustom fountain-completion-additional-characters
+  nil
+  "List of additional characters to offer for completion.
+Case insensitive, all character names will be made uppercase.
+
+This is more useful when working with multiple files and set with
+`add-dir-local-variable'."
+  :type '(repeat (string :tag "Character"))
+  :safe '(lambda (value)
+   (and (listp value)
+(seq-every-p 'stringp value
+
+(defcustom fountain-completion-additional-locations
+  nil
+  "List of additional locations to offer for completion.
+Case insensitive, all locations will be made uppercase.
+
+This is more useful when working with multiple files and set with
+`add-dir-local-variable'."
+  :type '(repeat (string :tag "Location"))
+  :safe '(lambda (value)
+   (and (listp value)
+(seq-every-p 'stringp value
 
 (defun fountain-completion-get-characters ()
-  "Return candidates for completing character.
+  "Return a list of characters for completion.
 
 First, return second-last speaking character, followed by each
 previously speaking character within scene. After that, return
-characters from `fountain-completion-characters'."
-  (lambda (string pred action)
-(let (scene-characters alt-character contd-character rest-characters)
-  (save-excursion
-(save-restriction
-  (widen)
-  (fountain-forward-character 0 'scene)
-  (while (not (or (fountain-match-scene-heading)
-  (bobp)))
-(when (fountain-match-character)
-  (let ((character (match-string-no-properties 4)))
-(unless (member character scene-characters)
-  (push (list character) scene-characters
-(fountain-forward-character -1 'scene
-  (setq scene-characters (reverse scene-characters)
-alt-character (cadr scene-characters)
-contd-character (car scene-characters)
-rest-characters (cddr scene-characters)
-scene-characters nil)
-  (when rest-characters
-(setq scene-characters rest-characters))
-  (when contd-character
-(setq scene-characters
-  (cons contd-character scene-characters)))
-  (when alt-character
-(setq scene-characters
-  (cons alt-character scene-characters)))
-  (if (eq action 'metadata)
-  (list 'metadata
-(cons 'display-sort-function 'identity)
-(cons 'cycle-sort-function 'identity))
-(complete-with-action action
-  (append scene-characters 
fountain-completion-characters)
-  string pred)
+characters from `fountain-completion-additional-characters' then
+`fountain-completion-characters'.
+
+n.b. `fountain-completion-additional-characters' are offered as
+candidates ahead of `fountain-completion-characters' because
+these need to be manually set, and so are considered more
+important."
+  (let (scene-characters
+alt-character
+contd-character
+rest-characters)
+(save-excursion
+  (save-restriction
+(widen)
+(fountain-forward-character 0 'scene)
+(while (not (or (bobp) (fountain-match-scene-heading)))
+  (when (fountain-match-character)
+(let ((character (match-string-no-properties 4)))
+  (unless (member character scene-characters)
+(push (list character) scene-characters
+  (fountain-forward-character -1 'scene
+(setq scene

[elpa] externals/fountain-mode updated (44cbe32 -> fff47c4)

2019-08-10 Thread Paul W. Rankin
pwr pushed a change to branch externals/fountain-mode.

  from  44cbe32   Attempt to get fountain-mode.el bugs sent to p...@sdf.org
   new  14a898b   Merge functions into fountain-completion-update
   new  fff47c4   Add fountain-completion-additional-(characters|locations)


Summary of changes:
 fountain-mode.el | 199 ---
 1 file changed, 116 insertions(+), 83 deletions(-)



[elpa] externals/fountain-mode 14a898b 1/2: Merge functions into fountain-completion-update

2019-08-10 Thread Paul W. Rankin
branch: externals/fountain-mode
commit 14a898b4a478739f9f9396bd82c7c1a058eac7ef
Author: Paul W. Rankin 
Commit: Paul W. Rankin 

Merge functions into fountain-completion-update

Merges fountain-completion-update-locations and
fountain-completion-update-characters
---
 fountain-mode.el | 61 
 1 file changed, 22 insertions(+), 39 deletions(-)

diff --git a/fountain-mode.el b/fountain-mode.el
index 13b16e4..04210a1 100644
--- a/fountain-mode.el
+++ b/fountain-mode.el
@@ -1278,43 +1278,6 @@ Each element is a cons (NAME . OCCUR) where NAME is a 
string, and
 OCCUR is an integer representing the character's number of
 occurrences. ")
 
-(defun fountain-completion-update-locations (start end &optional length)
-  "Update `fountain-completion-locations' between START and END."
-  (goto-char end)
-  (if (fountain-match-scene-heading)
-  (forward-line)
-(fountain-forward-scene 1))
-  (setq end (point))
-  (goto-char start)
-  (fountain-forward-scene 0)
-  (while (< (point) end)
-(when (fountain-match-scene-heading)
-  (let ((location (match-string-no-properties 4)))
-(unless (member location fountain-completion-locations)
-  (push location fountain-completion-locations
-(fountain-forward-scene 1)))
-
-(defun fountain-completion-update-characters (start end &optional length)
-  "Update `fountain-completion-characters' in current buffer."
-  (goto-char end)
-  (if (fountain-match-scene-heading)
-  (forward-line)
-(fountain-forward-scene 1))
-  (setq end (point))
-  (goto-char start)
-  (fountain-forward-scene 0)
-  (while (< (point) end)
-(when (fountain-match-character)
-  (let* ((character (match-string-no-properties 4))
- (candidate (assoc-string character 
fountain-completion-characters))
- (n (cdr candidate)))
-(if (not n)
-(push (cons character 1) fountain-completion-characters)
-  (cl-incf (cdr candidate)
-(fountain-forward-character 1))
-  (setq fountain-completion-characters
-(sort fountain-completion-characters #'(lambda (a b)
- (< (cdr b) (cdr a))
 
 (defun fountain-completion-get-characters ()
   "Return candidates for completing character.
@@ -1405,8 +1368,28 @@ Add to `fountain-mode-hook' to have completion upon 
load."
   (save-excursion
 (save-restriction
   (widen)
-  (fountain-completion-update-locations (point-min) (point-max))
-  (fountain-completion-update-characters (point-min) (point-max
+  (goto-char (point-min))
+  (while (< (point) (point-max))
+(when (fountain-match-scene-heading)
+  (let ((location (match-string-no-properties 4)))
+(unless (member location fountain-completion-locations)
+  (push location fountain-completion-locations
+(fountain-forward-scene 1))
+  (goto-char (point-min))
+  (while (< (point) (point-max))
+(when (fountain-match-character)
+  (let ((character (match-string-no-properties 4))
+candidate lines)
+(setq candidate (assoc-string character
+  fountain-completion-characters)
+  lines (cdr candidate))
+(if (null lines)
+(push (cons character 1) fountain-completion-characters)
+  (cl-incf (cdr candidate)
+(fountain-forward-character 1))
+  (setq fountain-completion-characters
+(sort fountain-completion-characters
+  #'(lambda (a b) (< (cdr b) (cdr a)))
   (message "Completion candidates updated"))