summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/actions.c24
-rw-r--r--src/data.h2
-rw-r--r--src/history.c12
-rw-r--r--src/main.c1
4 files changed, 39 insertions, 0 deletions
diff --git a/src/actions.c b/src/actions.c
index 66ea755..702c419 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -72,6 +72,8 @@ static cmdret * set_framesels (struct cmdarg **args);
static cmdret * set_maxundos (struct cmdarg **args);
static cmdret * set_infofmt (struct cmdarg **args);
static cmdret * set_topkmap (struct cmdarg **args);
+static cmdret * set_historysize (struct cmdarg **args);
+static cmdret * set_historycompaction (struct cmdarg **args);
LIST_HEAD(set_vars);
@@ -138,6 +140,8 @@ init_set_vars(void)
add_set_var ("framesels", set_framesels, 1, "", arg_STRING);
add_set_var ("infofmt", set_infofmt, 1, "", arg_REST);
add_set_var ("topkmap", set_topkmap, 1, "", arg_STRING);
+ add_set_var ("historysize", set_historysize, 1, "", arg_NUMBER);
+ add_set_var ("historycompaction", set_historycompaction, 1, "", arg_NUMBER);
}
/* rp_keymaps is ratpoison's list of keymaps. */
@@ -3581,6 +3585,26 @@ update_all_gcs (void)
#endif
static cmdret *
+set_historysize (struct cmdarg **args)
+{
+ if (args[0] == NULL)
+ return cmdret_new (RET_SUCCESS, "%d", defaults.history_size);
+
+ defaults.history_size = ARG(0, number);
+ return cmdret_new (RET_SUCCESS, NULL);
+}
+
+static cmdret *
+set_historycompaction (struct cmdarg **args)
+{
+ if (args[0] == NULL)
+ return cmdret_new (RET_SUCCESS, "%d", defaults.history_compaction);
+
+ defaults.history_compaction = ARG(0, number);
+ return cmdret_new (RET_SUCCESS, NULL);
+}
+
+static cmdret *
set_font (struct cmdarg **args)
{
#ifdef USE_XFT_FONT
diff --git a/src/data.h b/src/data.h
index 10a0f1c..318e61c 100644
--- a/src/data.h
+++ b/src/data.h
@@ -259,6 +259,8 @@ struct rp_defaults
int warp;
int history_size;
+ /* remove older history when adding the same again */
+ int history_compaction;
char *frame_selectors;
diff --git a/src/history.c b/src/history.c
index bc6baa5..a04d580 100644
--- a/src/history.c
+++ b/src/history.c
@@ -228,6 +228,18 @@ history_add_upto (int history_id, const char *item, size_t max)
history_add_upto (hist_SHELLCMD, p, max);
}
+ if (defaults.history_compaction && max != INT_MAX) {
+ struct list_head *l;
+
+ for (l = h->head.prev ; l != &h->head ; l = l->prev) {
+ if (!strcmp (list_entry(l, struct history_item, node)->line, item)) {
+ list_del (l);
+ list_add_tail (l, &h->head);
+ return;
+ }
+ }
+ }
+
while (h->count >= max) {
list_first (i, &h->head, node);
if (!i) {
diff --git a/src/main.c b/src/main.c
index 919f4ca..bb9fb7f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -563,6 +563,7 @@ init_defaults (void)
defaults.window_list_style = STYLE_COLUMN;
defaults.history_size = 20;
+ defaults.history_compaction = True;
defaults.frame_selectors = xstrdup ("");
defaults.maxundos = 20;
}