Hide the output of refreshing packages

This commit is contained in:
Tom Willemse 2016-09-19 12:53:05 +02:00
parent ddf26ede7e
commit 40e71781db

View file

@ -38,12 +38,45 @@ To start off, first I need to enable lexical binding.
(eval-and-compile (package-initialize)) (eval-and-compile (package-initialize))
#+END_SRC #+END_SRC
Some actions produce a lot of output that is usually uninteresting
during compilation. However, this information may be crucial when an
error occurs. So for these actions I can use this macro, which
stores all sent messages in a temporary buffer and prints them when
an error occurs, and hides them when it doesn't.
#+BEGIN_SRC emacs-lisp
(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"))))))))
#+END_SRC
Refresh the package contents so packages can be installed from all Refresh the package contents so packages can be installed from all
configured archives. Don't do this at run-time because it slows down configured archives. Don't do this at run-time because it slows down
the process too much. the process too much.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(eval-when-compile (package-refresh-contents)) (eval-when-compile
(silently "Refresh packages"
(package-refresh-contents)))
#+END_SRC #+END_SRC
This macro is inspired by use-package, but I want to maintain some This macro is inspired by use-package, but I want to maintain some