Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
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)))
Required, but never shown