1
0
mirror of https://github.com/irssi/irssi.git synced 2024-09-29 04:45:57 -04:00

/MSG completion fixes. /HELP command completion works. Some other fixes.

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@399 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-06-30 19:51:53 +00:00 committed by cras
parent e90cdaf4ca
commit 58397c1ca9
2 changed files with 78 additions and 55 deletions

View File

@ -157,7 +157,7 @@ char *word_complete(WINDOW_REC *window, const char *line, int *pos)
g_free(word);
word = g_strdup("");
startpos = (int) (wordstart-line)+wordlen+1;
startpos = strlen(linestart)+1;/*(int) (wordstart-line)+wordlen+1*/;
wordlen = 0;
}
@ -173,7 +173,7 @@ char *word_complete(WINDOW_REC *window, const char *line, int *pos)
return NULL;
/* word completed */
*pos = startpos+strlen(complist->data)+1;
*pos = startpos+strlen(complist->data);
/* replace the word in line - we need to return
a full new line */
@ -181,8 +181,11 @@ char *word_complete(WINDOW_REC *window, const char *line, int *pos)
g_string_erase(result, startpos, wordlen);
g_string_insert(result, startpos, complist->data);
if (want_space && !isseparator(result->str[*pos-1]))
g_string_insert_c(result, *pos-1, ' ');
if (want_space) {
if (!isseparator(result->str[*pos]))
g_string_insert_c(result, *pos, ' ');
(*pos)++;
}
wordlen = strlen(complist->data);
last_line_pos = *pos;
@ -344,7 +347,8 @@ static GList *completion_get_commands(const char *cmd, char cmdchar)
continue;
if (g_strncasecmp(rec->cmd, cmd, len) == 0) {
word = g_strdup_printf("%c%s", cmdchar, rec->cmd);
word = cmdchar == '\0' ? g_strdup(rec->cmd) :
g_strdup_printf("%c%s", cmdchar, rec->cmd);
if (glist_find_icase_string(complist, word) == NULL)
complist = g_list_insert_sorted(complist, word, (GCompareFunc) g_istr_cmp);
else
@ -550,10 +554,7 @@ static void sig_complete_set(GList **list, WINDOW_REC *window,
if (*line != '\0') return;
*list = completion_get_settings(word);
if (*list != NULL) {
*want_space = FALSE;
signal_stop();
}
if (*list != NULL) signal_stop();
}
static void sig_complete_toggle(GList **list, WINDOW_REC *window,
@ -566,10 +567,7 @@ static void sig_complete_toggle(GList **list, WINDOW_REC *window,
if (*line != '\0') return;
*list = completion_get_bool_settings(word);
if (*list != NULL) {
*want_space = FALSE;
signal_stop();
}
if (*list != NULL) signal_stop();
}
/* first argument of command is file name - complete it */
@ -589,6 +587,29 @@ static void sig_complete_filename(GList **list, WINDOW_REC *window,
}
}
/* first argument of command is .. command :) (/HELP command) */
static void sig_complete_command(GList **list, WINDOW_REC *window,
const char *word, const char *line, int *want_space)
{
char *cmd;
g_return_if_fail(list != NULL);
g_return_if_fail(word != NULL);
g_return_if_fail(line != NULL);
if (*line == '\0') {
/* complete base command */
*list = completion_get_commands(word, '\0');
} else if (is_base_command(line)) {
/* complete subcommand */
cmd = g_strconcat(line, " ", word, NULL);
*list = completion_get_subcommands(cmd);
g_free(cmd);
}
if (*list != NULL) signal_stop();
}
void completion_init(void)
{
complist = NULL;
@ -603,6 +624,7 @@ void completion_init(void)
signal_add("complete command reload", (SIGNAL_FUNC) sig_complete_filename);
signal_add("complete command rawlog open", (SIGNAL_FUNC) sig_complete_filename);
signal_add("complete command rawlog save", (SIGNAL_FUNC) sig_complete_filename);
signal_add("complete command help", (SIGNAL_FUNC) sig_complete_command);
}
void completion_deinit(void)
@ -618,4 +640,5 @@ void completion_deinit(void)
signal_remove("complete command reload", (SIGNAL_FUNC) sig_complete_filename);
signal_remove("complete command rawlog open", (SIGNAL_FUNC) sig_complete_filename);
signal_remove("complete command rawlog save", (SIGNAL_FUNC) sig_complete_filename);
signal_remove("complete command help", (SIGNAL_FUNC) sig_complete_command);
}

View File

@ -377,31 +377,6 @@ static GList *completion_joinlist(GList *list1, GList *list2)
return list1;
}
static IRC_SERVER_REC *line_get_server(const char *line)
{
IRC_SERVER_REC *server;
const char *ptr;
char *tag, *p;
g_return_val_if_fail(line != NULL, NULL);
ptr = strchr(line, ' ');
if (ptr == NULL) return NULL;
while (*ptr == ' ') ptr++;
if (*ptr != '-') return NULL;
/* -option found - should be server tag */
tag = g_strdup(ptr+1);
p = strchr(tag, ' ');
if (p != NULL) *p = '\0';
server = (IRC_SERVER_REC *) server_find_tag(tag);
g_free(tag);
return server;
}
static void sig_complete_word(GList **list, WINDOW_REC *window,
const char *word, const char *linestart)
{
@ -426,15 +401,9 @@ static void sig_complete_word(GList **list, WINDOW_REC *window,
if (server == NULL || !server->connected)
return;
channel = irc_item_channel(window->active);
/* check for /MSG completion */
cmdchars = settings_get_str("cmdchars");
if ((*linestart == '\0' && *word == '\0') ||
(*linestart == '\0' && strchr(cmdchars, *word) != NULL &&
g_strcasecmp(word+1, "msg") == 0)) {
/* pressed TAB at the start of line - add /MSG
... or ... trying to complete /MSG command */
if (*linestart == '\0' && *word == '\0') {
/* pressed TAB at the start of line - add /MSG */
prefix = g_strdup_printf("%cmsg", *cmdchars);
*list = completion_msg(server, NULL, "", prefix);
if (*list == NULL) *list = g_list_append(*list, g_strdup(prefix));
@ -444,17 +413,9 @@ static void sig_complete_word(GList **list, WINDOW_REC *window,
return;
}
if (strchr(cmdchars, *linestart) != NULL &&
g_strcasecmp(linestart+1, "msg") == 0) {
/* completing /MSG nick */
IRC_SERVER_REC *msgserver;
msgserver = line_get_server(linestart);
*list = completion_msg(server, msgserver, word, NULL);
}
/* nick completion .. we could also be completing a nick after /MSG
from nicks in channel */
channel = irc_item_channel(window->active);
if (channel == NULL)
return;
@ -467,6 +428,43 @@ static void sig_complete_word(GList **list, WINDOW_REC *window,
if (*list != NULL) signal_stop();
}
static IRC_SERVER_REC *line_get_server(const char *line)
{
IRC_SERVER_REC *server;
char *tag, *ptr;
g_return_val_if_fail(line != NULL, NULL);
if (*line != '-') return NULL;
/* -option found - should be server tag */
tag = g_strdup(line+1);
ptr = strchr(tag, ' ');
if (ptr != NULL) *ptr = '\0';
server = (IRC_SERVER_REC *) server_find_tag(tag);
g_free(tag);
return server;
}
static void sig_complete_msg(GList **list, WINDOW_REC *window,
const char *word, const char *line, int *want_space)
{
IRC_SERVER_REC *server, *msgserver;
g_return_if_fail(list != NULL);
g_return_if_fail(word != NULL);
g_return_if_fail(line != NULL);
server = window->active_server;
if (server == NULL || !server->connected)
return;
msgserver = line_get_server(line);
*list = completion_msg(server, msgserver, word, NULL);
if (*list != NULL) signal_stop();
}
/* expand \n, \t and \\ - FIXME: this doesn't work right */
static char *expand_escapes(const char *line, IRC_SERVER_REC *server, WI_IRC_REC *item)
{
@ -598,6 +596,7 @@ void irc_completion_init(void)
complete_tag = g_timeout_add(1000, (GSourceFunc) nick_completion_timeout, NULL);
signal_add("complete word", (SIGNAL_FUNC) sig_complete_word);
signal_add("complete command msg", (SIGNAL_FUNC) sig_complete_msg);
signal_add("event privmsg", (SIGNAL_FUNC) event_privmsg);
signal_add("command msg", (SIGNAL_FUNC) cmd_msg);
signal_add("nicklist remove", (SIGNAL_FUNC) sig_nick_removed);
@ -612,6 +611,7 @@ void irc_completion_deinit(void)
g_source_remove(complete_tag);
signal_remove("complete word", (SIGNAL_FUNC) sig_complete_word);
signal_remove("complete command msg", (SIGNAL_FUNC) sig_complete_msg);
signal_remove("event privmsg", (SIGNAL_FUNC) event_privmsg);
signal_remove("command msg", (SIGNAL_FUNC) cmd_msg);
signal_remove("nicklist remove", (SIGNAL_FUNC) sig_nick_removed);