summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2021-08-28 19:07:45 +0800
committerJSDurand <mmemmew@gmail.com>2021-08-28 19:07:45 +0800
commit30e4f3280bdbb82e10be0cf6a5dc68863b13fb80 (patch)
treed22d3b8e90d6a193b57ceef0da9e1cd90b289c1d
parentd88aaabf6d40349c3d20ffa96fbba603e1075b04 (diff)
* common.el (durand-take): Convenient function
-rw-r--r--common.el20
1 files changed, 19 insertions, 1 deletions
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.