From: Michael Albinus Date: Mon, 18 Jul 2022 13:47:28 +0000 (+0200) Subject: Use ntake in Tramp X-Git-Tag: emacs-29.0.90~1447^2~864 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=50d96b95f0aa7e81309d5a4684ef1239d9b4c3fa;p=emacs.git 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. --- diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el index a12e4859ac4..1286255c898 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 6cb1237a0f4..f45c303ab12 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 174fde720e4..e772af9e0a1 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 b717c4dcc38..5789b8f9474 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 0198aacf15a..da2fa4c5acd 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