Is there a command to display and automatically copy to clipboard both the current version of Emacs and the current version of org-mode?
1 Answer
I suggest you take a look at the doc string for function format
, with C-h f format
(M-x describe-function
). It is similar to the C language printf
, if you know that. The doc string for message includes:
(message FORMAT-STRING &rest ARGS)
Display a message at the bottom of the screen. The message also goes into the ‘Messages’ buffer, if ‘message-log-max’ is non-nil. (In keyboard macros, that’s all it does.) Return the message.
Also, the docstring for clipboard-kill-ring-save
shows you don't call it with the proper arguments, and in fact is to be used when copying some text from a buffer, not from a string.
Searching for "kill-ring" in the index of the info elisp manual can bring to the section Low-Level Kill Ring where the function kill-new
is described. Since message
returns the displayed string, we can feed it directly to kill-new
.
(defun display-and-copy-version-info ()
"Echo the current version of Spacemacs, Emacs, and org-mode, and copy it."
(interactive)
(kill-new
(message "Spacemacs v.%s Emacs %s org-mode %s"
spacemacs-version emacs-version org-version)))
-
You should use
(message "%s" msg)
to be safe (probably none of the versions will include a%
so it doesn't really matter, but still...)– npostavsApr 24, 2017 at 14:19 -
(defun display-and-copy-version-info () "Echo the current version of Spacemacs, Emacs, and org-mode, and copy it." (interactive) (let ((msg (format "Spacemacs v.%s" spacemacs-version "Emacs" emacs-version "org-mode" org-version))) (message msg) (clipboard-kill-ring-save msg)))
I feel like it would be useful to anyone who needs to submit issues for any package that's org-mode related.concat
andformat
.edebug-read-sexp: Lisp nesting exceeds ‘max-lisp-eval-depth’
emacs-version
andorg-version
take a prefix argument which says "put the output in this buffer". So if you are composing your bug report in emacs, all you have to do isC-u M-x emacs-version
andC-u M-x org-version
and you are done. You can also wrap the two calls into a single function of course, or bind them to keys.