all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* emacs-uptime - insert text with C-u [patch]
@ 2014-12-25 18:35 Adam Sjøgren
  2014-12-25 19:53 ` Andreas Schwab
  0 siblings, 1 reply; 7+ messages in thread
From: Adam Sjøgren @ 2014-12-25 18:35 UTC (permalink / raw
  To: emacs-devel

When you want to insert the current Emacs version into a buffer, you go:
C-u M-x emacs-version, and badaboom:

  GNU Emacs 24.4.1 (x86_64-pc-linux-gnu, [...]

It would be cool if emacs-uptime also worked like that. C-u M-x
emacs-uptime, badabing:

  7 hours, 46 minutes, 25 seconds

The following patch tries to make this happen, however I don't know what
the idiom is to distinguish a prefix argument from an optional one, so I
guess there must be a better way:

--- time.el.orig	2014-12-25 19:27:16.166584389 +0100
+++ time.el	2014-12-25 19:26:15.026582109 +0100
@@ -574,15 +574,19 @@
 (defun emacs-uptime (&optional format)
   "Return a string giving the uptime of this instance of Emacs.
 FORMAT is a string to format the result, using `format-seconds'.
-For example, the Unix uptime command format is \"%D, %z%2h:%.2m\"."
-  (interactive)
+For example, the Unix uptime command format is \"%D, %z%2h:%.2m\".
+If called interactively with a prefix argument, insert string at point."
+  (interactive "P")
   (let ((str
-         (format-seconds (or format "%Y, %D, %H, %M, %z%S")
+         (format-seconds (if (stringp format) format
+                           "%Y, %D, %H, %M, %z%S")
                          (float-time
                           (time-subtract (current-time) before-init-time)))))
-    (if (called-interactively-p 'interactive)
-        (message "%s" str)
-      str)))
+    (if (and (not (stringp format)) format)
+        (insert str)
+      (if (called-interactively-p 'interactive)
+          (message "%s" str)
+        str))))
 
 ;;;###autoload
 (defun emacs-init-time ()



  Best regards,

    Adam

-- 
 "I find television very educating. Every time                Adam Sjøgren
  somebody turns on the set, I go into the other room    asjo@koldfront.dk
  and read a book."




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-02-10 15:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-25 18:35 emacs-uptime - insert text with C-u [patch] Adam Sjøgren
2014-12-25 19:53 ` Andreas Schwab
2014-12-25 19:56   ` Adam Sjøgren
2014-12-26  4:54     ` Stephen J. Turnbull
2015-02-10 14:51       ` Adam Sjøgren
2015-02-10 15:18         ` Andreas Schwab
2015-02-10 15:24           ` Adam Sjøgren

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.