From: Jean Louis <bugs@gnu.support>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Maybe we can improve this function call-process-to-string?
Date: Thu, 8 Apr 2021 21:33:57 +0300 [thread overview]
Message-ID: <YG9MlYsUrqaM/ZBY@protected.localdomain> (raw)
In-Reply-To: <jwvft00657l.fsf-monnier+emacs@gnu.org>
* Stefan Monnier <monnier@iro.umontreal.ca> [2021-04-08 20:50]:
> > (defun call-process-to-string (program &optional infile display &rest args)
> > (let* ((buffer-name "Output")
> > (buffer (generate-new-buffer buffer-name))
> > (status (apply #'call-process program infile buffer display args))
> > (current-buffer (current-buffer))
> > (output (if status
> > (progn
> > (switch-to-buffer buffer)
> > (buffer-string))
> > "")))
> > (switch-to-buffer current-buffer)
> > output))
>
> The docstring of `switch-to-buffer` is fairly long, but the first
> 5 lines are recommended reading:
>
> Display buffer BUFFER-OR-NAME in the selected window.
>
> WARNING: This is NOT the way to work on another buffer temporarily
> within a Lisp program! Use `set-buffer' instead. That avoids
> messing with the window-buffer correspondences.
Oh, that is right, thanks.
> Also the above code forgot to kill the buffer you created.
> I recommend `with-temp-buffer` here instead:
>
> (with-temp-buffer
> (apply #'call-process program infile t display args)
> (buffer-string))
>
>
> -- Stefan
That looks perfect, thank you.
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
Sign an open letter in support of Richard M. Stallman
https://rms-support-letter.github.io/
next prev parent reply other threads:[~2021-04-08 18:33 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-08 7:40 Maybe we can improve this function call-process-to-string? Jean Louis
2021-04-08 7:55 ` Eli Zaretskii
2021-04-08 11:53 ` Jean Louis
2021-04-08 13:39 ` Eli Zaretskii
2021-04-08 15:56 ` Jean Louis
2021-04-08 16:25 ` Eli Zaretskii
2021-04-08 18:17 ` Jean Louis
2021-04-08 18:36 ` Eli Zaretskii
2021-04-08 18:44 ` Jean Louis
2021-04-08 17:18 ` Arthur Miller
2021-04-08 18:32 ` Jean Louis
2021-04-08 19:41 ` Arthur Miller
2021-04-09 8:52 ` Jean Louis
2021-04-09 10:07 ` tomas
2021-04-08 13:08 ` Michael Albinus
2021-04-08 15:50 ` Jean Louis
2021-04-08 17:49 ` Stefan Monnier
2021-04-08 18:33 ` Jean Louis [this message]
2021-04-08 18:40 ` Jean Louis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YG9MlYsUrqaM/ZBY@protected.localdomain \
--to=bugs@gnu.support \
--cc=help-gnu-emacs@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.