Move the silently macro to helpers library
This commit is contained in:
parent
2f3cbefaf9
commit
fec859e587
1 changed files with 25 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue