commit 861cf3a5c9d2081d811dcfc2c5ce5357f3dc44d4 (HEAD, refs/remotes/origin/master) Author: Stefan Monnier Date: Wed Apr 12 16:32:39 2023 -0400 (RE_SETUP_SYNTAX_TABLE_FOR_OBJECT): Simplify It turns out all calls to this function pass the same value for the `count` argument, and they're all in `regexp.c`. * src/syntax.c (RE_SETUP_SYNTAX_TABLE_FOR_OBJECT): Rename from `SETUP_SYNTAX_TABLE_FOR_OBJECT`. Remove `count` argument. Move call to `RE_SYNTAX_TABLE_BYTE_TO_CHAR` to where its result is actually used. * src/regex-emacs.c (re_search_2, re_match_2): Adjust accordingly. * src/syntax.h (RE_SYNTAX_TABLE_BYTE_TO_CHAR): Rename from `SYNTAX_TABLE_BYTE_TO_CHAR` to clarify that it takes a byteoffset as used in the regexp engine and not a "bytepos". Adjust all callers. diff --git a/src/regex-emacs.c b/src/regex-emacs.c index 83caeca2464..746779490ad 100644 --- a/src/regex-emacs.c +++ b/src/regex-emacs.c @@ -3251,7 +3251,7 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, ptrdiff_t size1, /* See whether the pattern is anchored. */ anchored_start = (bufp->buffer[0] == begline); - SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, startpos, 1); + RE_SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, startpos); /* Loop through the string, looking for a place to start matching. */ for (;;) @@ -3859,7 +3859,7 @@ re_match_2 (struct re_pattern_buffer *bufp, { ptrdiff_t result; - SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, pos, 1); + RE_SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, pos); result = re_match_2_internal (bufp, (re_char *) string1, size1, (re_char *) string2, size2, @@ -4792,7 +4792,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, int s1, s2; int dummy; ptrdiff_t offset = POINTER_TO_OFFSET (d); - ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1; + ptrdiff_t charpos = RE_SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1; UPDATE_SYNTAX_TABLE (charpos); GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); nchars++; @@ -4832,7 +4832,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, int s1, s2; int dummy; ptrdiff_t offset = POINTER_TO_OFFSET (d); - ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); + ptrdiff_t charpos = RE_SYNTAX_TABLE_BYTE_TO_CHAR (offset); UPDATE_SYNTAX_TABLE (charpos); PREFETCH (); GET_CHAR_AFTER (c2, d, dummy); @@ -4875,7 +4875,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, int s1, s2; int dummy; ptrdiff_t offset = POINTER_TO_OFFSET (d); - ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1; + ptrdiff_t charpos = RE_SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1; UPDATE_SYNTAX_TABLE (charpos); GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); nchars++; @@ -4917,7 +4917,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, int c1, c2; int s1, s2; ptrdiff_t offset = POINTER_TO_OFFSET (d); - ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); + ptrdiff_t charpos = RE_SYNTAX_TABLE_BYTE_TO_CHAR (offset); UPDATE_SYNTAX_TABLE (charpos); PREFETCH (); c2 = RE_STRING_CHAR (d, target_multibyte); @@ -4958,7 +4958,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, int c1, c2; int s1, s2; ptrdiff_t offset = POINTER_TO_OFFSET (d); - ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1; + ptrdiff_t charpos = RE_SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1; UPDATE_SYNTAX_TABLE (charpos); GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); nchars++; @@ -4994,7 +4994,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, PREFETCH (); { ptrdiff_t offset = POINTER_TO_OFFSET (d); - ptrdiff_t pos1 = SYNTAX_TABLE_BYTE_TO_CHAR (offset); + ptrdiff_t pos1 = RE_SYNTAX_TABLE_BYTE_TO_CHAR (offset); UPDATE_SYNTAX_TABLE (pos1); } { diff --git a/src/syntax.c b/src/syntax.c index c1caaa8a739..e9e04e2d638 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -268,12 +268,11 @@ SETUP_SYNTAX_TABLE (ptrdiff_t from, ptrdiff_t count) FROMBYTE is an regexp-byteoffset. */ void -SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object, - ptrdiff_t frombyte, ptrdiff_t count) +RE_SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object, + ptrdiff_t frombyte) { SETUP_BUFFER_SYNTAX_TABLE (); gl_state.object = object; - ptrdiff_t from = SYNTAX_TABLE_BYTE_TO_CHAR (frombyte); if (BUFFERP (gl_state.object)) { struct buffer *buf = XBUFFER (gl_state.object); @@ -296,8 +295,8 @@ SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object, gl_state.e_property = 1 + SCHARS (gl_state.object); } if (parse_sexp_lookup_properties) - update_syntax_table (from - (count <= 0), - count, 1, gl_state.object); + update_syntax_table (RE_SYNTAX_TABLE_BYTE_TO_CHAR (frombyte), + 1, 1, gl_state.object); } /* Update gl_state to an appropriate interval which contains CHARPOS. The diff --git a/src/syntax.h b/src/syntax.h index 05d58eff05f..01982be25a0 100644 --- a/src/syntax.h +++ b/src/syntax.h @@ -145,15 +145,15 @@ SYNTAX (int c) extern unsigned char const syntax_spec_code[0400]; -/* Convert the regexp BYTEOFFSET into a character position, - for the object recorded in gl_state with SETUP_SYNTAX_TABLE_FOR_OBJECT. +/* Convert the regexp's BYTEOFFSET into a character position, + for the object recorded in gl_state with RE_SETUP_SYNTAX_TABLE_FOR_OBJECT. The value is meant for use in code that does nothing when parse_sexp_lookup_properties is false, so return 0 in that case, for speed. */ INLINE ptrdiff_t -SYNTAX_TABLE_BYTE_TO_CHAR (ptrdiff_t byteoffset) +RE_SYNTAX_TABLE_BYTE_TO_CHAR (ptrdiff_t byteoffset) { return (! parse_sexp_lookup_properties ? 0 @@ -208,7 +208,7 @@ SETUP_BUFFER_SYNTAX_TABLE (void) } extern ptrdiff_t scan_words (ptrdiff_t, EMACS_INT); -extern void SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object, ptrdiff_t, ptrdiff_t); +extern void RE_SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object, ptrdiff_t); INLINE_HEADER_END commit c2c3114961802b4c52b4cde0271e460fb08698cf Author: Stefan Monnier Date: Wed Apr 12 15:50:49 2023 -0400 (SETUP_SYNTAX_TABLE_FOR_OBJECT): Take a byteoffset * src/syntax.c (SETUP_SYNTAX_TABLE_FOR_OBJECT): Take a byteoffset. * src/regex-emacs.c (re_search_2, re_match_2): Simplify accordingly. diff --git a/src/regex-emacs.c b/src/regex-emacs.c index 969f2ff9464..83caeca2464 100644 --- a/src/regex-emacs.c +++ b/src/regex-emacs.c @@ -3251,12 +3251,7 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, ptrdiff_t size1, /* See whether the pattern is anchored. */ anchored_start = (bufp->buffer[0] == begline); - gl_state.object = re_match_object; /* Used by SYNTAX_TABLE_BYTE_TO_CHAR. */ - { - ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (startpos); - - SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, charpos, 1); - } + SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, startpos, 1); /* Loop through the string, looking for a place to start matching. */ for (;;) @@ -3864,10 +3859,7 @@ re_match_2 (struct re_pattern_buffer *bufp, { ptrdiff_t result; - ptrdiff_t charpos; - gl_state.object = re_match_object; /* Used by SYNTAX_TABLE_BYTE_TO_CHAR. */ - charpos = SYNTAX_TABLE_BYTE_TO_CHAR (pos); - SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, charpos, 1); + SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, pos, 1); result = re_match_2_internal (bufp, (re_char *) string1, size1, (re_char *) string2, size2, diff --git a/src/syntax.c b/src/syntax.c index 8ef13eec40a..c1caaa8a739 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -264,14 +264,16 @@ SETUP_SYNTAX_TABLE (ptrdiff_t from, ptrdiff_t count) /* Same as above, but in OBJECT. If OBJECT is nil, use current buffer. If it is t (which is only used in fast_c_string_match_ignore_case), - ignore properties altogether. */ + ignore properties altogether. + FROMBYTE is an regexp-byteoffset. */ void SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object, - ptrdiff_t from, ptrdiff_t count) + ptrdiff_t frombyte, ptrdiff_t count) { SETUP_BUFFER_SYNTAX_TABLE (); gl_state.object = object; + ptrdiff_t from = SYNTAX_TABLE_BYTE_TO_CHAR (frombyte); if (BUFFERP (gl_state.object)) { struct buffer *buf = XBUFFER (gl_state.object); commit d53ff9fe28b63dcd9bab2479cb7a517ba7233016 Author: Stefan Monnier Date: Wed Apr 12 15:44:58 2023 -0400 src/regex-emacs.c (POS_AS_IN_BUFFER): Delete macro That macro added 1 to buffer positions because: Strings are 0-indexed, buffers are 1-indexed but the reality is that this 1 was added to the regexp engine's "byte offsets" which are not 1-based byte positions as used throughout the rest of Emacs, but they are BEGV_BYTE-relative offsets, so the two did not cancel out. * src/regex-emacs.c (PTR_TO_OFFSET, POS_AS_IN_BUFFER): Delete macros; use `POINTER_TO_OFFSET` instead. (re_search_2, re_match_2, re_match_2_internal): Adjust accordingly. * src/syntax.h (SYNTAX_TABLE_BYTE_TO_CHAR): Don't remove 1 from buffer byteoffsets now that `POS_AS_IN_BUFFER` doesn't add it any more. diff --git a/src/regex-emacs.c b/src/regex-emacs.c index 2571812cb39..969f2ff9464 100644 --- a/src/regex-emacs.c +++ b/src/regex-emacs.c @@ -47,13 +47,6 @@ #define RE_DUP_MAX (0xffff) /* Make syntax table lookup grant data in gl_state. */ #define SYNTAX(c) syntax_property (c, 1) -/* Convert the pointer to the char to BEG-based offset from the start. */ -#define PTR_TO_OFFSET(d) POS_AS_IN_BUFFER (POINTER_TO_OFFSET (d)) -/* Strings are 0-indexed, buffers are 1-indexed; pun on the boolean - result to get the right base index. */ -#define POS_AS_IN_BUFFER(p) \ - ((p) + (NILP (gl_state.object) || BUFFERP (gl_state.object))) - #define RE_MULTIBYTE_P(bufp) ((bufp)->multibyte) #define RE_TARGET_MULTIBYTE_P(bufp) ((bufp)->target_multibyte) #define RE_STRING_CHAR(p, multibyte) \ @@ -3260,7 +3253,7 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, ptrdiff_t size1, gl_state.object = re_match_object; /* Used by SYNTAX_TABLE_BYTE_TO_CHAR. */ { - ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (POS_AS_IN_BUFFER (startpos)); + ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (startpos); SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, charpos, 1); } @@ -3873,7 +3866,7 @@ re_match_2 (struct re_pattern_buffer *bufp, ptrdiff_t charpos; gl_state.object = re_match_object; /* Used by SYNTAX_TABLE_BYTE_TO_CHAR. */ - charpos = SYNTAX_TABLE_BYTE_TO_CHAR (POS_AS_IN_BUFFER (pos)); + charpos = SYNTAX_TABLE_BYTE_TO_CHAR (pos); SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, charpos, 1); result = re_match_2_internal (bufp, (re_char *) string1, size1, @@ -4806,7 +4799,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, int c1, c2; int s1, s2; int dummy; - ptrdiff_t offset = PTR_TO_OFFSET (d); + ptrdiff_t offset = POINTER_TO_OFFSET (d); ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1; UPDATE_SYNTAX_TABLE (charpos); GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); @@ -4846,7 +4839,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, int c1, c2; int s1, s2; int dummy; - ptrdiff_t offset = PTR_TO_OFFSET (d); + ptrdiff_t offset = POINTER_TO_OFFSET (d); ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); UPDATE_SYNTAX_TABLE (charpos); PREFETCH (); @@ -4889,7 +4882,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, int c1, c2; int s1, s2; int dummy; - ptrdiff_t offset = PTR_TO_OFFSET (d); + ptrdiff_t offset = POINTER_TO_OFFSET (d); ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1; UPDATE_SYNTAX_TABLE (charpos); GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); @@ -4931,7 +4924,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, is the character at D, and S2 is the syntax of C2. */ int c1, c2; int s1, s2; - ptrdiff_t offset = PTR_TO_OFFSET (d); + ptrdiff_t offset = POINTER_TO_OFFSET (d); ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); UPDATE_SYNTAX_TABLE (charpos); PREFETCH (); @@ -4972,7 +4965,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, is the character at D, and S2 is the syntax of C2. */ int c1, c2; int s1, s2; - ptrdiff_t offset = PTR_TO_OFFSET (d); + ptrdiff_t offset = POINTER_TO_OFFSET (d); ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1; UPDATE_SYNTAX_TABLE (charpos); GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); @@ -5008,7 +5001,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, mcnt); PREFETCH (); { - ptrdiff_t offset = PTR_TO_OFFSET (d); + ptrdiff_t offset = POINTER_TO_OFFSET (d); ptrdiff_t pos1 = SYNTAX_TABLE_BYTE_TO_CHAR (offset); UPDATE_SYNTAX_TABLE (pos1); } diff --git a/src/syntax.h b/src/syntax.h index aefe4dafa42..05d58eff05f 100644 --- a/src/syntax.h +++ b/src/syntax.h @@ -145,7 +145,7 @@ SYNTAX (int c) extern unsigned char const syntax_spec_code[0400]; -/* Convert the byte offset BYTEPOS into a character position, +/* Convert the regexp BYTEOFFSET into a character position, for the object recorded in gl_state with SETUP_SYNTAX_TABLE_FOR_OBJECT. The value is meant for use in code that does nothing when @@ -153,19 +153,19 @@ SYNTAX (int c) for speed. */ INLINE ptrdiff_t -SYNTAX_TABLE_BYTE_TO_CHAR (ptrdiff_t bytepos) +SYNTAX_TABLE_BYTE_TO_CHAR (ptrdiff_t byteoffset) { return (! parse_sexp_lookup_properties ? 0 : STRINGP (gl_state.object) - ? string_byte_to_char (gl_state.object, bytepos) + ? string_byte_to_char (gl_state.object, byteoffset) : BUFFERP (gl_state.object) ? ((buf_bytepos_to_charpos (XBUFFER (gl_state.object), - (bytepos + BUF_BEGV_BYTE (XBUFFER (gl_state.object)) - 1)))) + (byteoffset + BUF_BEGV_BYTE (XBUFFER (gl_state.object)))))) : NILP (gl_state.object) - ? BYTE_TO_CHAR (bytepos + BEGV_BYTE - 1) - : bytepos); + ? BYTE_TO_CHAR (byteoffset + BEGV_BYTE) + : byteoffset); } /* Make syntax table state (gl_state) good for CHARPOS, assuming it is commit 1e6463ad22cd74b1b74b9395dff8c8b1485e202e Author: Stefan Monnier Date: Wed Apr 12 15:14:39 2023 -0400 (struct gl_state_s): Delete `offset` field `gl_state` had an `offset` field because: For buffers, regex-emacs.c passes arguments to the UPDATE_SYNTAX_TABLE functions which are relative to BEGV but the reality is that these arguments are byte offsets relative to BEGV_BYTE whereas `offset` was counted in chars, so the two didn't cancel each other out. * src/syntax.h (struct gl_state_s): Delete `offset` field. (UPDATE_SYNTAX_TABLE_FORWARD, UPDATE_SYNTAX_TABLE_BACKWARD) (SYNTAX_TABLE_BYTE_TO_CHAR): * src/syntax.c (SETUP_SYNTAX_TABLE, SETUP_SYNTAX_TABLE_FOR_OBJECT) (update_syntax_table, skip_syntaxes): Simplify accordingly. diff --git a/src/syntax.c b/src/syntax.c index 79e16f652f3..8ef13eec40a 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -250,7 +250,6 @@ SETUP_SYNTAX_TABLE (ptrdiff_t from, ptrdiff_t count) gl_state.b_property = BEGV; gl_state.e_property = ZV + 1; gl_state.object = Qnil; - gl_state.offset = 0; if (parse_sexp_lookup_properties) { if (count > 0) @@ -265,12 +264,7 @@ SETUP_SYNTAX_TABLE (ptrdiff_t from, ptrdiff_t count) /* Same as above, but in OBJECT. If OBJECT is nil, use current buffer. If it is t (which is only used in fast_c_string_match_ignore_case), - ignore properties altogether. - - This is meant for regex-emacs.c to use. For buffers, regex-emacs.c - passes arguments to the UPDATE_SYNTAX_TABLE functions which are - relative to BEGV. So if it is a buffer, we set the offset field to - BEGV. */ + ignore properties altogether. */ void SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object, @@ -281,30 +275,26 @@ SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object, if (BUFFERP (gl_state.object)) { struct buffer *buf = XBUFFER (gl_state.object); - gl_state.b_property = 1; - gl_state.e_property = BUF_ZV (buf) - BUF_BEGV (buf) + 1; - gl_state.offset = BUF_BEGV (buf) - 1; + gl_state.b_property = BEG; + gl_state.e_property = BUF_ZV (buf); } else if (NILP (gl_state.object)) { - gl_state.b_property = 1; - gl_state.e_property = ZV - BEGV + 1; - gl_state.offset = BEGV - 1; + gl_state.b_property = BEG; + gl_state.e_property = ZV; /* FIXME: Why not +1 like in SETUP_SYNTAX_TABLE? */ } else if (EQ (gl_state.object, Qt)) { gl_state.b_property = 0; gl_state.e_property = PTRDIFF_MAX; - gl_state.offset = 0; } else { gl_state.b_property = 0; gl_state.e_property = 1 + SCHARS (gl_state.object); - gl_state.offset = 0; } if (parse_sexp_lookup_properties) - update_syntax_table (from + gl_state.offset - (count <= 0), + update_syntax_table (from - (count <= 0), count, 1, gl_state.object); } @@ -341,8 +331,8 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, bool init, if (!i) return; i = gl_state.forward_i; - gl_state.b_property = i->position - gl_state.offset; - gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset; + gl_state.b_property = i->position; + gl_state.e_property = INTERVAL_LAST_POS (i); } else { @@ -362,7 +352,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, bool init, { invalidate = false; gl_state.forward_i = i; - gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset; + gl_state.e_property = INTERVAL_LAST_POS (i); } } else if (charpos >= INTERVAL_LAST_POS (i)) /* Move right. */ @@ -375,7 +365,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, bool init, { invalidate = false; gl_state.backward_i = i; - gl_state.b_property = i->position - gl_state.offset; + gl_state.b_property = i->position; } } } @@ -391,12 +381,12 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, bool init, if (count > 0) { gl_state.backward_i = i; - gl_state.b_property = i->position - gl_state.offset; + gl_state.b_property = i->position; } else { gl_state.forward_i = i; - gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset; + gl_state.e_property = INTERVAL_LAST_POS (i); } } @@ -426,13 +416,13 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, bool init, { if (count > 0) { - gl_state.e_property = i->position - gl_state.offset; + gl_state.e_property = i->position; gl_state.forward_i = i; } else { gl_state.b_property - = i->position + LENGTH (i) - gl_state.offset; + = i->position + LENGTH (i); gl_state.backward_i = i; } return; @@ -442,7 +432,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, bool init, if (count > 0) { gl_state.e_property - = i->position + LENGTH (i) - gl_state.offset + = i->position + LENGTH (i) /* e_property at EOB is not set to ZV but to ZV+1, so that we can do INC(from);UPDATE_SYNTAX_TABLE_FORWARD without having to check eob between the two. */ @@ -451,7 +441,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, bool init, } else { - gl_state.b_property = i->position - gl_state.offset; + gl_state.b_property = i->position; gl_state.backward_i = i; } return; @@ -2201,8 +2191,7 @@ skip_syntaxes (bool forwardp, Lisp_Object string, Lisp_Object lim) while (!parse_sexp_lookup_properties || pos < gl_state.e_property); - update_syntax_table_forward (pos + gl_state.offset, - false, gl_state.object); + update_syntax_table_forward (pos, false, gl_state.object); } } else diff --git a/src/syntax.h b/src/syntax.h index 9eb8701628b..aefe4dafa42 100644 --- a/src/syntax.h +++ b/src/syntax.h @@ -85,8 +85,6 @@ #define Vstandard_syntax_table BVAR (&buffer_defaults, syntax_table) and possibly at the intervals too, depending on: */ - /* Offset for positions specified to UPDATE_SYNTAX_TABLE. */ - ptrdiff_t offset; }; extern struct gl_state_s gl_state; @@ -164,10 +162,9 @@ SYNTAX_TABLE_BYTE_TO_CHAR (ptrdiff_t bytepos) : BUFFERP (gl_state.object) ? ((buf_bytepos_to_charpos (XBUFFER (gl_state.object), - (bytepos + BUF_BEGV_BYTE (XBUFFER (gl_state.object)) - 1))) - - BUF_BEGV (XBUFFER (gl_state.object)) + 1) + (bytepos + BUF_BEGV_BYTE (XBUFFER (gl_state.object)) - 1)))) : NILP (gl_state.object) - ? BYTE_TO_CHAR (bytepos + BEGV_BYTE - 1) - BEGV + 1 + ? BYTE_TO_CHAR (bytepos + BEGV_BYTE - 1) : bytepos); } @@ -178,8 +175,7 @@ SYNTAX_TABLE_BYTE_TO_CHAR (ptrdiff_t bytepos) UPDATE_SYNTAX_TABLE_FORWARD (ptrdiff_t charpos) { /* Performs just-in-time syntax-propertization. */ if (parse_sexp_lookup_properties && charpos >= gl_state.e_property) - update_syntax_table_forward (charpos + gl_state.offset, - false, gl_state.object); + update_syntax_table_forward (charpos, false, gl_state.object); } /* Make syntax table state (gl_state) good for CHARPOS, assuming it is @@ -189,7 +185,7 @@ UPDATE_SYNTAX_TABLE_FORWARD (ptrdiff_t charpos) UPDATE_SYNTAX_TABLE_BACKWARD (ptrdiff_t charpos) { if (parse_sexp_lookup_properties && charpos < gl_state.b_property) - update_syntax_table (charpos + gl_state.offset, -1, false, gl_state.object); + update_syntax_table (charpos, -1, false, gl_state.object); } /* Make syntax table good for CHARPOS. */ commit 8fdd7710ec0448fe9d3908ad073ddd4d69917719 Author: João Távora Date: Wed Apr 12 14:41:13 2023 +0100 Flymake: futher enhance echo-area appearance of diagnostics Also describe new 'echo-face' property in the Flymake manual, and fix it's mistaken mention of a non-existing 'flymake-severity' property. * doc/misc/flymake.texi: (Flymake error types): Describe new properties and correct mention of 'severity' property. * lisp/progmodes/flymake.el: (flymake-diagnostic-oneliner): Rework. (flymake-error, flymake-warning, flymake-note): Add new 'echo-face' property. (flymake--highlight-line) (flymake-eldoc-function) (flymake--tabulated-entries-1): Use flymake-diagnostic-oneliner (Version): Bump to 1.3.3 diff --git a/doc/misc/flymake.texi b/doc/misc/flymake.texi index 03d296a1d42..13616f39f16 100644 --- a/doc/misc/flymake.texi +++ b/doc/misc/flymake.texi @@ -1,8 +1,8 @@ \input texinfo @c -*- mode: texinfo; coding: utf-8 -*- @comment %**start of header @setfilename ../../info/flymake.info -@set VERSION 1.2.2 -@set UPDATED November 2021 +@set VERSION 1.3.3 +@set UPDATED April 2023 @settitle GNU Flymake @value{VERSION} @include docstyle.texi @syncodeindex pg cp @@ -394,7 +394,7 @@ Flymake error types @item @cindex severity of diagnostic -@code{flymake-severity} is a non-negative integer specifying the +@code{severity} is a non-negative integer specifying the diagnostic's severity. The higher the value, the more serious is the error. If the overlay property @code{priority} is not specified in @code{flymake-overlay-control}, @code{flymake-severity} is used to set @@ -409,6 +409,17 @@ Flymake error types @vindex flymake-category @code{flymake-category} is a symbol whose property list is considered the default for missing values of any other properties. + +@item +@cindex mode-line appearance of a diagnostic +@code{mode-line-face} is a face specifier controlling the appearance +of the indicator of this type of diagnostic in the mode line. + +@item +@cindex summarized appearance of a diagnostic +@code{echo-face} is a face specifier controlling the appearance of the +summarized description of this diagnostic when reading diagnostic +messages (@pxref{Finding diagnostics}). @end itemize @cindex predefined diagnostic types diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index 1cd9f0a6b0c..c751e5bd432 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el @@ -4,7 +4,7 @@ ;; Author: Pavel Kobyakov ;; Maintainer: João Távora -;; Version: 1.3.2 +;; Version: 1.3.3 ;; Keywords: c languages tools ;; Package-Requires: ((emacs "26.1") (eldoc "1.14.0") (project "0.7.1")) @@ -371,11 +371,19 @@ flymake--diag-accessor (flymake--diag-accessor flymake-diagnostic-end flymake--diag-end end) (flymake--diag-accessor flymake-diagnostic-buffer flymake--diag-locus locus) -(defun flymake-diagnostic-oneliner (diag) - "Get truncated one-line text string for diagnostic DIAG." - (let ((txt (flymake-diagnostic-text diag))) - (substring txt 0 (cl-loop for i from 0 for a across txt - when (eq a ?\n) return i)))) +(defun flymake-diagnostic-oneliner (diag &optional nopaintp) + "Get truncated one-line text string for diagnostic DIAG. +This is useful for displaying the DIAG's text to the user in +confined spaces, such as the echo are. Unless NOPAINTP is t, +propertize returned text with the `echo-face' property of DIAG's +type." + (let* ((txt (flymake-diagnostic-text diag)) + (txt (substring txt 0 (cl-loop for i from 0 for a across txt + when (eq a ?\n) return i)))) + (if nopaintp txt + (propertize txt 'face + (flymake--lookup-type-property + (flymake-diagnostic-type diag) 'echo-face 'flymake-error))))) (cl-defun flymake--overlays (&key beg end filter compare key) "Get flymake-related overlays. @@ -577,18 +585,21 @@ flymake-diagnostic-types-alist (put 'flymake-error 'flymake-bitmap 'flymake-error-bitmap) (put 'flymake-error 'severity (warning-numeric-level :error)) (put 'flymake-error 'mode-line-face 'compilation-error) +(put 'flymake-error 'echo-face 'error) (put 'flymake-error 'flymake-type-name "error") (put 'flymake-warning 'face 'flymake-warning) (put 'flymake-warning 'flymake-bitmap 'flymake-warning-bitmap) (put 'flymake-warning 'severity (warning-numeric-level :warning)) (put 'flymake-warning 'mode-line-face 'compilation-warning) +(put 'flymake-warning 'echo-face 'warning) (put 'flymake-warning 'flymake-type-name "warning") (put 'flymake-note 'face 'flymake-note) (put 'flymake-note 'flymake-bitmap 'flymake-note-bitmap) (put 'flymake-note 'severity (warning-numeric-level :debug)) (put 'flymake-note 'mode-line-face 'compilation-info) +(put 'flymake-note 'echo-face 'compilation-info) (put 'flymake-note 'flymake-type-name "note") (defun flymake--lookup-type-property (type prop &optional default) @@ -736,7 +747,7 @@ flymake--highlight-line (lambda (window _ov pos) (with-selected-window window (mapconcat - #'flymake-diagnostic-text + #'flymake-diagnostic-oneliner (flymake-diagnostics pos) "\n")))) (default-maybe 'severity (warning-numeric-level :error)) @@ -1263,13 +1274,7 @@ flymake-eldoc-function (when-let ((diags (flymake-diagnostics (point)))) (funcall report-doc (mapconcat #'flymake-diagnostic-text diags "\n") - :echo (mapconcat (lambda (d) - (propertize (flymake-diagnostic-oneliner d) - 'face - (flymake--lookup-type-property - (flymake-diagnostic-type d) - 'face - 'flymake-error))) + :echo (mapconcat #'flymake-diagnostic-oneliner diags "\n")))) (defun flymake-goto-next-error (&optional n filter interactive) @@ -1595,7 +1600,7 @@ flymake--tabulated-entries-1 "\\1\\2" bname) "(anon)") 'help-echo (format "From `%s' backend" backend)) - (,(flymake-diagnostic-oneliner diag) + (,(flymake-diagnostic-oneliner diag t) mouse-face highlight help-echo "mouse-2: visit this diagnostic" face nil commit 9d025eab2492519b26d69667a529865ea01f3318 Author: Mattias Engdegård Date: Wed Apr 12 10:42:57 2023 +0200 `byte-code-function-p` is error-free * lisp/emacs-lisp/byte-opt.el (side-effect-free-fns, side-effect-and-error-free-fns): Upgrade `byte-code-function-p` to error-free status. diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el index dad3bd694a6..c9c94f51ef0 100644 --- a/lisp/emacs-lisp/byte-opt.el +++ b/lisp/emacs-lisp/byte-opt.el @@ -1642,7 +1642,7 @@ byte-optimize-set bool-vector-count-consecutive bool-vector-count-population bool-vector-subsetp boundp buffer-file-name buffer-local-variables buffer-modified-p - buffer-substring byte-code-function-p + buffer-substring capitalize car-less-than-car car cdr ceiling char-after char-before char-equal char-to-string char-width compare-strings window-configuration-equal-p concat coordinates-in-window-p @@ -1702,6 +1702,7 @@ byte-optimize-set '(arrayp atom bobp bolp bool-vector-p buffer-list buffer-size buffer-string bufferp + byte-code-function-p car-safe case-table-p cdr-safe char-or-string-p characterp charsetp commandp cons consp current-buffer current-global-map current-indentation commit ea9831bb3cb4878273f6f848051c9b8c3c76d5f1 Author: Mattias Engdegård Date: Wed Apr 12 10:17:01 2023 +0200 Better compilation of arguments to `ignore` * lisp/emacs-lisp/bytecomp.el (byte-compile-form) (byte-compile-ignore): Instead of compiling each `ignore` argument for value which is then immediately discarded, compile it for effect but suppress ignore-return-value warnings by passing the special value `for-effect-no-warn` as for-effect parameter. Proposed by Stefan Monnier. diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 1b28fcd5093..c84c70971b3 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -3563,6 +3563,8 @@ byte-compile-form ;;delq delete cl-delete ;;nconc plist-put ))) + ;; Don't warn for arguments to `ignore'. + (not (eq byte-compile--for-effect 'for-effect-no-warn)) (byte-compile-warning-enabled-p 'ignored-return-value (car form))) (byte-compile-warn-x @@ -4446,11 +4448,8 @@ byte-compile-goto-if (defun byte-compile-ignore (form) (dolist (arg (cdr form)) - ;; Compile args for value (to avoid warnings about unused values), - ;; emit a discard after each, and trust the LAP peephole optimiser - ;; to annihilate useless ops. - (byte-compile-form arg) - (byte-compile-discard)) + ;; Compile each argument for-effect but suppress unused-value warnings. + (byte-compile-form arg 'for-effect-no-warn)) (byte-compile-form nil)) ;; Return the list of items in CONDITION-PARAM that match PRED-LIST.