summaryrefslogtreecommitdiff
path: root/src/completions.c
diff options
context:
space:
mode:
authorsabetts <sabetts>2003-05-28 22:36:27 +0000
committersabetts <sabetts>2003-05-28 22:36:27 +0000
commit99d6bf980b231670ef58d12e082cfd52e0513707 (patch)
treea9c2d6dbb1810084a42969039b54123816ec15eb /src/completions.c
parentc590e039dac7c9edd4074d8e52f7928e789b5078 (diff)
downloadratpoison-99d6bf980b231670ef58d12e082cfd52e0513707.zip
* src/globals.h (COMPLETION_NEXT): new define
(COMPLETION_PREVIOUS): likewise * src/editor.c (editor_complete): remove prototype (editor_complete_prev): new prototype (editor_complete_next): likewise (editor_insert): make it a static function. update prototype (edit_bindings): add editor_complete_prev. replace editor_complete with editor_complete_next. (editor_complete): call completions_complete (editor_complete_next): new function (editor_complete_prev): likewise * src/completions.h (completions_next_completion): remove prototype (completions_update): likewise (completions_assign): likewise (completions_complete): new prototype * src/completions.c (completions_assign): make it a static function (completions_update): likewise (completions_prev_match): new function (completions_next_match): likewise (completions_complete): renamed from completions_next_completion. call completions_next_match and completions_prev_match.
Diffstat (limited to 'src/completions.c')
-rw-r--r--src/completions.c70
1 files changed, 51 insertions, 19 deletions
diff --git a/src/completions.c b/src/completions.c
index 6f2ed12..314bd23 100644
--- a/src/completions.c
+++ b/src/completions.c
@@ -37,7 +37,7 @@ completions_free (rp_completions *c)
free (c->partial);
}
-void
+static void
completions_assign (rp_completions *c, struct list_head *new_list)
{
struct sbuf *cur;
@@ -58,7 +58,7 @@ completions_assign (rp_completions *c, struct list_head *new_list)
list_first (c->last_match, &c->completion_list, node);
}
-void
+static void
completions_update (rp_completions *c, char *partial)
{
struct list_head *new_list;
@@ -76,30 +76,33 @@ completions_update (rp_completions *c, char *partial)
free (new_list);
}
-/* Return a completed string that starts with partial. */
-char *
-completions_next_completion (rp_completions *c, char *partial)
+static char *
+completions_prev_match (rp_completions *c)
{
struct sbuf *cur;
- if (c->virgin)
+ /* search forward from our last match through the list looking for
+ another match. */
+ for (cur = list_prev_entry (c->last_match, &c->completion_list, node);
+ cur != c->last_match;
+ cur = list_prev_entry (cur, &c->completion_list, node))
{
- completions_update (c, partial);
-
- /* Since it's never been completed on and c->last_match points
- to the first element of the list which may be a match. So
- check it. FIXME: This is a bit of a hack. */
- if (c->last_match == NULL)
- return NULL;
-
- if (str_comp (sbuf_get (c->last_match), c->partial, strlen (c->partial)))
- return sbuf_get (c->last_match);
+ if (str_comp (sbuf_get (cur), c->partial, strlen (c->partial)))
+ {
+ /* We found a match so update our last_match pointer and
+ return the string. */
+ c->last_match = cur;
+ return sbuf_get (cur);
+ }
}
- if (c->last_match == NULL)
- return NULL;
+ return NULL;
+}
- /* */
+static char *
+completions_next_match (rp_completions *c)
+{
+ struct sbuf *cur;
/* search forward from our last match through the list looking for
another match. */
@@ -118,3 +121,32 @@ completions_next_completion (rp_completions *c, char *partial)
return NULL;
}
+
+/* Return a completed string that starts with partial. */
+char *
+completions_complete (rp_completions *c, char *partial, int direction)
+{
+ if (c->virgin)
+ {
+ completions_update (c, partial);
+
+ /* Since it's never been completed on and c->last_match points
+ to the first element of the list which may be a match. So
+ check it. FIXME: This is a bit of a hack. */
+ if (c->last_match == NULL)
+ return NULL;
+
+ if (str_comp (sbuf_get (c->last_match), c->partial, strlen (c->partial)))
+ return sbuf_get (c->last_match);
+ }
+
+ if (c->last_match == NULL)
+ return NULL;
+
+ /* Depending on the direction, find our "next" match. */
+ if (direction == COMPLETION_NEXT)
+ return completions_next_match (c);
+
+ /* Otherwise get the previous match */
+ return completions_prev_match (c);
+}