aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-01-04 22:22:07 +0100
committerMarc André Tanner <mat@brain-dump.org>2015-01-04 22:31:50 +0100
commitc6953f92be304c637ecb64a8ef363c151ec0f409 (patch)
tree7f6d2153f094beac6cf3f8d38c6748b316ecb503
parentf356d76752c59bef8e4034e759226ab36c8a1a62 (diff)
downloadvis-c6953f92be304c637ecb64a8ef363c151ec0f409.tar.gz
vis-c6953f92be304c637ecb64a8ef363c151ec0f409.tar.xz
Simplify jump to line :nnn
As a side effect this also allows to jump to marks via :'m
-rw-r--r--config.def.h1
-rw-r--r--vis.c25
2 files changed, 11 insertions, 15 deletions
diff --git a/config.def.h b/config.def.h
index 0ca896b..370fb1b 100644
--- a/config.def.h
+++ b/config.def.h
@@ -47,7 +47,6 @@ enum {
/* command recognized at the ':'-prompt. tested top to bottom, first match wins. */
static Command cmds[] = {
- { "^[0-9]+$", cmd_gotoline, false },
{ "^bd(elete)?!?$", cmd_bdelete, false },
{ "^e(dit)?!?$", cmd_edit, false },
{ "^new$", cmd_new, false },
diff --git a/vis.c b/vis.c
index d86b9ec..6ef4964 100644
--- a/vis.c
+++ b/vis.c
@@ -483,8 +483,6 @@ static void quit(const Arg *arg);
/** commands to enter at the ':'-prompt */
/* set various runtime options */
static bool cmd_set(Filerange*, const char *argv[]);
-/* goto line indicated by argv[0] */
-static bool cmd_gotoline(Filerange*, const char *argv[]);
/* for each argument create a new window and open the corresponding file */
static bool cmd_open(Filerange*, const char *argv[]);
/* close current window (discard modifications if argv[0] contains '!')
@@ -1422,12 +1420,6 @@ static bool cmd_set(Filerange *range, const char *argv[]) {
return true;
}
-static bool cmd_gotoline(Filerange *range, const char *argv[]) {
- action.count = strtoul(argv[0], NULL, 10);
- movement(&(const Arg){ .i = action.count <= 1 ? MOVE_FILE_BEGIN : MOVE_LINE });
- return true;
-}
-
static bool cmd_open(Filerange *range, const char *argv[]) {
for (const char **file = &argv[1]; *file; file++) {
if (!editor_window_new(vis, *file)) {
@@ -1677,10 +1669,11 @@ static Filepos parse_pos(char **cmd) {
static Filerange parse_range(char **cmd) {
Text *txt = vis->win->text;
- Filerange r = (Filerange){ .start = 0, .end = text_size(txt) };
- char *start = *cmd;
+ Filerange r = text_range_empty();
switch (**cmd) {
case '%':
+ r.start = 0;
+ r.end = text_size(txt);
(*cmd)++;
break;
case '*':
@@ -1690,10 +1683,8 @@ static Filerange parse_range(char **cmd) {
break;
default:
r.start = parse_pos(cmd);
- if (**cmd != ',') {
- *cmd = start;
- return text_range_empty();
- }
+ if (**cmd != ',')
+ return r;
(*cmd)++;
r.end = parse_pos(cmd);
break;
@@ -1713,6 +1704,12 @@ static bool exec_cmdline_command(char *cmdline) {
char *cmdstart = cmdline;
Filerange range = parse_range(&cmdstart);
if (!text_range_valid(&range)) {
+ /* if only one position was given, jump to it */
+ if (range.start != EPOS && !*cmdstart) {
+ window_cursor_to(vis->win->win, range.start);
+ return true;
+ }
+
if (cmdstart != cmdline) {
editor_info_show(vis, "Invalid range\n");
return false;