[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master d22e747: Revert recent add-to-ordered-list changes
From: |
Lars Ingebrigtsen |
Subject: |
master d22e747: Revert recent add-to-ordered-list changes |
Date: |
Thu, 31 Dec 2020 23:48:13 -0500 (EST) |
branch: master
commit d22e74795d8c6aeb3af64e2af8a8f3d96924f6f1
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Revert recent add-to-ordered-list changes
* doc/lispref/lists.texi (List Variables): Revert.
* lisp/subr.el (add-to-ordered-list): Revert recent changes
because the semantics are too muddled.
---
doc/lispref/lists.texi | 9 ++++-----
lisp/subr.el | 38 ++++++++++++++------------------------
test/lisp/subr-tests.el | 20 --------------------
3 files changed, 18 insertions(+), 49 deletions(-)
diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi
index 21ee386..ae793d5 100644
--- a/doc/lispref/lists.texi
+++ b/doc/lispref/lists.texi
@@ -807,14 +807,13 @@ foo ;; @r{@code{foo} was changed.}
(setq @var{var} (cons @var{value} @var{var})))
@end example
-@defun add-to-ordered-list symbol element &optional order test-function
+@defun add-to-ordered-list symbol element &optional order
This function sets the variable @var{symbol} by inserting
@var{element} into the old value, which must be a list, at the
position specified by @var{order}. If @var{element} is already a
-member of the list, its position in the list is adjusted according to
-@var{order}. Membership is tested using @var{test-function},
-defaulting to @code{eq} if @var{test-function} isn't present. This
-function returns the resulting list, whether updated or not.
+member of the list, its position in the list is adjusted according
+to @var{order}. Membership is tested using @code{eq}.
+This function returns the resulting list, whether updated or not.
The @var{order} is typically a number (integer or float), and the
elements of the list are sorted in non-decreasing numerical order.
diff --git a/lisp/subr.el b/lisp/subr.el
index 77b142c..7b796df 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -1971,10 +1971,9 @@ can do the job."
(cons element (symbol-value list-var))))))
-(defun add-to-ordered-list (list-var element &optional order test-function)
+(defun add-to-ordered-list (list-var element &optional order)
"Add ELEMENT to the value of LIST-VAR if it isn't there yet.
-TEST-FUNCTION is used to test for the presence of ELEMENT, and
-defaults to `eq'.
+The test for presence of ELEMENT is done with `eq'.
The value of LIST-VAR is kept ordered based on the ORDER
parameter.
@@ -1990,30 +1989,21 @@ The list order for each element is stored in LIST-VAR's
LIST-VAR cannot refer to a lexical variable.
The return value is the new value of LIST-VAR."
- (let ((ordering (get list-var 'list-order))
- missing)
- ;; Make a hash table for storing the ordering.
+ (let ((ordering (get list-var 'list-order)))
(unless ordering
(put list-var 'list-order
- (setq ordering (make-hash-table :weakness 'key
- :test (or test-function #'eq)))))
- (when (and test-function
- (not (eq test-function (hash-table-test ordering))))
- (error "Conflicting test functions given"))
- ;; Add new values.
- (when (setq missing (eq (gethash element ordering 'missing) 'missing))
+ (setq ordering (make-hash-table :weakness 'key :test 'eq))))
+ (when order
+ (puthash element (and (numberp order) order) ordering))
+ (unless (memq element (symbol-value list-var))
(set list-var (cons element (symbol-value list-var))))
- ;; Set/change the order.
- (when (or order missing)
- (setf (gethash element ordering) (and (numberp order) order)))
- (set list-var
- (sort (symbol-value list-var)
- (lambda (a b)
- (let ((oa (gethash a ordering))
- (ob (gethash b ordering)))
- (if (and oa ob)
- (< oa ob)
- oa)))))))
+ (set list-var (sort (symbol-value list-var)
+ (lambda (a b)
+ (let ((oa (gethash a ordering))
+ (ob (gethash b ordering)))
+ (if (and oa ob)
+ (< oa ob)
+ oa)))))))
(defun add-to-history (history-var newelt &optional maxelt keep-all)
"Add NEWELT to the history list stored in the variable HISTORY-VAR.
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index 5be3b89..6677630 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -617,26 +617,6 @@ See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19350."
(add-to-ordered-list 'subr--ordered 'b 5)
(should (equal subr--ordered '(a c d b e))))
-(defvar subr--ordered-s nil)
-
-(ert-deftest subr--add-to-ordered-list-equal ()
- (setq subr--ordered-s nil)
- (add-to-ordered-list 'subr--ordered-s "b" 2 #'equal)
- (should (equal subr--ordered-s '("b")))
- (add-to-ordered-list 'subr--ordered-s "c" 3)
- (should (equal subr--ordered-s '("b" "c")))
- (add-to-ordered-list 'subr--ordered-s "a" 1)
- (should (equal subr--ordered-s '("a" "b" "c")))
- (add-to-ordered-list 'subr--ordered-s "e")
- (should (equal subr--ordered-s '("a" "b" "c" "e")))
- (add-to-ordered-list 'subr--ordered-s "d" 4)
- (should (equal subr--ordered-s '("a" "b" "c" "d" "e")))
- (add-to-ordered-list 'subr--ordered-s "e")
- (should (equal subr--ordered-s '("a" "b" "c" "d" "e")))
- (add-to-ordered-list 'subr--ordered-s "b" 5)
- (should (equal subr--ordered-s '("a" "c" "d" "b" "e")))
- (should-error (add-to-ordered-list 'subr--ordered-s "b" 5 #'eql)))
-
;;; Apropos.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master d22e747: Revert recent add-to-ordered-list changes,
Lars Ingebrigtsen <=