all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* insert gives args out of range
@ 2024-08-16  9:24 Heime
  2024-08-16  9:54 ` Stephen Berman
  0 siblings, 1 reply; 18+ messages in thread
From: Heime @ 2024-08-16  9:24 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

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)))





^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2024-08-17  9:47 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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.