From 30e4f3280bdbb82e10be0cf6a5dc68863b13fb80 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sat, 28 Aug 2021 19:07:45 +0800 Subject: * common.el (durand-take): Convenient function --- common.el | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/common.el b/common.el index 75fe201..0b3df31 100644 --- a/common.el +++ b/common.el @@ -450,8 +450,26 @@ current line; negative ARG means to put the line upwards." (num)))) (insert "\n" line))))) +;;; A minor helper function + +;;;###autoload +(defun durand-take (n ls) + "Return the first N items of LS. +If the length of LS is less than N, then return the whole LS." + (cond + ((< (length ls) n) ls) + ((let ((i 0) result) + (while (< i n) + (cond + (ls + (setq result (cons (car ls) result)) + (setq ls (cdr ls)) + (setq i (1+ i))) + ((setq i n)))) + (reverse result))))) + (provide 'common) -;;; common.el ends here. +;; common.el ends here. -- cgit v1.2.3-18-g5258