From 5dbacce10b4cc5fe0785840c09398fc5b19fb96a Mon Sep 17 00:00:00 2001 From: han Date: Sat, 12 Nov 2022 11:05:42 +0100 Subject: [PATCH] merging upstream: See https://cvsweb.openbsd.org/src/usr.bin/mg/?sortby=date#dirlist for details --- CVS/Entries | 84 ++++++++++++++++++++++++++--------------------------- cmode.c | 4 +-- def.h | 5 +++- dired.c | 4 +-- echo.c | 22 +++++++------- funmap.c | 4 ++- keymap.c | 4 +-- mg.1 | 11 +++++-- search.c | 73 +++++++++++++++++++++++++++++++++++++++++++++- 9 files changed, 147 insertions(+), 64 deletions(-) diff --git a/CVS/Entries b/CVS/Entries index 16c4e5c0..1ccd3d6c 100644 --- a/CVS/Entries +++ b/CVS/Entries @@ -3,52 +3,52 @@ /fileio.c/1.108/Result of merge// /region.c/1.39/Result of merge// /ttyio.c/1.40/Result of merge// -/def.h/1.176/Result of merge// -/dired.c/1.100/Result of merge// /main.c/1.90/Result of merge// /re_search.c/1.36/Result of merge// -/README/1.14/Sun Aug 1 20:42:15 2021// -/chrdef.h/1.10/Sun Aug 1 20:42:15 2021// -/cinfo.c/1.18/Sun Aug 1 20:42:15 2021// -/display.c/1.48/Sun Aug 1 20:42:15 2021// /extend.c/1.75/Sun Aug 1 20:42:15 2021// -/file.c/1.102/Sun Aug 1 20:42:15 2021// -/funmap.h/1.8/Sun Aug 1 20:42:15 2021// -/kbd.h/1.19/Sun Aug 1 20:42:15 2021// -/key.h/1.6/Sun Aug 1 20:42:15 2021// -/macro.c/1.16/Sun Aug 1 20:42:15 2021// -/macro.h/1.7/Sun Aug 1 20:42:15 2021// -/modes.c/1.21/Sun Aug 1 20:42:15 2021// -/paragraph.c/1.46/Sun Aug 1 20:42:15 2021// -/pathnames.h/1.1/Sun Aug 1 20:42:15 2021// -/search.c/1.47/Sun Aug 1 20:42:15 2021// -/spawn.c/1.12/Sun Aug 1 20:42:15 2021// /version.c/1.10/Sun Aug 1 20:42:15 2021// -/window.c/1.36/Sun Aug 1 20:42:15 2021// -/word.c/1.19/Sun Aug 1 20:42:15 2021// -/autoexec.c/1.18/Sun Nov 21 22:19:09 2021// -/bell.c/1.6/Sun Nov 21 22:19:09 2021// -/buffer.c/1.112/Sun Nov 21 22:19:09 2021// -/dir.c/1.32/Sat Feb 12 21:09:39 2022// -/echo.c/1.68/Sun Nov 21 22:19:09 2021// -/funmap.c/1.63/Sun Nov 21 22:19:09 2021// -/grep.c/1.49/Sun Nov 21 22:19:09 2021// -/help.c/1.36/Sat Feb 12 21:09:39 2022// /interpreter.c/1.34/Result of merge+Sat Feb 12 21:09:39 2022// -/kbd.c/1.35/Sun Nov 21 22:19:09 2021// -/keymap.c/1.59/Sun Nov 21 22:19:09 2021// -/line.c/1.63/Sun Nov 21 22:19:09 2021// -/log.c/1.12/Sun Nov 21 22:19:09 2021// -/log.h/1.6/Sun Nov 21 22:19:09 2021// -/match.c/1.22/Sun Nov 21 22:19:09 2021// /tags.c/1.17/Result of merge// -/tty.c/1.39/Sun Nov 21 22:19:09 2021// -/ttykbd.c/1.20/Sun Nov 21 22:19:09 2021// -/yank.c/1.15/Sun Nov 21 22:19:09 2021// -/mg.1/1.126/Thu Mar 31 20:05:13 2022// -/basic.c/1.51/Sat Jun 11 23:27:52 2022// -/cmode.c/1.18/Sat Jun 11 23:27:52 2022// -/cscope.c/1.21/Sat Jun 11 23:27:52 2022// -/util.c/1.44/Sat Jun 11 23:27:52 2022// -/tutorial/1.19/Sat Jul 23 09:28:43 2022// +/README/1.14/Wed Aug 24 19:54:15 2022// +/autoexec.c/1.18/Wed Aug 24 19:54:15 2022// +/basic.c/1.51/Wed Aug 24 19:54:15 2022// +/bell.c/1.6/Wed Aug 24 19:54:15 2022// +/buffer.c/1.112/Wed Aug 24 19:54:15 2022// +/chrdef.h/1.10/Wed Aug 24 19:54:15 2022// +/cinfo.c/1.18/Wed Aug 24 19:54:15 2022// +/cmode.c/1.19/Sat Nov 12 10:02:34 2022// +/cscope.c/1.21/Wed Aug 24 19:54:15 2022// +/def.h/1.177/Result of merge// +/dir.c/1.32/Wed Aug 24 19:54:15 2022// +/dired.c/1.101/Result of merge// +/display.c/1.48/Wed Aug 24 19:54:15 2022// +/echo.c/1.69/Sat Nov 12 10:02:34 2022// +/file.c/1.102/Wed Aug 24 19:54:15 2022// +/funmap.c/1.64/Sat Nov 12 10:02:34 2022// +/funmap.h/1.8/Wed Aug 24 19:54:15 2022// +/grep.c/1.49/Wed Aug 24 19:54:15 2022// +/help.c/1.36/Wed Aug 24 19:54:15 2022// +/kbd.c/1.35/Wed Aug 24 19:54:15 2022// +/kbd.h/1.19/Wed Aug 24 19:54:15 2022// +/key.h/1.6/Wed Aug 24 19:54:15 2022// +/keymap.c/1.60/Sat Nov 12 10:02:34 2022// +/line.c/1.63/Wed Aug 24 19:54:15 2022// +/log.c/1.12/Wed Aug 24 19:54:15 2022// +/log.h/1.6/Wed Aug 24 19:54:15 2022// +/macro.c/1.16/Wed Aug 24 19:54:15 2022// +/macro.h/1.7/Wed Aug 24 19:54:15 2022// +/match.c/1.22/Wed Aug 24 19:54:15 2022// +/mg.1/1.127/Sat Nov 12 10:02:34 2022// +/modes.c/1.21/Wed Aug 24 19:54:15 2022// +/paragraph.c/1.46/Wed Aug 24 19:54:15 2022// +/pathnames.h/1.1/Wed Aug 24 19:54:15 2022// +/search.c/1.48/Sat Nov 12 10:02:35 2022// +/spawn.c/1.12/Wed Aug 24 19:54:15 2022// +/tty.c/1.39/Wed Aug 24 19:54:15 2022// +/ttykbd.c/1.20/Wed Aug 24 19:54:15 2022// +/tutorial/1.19/Wed Aug 24 19:54:15 2022// +/util.c/1.44/Wed Aug 24 19:54:15 2022// +/window.c/1.36/Wed Aug 24 19:54:15 2022// +/word.c/1.19/Wed Aug 24 19:54:15 2022// +/yank.c/1.15/Wed Aug 24 19:54:15 2022// D diff --git a/cmode.c b/cmode.c index bd231d12..c5e5a8df 100644 --- a/cmode.c +++ b/cmode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmode.c,v 1.18 2022/05/24 16:24:31 op Exp $ */ +/* $OpenBSD: cmode.c,v 1.19 2022/10/15 09:54:29 op Exp $ */ /* * This file is in the public domain. * @@ -86,7 +86,7 @@ static struct KEYMAPE (3) cmodemap = { } }; -/* Funtion, Mode hooks */ +/* Function, Mode hooks */ void cmode_init(void) diff --git a/def.h b/def.h index 63d9d306..4fb8ba6b 100644 --- a/def.h +++ b/def.h @@ -1,4 +1,4 @@ -/* $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. */ @@ -662,6 +662,9 @@ int queryrepl(int, int); 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); diff --git a/dired.c b/dired.c index 40f08da8..c5f330fe 100644 --- a/dired.c +++ b/dired.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dired.c,v 1.100 2021/05/02 14:13:17 lum Exp $ */ +/* $OpenBSD: dired.c,v 1.101 2022/10/15 17:01:14 op Exp $ */ /* This file is in the public domain. */ @@ -1189,7 +1189,7 @@ gotofile(char *fpth) ewprintf("File not found %s", fname); return (FALSE); } else { - ewprintf(""); + eerase(); return (TRUE); } } diff --git a/echo.c b/echo.c index ced1a2dc..9b90aaa5 100644 --- a/echo.c +++ b/echo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: echo.c,v 1.68 2021/03/02 15:03:35 lum Exp $ */ +/* $OpenBSD: echo.c,v 1.69 2022/10/15 17:01:14 op Exp $ */ /* This file is in the public domain. */ @@ -67,15 +67,15 @@ eyorn(const char *sp) for (;;) { s = getkey(FALSE); if (s == 'y' || s == 'Y' || s == ' ') { - ewprintf(""); + eerase(); return (TRUE); } if (s == 'n' || s == 'N' || s == CCHR('M')) { - ewprintf(""); + eerase(); return (FALSE); } if (s == CCHR('G')) { - ewprintf(""); + eerase(); return (ctrlg(FFRAND, 1)); } ewprintf("Please answer y or n. %s? (y or n) ", sp); @@ -101,19 +101,19 @@ eynorr(const char *sp) for (;;) { s = getkey(FALSE); if (s == 'y' || s == 'Y' || s == ' ') { - ewprintf(""); + eerase(); return (TRUE); } if (s == 'n' || s == 'N' || s == CCHR('M')) { - ewprintf(""); + eerase(); return (FALSE); } if (s == 'r' || s == 'R') { - ewprintf(""); + eerase(); return (REVERT); } if (s == CCHR('G')) { - ewprintf(""); + eerase(); return (ctrlg(FFRAND, 1)); } ewprintf("Please answer y, n or r."); @@ -137,7 +137,7 @@ eyesno(const char *sp) EFNUL | EFNEW | EFCR, sp); for (;;) { if (rep == NULL) { - ewprintf(""); + eerase(); return (ABORT); } if (rep[0] != '\0') { @@ -149,11 +149,11 @@ eyesno(const char *sp) free(lp); } if (strcasecmp(rep, "yes") == 0) { - ewprintf(""); + eerase(); return (TRUE); } if (strcasecmp(rep, "no") == 0) { - ewprintf(""); + eerase(); return (FALSE); } } diff --git a/funmap.c b/funmap.c index 36a88e45..2b704fcf 100644 --- a/funmap.c +++ b/funmap.c @@ -1,4 +1,4 @@ -/* $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 */ @@ -138,6 +138,8 @@ static struct funmap functnames[] = { {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}, diff --git a/keymap.c b/keymap.c index 32a9267d..6e47e4f6 100644 --- a/keymap.c +++ b/keymap.c @@ -1,4 +1,4 @@ -/* $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. */ @@ -290,7 +290,7 @@ static PF metal[] = { copyregion, /* w */ extend, /* x */ rescan, /* y */ - rescan, /* z */ + zaptochar, /* z */ gotobop, /* { */ piperegion, /* | */ gotoeop /* } */ diff --git a/mg.1 b/mg.1 index a335c89e..f23e3c04 100644 --- a/mg.1 +++ b/mg.1 @@ -1,7 +1,7 @@ -.\" $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 @@ -331,6 +331,8 @@ scroll-down copy-region-as-kill .It M-x execute-extended-command +.It M-z +zap-to-char .It M-{ backward-paragraph .It M-| @@ -986,6 +988,11 @@ Unlike emacs, the 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. diff --git a/search.c b/search.c index fa12b409..931288f6 100644 --- a/search.c +++ b/search.c @@ -1,4 +1,4 @@ -/* $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. */ @@ -853,3 +853,74 @@ readpattern(char *r_prompt) 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); +}