Add macro `with-message'

This commit is contained in:
Case Duckworth 2021-04-21 17:54:29 -05:00
parent c478ecae3c
commit 152daf82ef
2 changed files with 14 additions and 7 deletions

12
init.el
View File

@ -846,13 +846,11 @@ if ripgrep is installed, otherwise `consult-grep'."
(defun acdw/eval-region-or-buffer ()
(interactive)
(if (region-active-p)
(progn
(message "Evaluating %S -> %S..." (region-beginning) (region-end))
(eval-region (region-beginning) (region-end))
(message "Evaluating %S -> %S... Done." (region-beginning) (region-end)))
(message "%s" "Evaluating buffer...")
(eval-buffer)
(message "%s" "Evaluating buffer... Done.")))
(with-message (format "Evaluating %S -> %S"
(region-beginning) (region-end))
(eval-region (region-beginning) (region-end)))
(with-message "Evaluating buffer"
(eval-buffer))))
(:with-map emacs-lisp-mode-map
(:bind "C-c C-c" acdw/eval-region-or-buffer

View File

@ -70,6 +70,15 @@ each hook in HOOKS."
file
nil)))
(defmacro with-message (message &rest body)
"Execute BODY, messaging 'MESSAGE...' before and 'MESSAGE... Done.' after."
(declare (indent 1))
;; Wrap a progn inside a prog1 to return the return value of the body.
`(prog1
(progn (message "%s..." ,message)
,@body)
(message "%s... Done." ,message)))
(defun acdw/dir (&optional file make-directory)
"Place Emacs files in one place.