qemacs-commit
[Top][All Lists]
Advanced

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

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


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs qe.c qe.h qeconfig.h
Date: Wed, 26 Dec 2007 10:20:10 +0000

CVSROOT:        /cvsroot/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        07/12/26 10:20:09

Modified files:
        .              : qe.c qe.h qeconfig.h 

Log message:
        renamed do_quit -> do_exit_qemacs, takes argval:
           exits unconditionally if passed argument
        do_not_modified takes argval: set modified status if passed argument
        fixed argval passing to do_execute_command
        M-- start argument with -4, or changes sign
        protect against buffer overflow in qe_key_process (repeated C-u caused 
it)
        bind search forward/backward to M-S and M-R
        pass argval to do_replace_string, matches words if set
        fixed word matching in search function
        published search/replace functions as commands
        published do_end_macro and do_cmd_set_mode
        use name argval instead of argument for universal argument passed to 
command

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.54&r2=1.55
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.49&r2=1.50
http://cvs.savannah.gnu.org/viewcvs/qemacs/qeconfig.h?cvsroot=qemacs&r1=1.22&r2=1.23

Patches:
Index: qe.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -b -r1.54 -r1.55
--- qe.c        25 Dec 2007 07:54:00 -0000      1.54
+++ qe.c        26 Dec 2007 10:20:09 -0000      1.55
@@ -41,8 +41,6 @@
 void print_at_byte(QEditScreen *screen,
                    int x, int y, int width, int height,
                    const char *str, int style_index);
-static void do_cmd_set_mode(EditState *s, const char *name);
-void do_end_macro(EditState *s);
 static void get_default_path(EditState *s, char *buf, int buf_size);
 static EditBuffer *predict_switch_to_buffer(EditState *s);
 static StringArray *get_history(const char *name);
@@ -1208,7 +1206,7 @@
 }
 #endif
 
-void do_char(EditState *s, int key, int argument)
+void do_char(EditState *s, int key, int argval)
 {
     if (s->b->flags & BF_READONLY)
         return;
@@ -1216,7 +1214,7 @@
     for (;;) {
         if (s->mode->write_char)
             s->mode->write_char(s, key);
-        if (argument-- <= 1)
+        if (argval-- <= 1)
             break;
     }
 }
@@ -1300,7 +1298,7 @@
 
 struct QuoteKeyArgument {
     EditState *s;
-    int argument;
+    int argval;
 };
 
 /* XXX: may be better to move it into qe_key_process() */
@@ -1317,19 +1315,19 @@
     /* CG: why not insert special keys as well? */
     if (!KEY_SPECIAL(key) ||
         (key >= 0 && key <= 31)) {
-        do_char(s, key, qa->argument);
+        do_char(s, key, qa->argval);
         edit_display(s->qe_state);
         dpy_flush(&global_screen);
     }
     qe_ungrab_keys();
 }
 
-void do_quote(EditState *s, int argument)
+void do_quote(EditState *s, int argval)
 {
     struct QuoteKeyArgument *qa = qe_mallocz(struct QuoteKeyArgument);
 
     qa->s = s;
-    qa->argument = argument;
+    qa->argval = argval;
 
     qe_grab_keys(quote_key, qa);
     put_status(s, "Quote: ");
@@ -1340,9 +1338,9 @@
     s->insert = !s->insert;
 }
 
-void do_tab(EditState *s, int argument)
+void do_tab(EditState *s, int argval)
 {
-    do_char(s, 9, argument);
+    do_char(s, 9, argval);
 }
 
 void do_open_line(EditState *s)
@@ -1660,7 +1658,7 @@
     do_set_mode_file(s, m, saved_data, NULL);
 }
 
-static void do_cmd_set_mode(EditState *s, const char *name)
+void do_cmd_set_mode(EditState *s, const char *name)
 {
     ModeDef *m;
 
@@ -3922,7 +3920,8 @@
                         c->argval = c->argval * 10 + (key - '0');
                         c->nb_keys = 0;
                         goto next;
-                    } else if (key == '-') {
+                    } else
+                    if (key == '-') {
                         c->sign = -c->sign;
                         c->nb_keys = 0;
                         goto next;
@@ -3953,22 +3952,27 @@
         qe_key_init();
         dpy_flush(&global_screen);
         return;
-    } else if (c->nb_keys == kd->nb_keys) {
+    } else
+    if (c->nb_keys == kd->nb_keys) {
     exec_cmd:
         d = kd->cmd;
         if (d->action.func == (void *)do_universal_argument && 
             !c->describe_key) {
             /* special handling for universal argument */
             c->is_universal_arg = 1;
+            if (key == KEY_META('-')) {
+                c->sign = -c->sign;
+                if (c->noargval == 1)
+                    c->noargval = 4;
+            } else {
             c->noargval = c->noargval * 4;
+            }
             c->nb_keys = 0;
         } else {
             if (c->is_universal_arg) {
-                if (c->argval == NO_ARG) {
+                if (c->argval == NO_ARG)
                     c->argval = c->noargval;
-                } else {
-                    c->argval = c->argval * c->sign;
-                }
+                c->argval *= c->sign;
             }
             if (c->describe_key) {
                 put_status(s, "%s runs the command %s", 
@@ -3998,8 +4002,8 @@
         len = strlen(c->buf);
         if (len >= 1)
             c->buf[len-1] = ' ';
-        strcat(c->buf, buf1);
-        strcat(c->buf, "-");
+        pstrcat(c->buf, sizeof(c->buf), buf1);
+        pstrcat(c->buf, sizeof(c->buf), "-");
         put_status(s, "%s", c->buf);
         dpy_flush(&global_screen);
     }
@@ -4857,9 +4861,9 @@
     s->b->flags ^= BF_READONLY;
 }
 
-void do_not_modified(EditState *s)
+void do_not_modified(EditState *s, int argval)
 {
-    s->b->modified = 0;
+    s->b->modified = (argval != NO_ARG);
 }
 
 static void kill_buffer_confirm_cb(void *opaque, char *reply);
@@ -5203,11 +5207,16 @@
 static void quit_key(void *opaque, int ch);
 static void quit_confirm_cb(void *opaque, char *reply);
 
-void do_quit(EditState *s)
+void do_exit_qemacs(EditState *s, int argval)
 {
     QEmacsState *qs = s->qe_state;
     QuitState *is;
 
+    if (argval != NO_ARG) {
+        url_exit();
+        return;
+    }
+
     is = qe_malloc(QuitState);
     if (!is)
         return;
@@ -5367,6 +5376,7 @@
             return -1;
         if (offset > (total_size - size))
             return -1;
+
         /* search abort */
         if ((offset & 0xfff) == 0) {
             if (abort_func && abort_func(abort_opaque))
@@ -5375,16 +5385,11 @@
 
         /* search start of word */
         if (flags & SEARCH_FLAG_WORD) {
-            if (offset == 0)
-                goto word_start_found;
-            eb_read(b, offset - 1, &ch, 1);
-            if (!qe_isword(ch))
-                goto word_start_found;
-            else
+            ch = eb_prevc(b, offset, NULL);
+            if (qe_isword(ch))
                 continue;
         }
 
-    word_start_found:
         i = 0;
         for (;;) {
             eb_read(b, offset + i, &ch, 1);
@@ -5396,14 +5401,10 @@
             if (i == size) {
                 /* check end of word */
                 if (flags & SEARCH_FLAG_WORD) {
-                    if (offset + size >= total_size)
-                        goto word_end_found;
-                    eb_read(b, offset + size, &ch, 1);
-                    if (!qe_isword(ch))
-                        goto word_end_found;
+                    ch = eb_prevc(b, offset + size, NULL);
+                    if (qe_isword(ch))
                     break;
                 }
-            word_end_found:
                 return offset;
             }
         }
@@ -5671,6 +5672,7 @@
     int nb_reps;
     int search_bytes_len, replace_bytes_len, found_offset;
     int replace_all;
+    int flags;
     char search_str[SEARCH_LENGTH];
     char replace_str[SEARCH_LENGTH];
     u8 search_bytes[SEARCH_LENGTH];
@@ -5705,7 +5707,7 @@
  redo:
     is->found_offset = eb_search(s->b, is->found_offset, 1, 
                                  is->search_bytes, is->search_bytes_len, 
-                                 0, NULL, NULL);
+                                 is->flags, NULL, NULL);
     if (is->found_offset < 0) {
         query_replace_abort(is);
         return;
@@ -5755,14 +5757,14 @@
     
 static void query_replace(EditState *s, 
                           const char *search_str,
-                          const char *replace_str, int all)
+                          const char *replace_str, int all, int flags)
 {
     QueryReplaceState *is;
     
     if (s->b->flags & BF_READONLY)
         return;
 
-    is = qe_malloc(QueryReplaceState);
+    is = qe_mallocz(QueryReplaceState);
     if (!is)
         return;
     is->s = s;
@@ -5776,26 +5778,26 @@
     is->nb_reps = 0;
     is->replace_all = all;
     is->found_offset = s->offset;
+    is->flags = flags;
 
     qe_grab_keys(query_replace_key, is);
     query_replace_display(is);
 }
 
-static void do_query_replace(EditState *s, 
-                             const char *search_str,
+void do_query_replace(EditState *s, const char *search_str,
                              const char *replace_str)
 {
-    query_replace(s, search_str, replace_str, 0);
+    query_replace(s, search_str, replace_str, 0, 0);
 }
 
-static void do_replace_string(EditState *s, 
-                              const char *search_str,
-                              const char *replace_str)
+void do_replace_string(EditState *s, const char *search_str,
+                       const char *replace_str, int argval)
 {
-    query_replace(s, search_str, replace_str, 1);
+    query_replace(s, search_str, replace_str, 1,
+                  argval == NO_ARG ? 0 : SEARCH_FLAG_WORD);
 }
 
-static void do_search_string(EditState *s, const char *search_str, int dir)
+void do_search_string(EditState *s, const char *search_str, int dir)
 {
     u8 search_bytes[SEARCH_LENGTH];
     int search_bytes_len;

Index: qe.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.h,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -b -r1.49 -r1.50
--- qe.h        26 Dec 2007 09:53:46 -0000      1.49
+++ qe.h        26 Dec 2007 10:20:09 -0000      1.50
@@ -1432,7 +1432,7 @@
 void display_mode_line(EditState *s);
 
 /* loading files */
-void do_quit(EditState *s);
+void do_exit_qemacs(EditState *s, int argval);
 void do_load(EditState *s, const char *filename);
 void do_load_from_path(EditState *s, const char *filename);
 void do_switch_to_buffer(EditState *s, const char *bufname);
@@ -1442,6 +1442,11 @@
 void do_write_file(EditState *s, const char *filename);
 void do_write_region(EditState *s, const char *filename);
 void do_isearch(EditState *s, int dir);
+void do_query_replace(EditState *s, const char *search_str,
+                      const char *replace_str);
+void do_replace_string(EditState *s, const char *search_str,
+                       const char *replace_str, int argval);
+void do_search_string(EditState *s, const char *search_str, int dir);
 void do_refresh_complete(EditState *s);
 void do_kill_buffer(EditState *s, const char *bufname1);
 void switch_to_buffer(EditState *s, EditBuffer *b);
@@ -1459,11 +1464,11 @@
 int get_colorized_line(EditState *s, unsigned int *buf, int buf_size,
                        int offset1, int line_num);
 
-// should take argval
-void do_char(EditState *s, int key, int argument);
+void do_char(EditState *s, int key, int argval);
 // bad name!
 // void do_set_mode(EditState *s, const char *mode_name);
 void do_set_mode(EditState *s, ModeDef *m, ModeSavedData *saved_data);
+void do_cmd_set_mode(EditState *s, const char *name);
 void text_move_left_right_visual(EditState *s, int dir);
 void text_move_word_left_right(EditState *s, int dir);
 void text_move_up_down(EditState *s, int dir);
@@ -1472,8 +1477,7 @@
 void do_return(EditState *s);
 void do_backspace(EditState *s, int argval);
 void do_delete_char(EditState *s, int argval);
-// should take argval
-void do_tab(EditState *s, int argument);
+void do_tab(EditState *s, int argval);
 EditBuffer *new_yank_buffer(void);
 void do_append_next_kill(EditState *s);
 void do_kill(EditState *s, int p1, int p2, int dir);
@@ -1519,8 +1523,7 @@
 void do_scroll_up_down(EditState *s, int dir);
 void perform_scroll_up_down(EditState *s, int h);
 void do_center_cursor(EditState *s);
-// should take argval
-void do_quote(EditState *s, int argument);
+void do_quote(EditState *s, int argval);
 void do_insert(EditState *s);
 void do_open_line(EditState *s);
 // should take argval
@@ -1558,6 +1561,7 @@
 void window_display(EditState *s);
 void do_universal_argument(EditState *s);
 void do_start_macro(EditState *s);
+void do_end_macro(EditState *s);
 void do_call_macro(EditState *s);
 void do_execute_macro_keys(EditState *s, const char *keys);
 void do_define_kbd_macro(EditState *s, const char *name, const char *keys,
@@ -1571,7 +1575,7 @@
 void do_minibuffer_exit(EditState *s, int abort);
 void do_less_exit(EditState *s);
 void do_toggle_read_only(EditState *s);
-void do_not_modified(EditState *s);
+void do_not_modified(EditState *s, int argval);
 void do_find_alternate_file(EditState *s, const char *filename);
 void do_load_file_from_path(EditState *s, const char *filename);
 void do_set_visited_file_name(EditState *s, const char *filename,

Index: qeconfig.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qeconfig.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- qeconfig.h  25 Dec 2007 07:54:00 -0000      1.22
+++ qeconfig.h  26 Dec 2007 10:20:09 -0000      1.23
@@ -49,7 +49,7 @@
     CMD0( KEY_META('>'), KEY_CTRL_END, "end-of-buffer", do_eof )
     /* do_tab will not change read only buffer */
     CMD_( KEY_CTRL('i'), KEY_NONE, "tabulate", do_tab, "ui")
-    //CMD0( KEY_SPC, KEY_NONE, "space", do_space) /* u? */
+    //CMD_( KEY_SPC, KEY_NONE, "space", do_space, "*ui")
     CMD_( KEY_CTRL('q'), KEY_NONE, "quoted-insert", do_quote, "*ui")
     CMD_( KEY_CTRL('j'), KEY_RET, "newline", do_return, "*")
     CMD_( KEY_CTRL('o'), KEY_NONE, "open-line", do_open_line, "*")
@@ -93,23 +93,25 @@
           "s{Kill buffer: }[buffer]|buffer|")
     CMD0( KEY_CTRLX(KEY_CTRL('q')), KEY_NONE, "toggle-read-only", 
           do_toggle_read_only)
-    CMD0( KEY_META('~'), KEY_NONE, "not-modified", do_not_modified) /* u */
+    CMD_( KEY_META('~'), KEY_NONE, "not-modified", do_not_modified, "ui")
     CMD_( KEY_NONE, KEY_NONE, "set-visited-file-name",
           do_set_visited_file_name,
           "s{Set visited file name: }[file]|file|s{Rename file? }")
 
     /*---------------- Search and replace ----------------*/
 
-    CMDV( KEY_NONE, KEY_NONE, "search-forward", do_search_string, 1,
+    CMDV( KEY_META('S'), KEY_NONE, "search-forward", do_search_string, 1,
           "s{Search forward: }|search|v")
-    CMDV( KEY_NONE, KEY_NONE, "search-backward", do_search_string, -1,
+    CMDV( KEY_META('R'), KEY_NONE, "search-backward", do_search_string, -1,
           "s{Search backward: }|search|v")
-    CMD1( KEY_CTRL('r'), KEY_NONE, "isearch-backward", do_isearch, -1 ) /* u? 
*/
-    CMD1( KEY_CTRL('s'), KEY_NONE, "isearch-forward", do_isearch, 1 ) /* u? */
+    /* passing argument should switch to regex incremental search */
+    CMD1( KEY_CTRL('r'), KEY_NONE, "isearch-backward", do_isearch, -1 )
+    CMD1( KEY_CTRL('s'), KEY_NONE, "isearch-forward", do_isearch, 1 )
     CMD_( KEY_META('%'), KEY_NONE, "query-replace", do_query_replace,
           "*s{Query replace: }|search|s{With: }|replace|")
+    /* passing argument restricts replace to word matches */
     CMD_( KEY_META('r'), KEY_NONE, "replace-string", do_replace_string,
-          "*s{Replace String: }|search|s{With: }|replace|") /* u? */
+          "*s{Replace String: }|search|s{With: }|replace|ui")
 
     /*---------------- Paragraph / case handling ----------------*/
 
@@ -123,17 +125,17 @@
     CMDV( KEY_META('u'), KEY_NONE, "upcase-word", do_changecase_word, 1, "*v")
     CMDV( KEY_META(KEY_CTRL('c')), KEY_NONE,
           "capitalize-region", do_changecase_region, 2, "*v")
-    CMDV( KEY_CTRLX(KEY_CTRL('l')), KEY_META(KEY_CTRL('l')),
+    CMDV( KEY_CTRLX(KEY_CTRL('l')), KEY_NONE,
           "downcase-region", do_changecase_region, -1, "*v")
-    CMDV( KEY_CTRLX(KEY_CTRL('u')), KEY_META(KEY_CTRL('u')),
+    CMDV( KEY_CTRLX(KEY_CTRL('u')), KEY_NONE,
           "upcase-region", do_changecase_region, 1, "*v")
 
     /*---------------- Command handling ----------------*/
 
     CMD_( KEY_META('x'), KEY_NONE, "execute-command", do_execute_command,
-          "s{Command: }[command]|command|i") /* u? */
-    /* A-- should start negative universal argument */
-    CMD0( KEY_CTRL('u'), KEY_NONE, "universal-argument",
+          "s{Command: }[command]|command|ui")
+    /* M-0 thru M-9 should start universal argument */
+    CMD0( KEY_CTRL('u'), KEY_META('-'), "universal-argument",
           do_universal_argument)
     CMD0( KEY_CTRL('g'), KEY_CTRLX(KEY_CTRL('g')), "abort", do_break)
     CMD0( KEY_CTRLX('('), KEY_NONE, "start-kbd-macro", do_start_macro)
@@ -208,7 +210,8 @@
 
     /*---------------- Miscellaneous ----------------*/
 
-    CMD0( KEY_CTRLX(KEY_CTRL('c')), KEY_NONE, "exit-qemacs", do_quit ) /* u? */
+    CMD_( KEY_CTRLX(KEY_CTRL('c')), KEY_NONE, "exit-qemacs", 
+          do_exit_qemacs, "ui")
     CMD0( KEY_CTRL('l'), KEY_NONE, "refresh", do_refresh_complete)
     CMD0( KEY_NONE, KEY_NONE, "doctor", do_doctor)
     CMD0( KEY_CTRLX('u'), KEY_CTRL('_'), "undo", do_undo)




reply via email to

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