aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2017-03-05 22:14:34 -0800
committerGravatar Tom Willemse2017-03-05 22:14:34 -0800
commitfec859e58745990dab9a3814ac9044fd1dfa97d4 (patch)
tree6c3ce28ed0f0be7596adfdc4ca3c58ae6819192c
parent2f3cbefaf96001681701efe07b829099be26f42a (diff)
downloadnew-dotfiles-fec859e58745990dab9a3814ac9044fd1dfa97d4.tar.gz
new-dotfiles-fec859e58745990dab9a3814ac9044fd1dfa97d4.zip
Move the silently macro to helpers library
-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