Revision: 2669
          http://tmux.svn.sourceforge.net/tmux/?rev=2669&view=rev
Author:   tcunha
Date:     2012-01-21 19:36:40 +0000 (Sat, 21 Jan 2012)
Log Message:
-----------
Sync OpenBSD patchset 1007:

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).

Modified Paths:
--------------
    trunk/cmd-send-prefix.c
    trunk/cmd-set-option.c
    trunk/key-string.c
    trunk/options-table.c
    trunk/options.c
    trunk/server-client.c
    trunk/tmux.1
    trunk/tmux.c
    trunk/tmux.h

Modified: trunk/cmd-send-prefix.c
===================================================================
--- trunk/cmd-send-prefix.c     2012-01-21 19:33:45 UTC (rev 2668)
+++ trunk/cmd-send-prefix.c     2012-01-21 19:36:40 UTC (rev 2669)
@@ -28,8 +28,8 @@
 
 const struct cmd_entry cmd_send_prefix_entry = {
        "send-prefix", NULL,
-       "t:", 0, 0,
-       CMD_TARGET_PANE_USAGE,
+       "2t:", 0, 0,
+       "[-2] " CMD_TARGET_PANE_USAGE,
        0,
        NULL,
        NULL,
@@ -42,13 +42,16 @@
        struct args             *args = self->args;
        struct session          *s;
        struct window_pane      *wp;
-       struct keylist          *keylist;
+       int                      key;
 
        if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
                return (-1);
 
-       keylist = options_get_data(&s->options, "prefix");
-       window_pane_key(wp, s, ARRAY_FIRST(keylist));
+       if (args_has(args, '2'))
+               key = options_get_number(&s->options, "prefix2");
+       else
+               key = options_get_number(&s->options, "prefix");
+       window_pane_key(wp, s, key);
 
        return (0);
 }

Modified: trunk/cmd-set-option.c
===================================================================
--- trunk/cmd-set-option.c      2012-01-21 19:33:45 UTC (rev 2668)
+++ trunk/cmd-set-option.c      2012-01-21 19:36:40 UTC (rev 2669)
@@ -45,7 +45,7 @@
 struct options_entry *cmd_set_option_number(struct cmd *, struct cmd_ctx *,
            const struct options_table_entry *, struct options *,
            const char *);
-struct options_entry *cmd_set_option_keys(struct cmd *, struct cmd_ctx *,
+struct options_entry *cmd_set_option_key(struct cmd *, struct cmd_ctx *,
            const struct options_table_entry *, struct options *,
            const char *);
 struct options_entry *cmd_set_option_colour(struct cmd *, struct cmd_ctx *,
@@ -236,8 +236,8 @@
        case OPTIONS_TABLE_NUMBER:
                o = cmd_set_option_number(self, ctx, oe, oo, value);
                break;
-       case OPTIONS_TABLE_KEYS:
-               o = cmd_set_option_keys(self, ctx, oe, oo, value);
+       case OPTIONS_TABLE_KEY:
+               o = cmd_set_option_key(self, ctx, oe, oo, value);
                break;
        case OPTIONS_TABLE_COLOUR:
                o = cmd_set_option_colour(self, ctx, oe, oo, value);
@@ -298,31 +298,19 @@
        return (options_set_number(oo, oe->name, ll));
 }
 
-/* Set a keys option. */
+/* Set a key option. */
 struct options_entry *
-cmd_set_option_keys(unused struct cmd *self, struct cmd_ctx *ctx,
+cmd_set_option_key(unused struct cmd *self, struct cmd_ctx *ctx,
     const struct options_table_entry *oe, struct options *oo, const char 
*value)
 {
-       struct keylist  *keylist;
-       char            *copy, *ptr, *s;
-       int              key;
+       int     key;
 
-       keylist = xmalloc(sizeof *keylist);
-       ARRAY_INIT(keylist);
-
-       ptr = copy = xstrdup(value);
-       while ((s = strsep(&ptr, ",")) != NULL) {
-               if ((key = key_string_lookup_string(s)) == KEYC_NONE) {
-                       ctx->error(ctx, "unknown key: %s", s);
-                       xfree(copy);
-                       xfree(keylist);
-                       return (NULL);
-               }
-               ARRAY_ADD(keylist, key);
+       if ((key = key_string_lookup_string(value)) == KEYC_NONE) {
+               ctx->error(ctx, "bad key: %s", value);
+               return (NULL);
        }
-       xfree(copy);
 
-       return (options_set_data(oo, oe->name, keylist, xfree));
+       return (options_set_number(oo, oe->name, key));
 }
 
 /* Set a colour option. */

Modified: trunk/key-string.c
===================================================================
--- trunk/key-string.c  2012-01-21 19:33:45 UTC (rev 2668)
+++ trunk/key-string.c  2012-01-21 19:36:40 UTC (rev 2669)
@@ -188,6 +188,10 @@
 
        *out = '\0';
 
+       /* Handle no key. */
+       if (key == KEYC_NONE)
+               return ("none");
+
        /*
         * Special case: display C-@ as C-Space. Could do this below in
         * the (key >= 0 && key <= 32), but this way we let it be found

Modified: trunk/options-table.c
===================================================================
--- trunk/options-table.c       2012-01-21 19:33:45 UTC (rev 2668)
+++ trunk/options-table.c       2012-01-21 19:36:40 UTC (rev 2669)
@@ -261,10 +261,15 @@
        },
 
        { .name = "prefix",
-         .type = OPTIONS_TABLE_KEYS,
-         /* set in main() */
+         .type = OPTIONS_TABLE_KEY,
+         .default_num = '\002',
        },
 
+       { .name = "prefix2",
+         .type = OPTIONS_TABLE_KEY,
+         .default_num = KEYC_NONE,
+       },
+
        { .name = "repeat-time",
          .type = OPTIONS_TABLE_NUMBER,
          .minimum = 0,
@@ -682,10 +687,8 @@
 options_table_print_entry(
     const struct options_table_entry *oe, struct options_entry *o)
 {
-       static char                              out[BUFSIZ];
-       const char                              *s;
-       struct keylist                          *keylist;
-       u_int                                    i;
+       static char      out[BUFSIZ];
+       const char      *s;
 
        *out = '\0';
        switch (oe->type) {
@@ -695,14 +698,8 @@
        case OPTIONS_TABLE_NUMBER:
                xsnprintf(out, sizeof out, "%lld", o->num);
                break;
-       case OPTIONS_TABLE_KEYS:
-               keylist = o->data;
-               for (i = 0; i < ARRAY_LENGTH(keylist); i++) {
-                       s = key_string_lookup_key(ARRAY_ITEM(keylist, i));
-                       strlcat(out, s, sizeof out);
-                       if (i != ARRAY_LENGTH(keylist) - 1)
-                               strlcat(out, ",", sizeof out);
-               }
+       case OPTIONS_TABLE_KEY:
+               xsnprintf(out, sizeof out, "%s", key_string_lookup_key(o->num));
                break;
        case OPTIONS_TABLE_COLOUR:
                s = colour_tostring(o->num);

Modified: trunk/options.c
===================================================================
--- trunk/options.c     2012-01-21 19:33:45 UTC (rev 2668)
+++ trunk/options.c     2012-01-21 19:36:40 UTC (rev 2669)
@@ -54,8 +54,6 @@
                xfree(o->name);
                if (o->type == OPTIONS_STRING)
                        xfree(o->str);
-               else if (o->type == OPTIONS_DATA)
-                       o->freefn(o->data);
                xfree(o);
        }
 }
@@ -97,8 +95,6 @@
        xfree(o->name);
        if (o->type == OPTIONS_STRING)
                xfree(o->str);
-       else if (o->type == OPTIONS_DATA)
-               o->freefn(o->data);
        xfree(o);
 }
 
@@ -114,8 +110,6 @@
                SPLAY_INSERT(options_tree, &oo->tree, o);
        } else if (o->type == OPTIONS_STRING)
                xfree(o->str);
-       else if (o->type == OPTIONS_DATA)
-               o->freefn(o->data);
 
        va_start(ap, fmt);
        o->type = OPTIONS_STRING;
@@ -147,8 +141,6 @@
                SPLAY_INSERT(options_tree, &oo->tree, o);
        } else if (o->type == OPTIONS_STRING)
                xfree(o->str);
-       else if (o->type == OPTIONS_DATA)
-               o->freefn(o->data);
 
        o->type = OPTIONS_NUMBER;
        o->num = value;
@@ -166,36 +158,3 @@
                fatalx("option not a number");
        return (o->num);
 }
-
-struct options_entry *
-options_set_data(
-    struct options *oo, const char *name, void *value, void (*freefn)(void *))
-{
-       struct options_entry    *o;
-
-       if ((o = options_find1(oo, name)) == NULL) {
-               o = xmalloc(sizeof *o);
-               o->name = xstrdup(name);
-               SPLAY_INSERT(options_tree, &oo->tree, o);
-       } else if (o->type == OPTIONS_STRING)
-               xfree(o->str);
-       else if (o->type == OPTIONS_DATA)
-               o->freefn(o->data);
-
-       o->type = OPTIONS_DATA;
-       o->data = value;
-       o->freefn = freefn;
-       return (o);
-}
-
-void *
-options_get_data(struct options *oo, const char *name)
-{
-       struct options_entry    *o;
-
-       if ((o = options_find(oo, name)) == NULL)
-               fatalx("missing option");
-       if (o->type != OPTIONS_DATA)
-               fatalx("option not data");
-       return (o->data);
-}

Modified: trunk/server-client.c
===================================================================
--- trunk/server-client.c       2012-01-21 19:33:45 UTC (rev 2668)
+++ trunk/server-client.c       2012-01-21 19:36:40 UTC (rev 2669)
@@ -272,9 +272,7 @@
        struct options          *oo;
        struct timeval           tv;
        struct key_binding      *bd;
-       struct keylist          *keylist;
        int                      xtimeout, isprefix;
-       u_int                    i;
 
        /* Check the client is good to accept input. */
        if ((c->flags & (CLIENT_DEAD|CLIENT_SUSPENDED)) != 0)
@@ -359,14 +357,12 @@
        }
 
        /* Is this a prefix key? */
-       keylist = options_get_data(&c->session->options, "prefix");
-       isprefix = 0;
-       for (i = 0; i < ARRAY_LENGTH(keylist); i++) {
-               if (key == ARRAY_ITEM(keylist, i)) {
-                       isprefix = 1;
-                       break;
-               }
-       }
+       if (key == options_get_number(&c->session->options, "prefix"))
+               isprefix = 1;
+       else if (key == options_get_number(&c->session->options, "prefix2"))
+               isprefix = 1;
+       else
+               isprefix = 0;
 
        /* No previous prefix key. */
        if (!(c->flags & CLIENT_PREFIX)) {

Modified: trunk/tmux.1
===================================================================
--- trunk/tmux.1        2012-01-21 19:33:45 UTC (rev 2668)
+++ trunk/tmux.1        2012-01-21 19:36:40 UTC (rev 2669)
@@ -1656,9 +1656,13 @@
 The
 .Fl R
 flag causes the terminal state to be reset.
-.It Ic send-prefix Op Fl t Ar target-pane
-Send the prefix key to a window as if it was pressed.
-If multiple prefix keys are configured, only the first is sent.
+.It Xo Ic send-prefix
+.Op Fl 2
+.Op Fl t Ar target-pane
+.Xc
+Send the prefix key, or with
+.Fl 2
+the secondary prefix key, to a window as if it was pressed.
 .It Xo Ic unbind-key
 .Op Fl acn
 .Op Fl t Ar key-table
@@ -2033,11 +2037,10 @@
 .It Ic pane-border-bg Ar colour
 .It Ic pane-border-fg Ar colour
 Set the pane border colour for panes aside from the active pane.
-.It Ic prefix Ar keys
-Set the keys accepted as a prefix key.
-.Ar keys
-is a comma-separated list of key names, each of which individually behave as
-the prefix key.
+.It Ic prefix Ar key
+Set the key accepted as a prefix key.
+.It Ic prefix2 Ar key
+Set a secondary key accepted as a prefix key.
 .It Ic repeat-time Ar time
 Allow multiple commands to be entered without pressing the prefix-key again
 in the specified

Modified: trunk/tmux.c
===================================================================
--- trunk/tmux.c        2012-01-21 19:33:45 UTC (rev 2668)
+++ trunk/tmux.c        2012-01-21 19:36:40 UTC (rev 2669)
@@ -235,7 +235,6 @@
 main(int argc, char **argv)
 {
        struct passwd   *pw;
-       struct keylist  *keylist;
        char            *s, *path, *label, *home, **var;
        int              opt, flags, quiet, keys;
 
@@ -335,12 +334,6 @@
        options_init(&global_w_options, NULL);
        options_table_populate_tree(window_options_table, &global_w_options);
 
-       /* Set the prefix option (its a list, so not in the table). */
-       keylist = xmalloc(sizeof *keylist);
-       ARRAY_INIT(keylist);
-       ARRAY_ADD(keylist, '\002');
-       options_set_data(&global_s_options, "prefix", keylist, xfree);
-
        /* Enable UTF-8 if the first client is on UTF-8 terminal. */
        if (flags & IDENTIFY_UTF8) {
                options_set_number(&global_s_options, "status-utf8", 1);

Modified: trunk/tmux.h
===================================================================
--- trunk/tmux.h        2012-01-21 19:33:45 UTC (rev 2668)
+++ trunk/tmux.h        2012-01-21 19:36:40 UTC (rev 2669)
@@ -669,10 +669,7 @@
 
        char            *str;
        long long        num;
-       void            *data;
 
-       void             (*freefn)(void *);
-
        SPLAY_ENTRY(options_entry) entry;
 };
 
@@ -681,9 +678,6 @@
        struct options  *parent;
 };
 
-/* Key list for prefix option. */
-ARRAY_DECL(keylist, int);
-
 /* Scheduled job. */
 struct job {
        char            *cmd;
@@ -1290,7 +1284,7 @@
 enum options_table_type {
        OPTIONS_TABLE_STRING,
        OPTIONS_TABLE_NUMBER,
-       OPTIONS_TABLE_KEYS,
+       OPTIONS_TABLE_KEY,
        OPTIONS_TABLE_COLOUR,
        OPTIONS_TABLE_ATTRIBUTES,
        OPTIONS_TABLE_FLAG,
@@ -1409,9 +1403,6 @@
 struct options_entry *options_set_number(
            struct options *, const char *, long long);
 long long options_get_number(struct options *, const char *);
-struct options_entry *options_set_data(
-           struct options *, const char *, void *, void (*)(void *));
-void   *options_get_data(struct options *, const char *);
 
 /* options-table.c */
 extern const struct options_table_entry server_options_table[];

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


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
tmux-cvs mailing list
tmux-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-cvs

Reply via email to