From: Stephen Berman <stephen.berman@gmx.net>
To: emacs-devel@gnu.org
Subject: Re: rename buffer but overwrite already existing one
Date: Mon, 23 Mar 2020 22:21:17 +0100 [thread overview]
Message-ID: <87lfnqzs1e.fsf@gmx.net> (raw)
In-Reply-To: <87imiu7q4q.fsf@mat.ucm.es> (Uwe Brauer's message of "Mon, 23 Mar 2020 21:49:57 +0100")
On Mon, 23 Mar 2020 21:49:57 +0100 Uwe Brauer <oub@mat.ucm.es> wrote:
> > On Mon, 23 Mar 2020 20:43:56 +0100 Uwe Brauer <oub@mat.ucm.es> 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
next prev parent reply other threads:[~2020-03-23 21:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-23 18:05 rename buffer but overwrite already existing one Uwe Brauer
2020-03-23 18:23 ` Stefan Monnier
2020-03-23 19:24 ` Uwe Brauer
2020-03-23 19:18 ` Eli Zaretskii
2020-03-23 19:23 ` Uwe Brauer
2020-03-23 19:35 ` Eli Zaretskii
2020-03-23 19:46 ` Uwe Brauer
2020-03-23 19:41 ` Andreas Schwab
2020-03-23 19:43 ` Uwe Brauer
2020-03-23 20:02 ` Stephen Berman
2020-03-23 20:49 ` Uwe Brauer
2020-03-23 21:21 ` Stephen Berman [this message]
2020-03-24 9:17 ` Uwe Brauer
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lfnqzs1e.fsf@gmx.net \
--to=stephen.berman@gmx.net \
--cc=emacs-devel@gnu.org \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).