[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: emacs-uptime - insert text with C-u [patch]
From: |
Adam Sjøgren |
Subject: |
Re: emacs-uptime - insert text with C-u [patch] |
Date: |
Tue, 10 Feb 2015 15:51:10 +0100 |
User-agent: |
Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.4 (gnu/linux) |
Stephen writes:
>>> address@hidden (Adam Sjøgren) writes:
>>>> I don't know what the idiom is to distinguish a prefix argument from
>>>> an optional one[...]
> In this case the argument list is (format insert), and you probably
> want a interactive spec of "iP".
Thanks for the hints; here is a nicer patch, and a ChangeLog entry:
2015-02-10 Adam Sjøgren <address@hidden>
* time.el (emacs-uptime): insert at point when called with
prefix.
--- time.el.orig 2015-02-10 15:42:48.472482974 +0100
+++ time.el 2015-02-10 15:45:27.743592919 +0100
@@ -571,18 +571,22 @@
(cancel-timer elt)))))))
;;;###autoload
-(defun emacs-uptime (&optional format)
+(defun emacs-uptime (&optional format here)
"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 the optional argument HERE is non-nil, insert string at
+point."
+ (interactive "i\nP")
(let ((str
(format-seconds (or 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 here
+ (insert str)
+ (if (called-interactively-p 'interactive)
+ (message "%s" str)
+ str))))
;;;###autoload
(defun emacs-init-time ()
--
"[T]he subject matter is so attractive that only Adam Sjøgren
extravagant incompetence could make it dull." address@hidden
- Re: emacs-uptime - insert text with C-u [patch],
Adam Sjøgren <=