% This module keeps up a list of buffers, ordered by the last visit % into the buffer. This information is then used for a convenient % user-interface for switching buffers. % % Installation: Add to your site.sl / .jedrc / whatever the following line: % () = evalfile("buflist"); % % Usage: % M-x buflist opens the buffer list, which might look like this: % % # foo.sl >>blah.sl *scratch* bar % % ">>" marks the selected buffer. The buffers are in visitation % order, with the most recently visited buffer at the left. % % The following keyboard commands can be used to navigate: % % Enter or Space: switch to selected buffer. % 'p' or '<': select previous buffer. % 'n' or '>': select next buffer. % 'q' or '^G': break. % % % 2002-06-23 / Juho Snellman % * First version, hacked together due to a case of Emacs-envy require("keydefs"); static variable buflist_buffers = Assoc_Type [ Int_Type, 0 ]; static variable buflist_count = 0; static define buflist_cmp(a, b) { % Kludge to sort minibuffer to last place (where it can be ignored) if (a == " ") { return 1; } else if (b == " ") { return -1; } a = buflist_buffers[a]; b = buflist_buffers[b]; if (a > b) { return -1; } else { return a != b; } } define buflist () { variable num = buffer_list; variable bufnames = String_Type [num]; variable i, j, n, v; _for (0, num-1, 1) { i = (); n = (); bufnames[i] = n; } bufnames = bufnames[array_sort(bufnames, &buflist_cmp)]; i = 1; forever { if (i == 0) { v = ">>"; } else { v = strcat(bufnames[i-1], " >>"); } v = strcat("# ", v); for (j = i; j < num-1 and strlen(v) < 60; j++) { v = strcat(v, strcat(bufnames[j], " ")); } n = get_mini_response(v); if (n == ' ' or n == 13) { sw2buf(bufnames[i]); return; } else if (n == '<' or n == 'p') { i -= 1; } else if (n == '>' or n == 'n') { i += 1; } else if (n == 'q' or n == '') { return; } if (i < 0) { i = 0; } if (i >= num) { i = num-1; } } } static define buflist_switch_buffer_hook (old_buffer) { variable buf = whatbuf(); if (buf != " ") { buflist_count++; buflist_buffers[buf] = buflist_count; } } add_to_hook ("_jed_switch_active_buffer_hooks", &buflist_switch_buffer_hook);