buffer-limit option.

pull/1/head
Nicholas Marriott 2008-06-20 18:45:35 +00:00
parent ef1c1d5753
commit 3128de3f19
7 changed files with 38 additions and 12 deletions

View File

@ -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 $

View File

@ -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 <nicm@users.sourceforge.net>
@ -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);

View File

@ -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 <nicm@users.sourceforge.net>
@ -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");

View File

@ -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 <nicm@users.sourceforge.net>
@ -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);

3
tmux.c
View File

@ -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 <nicm@users.sourceforge.net>
@ -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");

4
tmux.h
View File

@ -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 <nicm@users.sourceforge.net>
@ -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 */

View File

@ -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 <nicm@users.sourceforge.net>
@ -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);
}