From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.help Subject: Re: insert gives args out of range Date: Fri, 16 Aug 2024 13:51:49 +0200 Message-ID: <87le0wn0ru.fsf@gmx.net> References: <87plq8n66z.fsf@gmx.net> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22361"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Heime via Users list for the GNU Emacs text editor To: Heime Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Aug 16 13:52:29 2024 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sevVN-0005f9-7y for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 16 Aug 2024 13:52:29 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sevUy-0001eU-L8; Fri, 16 Aug 2024 07:52:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sevUq-0001SO-Rr for help-gnu-emacs@gnu.org; Fri, 16 Aug 2024 07:51:57 -0400 Original-Received: from mout.gmx.net ([212.227.17.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sevUn-0001EF-Av for help-gnu-emacs@gnu.org; Fri, 16 Aug 2024 07:51:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1723809110; x=1724413910; i=stephen.berman@gmx.net; bh=2BhRYpCVVQHxYoxX6KdhYNVIYxTht8WWU9Md7CTLxxE=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date: Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=BKHb0+/dV8JL439Gvzam2DAlJ+c4YsbkkcJsGeOEUXNId02hvfN0DvwEHYNrYEkq 64NopBjVeYVejEUUme4FLrmm2mAVTE40RkD3ato30feaJzhY9pBOQLAwsZKZI3gXw IFdipTKzFyz168UYYnJqLTb/VbJQh2XmpReG+xAKvztiFui+q5zkrwFoiE+/PfztC x+UxNiKWq7JRIe0Ja2dmaK+lTz5XpbM9T1c4AqrSzWY3RRqaFdZD8iWyn/PUaGnJk cZSUNkl+fjqyblpyUHfYphxHzQYm/8fXRjnsE/J0VSXbCq3Os4si4jCVtOCrE5EJm D0knz3/SwfXWYXdlOQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfs ([94.134.95.228]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MkYXm-1rtAkt3YY2-00qMnW; Fri, 16 Aug 2024 13:51:49 +0200 In-Reply-To: (Heime's message of "Fri, 16 Aug 2024 10:59:09 +0000") X-Provags-ID: V03:K1:natcvaaO5DM7b+3TnFqupZZEDr+4IJdGhVPe1tbgwjkkYc2tMvt GYbszLtG5RkarEVcY4Ve4qsc6fxkgPbpEW97xzirMOI5eAyPnNx6ldrZs0d0wvUv2Ai8FVS kQNc8ayvPoj6PZ0mrHTx/eGrT1C5pwa2AKyblmNQ9qYMZfLz1titR/EMyFVJN3QjpfzZiev KQxKDfMRv6OaPwVa4+m1w== UI-OutboundReport: notjunk:1;M01:P0:ZX2ixHJdizM=;/RMtSCfpe6XpRDtM2DLR2Y4IY+0 ZaOUxrce+Y6GFJBL2JGiTFD7RASRifQPQTKZEdRkhqEvMZSV5eqjtZAhn7dQYpsTRb+ke+h4+ lIwu1JKrjI95jywUZ1a7iC7nwAwprnikRxpJX/54w6ezw+U3pZf8nxaZn4B6xYtYIg0jE2z1u VHqRJB91UMpJL3W7Mr9l8t2xJ5op8mqpHeg1Hz/0pYnTIxXWQE1r0JGX83sdaWbcuLnJm0nyM X5W/dGnyQRwNdTiKhgEQjWbZcqC9OP8i+1wLf5CeIpdPl7NHwyQfNl0Uh8bNgRIYcJI1K36xk 2a7TDcCeM9fiEA0S6WbWT8Vw1Sx3SNgu18edFghQoTBUkMwfHPOPdVo/Zou5oxXAUjTUj098v pjElC6dKZSRp4gy/shNyzk1n0qUdpAN5p1fMDG+z2NWxsuF/YBLoyj2HiMQ2lB/EeH8H1E8pO B6nyD+S3ObtX8XJ/kO5yrwXjfg7S0v0E/ya9y8kq3U5Akk5drSyySeM0dw54LH719KEhi9sx3 orRxHliQurT57j1nW0uN3qhvbblZGCUYBLeS/IPf/U1SiaF2/z8xtW0Y1mvm8pUmaUzOo2rTb EvvL0rg+6kJk2VoIu8n7RB9aEfKjn2SU122XPhmsvOPB4Zoj7p6U9dc+8o4rR7sUa6lZJjICS YOBt+dYy+gBByAdzbIo5T6Nt9HTcAYbz8hRIFUfKpM6fl5M5ksu/89qeTSCfXEEbMgYoELS3a vPG8gG0v1tu4eYin4QA/ba8Eq8l+S75irTqZaTo9pGaYv9tBvJlKe17QbF3WDAI2wFtgdQ0Z Received-SPF: pass client-ip=212.227.17.21; envelope-from=stephen.berman@gmx.net; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:147711 Archived-At: On Fri, 16 Aug 2024 10:59:09 +0000 Heime wrot= e: > On Friday, August 16th, 2024 at 10:20 PM, Heime wrote: > >> 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 w= rote: >> > >> > > I want to display text starting from "(defun" up to the second blan= k >> > > line that is encountered. >> > > >> > > But with this code I get >> > > >> > > insert: Args out of range: #, 2706, 2804 >> > > >> > > (defun display-text () >> > > "Display the text between a line starting with '(defun' and the sec= ond >> > > 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 ra= nge >> > 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 > > I updated as suggested. Although I get the output, the search stops on = the first > blank line rather than on the second blank line. Consider a buffer "*test*" with the following content (two blank lines between the defuns): ;;;;;;;;;;;;; (defun f1 () (ignore)) (defun f2 () (ignore)) ;;;;;;;;;;;;; When you call `display-text' in "*test*", the first evaluation of the sexp (re-search-forward "^\\s-*$" nil t) moves point to the first blank line below the first defun. Where is point after the second evaluation of that sexp? Steve Berman