all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Heime <heimeborgia@protonmail.com>
To: Stephen Berman <stephen.berman@gmx.net>
Cc: Heime via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: Re: insert gives args out of range
Date: Fri, 16 Aug 2024 10:20:33 +0000	[thread overview]
Message-ID: <BSLEkgYodkKGKByAiLvtfVxoVLHXjPRerS0Oux72nbccFyUCHhG5D4qtuExcdCOr_JOEoVS0l8A8kqzjw_pL87B5-M5x_yfuIxSoZBHZepg=@protonmail.com> (raw)
In-Reply-To: <87plq8n66z.fsf@gmx.net>


On Friday, August 16th, 2024 at 9:54 PM, Stephen Berman <stephen.berman@gmx.net> wrote:

> On Fri, 16 Aug 2024 09:24:23 +0000 Heime heimeborgia@protonmail.com wrote:
> 
> > I want to display text starting from "(defun" up to the second blank line that is encountered.
> > 
> > But with this code I get
> > 
> > insert: Args out of range: #<buffer Defun Sections>, 2706, 2804
> > 
> > (defun display-text ()
> > "Display the text between a line starting with '(defun' and the second blank line."
> > (interactive)
> > (let ((output-buffer (get-buffer-create "Defun Sections")))
> > (with-current-buffer output-buffer
> > (erase-buffer)) ;; Clear previous contents
> > (save-excursion
> > (goto-char (point-min))
> > (while (re-search-forward "^(defun" nil t)
> > (let ((start (match-beginning 0))
> > (blank-lines 0)
> > end)
> > ;; Move forward to find the second blank line
> > (while (and (< blank-lines 2)
> > (re-search-forward "^\\s-*$" nil t))
> > (setq blank-lines (1+ blank-lines)))
> > (setq end (point))
> > ;; Ensure the range is valid before inserting
> > (when (> end start)
> > (with-current-buffer output-buffer
> > (insert (buffer-substring-no-properties start end) "\n"))))))
> > ;; Display the output buffer
> > (display-buffer output-buffer)))
> 
> 
> You've set `start' and` end' in a different buffer than output-buffer
> but you're invoking buffer-substring-no-properties with these values in
> output-buffer, which you've erased, so those values are not in the range
> of possible values in output-buffer. Try let-binding the result of
> invoking buffer-substring-no-properties before the second invocation of
> with-current-buffer.
> 
> Steve Berman

You're correct



  reply	other threads:[~2024-08-16 10:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-16  9:24 insert gives args out of range Heime
2024-08-16  9:54 ` Stephen Berman
2024-08-16 10:20   ` Heime [this message]
2024-08-16 10:59     ` Heime
2024-08-16 11:51       ` Stephen Berman
2024-08-16 12:03         ` Heime
2024-08-16 12:10           ` Heime
2024-08-16 12:26             ` Stephen Berman
2024-08-16 15:01               ` Heime
2024-08-16 15:09                 ` Heime
2024-08-16 15:16                   ` Stephen Berman
2024-08-16 15:21                     ` Heime
2024-08-16 15:34                       ` Stephen Berman
2024-08-16 17:32                         ` Heime
2024-08-16 21:29                           ` Stephen Berman
2024-08-16 21:47                             ` Heime
2024-08-16 22:26                               ` Stephen Berman
2024-08-17  9:47                                 ` Heime

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='BSLEkgYodkKGKByAiLvtfVxoVLHXjPRerS0Oux72nbccFyUCHhG5D4qtuExcdCOr_JOEoVS0l8A8kqzjw_pL87B5-M5x_yfuIxSoZBHZepg=@protonmail.com' \
    --to=heimeborgia@protonmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=stephen.berman@gmx.net \
    /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.