[Editorial comment: I'm not convinced this is a good idea - what difference does it make if the *Messages*
buffer has an extra line in it? Despite my misgivings, I provide an answer below.]
The relevant function is org-link--open-elisp
. If you check its implementation, you will see that it uses message
to print the result of the evaluation to the echo area. But message
also copies whatever it prints to the echo area, to the *Messages*
buffer. A quick perusal of the doc string for message
shows that you can avoid copying to the *Messages*
buffer if you set message-log-max
to nil
. Unfortunately, that is going to turn off all output to the Messages buffer which is a bad thing.
One way to accomplish what you want is to patch the org-link--open-elisp
function to bind message-log-max
to nil temporarily (as Marco Wahl suggests in his answer), but my suggestion would be to write a new function for this, which is an exact copy of org-link--open-elisp
except that it binds message-log-max
to nil
before calling message
:
(defun org-link--open-elisp-silent (path)
"Open a \"elisp-silent\" type link.
PATH is the sexp to evaluate, as a string."
(if (or (and (org-string-nw-p org-link-elisp-skip-confirm-regexp)
(string-match-p org-link-elisp-skip-confirm-regexp path))
(not org-link-elisp-confirm-function)
(funcall org-link-elisp-confirm-function
(format "Execute %S as Elisp? "
(org-add-props path nil 'face 'org-warning))))
(let ((message-log-max nil))
(message "%s => %s" path
(if (eq ?\( (string-to-char path))
(eval (read path))
(call-interactively (read path)))))
(user-error "Abort")))
You can then add a new link type "elisp-silent" that is handled by this function:
(org-link-set-parameters "elisp-silent" :follow #'org-link--open-elisp-silent)
Now [[elisp:(func)][verbose]]
works as before and [[elisp-silent:(func)][silent]]
works the same way but avoids writing to the *Messages*
buffer.
This technique of binding a variable around a function call is general and well-worth understanding if you are going to be doing elisp programming.