1

Is there a command to display and automatically copy to clipboard both the current version of Emacs and the current version of org-mode?

Drew
  • 77,472
  • 10
  • 114
  • 243
incandescentman
  • 4,221
  • 20
  • 53
  • 1
    That's pretty idiosyncratic, so you'll probably need to write it yourself. What have you tried? – Dan Apr 22 '17 at 18:22
  • Here's what I have. Doesn't work.

    (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.

    – incandescentman Apr 22 '17 at 18:37
  • @incandescentman it looks like you're confusing between concat and format. – npostavs Apr 22 '17 at 19:05
  • @npostavs When I change it to concat I get edebug-read-sexp: Lisp nesting exceeds ‘max-lisp-eval-depth’ – incandescentman Apr 23 '17 at 05:47
  • hmm, I get error: "Not enough arguments for format string", and after fixing the message call, Wrong number of arguments for the clipboard-kill-ring-save call. I think you want (let ((select-enable-clipboard t)) (kill-new msg)). – npostavs Apr 23 '17 at 13:02
  • @npostavs Like this? (defun display-and-copy-version-info () "Echo the current version of Spacemacs, Emacs, and org-mode, and copy it." (interactive) (let ((msg (concat "Spacemacs v.%s" spacemacs-version "Emacs" emacs-version "org-mode" org-version))) (message msg) (let ((select-enable-clipboard t)) (kill-new msg)) )) – incandescentman Apr 23 '17 at 21:33
  • @incandescentman does that work for you? I need (message %s msg) to run without error. – npostavs Apr 23 '17 at 22:13
  • @npostavs No, I still get let: Not enough arguments for format string – incandescentman Apr 23 '17 at 22:49
  • 2
    Not directly related, but may of interest in this context: the functions emacs-version and org-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 is C-u M-x emacs-version and C-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. – NickD Apr 24 '17 at 14:31

1 Answers1

1

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)))
JeanPierre
  • 7,465
  • 1
  • 20
  • 39