On Sat, Mar 26, 2011 at 06:47:36PM -0400, Ben Boeckel wrote:
> On Sat, Mar 26, 2011 at 06:39:12PM -0400, Ben Boeckel wrote:
> > 0001-Add-support-for-pane-ID.patch
> > 
> >     The original patch rebased onto master
> >     (568c723cf33426c1f7fe9419966cf111792f71fb).
> > 

Thanks I'll apply this now.

> > 0002-Only-store-the-session-back-if-non-NULL.patch
> > 
> >     Fixes the crash with swap-panes. The cmd_find_pane function is
> >     called with a NULL session in this case.
> > 
> > 0003-Print-the-pane-ID-when-listing-panes.patch
> > 
> >     Add the ID to the output when listing panes.

Style nits aside these are fine, cheers.

> > 
> > 0004-Add-list-session-panes-command.patch
> > 0005-Add-list-server-panes-command.patch
> > 
> >     These two add commands to list panes with different scopes. Maybe a
> >     list-server-windows would be in order as well?

Hmm. I'm not at all convinced we need any new commands. I wonder if this
stuff could be hooked into existing ones as new flags.

> > 
> > 0006-Fix-list-panes-documentation-to-match-the-rest.patch
> > 
> >     Minor fix to the manpage for list-panes to match the rest of the
> >     documentation.
> > 

I think we don't need to do this, Xc/Xo are only needed in mdoc if you
hit the limit of the number of parameters to It.

> > 0007-Remove-pane-id-from-TODO-list.patch
> > 
> >     Mark the pane ID feature off the TODO list.
> > 
> > 0008-Add-I-flag-to-new-window-and-split-window.patch
> > 
> >     Add a -I flag to new-window and split-window commands (similar to
> >     -P) to print the ID of the new window.
> 
> And I forget to attach them...
> 
> --Ben

> From 4c731f2854e6854cd72c39d9765a5b5969f555bb Mon Sep 17 00:00:00 2001
> From: Ben Boeckel <maths...@gmail.com>
> Date: Sun, 6 Mar 2011 05:25:09 -0500
> Subject: [PATCH 1/8] Add support for pane ID
> 
> ---
>  cmd.c    |   97 
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
>  server.c |    1 +
>  tmux.h   |    8 +++++
>  window.c |   31 +++++++++++++++++++-
>  4 files changed, 125 insertions(+), 12 deletions(-)
> 
> diff --git a/cmd.c b/cmd.c
> index d5f6374..20dd70c 100644
> --- a/cmd.c
> +++ b/cmd.c
> @@ -117,9 +117,12 @@ struct client    *cmd_lookup_client(const char *);
>  struct session       *cmd_lookup_session(const char *, int *);
>  struct winlink       *cmd_lookup_window(struct session *, const char *, int 
> *);
>  int           cmd_lookup_index(struct session *, const char *, int *);
> +struct window_pane *cmd_lookup_paneid(const char *);
> +struct session       *cmd_pane_session(struct cmd_ctx *,
> +                  struct window_pane *, struct winlink **);
>  struct winlink       *cmd_find_window_offset(const char *, struct session *, 
> int *);
>  int           cmd_find_index_offset(const char *, struct session *, int *);
> -struct window_pane   *cmd_find_pane_offset(const char *, struct winlink *);
> +struct window_pane *cmd_find_pane_offset(const char *, struct winlink *);
>  
>  int
>  cmd_pack_argv(int argc, char **argv, char *buf, size_t len)
> @@ -638,21 +641,78 @@ cmd_lookup_index(struct session *s, const char *name, 
> int *ambiguous)
>       return (-1);
>  }
>  
> +/*
> + * Lookup pane id. An initial % means a pane id. sp must already point to the
> + * current session.
> + */
> +struct window_pane *
> +cmd_lookup_paneid(const char *arg)
> +{
> +     const char      *errstr;
> +     u_int            paneid;
> +
> +     if (*arg != '%')
> +             return (NULL);
> +
> +     paneid = strtonum(arg + 1, 0, UINT_MAX, &errstr);
> +     if (errstr != NULL)
> +             return (NULL);
> +     return (window_pane_find_by_id(paneid));
> +}
> +
> +/* Find session and winlink for pane. */
> +struct session *
> +cmd_pane_session(struct cmd_ctx *ctx, struct window_pane *wp,
> +    struct winlink **wlp)
> +{
> +     struct session          *s;
> +     struct sessionslist      ss;
> +     struct winlink          *wl;
> +
> +     /* If this pane is in the current session, return that winlink. */
> +     s = cmd_current_session(ctx);
> +     if (s != NULL) {
> +             wl = winlink_find_by_window(&s->windows, wp->window);
> +             if (wl != NULL) {
> +                     if (wlp != NULL)
> +                             *wlp = wl;
> +                     return (s);
> +             }
> +     }
> +
> +     /* Otherwise choose from all sessions with this pane. */
> +     ARRAY_INIT(&ss);
> +     RB_FOREACH(s, sessions, &sessions) {
> +             if (winlink_find_by_window(&s->windows, wp->window) != NULL)
> +                     ARRAY_ADD(&ss, s);
> +     }
> +     s = cmd_choose_session_list(&ss);
> +     ARRAY_FREE(&ss);
> +     if (wlp != NULL)
> +             *wlp = winlink_find_by_window(&s->windows, wp->window);
> +     return (s);
> +}
> +
>  /* Find the target session or report an error and return NULL. */
>  struct session *
>  cmd_find_session(struct cmd_ctx *ctx, const char *arg)
>  {
> -     struct session  *s;
> -     struct client   *c;
> -     char            *tmparg;
> -     size_t           arglen;
> -     int              ambiguous;
> +     struct session          *s;
> +     struct window_pane      *wp;
> +     struct client           *c;
> +     char                    *tmparg;
> +     size_t                   arglen;
> +     int                      ambiguous;
>  
>       /* A NULL argument means the current session. */
>       if (arg == NULL)
>               return (cmd_current_session(ctx));
>       tmparg = xstrdup(arg);
>  
> +     /* Lookup as pane id. */
> +     if ((wp = cmd_lookup_paneid(arg)) != NULL)
> +             return (cmd_pane_session(ctx, wp, NULL));
> +
>       /* Trim a single trailing colon if any. */
>       arglen = strlen(tmparg);
>       if (arglen != 0 && tmparg[arglen - 1] == ':')
> @@ -681,11 +741,12 @@ cmd_find_session(struct cmd_ctx *ctx, const char *arg)
>  struct winlink *
>  cmd_find_window(struct cmd_ctx *ctx, const char *arg, struct session **sp)
>  {
> -     struct session  *s;
> -     struct winlink  *wl;
> -     const char      *winptr;
> -     char            *sessptr = NULL;
> -     int              ambiguous = 0;
> +     struct session          *s;
> +     struct winlink          *wl;
> +     struct window_pane      *wp;
> +     const char              *winptr;
> +     char                    *sessptr = NULL;
> +     int                      ambiguous = 0;
>  
>       /*
>        * Find the current session. There must always be a current session, if
> @@ -703,6 +764,14 @@ cmd_find_window(struct cmd_ctx *ctx, const char *arg, 
> struct session **sp)
>               return (s->curw);
>       }
>  
> +     /* Lookup as pane id. */
> +     if ((wp = cmd_lookup_paneid(arg)) != NULL) {
> +             s = cmd_pane_session(ctx, wp, &wl);
> +             if (sp != NULL)
> +                     *sp = s;
> +             return (wl);
> +     }
> +
>       /* Time to look at the argument. If it is empty, that is an error. */
>       if (*arg == '\0')
>               goto not_found;
> @@ -997,6 +1066,12 @@ cmd_find_pane(struct cmd_ctx *ctx,
>               return (s->curw);
>       }
>  
> +     /* Lookup as pane id. */
> +     if ((*wpp = cmd_lookup_paneid(arg)) != NULL) {
> +             *sp = cmd_pane_session(ctx, *wpp, &wl);
> +             return (wl);
> +     }
> +
>       /* Look for a separating period. */
>       if ((period = strrchr(arg, '.')) == NULL)
>               goto no_period;
> diff --git a/server.c b/server.c
> index 9b3b0d3..86a5b00 100644
> --- a/server.c
> +++ b/server.c
> @@ -142,6 +142,7 @@ server_start(void)
>       log_debug("server started, pid %ld", (long) getpid());
>  
>       ARRAY_INIT(&windows);
> +     RB_INIT(&all_window_panes);
>       ARRAY_INIT(&clients);
>       ARRAY_INIT(&dead_clients);
>       RB_INIT(&sessions);
> diff --git a/tmux.h b/tmux.h
> index 3e1b26b..a547ec8 100644
> --- a/tmux.h
> +++ b/tmux.h
> @@ -775,6 +775,8 @@ struct window_mode {
>  
>  /* Child window structure. */
>  struct window_pane {
> +     u_int            id;
> +
>       struct window   *window;
>       struct layout_cell *layout_cell;
>  
> @@ -817,8 +819,10 @@ struct window_pane {
>       void            *modedata;
>  
>       TAILQ_ENTRY(window_pane) entry;
> +     RB_ENTRY(window_pane) tree_entry;
>  };
>  TAILQ_HEAD(window_panes, window_pane);
> +RB_HEAD(window_pane_tree, window_pane);
>  
>  /* Window structure. */
>  struct window {
> @@ -1821,8 +1825,11 @@ int     screen_check_selection(struct screen *, u_int, 
> u_int);
>  
>  /* window.c */
>  extern struct windows windows;
> +extern struct window_pane_tree all_window_panes;
>  int           winlink_cmp(struct winlink *, struct winlink *);
>  RB_PROTOTYPE(winlinks, winlink, entry, winlink_cmp);
> +int           window_pane_cmp(struct window_pane *, struct window_pane *);
> +RB_PROTOTYPE(window_pane_tree, window_pane, tree_entry, window_pane_cmp);
>  struct winlink       *winlink_find_by_index(struct winlinks *, int);
>  struct winlink       *winlink_find_by_window(struct winlinks *, struct 
> window *);
>  int           winlink_next_index(struct winlinks *, int);
> @@ -1857,6 +1864,7 @@ struct window_pane 
> *window_pane_previous_by_number(struct window *,
>  u_int                 window_pane_index(struct window *, 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);
>  struct window_pane *window_pane_create(struct window *, u_int, u_int, u_int);
>  void          window_pane_destroy(struct window_pane *);
>  int           window_pane_spawn(struct window_pane *, const char *,
> diff --git a/window.c b/window.c
> index 02bc5e6..1a02f81 100644
> --- a/window.c
> +++ b/window.c
> @@ -53,6 +53,10 @@
>  /* Global window list. */
>  struct windows windows;
>  
> +/* Global panes tree. */
> +struct window_pane_tree all_window_panes;
> +u_int        next_window_pane;
> +
>  void window_pane_read_callback(struct bufferevent *, void *);
>  void window_pane_error_callback(struct bufferevent *, short, void *);
>  
> @@ -64,6 +68,14 @@ winlink_cmp(struct winlink *wl1, struct winlink *wl2)
>       return (wl1->idx - wl2->idx);
>  }
>  
> +RB_GENERATE(window_pane_tree, window_pane, tree_entry, window_pane_cmp);
> +
> +int
> +window_pane_cmp(struct window_pane *wp1, struct window_pane *wp2)
> +{
> +     return (wp1->id - wp2->id);
> +}
> +
>  struct winlink *
>  winlink_find_by_window(struct winlinks *wwl, struct window *w)
>  {
> @@ -492,6 +504,16 @@ window_printable_flags(struct session *s, struct winlink 
> *wl)
>       return (xstrdup(flags));
>  }
>  
> +/* Find pane in global tree by id. */
> +struct window_pane *
> +window_pane_find_by_id(u_int id)
> +{
> +     struct window_pane      wp;
> +
> +     wp.id = id;
> +     return (RB_FIND(window_pane_tree, &all_window_panes, &wp));
> +}
> +
>  struct window_pane *
>  window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit)
>  {
> @@ -500,6 +522,9 @@ window_pane_create(struct window *w, u_int sx, u_int sy, 
> u_int hlimit)
>       wp = xcalloc(1, sizeof *wp);
>       wp->window = w;
>  
> +     wp->id = next_window_pane++;
> +     RB_INSERT(window_pane_tree, &all_window_panes, wp);
> +
>       wp->cmd = NULL;
>       wp->shell = NULL;
>       wp->cwd = NULL;
> @@ -552,6 +577,8 @@ window_pane_destroy(struct window_pane *wp)
>               bufferevent_free(wp->pipe_event);
>       }
>  
> +     RB_REMOVE(window_pane_tree, &all_window_panes, wp);
> +
>       if (wp->cwd != NULL)
>               xfree(wp->cwd);
>       if (wp->shell != NULL)
> @@ -566,7 +593,7 @@ window_pane_spawn(struct window_pane *wp, const char 
> *cmd, const char *shell,
>      const char *cwd, struct environ *env, struct termios *tio, char **cause)
>  {
>       struct winsize   ws;
> -     char            *argv0;
> +     char            *argv0, paneid[16];
>       const char      *ptr;
>       struct termios   tio2;
>  
> @@ -613,6 +640,8 @@ window_pane_spawn(struct window_pane *wp, const char 
> *cmd, const char *shell,
>  
>               closefrom(STDERR_FILENO + 1);
>  
> +             xsnprintf(paneid, sizeof paneid, "%%%u", wp->id);
> +             environ_set(env, "TMUX_PANE", paneid);
>               environ_push(env);
>  
>               clear_signals(1);
> -- 
> 1.7.4.1
> 

> From b2ebf965d55a515e6410e5e4e5507ad85f572288 Mon Sep 17 00:00:00 2001
> From: Ben Boeckel <maths...@gmail.com>
> Date: Sat, 26 Mar 2011 16:46:58 -0400
> Subject: [PATCH 2/8] Only store the session back if non-NULL
> 
> ---
>  cmd.c |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/cmd.c b/cmd.c
> index 20dd70c..1690900 100644
> --- a/cmd.c
> +++ b/cmd.c
> @@ -1068,7 +1068,9 @@ cmd_find_pane(struct cmd_ctx *ctx,
>  
>       /* Lookup as pane id. */
>       if ((*wpp = cmd_lookup_paneid(arg)) != NULL) {
> -             *sp = cmd_pane_session(ctx, *wpp, &wl);
> +             struct session* session = cmd_pane_session(ctx, *wpp, &wl);
> +             if (sp != NULL)
> +                     *sp = session;
>               return (wl);
>       }
>  
> -- 
> 1.7.4.1
> 

> From e5659fe96f3ce699f75064695f42b80d9a98d9ea Mon Sep 17 00:00:00 2001
> From: Ben Boeckel <maths...@gmail.com>
> Date: Sat, 26 Mar 2011 16:58:29 -0400
> Subject: [PATCH 3/8] Print the pane ID when listing panes
> 
> ---
>  cmd-list-panes.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/cmd-list-panes.c b/cmd-list-panes.c
> index 72e8edc..c8aa7e9 100644
> --- a/cmd-list-panes.c
> +++ b/cmd-list-panes.c
> @@ -64,8 +64,8 @@ cmd_list_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
>               }
>               size += gd->hsize * sizeof *gd->linedata;
>  
> -             ctx->print(ctx, "%u: [%ux%u] [history %u/%u, %llu bytes]%s%s",
> -                 n, wp->sx, wp->sy, gd->hsize, gd->hlimit, size,
> +             ctx->print(ctx, "%u: [%ux%u] [history %u/%u, %llu bytes] 
> %%%u%s%s",
> +                 n, wp->sx, wp->sy, gd->hsize, gd->hlimit, size, wp->id,
>                   wp == wp->window->active ? " (active)" : "",
>                   wp->fd == -1 ? " (dead)" : "");
>               n++;
> -- 
> 1.7.4.1
> 

> From 9cb6a7ed1dad12ccb581fca7b04f6da80cfb3619 Mon Sep 17 00:00:00 2001
> From: Ben Boeckel <maths...@gmail.com>
> Date: Sat, 26 Mar 2011 17:41:45 -0400
> Subject: [PATCH 4/8] Add list-session-panes command
> 
> ---
>  Makefile.am              |    1 +
>  cmd-list-session-panes.c |   82 
> ++++++++++++++++++++++++++++++++++++++++++++++
>  cmd.c                    |    1 +
>  examples/tmux.vim        |    3 +-
>  tmux.1                   |    6 +++
>  tmux.h                   |    1 +
>  6 files changed, 93 insertions(+), 1 deletions(-)
>  create mode 100644 cmd-list-session-panes.c
> 
> diff --git a/Makefile.am b/Makefile.am
> index 62d704a..27d5cb2 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -96,6 +96,7 @@ dist_tmux_SOURCES = \
>       cmd-list-commands.c \
>       cmd-list-keys.c \
>       cmd-list-panes.c \
> +     cmd-list-session-panes.c \
>       cmd-list-sessions.c \
>       cmd-list-windows.c \
>       cmd-list.c \
> diff --git a/cmd-list-session-panes.c b/cmd-list-session-panes.c
> new file mode 100644
> index 0000000..4ef28d5
> --- /dev/null
> +++ b/cmd-list-session-panes.c
> @@ -0,0 +1,82 @@
> +/* $Id: cmd-list-session-panes.c,v 1.7 2011/01/07 14:45:34 tcunha Exp $ */
> +
> +/*
> + * Copyright (c) 2009 Nicholas Marriott <n...@users.sourceforge.net>
> + *
> + * Permission to use, copy, modify, and distribute this software for any
> + * purpose with or without fee is hereby granted, provided that the above
> + * copyright notice and this permission notice appear in all copies.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
> + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
> + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> + */
> +
> +#include <sys/types.h>
> +
> +#include <unistd.h>
> +
> +#include "tmux.h"
> +
> +/*
> + * List panes in a given session.
> + */
> +
> +int  cmd_list_session_panes_exec(struct cmd *, struct cmd_ctx *);
> +
> +const struct cmd_entry cmd_list_session_panes_entry = {
> +     "list-session-panes", "lssp",
> +     "t:", 0, 0,
> +     CMD_TARGET_SESSION_USAGE,
> +     0,
> +     NULL,
> +     NULL,
> +     cmd_list_session_panes_exec
> +};
> +
> +int
> +cmd_list_session_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
> +{
> +     struct args             *args = self->args;
> +     struct session  *s;
> +     struct winlink          *wl;
> +     struct window_pane      *wp;
> +     struct grid             *gd;
> +     struct grid_line        *gl;
> +     u_int                    i, n;
> +     unsigned long long       size;
> +
> +     if ((s = cmd_find_session(ctx, args_get(args, 't'))) == NULL)
> +             return (-1);
> +
> +     RB_FOREACH(wl, winlinks, &s->windows) {
> +             n = 0;
> +             TAILQ_FOREACH(wp, &wl->window->panes, entry) {
> +                     gd = wp->base.grid;
> +
> +                     size = 0;
> +                     for (i = 0; i < gd->hsize; i++) {
> +                             gl = &gd->linedata[i];
> +                             size += gl->cellsize * sizeof *gl->celldata;
> +                             size += gl->utf8size * sizeof *gl->utf8data;
> +                     }
> +                     size += gd->hsize * sizeof *gd->linedata;
> +
> +                     ctx->print(ctx, "%d.%u: [%ux%u] [history %u/%u, %llu 
> bytes] %%%u%s%s",
> +                             wl->idx, n, wp->sx, wp->sy, gd->hsize, 
> gd->hlimit, size, wp->id,
> +                             wp == wp->window->active ? " (active)" : "",
> +                             wp->fd == -1 ? " (dead)" : "");
> +                     n++;
> +             }
> +     }
> +
> +     if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
> +             return (-1);
> +
> +
> +     return (0);
> +}
> diff --git a/cmd.c b/cmd.c
> index 1690900..b5b34ac 100644
> --- a/cmd.c
> +++ b/cmd.c
> @@ -60,6 +60,7 @@ const struct cmd_entry *cmd_table[] = {
>       &cmd_list_commands_entry,
>       &cmd_list_keys_entry,
>       &cmd_list_panes_entry,
> +     &cmd_list_session_panes_entry,
>       &cmd_list_sessions_entry,
>       &cmd_list_windows_entry,
>       &cmd_load_buffer_entry,
> diff --git a/examples/tmux.vim b/examples/tmux.vim
> index eb607a4..6648f93 100644
> --- a/examples/tmux.vim
> +++ b/examples/tmux.vim
> @@ -41,7 +41,8 @@ syn keyword tmuxCmds clearhist clear-history selectl 
> select-layout if[-shell]
>  syn keyword tmuxCmds display[-message] setenv set-environment showenv
>  syn keyword tmuxCmds show-environment choose-client displayp display-panes
>  syn keyword tmuxCmds run[-shell] lockc lock-client locks lock-session lsp
> -syn keyword tmuxCmds list-panes pipep pipe-pane showmsgs show-messages 
> capturep
> +syn keyword tmuxCmds list-panes lssp list-session-panes
> +syn keyword tmuxCmds pipep pipe-pane showmsgs show-messages capturep
>  syn keyword tmuxCmds capture-pane joinp join-pane choose-buffer
>  
>  syn keyword tmuxOptsSet prefix status status-fg status-bg bell-action
> diff --git a/tmux.1 b/tmux.1
> index 8d462e7..a09e1dc 100644
> --- a/tmux.1
> +++ b/tmux.1
> @@ -1103,6 +1103,12 @@ is given, the newly linked window is not selected.
>  .D1 (alias: Ic lsp )
>  List the panes in the current window or in
>  .Ar target-window .
> +.It Xo Ic list-session-panes
> +.Op Fl t Ar target-session
> +.Xc
> +.D1 (alias: Ic lssp )
> +List the panes in the current session or in
> +.Ar target-session .
>  .It Ic list-windows Op Fl t Ar target-session
>  .D1 (alias: Ic lsw )
>  List windows in the current session or in
> diff --git a/tmux.h b/tmux.h
> index a547ec8..becc867 100644
> --- a/tmux.h
> +++ b/tmux.h
> @@ -1529,6 +1529,7 @@ extern const struct cmd_entry cmd_list_clients_entry;
>  extern const struct cmd_entry cmd_list_commands_entry;
>  extern const struct cmd_entry cmd_list_keys_entry;
>  extern const struct cmd_entry cmd_list_panes_entry;
> +extern const struct cmd_entry cmd_list_session_panes_entry;
>  extern const struct cmd_entry cmd_list_sessions_entry;
>  extern const struct cmd_entry cmd_list_windows_entry;
>  extern const struct cmd_entry cmd_load_buffer_entry;
> -- 
> 1.7.4.1
> 

> From a56df7d34a8fc6c4246732147f15383c277802de Mon Sep 17 00:00:00 2001
> From: Ben Boeckel <maths...@gmail.com>
> Date: Sat, 26 Mar 2011 17:42:16 -0400
> Subject: [PATCH 5/8] Add list-server-panes command
> 
> ---
>  Makefile.am             |    1 +
>  cmd-list-server-panes.c |   76 
> +++++++++++++++++++++++++++++++++++++++++++++++
>  cmd.c                   |    1 +
>  examples/tmux.vim       |    2 +-
>  tmux.1                  |    3 ++
>  tmux.h                  |    1 +
>  6 files changed, 83 insertions(+), 1 deletions(-)
>  create mode 100644 cmd-list-server-panes.c
> 
> diff --git a/Makefile.am b/Makefile.am
> index 27d5cb2..4394019 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -96,6 +96,7 @@ dist_tmux_SOURCES = \
>       cmd-list-commands.c \
>       cmd-list-keys.c \
>       cmd-list-panes.c \
> +     cmd-list-server-panes.c \
>       cmd-list-session-panes.c \
>       cmd-list-sessions.c \
>       cmd-list-windows.c \
> diff --git a/cmd-list-server-panes.c b/cmd-list-server-panes.c
> new file mode 100644
> index 0000000..280187c
> --- /dev/null
> +++ b/cmd-list-server-panes.c
> @@ -0,0 +1,76 @@
> +/* $Id: cmd-list-server-panes.c,v 1.7 2011/01/07 14:45:34 tcunha Exp $ */
> +
> +/*
> + * Copyright (c) 2009 Nicholas Marriott <n...@users.sourceforge.net>
> + *
> + * Permission to use, copy, modify, and distribute this software for any
> + * purpose with or without fee is hereby granted, provided that the above
> + * copyright notice and this permission notice appear in all copies.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
> + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
> + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> + */
> +
> +#include <sys/types.h>
> +
> +#include <unistd.h>
> +
> +#include "tmux.h"
> +
> +/*
> + * List all panes in the server.
> + */
> +
> +int  cmd_list_server_panes_exec(struct cmd *, struct cmd_ctx *);
> +
> +const struct cmd_entry cmd_list_server_panes_entry = {
> +     "list-server-panes", "lssrp",
> +     "", 0, 0,
> +     "",
> +     0,
> +     NULL,
> +     NULL,
> +     cmd_list_server_panes_exec
> +};
> +
> +int
> +cmd_list_server_panes_exec(unused struct cmd *self, struct cmd_ctx *ctx)
> +{
> +     struct session  *s;
> +     struct winlink          *wl;
> +     struct window_pane      *wp;
> +     struct grid             *gd;
> +     struct grid_line        *gl;
> +     u_int                    i, n;
> +     unsigned long long       size;
> +
> +     RB_FOREACH(s, sessions, &sessions) {
> +             RB_FOREACH(wl, winlinks, &s->windows) {
> +                     n = 0;
> +                     TAILQ_FOREACH(wp, &wl->window->panes, entry) {
> +                             gd = wp->base.grid;
> +
> +                             size = 0;
> +                             for (i = 0; i < gd->hsize; i++) {
> +                                     gl = &gd->linedata[i];
> +                                     size += gl->cellsize * sizeof 
> *gl->celldata;
> +                                     size += gl->utf8size * sizeof 
> *gl->utf8data;
> +                             }
> +                             size += gd->hsize * sizeof *gd->linedata;
> +
> +                             ctx->print(ctx, "%s:%d.%u: [%ux%u] [history 
> %u/%u, %llu bytes] %%%u%s%s",
> +                                     s->name, wl->idx, n, wp->sx, wp->sy, 
> gd->hsize, gd->hlimit, size, wp->id,
> +                                     wp == wp->window->active ? " (active)" 
> : "",
> +                                     wp->fd == -1 ? " (dead)" : "");
> +                             n++;
> +                     }
> +             }
> +     }
> +
> +     return (0);
> +}
> diff --git a/cmd.c b/cmd.c
> index b5b34ac..bbbc880 100644
> --- a/cmd.c
> +++ b/cmd.c
> @@ -60,6 +60,7 @@ const struct cmd_entry *cmd_table[] = {
>       &cmd_list_commands_entry,
>       &cmd_list_keys_entry,
>       &cmd_list_panes_entry,
> +     &cmd_list_server_panes_entry,
>       &cmd_list_session_panes_entry,
>       &cmd_list_sessions_entry,
>       &cmd_list_windows_entry,
> diff --git a/examples/tmux.vim b/examples/tmux.vim
> index 6648f93..38c1e9d 100644
> --- a/examples/tmux.vim
> +++ b/examples/tmux.vim
> @@ -41,7 +41,7 @@ syn keyword tmuxCmds clearhist clear-history selectl 
> select-layout if[-shell]
>  syn keyword tmuxCmds display[-message] setenv set-environment showenv
>  syn keyword tmuxCmds show-environment choose-client displayp display-panes
>  syn keyword tmuxCmds run[-shell] lockc lock-client locks lock-session lsp
> -syn keyword tmuxCmds list-panes lssp list-session-panes
> +syn keyword tmuxCmds list-panes lssrp list-server-panes lssp 
> list-session-panes
>  syn keyword tmuxCmds pipep pipe-pane showmsgs show-messages capturep
>  syn keyword tmuxCmds capture-pane joinp join-pane choose-buffer
>  
> diff --git a/tmux.1 b/tmux.1
> index a09e1dc..d306210 100644
> --- a/tmux.1
> +++ b/tmux.1
> @@ -583,6 +583,9 @@ List all clients attached to the server.
>  .D1 (alias: Ic lscm )
>  List the syntax of all commands supported by
>  .Nm .
> +.It Ic list-server-panes
> +.D1 (alias: Ic lssrp )
> +List all the panes in the server.
>  .It Ic list-sessions
>  .D1 (alias: Ic ls )
>  List all sessions managed by the server.
> diff --git a/tmux.h b/tmux.h
> index becc867..13e34a6 100644
> --- a/tmux.h
> +++ b/tmux.h
> @@ -1529,6 +1529,7 @@ extern const struct cmd_entry cmd_list_clients_entry;
>  extern const struct cmd_entry cmd_list_commands_entry;
>  extern const struct cmd_entry cmd_list_keys_entry;
>  extern const struct cmd_entry cmd_list_panes_entry;
> +extern const struct cmd_entry cmd_list_server_panes_entry;
>  extern const struct cmd_entry cmd_list_session_panes_entry;
>  extern const struct cmd_entry cmd_list_sessions_entry;
>  extern const struct cmd_entry cmd_list_windows_entry;
> -- 
> 1.7.4.1
> 

> From f269d36b12cae51f7d720fd8c038cf5b229d75b4 Mon Sep 17 00:00:00 2001
> From: Ben Boeckel <maths...@gmail.com>
> Date: Sat, 26 Mar 2011 17:42:27 -0400
> Subject: [PATCH 6/8] Fix list-panes documentation to match the rest
> 
> ---
>  tmux.1 |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/tmux.1 b/tmux.1
> index d306210..232d292 100644
> --- a/tmux.1
> +++ b/tmux.1
> @@ -1102,7 +1102,9 @@ exists, it is killed, otherwise an error is generated.
>  If
>  .Fl d
>  is given, the newly linked window is not selected.
> -.It Ic list-panes Op Fl t Ar target-window
> +.It Xo Ic list-panes
> +.Op Fl t Ar target-window
> +.Xc
>  .D1 (alias: Ic lsp )
>  List the panes in the current window or in
>  .Ar target-window .
> -- 
> 1.7.4.1
> 

> From 0b58a44182f4fade2d4c9ee656215f1437ce4993 Mon Sep 17 00:00:00 2001
> From: Ben Boeckel <maths...@gmail.com>
> Date: Sat, 26 Mar 2011 17:44:20 -0400
> Subject: [PATCH 7/8] Remove pane-id from TODO list
> 
> ---
>  TODO |    2 --
>  1 files changed, 0 insertions(+), 2 deletions(-)
> 
> diff --git a/TODO b/TODO
> index e51e517..0506887 100644
> --- a/TODO
> +++ b/TODO
> @@ -101,8 +101,6 @@
>  - a history of commands that can be reversed (reverse member of each command,
>    and a buffer) info() when changing to same window
>  - don't pass UTF-8 through vis for titles
> -- add a unique ever-increasing pane id to each pane, export it in $TMUX_PANE
> -   (as %1, %2 etc) and allow it to be used as a target
>  - way to add dest for break-pane; maybe some easier way to unbreak-pane
>  - case insensitive searching
>  - pane-index option like base-index
> -- 
> 1.7.4.1
> 

> From 2136eb7e2e14af40397a4e33746133050bfd5dbf Mon Sep 17 00:00:00 2001
> From: Ben Boeckel <maths...@gmail.com>
> Date: Sat, 26 Mar 2011 18:28:50 -0400
> Subject: [PATCH 8/8] Add -I flag to new-window and split-window
> 
> This is similar to the -P flag, but instead prints the ID of the new
> window.
> ---
>  cmd-new-window.c   |    6 ++++--
>  cmd-split-window.c |    6 ++++--
>  tmux.1             |   16 ++++++++++++++--
>  3 files changed, 22 insertions(+), 6 deletions(-)
> 
> diff --git a/cmd-new-window.c b/cmd-new-window.c
> index 79e301f..85b025d 100644
> --- a/cmd-new-window.c
> +++ b/cmd-new-window.c
> @@ -30,8 +30,8 @@ int cmd_new_window_exec(struct cmd *, struct cmd_ctx *);
>  
>  const struct cmd_entry cmd_new_window_entry = {
>       "new-window", "neww",
> -     "adkn:Pt:", 0, 1,
> -     "[-adk] [-n window-name] [-t target-window] [command]",
> +     "adkn:PIt:", 0, 1,
> +     "[-adkPI] [-n window-name] [-t target-window] [command]",
>       0,
>       NULL,
>       NULL,
> @@ -122,5 +122,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
>  
>       if (args_has(args, 'P'))
>               ctx->print(ctx, "%s:%u", s->name, wl->idx);
> +     if (args_has(args, 'I'))
> +             ctx->print(ctx, "%%%u", wl->window->active->id);
>       return (0);
>  }
> diff --git a/cmd-split-window.c b/cmd-split-window.c
> index 1aedf90..d19a7b3 100644
> --- a/cmd-split-window.c
> +++ b/cmd-split-window.c
> @@ -32,8 +32,8 @@ int cmd_split_window_exec(struct cmd *, struct cmd_ctx *);
>  
>  const struct cmd_entry cmd_split_window_entry = {
>       "split-window", "splitw",
> -     "dl:hp:Pt:v", 0, 1,
> -     "[-dhvP] [-p percentage|-l size] [-t target-pane] [command]",
> +     "dl:hp:PIt:v", 0, 1,
> +     "[-dhvPI] [-p percentage|-l size] [-t target-pane] [command]",
>       0,
>       cmd_split_window_key_binding,
>       NULL,
> @@ -140,6 +140,8 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx 
> *ctx)
>               paneidx = window_pane_index(wl->window, new_wp);
>               ctx->print(ctx, "%s:%u.%u", s->name, wl->idx, paneidx);
>       }
> +     if (args_has(args, 'I'))
> +             ctx->print(ctx, "%%%u", new_wp->id);
>       return (0);
>  
>  error:
> diff --git a/tmux.1 b/tmux.1
> index 232d292..c229686 100644
> --- a/tmux.1
> +++ b/tmux.1
> @@ -1131,7 +1131,7 @@ except the window at
>  is moved to
>  .Ar dst-window .
>  .It Xo Ic new-window
> -.Op Fl adkP
> +.Op Fl adkPI
>  .Op Fl n Ar window-name
>  .Op Fl t Ar target-window
>  .Op Ar shell-command
> @@ -1183,6 +1183,10 @@ start-up files.
>  The
>  .Fl P
>  option prints the location of the new window after it has been created.
> +.Pp
> +The
> +.Fl I
> +option prints the id of the new window after it has been created.
>  .It Ic next-layout Op Fl t Ar target-window
>  .D1 (alias: Ic nextl )
>  Move a window to the next layout and rearrange the panes to fit.
> @@ -1345,7 +1349,7 @@ and
>  .Ic previous-window
>  commands.
>  .It Xo Ic split-window
> -.Op Fl dhvP
> +.Op Fl dhvPI
>  .Oo Fl l
>  .Ar size |
>  .Fl p Ar percentage Oc
> @@ -1370,6 +1374,14 @@ cells (for horizontal split), or as a percentage, 
> respectively.
>  All other options have the same meaning as for the
>  .Ic new-window
>  command.
> +.Pp
> +The
> +.Fl P
> +option prints the location of the new window after it has been created.
> +.Pp
> +The
> +.Fl I
> +option prints the id of the new window after it has been created.
>  .It Xo Ic swap-pane
>  .Op Fl dDU
>  .Op Fl s Ar src-pane
> -- 
> 1.7.4.1
> 




------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to