Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Timestamps

6 views
Skip to first unread message

Kauser

unread,
Sep 4, 2002, 6:49:50 PM9/4/02
to
Hello everyone:

Is there any way I could get a file's timestamp using lisp code.
Timestamp as in the last time the file was modified. I probably need
to call some OS routine from lisp. And I need to do this for Windows,
Linux and Unix.

Any ideas?

Thanks,
Kauser

Erik Naggum

unread,
Sep 4, 2002, 7:15:02 PM9/4/02
to
[ Not cross-posting to comp.emacs ]

* k.k...@utoronto.ca (Kauser)


| Is there any way I could get a file's timestamp using lisp code. Timestamp
| as in the last time the file was modified. I probably need to call some OS
| routine from lisp. And I need to do this for Windows, Linux and Unix.

Do you want the file's write date?

--
Erik Naggum, Oslo, Norway

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.

Peter Breitfeld

unread,
Sep 5, 2002, 8:10:43 AM9/5/02
to
Kauser schrieb:

I use the following in my .emacs to create timestamps (hope you can
understand the German comments):

----------------8<----------------8<----------------
;; time-stamps in Buffer aktualisieren:
(add-hook 'find-file-hooks 'auto-insert)
(require 'time-stamp)
(add-hook 'write-file-hooks 'time-stamp)
(set 'time-stamp-active t)
(set 'time-stamp-format "%3a %2d.%3b %4y %02H:%02M:%02S %f")

(defun make-kopf-string (auf mark zu)
"'mark' ist das Kommentarzeichen am Anfang der Zeile incl. evtl.
Blanks. 'auf' ist das öffnende Kommentarzeichen (zB '(*' bei Pascal) und
'zu' das schließende."
(concat auf "Erzeugt am: "
(format-time-string "%a %d.%b %Y %H:%M:%S %Z") "\n"
mark "von " (user-full-name) " auf " (system-name) "\n"
mark "Zuletzt geändert:\n"
mark " Time-stamp: <>\n" zu "\n"))

(setq auto-insert-alist '(
(("\\.\\(tex\\|sty\\)\\'" .
"LaTeX-Kommentar") . (insert (make-kopf-string "% " "% " "")))
(("\\.\\([Hh]\\|hh\\|hpp\\|[Cc]\\|cc\\|cpp\\|cxx\\|java\\|pov\\)\\'" .
"C-Kommentar") . (insert (make-kopf-string "// " "// " "")))
(("\\.pas\\'" .
"Pascal-Kommentar") . (insert (make-kopf-string "(* " " * " " *)")))
(("Makefile$" . "Makefile-Kommentar") .
(insert (make-kopf-string "# " "# " "")))
(("\\.*\\'" .
"Shell/Perl-Kommentar") .
(concat "#!/bin/bash\n#!/usr/bin/perl -w\n"
(make-kopf-string "# " "# " "")))))

(defun insert-time-stamp ()
(interactive)
(insert (make-kopf-string "% " "% " "")))
----------------8<----------------8<----------------


Now, whenever I open a new file, I get asked if I want to insert a
time-stamp. If I agree the time-stamp is inserted and updated each time
I write the file.


Gruß Peter
--
=--=--=--=--=--=--=--=--=--=--=--=--=--= http://home.t-online.de/home/phbrf
Peter Breitfeld, Bad Saulgau, Germany Meinen GnuPG/PGP-5x Key gibts dort

Matthieu Moy

unread,
Sep 5, 2002, 9:12:39 AM9/5/02
to
k.k...@utoronto.ca (Kauser) writes:

> Hello everyone:
>
> Is there any way I could get a file's timestamp using lisp code.

Yes.

> Timestamp as in the last time the file was modified. I probably need
> to call some OS routine from lisp. And I need to do this for Windows,
> Linux and Unix.

Using only lisp, it will be portable.

M-x apropos

is your friend in those cases. (search for a regexp)

Here, the function is file-attributes.

,----[ C-h f file-attributes RET ]
| file-attributes is a built-in function.
| (file-attributes FILENAME)
|
| Return a list of attributes of file FILENAME.
| Value is nil if specified file cannot be opened.
|
| [...]
|
| 4. Last access time, as a list of two integers. First integer has
| high-order 16 bits of time, second has low 16 bits.
| 5. Last modification time, likewise.
|
| [...]
|
`----

--
Matthieu

0 new messages