diff options
author | 2004-06-12 15:04:41 +0000 | |
---|---|---|
committer | 2004-06-12 15:04:41 +0000 | |
commit | 2ec46f89f940e09f0f8afdf9c340e6fa996ee2a0 (patch) | |
tree | ecf47f786996a989059058c87a2e39d796f96d02 | |
parent | Make route show output similar to netstat -r output. (diff) | |
download | wireguard-openbsd-2ec46f89f940e09f0f8afdf9c340e6fa996ee2a0.tar.xz wireguard-openbsd-2ec46f89f940e09f0f8afdf9c340e6fa996ee2a0.zip |
make M-x gid try to guess the symbol name to look up by looking at the
current word.
ok beck@
-rw-r--r-- | usr.bin/mg/grep.c | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/usr.bin/mg/grep.c b/usr.bin/mg/grep.c index 9223eb033b6..55d89cc6107 100644 --- a/usr.bin/mg/grep.c +++ b/usr.bin/mg/grep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grep.c,v 1.10 2004/01/15 20:55:47 vincent Exp $ */ +/* $OpenBSD: grep.c,v 1.11 2004/06/12 15:04:41 vincent Exp $ */ /* * Copyright (c) 2001 Artur Grabowski <art@openbsd.org>. All rights reserved. * @@ -27,6 +27,8 @@ #include "kbd.h" #include "funmap.h" +#include <ctype.h> + static int compile_goto_error(int, int); static int next_error(int, int); static int grep(int, int); @@ -123,13 +125,39 @@ static int gid(int f, int n) { char command[NFILEN + 20]; - char prompt[NFILEN]; + char prompt[NFILEN], c; BUFFER *bp; MGWIN *wp; + int i, j; + + /* catch ([^\s(){}]+)[\s(){}]* */ + + i = curwp->w_doto; + /* Skip delimiters we are currently on */ + while (i > 0 && ((c = lgetc(curwp->w_dotp, i)) == '(' || c == ')' || + c == '{' || c == '}' || isspace(c))) + i--; + /* Skip the symbol itself */ + for (; i > 0; i--) { + c = lgetc(curwp->w_dotp, i - 1); + if (isspace(c) || c == '(' || c == ')' || + c == '{' || c == '}') + break; + } + /* Fill the symbol in prompt[] */ + for (j = 0; j < sizeof(prompt) - 1 && i < llength(curwp->w_dotp); + j++, i++) { + c = lgetc(curwp->w_dotp, i); + if (isspace(c) || c == '(' || c == ')' || + c == '{' || c == '}') + break; + prompt[j] = c; + } + prompt[j] = '\0'; - if (eread("Run gid (with args): ", prompt, NFILEN, EFNEW|EFCR) == ABORT) + if (eread("Run gid (with args): ", prompt, NFILEN, + (j ? EFDEF : 0)|EFNEW|EFCR) == ABORT) return ABORT; - (void)snprintf(command, sizeof command, "gid %s", prompt); if ((bp = compile_mode("*gid*", command)) == NULL) |