summaryrefslogtreecommitdiffstats
path: root/cmd-set-buffer.c
diff options
context:
space:
mode:
authornicm <nicm>2015-09-11 14:41:50 +0000
committernicm <nicm>2015-09-11 14:41:50 +0000
commita3de5dbab1680528d622a5054075e3d8efced795 (patch)
tree1417f7b21aea11c4911a5f95d1de02f3faa079a6 /cmd-set-buffer.c
parentcfabe30becba6f0c54035a29ee61a6a7f3d0cf60 (diff)
Merge delete-buffer into cmd-set-buffer.c and change the paste buffer
API so it has one paste_free() rather than free_top and free_name (everywhere that uses it already has the right pointer).
Diffstat (limited to 'cmd-set-buffer.c')
-rw-r--r--cmd-set-buffer.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/cmd-set-buffer.c b/cmd-set-buffer.c
index 4fa7ca11..01afa774 100644
--- a/cmd-set-buffer.c
+++ b/cmd-set-buffer.c
@@ -24,7 +24,7 @@
#include "tmux.h"
/*
- * Add, set, or append to a paste buffer.
+ * Add, set, append to or delete a paste buffer.
*/
enum cmd_retval cmd_set_buffer_exec(struct cmd *, struct cmd_q *);
@@ -37,6 +37,14 @@ const struct cmd_entry cmd_set_buffer_entry = {
cmd_set_buffer_exec
};
+const struct cmd_entry cmd_delete_buffer_entry = {
+ "delete-buffer", "deleteb",
+ "b:", 0, 0,
+ CMD_BUFFER_USAGE,
+ 0,
+ cmd_set_buffer_exec
+};
+
enum cmd_retval
cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
{
@@ -46,31 +54,31 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
const char *bufname, *olddata;
size_t bufsize, newsize;
- bufname = NULL;
+ bufname = args_get(args, 'b');
+ if (bufname == NULL)
+ pb = paste_get_top(&bufname);
+ else
+ pb = paste_get_name(bufname);
- if (args_has(args, 'n')) {
- if (args->argc > 0) {
- cmdq_error(cmdq, "don't provide data with n flag");
+ if (self->entry == &cmd_delete_buffer_entry) {
+ if (pb == NULL) {
+ cmdq_error(cmdq, "no buffer");
return (CMD_RETURN_ERROR);
}
+ paste_free(pb);
+ return (CMD_RETURN_NORMAL);
+ }
- if (args_has(args, 'b'))
- bufname = args_get(args, 'b');
-
- if (bufname == NULL) {
- pb = paste_get_top(&bufname);
- if (pb == NULL) {
- cmdq_error(cmdq, "no buffer");
- return (CMD_RETURN_ERROR);
- }
+ if (args_has(args, 'n')) {
+ if (pb == NULL) {
+ cmdq_error(cmdq, "no buffer");
+ return (CMD_RETURN_ERROR);
}
-
if (paste_rename(bufname, args_get(args, 'n'), &cause) != 0) {
cmdq_error(cmdq, "%s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
-
return (CMD_RETURN_NORMAL);
}
@@ -78,19 +86,11 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
cmdq_error(cmdq, "no data specified");
return (CMD_RETURN_ERROR);
}
- pb = NULL;
-
- bufsize = 0;
- bufdata = NULL;
-
if ((newsize = strlen(args->argv[0])) == 0)
return (CMD_RETURN_NORMAL);
- if (args_has(args, 'b')) {
- bufname = args_get(args, 'b');
- pb = paste_get_name(bufname);
- } else if (args_has(args, 'a'))
- pb = paste_get_top(&bufname);
+ bufsize = 0;
+ bufdata = NULL;
if (args_has(args, 'a') && pb != NULL) {
olddata = paste_buffer_data(pb, &bufsize);