emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-uptime - insert text with C-u [patch]


From: Adam Sjøgren
Subject: emacs-uptime - insert text with C-u [patch]
Date: Thu, 25 Dec 2014 19:35:44 +0100
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.4 (gnu/linux)

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    address@hidden
  and read a book."




reply via email to

[Prev in Thread] Current Thread [Next in Thread]