Hi,

The -F flag is great! I found out that pane_index was not implemented
however. The first patch adds pane_index to the format_tree. The second
patch fixes list-panes to use it rather than the 'line' format it
implements itself. The third patch fixes window_pane_index to return
(u_int)(-1) if the pane is not in the window given and logs a message
about it.

The third patch made me wonder whether it's unnecessary to pass the
window when getting a pane index since a pane knows the window it is a
member of anyways. A fourth patch changes it to do this. I've not hit
any issues yet, but I'll use it for a week or so to make sure.

--Ben
From 7c76a713a897c03482fa18c52d140a8835a3a30e Mon Sep 17 00:00:00 2001
From: Ben Boeckel <maths...@gmail.com>
Date: Wed, 19 Oct 2011 17:39:16 -0400
Subject: [PATCH 1/4] Implement the pane_index format string

---
 trunk/format.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/trunk/format.c b/trunk/format.c
index 0aad938..780e224 100644
--- a/trunk/format.c
+++ b/trunk/format.c
@@ -325,6 +325,7 @@ format_window_pane(struct format_tree *ft, struct 
window_pane *wp)
        struct grid_line        *gl;
        unsigned long long       size;
        u_int                    i;
+       u_int                    idx;
 
        size = 0;
        for (i = 0; i < gd->hsize; i++) {
@@ -334,8 +335,11 @@ format_window_pane(struct format_tree *ft, struct 
window_pane *wp)
        }
        size += gd->hsize * sizeof *gd->linedata;
 
+       idx = window_pane_index(wp->window, wp);
+
        format_add(ft, "pane_width", "%u", wp->sx);
        format_add(ft, "pane_height", "%u", wp->sy);
+       format_add(ft, "pane_index", "%u", idx);
        format_add(ft, "pane_title", "%s", wp->base.title);
        format_add(ft, "history_size", "%u", gd->hsize);
        format_add(ft, "history_limit", "%u", gd->hlimit);
-- 
1.7.6.4

From b495fb3ec384c5be1ca3429339fb2fefeec1ac5c Mon Sep 17 00:00:00 2001
From: Ben Boeckel <maths...@gmail.com>
Date: Wed, 19 Oct 2011 17:39:31 -0400
Subject: [PATCH 2/4] Use the pane_index format string

---
 trunk/cmd-list-panes.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/trunk/cmd-list-panes.c b/trunk/cmd-list-panes.c
index 723c703..f46c3c5 100644
--- a/trunk/cmd-list-panes.c
+++ b/trunk/cmd-list-panes.c
@@ -102,21 +102,21 @@ cmd_list_panes_window(struct cmd *self,
        if (template == NULL) {
                switch (type) {
                case 0:
-                       template = "#{line}: "
+                       template = "#{pane_index}: "
                            "[#{pane_width}x#{pane_height}] [history "
                            "#{history_size}/#{history_limit}, "
                            "#{history_bytes} bytes] #{pane_id}"
                            "#{?pane_active, (active),}#{?pane_dead, (dead),}";
                        break;
                case 1:
-                       template = "#{window_index}.#{line}: "
+                       template = "#{window_index}.#{pane_index}: "
                            "[#{pane_width}x#{pane_height}] [history "
                            "#{history_size}/#{history_limit}, "
                            "#{history_bytes} bytes] #{pane_id}"
                            "#{?pane_active, (active),}#{?pane_dead, (dead),}";
                        break;
                case 2:
-                       template = "#{session_name}:#{window_index}.#{line}: "
+                       template = 
"#{session_name}:#{window_index}.#{pane_index}: "
                            "[#{pane_width}x#{pane_height}] [history "
                            "#{history_size}/#{history_limit}, "
                            "#{history_bytes} bytes] #{pane_id}"
@@ -128,7 +128,6 @@ cmd_list_panes_window(struct cmd *self,
        n = 0;
        TAILQ_FOREACH(wp, &wl->window->panes, entry) {
                ft = format_create();
-               format_add(ft, "line", "%u", n);
                format_session(ft, s);
                format_winlink(ft, s, wl);
                format_window_pane(ft, wp);
-- 
1.7.6.4

From 95570f01e11670a0f2b70c71b95defa0c17df432 Mon Sep 17 00:00:00 2001
From: Ben Boeckel <maths...@gmail.com>
Date: Wed, 19 Oct 2011 17:43:32 -0400
Subject: [PATCH 3/4] Return '-1' for invalid pane index queries

If we're going to return a bogus index anyways (one past the max index
in the window), at make it a consistent and obviously invalid index
instead of a plausible one. Also log a message.
---
 trunk/window.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/trunk/window.c b/trunk/window.c
index 8b82c06..eb35a85 100644
--- a/trunk/window.c
+++ b/trunk/window.c
@@ -488,13 +488,24 @@ window_pane_index(struct window *w, struct window_pane 
*wp)
 {
        struct window_pane      *wq;
        u_int                    n;
+       int                      found;
 
        n = options_get_number(&w->options, "pane-base-index");
+       found = 0;
        TAILQ_FOREACH(wq, &w->panes, entry) {
-               if (wp == wq)
+               if (wp == wq) {
+                       found = 1;
                        break;
+               }
                n++;
        }
+
+       if (!found) {
+               if (debug_level > 0)
+                       log_warnx("could not find pane in window");
+               n = (u_int)(-1);
+       }
+
        return (n);
 }
 
-- 
1.7.6.4

From 3be855a5062b2da9bf86dc3888e4fc9b2afad052 Mon Sep 17 00:00:00 2001
From: Ben Boeckel <maths...@gmail.com>
Date: Wed, 19 Oct 2011 18:17:52 -0400
Subject: [PATCH 4/4] Make window_pane_index just take a pane

Since a pane knows the window it belongs to, a window does not need to
be passed as well.
---
 trunk/cmd-respawn-pane.c |    4 ++--
 trunk/cmd-split-window.c |    2 +-
 trunk/format.c           |    5 +----
 trunk/screen-redraw.c    |    2 +-
 trunk/status.c           |    2 +-
 trunk/tmux.h             |    2 +-
 trunk/window.c           |    3 ++-
 7 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/trunk/cmd-respawn-pane.c b/trunk/cmd-respawn-pane.c
index 7e272a8..232ef72 100644
--- a/trunk/cmd-respawn-pane.c
+++ b/trunk/cmd-respawn-pane.c
@@ -49,7 +49,7 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
        struct session          *s;
        struct environ           env;
        const char              *cmd;
-       char                    *cause;
+       char                    *cause;
 
        if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
                return (-1);
@@ -57,7 +57,7 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
 
        if (!args_has(self->args, 'k') && wp->fd != -1) {
                ctx->error(ctx, "pane still active: %s:%u.%u",
-                   s->name, wl->idx, window_pane_index(w, wp));
+                   s->name, wl->idx, window_pane_index(wp));
                return (-1);
        }
 
diff --git a/trunk/cmd-split-window.c b/trunk/cmd-split-window.c
index 6a95e1b..22e6113 100644
--- a/trunk/cmd-split-window.c
+++ b/trunk/cmd-split-window.c
@@ -139,7 +139,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
        environ_free(&env);
 
        if (args_has(args, 'P')) {
-               paneidx = window_pane_index(wl->window, new_wp);
+               paneidx = window_pane_index(new_wp);
                ctx->print(ctx, "%s:%u.%u", s->name, wl->idx, paneidx);
        }
        return (0);
diff --git a/trunk/format.c b/trunk/format.c
index 780e224..3acfc3f 100644
--- a/trunk/format.c
+++ b/trunk/format.c
@@ -325,7 +325,6 @@ format_window_pane(struct format_tree *ft, struct 
window_pane *wp)
        struct grid_line        *gl;
        unsigned long long       size;
        u_int                    i;
-       u_int                    idx;
 
        size = 0;
        for (i = 0; i < gd->hsize; i++) {
@@ -335,11 +334,9 @@ format_window_pane(struct format_tree *ft, struct 
window_pane *wp)
        }
        size += gd->hsize * sizeof *gd->linedata;
 
-       idx = window_pane_index(wp->window, wp);
-
        format_add(ft, "pane_width", "%u", wp->sx);
        format_add(ft, "pane_height", "%u", wp->sy);
-       format_add(ft, "pane_index", "%u", idx);
+       format_add(ft, "pane_index", "%u", window_pane_index(wp));
        format_add(ft, "pane_title", "%s", wp->base.title);
        format_add(ft, "history_size", "%u", gd->hsize);
        format_add(ft, "history_limit", "%u", gd->hlimit);
diff --git a/trunk/screen-redraw.c b/trunk/screen-redraw.c
index a12fa36..4ff176e 100644
--- a/trunk/screen-redraw.c
+++ b/trunk/screen-redraw.c
@@ -272,7 +272,7 @@ screen_redraw_draw_number(struct client *c, struct 
window_pane *wp)
        char                     buf[16], *ptr;
        size_t                   len;
 
-       idx = window_pane_index(w, wp);
+       idx = window_pane_index(wp);
        len = xsnprintf(buf, sizeof buf, "%u", idx);
 
        if (wp->sx < len)
diff --git a/trunk/status.c b/trunk/status.c
index 1baab92..6be1b7e 100644
--- a/trunk/status.c
+++ b/trunk/status.c
@@ -423,7 +423,7 @@ status_replace1(struct client *c, struct session *s, struct 
winlink *wl,
                goto do_replace;
        case 'P':
                xsnprintf(
-                   tmp, sizeof tmp, "%u", window_pane_index(wl->window, wp));
+                   tmp, sizeof tmp, "%u", window_pane_index(wp));
                ptr = tmp;
                goto do_replace;
        case 'S':
diff --git a/trunk/tmux.h b/trunk/tmux.h
index 74add28..19b5118 100644
--- a/trunk/tmux.h
+++ b/trunk/tmux.h
@@ -1923,7 +1923,7 @@ struct window_pane *window_pane_next_by_number(struct 
window *,
                        struct window_pane *, u_int);
 struct window_pane *window_pane_previous_by_number(struct window *,
                        struct window_pane *, u_int);
-u_int           window_pane_index(struct window *, struct window_pane *);
+u_int           window_pane_index(struct window_pane *);
 u_int           window_count_panes(struct window *);
 void            window_destroy_panes(struct window *);
 struct window_pane *window_pane_find_by_id(u_int);
diff --git a/trunk/window.c b/trunk/window.c
index eb35a85..3a54ca0 100644
--- a/trunk/window.c
+++ b/trunk/window.c
@@ -484,8 +484,9 @@ window_pane_previous_by_number(struct window *w, struct 
window_pane *wp,
 }
 
 u_int
-window_pane_index(struct window *w, struct window_pane *wp)
+window_pane_index(struct window_pane *wp)
 {
+       struct window           *w = wp->window;
        struct window_pane      *wq;
        u_int                    n;
        int                      found;
-- 
1.7.6.4

Attachment: pgpeUxwMU88Ew.pgp
Description: PGP signature

------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning@Ciosco Self-Assessment and learn 
about Cisco certifications, training, and career opportunities. 
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to