News for hackers. Stuff that matters.
Re:Why you shouldn't parse the output of ls(1) by SassyBird on Saturday June 15, 2024 @10:07PM (#40694178)
When would you use it?

Emacs dired works fine on other platforms, which don’t have GNU ls on them, so I’m guessing by default it doesn’t run ls on its own.

Re:Why you shouldn't parse the output of ls(1) by hprotagonist on Saturday June 15, 2024 @11:21PM (#40694445)
If your ls program supports the ‘--dired’ option, Dired automatically passes it that option; this causes ls to emit special escape sequences for certain unusual file names, without which Dired will not be able to parse those names. The first time you run Dired in an Emacs session, it checks whether ls supports the ‘--dired’ option by calling it once with that option. If the exit code is 0, Dired will subsequently use the ‘--dired’ option; otherwise it will not. You can inhibit this check by customizing the variable dired-use-ls-dired. The value unspecified (the default) means to perform the check; any other non-nil value means to use the ‘--dired’ option; and nil means not to use the ‘--dired’ option.

On MS-Windows and MS-DOS systems, and also on some remote systems, Emacs emulates ls. See Emulation of ls on MS-Windows, for options and peculiarities of this emulation.

https://www.gnu.org/software/emacs/manual/html_node/emacs/Di...

https://www.gnu.org/software/emacs/manual/html_node/emacs/ls...

Re:Why you shouldn't parse the output of ls(1) by oefrha on Sunday June 16, 2024 @01:23AM (#40694874)
Geez I didn't realize dired relies on shelling out to ls. Why the fuck would you go through all the trouble of

- shelling out to an unreliable program and doing all the parsing work;

- adding a special mode for yourself to another piece of software, which may or may not be present;

- adding a user customization point;

- adding an emulation of said software when it's not present;

when you are in a real programming language, and all you need to get the clean data directly is readdir(3) and stat(3) (or their Windows equivalents)? This is unbelievable.

Re:Why you shouldn't parse the output of ls(1) by TeMPOraL on Sunday June 16, 2024 @03:36AM (#40695352)
`ls` is faster and more portable in Unix-land, fallback to emulation on non-Unix platforms is easier than asking users to install a port of half of Unix just to have `ls`, and user customization points are what Emacs is made of and for in the first place.
Re:Why you shouldn't parse the output of ls(1) by oefrha on Sunday June 16, 2024 @04:13AM (#40695507)
Shelling out to `ls` (exec + opendir + readdir + stat) is not faster than opendir + readdir + stat. `ls --dired` is definitely not portable. readdir and stat (the libc functions) are portable, works across POSIX and other Unix-likes.
Re:Why you shouldn't parse the output of ls(1) by hprotagonist on Sunday June 16, 2024 @03:39AM (#40695366)
dired predates emacs, and was originally itself a standalone tool.
Re:Why you shouldn't parse the output of ls(1) by oefrha on Sunday June 16, 2024 @04:14AM (#40695513)
Sure, but the dired mode of Emacs has been first party forever, and nobody thought to improve it?
Re:Why you shouldn't parse the output of ls(1) by mickeyp on Sunday June 16, 2024 @04:57AM (#40695673)
It's not unbelievable if you know and use Emacs and dired.

dired will use `ls' if it is available. You can also control the arguments passed to `ls' if you want to customize sort order and suchlike. You cannot trivially do this if it's hardcoded as syscalls.

Emacs's buffer concept specifically works around the idea of annotating the output of common coreutils commands and annotating them so they are interactive in Emacs. That means you can combine `find' + `ls' and show a collated list of files matching the things you want. That is very powerful.

Oh, and you can swap out `find' or `ls' with anything that emits a similar format (or customize Emacs to interpret it differently).

Now your readdir, stat, etc. equivalents require significant development effort.

Re:Why you shouldn't parse the output of ls(1) by User23 on Saturday June 15, 2024 @10:59PM (#40694359)
Dired will warn in that case.

  ls does not support --dired; see `dired-use-ls-dired' for more details.