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
This commit is contained in:
Charlie Gordon 2017-03-31 15:33:02 +00:00
commit 073fbc3439
6 changed files with 82 additions and 15 deletions

View file

@ -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;

12
clang.c
View file

@ -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] != '.')

View file

@ -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;

View file

@ -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);
}
}
}
}

5
qe.c
View file

@ -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;

3
qe.h
View file

@ -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 */