From: boyd@phi.cs.fsu.edu (Mickey Boyd)
Newsgroups: comp.emacs
Subject: Modifying search-forward and seach-backward (summary)
Date: 24 Jul 92 16:05:48 GMT
Reply-To: boyd@nu.cs.fsu.edu
Distribution: comp.emacs
Organization: Florida State University Computer Science Department

First, thanks to the many that sent me replies via email.  My cockles warm to
the thought of such friendly netters the world over.

Ok, first of all, I managed to be less than clear about my question.  What 
I wanted to do was extend the functionality of search-forward and 
search-backward to remember the last search string (to be able to easily 
repeat the search).  Many folks pointed out to me that simply repeating the 
command will do it.  True, for isearch-forward and isearch-backward, but NOT
true for plain search-forward and search-backward (hence my problem).  

The two solutions that I liked the best were the following:

##########################################

(defvar my-search-string "")
(defvar this-string "")

(defun my-search-forward () ""
  (interactive)
  (setq this-string (read-string (format "String [%s] : " my-search-string)))
  (if (string-equal this-string "")
      (search-forward my-search-string)
    (progn
      (search-forward this-string)
      (setq my-search-string this-string))))

(defun my-search-backward () ""
  (interactive)
  (setq this-string (read-string (format "String [%s] : " my-search-string)))
  (if (string-equal this-string "")
      (search-backward my-search-string)
    (progn
      (search-backward this-string)
      (setq my-search-string this-string))))

###########################################

And an even cleaner solution:

###########################################

To: Mickey R. Boyd <boyd@nu.cs.fsu.edu>
Subject: Re: Modification to search-forward and search-backward
Date: Fri, 17 Jul 92 15:55:52 D
From: Don Markuson <dmm@tiger1.Prime.COM>


Here's what I do:  avoid using the lower-level internal search-forward/
search-backward functions (which are coded in C), and instead use the
nonincremental-search function defined in isearch.el, thusly:

(defun dmm-search-forward (&optional uncount)
    "Nonincremental forward search string or (with numeric argument) regexp"
    (interactive "P")

    (nonincremental-search t uncount)
)

(defun dmm-search-backward (&optional uncount)
    "Nonincremental reverse search string or (with numeric argument) regexp"
    (interactive "P")

    (nonincremental-search nil uncount)
)

and these are the functions to which I bind ^S and ^R:

(global-set-key     "\^R"           'dmm-search-backward)
(global-set-key     "\^S"           'dmm-search-forward)

Typing ^S-Return does a search-again quite nicely.

Hope this helps!

..Don Markuson
  Prime Computer, Inc.
  dmm@tiger1.prime.com

#####################################

Again, thanks to all that responded.


--
   ----------------------------------+--------------------------------------
             Mickey R. Boyd          |  "What a terrible thing to have lost
          FSU Computer Science       |    one's mind.  Or not to have a  
        Technical Support Group      |    mind at all.  How true that is."
       email:  boyd@nu.cs.fsu.edu    |       -- Vice President Dan Quayle
   ----------------------------------+--------------------------------------