diff options
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/acdw.el | 50 |
1 files changed, 50 insertions, 0 deletions
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." | |||
35 | (executable-find (car (ensure-list x)))) | 35 | (executable-find (car (ensure-list x)))) |
36 | programs)) | 36 | programs)) |
37 | 37 | ||
38 | (defun file-string (file) | ||
39 | "Return the contents of FILE as a string." | ||
40 | (with-current-buffer (find-file-noselect file) | ||
41 | (buffer-string))) | ||
42 | |||
43 | (defun unsmartify-region (begin end) | ||
44 | "Replace \"smart\" punctuation with \"dumb\" counterparts." | ||
45 | (interactive "*r") | ||
46 | (save-excursion | ||
47 | (goto-char begin) | ||
48 | (while (re-search-forward "[“”‘’–—]" end t) | ||
49 | (let ((replace (pcase (match-string 0) | ||
50 | ((or "“" "”") "\"") | ||
51 | ((or "‘" "’") "'") | ||
52 | ("–" "--") | ||
53 | ("—" "---")))) | ||
54 | (replace-match replace nil nil))))) | ||
55 | |||
56 | (defun ++concat (func strings) | ||
57 | "Concat STRINGS processed by FUNC. | ||
58 | Each of STRINGS can be a bare string or a list. Strings are | ||
59 | passed through as-is, but lists are passed to FUNC first as | ||
60 | arguments. Finally, all the resulting strings are `mapconcat'-ed | ||
61 | together. | ||
62 | |||
63 | As a special case, if `:separator' is the first of STRINGS, the | ||
64 | string following will be used as a separator. Otherwise, a | ||
65 | newline will be used." | ||
66 | (let (separator) | ||
67 | (when (eq (car strings) :separator) | ||
68 | (setq separator (cadr strings) | ||
69 | strings (cddr strings))) | ||
70 | (mapconcat (lambda (s) | ||
71 | (cond | ||
72 | ((listp s) (apply func s)) | ||
73 | ((stringp s) s) | ||
74 | (t (user-error "Bad argument: %S" s)))) | ||
75 | strings | ||
76 | (or separator "\n")))) | ||
77 | |||
78 | (defun format-concat (&rest strings) | ||
79 | "Concatenate formatted STRINGS. | ||
80 | Each of STRINGS can be a bare string or a list. Bare strings are passed as-is | ||
81 | to `mapconcat' for concatenation and separation. Lists, however, are passed to | ||
82 | `format' first. | ||
83 | |||
84 | If `:separator' is the first of STRINGS, the next string will be | ||
85 | used as a separator." | ||
86 | (++concat #'format strings)) | ||
87 | |||
38 | (provide 'acdw) | 88 | (provide 'acdw) |
39 | ;;; acdw.el ends here | 89 | ;;; acdw.el ends here |