From b13e8f87a92c34abb7168a812523f395151afcc7 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 12 Jan 2023 16:39:31 -0600 Subject: Meh --- lisp/acdw.el | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'lisp/acdw.el') diff --git a/lisp/acdw.el b/lisp/acdw.el index f16a679..6729759 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -35,5 +35,55 @@ enables passing arguments to a calling function." (executable-find (car (ensure-list x)))) programs)) +(defun file-string (file) + "Return the contents of FILE as a string." + (with-current-buffer (find-file-noselect file) + (buffer-string))) + +(defun unsmartify-region (begin end) + "Replace \"smart\" punctuation with \"dumb\" counterparts." + (interactive "*r") + (save-excursion + (goto-char begin) + (while (re-search-forward "[“”‘’–—]" end t) + (let ((replace (pcase (match-string 0) + ((or "“" "”") "\"") + ((or "‘" "’") "'") + ("–" "--") + ("—" "---")))) + (replace-match replace nil nil))))) + +(defun ++concat (func strings) + "Concat STRINGS processed by FUNC. +Each of STRINGS can be a bare string or a list. Strings are +passed through as-is, but lists are passed to FUNC first as +arguments. Finally, all the resulting strings are `mapconcat'-ed +together. + +As a special case, if `:separator' is the first of STRINGS, the +string following will be used as a separator. Otherwise, a +newline will be used." + (let (separator) + (when (eq (car strings) :separator) + (setq separator (cadr strings) + strings (cddr strings))) + (mapconcat (lambda (s) + (cond + ((listp s) (apply func s)) + ((stringp s) s) + (t (user-error "Bad argument: %S" s)))) + strings + (or separator "\n")))) + +(defun format-concat (&rest strings) + "Concatenate formatted STRINGS. +Each of STRINGS can be a bare string or a list. Bare strings are passed as-is +to `mapconcat' for concatenation and separation. Lists, however, are passed to +`format' first. + +If `:separator' is the first of STRINGS, the next string will be +used as a separator." + (++concat #'format strings)) + (provide 'acdw) ;;; acdw.el ends here -- cgit 1.4.1-21-gabe81