diff options
author | sabetts <sabetts> | 2001-12-21 13:58:01 +0000 |
---|---|---|
committer | sabetts <sabetts> | 2001-12-21 13:58:01 +0000 |
commit | 5127b4ce3d24180599e09b959c16da1cf72290e6 (patch) | |
tree | 28205ce5cb91af3a3bf2d57379ae8d75891a7cc2 | |
parent | bf97100618c4808f0e6d204c77290e4494e28e6e (diff) | |
download | ratpoison-5127b4ce3d24180599e09b959c16da1cf72290e6.zip |
* src/actions.h (cmd_alias): new prototype
* src/actions.c (user_commands): remove "license" from the
unimplemented section.
(user_commands): new command "alias"
(cmd_alias): new function
(command): handle aliases
(initialize_default_keybindings): initialize the alias list
(struct cmd_alias): new struct
(alias_list): new static global
(alias_list_size): likewise
(alias_list_last): likewise
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | doc/ratpoison.texi | 15 | ||||
-rw-r--r-- | src/actions.c | 60 | ||||
-rw-r--r-- | src/actions.h | 1 |
4 files changed, 85 insertions, 1 deletions
@@ -1,7 +1,17 @@ 2001-12-21 shawn <sabetts@vcn.bc.ca> + * src/actions.h (cmd_alias): new prototype + * src/actions.c (user_commands): remove "license" from the unimplemented section. + (user_commands): new command "alias" + (cmd_alias): new function + (command): handle aliases + (initialize_default_keybindings): initialize the alias list + (struct cmd_alias): new struct + (alias_list): new static global + (alias_list_size): likewise + (alias_list_last): likewise * src/actions.h (cmd_license): new prototype diff --git a/doc/ratpoison.texi b/doc/ratpoison.texi index 5c6404c..8a1431d 100644 --- a/doc/ratpoison.texi +++ b/doc/ratpoison.texi @@ -329,7 +329,7 @@ Indicate which frame is the current frame. @end table @node Commands, Input, Keystrokes, Top -@chapter ratpoison commands +@chapter Commands ratpoison can be controlled with commands (so called colon-commands). The summary of available commands is listed below: @@ -340,6 +340,19 @@ The summary of available commands is listed below: This is a pretty useless command. By default, it is bound to @kbd{C-t g}, and its purpose is to abort other commands. +@item alias @var{name} @var{command} +An allows you to name a ratpoison command something else. For +instance, if you frequently open emacs you may want to make an alias +called @samp{emacs} that loads emacs. You would do it like this: + +@example +: alias emacs exec emacs +@end example + +An alias is treated exactly like a colon command in that you can call +it from the colon prompt, bind it to a key, and call it +non-interactively with @command{ratpoison -c}. + @item banish Banish the mouse to the lower right corner of the screen. diff --git a/src/actions.c b/src/actions.c index 3fc733f..6adb8cf 100644 --- a/src/actions.c +++ b/src/actions.c @@ -81,6 +81,7 @@ static user_command user_commands[] = {"restart", cmd_restart, arg_VOID}, {"startup_message", cmd_startup_message, arg_STRING}, {"link", cmd_link, arg_STRING}, + {"alias", cmd_alias, arg_STRING}, /*@end (tag required for genrpbindings) */ /* Commands to set default behavior. */ @@ -115,6 +116,16 @@ static user_command user_commands[] = #endif {0, 0, 0} }; +struct cmd_alias +{ + char *name; + char *alias; +}; + +static struct cmd_alias *alias_list; +static int alias_list_size; +static int alias_list_last; + rp_action* find_keybinding_by_action (char *action) { @@ -249,6 +260,11 @@ initialize_default_keybindings (void) key_actions = (rp_action*) xmalloc (sizeof (rp_action) * key_actions_table_size); key_actions_last = 0; + /* Initialive the alias list. */ + alias_list_size = 5; + alias_list_last = 0; + alias_list = xmalloc (sizeof (cmd_alias) * alias_list_size); + prefix_key.sym = KEY_PREFIX; prefix_key.state = MODIFIER_PREFIX; @@ -827,6 +843,7 @@ command (int interactive, char *data) char *cmd, *rest; char *input; user_command *uc; + int i; if (data == NULL) return NULL; @@ -863,6 +880,16 @@ command (int interactive, char *data) } } + /* Look for it in the aliases. */ + for (i=0; i<alias_list_last; i++) + { + if (!strcmp (cmd, alias_list[i].name)) + { + result = command (interactive, alias_list[i].alias); + goto done; + } + } + marked_message_printf (0, 0, MESSAGE_UNKNOWN_COMMAND, cmd); done: @@ -2212,3 +2239,36 @@ cmd_defbarpadding (int interactive, void *data) } return NULL; } + +char * +cmd_alias (int interactive, void *data) +{ + char *name, *alias; + + if (data == NULL) + { + message (" alias: At least one argument required "); + return NULL; + } + + if (alias_list_last >= alias_list_size) + { + alias_list_size *= 2; + alias_list = xrealloc (alias_list, sizeof (cmd_alias) * alias_list_size); + } + + name = strtok (data, " "); + alias = strtok (NULL, "\0"); + + if (name == NULL || alias == NULL) + { + message (" alias: Two arguments required "); + return NULL; + } + + alias_list[alias_list_last].name = xstrdup (name); + alias_list[alias_list_last].alias = xstrdup (alias); + alias_list_last++; + + return NULL; +} diff --git a/src/actions.h b/src/actions.h index 6c46da1..685b00f 100644 --- a/src/actions.h +++ b/src/actions.h @@ -106,6 +106,7 @@ char * cmd_focuslast (int interactive, void *data); char * cmd_link (int interactive, void *data); char * cmd_defbarpadding (int interactive, void *data); char * cmd_license (int interactive, void *data); +char * cmd_alias (int interactive, void *data); /* void cmd_xterm (void *data); */ |