summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2022-02-18 18:25:33 -0600
committerCase Duckworth2022-02-18 18:25:33 -0600
commit277dfcc6cd8ac197eeb2490b8ba3bcb3d47f6243 (patch)
tree388714f48f07ff8b3214ae7317b6cc9c5260d7ce
parentChanges (diff)
downloademacs-277dfcc6cd8ac197eeb2490b8ba3bcb3d47f6243.tar.gz
emacs-277dfcc6cd8ac197eeb2490b8ba3bcb3d47f6243.zip
Add +concat and +file-string
-rw-r--r--lisp/acdw.el28
1 files changed, 27 insertions, 1 deletions
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 @@
28 "Define a variable and function NAME expanding to DIRECTORY. 28 "Define a variable and function NAME expanding to DIRECTORY.
29DOCSTRING is applied to the variable. Ensure DIRECTORY exists in 29DOCSTRING is applied to the variable. Ensure DIRECTORY exists in
30the filesystem, unless INHIBIT-MKDIR is non-nil." 30the filesystem, unless INHIBIT-MKDIR is non-nil."
31 (declare (indent 2)) 31 (declare (indent 2)
32 (doc-string 3))
32 (unless inhibit-mkdir 33 (unless inhibit-mkdir
33 (make-directory (eval directory) :parents)) 34 (make-directory (eval directory) :parents))
34 `(progn 35 `(progn
@@ -327,5 +328,30 @@ See `+forward-paragraph' for the behavior."
327 (interactive "p") 328 (interactive "p")
328 (+forward-paragraph (- arg))) 329 (+forward-paragraph (- arg)))
329 330
331(defun +concat (&rest strings)
332 "Concat STRINGS separated by SEPARATOR.
333Each item in STRINGS is either a string or a list or strings,
334which is concatenated without any separator.
335
336SEPARATOR defaults to the newline (\\n)."
337 (let (ret
338 ;; I don't know why a `cl-defun' with
339 ;; (&rest strings &key (separator "\n")) doesn't work
340 (separator (or (cl-loop for i from 0 upto (length strings)
341 if (eq (nth i strings) :separator)
342 return (nth (1+ i) strings))
343 "\n")))
344 (while strings
345 (let ((string (pop strings)))
346 (cond ((eq string :separator) (pop strings))
347 ((listp string) (push (apply #'concat string) ret))
348 ((stringp string) (push string ret)))))
349 (mapconcat #'identity (nreverse ret) separator)))
350
351(defun +file-string (file)
352 "Fetch the contents of FILE and return its string."
353 (with-current-buffer (find-file-noselect file)
354 (buffer-string)))
355
330(provide 'acdw) 356(provide 'acdw)
331;;; acdw.el ends here 357;;; acdw.el ends here