From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: asjo@koldfront.dk (Adam =?utf-8?Q?Sj=C3=B8gren?=) Newsgroups: gmane.emacs.devel Subject: emacs-uptime - insert text with C-u [patch] Date: Thu, 25 Dec 2014 19:35:44 +0100 Organization: koldfront - analysis & revolution, Copenhagen, Denmark Message-ID: <871tnnh91b.fsf@topper.koldfront.dk> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1419532589 11079 80.91.229.3 (25 Dec 2014 18:36:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 25 Dec 2014 18:36:29 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Dec 25 19:36:20 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Y4DGj-0006xr-D1 for ged-emacs-devel@m.gmane.org; Thu, 25 Dec 2014 19:36:17 +0100 Original-Received: from localhost ([::1]:51582 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y4DGi-0005Ul-PS for ged-emacs-devel@m.gmane.org; Thu, 25 Dec 2014 13:36:16 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51201) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y4DGW-0005Uf-BR for emacs-devel@gnu.org; Thu, 25 Dec 2014 13:36:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y4DGS-0001J9-7H for emacs-devel@gnu.org; Thu, 25 Dec 2014 13:36:04 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:60580) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y4DGS-0001J3-0E for emacs-devel@gnu.org; Thu, 25 Dec 2014 13:36:00 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Y4DGP-0006sR-OM for emacs-devel@gnu.org; Thu, 25 Dec 2014 19:35:57 +0100 Original-Received: from 2505ds5-by.0.fullrate.dk ([89.150.142.116]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 25 Dec 2014 19:35:57 +0100 Original-Received: from asjo by 2505ds5-by.0.fullrate.dk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 25 Dec 2014 19:35:57 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 53 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 2505ds5-by.0.fullrate.dk OpenPGP: id=49D0746121BDE416; url=http://asjo.koldfront.dk/gpg.asc X-Face: )qY&CseJ?.:=8F#^~GcSA?F=9eu'{KAFfL1C3/A&:nE?PW\i65"ba0NS)97, Q(^@xk}n4Ou rPuR#V8I(J_@~H($[ym:`K_+]*kjvW>xH5jbgLBVFGXY:(#4P>zVBklLbdL&XxL\M)%T}3S/IS9lMJ ^St'=VZBR List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:180667 Archived-At: 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."