diff --git a/TODO.md b/TODO.md index 748585c..2e786aa 100644 --- a/TODO.md +++ b/TODO.md @@ -4,8 +4,6 @@ ## Current work -* `eb_add_property()` should duplicate and free string argument -* add `cp_add_tag(cp, offset, kbuf)`? * `S-TAB` -> untabify * `TAB` and `S-TAB` with selected block -> indent, unindent block * `C-x (` should restart macro learning mode diff --git a/buffer.c b/buffer.c index 4ff0ef1..f4f208b 100644 --- a/buffer.c +++ b/buffer.c @@ -2,7 +2,7 @@ * Buffer handling for QEmacs * * Copyright (c) 2000-2002 Fabrice Bellard. - * Copyright (c) 2002-2023 Charlie Gordon. + * Copyright (c) 2002-2024 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -2678,21 +2678,10 @@ void eb_add_property(EditBuffer *b, int offset, int type, void *data) { eb_add_callback(b, eb_plist_callback, NULL, 0); } + /* insert property in ascending order of offset */ for (pp = &b->property_list; (p = *pp) != NULL; pp = &(*pp)->next) { - if (p->offset >= offset) { - if (p->offset == offset) { - if (p->type == type && type == QE_PROP_TAG) { - /* prevent tag duplicates */ - if (strequal(p->data, data)) { - if (type & QE_PROP_FREE) - qe_free(&data); - return; - } - } - continue; - } + if (p->offset > offset) break; - } } p = qe_mallocz(QEProperty); @@ -2703,6 +2692,17 @@ void eb_add_property(EditBuffer *b, int offset, int type, void *data) { *pp = p; } +void eb_add_tag(EditBuffer *b, int offset, const char *s) { + QEProperty *p; + + /* prevent tag duplicates */ + for (p = b->property_list; p != NULL; p = p->next) { + if (p->offset == offset && p->type == QE_PROP_TAG && strequal(p->data, s)) + return; + } + eb_add_property(b, offset, QE_PROP_TAG, qe_strdup(s)); +} + QEProperty *eb_find_property(EditBuffer *b, int offset, int offset2, int type) { QEProperty *found = NULL; QEProperty *p; diff --git a/lang/clang.c b/lang/clang.c index 9f7b428..ab8b09d 100644 --- a/lang/clang.c +++ b/lang/clang.c @@ -598,8 +598,7 @@ static void c_colorize_line(QEColorizeContext *cp, i2++; if (tag && qe_findchar("({[,;=", str[i1])) { - eb_add_property(cp->b, cp->offset + start, - QE_PROP_TAG, qe_strdup(kbuf)); + eb_add_tag(cp->b, cp->offset + start, kbuf); } if ((start == 0 || str[start - 1] != '.') @@ -1694,7 +1693,7 @@ static int get_js_identifier(char *dest, int size, char32_t c, int pos = 0, j = i; if (c == 0) { - if (!(i < n && is_js_identifier_start(c = str[i++]))) { + if (!(j < n && is_js_identifier_start(c = str[j++]))) { if (size > 0) *dest = '\0'; return 0; @@ -1996,16 +1995,14 @@ static void js_colorize_line(QEColorizeContext *cp, style = C_STYLE_FUNCTION; if (tag) { /* tag function definition */ - eb_add_property(cp->b, cp->offset + start, - QE_PROP_TAG, qe_strdup(kbuf)); + eb_add_tag(cp->b, cp->offset + start, kbuf); tag = 0; } break; } else if (tag && qe_findchar("(,;=", str[i1])) { /* tag variable definition */ - eb_add_property(cp->b, cp->offset + start, - QE_PROP_TAG, qe_strdup(kbuf)); + eb_add_tag(cp->b, cp->offset + start, kbuf); } if ((start == 0 || str[start - 1] != '.') @@ -3813,16 +3810,14 @@ static void salmon_colorize_line(QEColorizeContext *cp, style = C_STYLE_FUNCTION; if (tag) { /* tag function definition */ - eb_add_property(cp->b, cp->offset + start, - QE_PROP_TAG, qe_strdup(kbuf)); + eb_add_tag(cp->b, cp->offset + start, kbuf); tag = 0; } break; } else if (tag && qe_findchar("(,;=", str[i1])) { /* tag variable definition */ - eb_add_property(cp->b, cp->offset + start, - QE_PROP_TAG, qe_strdup(kbuf)); + eb_add_tag(cp->b, cp->offset + start, kbuf); } if ((start == 0 || str[start - 1] != '.') @@ -4202,9 +4197,8 @@ static void ppl_colorize_line(QEColorizeContext *cp, && strfind("function|creator|command|template|service|factory|type", kbuf)) { int fstart = cp_skip_blanks(str, i, n); - if (get_js_identifier(kbuf, countof(kbuf), 0, str, fstart, n)) { - eb_add_property(cp->b, cp->offset + fstart, QE_PROP_TAG, qe_strdup(kbuf)); - } + if (get_js_identifier(kbuf, countof(kbuf), 0, str, fstart, n)) + eb_add_tag(cp->b, cp->offset + start, kbuf); } else if (start == indent && strfind("java|java_header", kbuf)) { state |= IN_PPL_JAVA; diff --git a/lang/python.c b/lang/python.c index 4ab469b..732b85c 100644 --- a/lang/python.c +++ b/lang/python.c @@ -282,8 +282,7 @@ static void python_colorize_line(QEColorizeContext *cp, style = PYTHON_STYLE_FUNCTION; if (tag) { /* tag function definition */ - eb_add_property(cp->b, cp->offset + start, - QE_PROP_TAG, qe_strdup(kbuf)); + eb_add_tag(cp->b, cp->offset + start, kbuf); tag = 0; } break; @@ -293,8 +292,7 @@ static void python_colorize_line(QEColorizeContext *cp, continue; if (qe_findchar(",=", str[i1])) { /* tag variable definition */ - eb_add_property(cp->b, cp->offset + start, - QE_PROP_TAG, qe_strdup(kbuf)); + eb_add_tag(cp->b, cp->offset + start, kbuf); /* XXX: should colorize variable definition */ } } diff --git a/modes/fractal.c b/modes/fractal.c index 053ad9a..a3bad39 100644 --- a/modes/fractal.c +++ b/modes/fractal.c @@ -181,8 +181,7 @@ static void fractint_colorize_line(QEColorizeContext *cp, } style = FRACTINT_STYLE_COMMENT; } else { - eb_add_property(cp->b, cp->offset + start, - QE_PROP_TAG, qe_strdup(kbuf)); + eb_add_tag(cp->b, cp->offset + start, kbuf); style = FRACTINT_STYLE_DEFINITION; } break; diff --git a/qe.h b/qe.h index 11a86ca..a1e7b0f 100644 --- a/qe.h +++ b/qe.h @@ -595,6 +595,7 @@ struct QEProperty { void eb_add_property(EditBuffer *b, int offset, int type, void *data); QEProperty *eb_find_property(EditBuffer *b, int offset, int offset2, int type); +void eb_add_tag(EditBuffer *b, int offset, const char *s); void eb_delete_properties(EditBuffer *b, int offset, int offset2); /* qe module handling */