[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Insert date and Time
From: |
David Rogoff |
Subject: |
Re: Insert date and Time |
Date: |
Thu, 25 Feb 2010 11:20:29 -0800 |
User-agent: |
Unison/2.0.4 |
On 2010-02-25 06:50:34 -0800, Pascal J. Bourguignon said:
Tugello <kompy01@yahoo.it> writes:
Hello,
good morning to all,I'm newbie with emacs
my question is about how to insert current date and time, using a short key
combination instead to write they completely .
someone ave any suggestion ?
thanks in advance
I type: C-u M-! date RET
A purely emacs lisp alternative would be:
M-: (insert (current-time-string)) RET
Of course, if you have to do it often, you can do:
(defun insert-timestamp ()
(interactive)
(insert (current-time-string)))
(global-set-key (kbd "<f8>") 'insert-timestamp)
so that you only have to type F8 to insert the timestamp.
Here's a couple of versions I use with some formatting and chioce of
just date or date and time:
(defun insert-date ()
"Insert current date at point, and newline if point is at beginning of line."
(interactive)
(if (prog1 (bolp)
(let ((time (current-time-string)))
(insert (substring time 4 11) (substring time 20 24)))
)
;; insert newline if point was at beginning of line
(insert ?\n))
)
;; output looks like this: Feb 25 2010
;; (global-set-key '[(meta f12)] 'insert-date)
(defun insert-date-and-time ()
"Insert current date and time at point, and newline if point is at
beginning of line."
(interactive)
(if (prog1 (bolp)
(let ((time (current-time-string)))
(insert (substring time 4 11) (substring time 20 24)
(substring time 10 19) ) )
)
;; insert newline if point was at beginning of line
(insert ?\n))
)
(global-set-key '[A-home] 'insert-date-and-time)
;; output looks like this: Feb 25 2010 11:05:43