1

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?

3

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)))
  • Thank you, but I'm trying to do that from Lisp code. – Elena May 30 '18 at 4:29
  • Sorry, I didn't read your question carefully. I updated my answer, hope it helps. – AhLeung May 30 '18 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.