Skip to content

Commit

Permalink
straight--process-call: avoid find-file-noselect (#1100)
Browse files Browse the repository at this point in the history
Use insert-file-contents when reading process stderr.
This avoids running hooks and minor modes.
It also allows us to optimize straight--process-call by reusing a single temp buffer.

Co-authored-by: Nicholas Vollmer <44036031+progfolio@users.noreply.github.com>
  • Loading branch information
league and progfolio committed Jun 15, 2023
1 parent 4701c9a commit ff63b15
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions straight.el
Original file line number Diff line number Diff line change
Expand Up @@ -926,24 +926,22 @@ eaten by a grue.")
"Run PROGRAM syncrhonously with ARGS.
Return a list of form: (EXITCODE STDOUT STDERR).
If the process is unable to start, return an elisp error object."
(let* ((program (if (string-match-p "/" program)
(expand-file-name program)
program)))
(condition-case e
(with-temp-buffer
(list
(apply #'call-process program nil
(list (current-buffer) straight--process-stderr)
nil args)
(let ((s (buffer-string)))
(unless (string-empty-p s) s))
(with-current-buffer
(find-file-noselect straight--process-stderr
'nowarn 'raw)
(prog1 (let ((s (buffer-string)))
(unless (string-empty-p s) s))
(kill-buffer)))))
(error e))))
(when (string-match-p "/" program)
(setq program (expand-file-name program)))
(condition-case e
(with-temp-buffer
(list
(apply #'call-process program nil
(list t straight--process-stderr)
nil args)
(let ((s (buffer-substring-no-properties (point-min) (point-max))))
(unless (string-empty-p s) s))
(progn
(insert-file-contents
straight--process-stderr nil nil nil 'replace)
(let ((s (buffer-substring-no-properties (point-min) (point-max))))
(unless (string-empty-p s) s)))))
(error e)))

(defmacro straight--process-with-result (result &rest body)
"Provide anaphoric RESULT bindings for duration of BODY.
Expand Down

0 comments on commit ff63b15

Please sign in to comment.