From 40e71781db8b6dcbcf4c9f9dcdbed04d34e910dc Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Mon, 19 Sep 2016 12:53:05 +0200 Subject: [PATCH] Hide the output of refreshing packages --- emacs/.emacs.d/init.org | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/emacs/.emacs.d/init.org b/emacs/.emacs.d/init.org index 9258e52..ddd5a62 100644 --- a/emacs/.emacs.d/init.org +++ b/emacs/.emacs.d/init.org @@ -38,12 +38,45 @@ To start off, first I need to enable lexical binding. (eval-and-compile (package-initialize)) #+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 configured archives. Don't do this at run-time because it slows down the process too much. #+BEGIN_SRC emacs-lisp - (eval-when-compile (package-refresh-contents)) + (eval-when-compile + (silently "Refresh packages" + (package-refresh-contents))) #+END_SRC This macro is inspired by use-package, but I want to maintain some