with-current-buffer

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

with-current-buffer

Andreas Röhler
Hi,

docstring of "with-current-buffer" says:

"Execute the forms in BODY with BUFFER-OR-NAME temporarily current."

However, seems the old buffer isn't stored, buffer-or-name specified
here remain current.

Also don't see inside the macro which way the old buffer should be restored:

(defmacro with-current-buffer (buffer-or-name &rest body)
   "Execute the forms in BODY with BUFFER-OR-NAME temporarily current.
BUFFER-OR-NAME must be a buffer or the name of an existing buffer.
The value returned is the value of the last form in BODY.  See
also `with-temp-buffer'."
   (declare (indent 1) (debug t))
   `(save-current-buffer
      (set-buffer ,buffer-or-name)
      ,@body))


A bug?

Thanks,

Andreas,

GNU Emacs 26.3 (build 1, i686-pc-linux-gnu, GTK+ Version 3.14.5) of
2019-09-04


Reply | Threaded
Open this post in threaded view
|

Re: with-current-buffer

Tomas Zerolo
On Mon, Nov 11, 2019 at 09:31:08AM +0100, Andreas Röhler wrote:

> Hi,
>
> docstring of "with-current-buffer" says:
>
> "Execute the forms in BODY with BUFFER-OR-NAME temporarily current."
>
> However, seems the old buffer isn't stored, buffer-or-name specified
> here remain current.
>
> Also don't see inside the macro which way the old buffer should be restored:
This is the job of save-current-buffer, no?

Cheers
-- tomás

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: with-current-buffer

Andreas Röhler

On 11.11.19 10:04, [hidden email] wrote:

> On Mon, Nov 11, 2019 at 09:31:08AM +0100, Andreas Röhler wrote:
>> Hi,
>>
>> docstring of "with-current-buffer" says:
>>
>> "Execute the forms in BODY with BUFFER-OR-NAME current."
>>
>> However, seems the old buffer isn't stored, buffer-or-name specified
>> here remain current.
>>
>> Also don't see inside the macro which way the old buffer should be restored:
> This is the job of save-current-buffer, no?
>
> Cheers
> -- tomás


Hi Tomás,

thanks. So I have to write something like

(save-current-buffer
         (with-current-buffer buffer


Expected a behavior like with-temp-buffer.

As the wording "temporarily" seems to indicate.

Cheers,

Andreas


Reply | Threaded
Open this post in threaded view
|

Re: with-current-buffer

Tomas Zerolo
On Mon, Nov 11, 2019 at 11:58:43AM +0100, Andreas Röhler wrote:

[...]

> thanks. So I have to write something like
>
> (save-current-buffer
>         (with-current-buffer buffer

Hm. I'm far from an expert, but I think

  (save-current-buffer
    (with-current-buffer buffer
      ...))

should be equivalent to

  (with-current-buffer buffer
    ...)

i.e. you can just drop the "outer" save-current-buffer. Still, if
I were you I'd wait for more expert advise :-)

Cheers
-- t

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: with-current-buffer

Joost Kremers-2
In reply to this post by Andreas Röhler

On Mon, Nov 11 2019, Andreas Röhler wrote:
> docstring of "with-current-buffer" says:
>
> "Execute the forms in BODY with BUFFER-OR-NAME temporarily
> current."
>
> However, seems the old buffer isn't stored, buffer-or-name
> specified here remain
> current.

Could you be more specific? `save-current-buffer` works fine for
me.

> Also don't see inside the macro which way the old buffer should
> be restored:

That's done by `save-current-buffer`.


--
Joost Kremers
Life has its moments

Reply | Threaded
Open this post in threaded view
|

Re: with-current-buffer

Joost Kremers-2
In reply to this post by Andreas Röhler

On Mon, Nov 11 2019, Andreas Röhler wrote:
> thanks. So I have to write something like
>
> (save-current-buffer
>         (with-current-buffer buffer

Nope, there's a `save-current-buffer` in the definition of
`with-current-buffer`, so this would be superfluous.

--
Joost Kremers
Life has its moments

Reply | Threaded
Open this post in threaded view
|

Re: with-current-buffer

Andreas Röhler
In reply to this post by Joost Kremers-2

On 11.11.19 12:16, Joost Kremers wrote:

>
> On Mon, Nov 11 2019, Andreas Röhler wrote:
>> docstring of "with-current-buffer" says:
>>
>> "Execute the forms in BODY with BUFFER-OR-NAME temporarily current."
>>
>> However, seems the old buffer isn't stored, buffer-or-name specified
>> here remain
>> current.
>
> Could you be more specific? `save-current-buffer` works fine for me.
>
>> Also don't see inside the macro which way the old buffer should be
>> restored:
>
> That's done by `save-current-buffer`.
>
>

Turns out there an error in code, which set the wrong buffer   -
"with-current-buffer" works fine and temporarily as expected.

Thanks all,

Andreas