shithub: vexed

Download patch

ref: 1d8e44d00b264710d842a35a06073d7963f0dd5f
parent: 3aa02825d58581cfe0c1b4cafd278107908ac9e6
author: phil9 <telephil9@gmail.com>
date: Wed Dec 29 01:20:18 EST 2021

add action to go to a specific address

	address can be entered either in decimal or in hexadecimal
	in which case it needs to begin with 0x

--- a/README.md
+++ b/README.md
@@ -6,6 +6,7 @@
 Move using the arrow keys or select using the mouse.  
 Scroll with page up/down, the mouse wheel or using the scrollbar.  
 Home and End keys go to the beginning and end of the file respectively.  
+`g` go to given location which can be entered in decimal or in hexadecimal (starting with 0x).  
 `i` inserts a byte before the current selection.  
 `p` inserts a byte after the current selection.  
 `x` deletes the currently selected byte.  
--- a/vexed.c
+++ b/vexed.c
@@ -23,8 +23,8 @@
 	Scrollwidth = 12,
 };
 
-enum { Mdelete, Minsert, Mappend };
-char *menu2str[] = { "delete", "insert", "append", 0 };
+enum { Mgoto, Mdelete, Minsert, Mappend };
+char *menu2str[] = { "go...", "delete", "insert", "append", 0 };
 Menu menu2 = { menu2str };
 
 enum { Msave, Mquit, };
@@ -47,6 +47,23 @@
 int sel = 0;
 
 void
+xgoto(void)
+{
+	char b[16] = {0}, *endp;
+	int n;
+
+	if(enter("Go to:", b, sizeof b, mctl, kctl, nil) <= 0)
+		return;
+	n = strtol(b, &endp, 0);
+	if(endp == nil || endp == b)
+		return;
+	if(n < 0 || n >= buf.count)
+		return;
+	sel = n;
+	redraw();
+}
+
+void
 xdelete(void)
 {
 	if(delete(&buf, sel) < 0)
@@ -239,6 +256,9 @@
 
 	n = menuhit(2, mctl, &menu2, nil);
 	switch(n){
+	case Mgoto:
+		xgoto();
+		break;
 	case Mdelete:
 		xdelete();
 		break;
@@ -399,6 +419,10 @@
 				offset = blines - blines%nlines;
 			redraw();
 		}
+		break;
+	case 'g':
+	case 'G':
+		xgoto();
 		break;
 	case 'x':
 	case 'X':