Re: [PATCH v2 1/4] Add cmd-renumber-windows definition

2012-04-29 Thread Nicholas Marriott
Hi

This looks great, except you need to call winlink_remove on the old
winlink to remove the old win ref count and free the winlink. Also no
point in the function returning an error that is never used or checking
that s is NULL when it never can be :-).

Going to go with this, minor tweaks only:

Index: cmd-move-window.c
===
RCS file: /cvs/src/usr.bin/tmux/cmd-move-window.c,v
retrieving revision 1.10
diff -u -p -r1.10 cmd-move-window.c
--- cmd-move-window.c   4 Jan 2011 00:42:47 -   1.10
+++ cmd-move-window.c   29 Apr 2012 08:15:39 -
@@ -30,8 +30,8 @@ int   cmd_move_window_exec(struct cmd *, s
 
 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,10 +42,21 @@ int
 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);
Index: options-table.c
===
RCS file: /cvs/src/usr.bin/tmux/options-table.c,v
retrieving revision 1.28
diff -u -p -r1.28 options-table.c
--- options-table.c 23 Apr 2012 22:23:14 -  1.28
+++ options-table.c 29 Apr 2012 08:15:40 -
@@ -274,6 +274,11 @@ const struct options_table_entry session
  .default_num = KEYC_NONE,
},
 
+   { .name = "renumber-windows",
+ .type = OPTIONS_TABLE_FLAG,
+ .default_num = 0
+   },
+
{ .name = "repeat-time",
  .type = OPTIONS_TABLE_NUMBER,
  .minimum = 0,
Index: server-fn.c
===
RCS file: /cvs/src/usr.bin/tmux/server-fn.c,v
retrieving revision 1.55
diff -u -p -r1.55 server-fn.c
--- server-fn.c 17 Mar 2012 22:35:09 -  1.55
+++ server-fn.c 29 Apr 2012 08:15:40 -
@@ -263,6 +263,9 @@ server_kill_window(struct window *w)
} else
server_redraw_session_group(s);
}
+
+   if (options_get_number(&s->options, "renumber-windows"))
+   session_renumber_windows(s);
}
 }
 
Index: session.c
===
RCS file: /cvs/src/usr.bin/tmux/session.c,v
retrieving revision 1.33
diff -u -p -r1.33 session.c
--- session.c   17 Mar 2012 22:35:09 -  1.33
+++ session.c   29 Apr 2012 08:15:40 -
@@ -591,3 +591,49 @@ session_group_synchronize1(struct sessio
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);
+}
Index: tmux.1
===

Re: [PATCH v2 1/4] Add cmd-renumber-windows definition

2012-04-29 Thread Thomas Adam
Hi,

On 29 April 2012 09:16, Nicholas Marriott  wrote:
> Hi
>
> This looks great, except you need to call winlink_remove on the old
> winlink to remove the old win ref count and free the winlink. Also no

Oops.  That'll help plug some leaks, yes.  Thanks for spotting that.

> point in the function returning an error that is never used or checking
> that s is NULL when it never can be :-).

Heh, true.  I think I might have over-tightened the belt a bit there.

> Going to go with this, minor tweaks only:

Looks fine to me, thanks.

> +       /* Free the old winlinks (reducing window references too). */
> +       RB_FOREACH_SAFE(wl, winlinks, &old_wins, wl1)
> +               winlink_remove(&old_wins, wl);
> +}

I wonder if using RB_FOREACH_SAFE() in this way is also applicable to
session_group_synchronize1() as well?  Rather than the while
(!RB_EMPTY(&old_windows)) call?  I appreciate it's an aside.

-- Thomas Adam

--
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-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users


Re: [PATCH v2 1/4] Add cmd-renumber-windows definition

2012-04-29 Thread Nicholas Marriott
Hi

RB_FOREACH_SAFE is fairly new, so yes no doubt there are a good few
places it could be used instead of manual loops.

I've applied the diff, thanks!


On Sun, Apr 29, 2012 at 05:35:28PM +0100, Thomas Adam wrote:
> Hi,
> 
> On 29 April 2012 09:16, Nicholas Marriott  wrote:
> > Hi
> >
> > This looks great, except you need to call winlink_remove on the old
> > winlink to remove the old win ref count and free the winlink. Also no
> 
> Oops.  That'll help plug some leaks, yes.  Thanks for spotting that.
> 
> > point in the function returning an error that is never used or checking
> > that s is NULL when it never can be :-).
> 
> Heh, true.  I think I might have over-tightened the belt a bit there.
> 
> > Going to go with this, minor tweaks only:
> 
> Looks fine to me, thanks.
> 
> > + ?? ?? ?? /* Free the old winlinks (reducing window references too). */
> > + ?? ?? ?? RB_FOREACH_SAFE(wl, winlinks, &old_wins, wl1)
> > + ?? ?? ?? ?? ?? ?? ?? winlink_remove(&old_wins, wl);
> > +}
> 
> I wonder if using RB_FOREACH_SAFE() in this way is also applicable to
> session_group_synchronize1() as well?  Rather than the while
> (!RB_EMPTY(&old_windows)) call?  I appreciate it's an aside.
> 
> -- Thomas Adam

--
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-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users


Re: [PATCH] Add -n argument to show-environment to specify a variable name

2012-04-29 Thread Thomas Adam
Hi,

On 22 March 2012 11:14, Nicholas Marriott  wrote:
> Hi
>
> I tweaked this a bit so the output format is the same for one or many
> variables and applied it, thanks!

Sorry to bring this up now after this patch has gone out, but I'm
curious to know if the following patch isn't more preferred when
"show-options" is given a key to look up the value for?

diff --git a/trunk/cmd-show-options.c b/trunk/cmd-show-options.c
index 3abb564..9027d90 100644
--- a/trunk/cmd-show-options.c
+++ b/trunk/cmd-show-options.c
@@ -99,7 +99,7 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
if ((o = options_find1(oo, oe->name)) == NULL)
return (0);
optval = options_table_print_entry(oe, o);
-   ctx->print(ctx, "%s %s", oe->name, optval);
+   ctx->print(ctx, "%s" optval);
} else {
for (oe = table; oe->name != NULL; oe++) {
if ((o = options_find1(oo, oe->name)) == NULL)

The idea being that if I've given an option to show-options I already
know what the key is -- I care more for finding out its *value*.
Currently I would have to do this:

tmux show-options -g status | awk '{print $2}'

Which, for other things, I can already do the whole awk thing, just by
using show-options without any parameters.

Just a thought... One guy was alluding to this on IRC earlier.

Kindly,

-- Thomas Adam

--
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-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users