If I want to delete everything in a buffer with elisp, how do I do that?
Asked
Active
Viewed 6,681 times
3 Answers
31
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

Drew
- 75,699
- 9
- 109
- 225
-
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. – lawlist Oct 19 '15 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. – Drew Oct 19 '15 at 21:54
-1
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).

Joshua Goldberg
- 133
- 4