Hi

I don't mind the idea but I think this code is wrong - the tree is keyed
by index so you shouldn't change it like this. You will need to create a
temporary tree, remove each window from the current tree, increase the
index and add it to the temporary tree. Then copy the temporary over
s->windows (can use memcpy).

Also from what I can see the if () in the loop does nothing so it isn't
needed.



On Thu, Aug 04, 2011 at 11:24:02PM +0100, Thomas Adam wrote:
> This is responsible for reassigning new index numbers to the winlinks in a
> given session.
> ---
>  trunk/tmux.h   |    1 +
>  trunk/window.c |   27 +++++++++++++++++++++++++++
>  2 files changed, 28 insertions(+), 0 deletions(-)
> 
> diff --git a/trunk/tmux.h b/trunk/tmux.h
> index b118f49..3881bd2 100644
> --- a/trunk/tmux.h
> +++ b/trunk/tmux.h
> @@ -1924,6 +1924,7 @@ int              window_pane_visible(struct window_pane 
> *);
>  char         *window_pane_search(
>                    struct window_pane *, const char *, u_int *);
>  char         *window_printable_flags(struct session *, struct winlink *);
> +int           window_renumber_windows(struct session *);
>  
>  struct window_pane *window_pane_find_up(struct window_pane *);
>  struct window_pane *window_pane_find_down(struct window_pane *);
> diff --git a/trunk/window.c b/trunk/window.c
> index 4b5f901..600794a 100644
> --- a/trunk/window.c
> +++ b/trunk/window.c
> @@ -1087,3 +1087,30 @@ window_pane_find_right(struct window_pane *wp)
>       }
>       return (NULL);
>  }
> +
> +/* Renumber the windows across winlinks attached to a specific session. */
> +int
> +window_renumber_windows(struct session *s)
> +{
> +     struct winlink  *wl;
> +     int              new_idx;
> +
> +     if (s == NULL)
> +             return (-1);
> +
> +     /* Start renumbering from the base-index if it's set. */
> +     new_idx = options_get_number(&s->options, "base-index");
> +
> +     /* Go through the winlinks and assign new indexes. */
> +     RB_FOREACH(wl, winlinks, &s->windows) {
> +             /* This clashes with a window already with that id, so skip
> +              * it.
> +              */
> +             if (wl->idx == new_idx) {
> +                     new_idx++;
> +                     continue;
> +             }
> +             wl->idx = new_idx++;
> +     }
> +     return (0);
> +}
> -- 
> 1.7.5.4
> 
> ------------------------------------------------------------------------------
> BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
> The must-attend event for mobile developers. Connect with experts. 
> Get tools for creating Super Apps. See the latest technologies.
> Sessions, hands-on labs, demos & much more. Register early & save!
> http://p.sf.net/sfu/rim-blackberry-1
> _______________________________________________
> tmux-users mailing list
> tmux-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tmux-users

------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
The must-attend event for mobile developers. Connect with experts. 
Get tools for creating Super Apps. See the latest technologies.
Sessions, hands-on labs, demos & much more. Register early & save!
http://p.sf.net/sfu/rim-blackberry-1
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to