aboutsummaryrefslogtreecommitdiff
path: root/compat-28.el
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2023-02-10 00:22:43 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2023-02-10 00:24:17 +0100
commit51326170de92b88e14b8d8f0ed30f33e3eeb4c48 (patch)
tree6711e0eb1c1003254ccd9c667d61189afe9c3aa2 /compat-28.el
parente59e311d1ffc422f91e4e9c494598e978f5c2125 (diff)
compat-28: Add process-lines-ignore-status and process-lines-handling-status
Diffstat (limited to 'compat-28.el')
-rw-r--r--compat-28.el29
1 files changed, 29 insertions, 0 deletions
diff --git a/compat-28.el b/compat-28.el
index 645f5cb..e3bde86 100644
--- a/compat-28.el
+++ b/compat-28.el
@@ -225,6 +225,35 @@ If LENGTH is nil, use the window width."
;;;; Defined in subr.el
+(compat-defun process-lines-handling-status (program status-handler &rest args) ;; <compat-tests:process-lines-handling-status>
+ "Execute PROGRAM with ARGS, returning its output as a list of lines.
+If STATUS-HANDLER is non-nil, it must be a function with one
+argument, which will be called with the exit status of the
+program before the output is collected. If STATUS-HANDLER is
+nil, an error is signaled if the program returns with a non-zero
+exit status."
+ (with-temp-buffer
+ (let ((status (apply #'call-process program nil (current-buffer) nil args)))
+ (if status-handler
+ (funcall status-handler status)
+ (unless (eq status 0)
+ (error "%s exited with status %s" program status)))
+ (goto-char (point-min))
+ (let (lines)
+ (while (not (eobp))
+ (setq lines (cons (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position))
+ lines))
+ (forward-line 1))
+ (nreverse lines)))))
+
+(compat-defun process-lines-ignore-status (program &rest args) ;; <compat-tests:process-lines-ignore-status>
+ "Execute PROGRAM with ARGS, returning its output as a list of lines.
+The exit status of the program is ignored.
+Also see `process-lines'."
+ (apply 'process-lines-handling-status program #'ignore args))
+
;; FIXME Should handle multibyte regular expressions
(compat-defun string-replace (fromstring tostring instring) ;; <compat-tests:string-replace>
"Replace FROMSTRING with TOSTRING in INSTRING each time it occurs."