From: asjo@koldfront.dk (Adam Sjøgren)
To: emacs-devel@gnu.org
Subject: emacs-uptime - insert text with C-u [patch]
Date: Thu, 25 Dec 2014 19:35:44 +0100 [thread overview]
Message-ID: <871tnnh91b.fsf@topper.koldfront.dk> (raw)
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."
next reply other threads:[~2014-12-25 18:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-25 18:35 Adam Sjøgren [this message]
2014-12-25 19:53 ` emacs-uptime - insert text with C-u [patch] 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871tnnh91b.fsf@topper.koldfront.dk \
--to=asjo@koldfront.dk \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).