Add (optional) suffix after nick completion in Multi-User Chats
New option: 'completion_muc_suffix'
Closes issue #20 in mcabber-crew BTS.
--- 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;
--- a/mcabber/mcabber/compl.h Sat Mar 13 11:57:32 2010 +0100
+++ b/mcabber/mcabber/compl.h Sat Mar 13 13:18:07 2010 +0100
@@ -33,11 +33,12 @@
void compl_del_category (guint id);
#endif
-void compl_add_category_word(guint, const char *command);
-void compl_del_category_word(guint categ, const char *word);
+void compl_add_category_word(guint, const gchar *command);
+void compl_del_category_word(guint categ, const gchar *word);
GSList *compl_get_category_list(guint cat_flags, guint *dynlist);
-guint new_completion(char *prefix, GSList *compl_cat);
+guint new_completion(const gchar *prefix, GSList *compl_cat,
+ const gchar *suffix);
void done_completion(void);
guint cancel_completion(void);
const char *complete(void);
--- a/mcabber/mcabber/screen.c Sat Mar 13 11:57:32 2010 +0100
+++ b/mcabber/mcabber/screen.c Sat Mar 13 13:18:07 2010 +0100
@@ -3522,7 +3522,9 @@
guint n;
char *prefix = g_strndup(row, ptr_inputline-row);
// Init completion
- n = new_completion(prefix, list);
+ n = new_completion(prefix, list,
+ (compl_categ == COMPL_RESOURCE ?
+ settings_opt_get("completion_muc_suffix") : NULL));
g_free(prefix);
if (n == 0 && nrow == -1) {
// This is a MUC room and we can't complete from the beginning of the
@@ -3540,7 +3542,7 @@
// There's no need to try again if row == inputLine
if (row > inputLine) {
prefix = g_strndup(row, ptr_inputline-row);
- new_completion(prefix, list);
+ new_completion(prefix, list, NULL);
g_free(prefix);
}
}
--- a/mcabber/mcabberrc.example Sat Mar 13 11:57:32 2010 +0100
+++ b/mcabber/mcabberrc.example Sat Mar 13 13:18:07 2010 +0100
@@ -307,6 +307,11 @@
# Set 'muc_disable_nick_hl' to 1 if you don't want mcabber to color lines
# containing your nickname in a MUC room.
#set muc_disable_nick_hl = 0
+#
+# Set 'completion_muc_suffix' if you want mcabber to append a string to
+# suggested nicknames (only at the beginning of a line), like ":" or ",".
+# (Default: none)
+#set completion_muc_suffix = ": "
# Status messages
# The 'message' value will override all others, take care!