1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05: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); g_free(word);
word = g_strdup(""); word = g_strdup("");
startpos = (int) (wordstart-line)+wordlen+1; startpos = strlen(linestart)+1;/*(int) (wordstart-line)+wordlen+1*/;
wordlen = 0; wordlen = 0;
} }
@ -173,7 +173,7 @@ char *word_complete(WINDOW_REC *window, const char *line, int *pos)
return NULL; return NULL;
/* word completed */ /* word completed */
*pos = startpos+strlen(complist->data)+1; *pos = startpos+strlen(complist->data);
/* replace the word in line - we need to return /* replace the word in line - we need to return
a full new line */ 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_erase(result, startpos, wordlen);
g_string_insert(result, startpos, complist->data); g_string_insert(result, startpos, complist->data);
if (want_space && !isseparator(result->str[*pos-1])) if (want_space) {
g_string_insert_c(result, *pos-1, ' '); if (!isseparator(result->str[*pos]))
g_string_insert_c(result, *pos, ' ');
(*pos)++;
}
wordlen = strlen(complist->data); wordlen = strlen(complist->data);
last_line_pos = *pos; last_line_pos = *pos;
@ -344,7 +347,8 @@ static GList *completion_get_commands(const char *cmd, char cmdchar)
continue; continue;
if (g_strncasecmp(rec->cmd, cmd, len) == 0) { 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) if (glist_find_icase_string(complist, word) == NULL)
complist = g_list_insert_sorted(complist, word, (GCompareFunc) g_istr_cmp); complist = g_list_insert_sorted(complist, word, (GCompareFunc) g_istr_cmp);
else else
@ -550,10 +554,7 @@ static void sig_complete_set(GList **list, WINDOW_REC *window,
if (*line != '\0') return; if (*line != '\0') return;
*list = completion_get_settings(word); *list = completion_get_settings(word);
if (*list != NULL) { if (*list != NULL) signal_stop();
*want_space = FALSE;
signal_stop();
}
} }
static void sig_complete_toggle(GList **list, WINDOW_REC *window, 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; if (*line != '\0') return;
*list = completion_get_bool_settings(word); *list = completion_get_bool_settings(word);
if (*list != NULL) { if (*list != NULL) signal_stop();
*want_space = FALSE;
signal_stop();
}
} }
/* first argument of command is file name - complete it */ /* 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) void completion_init(void)
{ {
complist = NULL; complist = NULL;
@ -603,6 +624,7 @@ void completion_init(void)
signal_add("complete command reload", (SIGNAL_FUNC) sig_complete_filename); 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 open", (SIGNAL_FUNC) sig_complete_filename);
signal_add("complete command rawlog save", (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) 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 reload", (SIGNAL_FUNC) sig_complete_filename);
signal_remove("complete command rawlog open", (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 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; 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, static void sig_complete_word(GList **list, WINDOW_REC *window,
const char *word, const char *linestart) 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) if (server == NULL || !server->connected)
return; return;
channel = irc_item_channel(window->active);
/* check for /MSG completion */
cmdchars = settings_get_str("cmdchars"); cmdchars = settings_get_str("cmdchars");
if ((*linestart == '\0' && *word == '\0') || if (*linestart == '\0' && *word == '\0') {
(*linestart == '\0' && strchr(cmdchars, *word) != NULL && /* pressed TAB at the start of line - add /MSG */
g_strcasecmp(word+1, "msg") == 0)) {
/* pressed TAB at the start of line - add /MSG
... or ... trying to complete /MSG command */
prefix = g_strdup_printf("%cmsg", *cmdchars); prefix = g_strdup_printf("%cmsg", *cmdchars);
*list = completion_msg(server, NULL, "", prefix); *list = completion_msg(server, NULL, "", prefix);
if (*list == NULL) *list = g_list_append(*list, g_strdup(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; 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 /* nick completion .. we could also be completing a nick after /MSG
from nicks in channel */ from nicks in channel */
channel = irc_item_channel(window->active);
if (channel == NULL) if (channel == NULL)
return; return;
@ -467,6 +428,43 @@ static void sig_complete_word(GList **list, WINDOW_REC *window,
if (*list != NULL) signal_stop(); 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 */ /* 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) 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); complete_tag = g_timeout_add(1000, (GSourceFunc) nick_completion_timeout, NULL);
signal_add("complete word", (SIGNAL_FUNC) sig_complete_word); 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("event privmsg", (SIGNAL_FUNC) event_privmsg);
signal_add("command msg", (SIGNAL_FUNC) cmd_msg); signal_add("command msg", (SIGNAL_FUNC) cmd_msg);
signal_add("nicklist remove", (SIGNAL_FUNC) sig_nick_removed); signal_add("nicklist remove", (SIGNAL_FUNC) sig_nick_removed);
@ -612,6 +611,7 @@ void irc_completion_deinit(void)
g_source_remove(complete_tag); g_source_remove(complete_tag);
signal_remove("complete word", (SIGNAL_FUNC) sig_complete_word); 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("event privmsg", (SIGNAL_FUNC) event_privmsg);
signal_remove("command msg", (SIGNAL_FUNC) cmd_msg); signal_remove("command msg", (SIGNAL_FUNC) cmd_msg);
signal_remove("nicklist remove", (SIGNAL_FUNC) sig_nick_removed); signal_remove("nicklist remove", (SIGNAL_FUNC) sig_nick_removed);