1
0
mirror of https://github.com/irssi/irssi.git synced 2025-02-02 15:08:01 -05:00

Subcommand and command parameter completion works now also if you use

alias as the base command.


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@380 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-06-25 22:59:49 +00:00 committed by cras
parent 0415b1bbce
commit 69b8d4f81b
3 changed files with 49 additions and 24 deletions

View File

@ -30,9 +30,6 @@
#include "lib-config/iconfig.h" #include "lib-config/iconfig.h"
#include "settings.h" #include "settings.h"
#define alias_find(alias) \
iconfig_get_str("aliases", alias, NULL)
GSList *commands; GSList *commands;
char *current_command; char *current_command;

View File

@ -22,6 +22,9 @@ enum {
CMDERR_NOT_GOOD_IDEA /* not good idea to do, -yes overrides this */ CMDERR_NOT_GOOD_IDEA /* not good idea to do, -yes overrides this */
}; };
#define alias_find(alias) \
iconfig_get_str("aliases", alias, NULL)
#define cmd_return_error(a) { signal_emit("error command", 1, GINT_TO_POINTER(a)); signal_stop(); return; } #define cmd_return_error(a) { signal_emit("error command", 1, GINT_TO_POINTER(a)); signal_stop(); return; }
#define cmd_param_error(a) { cmd_params_free(free_arg); cmd_return_error(a); } #define cmd_param_error(a) { cmd_params_free(free_arg); cmd_return_error(a); }

View File

@ -346,12 +346,12 @@ static GList *completion_get_subcommands(const char *cmd)
} }
/* split the line to command and arguments */ /* split the line to command and arguments */
static char *line_get_command(const char *line, char **args) static char *line_get_command(const char *line, char **args, int aliases)
{ {
const char *ptr, *cmdargs; const char *ptr, *cmdargs;
char *cmd, *checkcmd; char *cmd, *checkcmd;
cmd = checkcmd = NULL; cmd = checkcmd = NULL; *args = "";
cmdargs = NULL; ptr = line; cmdargs = NULL; ptr = line;
do { do {
@ -366,7 +366,8 @@ static char *line_get_command(const char *line, char **args)
cmdargs = ptr; cmdargs = ptr;
} }
if (!command_find(checkcmd)) { if (aliases ? !alias_find(checkcmd) :
!command_find(checkcmd)) {
/* not found, use the previous */ /* not found, use the previous */
g_free(checkcmd); g_free(checkcmd);
break; break;
@ -374,17 +375,36 @@ static char *line_get_command(const char *line, char **args)
/* found, check if it has subcommands */ /* found, check if it has subcommands */
g_free_not_null(cmd); g_free_not_null(cmd);
cmd = checkcmd; if (!aliases)
cmd = checkcmd;
else {
cmd = g_strdup(alias_find(checkcmd));
g_free(checkcmd);
}
*args = (char *) cmdargs; *args = (char *) cmdargs;
} while (ptr != NULL); } while (ptr != NULL);
return cmd; return cmd;
} }
static char *expand_aliases(const char *line)
{
char *cmd, *args, *ret;
cmd = line_get_command(line, &args, TRUE);
if (cmd == NULL) return g_strdup(line);
if (*args == '\0') return cmd;
ret = g_strconcat(cmd, " ", args, NULL);
g_free(cmd);
return ret;
}
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, int *want_space) const char *word, const char *linestart, int *want_space)
{ {
const char *newword, *cmdchars; const char *newword, *cmdchars;
char *signal, *cmd, *args, *line;
g_return_if_fail(list != NULL); g_return_if_fail(list != NULL);
g_return_if_fail(word != NULL); g_return_if_fail(word != NULL);
@ -409,31 +429,36 @@ static void sig_complete_word(GList **list, WINDOW_REC *window,
return; return;
} }
if (strchr(cmdchars, *linestart) && is_base_command(linestart+1)) { /* check only for /command completions from now on */
/* complete /command's subcommand */ cmdchars = strchr(cmdchars, *linestart);
char *tmp; if (cmdchars == NULL) return;
tmp = g_strconcat(linestart+1, " ", word, NULL); /* check if there's aliases */
*list = completion_get_subcommands(tmp); line = linestart[1] == *cmdchars ? g_strdup(linestart+2) :
g_free(tmp); expand_aliases(linestart+1);
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(); if (*list != NULL) signal_stop();
g_free(line);
return; return;
} }
if (strchr(cmdchars, *linestart)) { /* complete parameters */
/* complete /command's parameters */ cmd = line_get_command(line, &args, FALSE);
char *signal, *cmd, *args; if (cmd != NULL) {
signal = g_strconcat("complete command ", cmd, NULL);
signal_emit(signal, 5, list, window, word, args, want_space);
cmd = line_get_command(linestart+1, &args); g_free(signal);
if (cmd != NULL) { g_free(cmd);
signal = g_strconcat("complete command ", cmd, NULL);
signal_emit(signal, 5, list, window, word, args, want_space);
g_free(signal);
g_free(cmd);
}
} }
g_free(line);
} }
static void sig_complete_set(GList **list, WINDOW_REC *window, static void sig_complete_set(GList **list, WINDOW_REC *window,