From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.devel Subject: dired and ls (was: Human-readable file sorting) Date: Sat, 20 Feb 2016 17:16:09 +1100 Message-ID: <87mvqvewk6.fsf_-_@gnus.org> References: <87povs41xg.fsf@gnus.org> <87bn7c3yms.fsf@gnus.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1455949025 22851 80.91.229.3 (20 Feb 2016 06:17:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 20 Feb 2016 06:17:05 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Feb 20 07:16:55 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aX0qc-0006Yq-3o for ged-emacs-devel@m.gmane.org; Sat, 20 Feb 2016 07:16:54 +0100 Original-Received: from localhost ([::1]:58495 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX0qb-0004hV-BB for ged-emacs-devel@m.gmane.org; Sat, 20 Feb 2016 01:16:53 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35098) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX0qO-0004gM-Va for emacs-devel@gnu.org; Sat, 20 Feb 2016 01:16:42 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aX0qL-0007Is-Pc for emacs-devel@gnu.org; Sat, 20 Feb 2016 01:16:40 -0500 Original-Received: from hermes.netfonds.no ([80.91.224.195]:48442) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX0qL-0007Io-JM for emacs-devel@gnu.org; Sat, 20 Feb 2016 01:16:37 -0500 Original-Received: from cpe-60-225-211-161.nsw.bigpond.net.au ([60.225.211.161] helo=mouse) by hermes.netfonds.no with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1aX0px-0007g5-ON for emacs-devel@gnu.org; Sat, 20 Feb 2016 07:16:14 +0100 In-Reply-To: (John Wiegley's message of "Fri, 19 Feb 2016 18:33:26 -0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) X-MailScanner-ID: 1aX0px-0007g5-ON MailScanner-NULL-Check: 1456553776.24038@uC3Gw/AGgYCoJSCdJXynBQ X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.224.195 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:200273 Archived-At: This all reminds me of something I forgot to prattle on about in that dired bug report: ls-lisp.el. dired (on Unixey systems) uses "ls" to get the contents of directories, and then parses the results. And generates a buffer. Not all systems have "ls", so in that case it uses ls-lisp.el, which just calls directory-files and then file-attributes in a loop. I think this is rather suboptimal for many reasons: 1) dired look unnecessarily different on different systems 2) the customisability is limited -- both the look of the buffers and the sorting is limited by what the native "ls" returns 3) Reasons! So many reasons! I've asked "but why" before, but the only response I can remember is "ls is faster". Which may be true! (I may be misremembering this being the only answer.) Because `directory-files' uses opendir/readdir first to get the file names, and then we have to stat each and every file just to find out whether they're files or directories. If we instead had `directory-files-with-attributes' in C, we could just do what "ls" does, which is... opening the directory, reading it, and then statting all the files. (I just straced "ls -l".) So it should be just as fast? I think? And if you have your dired set up not to show ownership, date or file permissions, you don't even have to stat anything on Linux/BSD -- the d_type says whether something is a file or a directory directly. Hm... and there are a lot of functions in Emacs that only wants to know the file name and whether it's a directory or not... I mean, basically every file prompting function only needs that info... -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no