Exemple #1
0
/* Wants: mode request key */
static enum status_code
option_bind_command(int argc, const char *argv[])
{
	struct key key[1];
	size_t keys = 0;
	enum request request;
	struct keymap *keymap;
	const char *key_arg;

	if (argc < 3)
		return error("Invalid key binding: bind keymap key action");

	if (!(keymap = get_keymap(argv[0], strlen(argv[0])))) {
		if (!strcmp(argv[0], "branch"))
			keymap = get_keymap("refs", strlen("refs"));
		if (!keymap)
			return error("Unknown key map: %s", argv[0]);
	}

	for (keys = 0, key_arg = argv[1]; *key_arg && keys < ARRAY_SIZE(key); keys++) {
		enum status_code code = get_key_value(&key_arg, &key[keys]);

		if (code != SUCCESS)
			return code;
	}

	if (*key_arg && keys == ARRAY_SIZE(key))
		return error("Except for <Esc> combos only one key is allowed "
			     "in key combos: %s", argv[1]);

	request = get_request(argv[2]);
	if (request == REQ_UNKNOWN) {
		static const char *obsolete[][2] = {
			{ "view-branch",		"view-refs" },
		};
		static const char *toggles[][2] = {
			{ "diff-context-down",		"diff-context" },
			{ "diff-context-up",		"diff-context" },
			{ "stage-next",			":/^@@" },
			{ "toggle-author",		"author" },
			{ "toggle-changes",		"show-changes" },
			{ "toggle-commit-order",	"show-commit-order" },
			{ "toggle-date",		"date" },
			{ "toggle-files",		"file-filter" },
			{ "toggle-file-filter",		"file-filter" },
			{ "toggle-file-size",		"file-size" },
			{ "toggle-filename",		"filename" },
			{ "toggle-graphic",		"show-graphic" },
			{ "toggle-id",			"id" },
			{ "toggle-ignore-space",	"show-ignore-space" },
			{ "toggle-lineno",		"line-number" },
			{ "toggle-refs",		"commit-title-refs" },
			{ "toggle-rev-graph",		"commit-title-graph" },
			{ "toggle-show-changes",	"show-changes" },
			{ "toggle-sort-field",		"sort-field" },
			{ "toggle-sort-order",		"sort-order" },
			{ "toggle-title-overflow",	"commit-title-overflow" },
			{ "toggle-untracked-dirs",	"status-untracked-dirs" },
			{ "toggle-vertical-split",	"show-vertical-split" },
		};
		int alias;

		alias = find_remapped(obsolete, ARRAY_SIZE(obsolete), argv[2]);
		if (alias != -1) {
			const char *action = obsolete[alias][1];

			add_keybinding(keymap, get_request(action), key, keys);
			return error("%s has been renamed to %s",
				     obsolete[alias][0], action);
		}

		alias = find_remapped(toggles, ARRAY_SIZE(toggles), argv[2]);
		if (alias != -1) {
			const char *action = toggles[alias][0];
			const char *arg = prefixcmp(action, "diff-context-")
					? NULL : (strstr(action, "-down") ? "-1" : "+1");
			const char *mapped = toggles[alias][1];
			const char *toggle[] = { ":toggle", mapped, arg, NULL};
			const char *other[] = { mapped, NULL };
			const char **prompt = *mapped == ':' ? other : toggle;
			enum status_code code = add_run_request(keymap, key, keys, prompt);

			if (code == SUCCESS)
				code = error("%s has been replaced by `%s%s%s%s'",
					     action, prompt == other ? mapped : ":toggle ",
					     prompt == other ? "" : mapped,
					     arg ? " " : "", arg ? arg : "");
			return code;
		}
	}

	if (request == REQ_UNKNOWN)
		return add_run_request(keymap, key, keys, argv + 2);

	return add_keybinding(keymap, request, key, keys);
}
Exemple #2
0
/* Wants: mode request key */
static enum status_code
option_bind_command(int argc, const char *argv[])
{
	enum request request;
	struct keymap *keymap;
	int key;

	if (argc < 3)
		return ERROR_WRONG_NUMBER_OF_ARGUMENTS;

	if (!(keymap = get_keymap(argv[0])))
		return ERROR_UNKNOWN_KEY_MAP;

	key = get_key_value(argv[1]);
	if (key == ERR)
		return ERROR_UNKNOWN_KEY;

	request = get_request(argv[2]);
	if (request == REQ_UNKNOWN) {
		static const struct enum_map_entry obsolete[] = {
			ENUM_MAP_ENTRY("cherry-pick",		REQ_NONE),
			ENUM_MAP_ENTRY("screen-resize",	REQ_NONE),
			ENUM_MAP_ENTRY("tree-parent",		REQ_PARENT),
		};
		int alias;

		if (map_enum(&alias, obsolete, argv[2])) {
			if (alias != REQ_NONE)
				add_keybinding(keymap, alias, key);
			return ERROR_OBSOLETE_REQUEST_NAME;
		}
	}

	if (request == REQ_UNKNOWN) {
		enum run_request_flag flags = RUN_REQUEST_FORCE;

		if (strchr("!?@<", *argv[2])) {
			while (*argv[2]) {
				if (*argv[2] == '@') {
					flags |= RUN_REQUEST_SILENT;
				} else if (*argv[2] == '?') {
					flags |= RUN_REQUEST_CONFIRM;
				} else if (*argv[2] == '<') {
					flags |= RUN_REQUEST_EXIT;
				} else if (*argv[2] != '!') {
					break;
				}
				argv[2]++;
			}

		} else if (*argv[2] == ':') {
			argv[2]++;
			flags |= RUN_REQUEST_INTERNAL;

		} else {
			return ERROR_UNKNOWN_REQUEST_NAME;
		}

		return add_run_request(keymap, key, argv + 2, flags)
			? SUCCESS : ERROR_OUT_OF_MEMORY;
	}

	add_keybinding(keymap, request, key);

	return SUCCESS;
}
Exemple #3
0
/* Wants: mode request key */
static enum status_code
option_bind_command(int argc, const char *argv[])
{
	struct key_input input;
	enum request request;
	struct keymap *keymap;

	if (argc < 3)
		return error("Invalid key binding: bind keymap key action");

	if (!(keymap = get_keymap(argv[0], strlen(argv[0])))) {
		if (!strcmp(argv[0], "branch"))
			keymap = get_keymap("refs", strlen("refs"));
		if (!keymap)
			return error("Unknown key map: %s", argv[0]);
	}

	if (get_key_value(argv[1], &input) == ERR)
		return error("Unknown key: %s", argv[1]);

	request = get_request(argv[2]);
	if (request == REQ_UNKNOWN) {
		static const char *obsolete[][2] = {
			{ "view-branch",		"view-refs" },
		};
		static const char *toggles[][2] = {
			{ "diff-context-down",		"diff-context" },
			{ "diff-context-up",		"diff-context" },
			{ "toggle-author",		"show-author" },
			{ "toggle-changes",		"show-changes" },
			{ "toggle-commit-order",	"show-commit-order" },
			{ "toggle-date",		"show-date" },
			{ "toggle-file-filter",		"file-filter" },
			{ "toggle-file-size",		"show-file-size" },
			{ "toggle-filename",		"show-filename" },
			{ "toggle-graphic",		"show-graphic" },
			{ "toggle-id",			"show-id" },
			{ "toggle-ignore-space",	"show-ignore-space" },
			{ "toggle-lineno",		"show-line-numbers" },
			{ "toggle-refs",		"show-refs" },
			{ "toggle-rev-graph",		"show-rev-graph" },
			{ "toggle-sort-field",		"sort-field" },
			{ "toggle-sort-order",		"sort-order" },
			{ "toggle-title-overflow",	"show-title-overflow" },
			{ "toggle-untracked-dirs",	"status-untracked-dirs" },
			{ "toggle-vertical-split",	"show-vertical-split" },
		};
		int alias;

		alias = find_remapped(obsolete, ARRAY_SIZE(obsolete), argv[2]);
		if (alias != -1) {
			const char *action = obsolete[alias][1];

			add_keybinding(keymap, get_request(action), &input);
			return error("%s has been renamed to %s",
				     obsolete[alias][0], action);
		}

		alias = find_remapped(toggles, ARRAY_SIZE(toggles), argv[2]);
		if (alias != -1) {
			const char *action = toggles[alias][0];
			const char *arg = prefixcmp(action, "diff-context-")
					? NULL : (strstr(action, "-down") ? "-1" : "+1");
			const char *toggle[] = { ":toggle", toggles[alias][1], arg, NULL};
			enum status_code code = add_run_request(keymap, &input, toggle);

			if (code == SUCCESS)
				code = error("%s has been replaced by `:toggle %s%s%s'",
					     action, toggles[alias][1],
					     arg ? " " : "", arg ? arg : "");
			return code;
		}
	}

	if (request == REQ_UNKNOWN)
		return add_run_request(keymap, &input, argv + 2);

	return add_keybinding(keymap, request, &input);
}