views:

83

answers:

1

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)
    ...
)
+7  A: 

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))))
Eli Barzilay
Perfect. Thanks!
John