aboutsummaryrefslogtreecommitdiffstats
path: root/emacs/.emacs.d/site-lisp/oni-helpers.el
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/.emacs.d/site-lisp/oni-helpers.el')
-rw-r--r--emacs/.emacs.d/site-lisp/oni-helpers.el27
1 files changed, 25 insertions, 2 deletions
diff --git a/emacs/.emacs.d/site-lisp/oni-helpers.el b/emacs/.emacs.d/site-lisp/oni-helpers.el
index 3b3ad99..1807658 100644
--- a/emacs/.emacs.d/site-lisp/oni-helpers.el
+++ b/emacs/.emacs.d/site-lisp/oni-helpers.el
@@ -24,10 +24,33 @@
;;; Code:
+(defmacro silently (title &rest body)
+ "Only output something when an error occurs.
+Prefix with TITLE any output that occurs while executing BODY,
+but only when an error occurs, otherwise discard it."
+ (declare (indent 1))
+ (let ((buffer-var (cl-gensym))
+ (error-var (cl-gensym)))
+ `(with-temp-buffer
+ (let ((,buffer-var (current-buffer)))
+ (cl-letf (((symbol-function 'message)
+ (lambda (msg &rest args)
+ (with-current-buffer ,buffer-var
+ (insert " " (apply 'format msg args) "\n")))))
+ (condition-case ,error-var
+ (progn ,@body)
+ (error
+ (princ ,(concat title " output:\n"))
+ (princ (with-current-buffer ,buffer-var (buffer-string)))
+ (princ "Error:\n")
+ (princ " ")
+ (princ (cadr ,error-var))
+ (princ "\n"))))))))
+
(defun oni:data-location (file-name)
"Return the location of FILE-NAME within my data directory.
- This is currently the data directory under the
- `user-emacs-directory'."
+This is currently the data directory under the
+`user-emacs-directory'."
(concat user-emacs-directory "data/" file-name))
(with-eval-after-load 'ert