[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 50d96b95f0 1/2: Use ntake in Tramp
From: |
Michael Albinus |
Subject: |
master 50d96b95f0 1/2: Use ntake in Tramp |
Date: |
Mon, 18 Jul 2022 09:48:28 -0400 (EDT) |
branch: master
commit 50d96b95f0aa7e81309d5a4684ef1239d9b4c3fa
Author: Michael Albinus <michael.albinus@gmx.de>
Commit: Michael Albinus <michael.albinus@gmx.de>
Use ntake in Tramp
* lisp/net/tramp-compat.el (tramp-compat-ntake): New defalias.
* lisp/net/tramp.el (tramp-handle-directory-files):
* lisp/net/tramp-crypt.el (tramp-crypt-handle-directory-files):
* lisp/net/tramp-sh.el (tramp-sh-handle-directory-files-and-attributes):
* lisp/net/tramp-smb.el (tramp-smb-handle-directory-files): Use it.
---
lisp/net/tramp-compat.el | 9 +++++++++
lisp/net/tramp-crypt.el | 2 +-
lisp/net/tramp-sh.el | 2 +-
lisp/net/tramp-smb.el | 2 +-
lisp/net/tramp.el | 2 +-
5 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el
index a12e4859ac..1286255c89 100644
--- a/lisp/net/tramp-compat.el
+++ b/lisp/net/tramp-compat.el
@@ -294,6 +294,15 @@ CONDITION can also be a list of error conditions."
(setq secret (funcall secret)))
secret))))
+;; Function `ntake' is new in Emacs 29.1.
+(defalias 'tramp-compat-ntake
+ (if (fboundp 'ntake)
+ #'ntake
+ (lambda (n list)
+ (when (and (natnump n) (> n 0))
+ (if (>= n (length list))
+ list (nbutlast list (- (length list) n)))))))
+
(dolist (elt (all-completions "tramp-compat-" obarray 'functionp))
(put (intern elt) 'tramp-suppress-trace t))
diff --git a/lisp/net/tramp-crypt.el b/lisp/net/tramp-crypt.el
index 6cb1237a0f..f45c303ab1 100644
--- a/lisp/net/tramp-crypt.el
+++ b/lisp/net/tramp-crypt.el
@@ -730,7 +730,7 @@ absolute file names."
(unless nosort
(setq result (sort result #'string<)))
(when (and (natnump count) (> count 0))
- (setq result (nbutlast result (- (length result) count))))
+ (setq result (tramp-compat-ntake count result)))
result)))
(defun tramp-crypt-handle-file-attributes (filename &optional id-format)
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 174fde720e..e772af9e0a 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -1718,7 +1718,7 @@ ID-FORMAT valid values are `string' and `integer'."
(setq result (sort result (lambda (x y) (string< (car x) (car y))))))
(when (and (natnump count) (> count 0))
- (setq result (nbutlast result (- (length result) count))))
+ (setq result (tramp-compat-ntake count result)))
(or result
;; The scripts could fail, for example with huge file size.
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el
index b717c4dcc3..5789b8f947 100644
--- a/lisp/net/tramp-smb.el
+++ b/lisp/net/tramp-smb.el
@@ -726,7 +726,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are
completely ignored."
;; Return count number of results.
(when (and (natnump count) (> count 0))
- (setq result (nbutlast result (- (length result) count))))
+ (setq result (tramp-compat-ntake count result)))
;; Prepend directory.
(when full
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 0198aacf15..da2fa4c5ac 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -3623,7 +3623,7 @@ Let-bind it when necessary.")
(unless nosort
(setq result (sort result #'string<)))
(when (and (natnump count) (> count 0))
- (setq result (nbutlast result (- (length result) count))))
+ (setq result (tramp-compat-ntake count result)))
result)))
(defun tramp-handle-directory-files-and-attributes