qemacs-commit
[Top][All Lists]
Advanced

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

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


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs extras.c qe.h variables.c
Date: Sun, 19 Mar 2017 09:20:34 -0400 (EDT)

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        17/03/19 09:20:34

Modified files:
        .              : extras.c qe.h variables.c 

Log message:
        extras: improved compare-windows
        - add static int qe_skip_comments(EditState *s, int offset, int 
*offsetp);
        - add static int qe_skip_spaces(EditState *s, int offset, int *offsetp);
        - add state variable ignore-comments
        - C-u A-= toggles ignore-spaces
        - C-u C-u A-= toggles ignore-comments
        - C-u 2 0 A-= toggles ignore-spaces and ignore-comments
        - compare-windows status messages document ignored stuff

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/extras.c?cvsroot=qemacs&r1=1.58&r2=1.59
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.239&r2=1.240
http://cvs.savannah.gnu.org/viewcvs/qemacs/variables.c?cvsroot=qemacs&r1=1.21&r2=1.22

Patches:
Index: extras.c
===================================================================
RCS file: /sources/qemacs/qemacs/extras.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -b -r1.58 -r1.59
--- extras.c    18 Mar 2017 14:13:33 -0000      1.58
+++ extras.c    19 Mar 2017 13:20:34 -0000      1.59
@@ -24,6 +24,48 @@
 #include "qfribidi.h"
 #include "variables.h"
 
+static int qe_skip_comments(EditState *s, int offset, int *offsetp)
+{
+    unsigned int buf[COLORED_MAX_LINE_SIZE];
+    int line_num, col_num, len, pos;
+    int offset0, offset1;
+
+    if (!s->colorize_func && !s->b->b_styles)
+        return 0;
+
+    eb_get_pos(s->b, &line_num, &col_num, offset);
+    offset0 = eb_goto_bol2(s->b, offset, &pos);
+    /* XXX: should only query the syntax colorizer */
+    len = s->get_colorized_line(s, buf, countof(buf), offset0, &offset1, 
line_num);
+    if (len > countof(buf))
+        len = countof(buf);
+    if (pos >= len)
+        return 0;
+    if ((buf[pos] >> STYLE_SHIFT) != QE_STYLE_COMMENT)
+        return 0;
+    while (pos < len && (buf[pos] >> STYLE_SHIFT) == QE_STYLE_COMMENT) {
+        offset = eb_next(s->b, offset);
+        pos++;
+    }
+    *offsetp = offset;
+    return 1;
+}
+
+static int qe_skip_spaces(EditState *s, int offset, int *offsetp)
+{
+    int offset0 = offset, offset1;
+
+    while (offset < s->b->total_size
+        && qe_isspace(eb_nextc(s->b, offset, &offset1))) {
+        offset = offset1;
+    }
+    if (offset != offset0) {
+        *offsetp = offset;
+        return 1;
+    }
+    return 0;
+}
+
 void do_compare_windows(EditState *s, int argval)
 {
     QEmacsState *qs = s->qe_state;
@@ -32,6 +74,7 @@
     int offset1, offset2, size1, size2, ch1, ch2;
     int tries, resync = 0;
     char buf1[MAX_CHAR_BYTES + 2], buf2[MAX_CHAR_BYTES + 2];
+    const char *comment = "";
 
     s1 = s;
     /* Should use same internal function as for next_window */
@@ -40,9 +83,12 @@
     else
         s2 = qs->first_window;
 
-    if (argval != NO_ARG)
+    if (argval != NO_ARG) {
+        if (argval & 4)
         qs->ignore_spaces ^= 1;
-
+        if (argval & 16)
+            qs->ignore_comments ^= 1;
+    }
     if (s1 == s2) {
         /* single window: bail out */
         return;
@@ -78,17 +124,23 @@
         if (ch1 != ch2) {
             if (qs->ignore_spaces) {
                 /* UTF-8 issue */
-                if (qe_isspace(ch1)) {
-                    s1->offset = offset1;
+                if (qe_isspace(ch1) || qe_isspace(ch2)) {
+                    qe_skip_spaces(s1, s1->offset, &s1->offset);
+                    qe_skip_spaces(s2, s2->offset, &s2->offset);
+                    if (!*comment)
+                        comment = "Skipped spaces, ";
                     continue;
                 }
-                if (qe_isspace(ch2)) {
-                    s2->offset = offset2;
+            }
+            if (qs->ignore_comments) {
+                if (qe_skip_comments(s1, s1->offset, &s1->offset) |
+                    qe_skip_comments(s2, s2->offset, &s2->offset)) {
+                    comment = "Skipped comments, ";
                     continue;
                 }
             }
             if (ch1 == EOF || ch2 == EOF) {
-                put_status(s, "Extra characters");
+                put_status(s, "%sExtra characters", comment);
                 break;
             }
             if (resync) {
@@ -120,7 +172,7 @@
                            s1->offset - save1, s2->offset - save2);
                 break;
             }
-            put_status(s, "Difference: '%s' [0x%02X] <-> '%s' [0x%02X]",
+            put_status(s, "%sDifference: '%s' [0x%02X] <-> '%s' [0x%02X]", 
comment,
                        utf8_char_to_string(buf1, ch1), ch1,
                        utf8_char_to_string(buf2, ch2), ch2);
             break;
@@ -130,7 +182,7 @@
             s2->offset = offset2;
             continue;
         }
-        put_status(s, "No difference");
+        put_status(s, "%sNo difference", comment);
         break;
     }
 }

Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.239
retrieving revision 1.240
diff -u -b -r1.239 -r1.240
--- qe.h        18 Mar 2017 14:13:33 -0000      1.239
+++ qe.h        19 Mar 2017 13:20:34 -0000      1.240
@@ -1503,6 +1503,7 @@
     //int no_config;      /* prevent config file eval */
     //int force_refresh;  /* force a complete screen refresh */
     int ignore_spaces;  /* ignore spaces when comparing windows */
+    int ignore_comments;  /* ignore comments when comparing windows */
     int hilite_region;  /* hilite the current region when selecting */
     int mmap_threshold; /* minimum file size for mmap */
     int max_load_size;  /* maximum file size for loading in memory */

Index: variables.c
===================================================================
RCS file: /sources/qemacs/qemacs/variables.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- variables.c 7 Mar 2016 10:35:23 -0000       1.21
+++ variables.c 19 Mar 2017 13:20:34 -0000      1.22
@@ -41,6 +41,7 @@
     S_VAR( "QEPATH", res_path, VAR_CHARS, VAR_RO )
     //S_VAR( "it", it, VAR_NUMBER, VAR_RW )
     S_VAR( "ignore-spaces", ignore_spaces, VAR_NUMBER, VAR_RW_SAVE )
+    S_VAR( "ignore-comments", ignore_comments, VAR_NUMBER, VAR_RW_SAVE )
     S_VAR( "hilite-region", hilite_region, VAR_NUMBER, VAR_RW_SAVE )
     S_VAR( "mmap-threshold", mmap_threshold, VAR_NUMBER, VAR_RW_SAVE )
     S_VAR( "max-load-size", max_load_size, VAR_NUMBER, VAR_RW_SAVE )



reply via email to

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