[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

make mg's `gid' try to guess the symbol



Try to guess the symbol the user might want to look up by looking
under dot.

please test.

-vincent

Index: grep.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/grep.c,v
retrieving revision 1.10
diff -u -r1.10 grep.c
--- grep.c	2004/01/15 20:55:47	1.10
+++ grep.c	2004/06/11 13:33:19
@@ -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,45 @@
 gid(int f, int n)
 {
 	char command[NFILEN + 20];
-	char prompt[NFILEN];
+	char prompt[NFILEN], c;
 	BUFFER *bp;
 	MGWIN *wp;
+	int i, j;
 
-	if (eread("Run gid (with args): ", prompt, NFILEN, EFNEW|EFCR) == ABORT)
-		return ABORT;
+	/* 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 (j) {
+		if (eread("Run gid (with args): [%s] ", prompt, NFILEN,
+		    EFNEW|EFCR, prompt) == ABORT)
+			return ABORT;
+	} else {
+		if (eread("Run gid (with args): ", prompt, NFILEN,
+		    EFNEW|EFCR) == ABORT)
+			return ABORT;
+	}
 	(void)snprintf(command, sizeof command, "gid %s", prompt);
 
 	if ((bp = compile_mode("*gid*", command)) == NULL)