[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs qe.c qe.h shell.c util.c
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs qe.c qe.h shell.c util.c |
Date: |
Sun, 1 Jan 2017 10:40:46 -0500 (EST) |
CVSROOT: /sources/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 17/01/01 10:40:46
Modified files:
. : qe.c qe.h shell.c util.c
Log message:
shell: colorize file fragments from compilation and grep
- add `offset` member in `QEColorizeContext` structure
- add `ModeDef *qe_find_mode_filename(const char *filename, int flags);`
- make `combine_static_colorized_line` public
- add public function `shell_colorize_line`:
detect file fragments with filename followed by `:` without space at
bol
special case clang errors that display the file contents after the
line
- special case `shell_colorize_line` for static color combination scheme
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.245&r2=1.246
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.234&r2=1.235
http://cvs.savannah.gnu.org/viewcvs/qemacs/shell.c?cvsroot=qemacs&r1=1.114&r2=1.115
http://cvs.savannah.gnu.org/viewcvs/qemacs/util.c?cvsroot=qemacs&r1=1.75&r2=1.76
Patches:
Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.245
retrieving revision 1.246
diff -u -b -r1.245 -r1.246
--- qe.c 1 Jan 2017 12:51:22 -0000 1.245
+++ qe.c 1 Jan 2017 15:40:46 -0000 1.246
@@ -107,6 +107,20 @@
return m;
}
+ModeDef *qe_find_mode_filename(const char *filename, int flags)
+{
+ QEmacsState *qs = &qe_state;
+ ModeDef *m;
+
+ for (m = qs->first_mode; m; m = m->next) {
+ if ((m->flags & flags) == flags
+ && match_extension(filename, m->extensions)) {
+ break;
+ }
+ }
+ return m;
+}
+
void qe_register_mode(ModeDef *m, int flags)
{
QEmacsState *qs = &qe_state;
@@ -3758,6 +3772,7 @@
cctx.state_only = 1;
for (line = s->colorize_nb_valid_lines; line <= line_num; line++) {
+ cctx.offset = offset;
len = eb_get_line(b, buf, buf_size - 1, offset, &offset);
if (buf[len] != '\n') {
/* line was truncated */
@@ -3768,6 +3783,9 @@
/* skip byte order mark if present */
bom = (buf[0] == 0xFEFF);
+ if (bom) {
+ cctx.offset = eb_next(b, cctx.offset);
+ }
s->colorize_func(&cctx, buf + bom, len - bom, s->mode);
s->colorize_states[line] = cctx.colorize_state;
}
@@ -3776,6 +3794,7 @@
/* compute line color */
cctx.colorize_state = s->colorize_states[line_num];
cctx.state_only = 0;
+ cctx.offset = offset;
len = eb_get_line(b, buf, buf_size - 1, offset, offsetp);
if (buf[len] != '\n') {
/* line was truncated */
@@ -3787,6 +3806,7 @@
bom = (buf[0] == 0xFEFF);
if (bom) {
SET_COLOR1(buf, 0, QE_STYLE_PREPROCESS);
+ cctx.offset = eb_next(b, cctx.offset);
}
s->colorize_func(&cctx, buf + bom, len - bom, s->mode);
/* buf[len] has char '\0' but may hold style, force buf ending */
@@ -3815,12 +3835,13 @@
e->colorize_max_valid_offset = offset;
}
-static int combine_static_colorized_line(EditState *s, unsigned int *buf,
+int combine_static_colorized_line(EditState *s, unsigned int *buf,
int len, int offset)
{
EditBuffer *b = s->b;
int i;
+ if (b->b_styles) {
for (i = 0; i < len; i++) {
int style = eb_get_style(b, offset);
if (style) {
@@ -3828,6 +3849,7 @@
}
offset = eb_next(b, offset);
}
+ }
return len;
}
@@ -3859,7 +3881,7 @@
#ifndef CONFIG_TINY
if (s->colorize_func) {
len = syntax_get_colorized_line(s, buf, buf_size, offset, offsetp,
line_num);
- if (s->b->b_styles)
+ if (s->b->b_styles && s->colorize_func != shell_colorize_line)
combine_static_colorized_line(s, buf, buf_size, len);
} else
#endif
Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.234
retrieving revision 1.235
diff -u -b -r1.234 -r1.235
--- qe.h 31 Dec 2016 18:45:08 -0000 1.234
+++ qe.h 1 Jan 2017 15:40:46 -0000 1.235
@@ -2,7 +2,7 @@
* QEmacs, tiny but powerful multimode editor
*
* Copyright (c) 2000-2001 Fabrice Bellard.
- * Copyright (c) 2000-2016 Charlie Gordon.
+ * Copyright (c) 2000-2017 Charlie Gordon.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -788,6 +788,7 @@
struct QEColorizeContext {
EditState *s;
EditBuffer *b;
+ int offset;
int colorize_state;
int state_only;
};
@@ -1600,6 +1601,7 @@
{ 0, 0, NULL, { NULL }, CMD_void, 0 }
ModeDef *qe_find_mode(const char *name, int flags);
+ModeDef *qe_find_mode_filename(const char *filename, int flags);
void qe_register_mode(ModeDef *m, int flags);
void mode_completion(CompleteState *cp);
void qe_register_cmd_table(CmdDef *cmds, ModeDef *m);
@@ -1905,6 +1907,8 @@
void set_colorize_func(EditState *s, ColorizeFunc colorize_func);
int generic_get_colorized_line(EditState *s, unsigned int *buf, int buf_size,
int offset, int *offsetp, int line_num);
+int combine_static_colorized_line(EditState *s, unsigned int *buf,
+ int len, int offset);
int do_delete_selection(EditState *s);
void do_char(EditState *s, int key, int argval);
@@ -2136,6 +2140,8 @@
/* shell.c */
const char *get_shell(void);
+void shell_colorize_line(QEColorizeContext *cp,
+ unsigned int *str, int n, ModeDef *syn);
#define SF_INTERACTIVE 0x01
#define SF_COLOR 0x02
Index: shell.c
===================================================================
RCS file: /sources/qemacs/qemacs/shell.c,v
retrieving revision 1.114
retrieving revision 1.115
diff -u -b -r1.114 -r1.115
--- shell.c 23 Dec 2016 19:51:48 -0000 1.114
+++ shell.c 1 Jan 2017 15:40:46 -0000 1.115
@@ -2,7 +2,7 @@
* Shell mode for QEmacs.
*
* Copyright (c) 2001-2002 Fabrice Bellard.
- * Copyright (c) 2002-2016 Charlie Gordon.
+ * Copyright (c) 2002-2017 Charlie Gordon.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -2241,6 +2241,83 @@
put_status(s, "=> %s", error_message);
}
+static int match_digits(unsigned int *buf, int n, unsigned int sep) {
+ if (n >= 2 && qe_isdigit(buf[0])) {
+ int i = 1;
+ while (i < n && qe_isdigit(buf[i]))
+ i++;
+ if (buf[i] == sep) {
+ return i + 1;
+ }
+ }
+ return 0;
+}
+
+static int match_string(unsigned int *buf, int n, const char *str) {
+ int i;
+ for (i = 0; i < n && str[i] && buf[i] == str[i]; i++)
+ continue;
+ return (str[i] == '\0') ? i : 0;
+}
+
+void shell_colorize_line(QEColorizeContext *cp,
+ unsigned int *str, int n, ModeDef *syn)
+{
+ /* detect match lines for known languages and colorize accordingly */
+ static char filename[MAX_FILENAME_SIZE];
+ ModeDef *m;
+ int i = 0, len, stop = n;
+
+ if (cp->colorize_state) {
+ cp->colorize_state -= 1;
+ } else {
+ len = 0;
+ if (!qe_isspace(str[0])) {
+ while (i < n) {
+ int c = str[i++];
+ if (c == "()"[0]) {
+ i += match_digits(str + i, n - i, "()"[1]); /* old style */
+ i += (str[i] == ':');
+ break;
+ }
+ if (c == ':') {
+ i += match_digits(str + i, n - i, ':'); /* line number */
+ i += match_digits(str + i, n - i, ':'); /* col number */
+ if (match_string(str + i, n - i, " error:")
+ || match_string(str + i, n - i, " warning:")) {
+ /* clang diagnostic, will colorize the next line */
+ cp->colorize_state = 1;
+ i = n;
+ }
+ break;
+ }
+ if (qe_isspace(c)) {
+ len = 0;
+ break;
+ }
+ if (len < countof(filename) - 1) {
+ /* capture filename extension */
+ filename[len++] = c;
+ }
+ }
+ }
+ filename[len] = '\0';
+ }
+ if (cp->colorize_state == 0 && *filename) {
+ /* XXX: should verify if filename exists, but this is difficult
+ * if the current directory of the shell process changes and
+ * is not possible for remote shells.
+ */
+ if (i < n && (m = qe_find_mode_filename(filename, MODEF_SYNTAX)) !=
NULL) {
+ cp->colorize_state = 0;
+ m->colorize_func(cp, str + i, n - i, m);
+ stop = i;
+ }
+ cp->colorize_state = 0;
+ }
+ combine_static_colorized_line(cp->s, str, stop, cp->offset);
+}
+
/* shell mode specific commands */
static CmdDef shell_commands[] = {
CMD0( KEY_CTRL('o'), KEY_NONE,
@@ -2343,6 +2420,7 @@
shell_mode.name = "shell";
shell_mode.mode_name = NULL;
shell_mode.mode_probe = shell_mode_probe;
+ shell_mode.colorize_func = shell_colorize_line,
shell_mode.buffer_instance_size = sizeof(ShellState);
shell_mode.mode_init = shell_mode_init;
shell_mode.mode_free = shell_mode_free;
Index: util.c
===================================================================
RCS file: /sources/qemacs/qemacs/util.c,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -b -r1.75 -r1.76
--- util.c 25 Dec 2016 10:51:14 -0000 1.75
+++ util.c 1 Jan 2017 15:40:46 -0000 1.76
@@ -2,7 +2,7 @@
* Utilities for qemacs.
*
* Copyright (c) 2001 Fabrice Bellard.
- * Copyright (c) 2002-2016 Charlie Gordon.
+ * Copyright (c) 2002-2017 Charlie Gordon.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -319,13 +319,13 @@
*/
int match_extension(const char *filename, const char *extlist)
{
- const char *base = get_basename(filename);
+ const char *base, *p, *q;
int len;
- const char *p, *q;
if (!extlist)
return 0;
+ base = get_basename(filename);
while (*base == '.')
base++;
len = strlen(base);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemacs-commit] qemacs qe.c qe.h shell.c util.c,
Charlie Gordon <=