unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
To: help-gnu-emacs@gnu.org
Subject: Re: Insert date and Time
Date: Tue, 02 Mar 2010 11:36:03 +0100	[thread overview]
Message-ID: <4B8CEA13.8050907@easy-emacs.de> (raw)
In-Reply-To: <871vg35d7c.fsf@siart.de>

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/





  reply	other threads:[~2010-03-02 10:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-25  8:29 Insert date and Time 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 [this message]
     [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
     [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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B8CEA13.8050907@easy-emacs.de \
    --to=andreas.roehler@easy-emacs.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).