From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jim Diamond Newsgroups: gmane.emacs.help Subject: Re: Insert date and Time Date: Fri, 5 Mar 2010 11:06:06 -0400 Organization: A noiseless patient Spider Message-ID: References: <27714370.post@talk.nabble.com> <871vg35d7c.fsf@siart.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1273052980 15752 80.91.229.12 (5 May 2010 09:49:40 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 5 May 2010 09:49:40 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed May 05 11:49:38 2010 connect(): No such file or directory Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1O9bEX-00067F-JQ for geh-help-gnu-emacs@m.gmane.org; Wed, 05 May 2010 11:49:37 +0200 Original-Received: from localhost ([127.0.0.1]:32973 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9bEU-0001kU-1I for geh-help-gnu-emacs@m.gmane.org; Wed, 05 May 2010 05:49:34 -0400 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!news2.euro.net!news.mixmin.net!feeder.eternal-september.org!eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 44 Injection-Date: Fri, 5 Mar 2010 15:06:08 +0000 (UTC) Injection-Info: feeder.eternal-september.org; posting-host="gXVQO+xAw1VuzT2mIjc5jQ"; logging-data="25550"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/+rvexwq0qha66zDE62sUI" User-Agent: slrn/0.9.9p1 (Linux) Cancel-Lock: sha1:lsJSz9i/mp8hCJL2L01HjI40l5U= Original-Xref: usenet.stanford.edu gnu.emacs.help:177365 X-Mailman-Approved-At: Tue, 04 May 2010 16:45:11 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:73332 Archived-At: On 2010-03-02 at 06:36 AST, Andreas Röhler wrote: > Uwe Siart wrote: >> Tim Visher 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