home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / lisp / vm / vm-search.el < prev    next >
Encoding:
Text File  |  1993-03-24  |  3.2 KB  |  83 lines

  1. ;; Incremental search through a mail folder
  2. ;; Copyright (C) 1985, 1986, 1993 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  6. ;; GNU Emacs is distributed in the hope that it will be useful,
  7. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  8. ;; accepts responsibility to anyone for the consequences of using it
  9. ;; or for whether it serves any particular purpose or works at all,
  10. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  11. ;; License for full details.
  12.  
  13. ;; Everyone is granted permission to copy, modify and redistribute
  14. ;; GNU Emacs, but only under the conditions described in the
  15. ;; GNU Emacs General Public License.   A copy of this license is
  16. ;; supposed to have been given to you along with GNU Emacs so you
  17. ;; can know your rights and responsibilities.  It should be in a
  18. ;; file named COPYING.  Among other things, the copyright notice
  19. ;; and this notice must be preserved on all copies.
  20.  
  21. ;; Adapted for the VM mail reader, Kyle Jones, May 1989
  22. ;; And for isearch-mode, Tim Bradshaw, March 1993
  23.  
  24. (defun vm-isearch-forward ()
  25.   "Incrementally search forward through the current folder's messages.
  26. Usage is identical to the standard Emacs incremental search.
  27. When the search terminates the message containing point will be selected.
  28.  
  29. If the variable vm-search-using-regexps is non-nil, regular expressions
  30. are understood; nil means the search will be for the input string taken
  31. literally."
  32.   (interactive)
  33.   (vm-follow-summary-cursor)
  34.   (vm-select-folder-buffer)
  35.   (vm-check-for-killed-summary)
  36.   (vm-error-if-folder-empty)
  37.   (vm-set-window-configuration 'searching-folder)
  38.   (if (null (get-buffer-window (current-buffer)))
  39.       (vm-display-current-message-buffer))
  40.   (let ((clip-head (point-min))
  41.     (clip-tail (point-max))
  42.     (old-w (selected-window)))
  43.     (unwind-protect
  44.     (progn (select-window (get-buffer-window (current-buffer)))
  45.            (widen)
  46.            (isearch-mode t vm-search-using-regexps nil t)
  47.            (vm-update-search-position)
  48.            ;; vm-show-current-message only adjusts (point-max),
  49.            ;; it doesn't change (point-min).
  50.            (narrow-to-region
  51.         (if (< (point) (vm-vheaders-of (car vm-message-pointer)))
  52.             (vm-start-of (car vm-message-pointer))
  53.           (vm-vheaders-of (car vm-message-pointer)))
  54.         (point-max))
  55.            (vm-highlight-headers (car vm-message-pointer)
  56.                      (get-buffer-window (current-buffer)))
  57.            (vm-show-current-message)
  58.            (setq vm-system-state 'reading)
  59.            ;; turn the clipping unwind into a noop
  60.            (setq clip-head (point-min))
  61.            (setq clip-tail (point-max)))
  62.       (narrow-to-region clip-head clip-tail)
  63.       (select-window old-w))))
  64.  
  65.  
  66. (defun vm-update-search-position (&optional record-change)
  67.   (if (and (>= (point) (vm-start-of (car vm-message-pointer)))
  68.        (<= (point) (vm-end-of (car vm-message-pointer))))
  69.       nil
  70.     (let ((mp vm-message-list)
  71.       (point (point)))
  72.       (while mp
  73.     (if (and (>= point (vm-start-of (car mp)))
  74.          (<= point (vm-end-of (car mp))))
  75.         (if record-change
  76.         (progn
  77.           (vm-record-and-change-message-pointer vm-message-pointer mp)
  78.           (setq mp nil))
  79.           (setq vm-message-pointer mp mp nil))
  80.       (setq mp (cdr mp))))
  81.       (setq vm-need-summary-pointer-update t)
  82.       (vm-update-summary-and-mode-line))))
  83.