help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: can a command specify overwrite selection behavior?


From: Xah Lee
Subject: Re: can a command specify overwrite selection behavior?
Date: Wed, 08 Dec 2010 15:26:51 -0000
User-agent: G2/1.0

On Aug 31, 10:33 pm, Xah Lee <xah...@gmail.com> wrote:
> i have this code that inserts date.
>
> (defun insert-date ()
>   "Insert current date."
>   (interactive)
>   (insert (format-time-string "%Y-%m-%d"))
>   )
> (put 'insert-date 'delete-selection t)
>
> the last line is to make sure that if i have a text selection, just
> overwrite it.
>
> but it doesn't work.
> ...

work around:

(defun insert-date ()
  "Insert current date."
  (interactive)
  (when (region-active-p)
    (delete-region (region-beginning) (region-end) )
    )
  (insert (format-time-string "%Y-%m-%d"))
  )


reply via email to

[Prev in Thread] Current Thread [Next in Thread]