home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / SLRN0931 / DOC / SLRN.SL < prev    next >
Text File  |  1997-02-23  |  6KB  |  278 lines

  1. %  This file presents some simple examples of extending the newsreader.  
  2. %  See README.slang for a more complete discussion of the functions involved.
  3.  
  4. message ("reading ~/.slrn.sl file.");
  5.  
  6. % Some key macros
  7. % I like the refresh groups command to always return to the beginning of
  8. % the group buffer
  9.  
  10. define refresh_groups_bob ()
  11. {
  12.    call ("refresh_groups");
  13.    call ("bob");
  14. }
  15. definekey ("refresh_groups_bob", "G", "group");
  16.  
  17.  
  18. define article_mode_hook ()
  19. {
  20.    variable sorting_method = 7;
  21.    variable author_display = 2;
  22.    
  23.    if (is_substr (current_newsgroup (), "binaries")
  24.        or is_substr (current_newsgroup (), "pictures"))
  25.      {
  26.     sorting_method = 3;
  27.     author_display = 0;
  28.      }
  29.    
  30.    set_integer_variable ("sorting_method", sorting_method);
  31.    set_integer_variable ("author_display", author_display);
  32. }
  33.  
  34. define startup_hook ()
  35. {
  36.    !if (strcmp (server_name (), "uhog"))
  37.      {
  38.     set_integer_variable ("lines_per_update", 20);
  39.     set_integer_variable ("read_active", 0);
  40.      }
  41. }
  42.  
  43. % This function pipes the currently selected article to my paging program
  44. define pipe_to_most ()
  45. {
  46.    pipe_article ("most");
  47. }
  48. definekey ("pipe_to_most", "&", "article");
  49.  
  50. %
  51. %  Here are some article searching functions
  52. %
  53.  
  54. variable Last_Art_Search_Str = "";
  55. define search_newsgroup ()
  56. {
  57.    variable str;
  58.    variable flags;
  59.    
  60.    str = read_mini ("Search for regexp: ", Last_Art_Search_Str, "");
  61.    !if (strlen (str))
  62.      return;
  63.  
  64.    Last_Art_Search_Str = str;
  65.    
  66.    uncollapse_threads ();
  67.    
  68.    do
  69.      {
  70.     flags = get_header_flags ();
  71.     
  72.     if (re_search_article (str))
  73.       {
  74.          pop ();
  75.          return;
  76.       }
  77.     
  78.     set_header_flags (flags);
  79.     
  80.     call ("hide_article");
  81.     update ();
  82.      }
  83.    while (header_down (1));
  84.    
  85.    error ("Not found.");
  86. }
  87.  
  88.  
  89. define re_search_article_cmd ()
  90. {
  91.    variable str = read_mini ("Re-search: ", Last_Art_Search_Str, "");
  92.    !if (strlen (str))
  93.      return;
  94.    
  95.    Last_Art_Search_Str = str;
  96.    
  97.    if (re_search_article (str))
  98.      {
  99.     pop ();                   %  line matched on stack
  100.     return;
  101.      }
  102.    
  103.    error ("Not found.");
  104. }
  105.  
  106. definekey ("re_search_article_cmd", "/", "article");
  107.  
  108. % This function prompts for a search string and then calls Digital's
  109. % AltaVista search engine.
  110. define altavista_search ()
  111. {
  112.    variable browser = "lynx";
  113.    variable url = "http://www.altavista.digital.com/";
  114.    variable cgi = "cgi-bin/query?pg=q&what=news&fmt=.&q=";
  115.    variable str, new_str, len, ch, chlo, i;
  116.    variable cmd;
  117.    
  118.    str = strcat ("+newsgroups:", current_newsgroup ());
  119.    str = strcat (str, " +");
  120.    
  121.    str = read_mini ("AltaVista Search", "", str);
  122.    
  123.    len = strlen (str);
  124.    !if (len) return;
  125.    
  126.    new_str = "";
  127.    for (i = 0; i < len; i++)
  128.      {
  129.     ch = str [i];
  130.     chlo = ch | 0x20;
  131.     if ((chlo > 'z') or (chlo < 'a'))
  132.       ch = Sprintf ("%%%02X", ch, 1);
  133.     else 
  134.       ch = char (ch);
  135.     
  136.     new_str = strcat (new_str, ch);
  137.      }
  138.    
  139.    cmd = Sprintf ("%s '%s%s%s'", browser, url, cgi, new_str, 4);
  140.    () = system (cmd);
  141. }
  142.  
  143.  
  144. % This function pops up a selection box
  145. %
  146. define easy_search ()
  147. {
  148.    variable rsp;
  149.    rsp = get_select_box_response ("NewsGroup Searches",   %  title
  150.                   "AltaVista (WWW)",
  151.                   "search articles",
  152.                   2);
  153.  
  154.    switch (rsp)
  155.      { case 0: altavista_search (); }
  156.      { case 1: search_newsgroup (); }
  157. }
  158.  
  159. definekey ("easy_search", "$", "article");
  160.  
  161.  
  162. % This will allow me to execute S-Lang commands from within slrn.
  163. define execute_slang ()
  164. {
  165.    variable str;
  166.    
  167.    str = read_mini ("S-Lang> ",  "", "");
  168.    !if (strlen (str))
  169.      return;
  170.    
  171.    eval (str);
  172. }
  173.  
  174. definekey ("execute_slang", "^Kd", "group");
  175. definekey ("execute_slang", "^Kd", "article");
  176.  
  177.  
  178. % These functions may facilitate nn style reading
  179.  
  180. define tag_header ()
  181. {
  182.    set_header_flags (get_header_flags () | HEADER_TAGGED);
  183. }
  184.  
  185. define untag_header ()
  186. {
  187.    set_header_flags (get_header_flags () & ~(HEADER_TAGGED));
  188. }
  189.  
  190. define header_number_hook ()
  191. {
  192.    tag_header ();
  193. }
  194.  
  195.  
  196. define nn_like_function ()
  197. {
  198.    call ("catchup_all");
  199.    set_prefix_argument (1);
  200.    call ("toggle_header_tag");           % If used with prefix, it untags all  
  201.    call ("art_xpunge");               % remove read articles
  202.    call ("art_header_bob");           % goto top of list
  203.    call ("scroll_dn");               % read article
  204. }
  205.  
  206. definekey ("nn_like_function", "+", "article");
  207.  
  208. define read_prev_tagged ()
  209. {
  210.    !if (prev_tagged_header ())
  211.      error ("No more tagged headers.");
  212.    
  213.    untag_header ();
  214.    call ("scroll_dn");
  215. }
  216.  
  217. define read_next_tagged ()
  218. {
  219.    !if (next_tagged_header ())
  220.      error ("No more tagged headers.");
  221.    
  222.    untag_header ();
  223.    call ("scroll_dn");
  224. }
  225.  
  226.    
  227. definekey ("read_next_tagged", "]", "article");
  228. definekey ("read_prev_tagged", "[", "article");
  229.  
  230.  
  231. variable Last_Search_Str = "";
  232. define re_subject_search_forward ()
  233. {
  234.    variable str;
  235.    
  236.    !if (header_down (1))
  237.      return;
  238.    
  239.    str = read_mini ("Subject re-search fwd: ", Last_Search_Str, "");
  240.    
  241.    !if (strlen (str))
  242.      return;
  243.    
  244.    !if (re_fsearch_subject (str))
  245.      error ("Not found.");
  246. }
  247.  
  248. definekey ("re_subject_search_forward", "s", "article");   
  249.  
  250. define tag_via_subject_regexp ()
  251. {
  252.    variable str;
  253.    variable count = 0;
  254.    
  255.    str = read_mini ("Tag subjects pattern", "", "");
  256.    !if (strlen (str))
  257.      return;
  258.  
  259.    call ("mark_spot");
  260.    
  261.    uncollapse_threads ();
  262.    while (re_fsearch_subject (str))
  263.      {
  264.     tag_header ();
  265.     count++;
  266.     !if (header_down (1))
  267.       break;
  268.      }
  269.    collapse_threads ();
  270.  
  271.    call ("exchange_mark");
  272.    message (Sprintf ("%d headers marked.", count, 1));
  273. }
  274.  
  275. definekey ("tag_via_subject_regexp", "%", "article");
  276.  
  277.