Matthew Carter <[email protected]> writes:

> Matthew Carter <[email protected]> writes:
>
>> Morgan Howe <[email protected]> writes:
>>
>>> This patch adds basic support for handling multiple buffers. New
>>> commands are ":buf[fer], :badd, and :bdelete". Buffers are given a
>>> unique constant buffer id starting at 1 in the same manner as vim.
>>>
>>> <snip>
>>>
>>> Regards,
>>> Morgan
>>>
>>> ------------------------------------------------------------------------------
>>> Vimprobable-users mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/vimprobable-users
>>
>> Very nice Morgan, built cleanly and works great so far.
>>
>> I love that I can toggle what used to be tab specific features to a set
>> of buffers now.
>>
>> For instance, if I have a few sites that I want to run with javascript
>> enabled, I can open them all in buffers in one tab, do a:
>>
>>          :set javascript=on
>>
>> And as I refresh the pages (or do the set initially) they'll all retain
>> the setting.  Then my next tab of buffers will use my defaults.
>>
>> I don't like typing :buf 1, :buf 2 though, I'd like to use what I use in
>> vim, a simple :b1, :b2 (and :ls for listing the buffers).
>>
>> Maybe I'll expand on your patch unless you plan to (or there was a
>> larger reason for not using the shorter syntax).
>>
>> Just a wishlist item, but some type of command to open a "set" of
>> buffers defined in the RC file would be pretty awesome (for instance, I
>> could define news aggregates as something like:
>>
>>       :set NA=reddit.com,slashdot.org,hackernews.com
>>
>> And then run something like:
>>
>>     :bufaddset NA
>>
>> To automatically open up all 3 pages at once.
>>
>> For grouping, I can't imagine a better set up (where I could have news
>> buffers in one tab, social media in another, programming resources in
>> one and miscellaneous elsewhere).
>
> Usability issues I see so far:
>
>           'd' - I think this should close the current buffer, not the
>           whole window if we do use these buffers
>
>           '^6' - This should switch between most recent buffer and
>           current buffer instead of tabs (at least when buffers exist).
>
>           Maybe keep gt/gT bound for tab cycling still.
>
> Thats all I can think of for now.

Attached is a patch for a buffer list function callable via 'ls' command
that will display the results inline (similar to the stumpwm modeline,
with * indicating the selected buffer and - indicating others).

At the moment I'm also logging it to stderr so it is reusable outside of
vimprobable2 by doing something like:

./vimprobable2 > /tmp/bufls
tail -f /tmp/bufls | grep -C1 '---BUFLS---'

Which would allow displaying the buffer list in a window manager area
(or anywhere consistently).

A better solution would probably be to (optionally) log to a file, if
this was functionality that wasn't too much bloat and would be used by
users.

For whatever reason, printf output seems to be captured by the GTK main
loop until it terminates (hence why I chose stderr and not stdout for
this quickie approach to a buffer list available externally).

diff --git a/main.c b/main.c
index a8dc2ca..55f30da 100644
--- a/main.c
+++ b/main.c
@@ -96,6 +96,7 @@ static gboolean view_source(const Arg * arg);
 static gboolean zoom(const Arg *arg);
 static gboolean fake_key_event(const Arg *arg);
 static gboolean bufadd(const Arg *arg);
+static gboolean bufls();
 static gboolean bufdelete(const Arg *arg);
 static gboolean bufshow(const Arg *arg);
 
@@ -173,6 +174,7 @@ Command commands[] = {
     { "jumptop",                                        scroll,           {ScrollJumpTo   | DirectionTop} },
     { "jumpbottom",                                     scroll,           {ScrollJumpTo   | DirectionBottom} },
     { "javascript",                                     script,           {Silent} },
+    { "ls",                                             bufls,            {TargetCurrent} },
     { "map",                                            mappings,         {0} },
     { "navigationback",                                 navigate,         {NavigationBack} },
     { "navigationforward",                              navigate,         {NavigationForward} },
@@ -2367,6 +2369,7 @@ bufadd(const Arg *arg) {
     } else {
         echo_message(Error, "Max number of buffers reached!");
     }
+
     return TRUE;
 }
 
@@ -2416,6 +2419,28 @@ bufdelete(const Arg *arg) {
 }
 
 gboolean
+bufls() {
+  GSList *elem;
+  Buffer *currbuf = client.buffer;
+  char buffer_list[3000] = "";
+  char buffer_uri[300] = "";
+  char active[1] = "";
+  int i = 0;
+
+  for(elem = bufferlist.head; elem; elem = elem->next) {
+    Buffer *buf = (Buffer *)elem->data;
+    char *buffer_uri = webkit_web_view_get_uri(buf->webview);
+    active[0] = buf == currbuf ? '*' : '-';
+    sprintf(buffer_list, "%s%d%s%s ", buffer_list, buf->bufferid, active, buffer_uri);
+  }
+
+  echo_message(Info, "%s", buffer_list);
+  fprintf(stderr, "\n---BUFLS--\n%s\n", buffer_list);
+
+  return TRUE;
+}
+
+gboolean
 bufshow(const Arg *arg) {
     Buffer *newbuf = NULL;
     int targetid = 0;

-- 
Matthew Carter ([email protected])
http://ahungry.com
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
_______________________________________________
Vimprobable-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vimprobable-users

Reply via email to