emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: should search ring contain duplicates?


From: Dan Nicolaescu
Subject: Re: should search ring contain duplicates?
Date: Wed, 3 May 2006 00:27:02 -0700

"Drew Adams" <address@hidden> writes:

  > Each successful incremental search adds the search string to the search ring
  > (as the most recent entry), even if it is already in the ring past the first
  > entry. Nothing prevents the ring from containing multiple copies of the same
  > string, which seems wasteful (and useless). At the limit, the search ring,
  > regardless of its length, might contain as few as two different search
  > strings.
  >
  > Shouldn't `isearch-update-ring' (in isearch.el) add the latest search string
  > at the front of the ring but remove it elsewhere in the ring? The result
  > would be a more useful ring.

`isearch-update-ring' could at least do that when
history-delete-duplicates is t.

Something like this could help: [completely untested]

(defun isearch-update-ring (string &optional regexp)
  "Add STRING to the beginning of the search ring.
REGEXP says which ring to use."
  (if regexp
      (if (or (null regexp-search-ring)
              (not (string= string (car regexp-search-ring))))
          (progn
            (when history-delete-duplicates
              (setq regexp-search-ring (delete string regexp-search-ring)))
            (push string regexp-search-ring)
            (if (> (length regexp-search-ring) regexp-search-ring-max)
                (setcdr (nthcdr (1- search-ring-max) regexp-search-ring)
                        nil))))
    (if (or (null search-ring)
            (not (string= string (car search-ring))))
        (progn
          (when history-delete-duplicates
            (setq search-ring (delete string search-ring)))
          (push string search-ring)
          (if (> (length search-ring) search-ring-max)
              (setcdr (nthcdr (1- search-ring-max) search-ring) nil))))))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]