emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master cabd22f: Make parse-partial-sexp signal an error if TO is smaller


From: Lars Ingebrigtsen
Subject: master cabd22f: Make parse-partial-sexp signal an error if TO is smaller than FROM
Date: Sat, 21 Aug 2021 09:24:22 -0400 (EDT)

branch: master
commit cabd22f5c6c2f47b1f6efd627e9e760a31e8f015
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Make parse-partial-sexp signal an error if TO is smaller than FROM
    
    * src/syntax.c (Fparse_partial_sexp): Signal an error if TO is
    smaller than FROM (bug#49944).
---
 etc/NEWS                 | 6 ++++++
 src/syntax.c             | 9 +++++++--
 test/src/syntax-tests.el | 6 ++++++
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 02185a6..c3993b7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -3108,6 +3108,12 @@ This is to keep the same behavior as Eshell.
 
 * Incompatible Lisp Changes in Emacs 28.1
 
+---
+** 'parse-partial-sexp' now signals an error it TO is smaller than FROM.
+Previously this would lead to the function interpreting FROM as TO and
+vice versa, which would be confusing when passing in OLDSTATE, which
+refers to the old state at FROM.
+
 +++
 ** 'overlays-in' now handles zero-length overlays slightly differently.
 Previosly, zero-length overlays at the end of the buffer were included
diff --git a/src/syntax.c b/src/syntax.c
index 7bba336..6cbe0f6 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -3547,8 +3547,10 @@ DEFUN ("parse-partial-sexp", Fparse_partial_sexp, 
Sparse_partial_sexp, 2, 6, 0,
        doc: /* Parse Lisp syntax starting at FROM until TO; return status of 
parse at TO.
 Parsing stops at TO or when certain criteria are met;
  point is set to where parsing stops.
-If fifth arg OLDSTATE is omitted or nil,
- parsing assumes that FROM is the beginning of a function.
+
+If OLDSTATE is omitted or nil, parsing assumes that FROM is the
+ beginning of a function.  If not, OLDSTATE should be the state at
+ FROM.
 
 Value is a list of elements describing final state of parsing:
  0. depth in parens.
@@ -3594,6 +3596,9 @@ Sixth arg COMMENTSTOP non-nil means stop after the start 
of a comment.
   else
     target = TYPE_MINIMUM (EMACS_INT); /* We won't reach this depth.  */
 
+  if (XFIXNUM (to) < XFIXNUM (from))
+    error ("End position should be larger than start position.");
+
   validate_region (&from, &to);
   internalize_parse_state (oldstate, &state);
   scan_sexps_forward (&state, XFIXNUM (from), CHAR_TO_BYTE (XFIXNUM (from)),
diff --git a/test/src/syntax-tests.el b/test/src/syntax-tests.el
index e4e3054..bd89283 100644
--- a/test/src/syntax-tests.el
+++ b/test/src/syntax-tests.el
@@ -500,4 +500,10 @@ the `parse-partial-sexp's are expected to stop.  See
 (syntax-pps-comments /* 56 76 77 58)
 (syntax-pps-comments /* 60 78 79)
 
+(ert-deftest test-from-to-parse-partial-sexp ()
+  (with-temp-buffer
+    (insert "foo")
+    (should (parse-partial-sexp 1 1))
+    (should-error (parse-partial-sexp 2 1))))
+
 ;;; syntax-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]