emacs-devel
[Top][All Lists]
Advanced

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

Re: rename buffer but overwrite already existing one


From: Stephen Berman
Subject: Re: rename buffer but overwrite already existing one
Date: Mon, 23 Mar 2020 22:21:17 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

On Mon, 23 Mar 2020 21:49:57 +0100 Uwe Brauer <address@hidden> wrote:

>    > On Mon, 23 Mar 2020 20:43:56 +0100 Uwe Brauer <address@hidden> wrote:
>
>    > You're calling insert-buffer-substring with point-min and point-max of
>    > the buffer you've just created, so they're both 1.  Try this:
>
>    > (defun my-copy-to-buffer (buffer)
>    >   "Copy the contents of the current buffer to  BUFFER."
>    >   (interactive "BCopy to buffer: ")
>    >   (let ((start (point-min))
>    >  (end (point-max)))
>    >     (copy-to-buffer buffer start end)))
>
> Thanks I tried this
>
>
> (defun my-copy-to-buffer (buffer)
>   "Copy to specified BUFFER the whole buffer."
>   (interactive "BCopy to buffer: \n")
>   (let ((oldbuf (current-buffer))
>         (start (point-min))
>         (end (point-max)))
>
>     (with-current-buffer (get-buffer-create buffer)
>       (barf-if-buffer-read-only)
>       (save-excursion
>       (insert-buffer-substring oldbuf (point-min) (point-max))))))
>
> And it did not work,

This function doesn't use the local variables `start' and `end', and
evaluating (point-min) and (point-max) in the scope of
with-current-buffer again returns the values for the buffer just
created.  Replacing `(point-min)' and `(point-max)' there by `start' and
`end', respectively, will DTRT, but then you can just use copy-to-buffer
as I showed above.

Steve Berman



reply via email to

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