Changeset 7509


Ignore:
Timestamp:
Oct 24, 2007, 7:33:56 PM (14 years ago)
Author:
jaj
Message:

Implement wrapping in incremental search.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/cocoa-ide/hemlock/src/searchcoms.lisp

    r7475 r7509  
    1 ;;; -*- Log: hemlock.log; Package: Hemlock -*-
     1;; -*- Log: hemlock.log; Package: Hemlock -*-
    22;;;
    33;;; **********************************************************************
     
    2424  (new-search-pattern :string-insensitive :forward "Foo")
    2525  "Search pattern we keep around so we don't cons them all the time.")
     26(defvar *search-wrapped-p* nil "True if search wrapped")
    2627
    2728(defhvar "String Search Ignore Case"
     
    106107    (clear-echo-area)
    107108    (format *echo-area-stream*
    108             "~:[~;Failing ~]~:[Reverse I-Search~;I-Search~]: ~A"
    109             failure (eq direction :forward) string)))
     109            "~:[~;Failing ~]~:[~;Overwrapped ~]~:[Reverse I-Search~;I-Search~]: ~A"
     110            failure *search-wrapped-p* (eq direction :forward) string)))
    110111
    111112(defcommand "Incremental Search" (p)
     
    128129  (setf (last-command-type) nil)
    129130  (%i-search-echo-refresh "" :forward nil)
    130   (let* ((point (current-point))
     131  (let* ((*search-wrapped-p* nil)
     132         (point (current-point))
    131133         (save-start (copy-mark point :temporary)))
    132134    (with-mark ((here point))
     
    160162  (setf (last-command-type) nil)
    161163  (%i-search-echo-refresh "" :backward nil)
    162   (let* ((point (current-point))
     164  (let* ((*search-wrapped-p* nil)
     165         (point (current-point))
    163166         (save-start (copy-mark point :temporary)))
    164167    (with-mark ((here point))
     
    262265           (%i-search-empty-string point trailer direction forward-direction-p
    263266                                   forward-character-p))
    264           ((eq forward-direction-p forward-character-p)
    265            (if failure
    266                (%i-search string point trailer direction failure)
    267                (%i-search-find-pattern string point (move-mark trailer point)
    268                                        direction)))
     267          ((eq forward-direction-p forward-character-p) ;keep searching in the same direction
     268           (cond ((eq failure :first-failure)
     269                  (cond (forward-direction-p
     270                         (buffer-start point)
     271                         (buffer-start trailer)
     272                         (character-offset trailer (length string)))
     273                        (t
     274                         (buffer-end point)
     275                         (buffer-end trailer)))
     276                  (push-buffer-mark point nil)
     277                  (let ((*search-wrapped-p* t))
     278                    (%i-search-echo-refresh string direction nil)
     279                    (%i-search-find-pattern string point trailer direction)))
     280                  (failure
     281                   (%i-search string point trailer direction t))
     282                  (t
     283                   (%i-search-find-pattern string point (move-mark trailer point)
     284                                           direction))))
    269285          (t
    270286           (let ((new-direction (if forward-character-p :forward :backward)))
     
    348364               (beep)
    349365               (editor-error "I-Search failed."))
    350            (%i-search string point trailer direction t)))))
     366           (%i-search string point trailer direction :first-failure)))))
    351367
    352368
Note: See TracChangeset for help on using the changeset viewer.