Move the silently macro to helpers library

This commit is contained in:
Tom Willemse 2017-03-05 22:14:34 -08:00
parent 2f3cbefaf9
commit fec859e587

View file

@ -24,6 +24,29 @@
;;; 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