I want to know how do you use Emacs lisp to check the content of the current buffer, specially to know if certain string exists within the current buffer.
Asked
Active
Viewed 1,047 times
2 Answers
0
You can also do this on a way which probably looks familiar from other languages using s.el:
(with-current-buffer "some_buffer"
(s-contains? "some string"
(buffer-substring-no-properties (point-min) (point-max))))

yujaiyu
- 896
- 8
- 22
-
6Emacs is very good at acting directly on buffer contents. Copying portions of the buffer (let alone the entire contents, as in this case) in order to perform string-based operations is generally not the best approach. – phils Mar 19 '16 at 22:14
-
1I second @phils's recommendation, pointing out that it's very inefficient, especially in this case, since it copies the whole buffer's content. – Stefan Mar 19 '16 at 22:50
-
Yes, you're right. This is not the best approach, I recommend accepted answer over this one. My idea was to point to s.el. @phils – yujaiyu Mar 20 '16 at 00:45
re-search-forward
, for the added flexibility of specifying a regexp rather than a mere substring. – Stefan Mar 19 '16 at 22:52