[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Insert date and Time
From: |
Jim Diamond |
Subject: |
Re: Insert date and Time |
Date: |
Tue, 04 May 2010 15:41:35 -0000 |
User-agent: |
slrn/0.9.9p1 (Linux) |
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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Insert date and Time,
Jim Diamond <=