The branch, master has been updated
       via  8c0edcbfa3bd78bb8adaba13aad29a06d8988de8 (commit)
       via  b7f6356053638188a162df0d1912a6317e9d593d (commit)
      from  b65c72c45c79c3f1fea6446c83f6ac47e813a52a (commit)

- Log -----------------------------------------------------------------
commit 8c0edcbfa3bd78bb8adaba13aad29a06d8988de8
Author: Nicholas Marriott <nicholas.marri...@gmail.com>
Commit: Nicholas Marriott <nicholas.marri...@gmail.com>

    Add setb -a to append and a copy mode append command, from J Raynor with 
minor
    changes.
---
 cmd-set-buffer.c |   65 ++++++++++++++++++++++++++++++++---------------------
 mode-key.c       |    2 +
 paste.c          |    2 +-
 tmux.1           |    5 ++++
 tmux.h           |    1 +
 window-copy.c    |   48 +++++++++++++++++++++++++++++++++++++++
 6 files changed, 96 insertions(+), 27 deletions(-)

diff --git a/cmd-set-buffer.c b/cmd-set-buffer.c
index fade4fe..30a137c 100644
--- a/cmd-set-buffer.c
+++ b/cmd-set-buffer.c
@@ -24,15 +24,15 @@
 #include "tmux.h"
 
 /*
- * Add or set a paste buffer.
+ * Add, set, or append to a paste buffer.
  */
 
 enum cmd_retval         cmd_set_buffer_exec(struct cmd *, struct cmd_q *);
 
 const struct cmd_entry cmd_set_buffer_entry = {
        "set-buffer", "setb",
-       "b:", 1, 1,
-       CMD_BUFFER_USAGE " data",
+       "ab:", 1, 1,
+       "[-a] " CMD_BUFFER_USAGE " data",
        0,
        NULL,
        cmd_set_buffer_exec
@@ -41,35 +41,48 @@ const struct cmd_entry cmd_set_buffer_entry = {
 enum cmd_retval
 cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
 {
-       struct args     *args = self->args;
-       u_int            limit;
-       char            *pdata, *cause;
-       size_t           psize;
-       int              buffer;
+       struct args             *args = self->args;
+       struct paste_buffer     *pb;
+       u_int                    limit;
+       char                    *pdata, *cause;
+       size_t                   psize, newsize;
+       int                      buffer;
 
        limit = options_get_number(&global_options, "buffer-limit");
 
-       pdata = xstrdup(args->argv[0]);
-       psize = strlen(pdata);
+       psize = 0;
+       pdata = NULL;
 
-       if (!args_has(args, 'b')) {
-               paste_add(&global_buffers, pdata, psize, limit);
-               return (CMD_RETURN_NORMAL);
-       }
+       if (args_has(args, 'b')) {
+               buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
+               if (cause != NULL) {
+                       cmdq_error(cmdq, "buffer %s", cause);
+                       free(cause);
+                       return (CMD_RETURN_ERROR);
+               }
+               pb = paste_get_index(&global_buffers, buffer);
+               if (pb == NULL) {
+                       cmdq_error(cmdq, "no buffer %d", buffer);
+                       return (CMD_RETURN_ERROR);
+               }
+               if (args_has(args, 'a')) {
+                       psize = pb->size;
+                       pdata = xmalloc(psize);
+                       memcpy(pdata, pb->data, psize);
+               }
+       } else
+               buffer = -1;
+
+       newsize = strlen(args->argv[0]);
 
-       buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
-       if (cause != NULL) {
-               cmdq_error(cmdq, "buffer %s", cause);
-               free(cause);
-               free(pdata);
-               return (CMD_RETURN_ERROR);
-       }
+       pdata = xrealloc(pdata, 1, psize + newsize);
+       memcpy(pdata + psize, args->argv[0], newsize);
+       psize += newsize;
 
-       if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) {
-               cmdq_error(cmdq, "no buffer %d", buffer);
-               free(pdata);
-               return (CMD_RETURN_ERROR);
-       }
+       if (buffer == -1)
+               paste_add(&global_buffers, pdata, psize, limit);
+       else
+               paste_replace(&global_buffers, buffer, pdata, psize);
 
        return (CMD_RETURN_NORMAL);
 }
diff --git a/mode-key.c b/mode-key.c
index 5a68bc7..57be2d8 100644
--- a/mode-key.c
+++ b/mode-key.c
@@ -100,6 +100,7 @@ const struct mode_key_cmdstr mode_key_cmdstr_choice[] = {
 
 /* Copy keys command strings. */
 const struct mode_key_cmdstr mode_key_cmdstr_copy[] = {
+       { MODEKEYCOPY_APPENDSELECTION, "append-selection" },
        { MODEKEYCOPY_BACKTOINDENTATION, "back-to-indentation" },
        { MODEKEYCOPY_BOTTOMLINE, "bottom-line" },
        { MODEKEYCOPY_CANCEL, "cancel" },
@@ -272,6 +273,7 @@ const struct mode_key_entry mode_key_vi_copy[] = {
        { '9',                      0, MODEKEYCOPY_STARTNUMBERPREFIX },
        { ':',                      0, MODEKEYCOPY_GOTOLINE },
        { '?',                      0, MODEKEYCOPY_SEARCHUP },
+       { 'A',                      0, MODEKEYCOPY_APPENDSELECTION },
        { 'B',                      0, MODEKEYCOPY_PREVIOUSSPACE },
        { 'D',                      0, MODEKEYCOPY_COPYENDOFLINE },
        { 'E',                      0, MODEKEYCOPY_NEXTSPACEEND },
diff --git a/paste.c b/paste.c
index bc9b468..28f1230 100644
--- a/paste.c
+++ b/paste.c
@@ -171,7 +171,7 @@ paste_print(struct paste_buffer *pb, size_t width)
 
 /* Paste into a window pane, filtering '\n' according to separator. */
 void
-paste_send_pane (struct paste_buffer *pb, struct window_pane *wp,
+paste_send_pane(struct paste_buffer *pb, struct window_pane *wp,
     const char *sep, int bracket)
 {
        const char      *data = pb->data, *end = data + pb->size, *lf;
diff --git a/tmux.1 b/tmux.1
index c9e5815..4d09052 100644
--- a/tmux.1
+++ b/tmux.1
@@ -855,6 +855,7 @@ option).
 The following keys are supported as appropriate for the mode:
 .Bl -column "FunctionXXXXXXXXXXXXXXXXX" "viXXXXXXXXXX" "emacs" -offset indent
 .It Sy "Function" Ta Sy "vi" Ta Sy "emacs"
+.It Li "Append selection" Ta "A" Ta ""
 .It Li "Back to indentation" Ta "^" Ta "M-m"
 .It Li "Bottom of history" Ta "G" Ta "M-<"
 .It Li "Clear selection" Ta "Escape" Ta "C-g"
@@ -3548,12 +3549,16 @@ The
 .Fl a
 option appends to rather than overwriting the file.
 .It Xo Ic set-buffer
+.Op Fl a
 .Op Fl b Ar buffer-index
 .Ar data
 .Xc
 .D1 (alias: Ic setb )
 Set the contents of the specified buffer to
 .Ar data .
+The
+.Fl a
+option appends to rather than overwriting the buffer.
 .It Xo Ic show-buffer
 .Op Fl b Ar buffer-index
 .Xc
diff --git a/tmux.h b/tmux.h
index fb2fb94..68790a0 100644
--- a/tmux.h
+++ b/tmux.h
@@ -537,6 +537,7 @@ enum mode_key_cmd {
        MODEKEYCHOICE_UP,
 
        /* Copy keys. */
+       MODEKEYCOPY_APPENDSELECTION,
        MODEKEYCOPY_BACKTOINDENTATION,
        MODEKEYCOPY_BOTTOMLINE,
        MODEKEYCOPY_CANCEL,
diff --git a/window-copy.c b/window-copy.c
index 527c95c..e3164f6 100644
--- a/window-copy.c
+++ b/window-copy.c
@@ -58,6 +58,7 @@ void  window_copy_copy_buffer(struct window_pane *, int, void 
*, size_t);
 void   window_copy_copy_pipe(
            struct window_pane *, struct session *, int, const char *);
 void   window_copy_copy_selection(struct window_pane *, int);
+void   window_copy_append_selection(struct window_pane *, int);
 void   window_copy_clear_selection(struct window_pane *);
 void   window_copy_copy_line(
            struct window_pane *, char **, size_t *, u_int, u_int, u_int);
@@ -414,6 +415,13 @@ window_copy_key(struct window_pane *wp, struct session 
*sess, int key)
 
        cmd = mode_key_lookup(&data->mdata, key, &arg);
        switch (cmd) {
+       case MODEKEYCOPY_APPENDSELECTION:
+               if (sess != NULL) {
+                       window_copy_append_selection(wp, data->numprefix);
+                       window_pane_reset_mode(wp);
+                       return;
+               }
+               break;
        case MODEKEYCOPY_CANCEL:
                window_pane_reset_mode(wp);
                return;
@@ -1492,6 +1500,46 @@ window_copy_copy_selection(struct window_pane *wp, int 
idx)
 }
 
 void
+window_copy_append_selection(struct window_pane *wp, int idx)
+{
+       char                    *buf;
+       struct paste_buffer     *pb;
+       size_t                   len;
+       u_int                    limit;
+       struct screen_write_ctx  ctx;
+
+       buf = window_copy_get_selection(wp, &len);
+       if (buf == NULL)
+               return;
+
+       if (options_get_number(&global_options, "set-clipboard")) {
+               screen_write_start(&ctx, wp, NULL);
+               screen_write_setselection(&ctx, buf, len);
+               screen_write_stop(&ctx);
+       }
+
+       if (idx == -1)
+               idx = 0;
+
+       if (idx == 0 && paste_get_top(&global_buffers) == NULL) {
+               limit = options_get_number(&global_options, "buffer-limit");
+               paste_add(&global_buffers, buf, len, limit);
+               return;
+       }
+
+       pb = paste_get_index(&global_buffers, idx);
+       if (pb != NULL) {
+               buf = xrealloc(buf, 1, len + pb->size);
+               memmove(buf + pb->size, buf, len);
+               memcpy(buf, pb->data, pb->size);
+               len += pb->size;
+       }
+
+       if (paste_replace(&global_buffers, idx, buf, len) != 0)
+               free(buf);
+}
+
+void
 window_copy_copy_line(struct window_pane *wp,
     char **buf, size_t *off, u_int sy, u_int sx, u_int ex)
 {


commit b7f6356053638188a162df0d1912a6317e9d593d
Author: Nicholas Marriott <nicholas.marri...@gmail.com>
Commit: Nicholas Marriott <nicholas.marri...@gmail.com>

    Make session_attached a count and add session_many_attached flag.
---
 format.c |    6 ++----
 resize.c |    2 ++
 tmux.1   |    3 ++-
 tmux.h   |    2 ++
 4 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/format.c b/format.c
index 10ac613..497b5b5 100644
--- a/format.c
+++ b/format.c
@@ -401,10 +401,8 @@ format_session(struct format_tree *ft, struct session *s)
        *strchr(tim, '\n') = '\0';
        format_add(ft, "session_created_string", "%s", tim);
 
-       if (s->flags & SESSION_UNATTACHED)
-               format_add(ft, "session_attached", "%d", 0);
-       else
-               format_add(ft, "session_attached", "%d", 1);
+       format_add(ft, "session_attached", "%u", s->attached);
+       format_add(ft, "session_many_attached", "%u", s->attached > 1);
 }
 
 /* Set default format keys for a client. */
diff --git a/resize.c b/resize.c
index 8d0bd27..b3b031c 100644
--- a/resize.c
+++ b/resize.c
@@ -55,6 +55,7 @@ recalculate_sizes(void)
        RB_FOREACH(s, sessions, &sessions) {
                has_status = options_get_number(&s->options, "status");
 
+               s->attached = 0;
                ssx = ssy = UINT_MAX;
                for (j = 0; j < ARRAY_LENGTH(&clients); j++) {
                        c = ARRAY_ITEM(&clients, j);
@@ -69,6 +70,7 @@ recalculate_sizes(void)
                                        ssy = c->tty.sy - 1;
                                else if (c->tty.sy < ssy)
                                        ssy = c->tty.sy;
+                               s->attached++;
                        }
                }
                if (ssx == UINT_MAX || ssy == UINT_MAX) {
diff --git a/tmux.1 b/tmux.1
index 51d927a..c9e5815 100644
--- a/tmux.1
+++ b/tmux.1
@@ -3141,13 +3141,14 @@ The following variables are available, where 
appropriate:
 .It Li "saved_cursor_y" Ta "" Ta "Saved cursor Y in pane"
 .It Li "scroll_region_lower" Ta "" Ta "Bottom of scroll region in pane"
 .It Li "scroll_region_upper" Ta "" Ta "Top of scroll region in pane"
-.It Li "session_attached" Ta "" Ta "1 if session attached"
+.It Li "session_attached" Ta "" Ta "Number of clients session is attached to"
 .It Li "session_created" Ta "" Ta "Integer time session created"
 .It Li "session_created_string" Ta "" Ta "String time session created"
 .It Li "session_group" Ta "" Ta "Number of session group"
 .It Li "session_grouped" Ta "" Ta "1 if session in a group"
 .It Li "session_height" Ta "" Ta "Height of session"
 .It Li "session_id" Ta "" Ta "Unique session ID"
+.It Li "session_many_attached" Ta "" Ta "1 if multiple clients attached"
 .It Li "session_name" Ta "#S" Ta "Name of session"
 .It Li "session_width" Ta "" Ta "Width of session"
 .It Li "session_windows" Ta "" Ta "Number of windows in session"
diff --git a/tmux.h b/tmux.h
index 0a6ca4e..fb2fb94 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1083,6 +1083,8 @@ struct session {
 #define SESSION_UNATTACHED 0x1 /* not attached to any clients */
        int              flags;
 
+       u_int            attached;
+
        struct termios  *tio;
 
        struct environ   environ;


-----------------------------------------------------------------------

Summary of changes:
 cmd-set-buffer.c |   65 ++++++++++++++++++++++++++++++++---------------------
 format.c         |    6 +---
 mode-key.c       |    2 +
 paste.c          |    2 +-
 resize.c         |    2 +
 tmux.1           |    8 +++++-
 tmux.h           |    3 ++
 window-copy.c    |   48 +++++++++++++++++++++++++++++++++++++++
 8 files changed, 104 insertions(+), 32 deletions(-)


hooks/post-receive
-- 
tmux

------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
tmux-cvs mailing list
tmux-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-cvs

Reply via email to