In an Emacs Lisp function, I would like to insert some text at point or - if the region is active - overwrite it with such text. How to do it?
For Emacs setting:
(delete-selection-mode t) ; delete seleted text when typing
For lisp code, add following line before insert:
(if (region-active-p) (delete-region (region-beginning) (region-end)))