Emacs Lisp: Text Editing Functions
Here's the most used functions related to text editing.
Insert Text
;; insert string at current cursor position (insert "sun and moon")
Delete Text
delete-char
-
Delete n characters to the right. Use negative number to delete to the left.
;; delete 9 chars starting at cursor pos (delete-char 9)
delete-region
-
Delete text btween 2 positions.
Often used with
point-min
for getting the minimal position in a buffer. because minimal position is not 1, whennarrow-to-region
is in effect. And usepoint-max
for getting buffer max position.;; deleting text btween positions 59 and 896 (delete-region 59 896)
erase-buffer
-
Delete all next in buffer, ignores
narrow-to-region
.(erase-buffer)
delete-and-extract-region
-
Delete between 2 positions and return the deleted text.
(delete-and-extract-region 3 20)