jed-users mailing list

[2005 Date Index] [2005 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Minibuffer LRU


Hi.

I modified mini.sl to use the Least-Recently-Used strategy
when Mini_Store_Duplicates is -2.

When you have a list of recent minibuffer values

   aaa
   bbb
   ccc

and you enter 'aaa' in the minibuffer, the list changes to

   bbb
   ccc
   aaa

and the next time the value 'aaa' is available with one keypress.
Also all duplicate 'aaa' values are removed from the list.

This is useful when you do not want duplicates in the minibuffer history,
but you need to use the same value many times in a row.

The patch is attached.

Marko
--- /cygdrive/s/jed/jed-B0.99-17.95/lib/mini.sl	2005-04-18 19:02:30.000000000 +0200
+++ /cygdrive/s/localcvs/fljed/jed/lib/mini.sl	2005-07-29 11:38:06.015625000 +0200
@@ -2,6 +2,7 @@
 %  Recall previous commands in MiniBuffer
 %
 
+% If -2, never store duplicates, use Least-Recently-Used strategy
 % If -1, store only if not equal to last entered value
 % If 0, never store duplicates
 custom_variable ("Mini_Store_Duplicates", 1);
@@ -98,6 +99,29 @@
 	     if (Mini_Previous_Lines[i] == line)
 	       line = NULL;
 	  }
+	  {
+	   case -2:		       %  never, use LRU
+             variable il, delta, la = Mini_Last_Line;
+             if (la < Mini_First_Line) la = la + Max_Num_Lines;
+             delta = 0;
+             il = Mini_First_Line;
+             while (il < la)
+             {
+                if (Mini_Previous_Lines[il mod Max_Num_Lines] == line) delta++;
+                if (delta)
+                {
+                   if ((il + delta) > la) break;
+                   else
+                      Mini_Previous_Lines[il mod Max_Num_Lines] = Mini_Previous_Lines[(il + delta) mod Max_Num_Lines];
+                }
+                il++;
+             }
+             if (delta)
+             {
+                Mini_Last_Line = (Mini_Last_Line + Max_Num_Lines - delta) mod Max_Num_Lines;
+                Mini_Next_Line = Mini_Last_Line;
+             }
+	  }
 	store_line (line);
      }
    call ("exit_mini");

[2005 date index] [2005 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]