summaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-01-04 22:06:29 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2016-01-04 22:06:29 +0100
commit4832a994616bb9e7b8037cc1e58c96fc84da85e5 (patch)
tree6276da7bfc5bd0a52b2881fb71bb93a607523565 /degesch.c
parent0092c345688c7d84fb520207ca80335ccfde6e88 (diff)
downloadxK-4832a994616bb9e7b8037cc1e58c96fc84da85e5.tar.gz
xK-4832a994616bb9e7b8037cc1e58c96fc84da85e5.tar.xz
xK-4832a994616bb9e7b8037cc1e58c96fc84da85e5.zip
degesch: add basic autocomplete for /topic
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/degesch.c b/degesch.c
index 7163098..0a8d4b5 100644
--- a/degesch.c
+++ b/degesch.c
@@ -1,7 +1,7 @@
/*
* degesch.c: the experimental IRC client
*
- * Copyright (c) 2015, Přemysl Janouch <p.janouch@gmail.com>
+ * Copyright (c) 2015 - 2016, Přemysl Janouch <p.janouch@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -10176,6 +10176,29 @@ complete_option (struct app_context *ctx, struct completion *data,
}
static void
+complete_topic (struct app_context *ctx, struct completion *data,
+ const char *word, struct str_vector *output)
+{
+ (void) data;
+
+ // TODO: make it work in other server-related buffers, too, i.e. when we're
+ // completing the third word and the second word is a known channel name
+ struct buffer *buffer = ctx->current_buffer;
+ if (buffer->type != BUFFER_CHANNEL)
+ return;
+
+ const char *topic = buffer->channel->topic;
+ if (topic && !strncasecmp_ascii (word, topic, strlen (word)))
+ {
+ // We must prepend the channel name if the topic itself starts
+ // with something that could be regarded as a channel name
+ str_vector_add_owned (output, irc_is_channel (buffer->server, topic)
+ ? xstrdup_printf ("%s %s", buffer->channel->name, topic)
+ : xstrdup (topic));
+ }
+}
+
+static void
complete_nicknames (struct app_context *ctx, struct completion *data,
const char *word, struct str_vector *output)
{
@@ -10208,6 +10231,7 @@ complete_word (struct app_context *ctx, struct completion *data,
// First figure out what exactly we need to complete
bool try_commands = false;
bool try_options = false;
+ bool try_topic = false;
bool try_nicknames = false;
if (data->location == 0 && completion_matches (data, 0, "/*"))
@@ -10216,6 +10240,8 @@ complete_word (struct app_context *ctx, struct completion *data,
try_options = true;
else if (data->location == 1 && completion_matches (data, 0, "/help"))
try_commands = try_options = true;
+ else if (data->location == 1 && completion_matches (data, 0, "/topic"))
+ try_topic = try_nicknames = true;
else
try_nicknames = true;
@@ -10227,6 +10253,7 @@ complete_word (struct app_context *ctx, struct completion *data,
if (try_commands) complete_command (ctx, data, word, &words);
if (try_options) complete_option (ctx, data, word, &words);
+ if (try_topic) complete_topic (ctx, data, word, &words);
if (try_nicknames) complete_nicknames (ctx, data, word, &words);
if (words.len == 1)