From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Richard Stallman Newsgroups: gmane.emacs.devel Subject: uptime.el Date: Wed, 19 Dec 2007 05:12:31 -0500 Message-ID: Reply-To: rms@gnu.org NNTP-Posting-Host: lo.gmane.org Content-Type: text/plain; charset=ISO-8859-15 X-Trace: ger.gmane.org 1198059245 30930 80.91.229.12 (19 Dec 2007 10:14:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 19 Dec 2007 10:14:05 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Dec 19 11:14:18 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1J4vwO-0007ZG-8D for ged-emacs-devel@m.gmane.org; Wed, 19 Dec 2007 11:14:16 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J4vw4-0005LX-MS for ged-emacs-devel@m.gmane.org; Wed, 19 Dec 2007 05:13:56 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1J4vul-0003zy-Is for emacs-devel@gnu.org; Wed, 19 Dec 2007 05:12:35 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1J4vuj-0003w2-7i for emacs-devel@gnu.org; Wed, 19 Dec 2007 05:12:33 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J4vuj-0003vf-0C for emacs-devel@gnu.org; Wed, 19 Dec 2007 05:12:33 -0500 Original-Received: from fencepost.gnu.org ([140.186.70.10]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1J4vui-0008I4-LY for emacs-devel@gnu.org; Wed, 19 Dec 2007 05:12:32 -0500 Original-Received: from rms by fencepost.gnu.org with local (Exim 4.60) (envelope-from ) id 1J4vuh-0005Un-UT; Wed, 19 Dec 2007 05:12:32 -0500 X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:85278 Archived-At: What do people think of this? (The patch in startup.el should be done differently.) Message-ID: Date: Tue, 18 Dec 2007 00:01:18 +0100 From: "Francesc Rocher" To: "Richard M. Stallman" Subject: uptime.el MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) Hello, Please consider adding this little piece of elisp code into GNU Emacs: ---8<------ ;;; uptime.el --- tell how long Emacs has been up and running ;; Copyright (C) 2007 Free Software Foundation, Inc. ;; Author: Francesc Rocher ;; Keywords: time, uptime. ;; This file is part of GNU Emacs. ;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; This file provides a couple of functions: `emacs-uptime' tells you how ;; long Emacs has been up and running. `emacs-startup-time' return a string ;; containing the date and time Emacs was started up. ;;; Code: (require 'time-date) ;;;###autoload (defun emacs-uptime (&optional here) "\ Tell how long GNU Emacs has been running. If the optional argument HERE is non-nil, insert string at point." (interactive "P") (let* ((days (time-to-number-of-days (time-since emacs-startup-time))) (hours (* 24 (- days (truncate days)))) (minutes (* 60 (- hours (truncate hours)))) (seconds (* 60 (- minutes (truncate minutes)))) (uptime-string (format "%s, up %s" (format-time-string "%x %T %Z" (current-time)) (format "%s%02d:%02d:%02d" (if (> (truncate days) 0) (format "%d days, " days) "") hours minutes seconds)))) (if here (insert uptime-string) (if (interactive-p) (message "%s" uptime-string) uptime-string)))) ;;;###autoload (defun emacs-startup-time (&optional here format) "\ Return string containing the date and time Emacs was started up. If the optional argument FORMAT is non-nil, it is used to format the string. See `format-time-string' for valid formats. If the optional argument HERE is non-nil, insert string at point." (interactive "P") (let ((time-string (format-time-string (if (stringp format) format "%x %T %Z") emacs-startup-time))) (if here (insert time-string) (if (interactive-p) (message "%s" time-string) time-string)))) (provide 'uptime) ;;; arch-tag: ;;; uptime.el ends here ---8<------ Complemented with this constant definition: diff -u startup.el.~1.470.~ startup.el --- startup.el.~1.470.~ 2007-12-09 12:08:54.000000000 +0100 +++ startup.el 2007-12-17 23:18:01.000000000 +0100 @@ -2243,5 +2243,9 @@ (setq file (replace-match "/" t t file))) file)) +(eval-at-startup + (defconst emacs-startup-time (current-time) + "Time at which GNU Emacs was started up.")) + ;; arch-tag: 7e294698-244d-4758-984b-4047f887a5db ;;; startup.el ends here Best regards, --- Francesc Rocher