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: Kim F. Storm
Subject: Re: should search ring contain duplicates?
Date: Thu, 04 May 2006 12:12:20 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

address@hidden (Kim F. Storm) writes:

> I definitely think we need the history-push macro!
> Here is something which works for me:

.. almost :-)  Here is a better version:

(defmacro 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."
  (declare (debug (form sexp)))
  (unless maxelt
    (setq maxelt `(or (get ',history 'history-length)
                       history-length)))
  `(let ((len ,maxelt))
     (if history-delete-duplicates
         (setq ,history (delete ,newelt ,history)))
     (setq ,history (cons ,newelt ,history))
     (when (integerp len)
       (if (= 0 len)
           (setq ,history nil)
         (if (> (length ,history) len)
             (setcdr (nthcdr (1- len) ,history) nil))))))


-- 
Kim F. Storm <address@hidden> http://www.cua.dk





reply via email to

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