Could we add a new function `flatten-list'? There seems to be a need for it. Inside Emacs itself, I see at least four implementations of the same basic thing: - eshell-flatten-list - message-flatten-list - lpr-flatten-list - js--flatten-list And there are many more in the various 3rd-party packages. I was thinking of putting it in subr.el. What do you think? Thanks, Alex diff --git a/lisp/subr.el b/lisp/subr.el index 41dc9aa45f..3ea75ddf56 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -5447,5 +5447,14 @@ This function is called from lisp/Makefile and leim/Makefile." (setq file (concat (substring file 1 2) ":" (substring file 2)))) file) +(defun flatten-list (list) + "Take LIST and \"flatten\" it. +The result will be a list containing all the elements of LIST. +\(flatten-list \\='(1 (2 3 (4 5 (6))) 7)) +=> (1 2 3 4 5 6 7)" + (cond ((null list) nil) + ((consp list) (append (flatten-list (car list)) + (flatten-list (cdr list)))) + (t (list list)))) ;;; subr.el ends here