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: Stuart D. Herring
Subject: Re: should search ring contain duplicates?
Date: Thu, 4 May 2006 09:05:57 -0700 (PDT)
User-agent: SquirrelMail/1.4.3a-11.EL3

> (defun history-push (newelt history &optional maxelt)
>   "Add NEWELT to the history list stored in the symbol HISTORY.
> If symbol MAXELT is specified, the maximum length of the history is
> specified by the value of that symbol.  Otherwise, the maximum history
> length is  to the value of the `history-length' property on symbol
> HISTORY, if set, or to the value of the `history-length' variable.
> Remove duplicates of NEWELT unless `history-delete-duplicates' is nil."
>   (unless maxelt
>     (setq maxelt (or (get history 'history-length)
>                      history-length)))
>   (if history-delete-duplicates
>      (set history (delete newelt (symbol-value history))))
>   (set history (cons newelt (symbol-value history)))
>   (when (integerp maxelt)
>       (if (= 0 maxelt)
>        (set history nil)
>        (if (> (length (symbol-value history)) maxelt)
>           (setcdr (nthcdr (1- maxelt) (symbol-value history)) nil)))))
>
> Sure, you need to quote history in the call then, but it seems like
> the trouble for a macro is not really warranted.

Evaluating the history argument is a feature, not a bug.  It lets you do
something like this:

(defun isearch-update-ring (string &optional regexp)
  "Add STRING to the beginning of the search ring.
REGEXP says which ring to use."
  (history-push string
                (if regexp 'regexp-search-ring 'search-ring)
                (if regexp regexp-search-ring-max search-ring-max)))

(With, of course, modifications if Kim's `add-to-history' is used instead.)

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.




reply via email to

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