diff options
Diffstat (limited to 'lisp/acdw.el')
-rw-r--r-- | lisp/acdw.el | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/lisp/acdw.el b/lisp/acdw.el index 71905d2..8b9c7b9 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el | |||
@@ -44,7 +44,6 @@ the filesystem, unless INHIBIT-MKDIR is non-nil." | |||
44 | (make-directory (file-name-directory file-name) :parents)) | 44 | (make-directory (file-name-directory file-name) :parents)) |
45 | file-name)))) | 45 | file-name)))) |
46 | 46 | ||
47 | |||
48 | (defun +suppress-messages (oldfn &rest args) ; from pkal | 47 | (defun +suppress-messages (oldfn &rest args) ; from pkal |
49 | "Advice wrapper for suppressing `message'. | 48 | "Advice wrapper for suppressing `message'. |
50 | OLDFN is the wrapped function, that is passed the arguments | 49 | OLDFN is the wrapped function, that is passed the arguments |
@@ -126,5 +125,65 @@ I keep forgetting how they differ." | |||
126 | (declare (doc-string 3)) | 125 | (declare (doc-string 3)) |
127 | `(setq ,var ,value)) | 126 | `(setq ,var ,value)) |
128 | 127 | ||
128 | (defmacro +with-message (message &rest body) | ||
129 | "Execute BODY, with MESSAGE. | ||
130 | If body executes without errors, MESSAGE...Done will be displayed." | ||
131 | ;; ^ TODO | ||
132 | `(prog1 (progn (message ,(concat message "...")) | ||
133 | ,@body) | ||
134 | (message ,(concat message "...Done.")))) | ||
135 | |||
136 | (defun +mapc-some-buffers (func &optional predicate) | ||
137 | "Perform FUNC on all buffers satisfied by PREDICATE. | ||
138 | By default, act on all buffers. | ||
139 | |||
140 | PREDICATE is a function called with one argument, the current | ||
141 | buffer. FUNC is called with no arguments. Both are called | ||
142 | within a `with-current-buffer' form." | ||
143 | (let ((pred (or predicate t))) | ||
144 | (dolist (buf (buffer-list)) | ||
145 | (with-current-buffer buf | ||
146 | (when (funcall pred buf) | ||
147 | (funcall func)))))) | ||
148 | |||
149 | ;; https://github.com/cstby/emacs.d/blob/main/init.el#L67 | ||
150 | (defun +clean-empty-lines (&optional begin end) | ||
151 | "Remove duplicate empty lines from BEGIN to END. | ||
152 | Called interactively, this function acts on the region, if | ||
153 | active, or else the entire buffer." | ||
154 | (interactive "*r") | ||
155 | (unless (region-active-p) | ||
156 | (setq begin (point-min) | ||
157 | end (save-excursion | ||
158 | (goto-char (point-max)) | ||
159 | (skip-chars-backward "\n[:space:]") | ||
160 | (point)))) | ||
161 | (save-excursion | ||
162 | (save-restriction | ||
163 | (narrow-to-region begin end) | ||
164 | (goto-char (point-min)) | ||
165 | (while (re-search-forward "\n\n\n+" nil :move) | ||
166 | (replace-match "\n\n")) | ||
167 | ;; Insert a newline at the end. | ||
168 | (goto-char (point-max)) | ||
169 | (unless (= (line-beginning-position) (line-end-position)) | ||
170 | (insert "\n"))))) | ||
171 | |||
172 | (defun +open-paragraph () | ||
173 | "Open a paragraph after paragraph at point. | ||
174 | A paragraph is defined as continguous non-empty lines of text | ||
175 | surrounded by empty lines, so opening a paragraph means to make | ||
176 | three blank lines, then place the point on the second one." | ||
177 | (interactive "*") | ||
178 | (unless (derived-mode-p 'special-mode 'lui-mode 'comint-mode) | ||
179 | ;; Go to next blank line. This /isn't/ `end-of-paragraph-text' because | ||
180 | ;; that's weird with org, and I'm guessing other modes too. | ||
181 | (while (not (looking-at "^$")) | ||
182 | (forward-line 1)) | ||
183 | (newline) | ||
184 | (delete-blank-lines) | ||
185 | (newline 2) | ||
186 | (previous-line))) | ||
187 | |||
129 | (provide 'acdw) | 188 | (provide 'acdw) |
130 | ;;; acdw.el ends here | 189 | ;;; acdw.el ends here |