* Re: Insert date and Time
[not found] <mailman.1861.1267108056.14305.help-gnu-emacs@gnu.org>
@ 2010-02-25 14:50 ` Pascal J. Bourguignon
2010-02-25 19:20 ` David Rogoff
2010-02-25 22:23 ` Tim X
2010-02-25 22:26 ` B. T. Raven
2 siblings, 1 reply; 14+ messages in thread
From: Pascal J. Bourguignon @ 2010-02-25 14:50 UTC (permalink / raw)
To: help-gnu-emacs
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.
--
__Pascal Bourguignon__
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Insert date and Time
2010-02-25 14:50 ` Insert date and Time Pascal J. Bourguignon
@ 2010-02-25 19:20 ` David Rogoff
0 siblings, 0 replies; 14+ messages in thread
From: David Rogoff @ 2010-02-25 19:20 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Insert date and Time
[not found] <mailman.1861.1267108056.14305.help-gnu-emacs@gnu.org>
2010-02-25 14:50 ` Insert date and Time Pascal J. Bourguignon
@ 2010-02-25 22:23 ` Tim X
2010-02-25 22:26 ` B. T. Raven
2 siblings, 0 replies; 14+ messages in thread
From: Tim X @ 2010-02-25 22:23 UTC (permalink / raw)
To: help-gnu-emacs
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
Have a look at the commentry section of timestamp.el. It shows how this
can be done.
Tim
--
tcross (at) rapttech dot com dot au
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Insert date and Time
[not found] <mailman.1861.1267108056.14305.help-gnu-emacs@gnu.org>
2010-02-25 14:50 ` Insert date and Time Pascal J. Bourguignon
2010-02-25 22:23 ` Tim X
@ 2010-02-25 22:26 ` B. T. Raven
2 siblings, 0 replies; 14+ messages in thread
From: B. T. Raven @ 2010-02-25 22:26 UTC (permalink / raw)
To: help-gnu-emacs
Tugello wrote:
> 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
Also, if you need only one time-stamp per file and it's acceptable to
have this time stamp at the top of the buffer, you can put
(add-hook 'write-file-hooks 'time-stamp)
into the .emacs and then the line (or similar)
;; Time-stamp: "2010-02-19 12:15:41 userloginname"
near the top every file you want time-stamped.
The string part is formatted per variable 'time-stamp-format.
Every time the file is saved this commented line will be updated.
Ed
^ permalink raw reply [flat|nested] 14+ messages in thread
* Insert date and Time
@ 2010-02-25 8:29 Tugello
2010-02-25 14:41 ` Tim Visher
` (3 more replies)
0 siblings, 4 replies; 14+ messages in thread
From: Tugello @ 2010-02-25 8:29 UTC (permalink / raw)
To: Help-gnu-emacs
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
--
View this message in context: http://old.nabble.com/Insert-date-and-Time-tp27714370p27714370.html
Sent from the Emacs - Help mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Insert date and Time
2010-02-25 8:29 Tugello
@ 2010-02-25 14:41 ` Tim Visher
2010-02-25 14:49 ` Kevin Rodgers
` (2 subsequent siblings)
3 siblings, 0 replies; 14+ messages in thread
From: Tim Visher @ 2010-02-25 14:41 UTC (permalink / raw)
To: Tugello; +Cc: Help-gnu-emacs
On Thu, Feb 25, 2010 at 3:29 AM, Tugello <kompy01@yahoo.it> wrote:
> 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 use this function to insert a time stamp at point:
(defun insert-time-stamp ()
"Inserts a time stamp 'YYYY-MM-DD HH:MM AM/PM'"
(interactive)
(insert (format-time-string "%Y-%m-%d - %I:%M %p")))
I just call that via `M-x insert-time-stamp` unless a higher level
function calls it. You could call it with a short cut though with
something like
(global-set-key (kbd "<f12>") 'insert-time-stamp)
if you wanted.
You'll need to evaluate those in your scratch buffer to get them in
the current emacs session. Paste them in and then `M-x eval-buffer`.
If you want them in all emacs sessions, put them in your .emacs file.
`C-h r m Init File RET`. Also, [Yegge's .emacs
file](http://steve.yegge.googlepages.com/my-dot-emacs-file) is worth a
read.
Hope that helps.
--
In Christ,
Timmy V.
http://burningones.com/
http://five.sentenc.es/ - Spend less time on e-mail
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Insert date and Time
2010-02-25 8:29 Tugello
2010-02-25 14:41 ` Tim Visher
@ 2010-02-25 14:49 ` Kevin Rodgers
2010-02-25 22:52 ` Drew Adams
[not found] ` <mailman.1862.1267108938.14305.help-gnu-emacs@gnu.org>
3 siblings, 0 replies; 14+ messages in thread
From: Kevin Rodgers @ 2010-02-25 14:49 UTC (permalink / raw)
To: help-gnu-emacs
Tugello wrote:
> 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 ?
(defun insert-current-time ()
"Insert the result of `current-time-string' at point."
(interactive)
(insert (current-time-string)))
(global-set-key (kbd "C-c t") 'insert-current-time)
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: Insert date and Time
2010-02-25 8:29 Tugello
2010-02-25 14:41 ` Tim Visher
2010-02-25 14:49 ` Kevin Rodgers
@ 2010-02-25 22:52 ` Drew Adams
2010-02-26 6:26 ` Kevin Rodgers
[not found] ` <mailman.1862.1267108938.14305.help-gnu-emacs@gnu.org>
3 siblings, 1 reply; 14+ messages in thread
From: Drew Adams @ 2010-02-25 22:52 UTC (permalink / raw)
To: 'Tugello', Help-gnu-emacs
http://www.emacswiki.org/emacs/TimeStamp
^ permalink raw reply [flat|nested] 14+ messages in thread
[parent not found: <mailman.1862.1267108938.14305.help-gnu-emacs@gnu.org>]
* Re: Insert date and Time
[not found] ` <mailman.1862.1267108938.14305.help-gnu-emacs@gnu.org>
@ 2010-03-02 8:40 ` Uwe Siart
2010-03-02 10:36 ` Andreas Röhler
[not found] ` <mailman.2134.1267526036.14305.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 14+ messages in thread
From: Uwe Siart @ 2010-03-02 8:40 UTC (permalink / raw)
To: help-gnu-emacs
Tim Visher <tim.visher@gmail.com> writes:
> I use this function to insert a time stamp at point:
>
> (defun insert-time-stamp ()
> "Inserts a time stamp 'YYYY-MM-DD HH:MM AM/PM'"
> (interactive)
> (insert (format-time-string "%Y-%m-%d - %I:%M %p")))
Nice gimmick. To make it perfect I'd like insert-time-stamp to replace
region (if there is a region). How to achieve this? (insert "string")
does not replace region but inserts at point.
--
Uwe
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Insert date and Time
2010-03-02 8:40 ` Uwe Siart
@ 2010-03-02 10:36 ` Andreas Röhler
[not found] ` <mailman.2134.1267526036.14305.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 14+ messages in thread
From: Andreas Röhler @ 2010-03-02 10:36 UTC (permalink / raw)
To: help-gnu-emacs
Uwe Siart wrote:
> Tim Visher <tim.visher@gmail.com> writes:
>
>> I use this function to insert a time stamp at point:
>>
>> (defun insert-time-stamp ()
>> "Inserts a time stamp 'YYYY-MM-DD HH:MM AM/PM'"
>> (interactive)
>> (insert (format-time-string "%Y-%m-%d - %I:%M %p")))
>
> Nice gimmick. To make it perfect I'd like insert-time-stamp to replace
> region (if there is a region). How to achieve this? (insert "string")
> does not replace region but inserts at point.
>
May be that way:
(defun insert-time-stamp ()
"Inserts a time stamp 'YYYY-MM-DD HH:MM AM/PM'"
(interactive "*")
(let ((beg (when (region-active-p)
(region-beginning)))
(end (when
(region-active-p) (region-end))))
(when (and beg end)
(delete-region beg end)))
(insert (format-time-string "%Y-%m-%d - %I:%M %p")))
Andreas
--
https://code.launchpad.net/~a-roehler/python-mode
https://code.launchpad.net/s-x-emacs-werkstatt/
^ permalink raw reply [flat|nested] 14+ messages in thread
[parent not found: <mailman.2134.1267526036.14305.help-gnu-emacs@gnu.org>]
* Re: Insert date and Time
[not found] ` <mailman.2134.1267526036.14305.help-gnu-emacs@gnu.org>
@ 2010-03-02 13:25 ` Uwe Siart
2010-03-05 15:06 ` Jim Diamond
1 sibling, 0 replies; 14+ messages in thread
From: Uwe Siart @ 2010-03-02 13:25 UTC (permalink / raw)
To: help-gnu-emacs
Andreas Röhler <andreas.roehler@easy-emacs.de> writes:
> Uwe Siart wrote:
>> Nice gimmick. To make it perfect I'd like insert-time-stamp to replace
>> region (if there is a region). How to achieve this? (insert "string")
>> does not replace region but inserts at point.
>
> May be that way:
>
> (defun insert-time-stamp ()
> "Inserts a time stamp 'YYYY-MM-DD HH:MM AM/PM'"
> (interactive "*")
> (let ((beg (when (region-active-p)
> (region-beginning)))
> (end (when
> (region-active-p) (region-end))))
> (when (and beg end)
> (delete-region beg end)))
> (insert (format-time-string "%Y-%m-%d - %I:%M %p")))
Quite the thing. Many thanks!
--
Uwe
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Insert date and Time
[not found] ` <mailman.2134.1267526036.14305.help-gnu-emacs@gnu.org>
2010-03-02 13:25 ` Uwe Siart
@ 2010-03-05 15:06 ` Jim Diamond
1 sibling, 0 replies; 14+ messages in thread
From: Jim Diamond @ 2010-03-05 15:06 UTC (permalink / raw)
To: help-gnu-emacs
On 2010-03-02 at 06:36 AST, Andreas Röhler <andreas.roehler@easy-emacs.de> wrote:
> Uwe Siart wrote:
>> Tim Visher <tim.visher@gmail.com> writes:
>>
>>> I use this function to insert a time stamp at point:
>>>
>>> (defun insert-time-stamp ()
>>> "Inserts a time stamp 'YYYY-MM-DD HH:MM AM/PM'"
>>> (interactive)
>>> (insert (format-time-string "%Y-%m-%d - %I:%M %p")))
>>
>> Nice gimmick. To make it perfect I'd like insert-time-stamp to replace
>> region (if there is a region). How to achieve this? (insert "string")
>> does not replace region but inserts at point.
>>
>
> May be that way:
>
> (defun insert-time-stamp ()
> "Inserts a time stamp 'YYYY-MM-DD HH:MM AM/PM'"
> (interactive "*")
> (let ((beg (when (region-active-p)
> (region-beginning)))
> (end (when
> (region-active-p) (region-end))))
> (when (and beg end)
> (delete-region beg end)))
> (insert (format-time-string "%Y-%m-%d - %I:%M %p")))
Andreas,
this seems gratuitously complicated. Is there anything wrong with
(defun insert-time-stamp ()
"Inserts a time stamp 'YYYY-MM-DD HH:MM AM/PM'"
(interactive "*")
(when (region-active-p)
(delete-region (region-beginning) (region-end)))
(insert (format-time-string "%Y-%m-%d - %I:%M %p")))
Sorta curious, since I am no elisp wizard.
Cheers.
Jim
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2010-03-05 15:06 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.1861.1267108056.14305.help-gnu-emacs@gnu.org>
2010-02-25 14:50 ` Insert date and Time Pascal J. Bourguignon
2010-02-25 19:20 ` David Rogoff
2010-02-25 22:23 ` Tim X
2010-02-25 22:26 ` B. T. Raven
2010-02-25 8:29 Tugello
2010-02-25 14:41 ` Tim Visher
2010-02-25 14:49 ` Kevin Rodgers
2010-02-25 22:52 ` Drew Adams
2010-02-26 6:26 ` Kevin Rodgers
2010-02-26 15:02 ` Drew Adams
[not found] ` <mailman.1862.1267108938.14305.help-gnu-emacs@gnu.org>
2010-03-02 8:40 ` Uwe Siart
2010-03-02 10:36 ` Andreas Röhler
[not found] ` <mailman.2134.1267526036.14305.help-gnu-emacs@gnu.org>
2010-03-02 13:25 ` Uwe Siart
2010-03-05 15:06 ` Jim Diamond
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).