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

  1. % Mode for indenting slrn score files
  2.  
  3. % To use this, add the following line to your .jedrc file:
  4. %    autoload ("score_mode", "score");
  5.  
  6. % Mode for indenting slrn score files
  7.  
  8. % To use this, add the following line to your .jedrc file:
  9. %    autoload ("score_mode", "score");
  10.  
  11. % Align the ':' characters in the same column
  12. define score_indent_line ()
  13. {
  14.    variable col, colon;
  15.    push_spot ();
  16.    bol_skip_white ();
  17.  
  18.    EXIT_BLOCK {
  19.       pop_spot ();
  20.       if (bolp ()) skip_white ();
  21.    }
  22.  
  23.    col = what_column ();
  24.    if (looking_at_char ('[') or looking_at_char ('%')) col = 1;
  25.    else if (eolp ())
  26.      {
  27.     push_spot ();
  28.     bskip_chars ("\n\t ");
  29.     bol_skip_white ();
  30.     col = what_column ();
  31.     pop_spot ();
  32.      }
  33.    else if (ffind_char (':'))
  34.      {
  35.     colon = what_column ();
  36.     if (blooking_at ("Score")) colon -= 10; else colon -= 18;
  37.     !if (colon) return;
  38.     col -= colon;
  39.      }
  40.    else
  41.      return;
  42.  
  43.    if (what_column () != col)
  44.      {
  45.     bol ();
  46.     trim ();
  47.     col--;
  48.     whitespace (col);
  49.      }
  50. }
  51.  
  52. $1 = "score";
  53. create_syntax_table ($1);
  54.  
  55. define_syntax ("%", "", '%', $1);
  56. define_syntax ("([{", ")]}", '(', $1);
  57. define_syntax ('\\', '\\', $1);
  58. define_syntax ("-a-zA-Z:", 'w', $1);    % words
  59. define_syntax ("-0-9", '0', $1);    % Numbers
  60. define_syntax ('[', '#', $1);
  61.  
  62. () = define_keywords ($1, "From:Xref:", 5);
  63. () = define_keywords ($1, "Lines:Score:", 6);
  64. () = define_keywords ($1, "Score::", 7);
  65. () = define_keywords ($1, "Expires:Subject:", 8);
  66. () = define_keywords ($1, "Newsgroup:", 10);
  67. () = define_keywords ($1, "Message-Id:References:", 11);
  68.  
  69. define score_mode ()
  70. {
  71.    variable score = "score";
  72.    set_mode (score, 0);
  73.    use_syntax_table (score);
  74.    set_buffer_hook ("indent_hook", "score_indent_line");
  75.    runhooks ("score_mode_hook");
  76.    % called after the hook to give a chance to load the abbrev table
  77.    if (abbrev_table_p (score)) use_abbrev_table (score);
  78. }
  79.  
  80. % This function may be called by jed when starting newsreader
  81.  
  82. define score_arrange_score ()
  83. {
  84.    % See if this is a score file
  85.    variable mode;
  86.    variable group;
  87.    variable score;
  88.    variable group_re = "^[ \t]*\\(\\[.*\\]\\)";
  89.      
  90.    (mode, ) = what_mode ();
  91.    if (strcmp(mode, "score")) return;
  92.    
  93.    push_spot ();
  94.    EXIT_BLOCK 
  95.      {
  96.     pop_spot ();
  97.      }
  98.    
  99.    % Find name of group for the score
  100.    !if (re_fsearch (group_re)) return;
  101.    group = regexp_nth_match (1);
  102.  
  103.    % indent the region
  104.    push_spot ();
  105.    do 
  106.      {
  107.     score_indent_line ();
  108.     eol ();
  109.     trim ();
  110.      }
  111.    while (down(1));
  112.    pop_spot ();
  113.    
  114.    !if (bol_bsearch (group)) return;
  115.    
  116.    push_mark ();
  117.    pop_spot ();
  118.    bol ();
  119.    push_mark ();
  120.    push_mark ();
  121.    eob ();
  122.    score = bufsubstr ();
  123.    del_region ();
  124.    
  125.    pop_mark_1 ();
  126.    eol ();
  127.    !if (re_fsearch (group_re)) eob ();
  128.    insert (score);
  129.    if (re_bsearch (group_re)) delete_line ();
  130.    push_spot ();
  131.    return;
  132. }
  133.    
  134.