-/* $OpenBSD: def.h,v 1.176 2021/05/06 14:16:12 lum Exp $ */
+/* $OpenBSD: def.h,v 1.177 2022/10/20 18:59:24 op Exp $ */
/* This file is in the public domain. */
int forwsrch(void);
int backsrch(void);
int readpattern(char *);
+int zapuptochar(int, int);
+int zaptochar(int, int);
+int zap(int, int);
/* spawn.c X */
int spawncli(int, int);
-/* $OpenBSD: funmap.c,v 1.63 2021/04/22 19:50:55 lum Exp $ */
+/* $OpenBSD: funmap.c,v 1.64 2022/10/20 18:59:24 op Exp $ */
/* This file is in the public domain */
{killbuffer_cmd, "kill-buffer", 1},
{killline, "kill-line", 1},
{killpara, "kill-paragraph", 1},
+ {zaptochar, "zap-to-char", 1},
+ {zapuptochar, "zap-up-to-char", 1},
{killregion, "kill-region", 0},
{delfword, "kill-word", 1},
{toggleleavetmp, "leave-tmpdir-backups", 0},
-/* $OpenBSD: keymap.c,v 1.59 2021/04/20 10:02:50 lum Exp $ */
+/* $OpenBSD: keymap.c,v 1.60 2022/10/20 18:59:24 op Exp $ */
/* This file is in the public domain. */
copyregion, /* w */
extend, /* x */
rescan, /* y */
- rescan, /* z */
+ zaptochar, /* z */
gotobop, /* { */
piperegion, /* | */
gotoeop /* } */
-.\" $OpenBSD: mg.1,v 1.126 2022/03/31 17:27:25 naddy Exp $
+.\" $OpenBSD: mg.1,v 1.127 2022/10/20 18:59:24 op Exp $
.\" This file is in the public domain.
.\"
-.Dd $Mdocdate: March 31 2022 $
+.Dd $Mdocdate: October 20 2022 $
.Dt MG 1
.Os
.Sh NAME
copy-region-as-kill
.It M-x
execute-extended-command
+.It M-z
+zap-to-char
.It M-{
backward-paragraph
.It M-|
kill buffer consists only
of the most recent kill.
It is not a ring.
+.It zap-to-char
+Ask for a character and delete text from the current cursor position
+until the next instance of that character, including it.
+.It zap-up-to-char
+Like zap-to-char but doesn't delete the target character.
.El
.Sh MG DIRED KEY BINDINGS
Specific key bindings are available in dired mode.
-/* $OpenBSD: search.c,v 1.47 2018/07/11 12:21:37 krw Exp $ */
+/* $OpenBSD: search.c,v 1.48 2022/10/20 18:59:24 op Exp $ */
/* This file is in the public domain. */
retval = FALSE;
return (retval);
}
+
+/*
+ * Prompt for a character and kill until its next occurrence,
+ * including it. Mark is cleared afterwards.
+ */
+int
+zaptochar(int f, int n)
+{
+ return (zap(TRUE, n));
+}
+
+/* Like zaptochar but stops before the character. */
+int
+zapuptochar(int f, int n)
+{
+ return (zap(FALSE, n));
+}
+
+/*
+ * Prompt for a charcter and deletes from the point up to, optionally
+ * including, the first instance of that charcters. Marks is cleared
+ * afterwards.
+ */
+int
+zap(int including, int n)
+{
+ int s, backward;
+
+ backward = n < 0;
+ if (backward)
+ n = -n;
+
+ if (including)
+ ewprintf("Zap to char: ");
+ else
+ ewprintf("Zap up to char: ");
+
+ s = getkey(FALSE);
+ eerase();
+ if (s == ABORT || s == CCHR('G'))
+ return (FALSE);
+
+ if (n == 0)
+ return (TRUE);
+
+ pat[0] = (char)s;
+ pat[1] = '\0';
+
+ isetmark();
+ while (n--) {
+ s = backward ? backsrch() : forwsrch();
+ if (s != TRUE) {
+ dobeep();
+ ewprintf("Search failed: \"%s\"", pat);
+ swapmark(FFARG, 0);
+ clearmark(FFARG, 0);
+ return (s);
+ }
+ }
+
+ if (!including) {
+ if (backward)
+ forwchar(FFARG, 1);
+ else
+ backchar(FFARG, 1);
+ }
+
+ killregion(FFARG, 0);
+ clearmark(FFARG, 0);
+ return (TRUE);
+}