qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs extras.c qeconfig.h


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs extras.c qeconfig.h
Date: Sun, 19 Jan 2014 15:33:57 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        14/01/19 15:33:57

Modified files:
        .              : extras.c qeconfig.h 

Log message:
        add delete-horizontal-lines on C-x C-o
        
        * add command delete-horizontal-lines in extras.c
        * simplify do_delete_horizontal_space
        * bind backward-paragraph and forward-paragraph to M-[ and M-]
        * M-[ binding is not effective in terminal because it clashes with ansi
          escape sequences
        * comment some key bindings for compatibility

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/extras.c?cvsroot=qemacs&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/qemacs/qeconfig.h?cvsroot=qemacs&r1=1.41&r2=1.42

Patches:
Index: extras.c
===================================================================
RCS file: /sources/qemacs/qemacs/extras.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- extras.c    17 Jan 2014 13:19:15 -0000      1.14
+++ extras.c    19 Jan 2014 15:33:56 -0000      1.15
@@ -106,22 +106,81 @@
 
 void do_delete_horizontal_space(EditState *s)
 {
-    int from, to, offset, ch;
+    int from, to, offset;
 
+    /* boundary check unnecessary because eb_prevc returns '\n'
+     * at bof and eof and qe_isblank return true only on SPC and TAB.
+     */
     from = to = s->offset;
+    while (qe_isblank(eb_prevc(s->b, from, &offset)))
+        from = offset;
+
+    while (qe_isblank(eb_nextc(s->b, to, &offset)))
+        to = offset;
+
+    eb_delete_range(s->b, from, to);
+}
+
+/* test for blank line at offset.
+ * return 0 if not blank.
+ * return 1 if blank and boundaries in *offset0, *offset1.
+ */
+static int eb_is_blank_line(EditBuffer *b, int offset, 
+                            int *offset0, int *offset1)
+{
+    int c, bol;
+    
+    bol = offset = eb_goto_bol(b, offset);
+    while ((c = eb_nextc(b, offset, &offset)) != '\n') {
+        if (!qe_isblank(c))
+            return 0;
+    }
+    if (offset0)
+        *offset0 = bol;
+    if (offset1)
+        *offset1 = offset;
+    return 1;
+}
+
+void do_delete_blank_lines(EditState *s)
+{
+    /* Delete blank lines:
+     * On blank line, delete all surrounding blank lines, leaving just one.
+     * On isolated blank line, delete that one.
+     * On nonblank line, delete any immediately following blank lines.
+     */
+    /* XXX: should simplify */
+    int from, offset, offset1, all = 0;
+    EditBuffer *b = s->b;
+
+    offset = s->offset;
+    if (eb_is_blank_line(b, offset, &offset, &offset1)) {
+        if ((offset == 0 || !eb_is_blank_line(b,
+                             eb_prev_line(b, offset), NULL, NULL))
+        &&  (offset1 >= b->total_size || !eb_is_blank_line(b,
+                            offset1, NULL, NULL))) {
+            all = 1;
+        }
+    } else {
+        offset = eb_next_paragraph(b, offset);
+        all = 1;
+    }
+
+    from = offset;
     while (from > 0) {
-        ch = eb_prevc(s->b, from, &offset);
-        if (!qe_isblank(ch))
+        if (!eb_is_blank_line(b, eb_prev_line(b, from), &from, NULL))
             break;
-        from = offset;
     }
-    while (to < s->b->total_size) {
-        ch = eb_nextc(s->b, to, &offset);
-        if (!qe_isblank(ch))
+    if (!all) {
+        eb_delete_range(b, from, offset);
+        /* Keep current blank line */
+        from = offset = eb_next_line(b, from);
+    }
+    while (offset < s->b->total_size) {
+        if (!eb_is_blank_line(b, offset, NULL, &offset))
             break;
-        to = offset;
     }
-    s->offset = eb_delete_range(s->b, from, to);
+    eb_delete_range(b, from, offset);
 }
 
 void do_show_date_and_time(EditState *s, int argval)
@@ -675,6 +734,8 @@
           "compare-windows", do_compare_windows, ESi, "ui" )
     CMD2( KEY_META('\\'), KEY_NONE,
           "delete-horizontal-space", do_delete_horizontal_space, ES, "*")
+    CMD2( KEY_CTRLX(KEY_CTRL('o')), KEY_NONE,
+          "delete-blank-lines", do_delete_blank_lines, ES, "*")
     CMD2( KEY_CTRLX('t'), KEY_NONE,
           "show-date-and-time", do_show_date_and_time, ESi, "ui")
 

Index: qeconfig.h
===================================================================
RCS file: /sources/qemacs/qemacs/qeconfig.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -b -r1.41 -r1.42
--- qeconfig.h  16 Jan 2014 14:28:28 -0000      1.41
+++ qeconfig.h  19 Jan 2014 15:33:56 -0000      1.42
@@ -163,10 +163,14 @@
 
     /*---------------- Search and replace ----------------*/
 
+    /* M-C-s should be bound to isearch-forward-regex */
+    /* mg binds search-forward to M-s */
     CMD3( KEY_META('S'), KEY_NONE,
           "search-forward", do_search_string, ESsi, 1,
          "s{Search forward: }|search|"
          "v")
+    /* M-C-r should be bound to isearch-backward-regex */
+    /* mg binds search-forward to M-r */
     CMD3( KEY_META('R'), KEY_NONE,
           "search-backward", do_search_string, ESsi, -1,
          "s{Search backward: }|search|"
@@ -181,6 +185,7 @@
          "*" "s{Query replace: }|search|"
          "s{With: }|replace|")
     /* passing argument restricts replace to word matches */
+    /* XXX: non standard binding */
     CMD2( KEY_META('r'), KEY_NONE,
           "replace-string", do_replace_string, ESssi,
          "*" "s{Replace String: }|search|"
@@ -191,9 +196,9 @@
 
     CMD0( KEY_META('h'), KEY_NONE,
           "mark-paragraph", do_mark_paragraph)
-    CMD0( KEY_META('{'), KEY_NONE,
+    CMD0( KEY_META('{'), KEY_META('['),
           "backward-paragraph", do_backward_paragraph)
-    CMD0( KEY_META('}'), KEY_NONE,
+    CMD0( KEY_META('}'), KEY_META(']'),
           "forward-paragraph", do_forward_paragraph)
     CMD2( KEY_META('q'), KEY_NONE,
           "fill-paragraph", do_fill_paragraph, ES, "*")



reply via email to

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