emacs-devel
[Top][All Lists]
Advanced

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

Re: uptime.el


From: Juri Linkov
Subject: Re: uptime.el
Date: Sun, 23 Dec 2007 19:48:05 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.50 (gnu/linux)

> What do people think of this?  (The patch in startup.el should be done
> differently.)

This looks like a good fit to time.el with `display-uptime', no?

> Message-ID: <address@hidden>
> Date: Tue, 18 Dec 2007 00:01:18 +0100
> From: "Francesc Rocher" <address@hidden>
> To: "Richard M. Stallman" <address@hidden>
> 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 <address@hidden>
> ;; 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

-- 
Juri Linkov
http://www.jurta.org/emacs/




reply via email to

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