From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: storm@cua.dk (Kim F. Storm) Newsgroups: gmane.emacs.devel Subject: Re: should search ring contain duplicates? Date: Fri, 05 May 2006 00:44:09 +0200 Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1146782788 2054 80.91.229.2 (4 May 2006 22:46:28 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 4 May 2006 22:46:28 +0000 (UTC) Cc: Drew Adams , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri May 05 00:46:23 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FbmaO-0001GN-BN for ged-emacs-devel@m.gmane.org; Fri, 05 May 2006 00:46:17 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FbmaN-0000u4-9i for ged-emacs-devel@m.gmane.org; Thu, 04 May 2006 18:46:15 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FbmaA-0000qN-R9 for emacs-devel@gnu.org; Thu, 04 May 2006 18:46:02 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Fbma9-0000p7-GP for emacs-devel@gnu.org; Thu, 04 May 2006 18:46:02 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Fbma9-0000p3-Bb for emacs-devel@gnu.org; Thu, 04 May 2006 18:46:01 -0400 Original-Received: from [195.41.46.237] (helo=pfepc.post.tele.dk) by monty-python.gnu.org with esmtp (Exim 4.52) id 1Fbma7-0007mv-Cl; Thu, 04 May 2006 18:46:00 -0400 Original-Received: from kfs-l.imdomain.dk.cua.dk (0x503e2644.bynxx3.adsl-dhcp.tele.dk [80.62.38.68]) by pfepc.post.tele.dk (Postfix) with SMTP id B869D8A0041; Fri, 5 May 2006 00:45:51 +0200 (CEST) Original-To: rms@gnu.org In-Reply-To: (Kim F. Storm's message of "Thu, 04 May 2006 17:07:43 +0200") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:53936 Archived-At: storm@cua.dk (Kim F. Storm) writes: > There are many places where this would be useful! For example: Index: lisp/subr.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/subr.el,v retrieving revision 1.505 diff -c -r1.505 subr.el *** lisp/subr.el 29 Apr 2006 13:56:19 -0000 1.505 --- lisp/subr.el 4 May 2006 22:44:11 -0000 *************** *** 1122,1127 **** --- 1124,1155 ---- (if (and oa ob) (< oa ob) oa))))))) + + (defun add-to-history (history-var newelt &optional maxelt keep-dups) + "Add NEWELT to the history list stored in the variable HISTORY-VAR. + Return the new history list. + If MAXELT is non-nil, it specifies the maximum length of the history. + Otherwise, the maximum history length is the value of the `history-length' + property on symbol HISTORY-VAR, if set, or the value of the `history-length' + variable. + Remove duplicates of NEWELT unless `history-delete-duplicates' is nil + or KEEP-DUPS is non-nil." + (unless maxelt + (setq maxelt (or (get history-var 'history-length) + history-length))) + (let ((history (symbol-value history-var)) + tail) + (if (and history-delete-duplicates (not keep-dups)) + (setq history (delete newelt history))) + (setq history (cons newelt history)) + (when (integerp maxelt) + (if (= 0 maxelt) + (setq history nil) + (setq tail (nthcdr (1- maxelt) history)) + (when (consp tail) + (setcdr tail nil)))) + (set history-var history))) + ;;;; Mode hooks. Index: lisp/ediff.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/ediff.el,v retrieving revision 1.78 diff -c -r1.78 ediff.el *** lisp/ediff.el 19 Feb 2006 03:16:44 -0000 1.78 --- lisp/ediff.el 4 May 2006 22:41:46 -0000 *************** *** 210,221 **** ediff-last-dir-B (file-name-directory f))) (progn ! (setq file-name-history ! (cons (ediff-abbreviate-file-name ! (expand-file-name ! (file-name-nondirectory f) ! dir-B)) ! file-name-history)) (ediff-get-default-file-name f 1))) ))) (ediff-files-internal file-A --- 210,220 ---- ediff-last-dir-B (file-name-directory f))) (progn ! (add-to-history 'file-name-history ! (ediff-abbreviate-file-name ! (expand-file-name ! (file-name-nondirectory f) ! dir-B))) (ediff-get-default-file-name f 1))) ))) (ediff-files-internal file-A *************** *** 246,270 **** ediff-last-dir-B (file-name-directory f))) (progn ! (setq file-name-history ! (cons ! (ediff-abbreviate-file-name ! (expand-file-name ! (file-name-nondirectory f) ! dir-B)) ! file-name-history)) (ediff-get-default-file-name f 1)))) (ediff-read-file-name "File C to compare" (setq dir-C (if ediff-use-last-dir ediff-last-dir-C (file-name-directory ff))) (progn ! (setq file-name-history ! (cons (ediff-abbreviate-file-name ! (expand-file-name ! (file-name-nondirectory ff) ! dir-C)) ! file-name-history)) (ediff-get-default-file-name ff 2))) ))) (ediff-files-internal file-A --- 245,266 ---- ediff-last-dir-B (file-name-directory f))) (progn ! (add-to-history 'file-name-history ! (ediff-abbreviate-file-name ! (expand-file-name ! (file-name-nondirectory f) ! dir-B))) (ediff-get-default-file-name f 1)))) (ediff-read-file-name "File C to compare" (setq dir-C (if ediff-use-last-dir ediff-last-dir-C (file-name-directory ff))) (progn ! (add-to-history 'file-name-history ! (ediff-abbreviate-file-name ! (expand-file-name ! (file-name-nondirectory ff) ! dir-C))) (ediff-get-default-file-name ff 2))) ))) (ediff-files-internal file-A *************** *** 1109,1120 **** ediff-last-dir-B (file-name-directory f))) (progn ! (setq file-name-history ! (cons (ediff-abbreviate-file-name ! (expand-file-name ! (file-name-nondirectory f) ! dir-B)) ! file-name-history)) (ediff-get-default-file-name f 1))) ))) (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks)) --- 1105,1115 ---- ediff-last-dir-B (file-name-directory f))) (progn ! (add-to-history 'file-name-history ! (ediff-abbreviate-file-name ! (expand-file-name ! (file-name-nondirectory f) ! dir-B))) (ediff-get-default-file-name f 1))) ))) (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks)) *************** *** 1153,1165 **** ediff-last-dir-B (file-name-directory f))) (progn ! (setq file-name-history ! (cons ! (ediff-abbreviate-file-name ! (expand-file-name ! (file-name-nondirectory f) ! dir-B)) ! file-name-history)) (ediff-get-default-file-name f 1)))) (ediff-read-file-name "Ancestor file" (setq dir-ancestor --- 1148,1158 ---- ediff-last-dir-B (file-name-directory f))) (progn ! (add-to-history 'file-name-history ! (ediff-abbreviate-file-name ! (expand-file-name ! (file-name-nondirectory f) ! dir-B))) (ediff-get-default-file-name f 1)))) (ediff-read-file-name "Ancestor file" (setq dir-ancestor *************** *** 1167,1178 **** ediff-last-dir-ancestor (file-name-directory ff))) (progn ! (setq file-name-history ! (cons (ediff-abbreviate-file-name ! (expand-file-name ! (file-name-nondirectory ff) ! dir-ancestor)) ! file-name-history)) (ediff-get-default-file-name ff 2))) ))) (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks)) --- 1160,1170 ---- ediff-last-dir-ancestor (file-name-directory ff))) (progn ! (add-to-history 'file-name-history ! (ediff-abbreviate-file-name ! (expand-file-name ! (file-name-nondirectory ff) ! dir-ancestor))) (ediff-get-default-file-name ff 2))) ))) (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks)) Index: lisp/env.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/env.el,v retrieving revision 1.36 diff -c -r1.36 env.el *** lisp/env.el 18 Apr 2006 21:17:50 -0000 1.36 --- lisp/env.el 4 May 2006 22:42:16 -0000 *************** *** 117,123 **** (let* ((var (read-envvar-name "Set environment variable: " nil)) (value (getenv var))) (when value ! (push value setenv-history)) ;; Here finally we specify the args to give call setenv with. (list var (read-from-minibuffer (format "Set %s to value: " var) --- 117,123 ---- (let* ((var (read-envvar-name "Set environment variable: " nil)) (value (getenv var))) (when value ! (add-to-history 'setenv-history value)) ;; Here finally we specify the args to give call setenv with. (list var (read-from-minibuffer (format "Set %s to value: " var) Index: lisp/isearch.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/isearch.el,v retrieving revision 1.287 diff -c -r1.287 isearch.el *** lisp/isearch.el 3 May 2006 23:27:53 -0000 1.287 --- lisp/isearch.el 4 May 2006 22:42:46 -0000 *************** *** 831,851 **** (defun isearch-update-ring (string &optional regexp) "Add STRING to the beginning of the search ring. REGEXP if non-nil says use the regexp search ring." ! (if regexp ! (when (or (null regexp-search-ring) ! (not (string= string (car regexp-search-ring)))) ! (when history-delete-duplicates ! (setq regexp-search-ring (delete string regexp-search-ring))) ! (push string regexp-search-ring) ! (when (> (length regexp-search-ring) regexp-search-ring-max) ! (setcdr (nthcdr (1- search-ring-max) regexp-search-ring) nil))) ! (when (or (null search-ring) ! (not (string= string (car search-ring)))) ! (when history-delete-duplicates ! (setq search-ring (delete string search-ring))) ! (push string search-ring) ! (when (> (length search-ring) search-ring-max) ! (setcdr (nthcdr (1- search-ring-max) search-ring) nil))))) ;; Switching buffers should first terminate isearch-mode. ;; ;; For Emacs 19, the frame switch event is handled. --- 831,839 ---- (defun isearch-update-ring (string &optional regexp) "Add STRING to the beginning of the search ring. REGEXP if non-nil says use the regexp search ring." ! (add-to-history ! (if regexp 'regexp-search-ring 'search-ring) ! (if regexp regexp-search-ring-max search-ring-max))) ;; Switching buffers should first terminate isearch-mode. ;; ;; For Emacs 19, the frame switch event is handled. Index: lisp/kmacro.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/kmacro.el,v retrieving revision 1.32 diff -c -r1.32 kmacro.el *** lisp/kmacro.el 6 Feb 2006 14:33:34 -0000 1.32 --- lisp/kmacro.el 4 May 2006 22:43:11 -0000 *************** *** 349,358 **** (defun kmacro-push-ring (&optional elt) "Push ELT or current macro onto `kmacro-ring'." (when (setq elt (or elt (kmacro-ring-head))) ! (let ((len (length kmacro-ring))) ! (setq kmacro-ring (cons elt kmacro-ring)) ! (if (>= len kmacro-ring-max) ! (setcdr (nthcdr len kmacro-ring) nil))))) (defun kmacro-split-ring-element (elt) --- 349,355 ---- (defun kmacro-push-ring (&optional elt) "Push ELT or current macro onto `kmacro-ring'." (when (setq elt (or elt (kmacro-ring-head))) ! (add-to-history 'kmacro-ring elt kmacro-ring-max t))) (defun kmacro-split-ring-element (elt) *************** *** 377,387 **** (kmacro-pop-ring1 raw))) - (defun kmacro-ring-length () - "Return length of macro ring, including pseudo head." - (+ (if last-kbd-macro 1 0) (length kmacro-ring))) - - (defun kmacro-ring-empty-p (&optional none) "Tell user and return t if `last-kbd-macro' is nil or `kmacro-ring' is empty. Check only `last-kbd-macro' if optional arg NONE is non-nil." --- 374,379 ---- *************** *** 577,589 **** (let ((append (and arg (listp arg)))) (unless append (if last-kbd-macro ! (let ((len (length kmacro-ring))) ! (setq kmacro-ring ! (cons ! (list last-kbd-macro kmacro-counter kmacro-counter-format-start) ! kmacro-ring)) ! (if (>= len kmacro-ring-max) ! (setcdr (nthcdr len kmacro-ring) nil)))) (setq kmacro-counter (or (if arg (prefix-numeric-value arg)) kmacro-initial-counter-value 0) --- 569,576 ---- (let ((append (and arg (listp arg)))) (unless append (if last-kbd-macro ! (kmacro-push-ring ! (list last-kbd-macro kmacro-counter kmacro-counter-format-start))) (setq kmacro-counter (or (if arg (prefix-numeric-value arg)) kmacro-initial-counter-value 0) Index: lisp/server.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/server.el,v retrieving revision 1.109 diff -c -r1.109 server.el *** lisp/server.el 4 Mar 2006 16:06:46 -0000 1.109 --- lisp/server.el 4 May 2006 22:43:33 -0000 *************** *** 411,417 **** ;; deleted file, offer to write it. (let* ((filen (car file)) (obuf (get-file-buffer filen))) ! (push filen file-name-history) (if (and obuf (set-buffer obuf)) (progn (cond ((file-exists-p filen) --- 411,417 ---- ;; deleted file, offer to write it. (let* ((filen (car file)) (obuf (get-file-buffer filen))) ! (add-to-history 'file-name-history filen) (if (and obuf (set-buffer obuf)) (progn (cond ((file-exists-p filen) Index: lisp/progmodes/grep.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/progmodes/grep.el,v retrieving revision 1.55 diff -c -r1.55 grep.el *** lisp/progmodes/grep.el 2 May 2006 08:49:59 -0000 1.55 --- lisp/progmodes/grep.el 4 May 2006 22:43:51 -0000 *************** *** 676,682 **** (setq command (read-from-minibuffer "Confirm: " command nil nil 'grep-history)) ! (push command grep-history)))) (when command ;; Setting process-setup-function makes exit-message-function work ;; even when async processes aren't supported. --- 676,682 ---- (setq command (read-from-minibuffer "Confirm: " command nil nil 'grep-history)) ! (add-to-history 'grep-history command)))) (when command ;; Setting process-setup-function makes exit-message-function work ;; even when async processes aren't supported. *************** *** 742,748 **** (setq command (read-from-minibuffer "Confirm: " command nil nil 'grep-find-history)) ! (push command grep-find-history)) (compilation-start command 'grep-mode)))))) --- 742,748 ---- (setq command (read-from-minibuffer "Confirm: " command nil nil 'grep-find-history)) ! (add-to-history 'grep-find-history command)) (compilation-start command 'grep-mode)))))) Index: lisp/progmodes/vhdl-mode.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/progmodes/vhdl-mode.el,v retrieving revision 1.50 diff -c -r1.50 vhdl-mode.el *** lisp/progmodes/vhdl-mode.el 10 Feb 2006 09:00:30 -0000 1.50 --- lisp/progmodes/vhdl-mode.el 4 May 2006 22:45:20 -0000 *************** *** 16723,16730 **** (progn (save-buffer) (kill-buffer (current-buffer)) (set-buffer orig-buffer) ! (setq file-name-history ! (cons makefile-path-name file-name-history))) (vhdl-warning-when-idle (format "File not writable: \"%s\"" (abbreviate-file-name makefile-path-name))) --- 16723,16729 ---- (progn (save-buffer) (kill-buffer (current-buffer)) (set-buffer orig-buffer) ! (add-to-history 'file-name-history makefile-path-name)) (vhdl-warning-when-idle (format "File not writable: \"%s\"" (abbreviate-file-name makefile-path-name))) Index: lisp/progmodes/xscheme.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/progmodes/xscheme.el,v retrieving revision 1.9 diff -c -r1.9 xscheme.el *** lisp/progmodes/xscheme.el 10 Feb 2006 09:00:30 -0000 1.9 --- lisp/progmodes/xscheme.el 4 May 2006 22:45:38 -0000 *************** *** 580,591 **** ;;;; Scheme expressions ring (defun xscheme-insert-expression (string) ! (setq xscheme-expressions-ring (cons string xscheme-expressions-ring)) ! (if (> (length xscheme-expressions-ring) xscheme-expressions-ring-max) ! (setcdr (nthcdr (1- xscheme-expressions-ring-max) ! xscheme-expressions-ring) ! nil)) ! (setq xscheme-expressions-ring-yank-pointer xscheme-expressions-ring)) (defun xscheme-rotate-yank-pointer (arg) "Rotate the yanking point in the kill ring." --- 580,588 ---- ;;;; Scheme expressions ring (defun xscheme-insert-expression (string) ! (setq xscheme-expressions-ring-yank-pointer ! (add-to-history 'xscheme-expressions-ring string ! xscheme-expressions-ring-max))) (defun xscheme-rotate-yank-pointer (arg) "Rotate the yanking point in the kill ring." -- Kim F. Storm http://www.cua.dk