diff options
| author | Stefan Monnier | 2019-10-27 13:25:00 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2019-10-27 13:25:00 -0400 |
| commit | 0e4dd67aae8b10032317a29a6bd99d2d4a64c897 (patch) | |
| tree | 829c1831b9aa97cb8ab2819d5587d4b2fb10b846 | |
| parent | 2aaced16866f8b17ee109a0c5682b3896e713f5c (diff) | |
| download | emacs-0e4dd67aae8b10032317a29a6bd99d2d4a64c897.tar.gz emacs-0e4dd67aae8b10032317a29a6bd99d2d4a64c897.zip | |
* lisp/emacs-lisp/seq.el: Don't require cl-lib.
(seq-subseq): Move cl-subseq's code here instyead of calling it.
* lisp/emacs-lisp/cl-extra.el (cl-subseq): Use seq-subseq.
| -rw-r--r-- | lisp/emacs-lisp/cl-extra.el | 22 | ||||
| -rw-r--r-- | lisp/emacs-lisp/seq.el | 23 |
2 files changed, 23 insertions, 22 deletions
diff --git a/lisp/emacs-lisp/cl-extra.el b/lisp/emacs-lisp/cl-extra.el index 3a6def733f3..91034de5396 100644 --- a/lisp/emacs-lisp/cl-extra.el +++ b/lisp/emacs-lisp/cl-extra.el | |||
| @@ -38,6 +38,7 @@ | |||
| 38 | ;;; Code: | 38 | ;;; Code: |
| 39 | 39 | ||
| 40 | (require 'cl-lib) | 40 | (require 'cl-lib) |
| 41 | (require 'seq) | ||
| 41 | 42 | ||
| 42 | ;;; Type coercion. | 43 | ;;; Type coercion. |
| 43 | 44 | ||
| @@ -549,26 +550,7 @@ too large if positive or too small if negative)." | |||
| 549 | (macroexp-let2 nil new new | 550 | (macroexp-let2 nil new new |
| 550 | `(progn (cl-replace ,seq ,new :start1 ,start :end1 ,end) | 551 | `(progn (cl-replace ,seq ,new :start1 ,start :end1 ,end) |
| 551 | ,new))))) | 552 | ,new))))) |
| 552 | (cond ((or (stringp seq) (vectorp seq)) (substring seq start end)) | 553 | (seq-subseq seq start end)) |
| 553 | ((listp seq) | ||
| 554 | (let (len | ||
| 555 | (errtext (format "Bad bounding indices: %s, %s" start end))) | ||
| 556 | (and end (< end 0) (setq end (+ end (setq len (length seq))))) | ||
| 557 | (if (< start 0) (setq start (+ start (or len (setq len (length seq)))))) | ||
| 558 | (unless (>= start 0) | ||
| 559 | (error "%s" errtext)) | ||
| 560 | (when (> start 0) | ||
| 561 | (setq seq (nthcdr (1- start) seq)) | ||
| 562 | (or seq (error "%s" errtext)) | ||
| 563 | (setq seq (cdr seq))) | ||
| 564 | (if end | ||
| 565 | (let ((res nil)) | ||
| 566 | (while (and (>= (setq end (1- end)) start) seq) | ||
| 567 | (push (pop seq) res)) | ||
| 568 | (or (= (1+ end) start) (error "%s" errtext)) | ||
| 569 | (nreverse res)) | ||
| 570 | (copy-sequence seq)))) | ||
| 571 | (t (error "Unsupported sequence: %s" seq)))) | ||
| 572 | 554 | ||
| 573 | ;;;###autoload | 555 | ;;;###autoload |
| 574 | (defun cl-concatenate (type &rest sequences) | 556 | (defun cl-concatenate (type &rest sequences) |
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el index 918b0dcd390..9a5872c094b 100644 --- a/lisp/emacs-lisp/seq.el +++ b/lisp/emacs-lisp/seq.el | |||
| @@ -57,7 +57,6 @@ | |||
| 57 | ;;; Code: | 57 | ;;; Code: |
| 58 | 58 | ||
| 59 | (eval-when-compile (require 'cl-generic)) | 59 | (eval-when-compile (require 'cl-generic)) |
| 60 | (require 'cl-lib) ;; for cl-subseq | ||
| 61 | 60 | ||
| 62 | (defmacro seq-doseq (spec &rest body) | 61 | (defmacro seq-doseq (spec &rest body) |
| 63 | "Loop over a sequence. | 62 | "Loop over a sequence. |
| @@ -151,7 +150,27 @@ If END is omitted, it defaults to the length of the sequence. If | |||
| 151 | START or END is negative, it counts from the end. Signal an | 150 | START or END is negative, it counts from the end. Signal an |
| 152 | error if START or END are outside of the sequence (i.e too large | 151 | error if START or END are outside of the sequence (i.e too large |
| 153 | if positive or too small if negative)." | 152 | if positive or too small if negative)." |
| 154 | (cl-subseq sequence start end)) | 153 | (cond |
| 154 | ((or (stringp sequence) (vectorp sequence)) (substring sequence start end)) | ||
| 155 | ((listp sequence) | ||
| 156 | (let (len | ||
| 157 | (errtext (format "Bad bounding indices: %s, %s" start end))) | ||
| 158 | (and end (< end 0) (setq end (+ end (setq len (length sequence))))) | ||
| 159 | (if (< start 0) (setq start (+ start (or len (setq len (length sequence)))))) | ||
| 160 | (unless (>= start 0) | ||
| 161 | (error "%s" errtext)) | ||
| 162 | (when (> start 0) | ||
| 163 | (setq sequence (nthcdr (1- start) sequence)) | ||
| 164 | (or sequence (error "%s" errtext)) | ||
| 165 | (setq sequence (cdr sequence))) | ||
| 166 | (if end | ||
| 167 | (let ((res nil)) | ||
| 168 | (while (and (>= (setq end (1- end)) start) sequence) | ||
| 169 | (push (pop sequence) res)) | ||
| 170 | (or (= (1+ end) start) (error "%s" errtext)) | ||
| 171 | (nreverse res)) | ||
| 172 | (copy-sequence sequence)))) | ||
| 173 | (t (error "Unsupported sequence: %s" sequence)))) | ||
| 155 | 174 | ||
| 156 | 175 | ||
| 157 | (cl-defgeneric seq-map (function sequence) | 176 | (cl-defgeneric seq-map (function sequence) |