[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Any exceptions for the 15-line rule?

From: Dmitry Gutov
Subject: Re: Any exceptions for the 15-line rule?
Date: Sun, 05 May 2013 11:31:10 +0400
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130328 Thunderbird/17.0.5

On 05.05.2013 9:02, Stefan Monnier wrote:
-    (with-temp-buffer
+        (buf (get-buffer-create "*clang-output*"))
+    (with-current-buffer buf (erase-buffer))
+    (with-current-buffer buf
So, I've merged the patch into Git repo with some modifications, but looks
like the above change is perfectly justified: the new code uses
call-process-region', which takes the region from the current buffer, so
using it with `with-temp-buffer' doesn't seem possible.

I must be missing something because I don't see why that
changes anything.

Before, we were just calling `call-process', which uses one buffer, for stdout. So we created a temp buffer, collected program output in it, parsed that into our data structures and the buffer could be discarded.

Now, `call-process-region' needs two buffers, for stdin and stdout. That means that the current buffer has to be the buffer the user's editing, or at least contain its contents.

So we could, I guess, save (buffer-string) to a local var, switch to a temp buffer, insert it and then call `call-process-region' with non-nil DELETE argument (or save the current point value to start parsing output from it), but this may be slow for large files (not sure), and using a separate names buffer for output is more natural.

And using `with-temp-buffer' to create a non-current buffer (for output) is trickier: save current buffer to a local var, `with-temp-buffer', save *that* buffer in another `let', use `with-current-buffer' with the first var, and then pass the second var to `call-process-region'.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]