Search code examples
emacsemacsclient

Silently call defun from emacsclient


During the compilation of sources, I would like GNU Make to call an emacs defun. For this I have 2 options:

  • Start a new emacs instance, and load the desired function and call it.
  • Call the defun from the emacsclient like:

    emacsclient --eval "(my-emacs-defun)"
    

The latter has the advantage, it is faster, because the emacs server is already running and has the desired defun loaded.

But this also has a disadvantage, if (message ...) is called from (my-emacs-defun), it interrupts my active emacs session. I could try to modify (my-emacs-defun) so (message ...) isn't called, but is really hard when using emacs built-in functions.

Therefore I would like to know how to suppress the (message ...) from (my-emacs-defun). Is it possible to alter the (message ...) behavior when being called (my-emacs-defun)? Can I use(defadvice)` for this?

EDIT The real problem is, the message is displayed the minibuffer. It is irritating when using the minibuffer at that time (e.g. during (find-file)).


Solution

  • I decided to go for the first option: without emacsclient.

    To be more precise I now use:

    emacs --batch --eval "(my-emacs-defun)"
    

    In my Makefile it looks like this:

    sometarget:
            @emacs --batch --eval "$${elisp_code}"
    
    define elisp_code
       (require 'something)
       (my-emacs-defun)
    endif
    

    This also seems to be fast.