qemacs-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemacs-commit] qemacs qe.h qe.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs qe.h qe.c
Date: Mon, 15 May 2017 03:57:13 -0400 (EDT)

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        17/05/15 03:57:13

Modified files:
        .              : qe.h qe.c 

Log message:
        basic: fix CRC shadow buffer crash bug
        - add consistency checks for shadow buffer indexing
        - use generic_mode_probe() as default if mode extensions
          are set for all modes, not just MODEF_SYNTAX
        - improve mode name construction for modeline
        - display TAB as ^I in minibuffer
        - prevent display of characters in [128..159] for raw buffers
          this improves display speed in X11-Mac version
        - force window content and border invalidation if complete_refresh

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.265&r2=1.266
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.285&r2=1.286

Patches:
Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.265
retrieving revision 1.266
diff -u -b -r1.265 -r1.266
--- qe.h        10 May 2017 15:46:16 -0000      1.265
+++ qe.h        15 May 2017 07:57:12 -0000      1.266
@@ -1461,7 +1461,7 @@
     struct QEditScreen *screen; /* copy of qe_state->screen */
     /* display shadow to optimize redraw */
     char modeline_shadow[MAX_SCREEN_WIDTH];
-    OWNED QELineShadow *line_shadow; /* per window shadow */
+    OWNED QELineShadow *line_shadow; /* per window shadow CRC data */
     int shadow_nb_lines;
     /* compose state for input method */
     InputMethod *input_method; /* current input method */

Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.285
retrieving revision 1.286
diff -u -b -r1.285 -r1.286
--- qe.c        10 May 2017 15:46:16 -0000      1.285
+++ qe.c        15 May 2017 07:57:12 -0000      1.286
@@ -140,10 +140,6 @@
     m->flags |= flags;
 
     if (m->flags & MODEF_SYNTAX) {
-        /* if no syntax probing function, use extension matcher */
-        if (!m->mode_probe && m->extensions)
-            m->mode_probe = generic_mode_probe;
-
         /* default to text handling */
         if (!m->display_line)
             m->display_line = text_display_line;
@@ -174,6 +170,9 @@
     /* add missing functions */
     if (!m->mode_init)
         m->mode_init = default_mode_init;
+    /* if no syntax probing function, use extension matcher */
+    if (!m->mode_probe && m->extensions)
+        m->mode_probe = generic_mode_probe;
     if (!m->display)
         m->display = generic_text_display;
     if (!m->data_type)
@@ -377,7 +376,8 @@
 void do_set_key(EditState *s, const char *keystr,
                 const char *cmd_name, int local)
 {
-    int res = qe_mode_set_key(local ? s->mode : NULL, keystr, cmd_name);
+    ModeDef *m = local ? s->mode : NULL;
+    int res = qe_mode_set_key(m, keystr, cmd_name);
 
     if (res == -2)
         put_status(s, "Invalid keys: %s", keystr);
@@ -2726,10 +2726,33 @@
         s->b->fill_column = fill_column;
 }
 
+static char *qe_get_mode_name(EditState *s, char *buf, int size, int full)
+{
+    buf_t outbuf, *out;
+
+    out = buf_init(&outbuf, buf, size);
+
+    if (s->b->data_type_name)
+        buf_printf(out, "%s+", s->b->data_type_name);
+    buf_puts(out, s->mode ? s->mode->name : "raw");
+
+    if (full) {
+        if (!s->insert)
+            buf_puts(out, " Ovwrt");
+        if (s->interactive)
+            buf_puts(out, " Interactive");
+        if (s->b->flags & BF_PREVIEW)
+            buf_puts(out, " Preview");
+    }
+    return buf;
+}
+
 /* compute string for the first part of the mode line (flags,
    filename, modename) */
 void basic_mode_line(EditState *s, buf_t *out, int c1)
 {
+    char buf[128];
+    const char *mode_name;
     int mod, state;
 
     mod = s->b->modified ? '*' : '-';
@@ -2742,19 +2765,13 @@
     else
         state = '-';
 
-    buf_printf(out, "%c%c:%c%c  %-20s  (",
+    mode_name = qe_get_mode_name(s, buf, sizeof(buf), 1);
+    /* Strip text mode name if another mode is also active */
+    strstart(mode_name, "text ", &mode_name);
+
+    buf_printf(out, "%c%c:%c%c  %-20s  (%s)--",
                c1, state, s->b->flags & BF_READONLY ? '%' : mod,
-               mod, s->b->name);
-    if (s->b->data_type_name)
-        buf_printf(out, "%s+", s->b->data_type_name);
-    buf_puts(out, s->mode ? s->mode->name : "raw");
-    if (!s->insert)
-        buf_puts(out, " Ovwrt");
-    if (s->interactive)
-        buf_puts(out, " Interactive");
-    if (s->b->flags & BF_PREVIEW)
-        buf_puts(out, " Preview");
-    buf_puts(out, ")--");
+               mod, s->b->name, mode_name);
 }
 
 void text_mode_line(EditState *s, buf_t *out)
@@ -3309,25 +3326,30 @@
     &&  ds->y + line_height >= 0
     &&  ds->y < e->ytop + e->height) {
         QEStyleDef styledef, default_style;
-        QELineShadow *ls;
-        uint64_t crc;
+        int no_display = 0;
 
         /* test if display needed */
-        crc = compute_crc(fragments, sizeof(*fragments) * nb_fragments, 0);
-        crc = compute_crc(ds->line_chars, sizeof(*ds->line_chars) * 
ds->line_index, crc);
-        if (ds->line_num >= e->shadow_nb_lines) {
-            /* realloc shadow */
-            int n = e->shadow_nb_lines;
-            e->shadow_nb_lines = n + LINE_SHADOW_INCR;
-            qe_realloc(&e->line_shadow,
-                       e->shadow_nb_lines * sizeof(QELineShadow));
-            /* put an impossible value so that we redraw */
-            memset(&e->line_shadow[n], 0xff,
-                   LINE_SHADOW_INCR * sizeof(QELineShadow));
-        }
+        if (ds->line_num >= 0 && ds->line_num < 2048) {
+            /* paranoid: prevent cache growing too large */
         /* Use checksum based line cache to improve speed in graphics mode.
          * XXX: overlong lines will fail the cache test
          */
+            if (ds->line_num >= e->shadow_nb_lines) {
+                /* reallocate shadow */
+                int n = ds->line_num + LINE_SHADOW_INCR;
+                if (qe_realloc(&e->line_shadow, n * sizeof(QELineShadow))) {
+                    /* put an impossible value so that we redraw */
+                    memset(&e->line_shadow[e->shadow_nb_lines], 0xff,
+                           (n - e->shadow_nb_lines) * sizeof(QELineShadow));
+                    e->shadow_nb_lines = n;
+                }
+            }
+            if (ds->line_num < e->shadow_nb_lines) {
+                QELineShadow *ls;
+                uint64_t crc;
+
+                crc = compute_crc(fragments, sizeof(*fragments) * 
nb_fragments, 0);
+                crc = compute_crc(ds->line_chars, sizeof(*ds->line_chars) * 
ds->line_index, crc);
         ls = &e->line_shadow[ds->line_num];
         if (ls->y != ds->y || ls->x != ds->x_line
         ||  ls->height != line_height || ls->crc != crc) {
@@ -3336,7 +3358,12 @@
             ls->x = ds->x_line;
             ls->height = line_height;
             ls->crc = crc;
-
+                } else {
+                    no_display = 1;
+                }
+            }
+        }
+        if (!no_display) {
             /* display */
             get_style(e, &default_style, QE_STYLE_DEFAULT);
             x = ds->x_start;
@@ -3827,6 +3854,7 @@
         /* XXX: utf-8 unsupported, not needed at this point */
         display_char(ds, offset1, offset2, *p++);
         while (*p) {
+            /* XXX: Should make these display character mouse selectable */
             display_char(ds, -1, -1, *p++);
         }
     }
@@ -4297,7 +4325,7 @@
             embedding_level = bd[0].level;
             /* XXX: use embedding level for all cases ? */
             /* CG: should query screen or window about display methods */
-            if ((c < ' ' && c != '\t') || c == 127) {
+            if ((c < ' ' && (c != '\t' || (s->flags & WF_MINIBUF))) || c == 
127) {
                 if (c == '\r' && s->b->eol_type == EOL_MAC)
                     c = '\n';
                 display_printf(ds, offset0, offset, "^%c", ('@' + c) & 127);
@@ -4305,12 +4333,16 @@
             if (c >= 128
             &&  (s->qe_state->show_unicode == 1 ||
                  c == 0xfeff ||   /* Display BOM as \uFEFF to make it explicit 
*/
-                 c > MAX_UNICODE_DISPLAY)) {
+                 c > MAX_UNICODE_DISPLAY ||
+                 (c < 160 && s->b->charset == &charset_raw))) {
                 /* display unsupported unicode code points as hex */
                 if (c > 0xffff) {
                     display_printf(ds, offset0, offset, "\\U%08x", c);
-                } else {
+                } else
+                if (c > 0xff) {
                     display_printf(ds, offset0, offset, "\\u%04x", c);
+                } else {
+                    display_printf(ds, offset0, offset, "\\x%02x", c);
                 }
             } else {
                 display_char_bidir(ds, offset0, offset, embedding_level, c);
@@ -4467,10 +4499,12 @@
         fill_rectangle(s->screen, s->xleft, s->ytop + ds->y,
                        s->width, s->height - ds->y,
                        default_style.bg_color);
-        /* do not forget to erase the line shadow  */
+        if (ds->line_num >= 0 && ds->line_num < s->shadow_nb_lines) {
+            /* erase the line shadow for the rest of the window */
         memset(&s->line_shadow[ds->line_num], 0xff,
                (s->shadow_nb_lines - ds->line_num) * sizeof(QELineShadow));
     }
+    }
     display_close(ds);
 
     xc = m->xc;
@@ -4493,10 +4527,12 @@
                 w = -w;
             }
             xor_rectangle(s->screen, x, y, w, h, QERGB(0xFF, 0xFF, 0xFF));
+            if (m->linec >= 0 && m->linec < s->shadow_nb_lines) {
             /* invalidate line so that the cursor will be erased next time */
             memset(&s->line_shadow[m->linec], 0xff, sizeof(QELineShadow));
         }
     }
+    }
     s->cur_rtl = (m->dirc == DIR_RTL);
 #if 0
     printf("cursor1: xc=%d yc=%d w=%d h=%d linec=%d\n",
@@ -4946,6 +4982,7 @@
 
 void window_display(EditState *s)
 {
+    QEmacsState *qs = s->qe_state;
     CSSRect rect;
 
     /* set the clipping rectangle to the whole window */
@@ -4956,6 +4993,11 @@
     rect.y2 = rect.y1 + s->height;
     set_clip_rectangle(s->screen, &rect);
 
+    if (qs->complete_refresh) {
+        edit_invalidate(s, 0);
+        s->borders_invalid = 1;
+    }
+
     s->mode->display(s);
 
     display_mode_line(s);
@@ -5811,6 +5853,7 @@
         qe_free_mode_data(s->mode_data);
         qe_free(&s->prompt);
         qe_free(&s->line_shadow);
+        s->shadow_nb_lines = 0;
         qe_free(sp);
     }
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]