qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs buffer.c list.c markdown.c orgmode.c qe....


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs buffer.c list.c markdown.c orgmode.c qe....
Date: Tue, 25 Apr 2017 12:46:41 -0400 (EDT)

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        17/04/25 12:46:41

Modified files:
        .              : buffer.c list.c markdown.c orgmode.c qe.h 
                         charset.c 

Log message:
        buffer: new APIs
        - int eb_insert_uchars(EditBuffer *b, int offset, int c, int n);
        - int eb_replace_uchar(EditBuffer *b, int offset, int c);
        - inline eb_insert_spaces() using eb_insert_uchars() instead
        - add minp(), maxp() and clampp() with side effect on first argument
        - publish ucs2 and ucs4 charsets

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/buffer.c?cvsroot=qemacs&r1=1.114&r2=1.115
http://cvs.savannah.gnu.org/viewcvs/qemacs/list.c?cvsroot=qemacs&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/qemacs/markdown.c?cvsroot=qemacs&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/qemacs/orgmode.c?cvsroot=qemacs&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.256&r2=1.257
http://cvs.savannah.gnu.org/viewcvs/qemacs/charset.c?cvsroot=qemacs&r1=1.50&r2=1.51

Patches:
Index: buffer.c
===================================================================
RCS file: /sources/qemacs/qemacs/buffer.c,v
retrieving revision 1.114
retrieving revision 1.115
diff -u -b -r1.114 -r1.115
--- buffer.c    21 Apr 2017 14:44:14 -0000      1.114
+++ buffer.c    25 Apr 2017 16:46:41 -0000      1.115
@@ -2114,14 +2114,29 @@
     return eb_insert(b, offset, buf, len);
 }
 
-int eb_insert_spaces(EditBuffer *b, int offset, int n)
+/* Replace the character at `offset` with `c`,
+ * return number of bytes to move past `c`.
+ */
+int eb_replace_uchar(EditBuffer *b, int offset, int c)
+{
+    char buf[MAX_CHAR_BYTES];
+    int len;
+    int offset1;
+
+    len = eb_encode_uchar(b, buf, c);
+    eb_nextc(b, offset, &offset1);
+    eb_replace(b, offset, offset1 - offset, buf, len);
+    return len;
+}
+
+int eb_insert_uchars(EditBuffer *b, int offset, int c, int n)
 {
     char buf1[1024];
     int size, pos1;
 
     size = pos1 = 0;
     while (n-- > 0) {
-        int clen = eb_encode_uchar(b, buf1 + pos1, ' ');
+        int clen = eb_encode_uchar(b, buf1 + pos1, c);
         pos1 += clen;
         if (pos1 > ssizeof(buf1) - MAX_CHAR_BYTES || n == 0) {
             size += eb_insert(b, offset + size, buf1, pos1);

Index: list.c
===================================================================
RCS file: /sources/qemacs/qemacs/list.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- list.c      11 Apr 2017 07:28:26 -0000      1.24
+++ list.c      25 Apr 2017 16:46:41 -0000      1.25
@@ -85,8 +85,7 @@
         ch = ' ';
     flags = s->b->flags & BF_READONLY;
     s->b->flags ^= flags;
-    eb_delete_uchar(s->b, offset);
-    eb_insert_uchar(s->b, offset, ch);
+    eb_replace_uchar(s->b, offset, ch);
     s->b->flags ^= flags;
 
     if (dir > 0)

Index: markdown.c
===================================================================
RCS file: /sources/qemacs/qemacs/markdown.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- markdown.c  16 Apr 2017 21:51:20 -0000      1.27
+++ markdown.c  25 Apr 2017 16:46:41 -0000      1.28
@@ -632,8 +632,7 @@
     if (flags & 2) {
         /* respect-content: insert heading at end of subtree */
         offset = mkd_next_heading(s, offset, level, NULL);
-        eb_insert_uchar(s->b, offset, '\n');
-        eb_insert_uchar(s->b, offset, '\n');
+        eb_insert_uchars(s->b, offset, '\n', 2);
     } else
     if (s->offset <= offset + level + 1) {
         eb_insert_uchar(s->b, offset, '\n');
@@ -649,9 +648,7 @@
         continue;
     eb_delete(s->b, offset, offset1 - offset);
 
-    while (level-- > 0) {
-        offset += eb_insert_uchar(s->b, offset, '#');
-    }
+    offset += eb_insert_uchars(s->b, offset, '#', level);
     offset += eb_insert_uchar(s->b, offset, ' ');
     s->offset = eb_goto_eol(s->b, offset);
 }

Index: orgmode.c
===================================================================
RCS file: /sources/qemacs/qemacs/orgmode.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- orgmode.c   16 Apr 2017 21:51:20 -0000      1.27
+++ orgmode.c   25 Apr 2017 16:46:41 -0000      1.28
@@ -521,8 +521,7 @@
     if (flags & 2) {
         /* respect-content: insert heading at end of subtree */
         offset = org_next_heading(s, offset, level, NULL);
-        eb_insert_uchar(s->b, offset, '\n');
-        eb_insert_uchar(s->b, offset, '\n');
+        eb_insert_uchars(s->b, offset, '\n', 2);
     } else
     if (s->offset <= offset + level + 1) {
         eb_insert_uchar(s->b, offset, '\n');
@@ -538,9 +537,7 @@
         continue;
     eb_delete(s->b, offset, offset1 - offset);
 
-    while (level-- > 0) {
-        offset += eb_insert_uchar(s->b, offset, '*');
-    }
+    offset += eb_insert_uchars(s->b, offset, '*', level);
     offset += eb_insert_uchar(s->b, offset, ' ');
     s->offset = eb_goto_eol(s->b, offset);
     if (flags & 1) {

Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.256
retrieving revision 1.257
diff -u -b -r1.256 -r1.257
--- qe.h        21 Apr 2017 14:44:14 -0000      1.256
+++ qe.h        25 Apr 2017 16:46:41 -0000      1.257
@@ -645,6 +645,14 @@
         return b;
 }
 
+static inline int maxp(int *pa, int b) {
+    int a = *pa;
+    if (a > b)
+        return a;
+    else
+        return *pa = b;
+}
+
 static inline int max3(int a, int b, int c) {
     return max(max(a, b), c);
 }
@@ -656,6 +664,14 @@
         return b;
 }
 
+static inline int minp(int *pa, int b) {
+    int a = *pa;
+    if (a < b)
+        return a;
+    else
+        return *pa = b;
+}
+
 static inline int min3(int a, int b, int c) {
     return min(min(a, b), c);
 }
@@ -670,6 +686,17 @@
         return a;
 }
 
+static inline int clampp(int *pa, int b, int c) {
+    int a = *pa;
+    if (a < b)
+        return *pa = b;
+    else
+    if (a > c)
+        return *pa = c;
+    else
+        return a;
+}
+
 static inline int compute_percent(int a, int b) {
     return b <= 0 ? 0 : (int)((long long)a * 100 / b);
 }
@@ -724,6 +751,8 @@
 extern struct QECharset charset_utf8;
 extern struct QECharset charset_vt100; /* used for the tty output */
 extern struct QECharset charset_mac_roman;
+extern struct QECharset charset_ucs2le, charset_ucs2be;
+extern struct QECharset charset_ucs4le, charset_ucs4be;
 
 typedef enum EOLType {
     EOL_UNIX = 0,
@@ -1203,7 +1232,12 @@
 int eb_delete_uchar(EditBuffer *b, int offset);
 int eb_encode_uchar(EditBuffer *b, char *buf, unsigned int c);
 int eb_insert_uchar(EditBuffer *b, int offset, int c);
-int eb_insert_spaces(EditBuffer *b, int offset, int n);
+int eb_replace_uchar(EditBuffer *b, int offset, int c);
+int eb_insert_uchars(EditBuffer *b, int offset, int c, int n);
+static inline int eb_insert_spaces(EditBuffer *b, int offset, int n) {
+    return eb_insert_uchars(b, offset, ' ', n);
+}
+
 int eb_insert_utf8_buf(EditBuffer *b, int offset, const char *buf, int len);
 int eb_insert_u32_buf(EditBuffer *b, int offset, const unsigned int *buf, int 
len);
 int eb_insert_str(EditBuffer *b, int offset, const char *str);

Index: charset.c
===================================================================
RCS file: /sources/qemacs/qemacs/charset.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -b -r1.50 -r1.51
--- charset.c   17 Apr 2017 18:14:15 -0000      1.50
+++ charset.c   25 Apr 2017 16:46:41 -0000      1.51
@@ -558,8 +558,6 @@
 /********************************************************/
 /* UCS2/UCS4 */
 
-extern struct QECharset charset_ucs2le, charset_ucs2be;
-
 static int probe_ucs2le(qe__unused__ QECharset *charset, const u8 *buf, int 
size)
 {
     const uint32_t magic = (1U << '\b') | (1U << '\t') | (1U << '\f') |
@@ -835,8 +833,6 @@
     2, 0, 0, 10, 0, 0, table_none, NULL, NULL,
 };
 
-extern struct QECharset charset_ucs4le, charset_ucs4be;
-
 static int probe_ucs4le(qe__unused__ QECharset *charset, const u8 *buf, int 
size)
 {
     const uint32_t magic = (1U << '\b') | (1U << '\t') | (1U << '\f') |



reply via email to

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