Revision: 2786
          http://tmux.svn.sourceforge.net/tmux/?rev=2786&view=rev
Author:   tcunha
Date:     2012-05-03 17:51:04 +0000 (Thu, 03 May 2012)
Log Message:
-----------
Sync OpenBSD patchset 1104:

Add a flag to move-window to renumber the windows in a session (closing
any gaps) and add an option to do this automatically each time a window
is killed. From Thomas Adam.

Modified Paths:
--------------
    trunk/cmd-move-window.c
    trunk/options-table.c
    trunk/server-fn.c
    trunk/session.c
    trunk/tmux.1
    trunk/tmux.h

Modified: trunk/cmd-move-window.c
===================================================================
--- trunk/cmd-move-window.c     2012-05-03 17:12:38 UTC (rev 2785)
+++ trunk/cmd-move-window.c     2012-05-03 17:51:04 UTC (rev 2786)
@@ -30,8 +30,8 @@
 
 const struct cmd_entry cmd_move_window_entry = {
        "move-window", "movew",
-       "dks:t:", 0, 0,
-       "[-dk] " CMD_SRCDST_WINDOW_USAGE,
+       "dkrs:t:", 0, 0,
+       "[-dkr] " CMD_SRCDST_WINDOW_USAGE,
        0,
        NULL,
        NULL,
@@ -42,11 +42,22 @@
 cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
 {
        struct args     *args = self->args;
-       struct session  *src, *dst;
+       struct session  *src, *dst, *s;
        struct winlink  *wl;
        char            *cause;
        int              idx, kflag, dflag;
 
+       if ((s = ctx->curclient->session) == NULL)
+               return (-1);
+
+       if (args_has(args, 'r'))
+       {
+               session_renumber_windows(s);
+               recalculate_sizes();
+
+               return (0);
+       }
+
        if ((wl = cmd_find_window(ctx, args_get(args, 's'), &src)) == NULL)
                return (-1);
        if ((idx = cmd_find_index(ctx, args_get(args, 't'), &dst)) == -2)

Modified: trunk/options-table.c
===================================================================
--- trunk/options-table.c       2012-05-03 17:12:38 UTC (rev 2785)
+++ trunk/options-table.c       2012-05-03 17:51:04 UTC (rev 2786)
@@ -273,6 +273,11 @@
          .default_num = KEYC_NONE,
        },
 
+       { .name = "renumber-windows",
+         .type = OPTIONS_TABLE_FLAG,
+         .default_num = 0
+       },
+
        { .name = "repeat-time",
          .type = OPTIONS_TABLE_NUMBER,
          .minimum = 0,

Modified: trunk/server-fn.c
===================================================================
--- trunk/server-fn.c   2012-05-03 17:12:38 UTC (rev 2785)
+++ trunk/server-fn.c   2012-05-03 17:51:04 UTC (rev 2786)
@@ -263,6 +263,9 @@
                        } else
                                server_redraw_session_group(s);
                }
+
+               if (options_get_number(&s->options, "renumber-windows"))
+                       session_renumber_windows(s);
        }
 }
 

Modified: trunk/session.c
===================================================================
--- trunk/session.c     2012-05-03 17:12:38 UTC (rev 2785)
+++ trunk/session.c     2012-05-03 17:51:04 UTC (rev 2786)
@@ -590,3 +590,49 @@
                winlink_remove(&old_windows, wl);
        }
 }
+
+/* Renumber the windows across winlinks attached to a specific session. */
+void
+session_renumber_windows(struct session *s)
+{
+       struct winlink          *wl, *wl1, *wl_new;
+       struct winlinks          old_wins;
+       struct winlink_stack     old_lastw;
+       int                      new_idx, new_curw_idx;
+
+       /* Save and replace old window list. */
+       memcpy(&old_wins, &s->windows, sizeof old_wins);
+       RB_INIT(&s->windows);
+
+       /* Start renumbering from the base-index if it's set. */
+       new_idx = options_get_number(&s->options, "base-index");
+       new_curw_idx = 0;
+
+       /* Go through the winlinks and assign new indexes. */
+       RB_FOREACH(wl, winlinks, &old_wins) {
+               wl_new = winlink_add(&s->windows, new_idx);
+               winlink_set_window(wl_new, wl->window);
+               wl_new->flags |= wl->flags & WINLINK_ALERTFLAGS;
+
+               if (wl == s->curw)
+                       new_curw_idx = wl_new->idx;
+
+               new_idx++;
+       }
+
+       /* Fix the stack of last windows now. */
+       memcpy(&old_lastw, &s->lastw, sizeof old_lastw);
+       TAILQ_INIT(&s->lastw);
+       TAILQ_FOREACH(wl, &old_lastw, sentry) {
+               wl_new = winlink_find_by_index(&s->windows, wl->idx);
+               if (wl_new != NULL)
+                       TAILQ_INSERT_TAIL(&s->lastw, wl_new, sentry);
+       }
+
+       /* Set the current window. */
+       s->curw = winlink_find_by_index(&s->windows, new_curw_idx);
+
+       /* Free the old winlinks (reducing window references too). */
+       RB_FOREACH_SAFE(wl, winlinks, &old_wins, wl1)
+               winlink_remove(&old_wins, wl);
+}

Modified: trunk/tmux.1
===================================================================
--- trunk/tmux.1        2012-05-03 17:12:38 UTC (rev 2785)
+++ trunk/tmux.1        2012-05-03 17:51:04 UTC (rev 2786)
@@ -1262,7 +1262,7 @@
 .Ar dst-pane
 may belong to the same window.
 .It Xo Ic move-window
-.Op Fl dk
+.Op Fl rdk
 .Op Fl s Ar src-window
 .Op Fl t Ar dst-window
 .Xc
@@ -1273,6 +1273,12 @@
 .Ar src-window
 is moved to
 .Ar dst-window .
+With
+.Fl r ,
+all windows in the session are renumbered in sequential order, respecting
+the
+.Ic base-index
+option.
 .It Xo Ic new-window
 .Op Fl adkP
 .Op Fl c Ar start-directory
@@ -2126,6 +2132,15 @@
 Set the key accepted as a prefix key.
 .It Ic prefix2 Ar key
 Set a secondary key accepted as a prefix key.
+.It Xo Ic renumber-windows
+.Op Ic on | off
+.Xc
+If on, when a window is closed in a session, automatically renumber the other
+windows in numerical order.
+This respects the
+.Ic base-index
+option if it has been set.
+If off, do not renumber the windows.
 .It Ic repeat-time Ar time
 Allow multiple commands to be entered without pressing the prefix-key again
 in the specified

Modified: trunk/tmux.h
===================================================================
--- trunk/tmux.h        2012-05-03 17:12:38 UTC (rev 2785)
+++ trunk/tmux.h        2012-05-03 17:51:04 UTC (rev 2786)
@@ -2112,6 +2112,7 @@
 void            session_group_synchronize_to(struct session *);
 void            session_group_synchronize_from(struct session *);
 void            session_group_synchronize1(struct session *, struct session *);
+void            session_renumber_windows(struct session *);
 
 /* utf8.c */
 void   utf8_build(void);

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
tmux-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmux-cvs

Reply via email to