Add 'scan-error' error type.
authorSteve Youngs <steve@sxemacs.org>
Sun, 14 Jun 2015 06:01:39 +0000 (16:01 +1000)
committerSteve Youngs <steve@sxemacs.org>
Sun, 14 Jun 2015 06:01:39 +0000 (16:01 +1000)
* src/syntax.c: Add `Qscan_error'.

* src/syntax.c (syms_of_syntax): DEFERROR_STANDARD it.

* src/syntax.c (scan_lists): Use it.

* lisp/subr.el (error): Add it to the docstring.

Signed-off-by: Steve Youngs <steve@sxemacs.org>
lisp/subr.el
src/syntax.c

index a1b4959..d9a37a3 100644 (file)
@@ -1266,6 +1266,7 @@ error
     syntax-error
       invalid-read-syntax
       invalid-regexp
+      scan-error
       structure-formation-error
        list-formation-error
          malformed-list
index 4fbe814..13381b1 100644 (file)
@@ -88,6 +88,8 @@ Lisp_Object Vstandard_syntax_table;
 
 Lisp_Object Vsyntax_designator_chars_string;
 
+Lisp_Object Qscan_error;
+
 /* This is the internal form of the parse state used in parse-partial-sexp.  */
 
 struct lisp_parse_state {
@@ -1205,6 +1207,7 @@ scan_lists(struct buffer * buf, Bufpos from, int count, int depth,
        enum syntaxcode code;
        int syncode;
        int min_depth = depth;  /* Err out if depth gets less than this. */
+       Bufpos last_good = from;
 
        if (depth > 0)
                min_depth = 0;
@@ -1223,6 +1226,8 @@ scan_lists(struct buffer * buf, Bufpos from, int count, int depth,
                        c = BUF_FETCH_CHAR(buf, from);
                        syncode = SYNTAX_CODE_FROM_CACHE(mirrortab, c);
                        code = SYNTAX_FROM_CODE(syncode);
+                       if (depth == min_depth)
+                               last_good = from;
                        from++;
 
                        /* a 1-char comment start sequence */
@@ -1348,8 +1353,11 @@ scan_lists(struct buffer * buf, Bufpos from, int count, int depth,
                                if (depth < min_depth) {
                                        if (noerror)
                                                return Qnil;
-                                       error("Containing expression "
-                                             "ends prematurely");
+                                       signal_type_error_2(Qscan_error,
+                                                           "Containing expression "
+                                                           "ends prematurely",
+                                                           make_int(last_good),
+                                                           make_int(from));
                                }
                                break;
 
@@ -1536,8 +1544,11 @@ scan_lists(struct buffer * buf, Bufpos from, int count, int depth,
                                        if (noerror) {
                                                return Qnil;
                                        }
-                                       error("Containing expression "
-                                             "ends prematurely");
+                                       signal_type_error_2(Qscan_error,
+                                                           "Containing expression "
+                                                           "ends premeturely",
+                                                           make_int(last_good),
+                                                           make_int(from));
                                }
                                break;
 
@@ -1611,7 +1622,8 @@ scan_lists(struct buffer * buf, Bufpos from, int count, int depth,
 
       lose:
        if (!noerror)
-               error("Unbalanced parentheses");
+               signal_type_error_2(Qscan_error, "Unbalanced parentheses",
+                                   make_int(last_good), make_int(from));
        return Qnil;
 }
 
@@ -2260,6 +2272,8 @@ void syms_of_syntax(void)
        DEFSUBR(Fscan_sexps);
        DEFSUBR(Fbackward_prefix_chars);
        DEFSUBR(Fparse_partial_sexp);
+
+       DEFERROR_STANDARD(Qscan_error, Qsyntax_error);
 }
 
 void vars_of_syntax(void)