qemacs-commit
[Top][All Lists]
Advanced

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

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


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs buffer.c qe.c
Date: Thu, 27 Aug 2015 22:51:56 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        15/08/27 22:51:56

Modified files:
        .              : buffer.c qe.c 

Log message:
        buffers: fix improbable bugs
        - make kill buffers system buffers (not displayed in buffer-list)
        - only create *scratch* buffer in qe_kill_buffer() if needed
        - prevent crash if killing style, log or kill buffers
        - display \n as ^J in minibuf

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/buffer.c?cvsroot=qemacs&r1=1.95&r2=1.96
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.210&r2=1.211

Patches:
Index: buffer.c
===================================================================
RCS file: /sources/qemacs/qemacs/buffer.c,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -b -r1.95 -r1.96
--- buffer.c    27 Aug 2015 18:59:56 -0000      1.95
+++ buffer.c    27 Aug 2015 22:51:56 -0000      1.96
@@ -783,6 +783,7 @@
         EditBuffer *b = *bp;
         QEmacsState *qs = &qe_state;
         EditBuffer **pb;
+        EditBuffer *b1;
 
         /* free b->mode_data_list by calling destructors */
         while (b->mode_data_list) {
@@ -806,12 +807,18 @@
 
         /* suppress from buffer list */
         pb = &qs->first_buffer;
-        while (*pb != NULL) {
-            if (*pb == b)
-                break;
-            pb = &(*pb)->next;
+        while ((b1 = *pb) != NULL) {
+            if (b1->log_buffer == b) {
+                b1->log_buffer = NULL;
+            }
+            if (b1->b_styles == b) {
+                b1->b_styles = NULL;
+            }
+            if (b1 == b)
+                *pb = b1->next;
+            else
+                pb = &b1->next;
         }
-        *pb = (*pb)->next;
 
         if (b == qs->trace_buffer)
             qs->trace_buffer = NULL;
@@ -1124,6 +1131,11 @@
         b->log_buffer = eb_new(buf, BF_SYSTEM | BF_IS_LOG | BF_RAW);
         if (!b->log_buffer)
             return;
+        b->log_new_index = 0;
+        b->log_current = 0;
+        b->last_log = 0;
+        b->last_log_char = 0;
+        b->nb_logs = 0;
     }
     /* XXX: better test to limit size */
     if (b->nb_logs >= (NB_LOGS_MAX-1)) {

Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.210
retrieving revision 1.211
diff -u -b -r1.210 -r1.211
--- qe.c        27 Aug 2015 15:32:14 -0000      1.210
+++ qe.c        27 Aug 2015 22:51:56 -0000      1.211
@@ -1693,7 +1693,7 @@
     }
     snprintf(bufname, sizeof(bufname), "*kill-%d*", cur + 1);
     if (base) {
-        b = eb_new(bufname, base->flags & BF_STYLES);
+        b = eb_new(bufname, BF_SYSTEM | (base->flags & BF_STYLES));
         eb_set_charset(b, base->charset, base->eol_type);
     } else {
         b = eb_new(bufname, 0);
@@ -3868,7 +3868,7 @@
                 ds->style = c >> STYLE_SHIFT;
             }
             c = eb_nextc(s->b, offset, &offset);
-            if (c == '\n') {
+            if (c == '\n' && !s->minibuf) {
                 display_eol(ds, offset0, offset);
                 break;
             }
@@ -5955,29 +5955,44 @@
 {
     QEmacsState *qs = &qe_state;
     EditState *e;
-    EditBuffer *b1;
+    EditBuffer *b1 = NULL;
 
-    /* Emacs makes any window showing the killed buffer switch to
+    if (!b)
+        return;
+
+    /* Check for windows showing the buffer:
+     * - Emacs makes any window showing the killed buffer switch to
      * another buffer.
-     * An alternative is to delete windows showing the buffer.
+     * - An alternative is to delete windows showing the buffer, but we
+     *   cannot delete the main window, so switch to the scratch buffer.
      */
-
+    for (e = qs->first_window; e != NULL; e = e->next_window) {
+        if (e->last_buffer == b) {
+            e->last_buffer = NULL;
+        }
+        if (e->b == b) {
+            if (!b1) {
     /* find a new buffer to switch to */
     for (b1 = qs->first_buffer; b1 != NULL; b1 = b1->next) {
         if (b1 != b && !(b1->flags & BF_SYSTEM))
             break;
     }
-    if (!b1)
+                if (!b1) {
         b1 = eb_new("*scratch*", BF_SAVELOG | BF_UTF8);
-
-    /* if the buffer remains because we cannot delete the main
-       window, then switch to the scratch buffer */
-    for (e = qs->first_window; e != NULL; e = e->next_window) {
-        if (e->b == b) {
+                }
+            }
             switch_to_buffer(e, b1);
         }
     }
 
+    if (b->flags & BF_SYSTEM) {
+        int i;
+        for (i = 0; i < NB_YANK_BUFFERS; i++) {
+            if (qs->yank_buffers[i] == b)
+                qs->yank_buffers[i] = NULL;
+        }
+    }
+
     /* now we can safely delete buffer */
     eb_free(&b);
 
@@ -8014,6 +8029,8 @@
         }
         css_free_colors();
         free_font_cache(&global_screen);
+        qe_free(&qs->buffer_cache);
+        qs->buffer_cache_size = qs->buffer_cache_len = 0;
     }
 #endif
     dpy_close(&global_screen);



reply via email to

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