jed-users mailing list

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

Re: Cut buffer with ranking


"G. Milde" <g.milde@xxxxxx> wrote:
> On  7.01.05, John E. Davis wrote:
>> Joerg Sommer <joerg@xxxxxxxxxxxx> wrote:
>> >is it possible to make the cut buffer put the last used entry on top? I
>> >often have two or more strings that I use alternating. If I copy any
>> >other then all moves one step behind and I must do yp_yank_pop one time
>> >more to get my old entries. Is it possible to make the kill array is
>> >sorted by last usage?
>
> Everything is possible for the passionate SLang coder ;-)

I know.

> What kind of sorting do you want? 
>   
>   Scores for usage  (most used since start of Jed session first)

Yes.

>   Move last used to top of stack

Yes. This scores the usage.


>   Do not chage current position in the ring of killbuffers, when
>   copying a new one

No.

Yesterday I found time to implement my wish. Maybe someone else is
interested in it.

SLang2 has a cool new data type: List_Type. I used it to create a new
kill_buffer because moving elements in a list is terrible. Here is it:

#v+
_debug_info = 1;
_traceback = 1;
_slangtrace = -1;

private variable Kill_List = {};
private variable Last_pop = -1;

define yp_copy_region_as_kill()
{
   % Move the last poped element to the head of the list; it is most
   % interesting
   if (Last_pop > 0)
     list_insert(Kill_List, list_pop(Kill_List, Last_pop), 0);
   Last_pop = -1;

   list_insert(Kill_List, bufsubstr(), 0);

   % shorten the list if it is to long
   if (length(Kill_List) > KILL_ARRAY_SIZE)
     list_delete(Kill_List, -1);
}

define yp_kill_region()
{
   () = dupmark();
   Last_pop = -1;
   yp_copy_region_as_kill();
   del_region();
}

define yp_kill_line()
{
   variable one = eolp() or (KILL_LINE_FEATURE and bolp());

   mark_to_visible_eol();
   go_right(one);
   yp_kill_region();
}

define yp_kill_word()
{
   push_mark(); skip_word(); 
   yp_kill_region();
}

define yp_bkill_word()
{
   push_mark(); bskip_word();
   yp_kill_region();
}

define yp_yank()
{
   !if ( length(Kill_List) )
     error("Kill array is empty");

   % Move the last poped element to the head of the list; it is most
   % interesting
   if (Last_pop > 0)
     list_insert(Kill_List, list_pop(Kill_List, Last_pop), 0);
   
   Last_pop = 0;

   insert( Kill_List[0] );
   set_current_kbd_command("%yank%");
}

define yp_yank_pop()
{
   if (strcmp(LAST_KBD_COMMAND, "%yank%"))
     error("The last command must be a yank one.");

   %  Delete the previous yank 
   push_mark();
   ()=left( strlen(Kill_List[Last_pop]) );
   del_region();
   
   % we have a ring buffer
   ++Last_pop;
   if (Last_pop >= length(Kill_List))
     Last_pop = 0;
   
   insert( Kill_List[Last_pop] );
   set_current_kbd_command("%yank%");
}

provide("yankpop");
#v-

Save it in a file named yankpop-2.0.sl and add the following to your
.jedrc:
if (_slang_version >= 20000) {
   autoload("yp_copy_region_as_kill",     "yankpop-2.0");
   autoload("yp_kill_region",             "yankpop-2.0");
   autoload("yp_kill_line",               "yankpop-2.0");
   autoload("yp_yank",                    "yankpop-2.0");
   autoload("yp_yank_pop",      	  "yankpop-2.0");
   autoload("yp_bkill_word",     	  "yankpop-2.0");
   autoload("yp_kill_word",               "yankpop-2.0");
}

Jörg.

-- 
Ein Narr, er sieht die Weisheit nicht selbst wenn sie närrisch
zu Ihm spricht!

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


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