From c5cd90347faaeecdebae867df7096fd79d481962 Mon Sep 17 00:00:00 2001 From: "Taylor R. Campbell" Date: Mon, 3 Jul 2006 19:05:02 +0000 Subject: [PATCH] Implement PARSE-STATE-START-OF-SEXP and PARSE-STATE-END-OF-SEXP properly in Edwin's partial S-expression parser. This fixes a long- standing bug in paredit whereby character deletion in strings that were the first elements of lists would cause segmentation faults. --- v7/src/edwin/paredit.scm | 11 +---------- v7/src/edwin/syntax.scm | 12 +++++++++++- v7/src/microcode/syntax.c | 13 +++++++++---- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/v7/src/edwin/paredit.scm b/v7/src/edwin/paredit.scm index da9c1b9d3..6b10a29ea 100644 --- a/v7/src/edwin/paredit.scm +++ b/v7/src/edwin/paredit.scm @@ -1,6 +1,6 @@ #| -*-Scheme-*- -$Id: paredit.scm,v 1.5 2006/06/27 18:43:59 riastradh Exp $ +$Id: paredit.scm,v 1.6 2006/07/03 19:05:02 riastradh Exp $ This code is written by Taylor R. Campbell and placed in the Public Domain. All warranties are disclaimed. @@ -761,15 +761,6 @@ Both must be lists, strings, or atoms; error if there is mismatch." (buffer-start (current-buffer))) point))) -;++ These are wrong, but, argh, I don't think Edwin preserves enough -;++ information to make them right. - -(define (parse-state-end-of-sexp state) - (forward-one-sexp (forward-one-sexp (parse-state-last-sexp state)))) - -(define (parse-state-start-of-sexp state) - (backward-one-sexp (parse-state-end-of-sexp state))) - (define (insert-sexp-pair open close sexps #!optional mark) (define (insert-space end? mark) diff --git a/v7/src/edwin/syntax.scm b/v7/src/edwin/syntax.scm index b60e94aee..1f3a28654 100644 --- a/v7/src/edwin/syntax.scm +++ b/v7/src/edwin/syntax.scm @@ -1,6 +1,6 @@ #| -*-Scheme-*- -$Id: syntax.scm,v 1.93 2004/11/19 16:59:27 cph Exp $ +$Id: syntax.scm,v 1.94 2006/07/03 19:05:02 riastradh Exp $ Copyright 1987,1989,1991,1992,1996,1997 Massachusetts Institute of Technology Copyright 1998,1999,2000,2001,2002,2004 Massachusetts Institute of Technology @@ -243,6 +243,7 @@ a comment ending." ;; COMMENT-START is valid when COMMENT-STATE is not #f. (comment-state #f read-only #t) (quoted? #f read-only #t) + (start-of-sexp #f) (last-sexp #f) (containing-sexp #f) (location #f) @@ -257,6 +258,11 @@ a comment ending." (parse-state-quoted? state) (not (= (parse-state-depth state) 0)))) +(define (parse-state-end-of-sexp state) + (cond ((parse-state-start-of-sexp state) + => forward-one-sexp) + (else #f))) + (define (forward-to-sexp-start mark end) (parse-state-location (parse-partial-sexp mark end 0 #t))) @@ -279,6 +285,10 @@ a comment ending." (mark-index end) target-depth stop-before? old-state))) ;; Convert the returned indices to marks. + (if (parse-state-start-of-sexp state) + (set-parse-state-start-of-sexp! + state + (make-mark group (parse-state-start-of-sexp state)))) (if (parse-state-last-sexp state) (set-parse-state-last-sexp! state diff --git a/v7/src/microcode/syntax.c b/v7/src/microcode/syntax.c index c4b5cd918..76e699754 100644 --- a/v7/src/microcode/syntax.c +++ b/v7/src/microcode/syntax.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: syntax.c,v 1.30 2005/07/16 03:46:42 cph Exp $ +$Id: syntax.c,v 1.31 2006/07/03 19:05:02 riastradh Exp $ Copyright 1987,1988,1989,1991,1993,1996 Massachusetts Institute of Technology Copyright 2000,2004,2005 Massachusetts Institute of Technology @@ -1059,19 +1059,24 @@ DEFINE_PRIMITIVE ("SCAN-SEXPS-FORWARD", Prim_scan_sexps_forward, 7, 7, 0) FAST_VECTOR_SET (result, 3, (BOOLEAN_TO_OBJECT (quoted))); FAST_VECTOR_SET (result, 4, + (((level -> last) == NULL) + ? SHARP_F + : (LONG_TO_UNSIGNED_FIXNUM ((SCAN_TO_INDEX (level -> last)) - 1)))); + FAST_VECTOR_SET + (result, 5, (((level -> previous) == NULL) ? SHARP_F : (LONG_TO_UNSIGNED_FIXNUM ((SCAN_TO_INDEX (level -> previous)) - 1)))); FAST_VECTOR_SET - (result, 5, + (result, 6, (((level == level_start) || (((level - 1) -> last) == NULL)) ? SHARP_F : (LONG_TO_UNSIGNED_FIXNUM ((SCAN_TO_INDEX ((level - 1) -> last)) - 1)))); FAST_VECTOR_SET - (result, 6, (LONG_TO_UNSIGNED_FIXNUM (SCAN_TO_INDEX (start)))); + (result, 7, (LONG_TO_UNSIGNED_FIXNUM (SCAN_TO_INDEX (start)))); FAST_VECTOR_SET - (result, 7, + (result, 8, ((in_comment == 0) ? SHARP_F : (LONG_TO_UNSIGNED_FIXNUM (SCAN_TO_INDEX (comment_start))))); -- 2.25.1