Subject: Re: bug#76103: [PATCH] New function 'process-output'

From: Daniel Mendler <[email-masked]>
Date: Fri, 07 Feb 2025 10:54:48 +0100

Juri Linkov <[email-masked]> writes:

>> I find process-lines super convenient for glueing command line utilities.
>>
>> Often wished I had a similar function that neither split into lines
>> (process-lines) nor relied on shell (shell-command-to-string).
>>
>> Proposing process-output as a close cousin to process-lines.
>>
>> Happy to drop process-lines in favour of an existing function I may have
>> missed.
>
> Unfortunately, there is no such function for process output.
> What is worse there is no similar function even for files.
> So everyone have to reimplement the same idiom dozens of times:
>
>   (defun read-file (file)
>     "Return FILE content as string."
>     (with-temp-buffer
>       (insert-file-contents file)
>       (buffer-string)))
>
>   (defun read-lines (file)
>     "Return a list of lines of FILE."
>     (with-temp-buffer
>       (insert-file-contents file)
>       (split-string (buffer-string) "\n" t)))
>
> For example, there is a complete implementation of read-file
> in org-babel-eval-read-file, uudecode-tests-read-file,
> eshell-test-file-string.
>
> Also there is a complete implementation of read-lines
> in vc--read-lines.
>
> Also this idiom is widely used in comint-exec, eieio-persistent-read,
> ert-write-junit-test-summary-report, faceup-test-font-lock-file,
> package--get-description, epa-file-insert-file-contents,
> erc-load-irc-script, gnus-splash-svg-color-symbols, eww-submit,
> tramp-get-lock-file, org-babel-R-evaluate-external-process,
> org-babel-R-evaluate-session, ob-session-async-R-value-callback,
> org-babel-julia-evaluate-external-process,
> org-babel-julia-evaluate-session, org-babel-execute:plantuml,
> org-babel-execute:sass, org-babel-screen-test,
> org-texinfo-supports-math-p, ps-prologue-file, shell,
> vc-cvs-file-to-string, vc-hg--active-bookmark-internal,
> erc-tests-common-snapshot-compare em-extpipe-tests--deftest,
> em-hist-test/check-history-file, eshell-test-file-string,
> files-tests-save-buffer-read-only-file, dbus--test-introspect, url-file,

+1 I am in favor of adding such small utility functions to read small
files or handle limited process output. I think many of us have
implemented such functions, and Juri's code search in the Emacs code
base demonstrates that. I agree with Eli that for large files or more
extensive processing working with a buffer is better. But in other cases
these functions are still useful.

If a set of such functions will be added to Emacs subr.el or subr-x.el I
am happy to port them back via Compat, such that they are available to
all ELPA packages, including the ones targeting older Emacs versions.

Daniel