home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume4 / uemacs / part2 / extend.c < prev    next >
C/C++ Source or Header  |  1986-11-30  |  3KB  |  138 lines

  1. /*
  2.  * Name:    MicroEMACS
  3.  *        Extended (M-X) commands.
  4.  * Version:    29
  5.  * Last edit:    14-Feb-86
  6.  * By:        rex::conroy
  7.  *        decvax!decwrl!dec-rhea!dec-rex!conroy
  8.  */
  9. #include    "def.h"
  10.  
  11. /*
  12.  * This function modifies the keyboard
  13.  * binding table, by adjusting the entries in the
  14.  * big "bindings" array. Most of the grief deals with the
  15.  * prompting for additional arguments. This code does not
  16.  * work right if there is a keyboard macro floating around.
  17.  * Should be fixed.
  18.  */
  19. bindtokey(f, n, k)
  20. {
  21.     register int    s;
  22.     register char    *cp;
  23.     register SYMBOL    *sp;
  24.     register int    c;
  25.     char        xname[NXNAME];
  26.  
  27.     if (kbdmip!=NULL || kbdmop!=NULL) {
  28.         eprintf("Not now");
  29.         return (FALSE);
  30.     }
  31.     if ((s=eread("Function: ", xname, NXNAME, EFAUTO, NULL)) != TRUE)
  32.         return (s);
  33.     if ((sp=symlookup(xname)) == NULL) {
  34.         eprintf("Unknown function for binding");
  35.         return (FALSE);
  36.     }
  37.     eputc(' ');
  38.     eputc('K');
  39.     eputc('e');
  40.     eputc('y');
  41.     eputc(':');
  42.     eputc(' ');
  43.     ttflush();
  44.     c = getkey();                /* Read key.        */
  45.     keyname(xname, c);            /* Display keyname.    */
  46.     eputs(xname);
  47.     ttflush();
  48.     if (binding[c] != NULL)            /* Unbind old, and    */
  49.         --binding[c]->s_nkey;
  50.     binding[c] = sp;            /* rebind new.        */
  51.     ++sp->s_nkey;
  52.     return (TRUE);
  53. }
  54.  
  55. /*
  56.  * Extended command. Call the message line
  57.  * routine to read in the command name and apply autocompletion
  58.  * to it. When it comes back, look the name up in the symbol table
  59.  * and run the command if it is found and has the right type.
  60.  * Print an error if there is anything wrong.
  61.  */
  62. extend(f, n, k)
  63. {
  64.     register SYMBOL    *sp;
  65.     register int    s;
  66.     char        xname[NXNAME];
  67.  
  68.     if ((s=eread(": ", xname, NXNAME, EFNEW|EFAUTO, NULL)) != TRUE)
  69.         return (s);
  70.     if ((sp=symlookup(xname)) != NULL)
  71.         return ((*sp->s_funcp)(f, n, KRANDOM));
  72.     eprintf("Unknown extended command");
  73.     return (ABORT);
  74. }
  75.  
  76. /*
  77.  * Read a key from the keyboard, and look it
  78.  * up in the binding table. Display the name of the function
  79.  * currently bound to the key. Say that the key is not bound
  80.  * if it is indeed not bound, or if the type is not a
  81.  * "builtin". This is a bit of overkill, because this is the
  82.  * only kind of function there is.
  83.  */
  84. help(f, n, k)
  85. {
  86.     register SYMBOL    *sp;
  87.     register int    c;
  88.     char        b[20];
  89.  
  90.     c = getkey();
  91.     keyname(b, c);
  92.     if ((sp=binding[c]) == NULL)
  93.         eprintf("[%s is unbound]", b);
  94.     else
  95.         eprintf("[%s is bound to %s]", b, sp->s_name);
  96.     return (TRUE);
  97. }
  98.  
  99. /*
  100.  * This function creates a table, listing all
  101.  * of the command keys and their current bindings, and stores
  102.  * the table in the standard pop-op buffer (the one used by the
  103.  * directory list command, the buffer list command, etc.). This
  104.  * lets MicroEMACS produce it's own wall chart. The bindings to
  105.  * "ins-self" are only displayed if there is an argument.
  106.  */
  107. wallchart(f, n, k)
  108. {
  109.     register int    s;
  110.     register int    key;
  111.     register SYMBOL    *sp;
  112.     register char    *cp1;
  113.     register char    *cp2;
  114.     char        buf[64];
  115.  
  116.     if ((s=bclear(blistp)) != TRUE)        /* Clear it out.    */
  117.         return (s);
  118.     (void) strcpy(blistp->b_fname, "");
  119.     for (key=0; key<NKEYS; ++key) {        /* For all keys.    */
  120.         sp = binding[key];
  121.         if (sp != NULL
  122.         && (f!=FALSE || strcmp(sp->s_name, "ins-self")!=0)) {
  123.             keyname(buf, key);
  124.             cp1 = &buf[0];        /* Find end.        */
  125.             while (*cp1 != 0)
  126.                 ++cp1;
  127.             while (cp1 < &buf[16])    /* Goto column 16.    */
  128.                 *cp1++ = ' ';                
  129.             cp2 = sp->s_name;    /* Add function name.    */
  130.             while (*cp1++ = *cp2++)
  131.                 ;
  132.             if (addline(buf) == FALSE)
  133.                 return (FALSE);
  134.         }
  135.     }
  136.     return (popblist());
  137. }
  138.