[Top][All Lists]
[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: |
Fri, 05 May 2006 00:44:09 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) |
address@hidden (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 <address@hidden> http://www.cua.dk
- Re: C-f in isearch minibuffer, (continued)
Re: should search ring contain duplicates?, Stefan Monnier, 2006/05/03
- Re: should search ring contain duplicates?, Kim F. Storm, 2006/05/03
- RE: should search ring contain duplicates?, Drew Adams, 2006/05/03
- RE: should search ring contain duplicates?, Drew Adams, 2006/05/03
- Re: should search ring contain duplicates?, Juri Linkov, 2006/05/03
- RE: should search ring contain duplicates?, Drew Adams, 2006/05/03
Re: should search ring contain duplicates?, Richard Stallman, 2006/05/04
Re: should search ring contain duplicates?, Kim F. Storm, 2006/05/04
Re: should search ring contain duplicates?,
Kim F. Storm <=
Re: should search ring contain duplicates?, Richard Stallman, 2006/05/05
RE: should search ring contain duplicates?, Drew Adams, 2006/05/05
Re: should search ring contain duplicates?, David Kastrup, 2006/05/05
RE: should search ring contain duplicates?, Drew Adams, 2006/05/05
Re: should search ring contain duplicates?, Richard Stallman, 2006/05/06
Re: should search ring contain duplicates?, Juri Linkov, 2006/05/05
Re: should search ring contain duplicates?, Kim F. Storm, 2006/05/05
RE: should search ring contain duplicates?, Drew Adams, 2006/05/05
Re: should search ring contain duplicates?, Dan Nicolaescu, 2006/05/03
Re: should search ring contain duplicates?, Richard Stallman, 2006/05/04