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