From 277dfcc6cd8ac197eeb2490b8ba3bcb3d47f6243 Mon Sep 17 00:00:00 2001
From: Case Duckworth
Date: Fri, 18 Feb 2022 18:25:33 -0600
Subject: Add +concat and +file-string

---
 lisp/acdw.el | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

(limited to 'lisp')

diff --git a/lisp/acdw.el b/lisp/acdw.el
index d7b25c7..7012b16 100644
--- a/lisp/acdw.el
+++ b/lisp/acdw.el
@@ -28,7 +28,8 @@
   "Define a variable and function NAME expanding to DIRECTORY.
 DOCSTRING is applied to the variable.  Ensure DIRECTORY exists in
 the filesystem, unless INHIBIT-MKDIR is non-nil."
-  (declare (indent 2))
+  (declare (indent 2)
+           (doc-string 3))
   (unless inhibit-mkdir
     (make-directory (eval directory) :parents))
   `(progn
@@ -327,5 +328,30 @@ See `+forward-paragraph' for the behavior."
   (interactive "p")
   (+forward-paragraph (- arg)))
 
+(defun +concat (&rest strings)
+  "Concat STRINGS separated by SEPARATOR.
+Each item in STRINGS is either a string or a list or strings,
+which is concatenated without any separator.
+
+SEPARATOR defaults to the newline (\\n)."
+  (let (ret
+        ;; I don't know why a `cl-defun' with
+        ;; (&rest strings &key (separator "\n")) doesn't work
+        (separator (or (cl-loop for i from 0 upto (length strings)
+                                if (eq (nth i strings) :separator)
+                                return (nth (1+ i) strings))
+                       "\n")))
+    (while strings
+      (let ((string (pop strings)))
+        (cond ((eq string :separator) (pop strings))
+              ((listp string) (push (apply #'concat string) ret))
+              ((stringp string) (push string ret)))))
+    (mapconcat #'identity (nreverse ret) separator)))
+
+(defun +file-string (file)
+  "Fetch the contents of FILE and return its string."
+  (with-current-buffer (find-file-noselect file)
+    (buffer-string)))
+
 (provide 'acdw)
 ;;; acdw.el ends here
-- 
cgit 1.4.1-21-gabe81