home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / AP / JED / JED097-1.TAR / jed / lib / help.sl < prev    next >
Encoding:
Text File  |  1994-12-12  |  6.4 KB  |  292 lines

  1. %% help.sl
  2.  
  3. !if (is_defined ("Jed_Doc_File"))
  4. {
  5.    variable Jed_Doc_File = expand_jedlib_file ("jed_funs.hlp");
  6. }
  7.  
  8.  
  9. %% apropos function
  10. define apropos()
  11. {
  12.    variable n, cbuf, s;
  13.    if (MINIBUFFER_ACTIVE) return;
  14.  
  15.    s = read_mini("apropos:", Null_String, Null_String);
  16.    n = slapropos(s);
  17.    cbuf = whatbuf();
  18.    pop2buf("*apropos*");
  19.    erase_buffer();
  20.    loop (n) 
  21.      {
  22.     insert(());
  23.     newline();
  24.      }
  25.    buffer_format_in_columns();   
  26.    bob();
  27.    set_buffer_modified_flag(0);
  28.    pop2buf(cbuf);
  29. }
  30.  
  31. %!% Prototype: String expand_keystring (String key)
  32. %!% This function takes a key string that is suitable for use in a 'setkey'
  33. %!% definition and expands it to a human readable form.  
  34. %!% For example, it expands ^X to the form "Ctrl-X", ^[ to "ESC", 
  35. %!% ^[[A to "UP", etc...
  36. %!% See also: setkey
  37. define expand_keystring (key)
  38. {
  39.    variable n = strlen (key);
  40.    variable str, i = 1, ch, key_string = Null_String, the_key;
  41.    
  42.    while (i <= n)
  43.      {
  44.     ch = key[i - 1];
  45.     ++i;
  46.     switch (ch)
  47.       {
  48.          (case '^' and (i <= n)) or (ch < 32) :   
  49.          % control char
  50.          %% common cases are '^[, ^[[?, ^[O?'
  51.       
  52.          if (ch < 32)
  53.            {
  54.           str = strcat (char (ch + '@'), substr (key, i, 2));
  55.           i--;
  56.            }
  57.          else str = substr (key, i, 3);
  58.          
  59.          if (int(str) == '[')
  60.            {
  61.           i += 3;
  62.           switch (str)
  63.             { case "[[A" : "UP"; }
  64.             { case "[[B" : "DOWN"; }
  65.             { case "[[C" : "RIGHT"; }
  66.             { case "[[D" : "LEFT"; }
  67.             { case "[OP" : "GOLD"; }
  68.             { case "[OA" : "UP"; }
  69.             { case "[OB" : "DOWN"; }
  70.             { case "[OC" : "RIGHT"; }
  71.             { case "[OD" : "LEFT"; }
  72.             { pop(); "ESC"; i -= 2;
  73.             }
  74.            }
  75.          else
  76.            {
  77.           i++;
  78.           strcat ("Ctrl-", char(int(str)));
  79.            }
  80.       }
  81.       {
  82.          char (());
  83.       }
  84.     the_key = ();
  85.     
  86.     if (strlen(key_string)) key_string = strcat(key_string, " ");
  87.     key_string = strcat (key_string, the_key);
  88.      }
  89.    
  90.    key_string;
  91. }
  92.  
  93.  
  94. %% show key
  95. define showkey()
  96. {
  97.    variable f, type, the_type = "internal";
  98.    flush("Show Key: ");
  99.    f = get_key_function();        %% also, type is on stack (if defined)
  100.    !if (strlen(f)) {message("Key is undefined."); return; }
  101.    =type;
  102.    
  103.    !if (type) the_type = "S-Lang";
  104.    
  105.    message (Sprintf ("Key \"%s\" runs %s function %s.",
  106.              expand_keystring(LASTKEY),
  107.              the_type, f, 3));
  108. }
  109.  
  110. . (
  111. .    [n cmd]
  112. .    MINIBUFFER_ACTIVE {return} if
  113. .    "Where is command:" Null_String Null_String 'F' read_with_completion =cmd
  114. .    cmd strlen { return } !if
  115. .    cmd which_key =n
  116. .    n {"Not on any keys." message return} !if
  117. .    expand_keystring message
  118. .    --n
  119. .    n { pop } loop
  120. . ) where_is
  121.  
  122. %%
  123. %%  This next functions requires a doc file to be produced.  This is made
  124. %%  by running the executable mkdoc which comes with the distribution.
  125. %%
  126. %%  to produce it. It should be placed in JED_LIBRARY.
  127. %%
  128.  
  129. define help_cleanup ()
  130. {
  131.    bob ();
  132.    while (down (1))
  133.      {
  134.     skip_white ();
  135.     if (looking_at ("%!%")) deln (3);
  136.      }
  137.    bob ();
  138.    set_buffer_modified_flag (0);
  139.    set_readonly (1);
  140. }
  141.  
  142. %% gets help for a function
  143. . (
  144. .   [f] =f
  145. .   [cbuf] whatbuf =cbuf
  146. .   [flen tmp help full_f cbuf]  " *jed-help*" =tmp 
  147.  
  148. .   f strlen =flen
  149. .   "*function-help*" =help  
  150. .   [p n]
  151.   
  152. .   Jed_Doc_File strlen  { "Unable to read Jed_Doc_File!" error} !if
  153.  
  154. .   f is_defined 
  155. .     { f 1 }
  156. .     { f slapropos }
  157. .    else
  158. .    =n
  159. .   n 1 > {"Building list..." flush} if
  160. .   help pop2buf 0 set_readonly erase_buffer
  161.   
  162. .   n {
  163. .       =full_f
  164. .       f full_f flen strncmp %%flen and 
  165. .       {continue} if
  166.   
  167. .       full_f is_defined 1 < {continue} if
  168. .       "F" full_f strcat Jed_Doc_File get_doc_string 
  169. .         {  
  170. .        push_spot
  171. .        insert  %% help string
  172. .        pop_spot
  173. .        ":" ffind  %% function:cfun:T:n  where T is type and n is number of args
  174. .          {
  175. .            1 right pop "\tC function: " insert
  176. .            POINT =p ":" ffind {"Corrupt doc file?" error} !if
  177. .            push_spot 1 right pop 
  178. .            what_char
  179. .              { 'V' == : "void "}   % V
  180. .          { 'S' == : "string "} % S
  181. .          { pop "int "}            % I default
  182. .            switch p =POINT insert pop_spot
  183.        
  184. .                del del del  % :T: deleted
  185. .            " (" insert eol trim " args)" insert
  186. .          } if
  187. .     } { full_f insert} 
  188. .       else
  189. .       eob newline 50 {'-' insert_char} loop newline
  190. .     } loop
  191.       
  192. .   n 1 > {"Building list...done." flush} if
  193. .   help_cleanup
  194. .   cbuf pop2buf  
  195. . ) help_for_function
  196.  
  197. . (  
  198. .   MINIBUFFER_ACTIVE {return} if
  199. .   "Describe Function:" Null_String Null_String read_mini help_for_function
  200. . ) describe_function
  201.  
  202.  
  203. . (
  204. .   [tmp help f full_f cbuf]  " *jed-help*" =tmp 
  205. .   "*function-help*" =help  
  206. .   whatbuf =cbuf
  207. .   [p flen n]
  208.  
  209. .   MINIBUFFER_ACTIVE {return} if
  210. .   "Describe Variable:" Null_String Null_String read_mini =f
  211. .   f strlen =flen %%flen {return} !if
  212.   
  213. .   Jed_Doc_File strlen  { "Unable to read Jed_Doc_File!" error} !if
  214.   
  215. .   f slapropos =n
  216. .   n 1 > {"Building list..." flush} if
  217. .   help pop2buf 0 set_readonly erase_buffer
  218.   
  219. .   n {
  220. .       =full_f
  221. .       f full_f flen strncmp %%flen and 
  222. .       {continue} if
  223.   
  224. .       full_f is_defined -1 > {continue} if
  225. .       "V" full_f strcat " " strcat Jed_Doc_File get_doc_string
  226. .         {  
  227. .        push_spot
  228. .        insert  %% help string
  229. .        pop_spot
  230. .     } { full_f insert} 
  231. .       else
  232.        
  233. .       eol trim "\tvalue: " insert full_f eval string insert
  234.       
  235. .       eob newline 50 {'-' insert_char} loop newline
  236. .     } loop
  237.     
  238.     
  239. .   newline
  240. .   help_cleanup
  241. .   cbuf pop2buf
  242. . ) describe_variable
  243.  
  244.  
  245. . (
  246. .   [flags modstr]
  247. .   whatmode =flags =modstr
  248. .   modstr {strlen not : "no_mode" =modstr}
  249. .          {is_defined not : 
  250. .             modstr strlow =modstr
  251. .         modstr is_defined
  252. .          {
  253. .            modstr "_mode" strcat =modstr
  254. .          } !if
  255. .       }
  256. .        switch 
  257. .   modstr is_defined 
  258. .    {
  259. .      flags  { 1 == :  "text_mode" }
  260. .             { 2 & :  "c_mode" }
  261. .             { pop "no_mode" =modstr} 
  262. .      switch
  263. .    } !if
  264.    
  265. .   modstr help_for_function
  266. . ) describe_mode
  267.  
  268.  
  269. define describe_bindings ()
  270. {
  271.    flush("Building bindings..");
  272.    variable map = what_keymap ();
  273.    variable buf = whatbuf ();
  274.    variable cse = CASE_SEARCH;  CASE_SEARCH = 1;
  275.    pop2buf("*KeyBindings*");
  276.    erase_buffer ();
  277.    dump_bindings (map);
  278.    bob(); replace ("ESC [ A", "UP");
  279.    bob(); replace ("ESC [ B", "DOWN");
  280.    bob(); replace ("ESC [ C", "RIGHT");
  281.    bob(); replace ("ESC [ D", "LEFT");
  282.    bob(); replace ("ESC O P", "GOLD");
  283.    bob();
  284.    CASE_SEARCH = cse;
  285.    set_buffer_modified_flag(0);
  286.    pop2buf (buf);
  287.    message ("done");
  288. }
  289.  
  290.         
  291.    
  292.