From cd5dfa086d204c01791bfdcdf9fe1215c4bf1e42 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sat, 3 Apr 2021 01:21:32 +0200 Subject: Replace two functions with seq-subseq * lisp/emacs-lisp/seq.el (seq-subseq): Add autoload cookie. * lisp/eshell/esh-util.el (eshell-sublist): Redefine using seq-subseq and make obsolete. Update callers. * lisp/wid-edit.el (widget-sublist): Redefine as obsolete function alias for seq-subseq. Update callers. --- lisp/emacs-lisp/seq.el | 1 + 1 file changed, 1 insertion(+) (limited to 'lisp/emacs-lisp/seq.el') diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el index 2b8807faad5..f2f7d677e88 100644 --- a/lisp/emacs-lisp/seq.el +++ b/lisp/emacs-lisp/seq.el @@ -147,6 +147,7 @@ the sequence, and its index within the sequence." "Return a shallow copy of SEQUENCE." (copy-sequence sequence)) +;;;###autoload (cl-defgeneric seq-subseq (sequence start &optional end) "Return the sequence of elements of SEQUENCE from START to END. END is exclusive. -- cgit v1.2.3 From 20f7fa691b7c2859b96550d9ccb326bf394e160d Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 5 Apr 2021 14:24:00 +0200 Subject: Obsolete local set difference functions in favor of seq-difference * lisp/emacs-lisp/seq.el (seq-difference): Add autoload cookie. * lisp/gnus/gnus-range.el (gnus-set-difference): * lisp/gnus/spam.el (spam-set-difference): Make obsolete in favor of seq-difference. Update callers. --- lisp/emacs-lisp/seq.el | 1 + lisp/gnus/gnus-cite.el | 4 ++-- lisp/gnus/gnus-range.el | 9 ++------- lisp/gnus/gnus-sum.el | 5 +++-- lisp/gnus/gnus-uu.el | 2 +- lisp/gnus/nnimap.el | 10 ++++++---- lisp/gnus/spam.el | 14 +++----------- 7 files changed, 18 insertions(+), 27 deletions(-) (limited to 'lisp/emacs-lisp/seq.el') diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el index f2f7d677e88..7aa5684cfd1 100644 --- a/lisp/emacs-lisp/seq.el +++ b/lisp/emacs-lisp/seq.el @@ -468,6 +468,7 @@ Equality is defined by TESTFN if non-nil or by `equal' if nil." (seq-reverse sequence1) '())) +;;;###autoload (cl-defgeneric seq-difference (sequence1 sequence2 &optional testfn) "Return a list of the elements that appear in SEQUENCE1 but not in SEQUENCE2. Equality is defined by TESTFN if non-nil or by `equal' if nil." diff --git a/lisp/gnus/gnus-cite.el b/lisp/gnus/gnus-cite.el index 1f564f192b0..4249b50b9ff 100644 --- a/lisp/gnus/gnus-cite.el +++ b/lisp/gnus/gnus-cite.el @@ -839,7 +839,7 @@ See also the documentation for `gnus-article-highlight-citation'." (setq current (car loop) loop (cdr loop)) (setcdr current - (gnus-set-difference (cdr current) numbers))))))))) + (seq-difference (cdr current) numbers #'eq))))))))) (defun gnus-cite-parse-attributions () (let (al-alist) @@ -999,7 +999,7 @@ See also the documentation for `gnus-article-highlight-citation'." loop (cdr loop)) (if (eq current best) () - (setcdr current (gnus-set-difference (cdr current) numbers)) + (setcdr current (seq-difference (cdr current) numbers #'eq)) (when (null (cdr current)) (setq gnus-cite-loose-prefix-alist (delq current gnus-cite-loose-prefix-alist) diff --git a/lisp/gnus/gnus-range.el b/lisp/gnus/gnus-range.el index 456209f3d9a..7d12ae9fdcc 100644 --- a/lisp/gnus/gnus-range.el +++ b/lisp/gnus/gnus-range.el @@ -42,13 +42,8 @@ If RANGE is a single range, return (RANGE). Otherwise, return RANGE." (defun gnus-set-difference (list1 list2) "Return a list of elements of LIST1 that do not appear in LIST2." - (let ((hash2 (make-hash-table :test 'eq)) - (result nil)) - (dolist (elt list2) (puthash elt t hash2)) - (dolist (elt list1) - (unless (gethash elt hash2) - (setq result (cons elt result)))) - (nreverse result))) + (declare (obsolete seq-difference "28.1")) + (seq-difference list1 list2 #'eq)) (defun gnus-range-nconcat (&rest ranges) "Return a range comprising all the RANGES, which are pre-sorted. diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el index ac9317ef4e2..eeb5ac851ae 100644 --- a/lisp/gnus/gnus-sum.el +++ b/lisp/gnus/gnus-sum.el @@ -8569,8 +8569,9 @@ If UNREPLIED (the prefix), limit to unreplied articles." (interactive "P" gnus-summary-mode) (if unreplied (gnus-summary-limit - (gnus-set-difference gnus-newsgroup-articles - gnus-newsgroup-replied)) + (seq-difference gnus-newsgroup-articles + gnus-newsgroup-replied + #'eq)) (gnus-summary-limit gnus-newsgroup-replied)) (gnus-summary-position-point)) diff --git a/lisp/gnus/gnus-uu.el b/lisp/gnus/gnus-uu.el index 5cbe8495d31..ceb2ebcdcb1 100644 --- a/lisp/gnus/gnus-uu.el +++ b/lisp/gnus/gnus-uu.el @@ -579,7 +579,7 @@ didn't work, and overwrite existing files. Otherwise, ask each time." (defun gnus-new-processable (unmarkp articles) (if unmarkp (nreverse (seq-intersection gnus-newsgroup-processable articles #'eq)) - (gnus-set-difference articles gnus-newsgroup-processable))) + (seq-difference articles gnus-newsgroup-processable #'eq))) (defun gnus-uu-mark-by-regexp (regexp &optional unmark) "Set the process mark on articles whose subjects match REGEXP. diff --git a/lisp/gnus/nnimap.el b/lisp/gnus/nnimap.el index f06959f65d9..8990b2bebeb 100644 --- a/lisp/gnus/nnimap.el +++ b/lisp/gnus/nnimap.el @@ -1614,13 +1614,15 @@ If LIMIT, first try to limit the search to the N last articles." (setq start-article 1)) (let* ((unread (gnus-compress-sequence - (gnus-set-difference - (gnus-set-difference + (seq-difference + (seq-difference existing (gnus-sorted-union (cdr (assoc '%Seen flags)) - (cdr (assoc '%Deleted flags)))) - (cdr (assoc '%Flagged flags))))) + (cdr (assoc '%Deleted flags))) + #'eq) + (cdr (assoc '%Flagged flags)) + #'eq))) (read (gnus-range-difference (cons start-article high) unread))) (when (> start-article 1) diff --git a/lisp/gnus/spam.el b/lisp/gnus/spam.el index d00f0a60b66..3f978918b9a 100644 --- a/lisp/gnus/spam.el +++ b/lisp/gnus/spam.el @@ -710,16 +710,8 @@ finds ham or spam.") (defun spam-set-difference (list1 list2) "Return a set difference of LIST1 and LIST2. When either list is nil, the other is returned." - (if (and list1 list2) - ;; we have two non-nil lists - (progn - (dolist (item (append list1 list2)) - (when (and (memq item list1) (memq item list2)) - (setq list1 (delq item list1)) - (setq list2 (delq item list2)))) - (append list1 list2)) - ;; if either of the lists was nil, return the other one - (if list1 list1 list2))) + (declare (obsolete seq-difference "28.1")) + (seq-difference list1 list2 #'eq)) (defun spam-group-ham-mark-p (group mark &optional spam) "Checks if MARK is considered a ham mark in GROUP." @@ -1327,7 +1319,7 @@ In the case of mover backends, checks the setting of (new-articles (spam-list-articles gnus-newsgroup-articles classification)) - (changed-articles (spam-set-difference new-articles old-articles))) + (changed-articles (seq-difference new-articles old-articles #'eq))) ;; now that we have the changed articles, we go through the processors (dolist (backend (spam-backend-list)) (let (unregister-list) -- cgit v1.2.3 From 6686a31591d2d22a4d1c7b6e68a618823186c48e Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 5 Apr 2021 15:14:19 +0200 Subject: Remove local uniquify functions in favour of seq-uniq * lisp/emacs-lisp/seq.el (seq-uniq): Add autoload cookie. * lisp/pcomplete.el: (pcomplete-uniquify-list): Use seq-uniq. * lisp/eshell/esh-util.el (eshell-uniqify-list) (eshell-uniquify-list): * lisp/nxml/rng-util.el (rng-uniquify-equal): * lisp/progmodes/idlwave.el (idlwave-uniquify): * lisp/textmodes/artist.el (artist-uniq): Make into obsolete function aliases for seq-uniq. Update callers. * lisp/nxml/rng-util.el (rng-uniquify-eq): Make obsolete in favor of seq-uniq. Update callers. --- lisp/emacs-lisp/seq.el | 1 + lisp/eshell/em-pred.el | 2 +- lisp/eshell/esh-util.el | 16 ++-------------- lisp/nxml/rng-loc.el | 2 +- lisp/nxml/rng-match.el | 2 +- lisp/nxml/rng-nxml.el | 2 +- lisp/nxml/rng-util.el | 28 ++++++++-------------------- lisp/pcomplete.el | 15 +++------------ lisp/progmodes/idlwave.el | 12 +++--------- lisp/textmodes/artist.el | 14 ++------------ 10 files changed, 23 insertions(+), 71 deletions(-) (limited to 'lisp/emacs-lisp/seq.el') diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el index 7aa5684cfd1..6c15463ad52 100644 --- a/lisp/emacs-lisp/seq.el +++ b/lisp/emacs-lisp/seq.el @@ -431,6 +431,7 @@ Equality is defined by TESTFN if non-nil or by `equal' if nil." (setq index (1+ index))) nil))) +;;;###autoload (cl-defgeneric seq-uniq (sequence &optional testfn) "Return a list of the elements of SEQUENCE with duplicates removed. TESTFN is used to compare elements, or `equal' if TESTFN is nil." diff --git a/lisp/eshell/em-pred.el b/lisp/eshell/em-pred.el index b0a7544bdab..0780d6ee83a 100644 --- a/lisp/eshell/em-pred.el +++ b/lisp/eshell/em-pred.el @@ -130,7 +130,7 @@ The format of each entry is (?e . (lambda (lst) (mapcar #'file-name-extension lst))) (?t . (lambda (lst) (mapcar #'file-name-nondirectory lst))) (?q . (lambda (lst) (mapcar #'eshell-escape-arg lst))) - (?u . (lambda (lst) (eshell-uniquify-list lst))) + (?u . (lambda (lst) (seq-uniq lst))) (?o . (lambda (lst) (sort lst #'string-lessp))) (?O . (lambda (lst) (nreverse (sort lst #'string-lessp)))) (?j . (eshell-join-members)) diff --git a/lisp/eshell/esh-util.el b/lisp/eshell/esh-util.el index 1dcbed3d961..a48f62654d5 100644 --- a/lisp/eshell/esh-util.el +++ b/lisp/eshell/esh-util.el @@ -291,20 +291,6 @@ Prepend remote identification of `default-directory', if any." (define-obsolete-function-alias 'eshell-flatten-list #'flatten-tree "27.1") -(defun eshell-uniquify-list (l) - "Remove occurring multiples in L. You probably want to sort first." - (let ((m l)) - (while m - (while (and (cdr m) - (string= (car m) - (cadr m))) - (setcdr m (cddr m))) - (setq m (cdr m)))) - l) -(define-obsolete-function-alias - 'eshell-uniqify-list - 'eshell-uniquify-list "27.1") - (defun eshell-stringify (object) "Convert OBJECT into a string value." (cond @@ -700,6 +686,8 @@ gid format. Valid values are `string' and `integer', defaulting to ;; Obsolete. +(define-obsolete-function-alias 'eshell-uniquify-list #'seq-uniq "28.1") +(define-obsolete-function-alias 'eshell-uniqify-list #'seq-uniq "28.1") (define-obsolete-function-alias 'eshell-copy-tree #'copy-tree "28.1") (define-obsolete-function-alias 'eshell-user-name #'user-login-name "28.1") diff --git a/lisp/nxml/rng-loc.el b/lisp/nxml/rng-loc.el index d5a608d6ff2..a38da794226 100644 --- a/lisp/nxml/rng-loc.el +++ b/lisp/nxml/rng-loc.el @@ -182,7 +182,7 @@ If TYPE-ID is non-nil, then locate the schema for this TYPE-ID." (while files (setq type-ids (rng-possible-type-ids-using (car files) type-ids)) (setq files (cdr files))) - (rng-uniquify-equal (sort type-ids 'string<)))) + (seq-uniq (sort type-ids 'string<)))) (defun rng-locate-schema-file-using (files) "Locate a schema using the schema locating files FILES. diff --git a/lisp/nxml/rng-match.el b/lisp/nxml/rng-match.el index 4fc6727d0e6..7a2739c0616 100644 --- a/lisp/nxml/rng-match.el +++ b/lisp/nxml/rng-match.el @@ -472,7 +472,7 @@ list is nullable and whose cdr is the normalized list." (cons nullable (if sorted head - (rng-uniquify-eq (sort head 'rng-compare-ipattern)))))) + (seq-uniq (sort head 'rng-compare-ipattern) #'eq))))) (defun rng-compare-ipattern (p1 p2) (< (rng--ipattern-index p1) diff --git a/lisp/nxml/rng-nxml.el b/lisp/nxml/rng-nxml.el index 7ea6fb2e49d..33768a46c94 100644 --- a/lisp/nxml/rng-nxml.el +++ b/lisp/nxml/rng-nxml.el @@ -522,7 +522,7 @@ set `xmltok-dtd'. Returns the position of the end of the token." (unless attribute-flag (setcdr ns-prefixes (cons nil (cdr ns-prefixes)))))) (setq iter (cdr iter))) - (rng-uniquify-equal + (seq-uniq (sort (apply #'append (cons extra-strings (mapcar (lambda (name) diff --git a/lisp/nxml/rng-util.el b/lisp/nxml/rng-util.el index a20e95086cb..67e2ee9f1e3 100644 --- a/lisp/nxml/rng-util.el +++ b/lisp/nxml/rng-util.el @@ -36,26 +36,6 @@ (defconst rng-builtin-datatypes-uri (rng-make-datatypes-uri "")) -(defun rng-uniquify-eq (list) - "Destructively remove `eq' duplicates from LIST." - (and list - (let ((head list)) - (while (cdr head) - (if (eq (car head) (cadr head)) - (setcdr head (cddr head))) - (setq head (cdr head))) - list))) - -(defun rng-uniquify-equal (list) - "Destructively remove `equal' duplicates from LIST." - (and list - (let ((head list)) - (while (cdr head) - (if (equal (car head) (cadr head)) - (setcdr head (cddr head))) - (setq head (cdr head))) - list))) - (defun rng-blank-p (str) (string-match "\\`[ \t\n\r]*\\'" str)) (defun rng-substq (new old list) @@ -104,6 +84,14 @@ LIST is not modified." (define-error 'rng-error nil) +;; Obsolete. + +(defun rng-uniquify-eq (list) + (declare (obsolete seq-uniq "28.1")) + (seq-uniq list #'eq)) + +(define-obsolete-function-alias 'rng-uniquify-equal #'seq-uniq "28.1") + (provide 'rng-util) ;;; rng-util.el ends here diff --git a/lisp/pcomplete.el b/lisp/pcomplete.el index b648ecf0986..bffdcaa2de0 100644 --- a/lisp/pcomplete.el +++ b/lisp/pcomplete.el @@ -1260,18 +1260,9 @@ If specific documentation can't be given, be generic." (defun pcomplete-uniquify-list (l) "Sort and remove multiples in L." - (setq l (sort l 'string-lessp)) - (let ((m l)) - (while m - (while (and (cdr m) - (string= (car m) - (cadr m))) - (setcdr m (cddr m))) - (setq m (cdr m)))) - l) -(define-obsolete-function-alias - 'pcomplete-uniqify-list - 'pcomplete-uniquify-list "27.1") + (setq l (sort l #'string-lessp)) + (seq-uniq l)) +(define-obsolete-function-alias 'pcomplete-uniqify-list #'pcomplete-uniquify-list "27.1") (defun pcomplete-process-result (cmd &rest args) "Call CMD using `call-process' and return the simplest result." diff --git a/lisp/progmodes/idlwave.el b/lisp/progmodes/idlwave.el index f53f3f3b995..75f2016fc24 100644 --- a/lisp/progmodes/idlwave.el +++ b/lisp/progmodes/idlwave.el @@ -7601,15 +7601,6 @@ associated TAG, if any." (put-text-property (match-beginning 0) (match-end 0) 'face 'font-lock-string-face)))))) -(defun idlwave-uniquify (list) - (let ((ht (make-hash-table :size (length list) :test 'equal))) - (delq nil - (mapcar (lambda (x) - (unless (gethash x ht) - (puthash x t ht) - x)) - list)))) - (defun idlwave-after-successful-completion (type slash &optional verify) "Add `=' or `(' after successful completion of keyword and function. Restore the pre-completion window configuration if possible." @@ -9101,6 +9092,9 @@ This function was written since `list-abbrevs' looks terrible for IDLWAVE mode." ;; Run the hook (run-hooks 'idlwave-load-hook) +;; Obsolete. +(define-obsolete-function-alias 'idlwave-uniquify #'seq-uniq "28.1") + (provide 'idlwave) ;;; idlwave.el ends here diff --git a/lisp/textmodes/artist.el b/lisp/textmodes/artist.el index 22ade15921d..fbb9d2174fd 100644 --- a/lisp/textmodes/artist.el +++ b/lisp/textmodes/artist.el @@ -1753,13 +1753,6 @@ info-variant-part." "Call function FN with ARGS, if FN is not nil." `(if ,fn (funcall ,fn ,@args))) -(defun artist-uniq (l) - "Remove consecutive duplicates in list L. Comparison is done with `equal'." - (cond ((null l) nil) - ((null (cdr l)) l) ; only one element in list - ((equal (car l) (car (cdr l))) (artist-uniq (cdr l))) ; first 2 equal - (t (cons (car l) (artist-uniq (cdr l)))))) ; first 2 are different - (defun artist-string-split (str r) "Split string STR at occurrences of regexp R, returning a list of strings." (let ((res nil) @@ -2761,7 +2754,7 @@ to append to the end of the list, when doing free-hand drawing)." Also, the `artist-key-poly-point-list' is reversed." (setq artist-key-poly-point-list - (artist-uniq artist-key-poly-point-list)) + (seq-uniq artist-key-poly-point-list)) (if (>= (length artist-key-poly-point-list) 2) @@ -5372,10 +5365,7 @@ The event, EV, is the mouse event." (concat "Hello Tomas,\n\n" "I have a nice bug report on Artist for you! Here it is:"))))) - -;; -;; Now provide this minor mode -;; +(define-obsolete-function-alias 'artist-uniq #'seq-uniq "28.1") (provide 'artist) -- cgit v1.2.3