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: David Kastrup
Subject: Re: should search ring contain duplicates?
Date: Thu, 04 May 2006 18:23:47 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

"Stuart D. Herring" <address@hidden> writes:

>> (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)))

No, it doesn't.  Thanks for making my point that "the trouble for a
macro is not really warranted".

(get '(if regexp 'regexp-search-ring 'search-ring) 'history-length)

is going to throw an error at execution time.

Are you sure you know what a macro does?  It compiles the form
resulting from executing the macro on the quoted arguments at compile
time.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum




reply via email to

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