home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / emacs / 2699 < prev    next >
Encoding:
Text File  |  1992-07-24  |  3.4 KB  |  102 lines

  1. Path: sparky!uunet!paladin.american.edu!darwin.sura.net!tulane!uflorida!mailer.cc.fsu.edu!phi!boyd
  2. From: boyd@phi.cs.fsu.edu (Mickey Boyd)
  3. Newsgroups: comp.emacs
  4. Subject: Modifying search-forward and seach-backward (summary)
  5. Message-ID: <1992Jul19.235634.21730@mailer.cc.fsu.edu>
  6. Date: 24 Jul 92 16:05:48 GMT
  7. Reply-To: boyd@nu.cs.fsu.edu
  8. Distribution: comp.emacs
  9. Organization: Florida State University Computer Science Department
  10. Lines: 90
  11.  
  12. First, thanks to the many that sent me replies via email.  My cockles warm to
  13. the thought of such friendly netters the world over.
  14.  
  15. Ok, first of all, I managed to be less than clear about my question.  What 
  16. I wanted to do was extend the functionality of search-forward and 
  17. search-backward to remember the last search string (to be able to easily 
  18. repeat the search).  Many folks pointed out to me that simply repeating the 
  19. command will do it.  True, for isearch-forward and isearch-backward, but NOT
  20. true for plain search-forward and search-backward (hence my problem).  
  21.  
  22. The two solutions that I liked the best were the following:
  23.  
  24. ##########################################
  25.  
  26. (defvar my-search-string "")
  27. (defvar this-string "")
  28.  
  29. (defun my-search-forward () ""
  30.   (interactive)
  31.   (setq this-string (read-string (format "String [%s] : " my-search-string)))
  32.   (if (string-equal this-string "")
  33.       (search-forward my-search-string)
  34.     (progn
  35.       (search-forward this-string)
  36.       (setq my-search-string this-string))))
  37.  
  38. (defun my-search-backward () ""
  39.   (interactive)
  40.   (setq this-string (read-string (format "String [%s] : " my-search-string)))
  41.   (if (string-equal this-string "")
  42.       (search-backward my-search-string)
  43.     (progn
  44.       (search-backward this-string)
  45.       (setq my-search-string this-string))))
  46.  
  47. ###########################################
  48.  
  49. And an even cleaner solution:
  50.  
  51. ###########################################
  52.  
  53. To: Mickey R. Boyd <boyd@nu.cs.fsu.edu>
  54. Subject: Re: Modification to search-forward and search-backward
  55. Date: Fri, 17 Jul 92 15:55:52 D
  56. From: Don Markuson <dmm@tiger1.Prime.COM>
  57.  
  58.  
  59. Here's what I do:  avoid using the lower-level internal search-forward/
  60. search-backward functions (which are coded in C), and instead use the
  61. nonincremental-search function defined in isearch.el, thusly:
  62.  
  63. (defun dmm-search-forward (&optional uncount)
  64.     "Nonincremental forward search string or (with numeric argument) regexp"
  65.     (interactive "P")
  66.  
  67.     (nonincremental-search t uncount)
  68. )
  69.  
  70. (defun dmm-search-backward (&optional uncount)
  71.     "Nonincremental reverse search string or (with numeric argument) regexp"
  72.     (interactive "P")
  73.  
  74.     (nonincremental-search nil uncount)
  75. )
  76.  
  77. and these are the functions to which I bind ^S and ^R:
  78.  
  79. (global-set-key     "\^R"           'dmm-search-backward)
  80. (global-set-key     "\^S"           'dmm-search-forward)
  81.  
  82. Typing ^S-Return does a search-again quite nicely.
  83.  
  84. Hope this helps!
  85.  
  86. ..Don Markuson
  87.   Prime Computer, Inc.
  88.   dmm@tiger1.prime.com
  89.  
  90. #####################################
  91.  
  92. Again, thanks to all that responded.
  93.  
  94.  
  95. --
  96.    ----------------------------------+--------------------------------------
  97.              Mickey R. Boyd          |  "What a terrible thing to have lost
  98.           FSU Computer Science       |    one's mind.  Or not to have a  
  99.         Technical Support Group      |    mind at all.  How true that is."
  100.        email:  boyd@nu.cs.fsu.edu    |       -- Vice President Dan Quayle
  101.    ----------------------------------+--------------------------------------
  102.