diff mcabber/mcabber/compl.c @ 1756:e2c084204583

Add (optional) suffix after nick completion in Multi-User Chats New option: 'completion_muc_suffix' Closes issue #20 in mcabber-crew BTS.
author Mikael Berthe <mikael@lilotux.net>
date Sat, 13 Mar 2010 13:18:07 +0100
parents e6e89b1d7831
children e6d355e50d7a
line wrap: on
line diff
--- a/mcabber/mcabber/compl.c	Sat Mar 13 11:57:32 2010 +0100
+++ b/mcabber/mcabber/compl.c	Sat Mar 13 13:18:07 2010 +0100
@@ -91,13 +91,14 @@
 }
 #endif
 
-//  new_completion(prefix, compl_cat)
+//  new_completion(prefix, compl_cat, suffix)
 // . prefix    = beginning of the word, typed by the user
 // . compl_cat = pointer to a completion category list (list of *char)
+// . suffix    = string to append to all completion possibilities (i.e. ":")
 // Set the InputCompl pointer to an allocated compl structure.
 // done_completion() must be called when finished.
 // Returns the number of possible completions.
-guint new_completion(char *prefix, GSList *compl_cat)
+guint new_completion(const char *prefix, GSList *compl_cat, const gchar *suffix)
 {
   compl *c;
   GSList *sl_cat;
@@ -112,8 +113,14 @@
   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)
-        c->list = g_slist_append(c->list, g_strdup(word+len)); // TODO sort
+      if (strlen(word) != len) {
+        gchar *compval;
+        if (suffix)
+          compval = g_strdup_printf("%s%s", word+len, suffix);
+        else
+          compval = g_strdup(word+len);
+        c->list = g_slist_append(c->list, compval); // TODO sort
+      }
     }
   }
   c->next = c->list;
@@ -175,7 +182,7 @@
 
 //  compl_add_category_word(categ, command)
 // Adds a keyword as a possible completion in category categ.
-void compl_add_category_word(guint categ, const char *word)
+void compl_add_category_word(guint categ, const gchar *word)
 {
   GSList *sl_cat;
   category *cat;
@@ -208,7 +215,7 @@
 
 //  compl_del_category_word(categ, command)
 // Removes a keyword from category categ in completion list.
-void compl_del_category_word(guint categ, const char *word)
+void compl_del_category_word(guint categ, const gchar *word)
 {
   GSList *sl_cat, *sl_elt;
   category *cat;