Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

elisp: silence "Loading" messages in batch mode

Tags:

emacs

elisp

Even when I invoke emacs -batch (that is, batch mode without actually doing anything), emacs vomits out a whole pile of messages:

$ emacs -batch
Loading 00debian-vars...
Loading /etc/emacs/site-start.d/50autoconf.el (source)...
Loading /etc/emacs/site-start.d/50cmake-data.el (source)...
Loading /etc/emacs/site-start.d/50devhelp.el (source)...
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...
Loading debian-ispell...
Loading /var/cache/dictionaries-common/emacsen-ispell-default.el (source)...
Loading /var/cache/dictionaries-common/emacsen-ispell-dicts.el (source)...
Loading /etc/emacs/site-start.d/50psvn.el (source)...

Is there any way to silence these messages? Google hasn't been too helpful for this.

like image 651
Jack Kelly Avatar asked Jul 16 '12 04:07

Jack Kelly


2 Answers

Those are the messages that would normally show up in the *Messages* buffer, which are instead going to stderr. Here are a few ways to silence it, in increasing order of sophistication:

  • The simplest fix would be to redirect stderr, if you're not going to use it:

    emacs -batch 2>/dev/null
    
  • Those messages are coming from something loaded in the site-wide initialization. If you don't need any other functionality from your initialization files, you can try:

    emacs -batch --no-site-file ... # ignore system-wide
    emacs -batch -Q ... # ignore everything
    
  • In theory one can achieve this via (setq force-load-messages nil), but the fact that the site-file is the one printing here means you likely can't do it early enough.

  • advise the load function so that it is always called with NOMESSAGE. Here's a sketch:

    (defadvice load (before quiet-loading
                       (&optional NOMESSAGE)
                       activate)
       (setq NOMESSAGE t))
    (load site-run-file t)
    

    This should just force load to always pass t in the NOMESSAGE argument, and then loads the site-run-file, ignoring errors if no such file is present. (Note that at least on all 2 of the machines I use emacs on, there's no site-run-file; I have no idea how common that is in the wild.)

like image 119
Craig Citro Avatar answered Sep 18 '22 15:09

Craig Citro


I went source-diving and found that the load function calls the C function message_from_string to display the "Loading <whatever>..." messages. When Emacs is not running interactively, message_from_string just prints directly to stderr with no way to avoid it. Well, you could call the original load function with the nomessage parameter set to true, but it's probably not trivial to arrange that when running in batch mode.

It might suffice just to filter out the messages you don't want:

$ emacs -batch 2>&1 | grep -v '^Loading.*\.\.\.$'
like image 28
Sean Avatar answered Sep 20 '22 15:09

Sean