This is a modified diff of the previous evaluate multi-argument diff. The main difference is that all functions are given a number of parameters in the function map, this number represents how many arguments are required for the function to work. This extra column indicates to multiarg() how it should treat the list of arguments it receives, it needs to know how many arguments are 'normal' for the function being used, in order to separate the different invocations of the function to have the correct number of arguments. For example, this call to functionX:

(functionX w x y z)

Does functionX need 4 invocations, or 2, or 1?

The new value is not used in any other situation other than evaluating the startup file or using an evaluate command, therefor it doesn't interfere with using mg as an interactive editor.

I'd appreciate if this diff could be tested, to show if there are regressions in peoples .mg files. This diff does treat the '(' and ')' chars differently than previously, in-so-far as they are not ignored if they are at the end or start of a line now. However, even though these characters are not ignored, this diff should not change the behaviour of an extant .mg file, with '(' and ')' chars at the end and start of a line. This situation is accomodated for in this diff (with limited testing though).

Does the above text explain what I am trying to do? In a general sense, this diff is to aid in the programability/extensibility of mg. If you have any thoughts or suggestions on how this could be acheived, please feel free to give me feedback/observations/criticisms etc.. Thanks.

Mark

Index: cmode.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/cmode.c,v
retrieving revision 1.16
diff -u -p -u -p -r1.16 cmode.c
--- cmode.c     26 Sep 2015 21:51:58 -0000      1.16
+++ cmode.c     9 Jul 2019 16:54:49 -0000
@@ -91,12 +91,12 @@ static struct KEYMAPE (3) cmodemap = {
 void
 cmode_init(void)
 {
-       funmap_add(cmode, "c-mode");
-       funmap_add(cc_char, "c-handle-special-char");
-       funmap_add(cc_brace, "c-handle-special-brace");
-       funmap_add(cc_tab, "c-tab-or-indent");
-       funmap_add(cc_indent, "c-indent");
-       funmap_add(cc_lfindent, "c-indent-and-newline");
+       funmap_add(cmode, "c-mode", 0);
+       funmap_add(cc_char, "c-handle-special-char", 0);
+       funmap_add(cc_brace, "c-handle-special-brace", 0);
+       funmap_add(cc_tab, "c-tab-or-indent", 0);
+       funmap_add(cc_indent, "c-indent", 0);
+       funmap_add(cc_lfindent, "c-indent-and-newline", 0);
        maps_add((KEYMAP *)&cmodemap, "c");
 }

Index: dired.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/dired.c,v
retrieving revision 1.92
diff -u -p -u -p -r1.92 dired.c
--- dired.c     1 Jul 2019 19:36:17 -0000       1.92
+++ dired.c     9 Jul 2019 16:54:49 -0000
@@ -204,24 +204,24 @@ static struct KEYMAPE (7) diredmap = {
 void
 dired_init(void)
 {
-       funmap_add(dired, "dired");
-       funmap_add(d_create_directory, "dired-create-directory");
-       funmap_add(d_copy, "dired-do-copy");
-       funmap_add(d_expunge, "dired-do-flagged-delete");
-       funmap_add(d_rename, "dired-do-rename");
-       funmap_add(d_findfile, "dired-find-file");
-       funmap_add(d_ffotherwindow, "dired-find-file-other-window");
-       funmap_add(d_del, "dired-flag-file-deletion");
-       funmap_add(d_gotofile, "dired-goto-file");
-       funmap_add(d_forwline, "dired-next-line");
-       funmap_add(d_otherwindow, "dired-other-window");
-       funmap_add(d_backline, "dired-previous-line");
-       funmap_add(d_refreshbuffer, "dired-revert");
-       funmap_add(d_backpage, "dired-scroll-down");
-       funmap_add(d_forwpage, "dired-scroll-up");
-       funmap_add(d_undel, "dired-unmark");
-       funmap_add(d_undelbak, "dired-unmark-backward");
-       funmap_add(d_killbuffer_cmd, "quit-window");
+       funmap_add(dired, "dired", 1);
+       funmap_add(d_create_directory, "dired-create-directory", 1);
+       funmap_add(d_copy, "dired-do-copy", 1);
+       funmap_add(d_expunge, "dired-do-flagged-delete", 0);
+       funmap_add(d_rename, "dired-do-rename", 1);
+       funmap_add(d_findfile, "dired-find-file", 1);
+       funmap_add(d_ffotherwindow, "dired-find-file-other-window", 1);
+       funmap_add(d_del, "dired-flag-file-deletion", 0);
+       funmap_add(d_gotofile, "dired-goto-file", 1);
+       funmap_add(d_forwline, "dired-next-line", 0);
+       funmap_add(d_otherwindow, "dired-other-window", 0);
+       funmap_add(d_backline, "dired-previous-line", 0);
+       funmap_add(d_refreshbuffer, "dired-revert", 0);
+       funmap_add(d_backpage, "dired-scroll-down", 0);
+       funmap_add(d_forwpage, "dired-scroll-up", 0);
+       funmap_add(d_undel, "dired-unmark", 0);
+       funmap_add(d_undelbak, "dired-unmark-backward", 0);
+       funmap_add(d_killbuffer_cmd, "quit-window", 0);
        maps_add((KEYMAP *)&diredmap, "dired");
        dobindkey(fundamental_map, "dired", "^Xd");
 }
Index: extend.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/extend.c,v
retrieving revision 1.66
diff -u -p -u -p -r1.66 extend.c
--- extend.c    5 Jul 2019 14:50:59 -0000       1.66
+++ extend.c    9 Jul 2019 16:54:49 -0000
@@ -8,6 +8,7 @@

 #include <sys/queue.h>
 #include <sys/types.h>
+#include <regex.h>
 #include <ctype.h>
 #include <limits.h>
 #include <signal.h>
@@ -693,6 +694,115 @@ load(const char *fname)
 }

 /*
+ * Line has a '(' as the first non-white char.
+ */
+int
+multiarg(char *funstr)
+{
+       regex_t  regex_buff;
+       PF       funcp;
+       char     excbuf[128];
+       char    *cmdp, *argp, *fendp, *endp, *p, *s = " ";
+       int      singlecmd = 0, spc, numparams, numspc;
+ + endp = strrchr(funstr, ')');
+       if (endp == NULL) {
+               ewprintf("No closing parenthesis found");
+               return(FALSE);
+       }
+       p = endp + 1;
+       /* we now know that string starts with '(' and ends with ')' */
+       *p = '\0';
+
+       if (regcomp(&regex_buff, "^\([\t ]*)$", 0)) {
+               dobeep();
+               ewprintf("Could not compile regex");
+               return(FALSE);
+       }
+       if (!regexec(&regex_buff, funstr, 0, NULL, 0)) {
+               dobeep();
+               ewprintf("No command found");
+               return(FALSE);
+       }
+ + /* currently there are no mg commands that don't have a letter */
+       if (regcomp(&regex_buff, "^\([\t ]*[A-Za-z]*[\t ]*)$", 0)) {
+               dobeep();
+               ewprintf("Could not compile regex");
+               return(FALSE);
+       }
+       if (!regexec(&regex_buff, funstr, 0, NULL, 0))
+               singlecmd = 1;
+
+       p = funstr + 1;         /* move past first '(' char.    */
+       cmdp = skipwhite(p);    /* find first char of command.  */
+
+       if (singlecmd) {
+               cmdp[strlen(cmdp) - 1] = '\0'; /* remove ')'    */
+               return(excline(cmdp));
+       }
+ if ((fendp = strchr(cmdp, ' ')) == NULL) + fendp = strchr(cmdp, '\t');
+
+       *fendp = '\0';
+       /*
+        * If no extant mg command found, line could be a (define of some kind.
+        * Since no defines exist at the moment, just return.
+        */
+       if ((funcp = name_function(cmdp)) == NULL) {
+               dobeep();
+               ewprintf("Unknown command: %s", cmdp);
+               return (FALSE);
+       }
+       numparams = numparams_function(funcp);
+
+       /* now find the first argument */
+ p = fendp + 1; + argp = skipwhite(p);
+       numspc = spc = 1; /* initially fake a space so we find first argument */
+
+       for (p = argp; *p != '\0'; p++) {
+               if (*p == ' ' || *p == '\t' || *p == ')') {
+                       if (spc == 1)
+                               continue;
+                       if (spc == 0 && (numspc % numparams == 0)) {
+                               *p = '\0';      /* terminate arg string */
+                               excbuf[0] = '\0';
+                               if (strlcpy(excbuf, cmdp, sizeof(excbuf))
+                                    >= sizeof(excbuf)) {
+                                       dobeep();
+                                       ewprintf("strlcpy error");
+                                       return (FALSE);
+                               }
+                               if (strlcat(excbuf, s, sizeof(excbuf))
+                                   >= sizeof(excbuf)) {
+                                       dobeep();
+                                       ewprintf("strlcpy error");
+                                       return (FALSE);
+                               }
+                               if (strlcat(excbuf, argp, sizeof(excbuf))
+                                   >= sizeof(excbuf)) {
+                                       dobeep();
+                                       ewprintf("strlcpy error");
+                                       return (FALSE);
+                               }
+                               excline(excbuf);
+                               *p = ' ';       /* so 'for' loop can continue */
+                       }
+                       numspc++;
+                       spc = 1;
+               } else {
+                       if (spc == 1)
+                               if ((numparams == 1) ||
+                                   ((numspc + 1) % numparams) == 0)
+                                       argp = p;
+                       spc = 0;
+               }
+       }
+       return (TRUE);
+}
+
+/*
  * excline - run a line from a load file or eval-expression.
  */
 int
@@ -724,6 +834,8 @@ excline(char *line)
        funcp = skipwhite(line);
        if (*funcp == '\0')
                return (TRUE);  /* No error on blank lines */
+       if (*funcp == '(')
+               return (multiarg(funcp));
        line = parsetoken(funcp);
        if (*line != '\0') {
                *line++ = '\0';
@@ -928,7 +1040,7 @@ cleanup:
 static char *
 skipwhite(char *s)
 {
-       while (*s == ' ' || *s == '\t' || *s == ')' || *s == '(')
+       while (*s == ' ' || *s == '\t')
                s++;
        if ((*s == ';') || (*s == '#'))
                *s = '\0';
Index: funmap.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/funmap.c,v
retrieving revision 1.58
diff -u -p -u -p -r1.58 funmap.c
--- funmap.c    3 Jul 2019 18:11:07 -0000       1.58
+++ funmap.c    9 Jul 2019 16:54:49 -0000
@@ -13,213 +13,228 @@
 #include "kbd.h"

 /*
- * If the function is NULL, it must be listed with the
- * same name in the map_table.
+ * funmap structure: a list of functions and their command-names/#parameters.
+ *
+ * If the function is NULL, it must be listed with the same name in the
+ * map_table.
  */
-
 struct funmap {
        PF               fn_funct;
        const            char *fn_name;
+       int              fn_nparams;
        struct funmap   *fn_next;
 };
-
 static struct funmap *funs;

+/*
+ * 3rd column in the functnames structure indicates how many parameters the
+ * function takes in 'normal' usage. This column is only used to identify
+ * function profiles when lines of a buffer are being evaluated via excline().
+ *
+ *  0 = a toggle, non-modifiable insert/delete, region modifier, etc
+ *  1 = value can be string or number value (like: file/buf name, search 
string)
+ *  2 = multiple type value required, see auto-execute, or global-set-key, etc
+ * -1 = variable length # parameters (unused at moment)
+ *
+ * Some functions when used interactively may ask for a 'y' or 'n' (or another
+ * character) to continue, in excline, a 'y' is assumed. Functions like this
+ * have '0' in the 3rd column below.
+ */
 static struct funmap functnames[] = {
-       {apropos_command, "apropos",},
-       {toggleaudiblebell, "audible-bell",},
-       {auto_execute, "auto-execute",},
-       {fillmode, "auto-fill-mode",},
-       {indentmode, "auto-indent-mode",},
-       {backtoindent, "back-to-indentation",},
-       {backuptohomedir, "backup-to-home-directory",},
-       {backchar, "backward-char",},
-       {delbword, "backward-kill-word",},
-       {gotobop, "backward-paragraph",},
-       {backword, "backward-word",},
-       {gotobob, "beginning-of-buffer",},
-       {gotobol, "beginning-of-line",},
-       {showmatch, "blink-and-insert",},
-       {bsmap, "bsmap-mode",},
-       {NULL, "c-x 4 prefix",},
-       {NULL, "c-x prefix",},
-       {executemacro, "call-last-kbd-macro",},
-       {capword, "capitalize-word",},
-       {changedir, "cd",},
-       {clearmark, "clear-mark",},
-       {colnotoggle, "column-number-mode",},
-       {copyregion, "copy-region-as-kill",},
+       {apropos_command, "apropos", 1},
+       {toggleaudiblebell, "audible-bell", 0},
+       {auto_execute, "auto-execute", 2},
+       {fillmode, "auto-fill-mode", 0},
+       {indentmode, "auto-indent-mode", 0},
+       {backtoindent, "back-to-indentation", 0},
+       {backuptohomedir, "backup-to-home-directory", 0},
+       {backchar, "backward-char", 0},
+       {delbword, "backward-kill-word", 0},
+       {gotobop, "backward-paragraph", 0},
+       {backword, "backward-word", 0},
+       {gotobob, "beginning-of-buffer", 0},
+       {gotobol, "beginning-of-line", 0},
+       {showmatch, "blink-and-insert", 1},           /* startup only */
+       {bsmap, "bsmap-mode", 0},
+       {NULL, "c-x 4 prefix", 0},                    /* internal     */
+       {NULL, "c-x prefix", 0},                      /* internal     */
+       {executemacro, "call-last-kbd-macro", 0},
+       {capword, "capitalize-word", 0},
+       {changedir, "cd", 1},
+       {clearmark, "clear-mark", 0},
+       {colnotoggle, "column-number-mode", 0},
+       {copyregion, "copy-region-as-kill", 0},
 #ifdef REGEX
-       {cntmatchlines, "count-matches",},
-       {cntnonmatchlines, "count-non-matches",},
+       {cntmatchlines, "count-matches", 1},
+       {cntnonmatchlines, "count-non-matches", 1},
 #endif /* REGEX */
-       {cscreatelist, "cscope-create-list-of-files-to-index",},
-       {csfuncalled, "cscope-find-called-functions",},
-       {csegrep, "cscope-find-egrep-pattern",},
-       {csfindinc, "cscope-find-files-including-file",},
-       {cscallerfuncs, "cscope-find-functions-calling-this-function",},
-       {csdefinition, "cscope-find-global-definition",},
-       {csfindfile, "cscope-find-this-file",},
-       {cssymbol, "cscope-find-this-symbol",},
-       {csfindtext, "cscope-find-this-text-string",},
-       {csnextfile, "cscope-next-file",},
-       {csnextmatch, "cscope-next-symbol",},
-       {csprevfile, "cscope-prev-file",},
-       {csprevmatch, "cscope-prev-symbol",},
-       {redefine_key, "define-key",},
-       {backdel, "delete-backward-char",},
-       {deblank, "delete-blank-lines",},
-       {forwdel, "delete-char",},
-       {delwhite, "delete-horizontal-space",},
-       {delleadwhite, "delete-leading-space",},
+       {cscreatelist, "cscope-create-list-of-files-to-index", 1},
+       {csfuncalled, "cscope-find-called-functions", 1},
+       {csegrep, "cscope-find-egrep-pattern", 1},
+       {csfindinc, "cscope-find-files-including-file", 1},
+       {cscallerfuncs, "cscope-find-functions-calling-this-function", 1},
+       {csdefinition, "cscope-find-global-definition", 1},
+       {csfindfile, "cscope-find-this-file", 1},
+       {cssymbol, "cscope-find-this-symbol", 1},
+       {csfindtext, "cscope-find-this-text-string", 1},
+       {csnextfile, "cscope-next-file", 0},
+       {csnextmatch, "cscope-next-symbol", 0},
+       {csprevfile, "cscope-prev-file", 0},
+       {csprevmatch, "cscope-prev-symbol", 0},
+       {redefine_key, "define-key", 3},
+       {backdel, "delete-backward-char", 0},
+       {deblank, "delete-blank-lines", 0},
+       {forwdel, "delete-char", 0},
+       {delwhite, "delete-horizontal-space", 0},
+       {delleadwhite, "delete-leading-space", 0},
 #ifdef REGEX
-       {delmatchlines, "delete-matching-lines",},
-       {delnonmatchlines, "delete-non-matching-lines",},
+       {delmatchlines, "delete-matching-lines", 1},
+       {delnonmatchlines, "delete-non-matching-lines", 1},
 #endif /* REGEX */
-       {onlywind, "delete-other-windows",},
-       {deltrailwhite, "delete-trailing-space",},
-       {delwind, "delete-window",},
-       {wallchart, "describe-bindings",},
-       {desckey, "describe-key-briefly",},
-       {diffbuffer, "diff-buffer-with-file",},
-       {digit_argument, "digit-argument",},
-       {lowerregion, "downcase-region",},
-       {lowerword, "downcase-word",},
-       {showversion, "emacs-version",},
-       {finishmacro, "end-kbd-macro",},
-       {gotoeob, "end-of-buffer",},
-       {gotoeol, "end-of-line",},
-       {enlargewind, "enlarge-window",},
-       {NULL, "esc prefix",},
-       {evalbuffer, "eval-current-buffer",},
-       {evalexpr, "eval-expression",},
-       {swapmark, "exchange-point-and-mark",},
-       {extend, "execute-extended-command",},
-       {fillpara, "fill-paragraph",},
-       {filevisitalt, "find-alternate-file",},
-       {filevisit, "find-file",},
-       {poptofile, "find-file-other-window",},
-       {filevisitro, "find-file-read-only",},
-       {findtag, "find-tag",},
-       {forwchar, "forward-char",},
-       {gotoeop, "forward-paragraph",},
-       {forwword, "forward-word",},
-       {bindtokey, "global-set-key",},
-       {unbindtokey, "global-unset-key",},
-       {globalwdtoggle, "global-wd-mode",},
-       {gotoline, "goto-line",},
-       {help_help, "help-help",},
-       {indent, "indent-current-line",},
-       {insert, "insert",},
-       {bufferinsert, "insert-buffer",},
-       {fileinsert, "insert-file",},
-       {fillword, "insert-with-wrap",},
-       {backisearch, "isearch-backward",},
-       {forwisearch, "isearch-forward",},
-       {joinline, "join-line",},
-       {justone, "just-one-space",},
-       {ctrlg, "keyboard-quit",},
-       {killbuffer_cmd, "kill-buffer",},
-       {killline, "kill-line",},
-       {killpara, "kill-paragraph",},
-       {killregion, "kill-region",},
-       {delfword, "kill-word",},
-       {toggleleavetmp, "leave-tmpdir-backups",},
-       {linenotoggle, "line-number-mode",},
-       {listbuffers, "list-buffers",},
-       {evalfile, "load",},
-       {localbind, "local-set-key",},
-       {localunbind, "local-unset-key",},
-       {makebkfile, "make-backup-files",},
-       {makedir, "make-directory",},
-       {markpara, "mark-paragraph",},
-       {markbuffer, "mark-whole-buffer",},
-       {do_meta, "meta-key-mode",},  /* better name, anyone? */
-       {negative_argument, "negative-argument",},
-       {enewline, "newline",},
-       {lfindent, "newline-and-indent",},
-       {forwline, "next-line",},
+       {onlywind, "delete-other-windows", 0},
+       {deltrailwhite, "delete-trailing-space", 0},
+       {delwind, "delete-window", 0},
+       {wallchart, "describe-bindings", 0},
+       {desckey, "describe-key-briefly", 1},
+       {diffbuffer, "diff-buffer-with-file", 0},
+       {digit_argument, "digit-argument", 1},
+       {lowerregion, "downcase-region", 0},
+       {lowerword, "downcase-word", 0},
+       {showversion, "emacs-version", 0},
+       {finishmacro, "end-kbd-macro", 0},
+       {gotoeob, "end-of-buffer", 0},
+       {gotoeol, "end-of-line", 0},
+       {enlargewind, "enlarge-window", 0},
+       {NULL, "esc prefix", 0},                      /* internal     */
+       {evalbuffer, "eval-current-buffer", 0},
+       {evalexpr, "eval-expression", 0},
+       {swapmark, "exchange-point-and-mark", 0},
+       {extend, "execute-extended-command", 1},
+       {fillpara, "fill-paragraph", 0},
+       {filevisitalt, "find-alternate-file", 1},
+       {filevisit, "find-file", 1},
+       {poptofile, "find-file-other-window", 1},
+       {filevisitro, "find-file-read-only", 1},
+       {findtag, "find-tag", 1},
+       {forwchar, "forward-char", 0},
+       {gotoeop, "forward-paragraph", 0},
+       {forwword, "forward-word", 0},
+       {bindtokey, "global-set-key", 2},
+       {unbindtokey, "global-unset-key", 1},
+       {globalwdtoggle, "global-wd-mode", 0},
+       {gotoline, "goto-line", 1},
+       {help_help, "help-help", 0},
+       {indent, "indent-current-line", 0},
+       {insert, "insert", 1},
+       {bufferinsert, "insert-buffer", 1},
+       {fileinsert, "insert-file", 1},
+       {fillword, "insert-with-wrap", 1},            /* startup only */
+       {backisearch, "isearch-backward", 1},
+       {forwisearch, "isearch-forward", 1},
+       {joinline, "join-line", 0},
+       {justone, "just-one-space", 0},
+       {ctrlg, "keyboard-quit", 0},
+       {killbuffer_cmd, "kill-buffer", 1},
+       {killline, "kill-line", 0},
+       {killpara, "kill-paragraph", 0},
+       {killregion, "kill-region", 0},
+       {delfword, "kill-word", 0},
+       {toggleleavetmp, "leave-tmpdir-backups", 0},
+       {linenotoggle, "line-number-mode", 0},
+       {listbuffers, "list-buffers", 0},
+       {evalfile, "load", 1},
+       {localbind, "local-set-key", 1},
+       {localunbind, "local-unset-key", 1},
+       {makebkfile, "make-backup-files", 0},
+       {makedir, "make-directory", 1},
+       {markpara, "mark-paragraph", 0},
+       {markbuffer, "mark-whole-buffer", 0},
+       {do_meta, "meta-key-mode", 0},        /* better name, anyone? */
+       {negative_argument, "negative-argument", 1},
+       {enewline, "newline", 0},
+       {lfindent, "newline-and-indent", 0},
+       {forwline, "next-line", 0},
 #ifdef NOTAB
-       {notabmode, "no-tab-mode",},
+       {notabmode, "no-tab-mode", 0},
 #endif /* NOTAB */
-       {notmodified, "not-modified",},
-       {openline, "open-line",},
-       {nextwind, "other-window",},
-       {overwrite_mode, "overwrite-mode",},
-       {poptag, "pop-tag-mark",},
-       {prefixregion, "prefix-region",},
-       {backline, "previous-line",},
-       {prevwind, "previous-window",},
-       {spawncli, "push-shell",},
-       {showcwdir, "pwd",},
-       {queryrepl, "query-replace",},
+       {notmodified, "not-modified", 0},
+       {openline, "open-line", 0},
+       {nextwind, "other-window", 0},
+       {overwrite_mode, "overwrite-mode", 0},
+       {poptag, "pop-tag-mark", 0},
+       {prefixregion, "prefix-region", 0},
+       {backline, "previous-line", 0},
+       {prevwind, "previous-window", 0},
+       {spawncli, "push-shell", 0},
+       {showcwdir, "pwd", 0},
+       {queryrepl, "query-replace", 1},
 #ifdef REGEX
-       {re_queryrepl, "query-replace-regexp",},
+       {re_queryrepl, "query-replace-regexp", 1},
 #endif /* REGEX */
-       {quote, "quoted-insert",},
+       {quote, "quoted-insert", 1},
 #ifdef REGEX
-       {re_searchagain, "re-search-again",},
-       {re_backsearch, "re-search-backward",},
-       {re_forwsearch, "re-search-forward",},
+       {re_searchagain, "re-search-again", 0},
+       {re_backsearch, "re-search-backward", 0},
+       {re_forwsearch, "re-search-forward", 0},
 #endif /* REGEX */
-       {reposition, "recenter",},
-       {redraw, "redraw-display",},
+       {reposition, "recenter", 0},
+       {redraw, "redraw-display", 0},
 #ifdef REGEX
-       {replstr, "replace-string",},
+       {replstr, "replace-string", 2},
 #endif /* REGEX */
-       {revertbuffer, "revert-buffer",},
-       {filesave, "save-buffer",},
-       {quit, "save-buffers-kill-emacs",},
-       {savebuffers, "save-some-buffers",},
-       {backpage, "scroll-down",},
-       {back1page, "scroll-one-line-down",},
-       {forw1page, "scroll-one-line-up",},
-       {pagenext, "scroll-other-window",},
-       {forwpage, "scroll-up",},
-       {searchagain, "search-again",},
-       {backsearch, "search-backward",},
-       {forwsearch, "search-forward",},
-       {ask_selfinsert, "self-insert-char",},
-       {selfinsert, "self-insert-command",},
-       {sentencespace, "sentence-end-double-space",},
+       {revertbuffer, "revert-buffer", 0},
+       {filesave, "save-buffer", 0},
+       {quit, "save-buffers-kill-emacs", 0},
+       {savebuffers, "save-some-buffers", 0},
+       {backpage, "scroll-down", 0},
+       {back1page, "scroll-one-line-down", 0},
+       {forw1page, "scroll-one-line-up", 0},
+       {pagenext, "scroll-other-window", 0},
+       {forwpage, "scroll-up", 0},
+       {searchagain, "search-again", 0},
+       {backsearch, "search-backward", 0},
+       {forwsearch, "search-forward", 0},
+       {ask_selfinsert, "self-insert-char", 1},
+       {selfinsert, "self-insert-command", 1},               /* startup only */
+       {sentencespace, "sentence-end-double-space", 0},
 #ifdef REGEX
-       {setcasefold, "set-case-fold-search",},
+       {setcasefold, "set-case-fold-search", 0},
 #endif /* REGEX */
-       {setcasereplace, "set-case-replace",},
-       {set_default_mode, "set-default-mode",},
-       {setfillcol, "set-fill-column",},
-       {setmark, "set-mark-command",},
-       {setprefix, "set-prefix-string",},
-       {shellcommand, "shell-command",},
-       {piperegion, "shell-command-on-region",},
-       {shrinkwind, "shrink-window",},
+       {setcasereplace, "set-case-replace", 0},
+       {set_default_mode, "set-default-mode", 1},
+       {setfillcol, "set-fill-column", 1},
+       {setmark, "set-mark-command", 0},
+       {setprefix, "set-prefix-string", 1},
+       {shellcommand, "shell-command", 1},
+       {piperegion, "shell-command-on-region", 0},
+       {shrinkwind, "shrink-window", 0},
 #ifdef NOTAB
-       {space_to_tabstop, "space-to-tabstop",},
+       {space_to_tabstop, "space-to-tabstop", 0},
 #endif /* NOTAB */
-       {splitwind, "split-window-vertically",},
-       {definemacro, "start-kbd-macro",},
-       {spawncli, "suspend-emacs",},
-       {usebuffer, "switch-to-buffer",},
-       {poptobuffer, "switch-to-buffer-other-window",},
-       {togglereadonly, "toggle-read-only" },
-       {togglereadonlyall, "toggle-read-only-all" },
-       {twiddle, "transpose-chars",},
-       {transposepara, "transpose-paragraphs",},
-       {transposeword, "transpose-words",},
-       {undo, "undo",},
-       {undo_add_boundary, "undo-boundary",},
-       {undo_boundary_enable, "undo-boundary-toggle",},
-       {undo_enable, "undo-enable",},
-       {undo_dump, "undo-list",},
-       {universal_argument, "universal-argument",},
-       {upperregion, "upcase-region",},
-       {upperword, "upcase-word",},
-       {togglevisiblebell, "visible-bell",},
-       {tagsvisit, "visit-tags-table",},
-       {showcpos, "what-cursor-position",},
-       {filewrite, "write-file",},
-       {yank, "yank",},
-       {NULL, NULL,}
+       {splitwind, "split-window-vertically", 0},
+       {definemacro, "start-kbd-macro", 0},
+       {spawncli, "suspend-emacs", 0},
+       {usebuffer, "switch-to-buffer", 1},
+       {poptobuffer, "switch-to-buffer-other-window", 1},
+       {togglereadonly, "toggle-read-only", 0},
+       {togglereadonlyall, "toggle-read-only-all", 0},
+       {twiddle, "transpose-chars", 0},
+       {transposepara, "transpose-paragraphs", 0},
+       {transposeword, "transpose-words", 0},
+       {undo, "undo", 0},
+       {undo_add_boundary, "undo-boundary", 0},
+       {undo_boundary_enable, "undo-boundary-toggle", 0},
+       {undo_enable, "undo-enable", 0},
+       {undo_dump, "undo-list", 0},
+       {universal_argument, "universal-argument", 1},
+       {upperregion, "upcase-region", 0},
+       {upperword, "upcase-word", 0},
+       {togglevisiblebell, "visible-bell", 0},
+       {tagsvisit, "visit-tags-table", 0},
+       {showcpos, "what-cursor-position", 0},
+       {filewrite, "write-file", 1},
+       {yank, "yank", 0},
+       {NULL, NULL, 0}
 };

 void
@@ -234,7 +249,7 @@ funmap_init(void)
 }

 int
-funmap_add(PF fun, const char *fname)
+funmap_add(PF fun, const char *fname, int fparams)
 {
        struct funmap *fn;

@@ -243,6 +258,7 @@ funmap_add(PF fun, const char *fname)

        fn->fn_funct = fun;
        fn->fn_name = fname;
+       fn->fn_nparams = fparams;
        fn->fn_next = funs;

        funs = fn;
@@ -300,4 +316,19 @@ complete_function_list(const char *fname
                }
        }
        return (head);
+}
+
+/*
+ * Find number of parameters for function name.
+ */
+int
+numparams_function(PF fun)
+{
+       struct funmap *fn;
+
+       for (fn = funs; fn != NULL; fn = fn->fn_next) {
+               if (fn->fn_funct == fun)
+                       return (fn->fn_nparams);
+       }
+       return (FALSE);
 }
Index: funmap.h
===================================================================
RCS file: /cvs/src/usr.bin/mg/funmap.h,v
retrieving revision 1.7
diff -u -p -u -p -r1.7 funmap.h
--- funmap.h    10 Jun 2008 00:19:31 -0000      1.7
+++ funmap.h    9 Jul 2019 16:54:49 -0000
@@ -6,4 +6,5 @@ void             funmap_init(void);
 PF              name_function(const char *);
 const char     *function_name(PF);
 struct list    *complete_function_list(const char *);
-int             funmap_add(PF, const char *);
+int             funmap_add(PF, const char *, int);
+int             numparams_function(PF);
Index: grep.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/grep.c,v
retrieving revision 1.47
diff -u -p -u -p -r1.47 grep.c
--- grep.c      30 Dec 2018 23:09:58 -0000      1.47
+++ grep.c      9 Jul 2019 16:54:49 -0000
@@ -53,11 +53,11 @@ static struct KEYMAPE (1) compilemap = {
 void
 grep_init(void)
 {
-       funmap_add(compile_goto_error, "compile-goto-error");
-       funmap_add(next_error, "next-error");
-       funmap_add(grep, "grep");
-       funmap_add(compile, "compile");
-       funmap_add(gid, "gid");
+       funmap_add(compile_goto_error, "compile-goto-error", 0);
+       funmap_add(next_error, "next-error", 0);
+       funmap_add(grep, "grep", 1);
+       funmap_add(compile, "compile", 0);
+       funmap_add(gid, "gid", 1);
        maps_add((KEYMAP *)&compilemap, "compile");
 }


Reply via email to