qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs buffer.c latex-mode.c qe.h plugins/my_pl...


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs buffer.c latex-mode.c qe.h plugins/my_pl...
Date: Sat, 11 Jan 2014 14:38:30 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        14/01/11 14:38:30

Modified files:
        .              : buffer.c latex-mode.c qe.h 
        plugins        : my_plugin.c 

Log message:
        add some buffer APIs
        
        * add buffer APIs for matching and inserting text:
          - eb_insert_str
          - eb_match_uchar
          - eb_match_str
          - eb_match_istr
        * simplify eb_insert_utf8_buf: no longer accept -1 len

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/buffer.c?cvsroot=qemacs&r1=1.54&r2=1.55
http://cvs.savannah.gnu.org/viewcvs/qemacs/latex-mode.c?cvsroot=qemacs&r1=1.37&r2=1.38
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.113&r2=1.114
http://cvs.savannah.gnu.org/viewcvs/qemacs/plugins/my_plugin.c?cvsroot=qemacs&r1=1.2&r2=1.3

Patches:
Index: buffer.c
===================================================================
RCS file: /sources/qemacs/qemacs/buffer.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -b -r1.54 -r1.55
--- buffer.c    10 Jan 2014 01:17:14 -0000      1.54
+++ buffer.c    11 Jan 2014 14:38:30 -0000      1.55
@@ -1469,9 +1469,6 @@
 /* Insert buffer with utf8 chars according to buffer encoding */
 int eb_insert_utf8_buf(EditBuffer *b, int offset, const char *buf, int len)
 {
-    if (len < 0)
-        len = strlen(buf);
-
     if (b->charset == &charset_utf8) {
         eb_insert(b, offset, buf, len);
         return len;
@@ -1495,6 +1492,40 @@
     }
 }
 
+int eb_insert_str(EditBuffer *b, int offset, const char *str)
+{
+    return eb_insert_utf8_buf(b, offset, str, strlen(str));
+}
+
+int eb_match_uchar(EditBuffer *b, int offset, int c)
+{
+    return eb_nextc(b, offset, &offset) == c;
+}
+
+int eb_match_str(EditBuffer *b, int offset, const char *str)
+{
+    const char *p = str;
+
+    while (*p) {
+        int c = utf8_decode((const char **)(void *)&p);
+        if (eb_nextc(b, offset, &offset) != c)
+            return 0;
+    }
+    return 1;
+}
+
+int eb_match_istr(EditBuffer *b, int offset, const char *str)
+{
+    const char *p = str;
+
+    while (*p) {
+        int c = utf8_decode((const char **)(void *)&p);
+        if (qe_toupper(eb_nextc(b, offset, &offset)) != qe_toupper(c))
+            return 0;
+    }
+    return 1;
+}
+
 int eb_printf(EditBuffer *b, const char *fmt, ...)
 {
     char buf0[1024];
@@ -1518,7 +1549,10 @@
         vsnprintf(buf, size, fmt, ap);
         va_end(ap);
     }
-    /* CG: insert buffer translating according b->charset */
+    /* CG: insert buffer translating according b->charset.
+     * buf may contain \0 characters via the %c modifer.
+     * XXX: %c does not encode non ASCII characters as utf8.
+     */
     eb_insert_utf8_buf(b, b->total_size, buf, len);
 #ifdef CONFIG_WIN32
     if (buf != buf0)

Index: latex-mode.c
===================================================================
RCS file: /sources/qemacs/qemacs/latex-mode.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -b -r1.37 -r1.38
--- latex-mode.c        7 Jan 2014 14:46:24 -0000       1.37
+++ latex-mode.c        11 Jan 2014 14:38:30 -0000      1.38
@@ -158,9 +158,9 @@
         s->offset += eb_insert_uchar(s->b, s->offset, '\"');
     } else {
         if (pos == 0 || buf[pos-1] == ' ') {
-            s->offset += eb_insert_utf8_buf(s->b, s->offset, "``", 2);
+            s->offset += eb_insert_str(s->b, s->offset, "``");
         } else {
-            s->offset += eb_insert_utf8_buf(s->b, s->offset, "''", 2);
+            s->offset += eb_insert_str(s->b, s->offset, "''");
         }
     }
 }

Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -b -r1.113 -r1.114
--- qe.h        10 Jan 2014 01:09:26 -0000      1.113
+++ qe.h        11 Jan 2014 14:38:30 -0000      1.114
@@ -849,6 +849,10 @@
 int eb_delete_uchar(EditBuffer *b, int offset);
 int eb_insert_uchar(EditBuffer *b, int offset, int c);
 int eb_insert_utf8_buf(EditBuffer *b, int offset, const char *buf, int len);
+int eb_insert_str(EditBuffer *b, int offset, const char *str);
+int eb_match_uchar(EditBuffer *b, int offset, int c);
+int eb_match_str(EditBuffer *b, int offset, const char *str);
+int eb_match_istr(EditBuffer *b, int offset, const char *str);
 int eb_printf(EditBuffer *b, const char *fmt, ...) __attr_printf(2,3);
 void eb_line_pad(EditBuffer *b, int n);
 int eb_get_contents(EditBuffer *b, char *buf, int buf_size);

Index: plugins/my_plugin.c
===================================================================
RCS file: /sources/qemacs/qemacs/plugins/my_plugin.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- plugins/my_plugin.c 6 Jan 2014 09:40:21 -0000       1.2
+++ plugins/my_plugin.c 11 Jan 2014 14:38:30 -0000      1.3
@@ -6,14 +6,11 @@
 /* insert 'hello' at the current cursor position */
 static void insert_hello(EditState *s)
 {
-    static char hello[] = "Hello";
-    int len = strlen(hello);
-
-    s->offset += eb_insert_utf8_buf(s->b, s->offset, hello, len);
+    s->offset += eb_insert_str(s->b, s->offset, "Hello world\n");
 }
 
 static CmdDef my_commands[] = {
-    CMD2( KEY_CTRLX('h'), KEY_NONE,
+    CMD2( KEY_CTRLC('h'), KEY_NONE,     /* C-c h */
           "insert-hello", insert_hello, ES, "*")
     CMD_DEF_END,
 };
@@ -26,5 +23,4 @@
     return 0;
 }
 
-
 qe_module_init(my_plugin_init);



reply via email to

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