[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Insert date and Time
From: |
Andreas Röhler |
Subject: |
Re: Insert date and Time |
Date: |
Tue, 02 Mar 2010 11:36:03 +0100 |
User-agent: |
Thunderbird 2.0.0.19 (X11/20081227) |
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/