From be15049058ae955e04e1181abb9ce0f9bebf94a1 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 6 Jan 2022 15:49:32 -0600 Subject: Add some extra functions --- lisp/acdw.el | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) 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." (make-directory (file-name-directory file-name) :parents)) file-name)))) - (defun +suppress-messages (oldfn &rest args) ; from pkal "Advice wrapper for suppressing `message'. OLDFN is the wrapped function, that is passed the arguments @@ -125,5 +124,65 @@ I keep forgetting how they differ." "Quick way to `setq' a variable from a `defvar' form." `(setq ,var ,value)) +(defmacro +with-message (message &rest body) + "Execute BODY, with MESSAGE. +If body executes without errors, MESSAGE...Done will be displayed." + ;; ^ TODO + `(prog1 (progn (message ,(concat message "...")) + ,@body) + (message ,(concat message "...Done.")))) + +(defun +mapc-some-buffers (func &optional predicate) + "Perform FUNC on all buffers satisfied by PREDICATE. +By default, act on all buffers. + +PREDICATE is a function called with one argument, the current +buffer. FUNC is called with no arguments. Both are called +within a `with-current-buffer' form." + (let ((pred (or predicate t))) + (dolist (buf (buffer-list)) + (with-current-buffer buf + (when (funcall pred buf) + (funcall func)))))) + +;; https://github.com/cstby/emacs.d/blob/main/init.el#L67 +(defun +clean-empty-lines (&optional begin end) + "Remove duplicate empty lines from BEGIN to END. +Called interactively, this function acts on the region, if +active, or else the entire buffer." + (interactive "*r") + (unless (region-active-p) + (setq begin (point-min) + end (save-excursion + (goto-char (point-max)) + (skip-chars-backward "\n[:space:]") + (point)))) + (save-excursion + (save-restriction + (narrow-to-region begin end) + (goto-char (point-min)) + (while (re-search-forward "\n\n\n+" nil :move) + (replace-match "\n\n")) + ;; Insert a newline at the end. + (goto-char (point-max)) + (unless (= (line-beginning-position) (line-end-position)) + (insert "\n"))))) + +(defun +open-paragraph () + "Open a paragraph after paragraph at point. +A paragraph is defined as continguous non-empty lines of text +surrounded by empty lines, so opening a paragraph means to make +three blank lines, then place the point on the second one." + (interactive "*") + (unless (derived-mode-p 'special-mode 'lui-mode 'comint-mode) + ;; Go to next blank line. This /isn't/ `end-of-paragraph-text' because + ;; that's weird with org, and I'm guessing other modes too. + (while (not (looking-at "^$")) + (forward-line 1)) + (newline) + (delete-blank-lines) + (newline 2) + (previous-line))) + (provide 'acdw) ;;; acdw.el ends here -- cgit 1.4.1-21-gabe81