summary refs log tree commit diff
path: root/Src/Zle/deltochar.c
diff options
context:
space:
mode:
Diffstat (limited to 'Src/Zle/deltochar.c')
-rw-r--r--Src/Zle/deltochar.c60
1 files changed, 42 insertions, 18 deletions
diff --git a/Src/Zle/deltochar.c b/Src/Zle/deltochar.c
index 87f8593b8..054e7fe23 100644
--- a/Src/Zle/deltochar.c
+++ b/Src/Zle/deltochar.c
@@ -31,21 +31,24 @@
 #include "deltochar.pro"
 
 static Widget w_deletetochar;
+static Widget w_zaptochar;
 
 /**/
-static void
-deltochar(void)
+static int
+deltochar(UNUSED(char **args))
 {
     int c = getkey(0), dest = cs, ok = 0, n = zmult;
+    int zap = (bindk->widget == w_zaptochar);
 
     if (n > 0) {
 	while (n-- && dest != ll) {
 	    while (dest != ll && line[dest] != c)
 		dest++;
 	    if (dest != ll) {
-		dest++;
+		if (!zap || n > 0)
+		    dest++;
 		if (!n) {
-		    foredel(dest - cs);
+		    forekill(dest - cs, 0);
 		    ok++;
 		}
 	    }
@@ -57,35 +60,56 @@ deltochar(void)
 	while (n++ && dest != 0) {
 	    while (dest != 0 && line[dest] != c)
 		dest--;
-	    if (line[dest] == c && !n) {
-		backdel(cs - dest);
-		ok++;
+	    if (line[dest] == c) {
+		if (!n) {
+		    backkill(cs - dest - zap, 1);
+		    ok++;
+		}
+		if (dest)
+		    dest--;
 	    }
 	}
     }
-    if (!ok)
-	feep();
+    return !ok;
+}
+
+/**/
+int
+setup_(UNUSED(Module m))
+{
+    return 0;
 }
 
 /**/
 int
-boot_deltochar(Module m)
+boot_(Module m)
 {
-    w_deletetochar = addzlefunction("delete-to-char", deltochar, ZLE_KEEPSUFFIX);
-    if (w_deletetochar)
-	return 0;
-    zwarnnam(m->nam, "name clash when adding ZLE function `delete-to-char'",
+    w_deletetochar = addzlefunction("delete-to-char", deltochar,
+                                    ZLE_KILL | ZLE_KEEPSUFFIX);
+    if (w_deletetochar) {
+	w_zaptochar = addzlefunction("zap-to-char", deltochar,
+				     ZLE_KILL | ZLE_KEEPSUFFIX);
+	if (w_zaptochar)
+	    return 0;
+	deletezlefunction(w_deletetochar);
+    }
+    zwarnnam(m->nam, "deltochar: name clash when adding ZLE functions",
 	     NULL, 0);
     return -1;
 }
 
-#ifdef MODULE
-
 /**/
 int
-cleanup_deltochar(Module m)
+cleanup_(UNUSED(Module m))
 {
     deletezlefunction(w_deletetochar);
+    deletezlefunction(w_zaptochar);
+    return 0;
+}
+
+/**/
+int
+finish_(UNUSED(Module m))
+{
     return 0;
 }
-#endif