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 11:54:44 +0200 Message-ID: <87plq8n66z.fsf@gmx.net> References: 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="26718"; 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 11:55:42 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 1setgL-0006oP-F0 for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 16 Aug 2024 11:55:41 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1setfd-0001tn-0A; Fri, 16 Aug 2024 05:54:57 -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 1setfc-0001tf-8V for help-gnu-emacs@gnu.org; Fri, 16 Aug 2024 05:54:56 -0400 Original-Received: from mout.gmx.net ([212.227.15.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1setfa-0008HX-8O for help-gnu-emacs@gnu.org; Fri, 16 Aug 2024 05:54:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1723802087; x=1724406887; i=stephen.berman@gmx.net; bh=M1V9YCtx0p3U1OhxNar76wTUtxd9jKsZe8Za784wbTM=; 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=M9t51+DMDwCtfMX2T5992lWsDm7TbG4ErDRBd9P1KMy/8M0Smrpth6V3+x50RBNR GI2p8zjxObRY/D61/aLHveMChSOle3dUff7OGJxQVEPcrAOlkGjonGsj1+9H+/lEA 4NNfvSUH/Ah+b5Ung4wwjW9EPiGSBPcc4A3Tye+Dqt+3Fem0SpB81mookiuJAPT3u jwZDczg/sI0rMxsUDwTHFCKgn+aBWOVLolk51Z/3vcm1Q5p774yo0ovRRwT3lf4Dd MJ3eP7Yk22z8/Phx32eXUnqSDiGx40Wm7oCnAhiwQhFVqxbtkgchRetE7mi8qdzRd sHdXRDP11kJ9ZbtQMQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfs ([94.134.95.228]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MpUUw-1rpKh92V9Y-00mVfC; Fri, 16 Aug 2024 11:54:47 +0200 In-Reply-To: (Heime's message of "Fri, 16 Aug 2024 09:24:23 +0000") X-Provags-ID: V03:K1:TjvgFW1WayQFuQ43RegxqRkBdd8qPFPOK8nxuPVu/7RLydxyl+n myX6PUJX7IgHBVKdD5UjrdjDcu5AZrHHTKbSJZg67KXMiammVOWNh1gi5tB2mzwUUMnyQkf jue0QCTNz2fAVPo7an7rZe4XJt4bbFImaWZBwc2K43LW6RAvEtxXjvZiI1+KG8e+PC29Ir6 YReZwg26LSW36KOM5vOWw== UI-OutboundReport: notjunk:1;M01:P0:zjIrpIeaVRQ=;43XSGpIMSuIDpakYzOmsVTkU6b9 KPEgb+VOj/AgqVVWGbJsPYxfSNEyisGe9uwCpZ4rDGY59jBoldY57uJVWbzalql0TlSGoXINu ZppfmpGqclbArK+dXUwtmpPvDQqj3/fdZWD61efsyD5xRqXiDnzslB9lZO9AWXaZEnyPCZ45J heAGy9bZfmvx8pJ8pAPPO2TjF3l2D88xbi5afAL30hoGrYviN9qUHgg5yhOew4lT4sIZeCzdK U4hHultC4eG4A3nTW5L6+h8D14HOocpXVpNKLO2L4/oueoDFd/UtZtgIxSMGNmyFPBu8R+mMp upqHHcXesRwrt9e0VFu8plvMlpIpXHwxesMkNP0oH2rhhN1AlOqSkBOPxiOrNrQijblZd2NWj ug5lzDwZSlMOC2TIfmwtQAegiU7f7qq9i4b60XmUoJYvv1qRZPiCG0KE7QCpQLlZp7ZCglVJY LSm66NJIgI/LLa5J54unJEUzQvS4iVdLfg/DbI2PFBhrVBrHR9gCAdvVjA4u14zZTGVE+BBkf 7D1vwEWXqDoQRSx68qh4AIO08Fm1pp9e0X/C47FIRcYsXoagXI3tkcLWldBcEEJOHtKCx70H0 IvFAVrnueXAGh2VUTp7canE5OdYQFAgkjxDFUrEyJudzxuovjA8SFUPqZwZMM1Ti9z86YvAI5 T5Va34UeRNTKxqC8+vn+AisXSnxIvmVKT1Lez0DjpaUul6MiOrmj6adnhf/02FUf+/p3TxT2J IXdDXTkR+3OE9mmzuwEVWhzRowx/jnvyq80sPv9hSg7Zfpe3jgTV/sxzGZmRFDoZV6vFQqHR Received-SPF: pass client-ip=212.227.15.15; 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, 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:147706 Archived-At: On Fri, 16 Aug 2024 09:24:23 +0000 Heime wrot= e: > I want to display text starting from "(defun" up to the second blank lin= e 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 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