From 073fbc3439606fecfbebd0cf302e6496ef268490 Mon Sep 17 00:00:00 2001 From: Charlie Gordon Date: Fri, 31 Mar 2017 15:33:02 +0000 Subject: [PATCH] tags: fix some bugs, extend system - pass target window to completion functions - fix tag completion at find-tag prompt - add tag support in python mode - set tag offset to the actual word instead of start of line --- TODO.org | 41 ++++++++++++++++++++++++++++++++++++++--- clang.c | 12 ++++++++---- extra-modes.c | 26 +++++++++++++++++++++++++- extras.c | 10 ++++++---- qe.c | 5 +++-- qe.h | 3 ++- 6 files changed, 82 insertions(+), 15 deletions(-) diff --git a/TODO.org b/TODO.org index 2bf7d75..7e054e4 100644 --- a/TODO.org +++ b/TODO.org @@ -1,11 +1,10 @@ ; TODO list for qemacs ; ; Author: Charles Gordon -; Updated: 2017-03-25 +; Updated: 2017-03-31 * Needed for release version 5 - * Priority 0 ** basic: fix current position when changing buffer attached to window @@ -238,7 +237,9 @@ qemacs does not take into account combination performed by the terminal. Terminal glyph width of 0 should be supported. ** deal with accents in filenames (OS/X uses separate utf8 accents) -** 256 color mode +** support 256 and true color escapes in tty emulator +** support st-256-color terminal +** support 256 and true color terminals ** auto-fill-mode ** auto-revert-mode, global-auto-revert-mode, auto-revert-tail-mode ** rectangular regions, cut/paste @@ -568,3 +569,37 @@ C-x ` for next-error M-g M-g goto-line (with prefix argument) M-g M-p previous-error M-g M-n next-error + +colorizing bug: static int (*qe__initcall_first)(void) qe__init_call = NULL; +missed tag: static int (*qe__initcall_first)(void) qe__init_call = NULL; + +create tags in other languages: +ats.c:201: style = ATS_STYLE_FUNCTION; +elm.c:233: style = ELM_STYLE_FUNCTION; +extra-modes.c:515: style = VIM_STYLE_FUNCTION; +extra-modes.c:686: style = PASCAL_STYLE_FUNCTION; +extra-modes.c:866: style = ADA_STYLE_FUNCTION; +extra-modes.c:1017: style = FORTRAN_STYLE_FUNCTION; +extra-modes.c:1086: style = INI_STYLE_FUNCTION; +extra-modes.c:1706: SET_COLOR(str, start, i, LUA_STYLE_FUNCTION); +extra-modes.c:1973: SET_COLOR(str, start, i, JULIA_STYLE_FUNCTION); +extra-modes.c:2194: style = HASKELL_STYLE_FUNCTION; +extra-modes.c:2551: style = COFFEE_STYLE_FUNCTION; +extra-modes.c:2793: style = PYTHON_STYLE_FUNCTION; +extra-modes.c:3285: style = RUBY_STYLE_FUNCTION; +extra-modes.c:3540: style = ERLANG_STYLE_FUNCTION; +extra-modes.c:3829: style = ELIXIR_STYLE_FUNCTION; +extra-modes.c:4054: style = OCAML_STYLE_FUNCTION; +extra-modes.c:4165: style = EMF_STYLE_FUNCTION; +extra-modes.c:4331: style = AGENA_STYLE_FUNCTION; +extra-modes.c:4693: style = SCAD_STYLE_FUNCTION; +groovy.c:425: style = GROOVY_STYLE_FUNCTION; +icon.c:177: style = ICON_STYLE_FUNCTION; +jai.c:215: style = JAI_STYLE_FUNCTION; +latex-mode.c:94: SET_COLOR(str, start, i, LATEX_STYLE_FUNCTION); +makemode.c:253: SET_COLOR(str, start, i, CMAKE_STYLE_FUNCTION); +nim.c:306: style = NIM_STYLE_FUNCTION; +rlang.c:169: style = R_STYLE_FUNCTION; +rust.c:249: style = RUST_STYLE_FUNCTION; +swift.c:284: style = C_STYLE_FUNCTION; +virgil.c:426: style = VIRGIL_STYLE_FUNCTION; diff --git a/clang.c b/clang.c index 945bd49..04d133e 100644 --- a/clang.c +++ b/clang.c @@ -546,7 +546,8 @@ static void c_colorize_line(QEColorizeContext *cp, case '(': case '{': tag = 0; - break; + continue; + default: normal: if (state & IN_C_PREPROCESS) @@ -584,7 +585,8 @@ static void c_colorize_line(QEColorizeContext *cp, i2++; if (tag && qe_findchar("({[,;=", str[i1])) { - eb_add_property(cp->b, cp->offset, QE_PROP_TAG, qe_strdup(kbuf)); + eb_add_property(cp->b, cp->offset + start, + QE_PROP_TAG, qe_strdup(kbuf)); } if ((start == 0 || str[start - 1] != '.') @@ -1723,14 +1725,16 @@ static void js_colorize_line(QEColorizeContext *cp, style = C_STYLE_FUNCTION; if (tag) { /* tag function definition */ - eb_add_property(cp->b, cp->offset, QE_PROP_TAG, qe_strdup(kbuf)); + eb_add_property(cp->b, cp->offset + start, + QE_PROP_TAG, qe_strdup(kbuf)); tag = 0; } break; } else if (tag && qe_findchar("(,;=", str[i1])) { /* tag variable definition */ - eb_add_property(cp->b, cp->offset, QE_PROP_TAG, qe_strdup(kbuf)); + eb_add_property(cp->b, cp->offset + start, + QE_PROP_TAG, qe_strdup(kbuf)); } if ((start == 0 || str[start - 1] != '.') diff --git a/extra-modes.c b/extra-modes.c index b7f934f..fc429b3 100644 --- a/extra-modes.c +++ b/extra-modes.c @@ -2621,7 +2621,7 @@ enum { static void python_colorize_line(QEColorizeContext *cp, unsigned int *str, int n, ModeDef *syn) { - int i = 0, start = i, c, style = 0, sep, klen; + int i = 0, start = i, c, style = 0, sep, klen, i1, tag = 0; int state = cp->colorize_state; char kbuf[32]; @@ -2642,6 +2642,8 @@ static void python_colorize_line(QEColorizeContext *cp, goto parse_long_string; } + tag = !qe_isblank(str[i]); + while (i < n) { start = i; c = str[i++]; @@ -2724,6 +2726,11 @@ static void python_colorize_line(QEColorizeContext *cp, } goto has_alpha; + case '(': + case '{': + tag = 0; + continue; + default: if (qe_isdigit(c)) { if (c == '0' && qe_tolower(str[i]) == 'b') { @@ -2778,13 +2785,30 @@ static void python_colorize_line(QEColorizeContext *cp, kbuf[klen] = '\0'; if (strfind(syn->keywords, kbuf)) { + tag = strequal(kbuf, "def"); style = PYTHON_STYLE_KEYWORD; break; } if (check_fcall(str, i)) { style = PYTHON_STYLE_FUNCTION; + if (tag) { + /* tag function definition */ + eb_add_property(cp->b, cp->offset + start, + QE_PROP_TAG, qe_strdup(kbuf)); + tag = 0; + } break; } + if (tag) { + for (i1 = i; i1 < n && qe_isblank(str[i1]); i1++) + continue; + if (qe_findchar(",=", str[i1])) { + /* tag variable definition */ + eb_add_property(cp->b, cp->offset + start, + QE_PROP_TAG, qe_strdup(kbuf)); + /* XXX: should colorize variable definition */ + } + } continue; } continue; diff --git a/extras.c b/extras.c index bf61e37..fbf18a5 100644 --- a/extras.c +++ b/extras.c @@ -1518,11 +1518,13 @@ static void tag_completion(CompleteState *cp) { /* XXX: only support current buffer */ QEProperty *p; - tag_buffer(cp->s); + if (cp->target) { + tag_buffer(cp->target); - for (p = cp->s->b->property_list; p; p = p->next) { - if (p->type == QE_PROP_TAG) { - complete_test(cp, p->data); + for (p = cp->target->b->property_list; p; p = p->next) { + if (p->type == QE_PROP_TAG) { + complete_test(cp, p->data); + } } } } diff --git a/qe.c b/qe.c index 2953fa7..1a66ede 100644 --- a/qe.c +++ b/qe.c @@ -5711,10 +5711,11 @@ static CompletionFunc find_completion(const char *name) return NULL; } -static void complete_start(EditState *s, CompleteState *cp) +static void complete_start(CompleteState *cp, EditState *s, EditState *target) { memset(cp, 0, sizeof(*cp)); cp->s = s; + cp->target = target; cp->len = eb_get_contents(s->b, cp->current, sizeof(cp->current)); } @@ -5797,7 +5798,7 @@ void do_completion(EditState *s, int type) return; } - complete_start(s, &cs); + complete_start(&cs, s, check_window(&minibuffer_saved_active)); (*completion_function)(&cs); count = cs.cs.nb_items; outputs = cs.cs.items; diff --git a/qe.h b/qe.h index b882af4..aa7ea95 100644 --- a/qe.h +++ b/qe.h @@ -184,8 +184,9 @@ typedef struct StringArray { typedef struct CompleteState { StringArray cs; struct EditState *s; - char current[MAX_FILENAME_SIZE]; + struct EditState *target; int len; + char current[MAX_FILENAME_SIZE]; } CompleteState; /* media definitions */