2

Ctrl-s, isearch-forward is not appealing to me and so, i wrote a wrapper around it to search from the beginning of the buffer always.

(defun sk-isearch-forward (original)
  (interactive "sEnter search string:  ")
  (save-excursion
    (beginning-of-buffer)
    (isearch-forward original)))

Now, i am seeing two issues:::

1) M-x sk-isearch-forward goes to the beginning of the buffer but never returns to the original cursor position. save-excursion is added to take care of this but it is failing me

2) it is not highlighting any of the matching words in the current buffer.

Is isearch-forward not the right function for this job?

I always search for a word, no regexes and the search, i prefer to start from the beginning. How can i do this?

Saravana
  • 2,071
  • 13
  • 32

1 Answers1

3

Just remove the argument, i.e.

(defun sk-isearch-forward () 
  (interactive)
  (save-excursion 
    (goto-char (point-min))
    (isearch-forward)))
Jordon Biondo
  • 12,455
  • 2
  • 43
  • 62
Name
  • 7,849
  • 4
  • 41
  • 87
  • 2
    Thanks @lawlist I modified it. The OP wants to return to the original cursor position as stated in the question, so save-excursion seems to be the right choice in this situation. – Name Aug 05 '15 at 05:30
  • how is (beginning-of-buffer) different from (goto-char (point-min))? – Saravana Aug 05 '15 at 08:33
  • @MadhavanKumar Check out the docstring of beginning-of-buffer by using C-h f to learn that. – Kaushal Modi Aug 05 '15 at 10:59
  • 1
    Reproducing the relevant section of beginning-of-buffer's docstring for the benefit of others - Don't use this (beginning-of-buffer) command in Lisp programs! (goto-char (point-min)) is faster) – Saravana Aug 05 '15 at 13:07