"Fossies" - the Fresh Open Source Software Archive

Member "jed-0.99-19/lib/mini.sl" (14 Dec 2009, 4675 Bytes) of package /linux/misc/jed-0.99-19.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 %
    2 %  Recall previous commands in MiniBuffer
    3 %
    4 
    5 % If -2, never store duplicates, use Least-Recently-Used strategy
    6 % If -1, store only if not equal to last entered value
    7 % If 0, never store duplicates
    8 custom_variable ("Mini_Store_Duplicates", 1);
    9 
   10 private variable Max_Num_Lines = 32;
   11 
   12 private variable Mini_Previous_Lines;
   13 private variable Mini_Last_Line;
   14 private variable Mini_First_Line;
   15 private variable Mini_Next_Line;
   16 
   17 private define initialize ()
   18 {
   19    Mini_Previous_Lines =  String_Type [Max_Num_Lines];
   20    Mini_Last_Line = 0;
   21    Mini_First_Line = 0;
   22    Mini_Next_Line = 0;
   23 
   24    Mini_Previous_Lines[[:]] = "";
   25 }
   26 
   27 initialize ();
   28 
   29 private define mini_use_this_line ()
   30 {
   31    erase_buffer ();
   32    insert (Mini_Previous_Lines[Mini_Next_Line]);
   33 }
   34 
   35 
   36 define next_mini_command ()
   37 {
   38    variable line;
   39 
   40    if (Mini_Next_Line == Mini_Last_Line) 
   41      error ("End of list!");
   42 
   43    Mini_Next_Line++;
   44    % if (Mini_Next_Line == Max_Num_Lines)  Mini_Next_Line = 0;
   45    Mini_Next_Line = Mini_Next_Line mod Max_Num_Lines;
   46    mini_use_this_line ();
   47 }
   48 
   49 define prev_mini_command ()
   50 {
   51    variable line;
   52 
   53    line = Mini_Next_Line;
   54    if (line == Mini_Last_Line)
   55      Mini_Previous_Lines [line] = line_as_string ();
   56 
   57    if (Mini_First_Line == Mini_Next_Line)
   58      error ("Top of list!");
   59 
   60    Mini_Next_Line = (Mini_Next_Line + Max_Num_Lines - 1) mod Max_Num_Lines;
   61    mini_use_this_line ();
   62 }
   63 
   64 private define store_line (s)
   65 {
   66    if ((s == NULL) or (s == ""))
   67      return;
   68 
   69    Mini_Previous_Lines[Mini_Last_Line] = s;
   70    Mini_Last_Line++;
   71    Mini_Last_Line = Mini_Last_Line mod Max_Num_Lines;
   72    if (Mini_Last_Line == Mini_First_Line)
   73      {
   74     Mini_First_Line++;
   75     Mini_First_Line = Mini_First_Line mod Max_Num_Lines;
   76      }
   77    Mini_Next_Line = Mini_Last_Line;
   78    Mini_Previous_Lines [Mini_Last_Line] = "";
   79 }
   80 
   81 public define mini_exit_minibuffer ()
   82 {
   83    Mini_Next_Line = Mini_Last_Line;
   84 
   85    bol_skip_white ();
   86    !if (eolp ())
   87      {
   88     variable line = line_as_string ();
   89 
   90     switch (Mini_Store_Duplicates)
   91       {
   92        case 0:             %  never
   93          if (any (line == Mini_Previous_Lines))
   94            line = NULL;
   95       }
   96       {
   97        case -1:            %  sometimes
   98          variable i = (Mini_Next_Line + Max_Num_Lines - 1) mod Max_Num_Lines;
   99          if (Mini_Previous_Lines[i] == line)
  100            line = NULL;
  101       }
  102       {
  103        case -2:            %  never, use LRU
  104              variable il, delta, la = Mini_Last_Line;
  105              if (la < Mini_First_Line) la = la + Max_Num_Lines;
  106              delta = 0;
  107              il = Mini_First_Line;
  108              while (il < la)
  109            {
  110           if (Mini_Previous_Lines[il mod Max_Num_Lines] == line) delta++;
  111           if (delta)
  112             {
  113                if ((il + delta) > la) 
  114              break;
  115                Mini_Previous_Lines[il mod Max_Num_Lines] = Mini_Previous_Lines[(il + delta) mod Max_Num_Lines];
  116             }
  117           il++;
  118            }
  119              if (delta)
  120            {
  121           Mini_Last_Line = (Mini_Last_Line + Max_Num_Lines - delta) mod Max_Num_Lines;
  122           Mini_Next_Line = Mini_Last_Line;
  123            }
  124       }
  125     store_line (line);
  126      }
  127    call ("exit_mini");
  128 }
  129 
  130 
  131 public define mini_store_lines (lines)
  132 {
  133    foreach (lines)
  134      store_line ();
  135 }
  136 
  137 public define mini_set_lines (lines)
  138 {
  139    initialize ();
  140    mini_store_lines (lines);
  141 }
  142 
  143 
  144 
  145 public define mini_get_lines (num_p)
  146 {
  147    variable n = Mini_Last_Line - Mini_First_Line;
  148 
  149    if (num_p != NULL)
  150      @num_p = Max_Num_Lines;
  151 
  152    if (n < 0)
  153      n += (Max_Num_Lines+1);
  154    
  155    variable lines = String_Type [n];
  156    
  157    n = Mini_Last_Line - Mini_First_Line;
  158    if (n < 0)
  159      {
  160     n = Max_Num_Lines - Mini_First_Line;
  161     lines[[0:n-1]] = Mini_Previous_Lines[[Mini_First_Line:]];
  162     lines[[n:]] = Mini_Previous_Lines[[0:Mini_Last_Line]];
  163     return lines;
  164      }
  165    
  166    return Mini_Previous_Lines[[0:n-1]];
  167 }
  168 
  169 % This function is called from site.sl AFTER jed.rc has been read but
  170 % before other command line arguments have been parsed.
  171 public define mini_init_minibuffer ()
  172 {   
  173    variable mini = "Mini_Map";
  174    !if (keymap_p (mini))
  175      make_keymap (mini);
  176 
  177 #ifdef IBMPC_SYSTEM
  178    definekey ("next_mini_command", "\eOr", mini);
  179    definekey ("next_mini_command", "\xE0P", mini);
  180    definekey ("prev_mini_command", "\xE0H", mini);
  181    definekey ("prev_mini_command", "\eOx", mini);
  182 #else
  183    definekey ("next_mini_command", "\e[B", mini);
  184    definekey ("prev_mini_command", "\e[A", mini);
  185    definekey ("next_mini_command", "\eOB", mini);
  186    definekey ("prev_mini_command", "\eOA", mini);
  187 #endif
  188    definekey ("mini_exit_minibuffer", "\r", mini);
  189    
  190    definekey ("exit_mini", "\e\r", mini);
  191    definekey ("mini_complete", "\t", mini);
  192    definekey ("mini_complete", " ", mini);
  193 
  194    % Now that we are initialized, remove this function
  195    eval (".() mini_init_minibuffer");
  196 }
  197 
  198    
  199