home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / packages / search+.el < prev    next >
Encoding:
Text File  |  1990-07-22  |  4.2 KB  |  109 lines

  1. ;From ark1!uakari.primate.wisc.edu!samsung!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hp-pcd!hpcvca!charles Thu Jan 11 09:52:44 1990
  2. ;Article 1162 of comp.emacs:
  3. ;Path: ark1!uakari.primate.wisc.edu!samsung!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hp-pcd!hpcvca!charles
  4. ;From charles@hpcvca.CV.HP.COM (Charles Brown)
  5. ;Newsgroups: comp.emacs
  6. ;Subject: Re: Forward and Backward Searches with Full Editing.
  7. ;Message-ID: <640013@hpcvca.CV.HP.COM>
  8. ;Date: 9 Jan 90 00:10:18 GMT
  9. ;References: <640012@hpcvca.CV.HP.COM>
  10. ;Organization: Hewlett-Packard Co., Corvallis, Oregon
  11. ;Lines: 96
  12. ;
  13. ;I received several excellent suggestions from tale@turing.cs.rpi.edu
  14. ;(David C Lawrence).  Most of these have been incorporated into the
  15. ;following improved version.  This code should behave identically with
  16. ;the old code.
  17. ;
  18. ;I release any copyright from this code.  It is fully public domain.
  19. ;--
  20. ;    Charles Brown    charles@cv.hp.com or charles%hpcvca@hplabs.hp.com
  21. ;            or hplabs!hpcvca!charles or "Hey you!"
  22. ;---------------------------------------------------------------------
  23. ; Charles Brown  date="Mon Jan  8 16:10:12 1990"
  24.  
  25. ; The algorithm for each buffer is
  26. ;   if (a search has been done in this buffer) then
  27. ;     pull up the old search string for this buffer (search-last)
  28. ;   else
  29. ;     if (a search has been done in any buffer) then
  30. ;    pull up the old search string not specific this buffer (*search-last*)
  31.  
  32. (defvar *re-search-last* "")
  33. (defvar re-search-last "")
  34. (make-variable-buffer-local 're-search-last)
  35. (defvar *search-last* "")
  36. (defvar search-last "")
  37. (make-variable-buffer-local 'search-last)
  38.  
  39. (defun stringnzp (str)
  40.   "Return STR if it is a string of non-zero length."
  41.   (and (stringp str) (string< "" str) str))
  42.  
  43. (defun
  44.   re-search-forward-command (regexp &optional repeat)
  45.   "Search forward from point for regular expression REGEXP.
  46. Set point to the end of the occurrence found, and return t.
  47. Optional second argument REPEAT (prefix argument interactively)
  48. is the number of times to repeat the search."
  49.   (interactive (list (read-string
  50.                "RE search: "
  51.                (or (stringnzp re-search-last)
  52.                (stringnzp *re-search-last*)))
  53.              (prefix-numeric-value current-prefix-arg)))
  54.   (if (or (null regexp) (equal "" regexp))
  55.       (error "Search string is null")
  56.     (setq re-search-last (setq *re-search-last* regexp))
  57.     (re-search-forward regexp nil nil repeat))
  58.   t)
  59.  
  60. (defun re-search-backward-command (regexp &optional repeat)
  61.   "Search backward from point for match for regular expression REGEXP.
  62. Set point to the beginning of the match, and return t.
  63. Optional second argument REPEAT (prefix argument interactively)
  64. is the number of times to repeat the search."
  65.   (interactive (list (read-string
  66.                "RE search backward: "
  67.                (or (stringnzp re-search-last)
  68.                (stringnzp *re-search-last*)))
  69.              (prefix-numeric-value current-prefix-arg)))
  70.   (if (or (null regexp) (equal "" regexp))
  71.       (error "Search string is null")
  72.     (setq re-search-last (setq *re-search-last* regexp))
  73.     (re-search-backward regexp nil nil repeat))
  74.   t)
  75.  
  76. (defun
  77.   search-forward-command (regexp &optional repeat)
  78.   "Search forward from point for STRING.
  79. Set point to the end of the occurrence found, and return t.
  80. Optional second argument REPEAT (prefix argument interactively)
  81. is the number of times to repeat the search."
  82.   (interactive (list (read-string
  83.                "search: "
  84.                (or (stringnzp search-last)
  85.                (stringnzp *search-last*)))
  86.              (prefix-numeric-value current-prefix-arg)))
  87.   (if (or (null regexp) (equal "" regexp))
  88.       (error "Search string is null")
  89.     (setq search-last (setq *search-last* regexp))
  90.     (search-forward regexp nil nil repeat))
  91.   t)
  92.  
  93. (defun
  94.   search-backward-command (regexp &optional repeat)
  95.   "Search backward from point for STRING.
  96. Set point to the beginning of the occurrence found, and return t.
  97. Optional second argument REPEAT (prefix argument interactively)
  98. is the number of times to repeat the search."
  99.   (interactive (list (read-string
  100.                "RE search backward: "
  101.                (or (stringnzp search-last)
  102.                (stringnzp *search-last*)))
  103.              (prefix-numeric-value current-prefix-arg)))
  104.   (if (or (null regexp) (equal "" regexp))
  105.       (error "Search string is null")
  106.     (setq search-last (setq *search-last* regexp))
  107.     (search-backward regexp nil nil repeat))
  108.   t)
  109.