Sure would be nice to be to easily to insert the current
date, time, or both.
Thanks!
David
> I've looked in emacs' *info*, its list of commands, etc,
> and can find nothing.
C-u M-! date RET
Sun Jan 9 04:29:12 CET 2011
C-u M-: (calendar-current-date) RET
(1 9 2011)
> Sure would be nice to be to easily to insert the current
> date, time, or both.
Then write the command to do so.
Notice how each user will want to insert it in a different format.
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
Apart from what Pascal suggested, you could try these:
(defun insert-current-time ()
(interactive)
(destructuring-bind
(sec min hour day month year dow dst zone)
(decode-time)
(insert (format "%02d:%02d:%02d" hour min sec))))
(defun insert-current-date ()
(interactive)
(let ((days '((0 . Sunday)
(1 . Monday)
(2 . Tuesday)
(3 . Wednesday)
(4 . Thursday)
(5 . Friday)
(6 . Saturday)))
(months '((1 . Jan)
(2 . Feb)
(3 . Mar)
(4 . Apr)
(5 . May)
(6 . Jun)
(7 . Jul)
(8 . Aug)
(9 . Sep)
(10 . Oct)
(11 . Nov)
(12 . Dec))))
(destructuring-bind
(sec min hour day month year dow dst zone)
(decode-time)
(insert (format "%s, %d %s %d"
(rest (assoc dow days))
day
(rest (assoc month months))
year)))))
You could, of course, combine these as:
(defun insert-current-time-date ()
(interactive)
(insert-current-time)
(insert (format " "))
(insert-current-date))
Or whichever way you want them.
P.S. Suggested improvements gladly accepted.
| dkc...@panix.com (David Combs) writes:
|
| | I've looked in emacs' *info*, its list of commands, etc,
| | and can find nothing.
| |
| | Sure would be nice to be to easily to insert the current
| | date, time, or both.
| |
| | Thanks!
| |
| | David
| <Reply elided>
You'll want to do a
(require 'cl)
before using that.
Sorry for the omission.
Stolen from some website:
(defun insert-date (prefix)
"Insert the current date. With prefix-argument, use ISO format. With
two prefix arguments, write out the day and month name. With
three (!) prefix arguments give date and time in ISO Format
and append day and month name in brackets"
(interactive "P")
(let ((format (cond
((not prefix) "%d.%m.%Y")
((equal prefix '(4)) "%Y-%m-%d")
((equal prefix '(16)) "%A, %d. %B %Y")))
(system-time-locale "de_DE"))
(insert (format-time-string format))))
(global-set-key (kbd "C-c d") 'insert-date)
Ciao, Gregor
--
-... --- .-. . -.. ..--.. ...-.-
You forgot Emacs Wiki: http://www.emacswiki.org/.
Just type "insert date" into the search field - voila!
> I've looked in emacs' *info*, its list of commands, etc,
> and can find nothing.
You forgot Emacs Wiki: http://www.emacswiki.org/.
Just type "insert date" into the search field - voila!
THANKS EVERYONE!, for all the different ways of doing it!
David
<http://www.emacswiki.org/emacs/Journal>