[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master e99d7c4d62 1/2: Simplify code using take, ntake and butlast
From: |
Mattias Engdegård |
Subject: |
master e99d7c4d62 1/2: Simplify code using take, ntake and butlast |
Date: |
Sun, 14 Aug 2022 09:49:29 -0400 (EDT) |
branch: master
commit e99d7c4d627c1f9b4b26e3890fb3b39f74234d79
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>
Simplify code using take, ntake and butlast
* lisp/calc/calc-vec.el (calcFunc-rhead):
* lisp/calc/calc.el (calc-top-list, calc-pop):
* lisp/emacs-lisp/ert.el (ert-summarize-tests-batch-and-exit):
Simplify.
---
lisp/calc/calc-vec.el | 4 +---
lisp/calc/calc.el | 12 +++---------
lisp/emacs-lisp/ert.el | 3 +--
lisp/progmodes/gdb-mi.el | 5 ++---
4 files changed, 7 insertions(+), 17 deletions(-)
diff --git a/lisp/calc/calc-vec.el b/lisp/calc/calc-vec.el
index 3b8629b797..8d99f62a9b 100644
--- a/lisp/calc/calc-vec.el
+++ b/lisp/calc/calc-vec.el
@@ -647,9 +647,7 @@
(defun calcFunc-rhead (vec)
(if (and (Math-vectorp vec)
(cdr vec))
- (let ((vec (copy-sequence vec)))
- (setcdr (nthcdr (- (length vec) 2) vec) nil)
- vec)
+ (butlast vec)
(calc-record-why 'vectorp vec)
(list 'calcFunc-rhead vec)))
diff --git a/lisp/calc/calc.el b/lisp/calc/calc.el
index 254c703ee2..6c21430b1b 100644
--- a/lisp/calc/calc.el
+++ b/lisp/calc/calc.el
@@ -1959,12 +1959,8 @@ See calc-keypad for details."
(or n (setq n 1))
(or m (setq m 1))
(calc-check-stack (+ n m -1))
- (and (> n 0)
- (let ((top (copy-sequence (nthcdr (+ m calc-stack-top -1)
- calc-stack))))
- (setcdr (nthcdr (1- n) top) nil)
- (nreverse
- (mapcar (lambda (x) (calc-get-stack-element x sel-mode)) top)))))
+ (nreverse (mapcar (lambda (x) (calc-get-stack-element x sel-mode))
+ (take n (nthcdr (+ m calc-stack-top -1) calc-stack)))))
(defun calc-top-list-n (&optional n m sel-mode)
(mapcar #'math-check-complete
@@ -2291,9 +2287,7 @@ the United States."
((and (null n)
(eq (car-safe top) 'incomplete)
(> (length top) (if (eq (nth 1 top) 'intv) 3 2)))
- (calc-pop-push-list 1 (let ((tt (copy-sequence top)))
- (setcdr (nthcdr (- (length tt) 2) tt)
nil)
- (list tt))))
+ (calc-pop-push-list 1 (list (butlast top))))
((< nn 0)
(if (and calc-any-selections
(calc-top-selected 1 (- nn)))
diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el
index c8ff6b6814..047b0069bb 100644
--- a/lisp/emacs-lisp/ert.el
+++ b/lisp/emacs-lisp/ert.el
@@ -1813,8 +1813,7 @@ Ran \\([0-9]+\\) tests, \\([0-9]+\\) results as expected\
(unless (or (null tests) (zerop high))
(message "\nLONG-RUNNING TESTS")
(message "------------------")
- (setq tests (sort tests (lambda (x y) (> (car x) (car y)))))
- (when (< high (length tests)) (setcdr (nthcdr (1- high) tests) nil))
+ (setq tests (ntake high (sort tests (lambda (x y) (> (car x) (car y))))))
(message "%s" (mapconcat #'cdr tests "\n")))
;; More details on hydra and emba, where the logs are harder to get to.
(when (and (or (getenv "EMACS_HYDRA_CI") (getenv "EMACS_EMBA_CI"))
diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index 6f67eff31a..c256198b3c 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -2512,9 +2512,8 @@ means to decode using the coding-system set for the GDB
process."
;; Record transactions if logging is enabled.
(when gdb-enable-debug
(push (cons 'recv string) gdb-debug-log)
- (if (and gdb-debug-log-max
- (> (length gdb-debug-log) gdb-debug-log-max))
- (setcdr (nthcdr (1- gdb-debug-log-max) gdb-debug-log) nil)))
+ (when gdb-debug-log-max
+ (setq gdb-debug-log (ntake gdb-debug-log-max gdb-debug-log))))
;; Recall the left over gud-marker-acc from last time.
(setq gud-marker-acc (concat gud-marker-acc string))