If I want to delete everything in a buffer with elisp, how do I do that?
3 Answers
Have you tried erase-buffer
?
erase-buffer is an interactive built-in function in `C source code'.
(erase-buffer)
Delete the entire contents of the current buffer.
Any narrowing restriction in effect (see `narrow-to-region') is removed,
so the buffer is truly empty after this.
How to find such a function? M-x apropos buffer erase
-
1There are a few exceptions, e.g., overlay objects are not deleted, and there may be some other stuff I am not familiar with that continues to be present after
erase-buffer
is called.– lawlistOct 19, 2015 at 21:13 -
1Yes, the question is not very precise wrt "everything" and "in" the buffer. If you want to get rid of everything associated with the buffer, then
kill-buffer
is your friend.– DrewOct 19, 2015 at 21:54
There's also this answer:
C-x h + del
key clears the buffer
Note: This requires transient-mark-mode
to be enabled (which it is by default).