diff --git a/CHANGES b/CHANGES index ffd80f26..b9382451 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,6 @@ 20 June 2008 +* buffer-limit option to set maximum size of buffer stack. Default is 9. * Initial buffer improvements. Each session has a stack of buffers and each buffer command takes a -b option to manipulate items on the stack. If -b is omitted, the top entry is used. The following commands are currently @@ -528,4 +529,4 @@ (including mutt, emacs). No status bar yet and no key remapping or other customisation. -$Id: CHANGES,v 1.131 2008-06-20 17:31:48 nicm Exp $ +$Id: CHANGES,v 1.132 2008-06-20 18:45:35 nicm Exp $ diff --git a/cmd-set-buffer.c b/cmd-set-buffer.c index 150cbcc9..db972f8b 100644 --- a/cmd-set-buffer.c +++ b/cmd-set-buffer.c @@ -1,4 +1,4 @@ -/* $Id: cmd-set-buffer.c,v 1.1 2008-06-20 08:36:20 nicm Exp $ */ +/* $Id: cmd-set-buffer.c,v 1.2 2008-06-20 18:45:35 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -47,12 +47,14 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) { struct cmd_buffer_data *data = self->data; struct session *s; + u_int limit; if ((s = cmd_find_session(ctx, data->target)) == NULL) return; + limit = options_get_number(&s->options, "buffer-limit"); if (data->buffer == -1) - paste_add(&s->buffers, data->arg); + paste_add(&s->buffers, data->arg, limit); else { if (paste_replace(&s->buffers, data->buffer, data->arg) != 0) ctx->error(ctx, "no buffer %d", data->buffer); diff --git a/cmd-set-option.c b/cmd-set-option.c index b4b9ece0..501a94ff 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $Id: cmd-set-option.c,v 1.33 2008-06-19 23:20:45 nicm Exp $ */ +/* $Id: cmd-set-option.c,v 1.34 2008-06-20 18:45:35 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -250,6 +250,24 @@ cmd_set_option_exec(struct cmd *self, unused struct cmd_ctx *ctx) return; } options_set_number(oo, "display-time", number); + } else if (strcmp(data->option, "buffer-limit") == 0) { + if (data->value == NULL || number == -1) { + ctx->error(ctx, "invalid value"); + return; + } + if (errstr != NULL) { + ctx->error(ctx, "buffer-limit %s", errstr); + return; + } + if (number == 0) { + ctx->error(ctx, "zero buffer-limit"); + return; + } + if (number > INT_MAX) { + ctx->error(ctx, "buffer-limit too big: %u", number); + return; + } + options_set_number(oo, "buffer-limit", number); } else if (strcmp(data->option, "status-left") == 0) { if (data->value == NULL) { ctx->error(ctx, "invalid value"); diff --git a/paste.c b/paste.c index 0b50fe95..3882a260 100644 --- a/paste.c +++ b/paste.c @@ -1,4 +1,4 @@ -/* $Id: paste.c,v 1.2 2008-06-20 17:31:48 nicm Exp $ */ +/* $Id: paste.c,v 1.3 2008-06-20 18:45:35 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -97,10 +97,13 @@ paste_free_index(struct paste_stack *ps, u_int idx) } void -paste_add(struct paste_stack *ps, const char *data) +paste_add(struct paste_stack *ps, const char *data, u_int limit) { struct paste_buffer *pb; + while (ARRAY_LENGTH(ps) >= limit) + ARRAY_TRUNC(ps, 1); + pb = xmalloc(sizeof *pb); ARRAY_INSERT(ps, 0, pb); diff --git a/tmux.c b/tmux.c index 68c92675..baef9dc5 100644 --- a/tmux.c +++ b/tmux.c @@ -1,4 +1,4 @@ -/* $Id: tmux.c,v 1.65 2008-06-20 17:31:48 nicm Exp $ */ +/* $Id: tmux.c,v 1.66 2008-06-20 18:45:35 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -220,6 +220,7 @@ main(int argc, char **argv) &global_options, "status-right", "%%H:%%M %%d-%%b-%%y"); options_set_number(&global_options, "status-interval", 15); options_set_number(&global_options, "set-titles", 1); + options_set_number(&global_options, "buffer-limit", 9); if (cfg_file == NULL) { home = getenv("HOME"); diff --git a/tmux.h b/tmux.h index d61d1e60..6b72d2b9 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.158 2008-06-20 17:31:48 nicm Exp $ */ +/* $Id: tmux.h,v 1.159 2008-06-20 18:45:35 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -875,7 +875,7 @@ struct paste_buffer *paste_get_top(struct paste_stack *); struct paste_buffer *paste_get_index(struct paste_stack *, u_int); int paste_free_top(struct paste_stack *); int paste_free_index(struct paste_stack *, u_int); -void paste_add(struct paste_stack *, const char *); +void paste_add(struct paste_stack *, const char *, u_int); int paste_replace(struct paste_stack *, u_int, const char *); /* arg.c */ diff --git a/window-copy.c b/window-copy.c index 39f3bb6e..fc5708b0 100644 --- a/window-copy.c +++ b/window-copy.c @@ -1,4 +1,4 @@ -/* $Id: window-copy.c,v 1.20 2008-06-20 17:31:48 nicm Exp $ */ +/* $Id: window-copy.c,v 1.21 2008-06-20 18:45:35 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -362,7 +362,7 @@ window_copy_copy_selection(struct window *w, struct client *c) struct screen *s = &data->screen; char *buf; size_t len, off; - u_int i, xx, yy, sx, sy, ex, ey; + u_int i, xx, yy, sx, sy, ex, ey, limit; if (!s->sel.flag) return; @@ -415,7 +415,8 @@ window_copy_copy_selection(struct window *w, struct client *c) buf[off - 1] = '\0'; /* Add the buffer to the stack. */ - paste_add(&c->session->buffers, buf); + limit = options_get_number(&c->session->options, "buffer-limit"); + paste_add(&c->session->buffers, buf, limit); xfree(buf); }