From 7cdcbc15ac4025ccea3280904ee4c26deec94d3a Mon Sep 17 00:00:00 2001 From: Marco Peereboom Date: Wed, 24 Aug 2011 18:47:02 +0000 Subject: generalize history and remove debug cruft --- xxxterm.c | 76 +++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/xxxterm.c b/xxxterm.c index e88c00f..d74b66b 100644 --- a/xxxterm.c +++ b/xxxterm.c @@ -883,22 +883,22 @@ void completion_add(struct tab *); void completion_add_uri(const gchar *); void -cmd_history_delete(void) +cmd_history_delete(struct command_list *l) { struct command_entry *c; - c = TAILQ_LAST(&chl, command_list); + c = TAILQ_LAST(l, command_list); if (c == NULL) return; - TAILQ_REMOVE(&chl, c, entry); + TAILQ_REMOVE(l, c, entry); cmd_history_count--; g_free(c->line); g_free(c); } void -cmd_history_add(char *l) +cmd_history_add(struct command_list *list, char *l) { struct command_entry *c; @@ -906,24 +906,19 @@ cmd_history_add(char *l) return; /* don't add the same line */ - c = TAILQ_FIRST(&chl); - fprintf(stderr, "c %p\n", c); - if (c) { - fprintf(stderr, "s %s %s\n", c->line, l); - if (!strcmp(c->line + 1 /* skip : */, l)) { - fprintf(stderr, "skip %s %s\n", c->line, l); + c = TAILQ_FIRST(list); + if (c) + if (!strcmp(c->line + 1 /* skip : */, l)) return; - } - } c = g_malloc0(sizeof *c); c->line = g_strdup_printf(":%s", l); cmd_history_count++; - TAILQ_INSERT_HEAD(&chl, c, entry); + TAILQ_INSERT_HEAD(list, c, entry); if (cmd_history_count > 1000) - cmd_history_delete(); + cmd_history_delete(list); } /* marks and quickmarks array storage. @@ -7958,6 +7953,34 @@ entry_key_cb(GtkEntry *w, GdkEventKey *e, struct tab *t) return (handle_keypress(t, e, 1)); } +struct command_entry * +history_prev(struct command_list *l, struct command_entry *at) +{ + if (at == NULL) + at = TAILQ_LAST(l, command_list); + else { + at = TAILQ_PREV(at, command_list, entry); + if (at == NULL) + at = TAILQ_LAST(l, command_list); + } + + return (at); +} + +struct command_entry * +history_next(struct command_list *l, struct command_entry *at) +{ + if (at == NULL) + at = TAILQ_FIRST(l); + else { + at = TAILQ_NEXT(at, entry); + if (at == NULL) + at = TAILQ_FIRST(l); + } + + return (at); +} + int cmd_keypress_cb(GtkEntry *w, GdkEventKey *e, struct tab *t) { @@ -7996,36 +8019,21 @@ cmd_keypress_cb(GtkEntry *w, GdkEventKey *e, struct tab *t) if (c[0] != ':') goto done; - if (history_at == NULL) - history_at = TAILQ_LAST(&chl, command_list); - else { - history_at = TAILQ_PREV(history_at, command_list, - entry); - if (history_at == NULL) - history_at = TAILQ_LAST(&chl, command_list); - } - - if (history_at) { + if ((history_at = history_prev(&chl, history_at))) { gtk_entry_set_text(w, history_at->line); gtk_editable_set_position(GTK_EDITABLE(w), -1); } + goto done; case GDK_Up: if (c[0] != ':') goto done; - if (history_at == NULL) - history_at = TAILQ_FIRST(&chl); - else { - history_at = TAILQ_NEXT(history_at, entry); - if (history_at == NULL) - history_at = TAILQ_FIRST(&chl); - } - - if (history_at) { + if ((history_at = history_next(&chl, history_at))) { gtk_entry_set_text(w, history_at->line); gtk_editable_set_position(GTK_EDITABLE(w), -1); } + goto done; case GDK_BackSpace: if (!(!strcmp(c, ":") || !strcmp(c, "/") || !strcmp(c, "?"))) @@ -8129,7 +8137,7 @@ cmd_activate_cb(GtkEntry *entry, struct tab *t) cmd_execute(t, s); - cmd_history_add(s); + cmd_history_add(&chl, s); done: return; } -- cgit 1.4.1-2-gfad0 ' href='/akspecs/ranger/commit/doc/ranger.gui.widgets.titlebar.html?h=v1.6.0&id=f07bb12fc5c59430e995a64956b36331ce3629b9'>f07bb12f ^
ef0157ff ^
f07bb12f ^






ef0157ff ^
4c13e1f2 ^


f07bb12f ^







f07bb12f ^










f07bb12f ^









4c13e1f2 ^
f07bb12f ^
ef0157ff ^
f07bb12f ^


c9383c72 ^

a614f048 ^

f07bb12f ^

c9383c72 ^

f07bb12f ^

c9383c72 ^

f07bb12f ^







c9383c72 ^

f07bb12f ^



62cd83ba ^

f07bb12f ^
4c13e1f2 ^
f07bb12f ^
f07bb12f ^

4c13e1f2 ^

4c13e1f2 ^

f07bb12f ^
4c13e1f2 ^
f07bb12f ^












f07bb12f ^















4c13e1f2 ^




34a60763 ^
4c13e1f2 ^
34a60763 ^
4c13e1f2 ^



f07bb12f ^
62cd83ba ^
f07bb12f ^
c9383c72 ^
f07bb12f ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134