aboutsummaryrefslogtreecommitdiffstats
path: root/emacs/.emacs.d
diff options
context:
space:
mode:
authorGravatar Tom Willemse2016-09-19 12:53:05 +0200
committerGravatar Tom Willemse2016-09-19 12:53:05 +0200
commit40e71781db8b6dcbcf4c9f9dcdbed04d34e910dc (patch)
tree0d873bf95dbbeb009a3e6f089ead4fddc9ec7b8e /emacs/.emacs.d
parentddf26ede7e3709ed922c68c9d3017d705d847c8e (diff)
downloadnew-dotfiles-40e71781db8b6dcbcf4c9f9dcdbed04d34e910dc.tar.gz
new-dotfiles-40e71781db8b6dcbcf4c9f9dcdbed04d34e910dc.zip
Hide the output of refreshing packages
Diffstat (limited to 'emacs/.emacs.d')
-rw-r--r--emacs/.emacs.d/init.org35
1 files changed, 34 insertions, 1 deletions
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