Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if current Emacs buffer contains a string

I have a buffer open in emacs. I want a function that will return t if the current buffer contains the string, otherwise it returns nil.

(defun buffer-contains-substring (string)
    ...
)
like image 722
John Avatar asked Jun 13 '10 23:06

John


1 Answers

This is careful to not change where you are, or damage any match data.

(defun buffer-contains-substring (string)
  (save-excursion
    (save-match-data
      (goto-char (point-min))
      (search-forward string nil t))))
like image 135
Eli Barzilay Avatar answered Nov 13 '22 01:11

Eli Barzilay