--- a/mcabber/src/compl.c Sat May 19 12:18:25 2007 +0200
+++ b/mcabber/src/compl.c Sun May 20 22:01:20 2007 +0200
@@ -57,7 +57,8 @@
// . compl_cat = pointer to a completion category list (list of *char)
// Set the InputCompl pointer to an allocated compl structure.
// done_completion() must be called when finished.
-void new_completion(char *prefix, GSList *compl_cat)
+// Returns the number of possible completions.
+guint new_completion(char *prefix, GSList *compl_cat)
{
compl *c;
GSList *sl_cat;
@@ -69,7 +70,7 @@
c = g_new0(compl, 1);
// Build the list of matches
- for (sl_cat=compl_cat; sl_cat; sl_cat = g_slist_next(sl_cat)) {
+ for (sl_cat = compl_cat; sl_cat; sl_cat = g_slist_next(sl_cat)) {
char *word = sl_cat->data;
if (!strncasecmp(prefix, word, len)) {
if (strlen(word) != len)
@@ -78,6 +79,7 @@
}
c->next = c->list;
InputCompl = c;
+ return g_slist_length(c->list);
}
// done_completion();
--- a/mcabber/src/compl.h Sat May 19 12:18:25 2007 +0200
+++ b/mcabber/src/compl.h Sun May 20 22:01:20 2007 +0200
@@ -26,7 +26,7 @@
void compl_del_category_word(guint categ, const char *word);
GSList *compl_get_category_list(guint cat_flags, guint *dynlist);
-void new_completion(char *prefix, GSList *compl_cat);
+guint new_completion(char *prefix, GSList *compl_cat);
void done_completion(void);
guint cancel_completion(void);
const char *complete(void);
--- a/mcabber/src/screen.c Sat May 19 12:18:25 2007 +0200
+++ b/mcabber/src/screen.c Sun May 20 22:01:20 2007 +0200
@@ -2815,17 +2815,37 @@
guint dynlist;
GSList *list = compl_get_category_list(compl_categ, &dynlist);
if (list) {
+ guint n;
char *prefix = g_strndup(row, ptr_inputline-row);
// Init completion
- new_completion(prefix, list);
+ n = new_completion(prefix, list);
g_free(prefix);
+ if (n == 0 && nrow == -1) {
+ // This is a MUC room and we can't complete from the beginning of the
+ // line. Let's try a bit harder and complete the current word.
+ row = prev_char(ptr_inputline, inputLine);
+ while (row >= inputLine) {
+ if (!iswalnum(get_char(row)) && get_char(row) != '_') {
+ row = next_char((char*)row);
+ break;
+ }
+ if (row == inputLine)
+ break;
+ row = prev_char((char*)row, inputLine);
+ }
+ // There's no need to try again if row == inputLine
+ if (row > inputLine) {
+ prefix = g_strndup(row, ptr_inputline-row);
+ new_completion(prefix, list);
+ g_free(prefix);
+ }
+ }
// Free the list if it's a dynamic one
if (dynlist) {
GSList *slp;
for (slp = list; slp; slp = g_slist_next(slp))
g_free(slp->data);
g_slist_free(list);
-
}
// Now complete
cchar = complete();