skelrc: New function to insert flowed paragraphs.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 15 Sep 2017 08:55:36 +0000 (09:55 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 15 Sep 2017 08:55:36 +0000 (09:55 +0100)
skelrc

diff --git a/skelrc b/skelrc
index 43d6052..67ffd1a 100644 (file)
--- a/skelrc
+++ b/skelrc
@@ -95,6 +95,28 @@ the PREFIX is removed."
       (forward-line))
     (buffer-string)))
 
+(defun skelrc-prefix-and-reflow (prefix text)
+  "Return LINES, reflowed to `fill-column', with PREFIX at the start."
+  (let ((expanded-prefix (skelrc-expand-text prefix))
+       (expanded-text (skelrc-expand-text text))
+       (col (string-to-number (skel-lookup 'fill-column))))
+    (with-temp-buffer
+      (let* ((fill-prefix expanded-prefix)
+            (paragraph-start (concat (skelrc-strip-trailing-whitespace
+                                      (regexp-quote expanded-prefix))
+                                     "[ \t\f]*$"))
+            (paragraph-separate paragraph-start)
+            (fill-column col))
+
+       (insert (skelrc-prefix-lines expanded-prefix expanded-text))
+
+       (goto-char (point-min))
+       (while (< (point) (point-max))
+         (fill-paragraph)
+         (forward-paragraph))
+
+       (buffer-string)))))
+
 (defun skelrc-component ()
   "Return a suitable a `This file is part of ...' line."
   (if (assq 'full-title skel-alist)