diff --git a/lisp/subr.el b/lisp/subr.el index ea926ae..976e4fd 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -405,6 +405,19 @@ nbutlast (if (> n 0) (setcdr (nthcdr (- (1- m) n) list) nil)) list)))) +(defun front(list &optional n) + "Return a copy of LIST with just the first N elements. +If N is omitted or nil the full list is copied." +(let ((m (length list))) + (if (and n (<= n 0)) list + (nfront (copy-sequence list) n)))) + +(defun nfront(list &optional n) + "Modified LIST to remove all elements but the first N. +If N is omitted or nil the full list is copied." + (if (or (null n) (and n (<= n 0))) list + (nreverse (last (nreverse list) n)))) + (defun zerop (number) "Return t if NUMBER is zero." ;; Used to be in C, but it's pointless since (= 0 n) is faster anyway because