inserting the date in a buffer

inserting the date in a buffer

Post by Bill Cas » Mon, 04 Jul 2005 09:49:11


Hi;

Is there command, or a function, or a way to create a function that will
insert the current date into a buffer?

I particularly want to record dates of creation and changes etc. in my
programs and scripts. I had a nice little function in XEmacs I used.


;;; insert date in buffer
(defun insert-date ()
"Insert date at the current cursor postion in the active buffer."
(interactive)
(insert (format-time-string " %b %d %y")" William Case"))

Regards Bill
 
 
 

inserting the date in a buffer

Post by Flatma » Mon, 04 Jul 2005 19:36:49


|
| Hi;
|
| Is there command, or a function, or a way to create a function that will
| insert the current date into a buffer?
|
| I particularly want to record dates of creation and changes etc. in my
| programs and scripts. I had a nice little function in XEmacs I used.
|
|
| ;;; insert date in buffer
| (defun insert-date ()
| "Insert date at the current cursor postion in the active buffer."
| (interactive)
| (insert (format-time-string " %b %d %y")" William Case"))
|
| Regards Bill


I've this in my .emacs
it puts this in whatever buffer
**EC 2005-07-03 12:36 -
^^ are my initials


(defun insert-date-and-time ()
"Insert the date and time into the current buffer."
(interactive)
(insert (format-time-string "**EC %Y-%m-%d %H:%M - " (current-time))))

;; bound it to a key combination
(global-set-key (kbd "<f5> d") 'insert-date-and-time)


hope this helped
Erik

 
 
 

inserting the date in a buffer

Post by Peter Brei » Mon, 04 Jul 2005 23:08:15

Bill Case schrieb:

I have the following in my .emacs. It inserts a time stamp after
creating a new buffer (asks before) and updates modification time at
each saving of the buffer.

----------------8<----------------8<----------------

(add-hook 'find-file-hooks 'auto-insert)
(require 'time-stamp)
(add-hook 'write-file-hooks 'time-stamp)
(set 'time-stamp-active t)
;; this is the format of modification time
(set 'time-stamp-format "%:d.%:m.%:y %02H:%02M:%02S %f")

(defun brf-make-kopf-string (AUF MARK ZU)
"'MARK' is the comment sign at the beginning of a line incl. evtl.
Blanks. 'AUF' is the opening comment sign (eg. '(*' for Pascal) and
'ZU' the closing one."
(concat AUF "Created at: "
(format-time-string "%d.%m.%Y %H:%M:%S %Z") "\n"
MARK "by " (user-full-name) " on " (system-name) "\n"
MARK "Last modification:\n"
MARK " Time-stamp: <>\n" ZU "\n"))

;; this is a list of time-stamps for different modes I frequently use:
(setq auto-insert-alist '(
(("\\.\\(tex\\|sty\\)\\'" .
"LaTeX-Kommentar") . (insert (brf-make-kopf-string "% " "% " "")))
(("\\.\\([Hh]\\|hh\\|hpp\\|[Cc]\\|cc\\|cpp\\|cxx\\|m\\|java\\|pov\\)\\'" .
"C-Kommentar") . (insert (brf-make-kopf-string "// " "// " "")))
(("\\.pas\\'" .
"Pascal-Kommentar") . (insert (brf-make-kopf-string "(* " " * " " *)")))
(("[Mm]akefile$" . "Makefile-Kommentar") .
(insert (brf-make-kopf-string "# " "# " "")))
(("\\.*\\'" .
"Shell/Perl-Kommentar") .
(concat "#!/bin/bash\n#!/usr/bin/perl -w\n"
(brf-make-kopf-string "# " "# " "")))))

;; with this function you can add a timestamp-template to a buffer.
;; which hasn't one yet. It always uses *** comment-signs, but
;; this doesn't matter, because you may change them by hand. The
;; only thing which is really needed is "Time-stamp" folowed by the
;; angle brackets in one of the first four lines of the buffer,
;; where the new modification time will go.

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

----------------8<----------------8<----------------

Time formats are german, so you might want to change them

Gruss Peter
--
==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==
Peter Breitfeld, Bad Saulgau, Germany -- http://www.yqcomputer.com/
 
 
 

inserting the date in a buffer

Post by Alice Corb » Wed, 06 Jul 2005 00:28:31


I have:

(global-set-key [f7] 'enter-date)

(defun enter-date nil
"Enter today's date at point."
(interactive)
(shell-command "date '+&%B %d, %Y'" 1))

It might only work on Unixes, though.

Ali
 
 
 

inserting the date in a buffer

Post by Chris McMa » Wed, 06 Jul 2005 02:32:26

I've had these for a while.

(defvar insert-time-format "%H:%M"
"*Format for \\[insert-time] (c-h f 'format-time-string' for info on how to format).")

(defvar insert-date-format "%d %b %Y"
"*Format for \\[insert-date] (c-h f 'format-time-string' for info on how to format).")

(defun insert-time ()
"Insert the current time according to the variable \"insert-time-format\"."
(interactive "*")
(insert (concat (format-time-string insert-time-format (current-time)) " "))
)

(defun insert-date ()
"Insert the current date according to the variable \"insert-date-format\"."
(interactive "*")
(insert (concat (format-time-string insert-date-format (current-time))" "))
)

(defun insert-date-time ()
"Insert the current date according to the variable \"insert-date-format\", then a space, then the current time according to the variable \"insert-time-format\"."
(interactive "*")
(progn
(insert-date)
(insert " ")
(insert-time))
)

- Chris

Alice Corbin < XXXX@XXXXX.COM > writes:



--
(. .)
=ooO=(_)=Ooo========================
Chris McMahan | cmcmahan-at-one.net
====================================