From 97f2c661711dcb63df8fb3ff9d080345e2428c40 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Sat, 31 May 2003 03:15:18 +0000 Subject: [PATCH] In M-x occur, change recursive algorithm to iterative, so that large numbers of occurrences don't fail by running out of stack. --- v7/src/edwin/occur.scm | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/v7/src/edwin/occur.scm b/v7/src/edwin/occur.scm index 0bb1fa59f..8e72bbd29 100644 --- a/v7/src/edwin/occur.scm +++ b/v7/src/edwin/occur.scm @@ -1,8 +1,8 @@ #| -*-Scheme-*- -$Id: occur.scm,v 1.8 2003/02/14 18:28:12 cph Exp $ +$Id: occur.scm,v 1.9 2003/05/31 03:15:18 cph Exp $ -Copyright 1992-2000 Massachusetts Institute of Technology +Copyright 1992,1995,1997,2000,2003 Massachusetts Institute of Technology This file is part of MIT/GNU Scheme. @@ -226,32 +226,38 @@ It serves as a menu to find any of the occurrences in this buffer. (syntax-table (ref-variable syntax-table start)) (group (mark-group start)) (end (mark-index end))) - (let loop ((start (mark-index start))) + (let loop ((start (mark-index start)) (occurrences '())) (let ((match (re-search-buffer-forward pattern syntax-table group start end))) (if match - (cons (make-temporary-mark group (line-start-index group match) #f) - (loop (line-end-index group match))) - '()))))) + (loop (line-end-index group match) + (cons (make-temporary-mark group + (line-start-index group match) + #f) + occurrences)) + (reverse! occurrences)))))) (define (format-occurrences occurrences nlines output) - (if (null? occurrences) - '() + (if (pair? occurrences) (let loop ((occurrences occurrences) (previous (group-start (car occurrences))) - (line 1)) + (line 1) + (alist '())) (let ((lstart (car occurrences)) (index (mark-index output))) (let ((line (+ line (count-lines previous lstart)))) (format-occurrence lstart line nlines output) - (cons (cons index lstart) - (if (null? (cdr occurrences)) - '() - (begin - (if (not (= nlines 0)) - (insert-string "--------\n" output)) - (loop (cdr occurrences) lstart line))))))))) + (if (pair? (cdr occurrences)) + (begin + (if (not (= nlines 0)) + (insert-string "--------\n" output)) + (loop (cdr occurrences) + lstart + line + (cons (cons index lstart) alist))) + (reverse! alist))))) + '())) (define (format-occurrence lstart line nlines output) (let ((tag (pad-on-left-to (number->string line) 3))) -- 2.25.1