From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Michael Albinus Newsgroups: gmane.emacs.bugs Subject: bug#33309: Add flatten-list? Date: Tue, 11 Dec 2018 09:21:14 +0100 Message-ID: <87a7lccw3p.fsf@gmx.de> References: <87r2fw7jsa.fsf@gmail.com> <058f4a0f-7ce4-49c4-ae54-0bc259bd82d1@default> <87pnvg7fgg.fsf@gmail.com> <8736r5ojnc.fsf@gmx.de> <87sgz5m98k.fsf@gmail.com> <87tvjl80mx.fsf@tcd.ie> <87pnu9m0ou.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1544516417 12407 195.159.176.226 (11 Dec 2018 08:20:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 11 Dec 2018 08:20:17 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: "Basil L. Contovounesios" , 33309@debbugs.gnu.org, Stefan Monnier To: Alex Branham Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Dec 11 09:20:13 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gWdH1-00036O-Qf for geb-bug-gnu-emacs@m.gmane.org; Tue, 11 Dec 2018 09:20:12 +0100 Original-Received: from localhost ([::1]:36508 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWdJ7-0003Uq-TZ for geb-bug-gnu-emacs@m.gmane.org; Tue, 11 Dec 2018 03:22:21 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43425) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWdIt-0003UZ-N0 for bug-gnu-emacs@gnu.org; Tue, 11 Dec 2018 03:22:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWdIo-00066W-C2 for bug-gnu-emacs@gnu.org; Tue, 11 Dec 2018 03:22:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:38489) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gWdIo-00066G-73 for bug-gnu-emacs@gnu.org; Tue, 11 Dec 2018 03:22:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gWdIo-0000t8-19 for bug-gnu-emacs@gnu.org; Tue, 11 Dec 2018 03:22:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Michael Albinus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 11 Dec 2018 08:22:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 33309 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 33309-submit@debbugs.gnu.org id=B33309.15445164923378 (code B ref 33309); Tue, 11 Dec 2018 08:22:01 +0000 Original-Received: (at 33309) by debbugs.gnu.org; 11 Dec 2018 08:21:32 +0000 Original-Received: from localhost ([127.0.0.1]:42747 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gWdIK-0000sQ-0L for submit@debbugs.gnu.org; Tue, 11 Dec 2018 03:21:32 -0500 Original-Received: from mout.gmx.net ([212.227.17.21]:46233) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gWdIH-0000sC-W9 for 33309@debbugs.gnu.org; Tue, 11 Dec 2018 03:21:30 -0500 Original-Received: from detlef.gmx.de ([212.86.54.154]) by mail.gmx.com (mrgmx101 [212.227.17.168]) with ESMTPSA (Nemesis) id 0M2ojS-1hLqnb02qc-00sd7e; Tue, 11 Dec 2018 09:21:17 +0100 In-Reply-To: <87pnu9m0ou.fsf@gmail.com> (Alex Branham's message of "Mon, 10 Dec 2018 17:17:21 -0600") X-Provags-ID: V03:K1:FbI+Ku6y/cqCsFo09Kaqot2QODmeT/YNMrNNjG0EhIhB71mX93E 1MoAihftHurBjLcMQxf+j/kGpQ5o3FumeCZz15BAsSl7Qi2UDDJjnDCiERHCuiPu9N6gpUR tKlppFzJAbtYhYYWq586za7KgvANyTmnRCJQYwDSQZlqbQjAIUjieNxIk/rNVIR2CE3R9vR MU7H76EglbgEf7Jixyjqw== X-UI-Out-Filterresults: notjunk:1;V03:K0:onbZOa4dTCE=:ujlsG6P8SSZ9+0EiI6Lzwv vta0f2ZpyMELs2UYCfhgjuhC4WHIvLllEAG15TXT4BP1vlRNGz7uPcEntytkqpi9k5nIQG/EU S35k4TVTlQklYEhHfBrybjuqx0RHYOqMO8wqWW2cCpL7pIuIaYCz+XPtUChghlGYRTAlS/jEC uDnVsZtOVYt6IfoxTZUMHjlMUywddSMoq0fheHA/4jJ9//nfUOiDn1pHq/0RpFgXuf46304h6 AX64YGEkBRkHKT+sSNs+PrRM/+pK2yyrL7OkjT/N+p3VExh39L6ypkPcR6vCayImgFTdwV3YG 2d0HX4eg5xl3JaPc7VBr43enJOixquMme3jmxLtRK0cVNaw0F6no8MvPJQNniEwpkv0iP3R9a LMEWeVVhUFCoEFyOd9ZxSS/f9cCZmU7WUoNeGlI+qGe4zyv6rGEdhFSazsTQU8ONhTV7Q7eZo djSFO3wGdi7SorDWwEPm3t94y/E0bR2rO6w07a968IRkHzu5hqjizjZc7Poeb5ir4E1Z5TFKP se8Do7B92XtTkavBfbWRv35j8k6eg5bLzDF0pkV7K3nD5FDdtNim/qFIuyWcHA5Z6PJg8ps7p UHgZoM1XfLf3GlfGrN6g6h+UpL5yD/VnZp2Ha6AD/8Aj8Snj100NW4G5zvO4eUUDTTsmZA8Y9 GTZPSGIUbYWwWnhvZA6ca7ew/w9pUBpn4sNV0zHGvvJTSjwV/gkH6CoXp5qPItd/O4JfLRfCb pRTLw1nKJEFwBvrchlDxLnxLV9pQ90Zue65JQnpG1bR3BT/wRY3MJNRR61w8qBH8tY1qw37w X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:153347 Archived-At: Alex Branham writes: Hi Alex, > Yes, that does seem better, updated patch attached. I also updated the > docstring to explicitly state how it handles nil values and dotted > pairs. The docstring doesn't say what happens if TREE isn't a list. Something like (flatten-tree 42) => (42) I'm wondering also, whether we shall make removing nil elements optional: (defun flatten-tree (tree &optional omit-nil) ... Or, if we expect that removing nil elements shall be default: (defun flatten-tree (tree &optional keep-nil) ... > lisp/eshell/em-basic.el | 2 +- > lisp/eshell/em-dirs.el | 4 ++-- > lisp/eshell/em-term.el | 2 +- > lisp/eshell/em-tramp.el | 4 ++-- > lisp/eshell/em-unix.el | 22 +++++++++++----------- > lisp/eshell/em-xtra.el | 2 +- > lisp/eshell/esh-ext.el | 2 +- > lisp/eshell/esh-opt.el | 4 ++-- > lisp/eshell/esh-util.el | 12 ++---------- > lisp/gnus/gnus-sum.el | 10 +++++----- > lisp/gnus/message.el | 12 ++---------- > lisp/gnus/nnimap.el | 2 +- > lisp/lpr.el | 20 ++------------------ > lisp/net/tramp-compat.el | 13 +------------ > lisp/printing.el | 2 +- > lisp/progmodes/js.el | 8 ++------ > lisp/subr.el | 20 ++++++++++++++++++++ > test/lisp/subr-tests.el | 13 +++++++++++++ I suppose we need also an entry in etc/NEWS and doc/lispref/lists.texi. > diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el > index 046966e019..4f99a31e54 100644 > --- a/lisp/net/tramp-compat.el > +++ b/lisp/net/tramp-compat.el > @@ -270,18 +270,7 @@ tramp-compat-use-url-tramp-p > (unload-feature 'tramp-loaddefs 'force) > (unload-feature 'tramp-compat 'force))) > > -;; There does not exist a common `flatten-list' yet, this is discussed > -;; in Bug#33309. For the time being we implement our own version, > -;; derived from `eshell-flatten-list'. > -(defun tramp-compat-flatten-list (args) > - "Flatten any lists within ARGS, so that there are no sublists." > - (let ((new-list (list t))) > - (dolist (a args) > - (if (and (listp a) > - (listp (cdr a))) > - (nconc new-list (tramp-compat-flatten-list a)) > - (nconc new-list (list a)))) > - (cdr new-list))) > +(define-obsolete-function-alias 'tramp-compat-flatten-list #'flatten-tree "27.1") > > (provide 'tramp-compat) Please don't do this. Tramp must support Emacs back to version 24. Once flatten-tree has hit the git repository, I'll modify tramp-compat.el accordingly. > --- a/test/lisp/subr-tests.el > +++ b/test/lisp/subr-tests.el > @@ -372,5 +372,18 @@ subr-test--frames-1 > (shell-quote-argument "%ca%"))) > "without-caret %ca%")))) > > +(ert-deftest subr-tests-flatten-tree () > + "Test `flatten-tree' behavior." > + (should (equal (flatten-tree '(1 (2 . 3) nil (4 5 (6)) 7)) > + '(1 2 3 4 5 6 7))) > + (should (equal (flatten-tree '((1 . 2))) > + '(1 2))) > + (should (equal (flatten-tree '(1 nil 2)) > + '(1 2))) > + (should (equal (flatten-tree 42) > + '(42))) > + (should (equal (flatten-tree '(1 ("foo" "bar") 2)) > + '(1 "foo" "bar" 2)))) > + > (provide 'subr-tests) > ;;; subr-tests.el ends here I would also add (should (equal (flatten-tree t) '(t))) (should (equal (flatten-tree nil) nil)) > Alex Best regards, Michael.