From caf7703318081ebb6902fe51a36e15b28615ed9b Mon Sep 17 00:00:00 2001 From: Brian Callahan Date: Tue, 25 Jul 2023 17:11:31 -0400 Subject: [PATCH] Let's get this going again. mg-7.3 --- CVS/Entries | 106 +++++------ README | 93 ++++++++++ README.md | 2 +- autoexec.c | 3 +- basic.c | 26 +-- bell.c | 4 +- buffer.c | 47 +++-- cmode.c | 33 ++-- configure | 10 + cscope.c | 18 +- def.h | 16 +- dir.c | 7 +- dired.c | 18 +- display.c | 119 ++++++------ echo.c | 24 +-- extend.c | 55 +++--- file.c | 9 +- fileio.c | 41 +++-- funmap.c | 11 +- grep.c | 8 +- help.c | 7 +- interpreter.c | 16 +- kbd.c | 5 +- keymap.c | 8 +- log.c | 4 +- macro.c | 7 +- main.c | 23 ++- match.c | 21 ++- mg.1 | 502 ++++++++++++++++++++++++++++---------------------- modes.c | 6 +- paragraph.c | 17 +- re_search.c | 11 +- region.c | 47 ++--- search.c | 80 +++++++- spawn.c | 5 +- tags.c | 185 ++++++++----------- tty.c | 6 +- ttyio.c | 2 +- ttykbd.c | 15 +- tutorial | 2 +- undo.c | 4 +- util.c | 88 +++++---- version.c | 5 +- window.c | 10 +- word.c | 13 +- yank.c | 4 +- 46 files changed, 908 insertions(+), 835 deletions(-) create mode 100644 README diff --git a/CVS/Entries b/CVS/Entries index 7033ce6..e0fb145 100644 --- a/CVS/Entries +++ b/CVS/Entries @@ -1,54 +1,54 @@ -/version.c/1.10/Thu Mar 19 21:22:15 2015// -/word.c/1.19/Sun Jan 3 04:14:49 2016// -/tags.c/1.16/Result of merge// -/fileio.c/1.108/Result of merge// -/funmap.c/1.63/Result of merge// -/Makefile/1.35/Sat Jun 12 14:25:50 2021// -/README/1.14/Sat Jun 12 14:25:50 2021// -/autoexec.c/1.18/Sat Jun 12 14:25:34 2021// -/basic.c/1.50/Sat Jun 12 14:25:34 2021// -/bell.c/1.6/Sat Jun 12 14:25:50 2021// -/buffer.c/1.112/Sat Jun 12 14:25:34 2021// -/chrdef.h/1.10/Sat Jun 12 14:25:34 2021// -/cinfo.c/1.18/Sat Jun 12 14:25:34 2021// -/cmode.c/1.17/Sat Jun 12 14:25:34 2021// -/cscope.c/1.20/Sat Jun 12 14:25:34 2021// -/def.h/1.176/Result of merge// -/dir.c/1.31/Sat Jun 12 14:25:34 2021// -/dired.c/1.100/Sat Jun 12 14:25:50 2021// -/display.c/1.48/Sat Jun 12 14:25:34 2021// -/echo.c/1.68/Sat Jun 12 14:25:34 2021// -/extend.c/1.75/Result of merge// -/file.c/1.102/Sat Jun 12 14:25:34 2021// -/funmap.h/1.8/Sat Jun 12 14:25:34 2021// -/grep.c/1.49/Sat Jun 12 14:25:34 2021// -/help.c/1.35/Sat Jun 12 14:25:34 2021// -/interpreter.c/1.32/Sat Jun 12 14:25:50 2021// -/kbd.c/1.35/Sat Jun 12 14:25:34 2021// -/kbd.h/1.19/Sat Jun 12 14:25:34 2021// -/key.h/1.6/Sat Jun 12 14:25:34 2021// -/keymap.c/1.59/Sat Jun 12 14:25:34 2021// -/line.c/1.63/Sat Jun 12 14:25:34 2021// -/log.c/1.12/Sat Jun 12 14:25:34 2021// -/log.h/1.6/Sat Jun 12 14:25:34 2021// -/macro.c/1.16/Sat Jun 12 14:25:34 2021// -/macro.h/1.7/Sat Jun 12 14:25:34 2021// -/main.c/1.90/Result of merge// -/match.c/1.22/Sat Jun 12 14:25:34 2021// -/mg.1/1.125/Sat Jun 12 14:25:50 2021// -/modes.c/1.21/Sat Jun 12 14:25:34 2021// -/paragraph.c/1.46/Sat Jun 12 14:25:34 2021// -/pathnames.h/1.1/Sat Jun 12 14:25:34 2021// -/re_search.c/1.36/Sat Jun 12 14:25:34 2021// -/region.c/1.39/Sat Jun 12 14:25:34 2021// -/search.c/1.47/Sat Jun 12 14:25:34 2021// -/spawn.c/1.12/Sat Jun 12 14:25:34 2021// -/tty.c/1.39/Sat Jun 12 14:25:34 2021// -/ttyio.c/1.40/Sat Jun 12 14:25:34 2021// -/ttykbd.c/1.20/Sat Jun 12 14:25:34 2021// -/tutorial/1.18/Sat Jun 12 14:25:34 2021// -/undo.c/1.58/Sat Jun 12 14:25:34 2021// -/util.c/1.43/Sat Jun 12 14:25:34 2021// -/window.c/1.36/Sat Jun 12 14:25:34 2021// -/yank.c/1.15/Sat Jun 12 14:25:34 2021// +/Makefile/1.35/Tue Jul 25 20:51:27 2023// +/README/1.14/Tue Jul 25 20:51:27 2023// +/autoexec.c/1.19/Tue Jul 25 20:51:27 2023// +/basic.c/1.54/Tue Jul 25 20:51:27 2023// +/bell.c/1.7/Tue Jul 25 20:51:27 2023// +/buffer.c/1.114/Tue Jul 25 20:51:27 2023// +/chrdef.h/1.10/Tue Jul 25 20:51:20 2023// +/cinfo.c/1.18/Tue Jul 25 20:51:20 2023// +/cmode.c/1.22/Tue Jul 25 20:51:27 2023// +/cscope.c/1.22/Tue Jul 25 20:51:27 2023// +/def.h/1.180/Result of merge// +/dir.c/1.33/Tue Jul 25 20:51:27 2023// +/dired.c/1.102/Tue Jul 25 20:51:27 2023// +/display.c/1.52/Tue Jul 25 20:51:27 2023// +/echo.c/1.69/Tue Jul 25 20:51:27 2023// +/extend.c/1.80/Result of merge// +/file.c/1.103/Tue Jul 25 20:51:27 2023// +/fileio.c/1.111/Result of merge// +/funmap.c/1.67/Result of merge// +/funmap.h/1.8/Tue Jul 25 20:51:20 2023// +/grep.c/1.50/Tue Jul 25 20:51:27 2023// +/help.c/1.37/Tue Jul 25 20:51:27 2023// +/interpreter.c/1.35/Tue Jul 25 20:51:27 2023// +/kbd.c/1.37/Tue Jul 25 20:51:27 2023// +/kbd.h/1.19/Tue Jul 25 20:51:20 2023// +/key.h/1.6/Tue Jul 25 20:51:20 2023// +/keymap.c/1.61/Tue Jul 25 20:51:27 2023// +/line.c/1.63/Tue Jul 25 20:51:20 2023// +/log.c/1.13/Tue Jul 25 20:51:27 2023// +/log.h/1.6/Tue Jul 25 20:51:20 2023// +/macro.c/1.18/Tue Jul 25 20:51:27 2023// +/macro.h/1.7/Tue Jul 25 20:51:20 2023// +/main.c/1.95/Result of merge// +/match.c/1.25/Tue Jul 25 20:51:27 2023// +/mg.1/1.135/Tue Jul 25 20:51:27 2023// +/modes.c/1.22/Tue Jul 25 20:51:27 2023// +/paragraph.c/1.49/Tue Jul 25 20:51:27 2023// +/pathnames.h/1.1/Tue Jul 25 20:51:20 2023// +/re_search.c/1.37/Tue Jul 25 20:51:27 2023// +/region.c/1.44/Tue Jul 25 20:51:27 2023// +/search.c/1.50/Tue Jul 25 20:51:28 2023// +/spawn.c/1.13/Tue Jul 25 20:51:28 2023// +/tags.c/1.27/Result of merge// +/tty.c/1.40/Tue Jul 25 20:51:28 2023// +/ttyio.c/1.40/Tue Jul 25 20:51:20 2023// +/ttykbd.c/1.22/Tue Jul 25 20:51:28 2023// +/tutorial/1.19/Tue Jul 25 20:51:28 2023// +/undo.c/1.59/Tue Jul 25 20:51:28 2023// +/util.c/1.50/Tue Jul 25 20:51:28 2023// +/version.c/1.11/Result of merge// +/window.c/1.37/Tue Jul 25 20:51:28 2023// +/yank.c/1.16/Tue Jul 25 20:51:28 2023// +/word.c/1.21/Tue Jul 25 20:52:01 2023// D diff --git a/README b/README new file mode 100644 index 0000000..22e8d15 --- /dev/null +++ b/README @@ -0,0 +1,93 @@ +[This is an edited version of the original mg README, updated slightly to +reflect changes in the last 20 years.] + + +Mg (mg) is a Public Domain EMACS style editor. It is "broadly" +compatible with GNU Emacs, the latest creation of Richard M. +Stallman, Chief GNUisance and inventor of Emacs. GNU Emacs (and other +portions of GNU as they are released) are essentially free, (there are +handling charges for obtaining it) and so is Mg. You may never have +to learn another editor. (But probably will, at least long enough to +port Mg...) Mg was formerly named MicroGnuEmacs, the name change was +done at the request of Richard Stallman. + +Mg is not associated with the GNU project, and it does not have the +copyright restrictions present in GNU Emacs. (However, some modules +do have copyright notices.) The Mg authors individually may or may +not agree with the opinions expressed by Richard Stallman in "The GNU +Manifesto". + +This program is intended to be a small, fast, and portable editor for +people who can't (or don't want to) run real Emacs for one reason +or another. It is compatible with GNU because there shouldn't be +any reason to learn more than one Emacs flavor. + + +Beyond the work of Dave Conroy, author of the original public domain +v30, the current version contains the work of: + + blarson@ecla.usc.edu Bob Larson + mic@emx.utexas.edu Mic Kaczmarczik + mwm@violet.berkeley.edu Mike Meyer + sandra@cs.utah.edu Sandra Loosemore + mp1u+@andrew.cmu.edu Michael Portuesi + RCKG01M@CALSTATE.BITNET Stephen Walton + hakanson@mist.cs.orst.edu Marion Hakanson + +People who have worked on previous versions of Mg: + + rtech!daveb@sun.com Dave Brower + +Early release history: + +* Nov 16, 1986: First release to mod.sources +* Mar 3, 1987: First Release (mg1a) via comp.sources.unix +* May 26, 1988: Second release: (mg2a) via comp.sources.misc +* Jan 26, 1992: Linux port released by Charles Hedrick. This version + later makes its way onto tsx-11, Infomagic, and various other Linux + repositories. +* Feb 25, 2000: First import into the OpenBSD tree, where it is + currently maintained with contributions from many others. + +---------------------------------------------------------------------- + +Known limitations: + +Recursive bindings may cause help and key rebinding code to go into +an infinite loop, aborting with a stack overflow. + +Overwrite mode does not work in macros. (Characters are inserted +rather than overwriting.) + +Dired mode has some problems: .. and . are not recognized as special +cases. Also, mg uses the output of the command 'ls' to populate a +dired buffer. This is not ideal, dired mode should probably be +rewritten to use the directory(3) set of functions. + +On systems with 16 bit integers, the kill buffer cannot exceed 32767 +bytes. + +Unlike GNU Emacs, Mg's minibuffer isn't multi-line aware and hence +some commands like "shell-command-on-region" always pop up a buffer to +display output irrespective of output's size. + +While navigating source code using Mg's cscope commands, the cursor +is always at the match location rather than in *cscope* buffer. Mg uses +the same keybindings of GNU Emacs's xcscope package for it's cscope commands. +As Mg's keybindings are case-insensitive some of the commands don't have a +default keybinding. + +New implementation oddities: + +insert and define-key are new commands corresponding to the mocklisp +functions in GNU Emacs. (Mg does not have non-command functions.) +(Mg's insert will only insert one string.) + +The display wrap code does not work at all like that of GNU emacs. + +Some commands that do not mimic emacs exactly don't have a "standard" +emacs name. For example 'backup-to-home-directory' is only a partial +implementation of emacs' range of commands that allow a user to +customise the backup file location. If a more complete implementation +were coded of these commands the non standard commands would probably +be removed. diff --git a/README.md b/README.md index c427640..ca73f12 100644 --- a/README.md +++ b/README.md @@ -59,4 +59,4 @@ reach out to the tech@ mailing list on OpenBSD. Get a tarball ------------- See the Releases tab on GitHub. -The latest version is mg-7.0. +The latest version is mg-7.3. diff --git a/autoexec.c b/autoexec.c index 1faf9e7..922a631 100644 --- a/autoexec.c +++ b/autoexec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoexec.c,v 1.18 2021/04/21 14:45:28 lum Exp $ */ +/* $OpenBSD: autoexec.c,v 1.19 2023/03/08 04:43:11 guenther Exp $ */ /* this file is in the public domain */ /* Author: Vincent Labrecque April 2002 */ @@ -93,7 +93,6 @@ add_autoexec(const char *pattern, const char *func) * function to execute when a file matching the specified pattern * is read into a buffer. */ -/* ARGSUSED */ int auto_execute(int f, int n) { diff --git a/basic.c b/basic.c index 251e7e8..d5f8ecb 100644 --- a/basic.c +++ b/basic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: basic.c,v 1.50 2021/02/27 13:24:52 lum Exp $ */ +/* $OpenBSD: basic.c,v 1.54 2023/04/21 13:39:36 op Exp $ */ /* This file is in the public domain */ @@ -26,7 +26,6 @@ /* * Go to beginning of line. */ -/* ARGSUSED */ int gotobol(int f, int n) { @@ -43,7 +42,6 @@ gotobol(int f, int n) * 0. Error if you try to move back from * the beginning of the buffer. */ -/* ARGSUSED */ int backchar(int f, int n) { @@ -72,7 +70,6 @@ backchar(int f, int n) /* * Go to end of line. */ -/* ARGSUSED */ int gotoeol(int f, int n) { @@ -89,7 +86,6 @@ gotoeol(int f, int n) * 0. Error if you try to move forward * from the end of the buffer. */ -/* ARGSUSED */ int forwchar(int f, int n) { @@ -182,7 +178,6 @@ gotoeob(int f, int n) * actually do it. The last command controls how * the goal column is set. */ -/* ARGSUSED */ int forwline(int f, int n) { @@ -226,7 +221,6 @@ forwline(int f, int n) * call your alternate. Figure out the new line and * call "movedot" to perform the motion. */ -/* ARGSUSED */ int backline(int f, int n) { @@ -280,16 +274,10 @@ getgoal(struct line *dlp) int c, i, col = 0; char tmp[5]; - for (i = 0; i < llength(dlp); i++) { c = lgetc(dlp, i); - if (c == '\t' -#ifdef NOTAB - && !(curbp->b_flag & BFNOTAB) -#endif - ) { - col |= 0x07; - col++; + if (c == '\t') { + col = ntabstop(col, curbp->b_tabw); } else if (ISCTRL(c) != FALSE) { col += 2; } else if (isprint(c)) @@ -311,7 +299,6 @@ getgoal(struct line *dlp) * the window is zapped, we have to do a hard * update and get it back. */ -/* ARGSUSED */ int forwpage(int f, int n) { @@ -355,7 +342,6 @@ forwpage(int f, int n) * hard update is done because the top line in * the window is zapped. */ -/* ARGSUSED */ int backpage(int f, int n) { @@ -460,7 +446,6 @@ isetmark(void) * to the value of dot. A message is written to * the echo line. (ewprintf knows about macros) */ -/* ARGSUSED */ int setmark(int f, int n) { @@ -470,7 +455,6 @@ setmark(int f, int n) } /* Clear the mark, if set. */ -/* ARGSUSED */ int clearmark(int f, int n) { @@ -491,7 +475,6 @@ clearmark(int f, int n) * that moves the mark about. The only possible * error is "no mark". */ -/* ARGSUSED */ int swapmark(int f, int n) { @@ -521,7 +504,6 @@ swapmark(int f, int n) * it is the line number, else prompt for a line number * to use. */ -/* ARGSUSED */ int gotoline(int f, int n) { @@ -536,7 +518,7 @@ gotoline(int f, int n) return (ABORT); n = (int)strtonum(buf, INT_MIN, INT_MAX, &err); if (err) - return(dobeep_msgs("Line number %s", err)); + return(dobeep_msgs("Line number", err)); } return(setlineno(n)); } diff --git a/bell.c b/bell.c index ef7e93b..fcbd7c9 100644 --- a/bell.c +++ b/bell.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bell.c,v 1.6 2021/05/06 12:44:21 lum Exp $ */ +/* $OpenBSD: bell.c,v 1.7 2023/03/08 04:43:11 guenther Exp $ */ /* * This file is in the public domain. @@ -65,7 +65,6 @@ dobeep(void) } } -/* ARGSUSED */ int toggleaudiblebell(int f, int n) { @@ -77,7 +76,6 @@ toggleaudiblebell(int f, int n) return (TRUE); } -/* ARGSUSED */ int togglevisiblebell(int f, int n) { diff --git a/buffer.c b/buffer.c index 410d8ed..8c8aab4 100644 --- a/buffer.c +++ b/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.112 2021/03/26 15:02:10 lum Exp $ */ +/* $OpenBSD: buffer.c,v 1.114 2023/04/21 13:39:36 op Exp $ */ /* This file is in the public domain. */ @@ -26,10 +26,42 @@ static struct buffer *bnew(const char *); static int usebufname(const char *); +/* Default tab width */ +int defb_tabw = 8; + /* Flag for global working dir */ extern int globalwd; -/* ARGSUSED */ +/* + * Set the tab width for the current buffer, or the default for new + * buffers if called with a prefix argument. + */ +int +settabw(int f, int n) +{ + char buf[8], *bufp; + const char *errstr; + + if (f & FFARG) { + if (n <= 0 || n > 16) + return (FALSE); + defb_tabw = n; + return (TRUE); + } + + if ((bufp = eread("Tab Width: ", buf, sizeof(buf), + EFNUL | EFNEW | EFCR)) == NULL) + return (ABORT); + if (bufp[0] == '\0') + return (ABORT); + n = strtonum(buf, 1, 16, &errstr); + if (errstr) + return (dobeep_msgs("Tab width", errstr)); + curbp->b_tabw = n; + curwp->w_rflag |= WFFRAME; + return (TRUE); +} + int togglereadonlyall(int f, int n) { @@ -51,7 +83,6 @@ togglereadonlyall(int f, int n) return (TRUE); } -/* ARGSUSED */ int togglereadonly(int f, int n) { @@ -102,7 +133,6 @@ usebufname(const char *bufp) * from some other window. *scratch* is the default alternate * buffer. */ -/* ARGSUSED */ int usebuffer(int f, int n) { @@ -124,7 +154,6 @@ usebuffer(int f, int n) /* * pop to buffer asked for by the user. */ -/* ARGSUSED */ int poptobuffer(int f, int n) { @@ -163,7 +192,6 @@ poptobuffer(int f, int n) * if the buffer has been changed). Then free the header * line and the buffer header. Bound to "C-x k". */ -/* ARGSUSED */ int killbuffer_cmd(int f, int n) { @@ -255,7 +283,6 @@ killbuffer(struct buffer *bp) /* * Save some buffers - just call anycb with the arg flag. */ -/* ARGSUSED */ int savebuffers(int f, int n) { @@ -302,7 +329,6 @@ static struct KEYMAPE (2) listbufmap = { * then pops the data onto the screen. Bound to * "C-x C-b". */ -/* ARGSUSED */ int listbuffers(int f, int n) { @@ -595,6 +621,7 @@ bnew(const char *bname) bp->b_lines = 1; bp->b_nlseq = "\n"; /* use unix default */ bp->b_nlchr = bp->b_nlseq; + bp->b_tabw = defb_tabw; if ((bp->b_bname = strdup(bname)) == NULL) { dobeep(); ewprintf("Can't get %d bytes", strlen(bname) + 1); @@ -763,7 +790,6 @@ popbuf(struct buffer *bp, int flags) /* * Insert another buffer at dot. Very useful. */ -/* ARGSUSED */ int bufferinsert(int f, int n) { @@ -819,7 +845,6 @@ bufferinsert(int f, int n) /* * Turn off the dirty bit on this buffer. */ -/* ARGSUSED */ int notmodified(int f, int n) { @@ -919,7 +944,6 @@ checkdirty(struct buffer *bp) /* * Revert the current buffer to whatever is on disk. */ -/* ARGSUSED */ int revertbuffer(int f, int n) { @@ -975,7 +999,6 @@ dorevert(void) /* * Diff the current buffer to what is on disk. */ -/*ARGSUSED */ int diffbuffer(int f, int n) { diff --git a/cmode.c b/cmode.c index 6c0ef5b..2a2a109 100644 --- a/cmode.c +++ b/cmode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmode.c,v 1.17 2019/07/11 18:20:18 lum Exp $ */ +/* $OpenBSD: cmode.c,v 1.22 2023/04/21 13:39:37 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) @@ -205,13 +205,15 @@ cc_lfindent(int f, int n) { if (n < 0) return (FALSE); + if (cc_strip_trailp) + (void)delwhite(FFRAND, 1); if (enewline(FFRAND, 1) == FALSE) return (FALSE); return (cc_indent(FFRAND, n)); } /* - * Get the level of indention after line lp is processed + * Get the level of indentation after line lp is processed * Note getindent has two returns: * curi = value if indenting current line. * return value = value affecting subsequent lines. @@ -225,7 +227,7 @@ getindent(const struct line *lp, int *curi) int newind = 0; /* new index value */ int stringp = FALSE; /* in string? */ int escp = FALSE; /* Escape char? */ - int lastc = '\0'; /* Last matched string delimeter */ + int lastc = '\0'; /* Last matched string delimiter */ int nparen = 0; /* paren count */ int obrace = 0; /* open brace count */ int cbrace = 0; /* close brace count */ @@ -243,14 +245,10 @@ getindent(const struct line *lp, int *curi) for (lo = 0; lo < llength(lp); lo++) { if (!isspace(c = lgetc(lp, lo))) break; - if (c == '\t' -#ifdef NOTAB - && !(curbp->b_flag & BFNOTAB) -#endif /* NOTAB */ - ) { - nicol |= 0x07; - } - nicol++; + if (c == '\t') + nicol = ntabstop(nicol, curbp->b_tabw); + else + nicol++; } /* If last line was blank, choose 0 */ @@ -354,7 +352,7 @@ getindent(const struct line *lp, int *curi) } /* - * Given a delimeter and its purported mate, tell us if they + * Given a delimiter and its purported mate, tell us if they * match. */ static int @@ -412,13 +410,8 @@ findcolpos(const struct buffer *bp, const struct line *lp, int lo) for (i = 0; i < lo; ++i) { c = lgetc(lp, i); - if (c == '\t' -#ifdef NOTAB - && !(bp->b_flag & BFNOTAB) -#endif /* NOTAB */ - ) { - col |= 0x07; - col++; + if (c == '\t') { + col = ntabstop(col, curbp->b_tabw); } else if (ISCTRL(c) != FALSE) col += 2; else if (isprint(c)) { diff --git a/configure b/configure index 4e5afb5..32aeac5 100755 --- a/configure +++ b/configure @@ -267,6 +267,12 @@ do --mandir=*) mandir=`echo $opt | cut -d '=' -f 2` ;; + --cc=*) + CC=${opt#*=} + ;; + --cflags=*) + CFLAGS=${opt#*=} + ;; --disable-logging|--enable-logging) if [ "x$opt" = "x--enable-logging" ] ; then log=1 @@ -298,6 +304,10 @@ do echo "Top level install directory is PREFIX [$prefix]" printf " --mandir=MANDIR " echo "Manual pages are installed to MANDIR [$mandir]" + printf " --cc=CC " + echo "Use specified C compiler [default=cc]" + printf " --cflags=CFLAGS " + echo "Use specified CFLAGS [default=\"-g -O2\"]" printf " --enable-logging " echo "Enable run-time debugging [default=no]" printf " --enable-static " diff --git a/cscope.c b/cscope.c index 9ad06e4..20140b7 100644 --- a/cscope.c +++ b/cscope.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cscope.c,v 1.20 2021/03/01 10:51:14 lum Exp $ */ +/* $OpenBSD: cscope.c,v 1.22 2023/03/08 04:43:11 guenther Exp $ */ /* * This file is in the public domain. @@ -78,7 +78,6 @@ static const char *ltrim(const char *); /* * Find this symbol. Bound to C-c s s */ -/* ARGSUSED */ int cssymbol(int f, int n) { @@ -88,7 +87,7 @@ cssymbol(int f, int n) /* * Find this global definition. Bound to C-c s d */ -/* ARGSUSED */int +int csdefinition(int f, int n) { return (do_cscope(CSDEFINITION)); @@ -97,7 +96,6 @@ csdefinition(int f, int n) /* * Find functions called by this function. Bound to C-c s l */ -/* ARGSUSED */ int csfuncalled(int f, int n) { @@ -107,7 +105,6 @@ csfuncalled(int f, int n) /* * Find functions calling this function. Bound to C-c s c */ -/* ARGSUSED */ int cscallerfuncs(int f, int n) { @@ -117,7 +114,6 @@ cscallerfuncs(int f, int n) /* * Find this text. Bound to C-c s t */ -/* ARGSUSED */ int csfindtext(int f, int n) { @@ -127,7 +123,6 @@ csfindtext(int f, int n) /* * Find this egrep pattern. Bound to C-c s e */ -/* ARGSUSED */ int csegrep(int f, int n) { @@ -137,7 +132,6 @@ csegrep(int f, int n) /* * Find this file. Bound to C-c s f */ -/* ARGSUSED */ int csfindfile(int f, int n) { @@ -147,7 +141,6 @@ csfindfile(int f, int n) /* * Find files #including this file. Bound to C-c s i */ -/* ARGSUSED */ int csfindinc(int f, int n) { @@ -158,7 +151,6 @@ csfindinc(int f, int n) * Create list of files to index in the given directory * using cscope-indexer. */ -/* ARGSUSED */ int cscreatelist(int f, int n) { @@ -185,9 +177,9 @@ cscreatelist(int f, int n) return (FALSE); if (stat(dir, &sb) == -1) - return(dobeep_msgs("stat: %s", strerror(errno))); + return(dobeep_msgs("stat:", strerror(errno))); else if (S_ISDIR(sb.st_mode) == 0) - return(dobeep_msgs("%s: Not a directory", dir)); + return(dobeep_msgs(dir, "Not a directory")); if (csexists("cscope-indexer") == FALSE) return(dobeep_msg("no such file or directory, cscope-indexer")); @@ -229,7 +221,6 @@ cscreatelist(int f, int n) /* * Next Symbol. Bound to C-c s n */ -/* ARGSUSED */ int csnextmatch(int f, int n) { @@ -263,7 +254,6 @@ csnextmatch(int f, int n) /* * Previous Symbol. Bound to C-c s p */ -/* ARGSUSED */ int csprevmatch(int f, int n) { diff --git a/def.h b/def.h index 1d1dc33..e67e48b 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.180 2023/04/21 13:39:37 op Exp $ */ /* This file is in the public domain. */ @@ -274,6 +274,7 @@ struct buffer { char b_cwd[NFILEN]; /* working directory */ char *b_nlseq; /* Newline sequence of chars */ char *b_nlchr; /* 1st newline character */ + int b_tabw; /* Width of a tab character */ struct fileinfo b_fi; /* File attributes */ struct undoq b_undo; /* Undo actions list */ struct undo_rec *b_undoptr; @@ -290,9 +291,7 @@ struct buffer { #define BFCHG 0x01 /* Changed. */ #define BFBAK 0x02 /* Need to make a backup. */ -#ifdef NOTAB #define BFNOTAB 0x04 /* no tab mode */ -#endif #define BFOVERWRITE 0x08 /* overwrite mode */ #define BFREADONLY 0x10 /* read only mode */ #define BFDIRTY 0x20 /* Buffer was modified elsewhere */ @@ -437,6 +436,7 @@ int shrinkwind(int, int); int delwind(int, int); /* buffer.c */ +int settabw(int, int); int togglereadonly(int, int); int togglereadonlyall(int, int); struct buffer *bfind(const char *, int); @@ -491,7 +491,7 @@ int ffputbuf(FILE *, struct buffer *, int); int ffgetline(FILE *, char *, int, int *); int fbackupfile(const char *); char *adjustname(const char *, int); -char *startupfile(char *, char *); +FILE *startupfile(char *, char *, char *, size_t); int copy(char *, char *); struct list *make_file_list(char *); int fisdir(const char *); @@ -549,6 +549,7 @@ int gotoline(int, int); int setlineno(int); /* util.c X */ +int ntabstop(int, int); int showcpos(int, int); int getcolpos(struct mgwin *); int twiddle(int, int); @@ -599,7 +600,7 @@ int extend(int, int); int evalexpr(int, int); int evalbuffer(int, int); int evalfile(int, int); -int load(const char *); +int load(FILE *, const char *); int excline(char *, int, int); char *skipwhite(char *); @@ -656,6 +657,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); @@ -678,9 +682,7 @@ int executemacro(int, int); /* modes.c X */ int indentmode(int, int); int fillmode(int, int); -#ifdef NOTAB int notabmode(int, int); -#endif /* NOTAB */ int overwrite_mode(int, int); int set_default_mode(int,int); diff --git a/dir.c b/dir.c index 0674f63..417061d 100644 --- a/dir.c +++ b/dir.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dir.c,v 1.31 2019/06/28 13:35:02 deraadt Exp $ */ +/* $OpenBSD: dir.c,v 1.33 2023/03/08 04:43:11 guenther Exp $ */ /* This file is in the public domain. */ @@ -36,7 +36,6 @@ dirinit(void) /* * Change current working directory. */ -/* ARGSUSED */ int changedir(int f, int n) { @@ -69,7 +68,6 @@ changedir(int f, int n) /* * Show current directory. */ -/* ARGSUSED */ int showcwdir(int f, int n) { @@ -86,8 +84,7 @@ getcwdir(char *buf, size_t len) return (TRUE); } -/* Create the directory and it's parents. */ -/* ARGSUSED */ +/* Create the directory and its parents. */ int makedir(int f, int n) { diff --git a/dired.c b/dired.c index 810ea3a..5cb747c 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.102 2023/03/08 04:43:11 guenther Exp $ */ /* This file is in the public domain. */ @@ -228,7 +228,6 @@ dired_init(void) dobindkey(fundamental_map, "dired", "^Xd"); } -/* ARGSUSED */ int dired(int f, int n) { @@ -257,7 +256,6 @@ dired(int f, int n) return (showbuffer(bp, curwp, WFFULL | WFMODE)); } -/* ARGSUSED */ int d_otherwindow(int f, int n) { @@ -289,7 +287,6 @@ d_otherwindow(int f, int n) return (TRUE); } -/* ARGSUSED */ int d_del(int f, int n) { @@ -309,7 +306,6 @@ d_del(int f, int n) return (d_warpdot(curwp->w_dotp, &curwp->w_doto)); } -/* ARGSUSED */ int d_undel(int f, int n) { @@ -327,7 +323,6 @@ d_undel(int f, int n) return (d_warpdot(curwp->w_dotp, &curwp->w_doto)); } -/* ARGSUSED */ int d_undelbak(int f, int n) { @@ -345,7 +340,6 @@ d_undelbak(int f, int n) return (d_warpdot(curwp->w_dotp, &curwp->w_doto)); } -/* ARGSUSED */ int d_findfile(int f, int n) { @@ -369,7 +363,6 @@ d_findfile(int f, int n) return (readin(fname)); } -/* ARGSUSED */ int d_ffotherwindow(int f, int n) { @@ -391,7 +384,6 @@ d_ffotherwindow(int f, int n) return (readin(fname)); } -/* ARGSUSED */ int d_expunge(int f, int n) { @@ -448,7 +440,6 @@ d_expunge(int f, int n) return (TRUE); } -/* ARGSUSED */ int d_copy(int f, int n) { @@ -507,7 +498,6 @@ d_copy(int f, int n) return (showbuffer(bp, curwp, WFFULL | WFMODE)); } -/* ARGSUSED */ int d_rename(int f, int n) { @@ -567,7 +557,6 @@ d_rename(int f, int n) return (showbuffer(bp, curwp, WFFULL | WFMODE)); } -/* ARGSUSED */ void reaper(int signo __attribute__((unused))) { @@ -581,7 +570,6 @@ reaper(int signo __attribute__((unused))) /* * Pipe the currently selected file through a shell command. */ -/* ARGSUSED */ int d_shell_command(int f, int n) { @@ -730,7 +718,6 @@ d_exec(int space, struct buffer *bp, const char *input, const char *cmd, ...) return ret; } -/* ARGSUSED */ int d_create_directory(int f, int n) { @@ -747,7 +734,6 @@ d_create_directory(int f, int n) return (showbuffer(bp, curwp, WFFULL | WFMODE)); } -/* ARGSUSED */ int d_killbuffer_cmd(int f, int n) { @@ -1185,7 +1171,7 @@ gotofile(char *fpth) ewprintf("File not found %s", fname); return (FALSE); } else { - ewprintf(""); + eerase(); return (TRUE); } } diff --git a/display.c b/display.c index c26f093..7071081 100644 --- a/display.c +++ b/display.c @@ -1,4 +1,4 @@ -/* $OpenBSD: display.c,v 1.48 2017/07/06 19:27:37 schwarze Exp $ */ +/* $OpenBSD: display.c,v 1.52 2023/04/21 13:39:37 op Exp $ */ /* This file is in the public domain. */ @@ -17,7 +17,7 @@ #include #include #include -#include +#include "terminfo_term.h" #include "def.h" #include "kbd.h" @@ -38,7 +38,7 @@ struct video { #define VFCHG 0x0001 /* Changed. */ #define VFHBAD 0x0002 /* Hash and cost are bad. */ -#define VFEXT 0x0004 /* extended line (beond ncol) */ +#define VFEXT 0x0004 /* extended line (beyond ncol) */ /* * SCORE structures hold the optimal @@ -52,9 +52,9 @@ struct score { }; void vtmove(int, int); -void vtputc(int); -void vtpute(int); -int vtputs(const char *); +void vtputc(int, struct mgwin *); +void vtpute(int, struct mgwin *); +int vtputs(const char *, struct mgwin *); void vteeol(void); void updext(int, int); void modeline(struct mgwin *, int); @@ -102,7 +102,6 @@ extern int globalwd; * Since we don't have variables (we probably should) these are command * processors for changing the values of mode flags. */ -/* ARGSUSED */ int linenotoggle(int f, int n) { @@ -116,7 +115,6 @@ linenotoggle(int f, int n) return (TRUE); } -/* ARGSUSED */ int colnotoggle(int f, int n) { @@ -310,33 +308,31 @@ vtmove(int row, int col) * Three guesses how we found this. */ void -vtputc(int c) +vtputc(int c, struct mgwin *wp) { struct video *vp; + int target; c &= 0xff; vp = vscreen[vtrow]; if (vtcol >= ncol) vp->v_text[ncol - 1] = '$'; - else if (c == '\t' -#ifdef NOTAB - && !(curbp->b_flag & BFNOTAB) -#endif - ) { + else if (c == '\t') { + target = ntabstop(vtcol, wp->w_bufp->b_tabw); do { - vtputc(' '); - } while (vtcol < ncol && (vtcol & 0x07) != 0); + vtputc(' ', wp); + } while (vtcol < ncol && vtcol < target); } else if (ISCTRL(c)) { - vtputc('^'); - vtputc(CCHR(c)); + vtputc('^', wp); + vtputc(CCHR(c), wp); } else if (isprint(c)) vp->v_text[vtcol++] = c; else { char bf[5]; snprintf(bf, sizeof(bf), "\\%o", c); - vtputs(bf); + vtputs(bf, wp); } } @@ -346,26 +342,24 @@ vtputc(int c) * margin. */ void -vtpute(int c) +vtpute(int c, struct mgwin *wp) { struct video *vp; + int target; c &= 0xff; vp = vscreen[vtrow]; if (vtcol >= ncol) vp->v_text[ncol - 1] = '$'; - else if (c == '\t' -#ifdef NOTAB - && !(curbp->b_flag & BFNOTAB) -#endif - ) { + else if (c == '\t') { + target = ntabstop(vtcol + lbound, wp->w_bufp->b_tabw); do { - vtpute(' '); - } while (((vtcol + lbound) & 0x07) != 0 && vtcol < ncol); + vtpute(' ', wp); + } while (((vtcol + lbound) < target) && vtcol < ncol); } else if (ISCTRL(c) != FALSE) { - vtpute('^'); - vtpute(CCHR(c)); + vtpute('^', wp); + vtpute(CCHR(c), wp); } else if (isprint(c)) { if (vtcol >= 0) vp->v_text[vtcol] = c; @@ -375,7 +369,7 @@ vtpute(int c) snprintf(bf, sizeof(bf), "\\%o", c); for (cp = bf; *cp != '\0'; cp++) - vtpute(*cp); + vtpute(*cp, wp); } } @@ -486,7 +480,7 @@ update(int modelinecolor) vscreen[i]->v_flag |= (VFCHG | VFHBAD); vtmove(i, 0); for (j = 0; j < llength(lp); ++j) - vtputc(lgetc(lp, j)); + vtputc(lgetc(lp, j), wp); vteeol(); } else if ((wp->w_rflag & (WFEDIT | WFFULL)) != 0) { hflag = TRUE; @@ -496,7 +490,7 @@ update(int modelinecolor) vtmove(i, 0); if (lp != wp->w_bufp->b_headp) { for (j = 0; j < llength(lp); ++j) - vtputc(lgetc(lp, j)); + vtputc(lgetc(lp, j), wp); lp = lforw(lp); } vteeol(); @@ -518,13 +512,8 @@ update(int modelinecolor) i = 0; while (i < curwp->w_doto) { c = lgetc(lp, i++); - if (c == '\t' -#ifdef NOTAB - && !(curbp->b_flag & BFNOTAB) -#endif - ) { - curcol |= 0x07; - curcol++; + if (c == '\t') { + curcol = ntabstop(curcol, curwp->w_bufp->b_tabw); } else if (ISCTRL(c) != FALSE) curcol += 2; else if (isprint(c)) @@ -559,7 +548,7 @@ update(int modelinecolor) (curcol < ncol - 1)) { vtmove(i, 0); for (j = 0; j < llength(lp); ++j) - vtputc(lgetc(lp, j)); + vtputc(lgetc(lp, j), wp); vteeol(); /* this line no longer is extended */ vscreen[i]->v_flag &= ~VFEXT; @@ -685,13 +674,13 @@ updext(int currow, int curcol) lbound = curcol - (curcol % (ncol >> 1)) - (ncol >> 2); /* - * scan through the line outputing characters to the virtual screen + * scan through the line outputting characters to the virtual screen * once we reach the left edge */ vtmove(currow, -lbound); /* start scanning offscreen */ lp = curwp->w_dotp; /* line to output */ for (j = 0; j < llength(lp); ++j) /* until the end-of-line */ - vtpute(lgetc(lp, j)); + vtpute(lgetc(lp, j), curwp); vteeol(); /* truncate the virtual line */ vscreen[currow]->v_text[0] = '$'; /* and put a '$' in column 1 */ } @@ -807,45 +796,45 @@ modeline(struct mgwin *wp, int modelinecolor) vscreen[n]->v_flag |= (VFCHG | VFHBAD); /* Recompute, display. */ vtmove(n, 0); /* Seek to right line. */ bp = wp->w_bufp; - vtputc('-'); - vtputc('-'); + vtputc('-', wp); + vtputc('-', wp); if ((bp->b_flag & BFREADONLY) != 0) { - vtputc('%'); + vtputc('%', wp); if ((bp->b_flag & BFCHG) != 0) - vtputc('*'); + vtputc('*', wp); else - vtputc('%'); + vtputc('%', wp); } else if ((bp->b_flag & BFCHG) != 0) { /* "*" if changed. */ - vtputc('*'); - vtputc('*'); + vtputc('*', wp); + vtputc('*', wp); } else { - vtputc('-'); - vtputc('-'); + vtputc('-', wp); + vtputc('-', wp); } - vtputc('-'); + vtputc('-', wp); n = 5; - n += vtputs("Mg: "); + n += vtputs("Mg: ", wp); if (bp->b_bname[0] != '\0') - n += vtputs(&(bp->b_bname[0])); + n += vtputs(&(bp->b_bname[0]), wp); while (n < 42) { /* Pad out with blanks. */ - vtputc(' '); + vtputc(' ', wp); ++n; } - vtputc('('); + vtputc('(', wp); ++n; for (md = 0; ; ) { - n += vtputs(bp->b_modes[md]->p_name); + n += vtputs(bp->b_modes[md]->p_name, wp); if (++md > bp->b_nmodes) break; - vtputc('-'); + vtputc('-', wp); ++n; } /* XXX These should eventually move to a real mode */ if (macrodef == TRUE) - n += vtputs("-def"); + n += vtputs("-def", wp); if (globalwd == TRUE) - n += vtputs("-gwd"); - vtputc(')'); + n += vtputs("-gwd", wp); + vtputc(')', wp); ++n; if (linenos && colnos) @@ -856,10 +845,10 @@ modeline(struct mgwin *wp, int modelinecolor) else if (colnos) len = snprintf(sl, sizeof(sl), "--C%d", getcolpos(wp)); if ((linenos || colnos) && len < sizeof(sl) && len != -1) - n += vtputs(sl); + n += vtputs(sl, wp); while (n < ncol) { /* Pad out. */ - vtputc('-'); + vtputc('-', wp); ++n; } } @@ -868,12 +857,12 @@ modeline(struct mgwin *wp, int modelinecolor) * Output a string to the mode line, report how long it was. */ int -vtputs(const char *s) +vtputs(const char *s, struct mgwin *wp) { int n = 0; while (*s != '\0') { - vtputc(*s++); + vtputc(*s++, wp); ++n; } return (n); diff --git a/echo.c b/echo.c index ced1a2d..f97bffc 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. */ @@ -15,7 +15,7 @@ #include #include #include -#include +#include "terminfo_term.h" #include "def.h" #include "funmap.h" @@ -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/extend.c b/extend.c index 9fb5a2b..154ff30 100644 --- a/extend.c +++ b/extend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: extend.c,v 1.75 2021/05/06 14:16:12 lum Exp $ */ +/* $OpenBSD: extend.c,v 1.80 2023/04/17 10:11:30 op Exp $ */ /* This file is in the public domain. */ /* @@ -32,7 +32,6 @@ static int bindkey(KEYMAP **, const char *, KCHAR *, int); /* * Insert a string, mainly for use from macros (created by selfinsert). */ -/* ARGSUSED */ int insert(int f, int n) { @@ -461,7 +460,6 @@ dobindkey(KEYMAP *map, const char *func, const char *str) /* * This function modifies the fundamental keyboard map. */ -/* ARGSUSED */ int bindtokey(int f, int n) { @@ -471,7 +469,6 @@ bindtokey(int f, int n) /* * This function modifies the current mode's keyboard map. */ -/* ARGSUSED */ int localbind(int f, int n) { @@ -482,7 +479,6 @@ localbind(int f, int n) /* * This function redefines a key in any keymap. */ -/* ARGSUSED */ int redefine_key(int f, int n) { @@ -497,7 +493,7 @@ redefine_key(int f, int n) return (FALSE); (void)strlcat(buf, tmp, sizeof(buf)); if ((mp = name_map(tmp)) == NULL) - return (dobeep_msgs("Unknown map ", tmp)); + return (dobeep_msgs("Unknown map", tmp)); if (strlcat(buf, "key: ", sizeof(buf)) >= sizeof(buf)) return (FALSE); @@ -505,14 +501,12 @@ redefine_key(int f, int n) return (dobind(mp, buf, FALSE)); } -/* ARGSUSED */ int unbindtokey(int f, int n) { return (dobind(fundamental_map, "Global unset key: ", TRUE)); } -/* ARGSUSED */ int localunbind(int f, int n) { @@ -573,7 +567,6 @@ extend(int f, int n) * Use strlen for length of line, assume user is not typing in a '\0' in the * modeline. llen only used for foundparen() so old-school will be ok. */ -/* ARGSUSED */ int evalexpr(int f, int n) { @@ -594,7 +587,6 @@ evalexpr(int f, int n) * evalbuffer - evaluate the current buffer as line commands. Useful for * testing startup files. */ -/* ARGSUSED */ int evalbuffer(int f, int n) { @@ -625,44 +617,40 @@ evalbuffer(int f, int n) * evalfile - go get a file and evaluate it as line commands. You can * go get your own startup file if need be. */ -/* ARGSUSED */ int evalfile(int f, int n) { + FILE *ffp; char fname[NFILEN], *bufp; + int ret; if ((bufp = eread("Load file: ", fname, NFILEN, EFNEW | EFCR)) == NULL) return (ABORT); - else if (bufp[0] == '\0') + if (bufp[0] == '\0') + return (FALSE); + if ((bufp = adjustname(fname, TRUE)) == NULL) + return (FALSE); + ret = ffropen(&ffp, bufp, NULL); + if (ret == FIODIR) + (void)ffclose(ffp, NULL); + if (ret != FIOSUC) return (FALSE); - return (load(fname)); + ret = load(ffp, bufp); + (void)ffclose(ffp, NULL); + return (ret); } /* * load - go load the file name we got passed. */ int -load(const char *fname) +load(FILE *ffp, const char *fname) { - int s = TRUE, line, ret; + int s = TRUE, line; int nbytes = 0; - char excbuf[BUFSIZE], fncpy[NFILEN]; - FILE *ffp; - - if ((fname = adjustname(fname, TRUE)) == NULL) - /* just to be careful */ - return (FALSE); + char excbuf[BUFSIZE]; - ret = ffropen(&ffp, fname, NULL); - if (ret != FIOSUC) { - if (ret == FIODIR) - (void)ffclose(ffp, NULL); - return (FALSE); - } - - /* keep a note of fname incase of errors in loaded file. */ - (void)strlcpy(fncpy, fname, sizeof(fncpy)); line = 0; while ((s = ffgetline(ffp, excbuf, sizeof(excbuf) - 1, &nbytes)) == FIOSUC) { @@ -671,11 +659,10 @@ load(const char *fname) if (excline(excbuf, nbytes, line) != TRUE) { s = FIOERR; dobeep(); - ewprintf("Error loading file %s at line %d", fncpy, line); + ewprintf("Error loading file %s at line %d", fname, line); break; } } - (void)ffclose(ffp, NULL); excbuf[nbytes] = '\0'; if (s != FIOEOF || (nbytes && excline(excbuf, nbytes, ++line) != TRUE)) return (FALSE); @@ -733,7 +720,7 @@ excline(char *line, int llen, int lnum) n = (int)nl; } if ((fp = name_function(funcp)) == NULL) - return (dobeep_msgs("Unknown function: ", funcp)); + return (dobeep_msgs("Unknown function:", funcp)); if (fp == bindtokey || fp == unbindtokey) { bind = BINDARG; @@ -860,7 +847,7 @@ excline(char *line, int llen, int lnum) case BINDNEXT: lp->l_text[lp->l_used] = '\0'; if ((curmap = name_map(lp->l_text)) == NULL) { - (void)dobeep_msgs("No such mode: ", lp->l_text); + (void)dobeep_msgs("No such mode:", lp->l_text); status = FALSE; free(lp); goto cleanup; diff --git a/file.c b/file.c index d6e0c8d..d710935 100644 --- a/file.c +++ b/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.102 2019/06/22 15:03:43 lum Exp $ */ +/* $OpenBSD: file.c,v 1.103 2023/03/08 04:43:11 guenther Exp $ */ /* This file is in the public domain. */ @@ -24,7 +24,6 @@ size_t xdirname(char *, const char *, size_t); * Insert a file into the current buffer. Real easy - just call the * insertfile routine with the file name. */ -/* ARGSUSED */ int fileinsert(int f, int n) { @@ -50,7 +49,6 @@ fileinsert(int f, int n) * if you can find it, just switch to the buffer. If you cannot find the * file, create a new buffer, read in the text, and switch to the new buffer. */ -/* ARGSUSED */ int filevisit(int f, int n) { @@ -90,7 +88,6 @@ filevisit(int f, int n) * buffer is killed before the switch. If the kill fails, or is aborted, * revert to the original file. */ -/* ARGSUSED */ int filevisitalt(int f, int n) { @@ -153,7 +150,6 @@ filevisitro(int f, int n) * Pop to a file in the other window. Same as the last function, but uses * popbuf instead of showbuffer. */ -/* ARGSUSED */ int poptofile(int f, int n) { @@ -506,7 +502,6 @@ out: lp2 = NULL; * This handling of file names is different from the earlier versions and * is more compatible with Gosling EMACS than with ITS EMACS. */ -/* ARGSUSED */ int filewrite(int f, int n) { @@ -567,7 +562,6 @@ filewrite(int f, int n) */ static int makebackup = TRUE; -/* ARGSUSED */ int filesave(int f, int n) { @@ -638,7 +632,6 @@ buffsave(struct buffer *bp) * is given, sets makebackup to true, so backups are made. If an argument is * given, no backup files are made when saving a new version of a file. */ -/* ARGSUSED */ int makebkfile(int f, int n) { diff --git a/fileio.c b/fileio.c index 3185222..b6ed356 100644 --- a/fileio.c +++ b/fileio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fileio.c,v 1.108 2021/03/01 10:51:14 lum Exp $ */ +/* $OpenBSD: fileio.c,v 1.111 2023/03/30 19:00:02 op Exp $ */ /* This file is in the public domain. */ @@ -136,7 +136,6 @@ ffwopen(FILE ** ffp, const char *fn, struct buffer *bp) /* * Close a file. */ -/* ARGSUSED */ int ffclose(FILE *ffp, struct buffer *bp) { @@ -329,10 +328,10 @@ adjustname(const char *fn, int slashslash) * the terminal driver in particular), accepts a suffix to be appended * to the startup file name. */ -char * -startupfile(char *suffix, char *conffile) +FILE * +startupfile(char *suffix, char *conffile, char *path, size_t len) { - static char file[NFILEN]; + FILE *ffp; char *home; int ret; @@ -340,34 +339,40 @@ startupfile(char *suffix, char *conffile) goto nohome; if (conffile != NULL) { - (void)strncpy(file, conffile, NFILEN); + (void)strlcpy(path, conffile, len); } else if (suffix == NULL) { - ret = snprintf(file, sizeof(file), _PATH_MG_STARTUP, home); - if (ret < 0 || ret >= sizeof(file)) + ret = snprintf(path, len, _PATH_MG_STARTUP, home); + if (ret < 0 || ret >= len) return (NULL); } else { - ret = snprintf(file, sizeof(file), _PATH_MG_TERM, home, suffix); - if (ret < 0 || ret >= sizeof(file)) + ret = snprintf(path, len, _PATH_MG_TERM, home, suffix); + if (ret < 0 || ret >= len) return (NULL); } - if (access(file, R_OK) == 0) - return (file); + ret = ffropen(&ffp, path, NULL); + if (ret == FIOSUC) + return (ffp); + if (ret == FIODIR) + (void)ffclose(ffp, NULL); nohome: #ifdef STARTUPFILE if (suffix == NULL) { - ret = snprintf(file, sizeof(file), "%s", STARTUPFILE); - if (ret < 0 || ret >= sizeof(file)) + ret = snprintf(path, len, "%s", STARTUPFILE); + if (ret < 0 || ret >= len) return (NULL); } else { - ret = snprintf(file, sizeof(file), "%s%s", STARTUPFILE, + ret = snprintf(path, len, "%s%s", STARTUPFILE, suffix); - if (ret < 0 || ret >= sizeof(file)) + if (ret < 0 || ret >= len) return (NULL); } - if (access(file, R_OK) == 0) - return (file); + ret = ffropen(&ffp, path, NULL); + if (ret == FIOSUC) + return (ffp); + if (ret == FIODIR) + (void)ffclose(ffp, NULL); #endif /* STARTUPFILE */ return (NULL); } diff --git a/funmap.c b/funmap.c index 3514a4d..f2ae58e 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.67 2023/04/21 13:39:37 op Exp $ */ /* This file is in the public domain */ @@ -34,7 +34,7 @@ static struct funmap *funs; * 0 = a toggle, non-modifiable insert/delete, region modifier, etc * 1 = value can be string or number value (like: file/buf name, search string) * 2 = multiple type value required, see auto-execute, or global-set-key, etc - * -1 = error: interactive commmand, unsuitable for interpreter + * -1 = error: interactive command, unsuitable for interpreter * * Some functions when used interactively may ask for a 'y' or 'n' (or another * character) to continue, in excline, a 'y' is assumed. Functions like this @@ -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}, @@ -155,9 +157,7 @@ static struct funmap functnames[] = { {enewline, "newline", 1}, {lfindent, "newline-and-indent", 1}, {forwline, "next-line", 1}, -#ifdef NOTAB {notabmode, "no-tab-mode", 0}, -#endif /* NOTAB */ {notmodified, "not-modified", 0}, {openline, "open-line", 1}, {nextwind, "other-window", 0}, @@ -199,6 +199,7 @@ static struct funmap functnames[] = { {ask_selfinsert, "self-insert-char", 1}, {selfinsert, "self-insert-command", 1}, /* startup only */ {sentencespace, "sentence-end-double-space", 0}, + {settabw, "set-tab-width", 1}, #ifdef REGEX {setcasefold, "set-case-fold-search", 0}, #endif /* REGEX */ @@ -210,9 +211,7 @@ static struct funmap functnames[] = { {shellcommand, "shell-command", 1}, {piperegion, "shell-command-on-region", 1}, {shrinkwind, "shrink-window", 1}, -#ifdef NOTAB {space_to_tabstop, "space-to-tabstop", 0}, -#endif /* NOTAB */ {splitwind, "split-window-vertically", 0}, {definemacro, "start-kbd-macro", 0}, {spawncli, "suspend-emacs", 0}, diff --git a/grep.c b/grep.c index 016256f..aa7f9df 100644 --- a/grep.c +++ b/grep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grep.c,v 1.49 2021/03/01 10:51:14 lum Exp $ */ +/* $OpenBSD: grep.c,v 1.50 2023/03/08 04:43:11 guenther Exp $ */ /* This file is in the public domain */ @@ -61,7 +61,6 @@ grep_init(void) maps_add((KEYMAP *)&compilemap, "compile"); } -/* ARGSUSED */ static int grep(int f, int n) { @@ -87,7 +86,6 @@ grep(int f, int n) return (TRUE); } -/* ARGSUSED */ int compile(int f, int n) { @@ -116,7 +114,6 @@ compile(int f, int n) } /* id-utils foo. */ -/* ARGSUSED */ static int gid(int f, int n) { @@ -253,7 +250,6 @@ compile_mode(const char *name, const char *command) return (bp); } -/* ARGSUSED */ static int compile_goto_error(int f, int n) { @@ -321,7 +317,6 @@ compile_goto_error(int f, int n) return (FALSE); } -/* ARGSUSED */ int next_error(int f, int n) { @@ -347,7 +342,6 @@ next_error(int f, int n) * Since we don't have variables (we probably should) these are command * processors for changing the values of mode flags. */ -/* ARGSUSED */ int globalwdtoggle(int f, int n) { diff --git a/help.c b/help.c index cd983a3..78b55f4 100644 --- a/help.c +++ b/help.c @@ -1,4 +1,4 @@ -/* $OpenBSD: help.c,v 1.35 2015/03/19 21:22:15 bcallah Exp $ */ +/* $OpenBSD: help.c,v 1.37 2023/03/08 04:43:11 guenther Exp $ */ /* This file is in the public domain. */ @@ -24,7 +24,6 @@ static int findbind(KEYMAP *, PF, char *, size_t); * Read a key from the keyboard, and look it up in the keymap. * Display the name of the function currently bound to the key. */ -/* ARGSUSED */ int desckey(int f, int n) { @@ -97,9 +96,8 @@ desckey(int f, int n) /* * This function creates a table, listing all of the command * keys and their current bindings, and stores the table in the - * *help* pop-up buffer. This lets Mg produce it's own wall chart. + * *help* pop-up buffer. This lets Mg produce its own wall chart. */ -/* ARGSUSED */ int wallchart(int f, int n) { @@ -173,7 +171,6 @@ help_help(int f, int n) return ((*funct)(f, n)); } -/* ARGSUSED */ int apropos_command(int f, int n) { diff --git a/interpreter.c b/interpreter.c index 320b408..d73e3d6 100644 --- a/interpreter.c +++ b/interpreter.c @@ -1,4 +1,4 @@ -/* $OpenBSD: interpreter.c,v 1.32 2021/05/12 11:13:23 lum Exp $ */ +/* $OpenBSD: interpreter.c,v 1.35 2023/04/17 10:11:30 op Exp $ */ /* * This file is in the public domain. * @@ -8,7 +8,7 @@ /* * This file attempts to add some 'scripting' functionality into mg. * - * The initial goal is to give mg the ability to use it's existing functions + * The initial goal is to give mg the ability to use its existing functions * and structures in a linked-up way. Hopefully resulting in user definable * functions. The syntax is 'scheme' like but currently it is not a scheme * interpreter. @@ -406,7 +406,7 @@ parsexp(char *begp, const char *par1, const char *par2, int blkid, int expctr, * If no extant mg command found, just return. */ if ((funcp = name_function(cmdp)) == NULL) - return (dobeep_msgs("Unknown command: ", cmdp)); + return (dobeep_msgs("Unknown command:", cmdp)); numparams = numparams_function(funcp); if (numparams == 0) @@ -492,9 +492,8 @@ multiarg(char *cmdp, char *argbuf, int numparams) if (!doregex(regs, argp)) { const char *errstr; - int iters; - iters = strtonum(argp, 0, INT_MAX, &errstr); + strtonum(argp, 0, INT_MAX, &errstr); if (errstr != NULL) return (dobeep_msgs("Var not found:", argp)); @@ -628,7 +627,7 @@ expandvals(char *cmdp, char *valp, char *bp) char *argp, *endp, *p, *v, *s = " "; char *regs; int spc, cnt; - int inlist, sizof, fin, inquote; + int sizof, fin, inquote; /* now find the first argument */ p = skipwhite(valp); @@ -637,7 +636,7 @@ expandvals(char *cmdp, char *valp, char *bp) return (dobeep_msg("strlcpy error")); argp = argbuf; spc = 1; /* initially fake a space so we find first argument */ - inlist = fin = inquote = cnt = spc = 0; + fin = inquote = cnt = spc = 0; for (p = argbuf; *p != '\0'; p++) { if (*(p + 1) == '\0') @@ -693,9 +692,8 @@ expandvals(char *cmdp, char *valp, char *bp) continue; } else { const char *errstr; - int iters; - iters = strtonum(argp, 0, INT_MAX, &errstr); + strtonum(argp, 0, INT_MAX, &errstr); if (errstr != NULL) return (dobeep_msgs("Var not found:", argp)); diff --git a/kbd.c b/kbd.c index 2015a8b..3d3bc03 100644 --- a/kbd.c +++ b/kbd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kbd.c,v 1.35 2021/03/01 10:51:14 lum Exp $ */ +/* $OpenBSD: kbd.c,v 1.37 2023/03/08 04:43:11 guenther Exp $ */ /* This file is in the public domain. */ @@ -254,7 +254,6 @@ universal_argument(int f, int n) } } -/* ARGSUSED */ int digit_argument(int f, int n) { @@ -438,7 +437,7 @@ quote(int f, int n) } /* - * Wraper function to count invocation repeats. + * Wrapper function to count invocation repeats. * We ignore any function whose sole purpose is to get us * to the intended function. */ diff --git a/keymap.c b/keymap.c index 32a9267..83e8b54 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.61 2023/04/17 09:49:04 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 /* } */ @@ -464,7 +464,6 @@ static struct KEYMAPE (1) indntmap = { } }; -#ifdef NOTAB static PF notab_tab[] = { space_to_tabstop /* ^I */ }; @@ -479,7 +478,6 @@ static struct KEYMAPE (1) notabmap = { } } }; -#endif /* NOTAB */ static struct KEYMAPE (1) overwmap = { 0, @@ -511,9 +509,7 @@ struct maps_s fundamental_mode = { (KEYMAP *)&fundmap, "fundamental" }; static struct maps_s map_table[] = { {(KEYMAP *) &fillmap, "fill",}, {(KEYMAP *) &indntmap, "indent",}, -#ifdef NOTAB {(KEYMAP *) ¬abmap, "notab",}, -#endif /* NOTAB */ {(KEYMAP *) &overwmap, "overwrite",}, {(KEYMAP *) &metamap, "esc prefix",}, {(KEYMAP *) &cXmap, "c-x prefix",}, diff --git a/log.c b/log.c index 5f95afd..5591032 100644 --- a/log.c +++ b/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.12 2021/03/02 13:06:50 lum Exp $ */ +/* $OpenBSD: log.c,v 1.13 2022/12/26 19:16:02 jmc Exp $ */ /* * This file is in the public domain. @@ -16,7 +16,7 @@ * amend the 'Makefile' for that to happen. Because of this, the code * is subject to bit-rot. However, I know myself and others have * written similar functionally often enough, that recording the below - * in a code repository could aid the developement efforts of mg, even + * in a code repository could aid the development efforts of mg, even * if it requires a bit of effort to get working. The current code is * written in the spirit of debugging (quickly and perhaps not ideal, * but it does what is required well enough). Should debugging become diff --git a/macro.c b/macro.c index 984f614..50c6aba 100644 --- a/macro.c +++ b/macro.c @@ -1,4 +1,4 @@ -/* $OpenBSD: macro.c,v 1.16 2015/03/19 21:22:15 bcallah Exp $ */ +/* $OpenBSD: macro.c,v 1.18 2023/03/08 04:43:11 guenther Exp $ */ /* This file is in the public domain. */ @@ -15,7 +15,7 @@ #include "key.h" #include "macro.h" -int inmacro = FALSE; /* Macro playback in progess */ +int inmacro = FALSE; /* Macro playback in progress */ int macrodef = FALSE; /* Macro recording in progress */ int macrocount = 0; @@ -24,7 +24,6 @@ struct line *maclcur; union macrodef macro[MAXMACRO]; -/* ARGSUSED */ int definemacro(int f, int n) { @@ -54,7 +53,6 @@ definemacro(int f, int n) return (macrodef = TRUE); } -/* ARGSUSED */ int finishmacro(int f, int n) { @@ -66,7 +64,6 @@ finishmacro(int f, int n) return (FALSE); } -/* ARGSUSED */ int executemacro(int f, int n) { diff --git a/main.c b/main.c index 743f0de..bbc8fb9 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.90 2021/05/03 12:18:43 lum Exp $ */ +/* $OpenBSD: main.c,v 1.95 2023/04/14 15:34:08 tb Exp $ */ /* This file is in the public domain. */ @@ -57,7 +57,7 @@ extern char *__progname; extern void closetags(void); static __dead void -usage() +usage(void) { fprintf(stderr, "usage: %s [-nR] [-b file] [-f mode] [-u file] " "[+number] [file ...]\n", @@ -68,6 +68,8 @@ usage() int main(int argc, char **argv) { + FILE *ffp; + char file[NFILEN]; char *cp, *conffile = NULL, *init_fcn_name = NULL; char *batchfile = NULL; PF init_fcn = NULL; @@ -115,10 +117,11 @@ main(int argc, char **argv) pty_init(); conffile = batchfile; } - if (conffile != NULL && access(conffile, R_OK) != 0) { - fprintf(stderr, "%s: Problem with file: %s\n", __progname, + if ((ffp = startupfile(NULL, conffile, file, sizeof(file))) == NULL && + conffile != NULL) { + fprintf(stderr, "%s: Problem with file: %s\n", __progname, conffile); - exit(1); + exit(1); } argc -= optind; @@ -167,8 +170,10 @@ main(int argc, char **argv) update(CMODE); /* user startup file. */ - if ((cp = startupfile(NULL, conffile)) != NULL) - (void)load(cp); + if (ffp != NULL) { + (void)load(ffp, file); + ffclose(ffp, NULL); + } if (batch) return (0); @@ -301,7 +306,7 @@ pty_init(void) memset(&ws, 0, sizeof(ws)); ws.ws_col = 80, ws.ws_row = 24; - + openpty(&master, &slave, NULL, NULL, &ws); login_tty(slave); @@ -312,7 +317,6 @@ pty_init(void) * Quit command. If an argument, always quit. Otherwise confirm if a buffer * has been changed and not written out. Normally bound to "C-x C-c". */ -/* ARGSUSED */ int quit(int f, int n) { @@ -335,7 +339,6 @@ quit(int f, int n) * User abort. Should be called by any input routine that sees a C-g to abort * whatever C-g is aborting these days. Currently does nothing. */ -/* ARGSUSED */ int ctrlg(int f, int n) { diff --git a/match.c b/match.c index d35fcfd..9481985 100644 --- a/match.c +++ b/match.c @@ -1,4 +1,4 @@ -/* $OpenBSD: match.c,v 1.22 2021/03/01 10:51:14 lum Exp $ */ +/* $OpenBSD: match.c,v 1.25 2023/04/21 13:39:37 op Exp $ */ /* This file is in the public domain. */ @@ -136,6 +136,7 @@ displaymatch(struct line *clp, int cbo) int cp; int bufo; int c; + int col; int inwindow; char buf[NLINE]; @@ -168,21 +169,23 @@ displaymatch(struct line *clp, int cbo) /* match is not in this window, so display line in echo area */ bufo = 0; for (cp = 0; cp < llength(clp); cp++) { + if (bufo >= sizeof(buf) - 1) + break; + c = lgetc(clp, cp); - if (c != '\t' -#ifdef NOTAB - || (curbp->b_flag & BFNOTAB) -#endif - ) + if (c != '\t') { if (ISCTRL(c)) { + if (bufo >= sizeof(buf) - 3) + break; buf[bufo++] = '^'; buf[bufo++] = CCHR(c); } else buf[bufo++] = c; - else - do { + } else { + col = ntabstop(bufo, curbp->b_tabw); + while (bufo < col && bufo < sizeof(buf) - 1) buf[bufo++] = ' '; - } while (bufo & 7); + } } buf[bufo++] = '\0'; ewprintf("Matches %s", buf); diff --git a/mg.1 b/mg.1 index e559aff..e1df3f2 100644 --- a/mg.1 +++ b/mg.1 @@ -1,7 +1,7 @@ -.\" $OpenBSD: mg.1,v 1.125 2021/05/02 14:13:17 lum Exp $ +.\" $OpenBSD: mg.1,v 1.135 2023/06/28 08:37:52 op Exp $ .\" This file is in the public domain. .\" -.Dd $Mdocdate: May 2 2021 $ +.Dd $Mdocdate: June 28 2023 $ .Dt MG 1 .Os .Sh NAME @@ -43,7 +43,9 @@ commands found in the specified .Ar file and then terminate. .It Fl f Ar mode -Run the mode command for all buffers created from +Run the +.Ar mode +command for all buffers created from arguments on the command line, including the scratch buffer and all files. .It Fl n @@ -101,15 +103,20 @@ Backup files have a character appended to the file name and are created in the current working directory by default. Whether to create backup files or not can be toggled with the -make-backup-files command. +.Ic make-backup-files +command. The backup file location can either be in the current working directory, or all backups can be moved to a .Pa ~/.mg.d directory where files retain their path name to retain uniqueness. -Use the backup-to-home-directory to alternate between these two locations. +Use the +.Ic backup-to-home-directory +command to alternate between these two locations. Further, if any application creates backup files in .Pa /tmp , -these can be left with the leave-tmpdir-backups command. +these can be left with the +.Ic leave-tmpdir-backups +command. .Sh TAGS .Nm supports tag files created by @@ -331,6 +338,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-| @@ -376,294 +385,314 @@ If a positive parameter is supplied, the mode is forced to on. Otherwise, it is forced to off. .\" .Bl -tag -width xxxxx -.It apropos +.It Ic apropos Help Apropos. Prompt the user for a string, open the *help* buffer, and list all .Nm commands that contain that string. -.It audible-bell +.It Ic audible-bell Toggle the audible system bell. -.It auto-execute +.It Ic auto-execute Register an auto-execute hook; that is, specify a filename pattern (conforming to the shell's filename globbing rules) and an associated function to execute when a file matching the specified pattern is read into a buffer. -.It auto-fill-mode +.It Ic auto-fill-mode Toggle auto-fill mode (sometimes called mail-mode) in the current buffer, where text inserted past the fill column is automatically wrapped to a new line. -Can be set globally with set-default-mode. -.It auto-indent-mode +Can be set globally with +.Ic set-default-mode . +.It Ic auto-indent-mode Toggle indent mode in the current buffer, where indentation is preserved after a newline. -Can be set globally with set-default-mode. -.It back-to-indentation +Can be set globally with +.Ic set-default-mode . +.It Ic back-to-indentation Move the dot to the first non-whitespace character on the current line. -.It backup-to-home-directory +.It Ic backup-to-home-directory Save backup copies to a .Pa ~/.mg.d directory instead of working directory. -Requires make-backup-files to be on. -.It backward-char +Requires +.Ic make-backup-files +to be on. +.It Ic backward-char Move cursor backwards one character. -.It backward-kill-word +.It Ic backward-kill-word Kill text backwards by .Va n words. -.It backward-paragraph +.It Ic backward-paragraph Move cursor backwards .Va n paragraphs. Paragraphs are delimited by or or . -.It backward-word +.It Ic backward-word Move cursor backwards by the specified number of words. -.It beginning-of-buffer +.It Ic beginning-of-buffer Move cursor to the top of the buffer. If set, keep mark's position, otherwise set at current position. A numeric argument .Va n will move n/10th of the way from the top. -.It beginning-of-line +.It Ic beginning-of-line Move cursor to the beginning of the line. -.It blink-and-insert +.It Ic blink-and-insert Self-insert a character, then search backwards and blink its matching delimiter. For delimiters other than parenthesis, brackets, and braces, the character itself is used as its own match. -Can be used in the startup file with the global-set-key command. -.It bsmap-mode +Can be used in the startup file with the +.Ic global-set-key +command. +.It Ic bsmap-mode Toggle bsmap mode, where DEL and C-h are swapped. -.It c-mode +.It Ic c-mode Toggle a KNF-compliant mode for editing C program files. -.It call-last-kbd-macro +.It Ic call-last-kbd-macro Invoke the keyboard macro. -.It capitalize-word +.It Ic capitalize-word Capitalize .Va n words; i.e. convert the first character of the word to upper case, and subsequent letters to lower case. -.It cd +.It Ic cd Change the global working directory. -See also global-wd-mode. -.It column-number-mode +See also +.Ic global-wd-mode . +.It Ic column-number-mode Toggle whether the column number is displayed in the modeline. -.It copy-region-as-kill +.It Ic copy-region-as-kill Copy all of the characters in the region to the kill buffer, clearing the mark afterwards. -This is a bit like a kill-region followed by a yank. -.It count-matches +This is a bit like a +.Ic kill-region +followed by a +.Ic yank . +.It Ic count-matches Count the number of lines matching the supplied regular expression. -.It count-non-matches +.It Ic count-non-matches Count the number of lines not matching the supplied regular expression. -.It cscope-find-this-symbol +.It Ic cscope-find-this-symbol List the matches for the given symbol. -.It cscope-find-global-definition +.It Ic cscope-find-global-definition List global definitions for the given literal. -.It cscope-find-called-functions +.It Ic cscope-find-called-functions List functions called from the given function. -.It cscope-find-functions-calling-this-function +.It Ic cscope-find-functions-calling-this-function List functions calling the given function. -.It cscope-find-this-text-string +.It Ic cscope-find-this-text-string List locations matching the given text string. -.It cscope-find-egrep-pattern +.It Ic cscope-find-egrep-pattern List locations matching the given extended regular expression pattern. -.It cscope-find-this-file +.It Ic cscope-find-this-file List filenames matching the given filename. -.It cscope-find-files-including-file +.It Ic cscope-find-files-including-file List files that #include the given filename. -.It cscope-next-symbol +.It Ic cscope-next-symbol Navigate to the next match. -.It cscope-prev-symbol +.It Ic cscope-prev-symbol Navigate to the previous match. -.It cscope-next-file +.It Ic cscope-next-file Navigate to the next file. -.It cscope-prev-file +.It Ic cscope-prev-file Navigate to the previous file. -.It cscope-create-list-of-files-to-index +.It Ic cscope-create-list-of-files-to-index Create cscope's List and Index in the given directory. -.It define-key +.It Ic define-key Prompts the user for a named keymap (mode), a key, and an .Nm command, then creates a keybinding in the appropriate map. -.It delete-backward-char +.It Ic delete-backward-char Delete backwards .Va n characters. -Like delete-char, this actually does a kill if presented +Like +.Ic delete-char , +this actually does a kill if presented with an argument. -.It delete-blank-lines +.It Ic delete-blank-lines Delete blank lines around dot. If dot is sitting on a blank line, this command deletes all the blank lines above and below the current line. Otherwise, it deletes all of the blank lines after the current line. -.It delete-char +.It Ic delete-char Delete .Va n characters forward. If any argument is present, it kills rather than deletes, saving the result in the kill buffer. -.It delete-horizontal-space +.It Ic delete-horizontal-space Delete any whitespace around the dot. -.It delete-leading-space +.It Ic delete-leading-space Delete leading whitespace on the current line. -.It delete-trailing-space +.It Ic delete-trailing-space Delete trailing whitespace on the current line. -.It delete-matching-lines +.It Ic delete-matching-lines Delete all lines after dot that contain a string matching the supplied regular expression. -.It delete-non-matching-lines +.It Ic delete-non-matching-lines Delete all lines after dot that don't contain a string matching the supplied regular expression. -.It delete-other-windows +.It Ic delete-other-windows Make the current window the only window visible on the screen. -.It delete-window +.It Ic delete-window Delete current window. -.It describe-bindings +.It Ic describe-bindings List all global and local keybindings, putting the result in the *help* buffer. -.It describe-key-briefly +.It Ic describe-key-briefly Read a key from the keyboard, and look it up in the keymap. Display the name of the function currently bound to the key. -.It diff-buffer-with-file +.It Ic diff-buffer-with-file View the differences between buffer and its associated file. -.It digit-argument +.It Ic digit-argument Process a numerical argument for keyboard-invoked functions. -.It dired-jump +.It Ic dired-jump Open a dired buffer containing the current buffer's directory location. -.It downcase-region +.It Ic downcase-region Set all characters in the region to lower case. -.It downcase-word +.It Ic downcase-word Set characters to lower case, starting at the dot, and ending .Va n words away. -.It emacs-version +.It Ic emacs-version Return an .Nm version string. -.It end-kbd-macro +.It Ic end-kbd-macro Stop defining a keyboard macro. -.It end-of-buffer +.It Ic end-of-buffer Move cursor to the end of the buffer. If set, keep mark's position, otherwise set at current position. A numeric argument .Va n will move n/10th of the way from the end. -.It end-of-line +.It Ic end-of-line Move cursor to the end of the line. -.It enlarge-window +.It Ic enlarge-window Enlarge the current window by shrinking either the window above or below it. -.It eval-current-buffer +.It Ic eval-current-buffer Evaluate the current buffer as a series of .Nm commands. Useful for testing .Nm startup files. -.It eval-expression +.It Ic eval-expression Get one line from the user, and run it. Useful for testing expressions in .Nm startup files. -.It exchange-point-and-mark +.It Ic exchange-point-and-mark Swap the values of "dot" and "mark" in the current window. Return an error if no mark is set. -.It execute-extended-command +.It Ic execute-extended-command Invoke an extended command; i.e. M-x. Call the message line routine to read in the command name and apply autocompletion to it. When it comes back, look the name up in the symbol table and run the command if it is found, passing arguments as necessary. Print an error if there is anything wrong. -.It fill-paragraph +.It Ic fill-paragraph Justify a paragraph, wrapping text at the current fill column. -.It find-file +.It Ic find-file Select a file for editing. First check if the file can be found in another buffer; if it is there, just switch to that buffer. If the file cannot be found, create a new buffer, read in the file from disk, and switch to the new buffer. -.It find-file-read-only -Same as find-file, except the new buffer is set to read-only. -.It find-alternate-file +.It Ic find-file-read-only +Same as +.Ic find-file , +except the new buffer is set to read-only. +.It Ic find-alternate-file Replace the current file with an alternate one. Semantics for finding the replacement file are the same as -find-file, except the current buffer is killed before the switch. +.Ic find-file , +except the current buffer is killed before the switch. If the kill fails, or is aborted, revert to the original file. -.It find-file-other-window +.It Ic find-file-other-window Opens the specified file in a second buffer. Splits the current window if necessary. -.It find-tag +.It Ic find-tag Jump to definition of tag at dot. -.It forward-char +.It Ic forward-char Move cursor forwards (or backwards, if .Va n is negative) .Va n characters. Returns an error if the end of buffer is reached. -.It forward-paragraph +.It Ic forward-paragraph Move forward .Va n paragraphs. Paragraphs are delimited by or or . -.It forward-word +.It Ic forward-word Move the cursor forward by the specified number of words. -.It global-set-key +.It Ic global-set-key Bind a key in the global (fundamental) key map. -.It global-unset-key +.It Ic global-unset-key Unbind a key from the global (fundamental) key map; i.e. set it to 'rescan'. -.It global-wd-mode +.It Ic global-wd-mode Toggle global working-directory mode. When enabled, .Nm -defaults to opening files (and executing commands like compile and grep) +defaults to opening files (and executing commands like +.Ic compile +and +.Ic grep ) relative to the global working directory. When disabled, a working directory is set for each buffer. -.It goto-line +.It Ic goto-line Go to a specific line. If an argument is present, then it is the line number, else prompt for a line number to use. -.It help-help +.It Ic help-help Prompts for one of (a)propos, (b)indings, des(c)ribe key briefly. -.It insert +.It Ic insert Insert a string, mainly for use from macros. -.It insert-buffer +.It Ic insert-buffer Insert the contents of another buffer at dot. -.It insert-file +.It Ic insert-file Insert a file into the current buffer at dot. -.It insert-with-wrap +.It Ic insert-with-wrap Insert the bound character with word wrap. Check to see if we're past the fill column, and if so, justify this line. -.It isearch-backward +.It Ic isearch-backward Use incremental searching, initially in the reverse direction. isearch ignores any explicit arguments. If invoked during macro definition or evaluation, the non-incremental -search-backward is invoked instead. -.It isearch-forward +.Ic search-backward +is invoked instead. +.It Ic isearch-forward Use incremental searching, initially in the forward direction. isearch ignores any explicit arguments. If invoked during macro definition or evaluation, the non-incremental -search-forward is invoked instead. -.It join-line +.Ic search-forward +is invoked instead. +.It Ic join-line Join the current line to the previous. If called with an argument, join the next line to the current one. -.It just-one-space +.It Ic just-one-space Delete any whitespace around dot, then insert a space. -.It keyboard-quit +.It Ic keyboard-quit Abort the current action. -.It kill-buffer +.It Ic kill-buffer Dispose of a buffer, by name. If the buffer name does not start and end with an asterisk, prompt the user if the buffer has been changed. -.It kill-line +.It Ic kill-line Kill line. If called without an argument, it kills from dot to the end of the line, unless it is at the end of the line, when it kills the @@ -675,138 +704,145 @@ forward over that number of newlines. If called with a negative argument it kills any text before dot on the current line, then it kills back abs(n) lines. -.It kill-paragraph +.It Ic kill-paragraph Delete .Va n paragraphs starting with the current one. -.It kill-region +.It Ic kill-region Kill the currently defined region. -.It kill-word +.It Ic kill-word Delete forward .Va n words. -.It leave-tmpdir-backups -Modifies the behaviour of backup-to-home-directory. +.It Ic leave-tmpdir-backups +Modifies the behaviour of +.Ic backup-to-home-directory . Backup files that would normally reside in .Pa /tmp are left there and not moved to the .Pa ~/.mg.d directory. -.It line-number-mode +.It Ic line-number-mode Toggle whether the line number is displayed in the modeline. -.It list-buffers +.It Ic list-buffers Display the list of available buffers. The first column in the output indicates which buffer is active with a '>' character. The second column indicates which buffers are modified. The third column indicates which buffers are read-only. The remaining columns are self-explanatory. -.It load +.It Ic load Prompt the user for a filename, and then execute commands from that file. -.It local-set-key +.It Ic local-set-key Bind a key mapping in the local (topmost) mode. -.It local-unset-key +.It Ic local-unset-key Unbind a key mapping in the local (topmost) mode. -.It make-backup-files +.It Ic make-backup-files Toggle generation of backup files. Enabled by default. -.It make-directory +.It Ic make-directory Prompt the user for a path or directory name which is then created. -.It mark-paragraph +.It Ic mark-paragraph Mark .Va n paragraphs. -.It mark-whole-buffer +.It Ic mark-whole-buffer Marks whole buffer as a region by putting dot at the beginning and mark at the end of buffer. -.It meta-key-mode +.It Ic meta-key-mode When disabled, the meta key can be used to insert extended-ascii (8-bit) characters. When enabled, the meta key acts as usual. -.It negative-argument +.It Ic negative-argument Process a negative argument for keyboard-invoked functions. -.It newline +.It Ic newline Insert a newline into the current buffer. -.It newline-and-indent +.It Ic newline-and-indent Insert a newline, then enough tabs and spaces to duplicate the indentation -of the previous line. -Assumes tabs are every eight characters. -.It next-line +of the previous line, respecting +.Ic no-tab-mode +and the buffer tab width. +.It Ic next-line Move forward .Va n lines. -.\" .It no-tab-mode -.\" Toggle notab mode. -.\" In this mode, spaces are inserted rather than tabs. -.It not-modified +.It Ic no-tab-mode +Toggle notab mode. +In this mode, spaces are inserted rather than tabs. +Can be set globally with +.Ic set-default-mode . +.It Ic not-modified Turn off the modified flag in the current buffer. -.It open-line +.It Ic open-line Open up some blank space. Essentially, insert .Va n newlines, then back up over them. -.It other-window +.It Ic other-window The command to make the next (down the screen) window the current window. There are no real errors, although the command does nothing if there is only 1 window on the screen. -.It overwrite-mode +.It Ic overwrite-mode Toggle overwrite mode in the current buffer, where typing overwrites existing characters rather than inserting them. -Can be set globally with set-default-mode. -.It prefix-region +Can be set globally with +.Ic set-default-mode . +.It Ic prefix-region Inserts a prefix string before each line of a region. -The prefix string is settable by using 'set-prefix-string'. -.It previous-line +The prefix string is settable by using +.Ic set-prefix-string +or by invoking this command with a prefix argument. +.It Ic previous-line Move backwards .Va n lines. -.It previous-window +.It Ic previous-window This command makes the previous (up the screen) window the current window. There are no errors, although the command does not do a lot if there is only 1 window. -.It pop-tag-mark +.It Ic pop-tag-mark Return to position where find-tag was previously invoked. -.It push-shell +.It Ic push-shell Suspend .Nm and switch to alternate screen, if available. -.It pwd +.It Ic pwd Display current (global) working directory in the status area. -.It query-replace +.It Ic query-replace Query Replace. Search and replace strings selectively, prompting after each match. -.It replace-regexp +.It Ic replace-regexp Replace regular expression globally without individual prompting. -.It replace-string +.It Ic replace-string Replace string globally without individual prompting. -.It query-replace-regexp +.It Ic query-replace-regexp Replace strings selectively. Does a search and replace operation using regular expressions for both patterns. -.It quoted-insert +.It Ic quoted-insert Insert the next character verbatim into the current buffer; i.e. ignore any function bound to that key. -.It re-search-again +.It Ic re-search-again Perform a regular expression search again, using the same search string and direction as the last search command. -.It re-search-backward +.It Ic re-search-backward Search backwards using a regular expression. Get a search string from the user, and search, starting at dot and proceeding toward the front of the buffer. If found, dot is left pointing at the first character of the pattern [the last character that was matched]. -.It re-search-forward +.It Ic re-search-forward Search forward using a regular expression. Get a search string from the user and search for it starting at dot. If found, move dot to just after the matched characters. display does all the hard stuff. If not found, it just prints a message. -.It recenter +.It Ic recenter Reposition dot in the current window. By default, the dot is centered. If given a positive argument (n), the display is repositioned to line @@ -814,159 +850,166 @@ n. If .Va n is negative, it is that line from the bottom. -.It redraw-display +.It Ic redraw-display Refresh the display. Recomputes all window sizes in case something has changed. -.It revert-buffer +.It Ic revert-buffer Revert the current buffer to the latest file on disk. -.It save-buffer +.It Ic save-buffer Save the contents of the current buffer if it has been changed, optionally creating a backup copy. -.It save-buffers-kill-emacs +.It Ic save-buffers-kill-emacs Offer to save modified buffers and quit .Nm . -.It save-some-buffers +.It Ic save-some-buffers Look through the list of buffers, offering to save any buffer that has been changed. Buffers that are not associated with files (such as *scratch*, *grep*, *compile*) are ignored. -.It scroll-down +.It Ic scroll-down Scroll backwards .Va n pages. A two-line overlap between pages is assumed. If given a repeat argument, scrolls back lines, not pages. -.It scroll-one-line-down +.It Ic scroll-one-line-down Scroll the display down .Va n lines without changing the cursor position. -.It scroll-one-line-up +.It Ic scroll-one-line-up Scroll the display .Va n lines up without moving the cursor position. -.It scroll-other-window +.It Ic scroll-other-window Scroll the next window in the window list window forward .Va n pages. -.It scroll-up +.It Ic scroll-up Scroll forward one page. A two-line overlap between pages is assumed. If given a repeat argument, scrolls back lines, not pages. -.It search-again +.It Ic search-again Search again, using the same search string and direction as the last search command. -.It search-backward +.It Ic search-backward Reverse search. Get a search string from the user, and search, starting at dot and proceeding toward the front of the buffer. If found, dot is left pointing at the first character of the pattern (the last character that was matched). -.It search-forward +.It Ic search-forward Search forward. Get a search string from the user, and search for it starting at dot. If found, dot gets moved to just after the matched characters, if not found, print a message. -.It self-insert-command +.It Ic self-insert-command Insert a character. -.It sentence-end-double-space +.It Ic sentence-end-double-space Toggle double or single spaces for end of sentences. Double is the default. Currently only affects fill-paragraph. -.It set-case-fold-search +.It Ic set-case-fold-search Set case-fold searching, causing case not to matter in regular expression searches. This is the default. -.It set-case-replace +.It Ic set-case-replace Preserve the case of the replaced string. This is the default. -.It set-default-mode +.It Ic set-default-mode Append the supplied mode to the list of default modes used by subsequent buffer creation. -Built in modes include: fill, indent and overwrite. -.It set-fill-column +Built in modes include: fill, indent, notab and overwrite. +.It Ic set-fill-column Prompt the user for a fill column. -Used by auto-fill-mode. -.It set-mark-command +Used by +.Ic auto-fill-mode . +.It Ic set-mark-command Sets the mark in the current window to the current dot location. -.It set-prefix-string -Sets the prefix string to be used by the 'prefix-region' command. -.It shell-command +.It Ic set-prefix-string +Sets the prefix string to be used by the +.Ic prefix-region +command. +.It Ic set-tab-width +Set the tab width for the current buffer, or the default for new buffers +if called with a prefix argument or from the startup file. +.It Ic shell-command Execute external command from mini-buffer. -.It shell-command-on-region +.It Ic shell-command-on-region Provide the text in region to the shell command as input. -.It shrink-window +.It Ic shrink-window Shrink current window by one line. The window immediately below is expanded to pick up the slack. If only one window is present, this command has no effect. -.It split-window-vertically +.It Ic split-window-vertically Split the current window. A window smaller than 3 lines cannot be split. -.It start-kbd-macro +.It Ic start-kbd-macro Start defining a keyboard macro. Macro definition is ended by invoking end-kbd-macro. -.It suspend-emacs +.It Ic suspend-emacs Suspend .Nm and switch back to alternate screen, if in use. -.It switch-to-buffer +.It Ic switch-to-buffer Prompt and switch to a new buffer in the current window. -.It switch-to-buffer-other-window +.It Ic switch-to-buffer-other-window Switch to buffer in another window. -.It toggle-read-only +.It Ic toggle-read-only Toggle the read-only flag on the current buffer. -.It toggle-read-only-all +.It Ic toggle-read-only-all Toggle the read-only flag on all non-ephemeral buffers. A simple toggle that switches a global read-only flag either on or off. -.It transpose-chars +.It Ic transpose-chars Transpose the two characters in front of and under dot, then move forward one character. Treat newline characters the same as any other. -.It transpose-paragraphs +.It Ic transpose-paragraphs Transpose adjacent paragraphs. If multiple iterations are requested, the current paragraph will be moved .Va n paragraphs forward. -.It transpose-words +.It Ic transpose-words Transpose adjacent words. -.It undo +.It Ic undo Undo the most recent action. If invoked again without an intervening command, move the undo pointer to the previous action and undo it. -.It undo-boundary +.It Ic undo-boundary Add an undo boundary. This is not usually done interactively. -.It undo-boundary-toggle +.It Ic undo-boundary-toggle Toggle whether undo boundaries are generated. Undo boundaries are often disabled before operations that should be considered atomically undoable. -.It undo-enable +.It Ic undo-enable Toggle whether undo information is kept. -.It undo-list +.It Ic undo-list Show the undo records for the current buffer in a new buffer. -.It universal-argument +.It Ic universal-argument Repeat the next command 4 times. Usually bound to C-u. This command may be stacked; e.g.\& C-u C-u C-f moves the cursor forward 16 characters. -.It upcase-region +.It Ic upcase-region Upper case region. Change all of the lower case characters in the region to upper case. -.It upcase-word +.It Ic upcase-word Move the cursor forward by the specified number of words. As it moves, convert any characters to upper case. -.It visible-bell +.It Ic visible-bell Toggle the visible bell. If this toggle is on, the modeline will flash. -.It visit-tags-table -Record name of the tags file to be used for subsequent find-tag. -.It what-cursor-position +.It Ic visit-tags-table +Load tags file to be used for subsequent +.Ic find-tag . +.It Ic what-cursor-position Display a bunch of useful information about the current location of dot. The character under the cursor (in octal), the current line, row, @@ -974,18 +1017,26 @@ and column, and approximate position of the cursor in the file (as a percentage) is displayed. The column position assumes an infinite position display; it does not truncate just because the screen does. -.It write-file +.It Ic write-file Ask for a file name and write the contents of the current buffer to that file. Update the remembered file name and clear the buffer changed flag. -.It yank -Yank text from kill-buffer. +.It Ic yank +Yank text from +.Ic kill-buffer . Unlike emacs, the .Nm kill buffer consists only of the most recent kill. It is not a ring. +.It Ic 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 Ic zap-up-to-char +Like +.Ic zap-to-char +but doesn't delete the target character. .El .Sh MG DIRED KEY BINDINGS Specific key bindings are available in dired mode. @@ -1031,51 +1082,52 @@ dired-scroll-up .Sh MG DIRED COMMANDS The following are a list of the commands specific to dired mode: .Bl -tag -width Ds -.It dired-create-directory +.It Ic dired-create-directory Create a directory. -.It dired-do-copy +.It Ic dired-do-copy Copy the file listed on the current line of the dired buffer. -.It dired-do-flagged-delete +.It Ic dired-do-flagged-delete Delete the files that have been flagged for deletion. -.It dired-do-rename +.It Ic dired-do-rename Rename the file listed on the current line of the dired buffer. -.It dired-find-alternate-file +.It Ic dired-find-alternate-file Replace the current dired buffer with an alternate one as specified by the position of the cursor in the dired buffer. -.It dired-find-file +.It Ic dired-find-file Open the file on the current line of the dired buffer. -If the cursor is on a directory it will be opened in dired mode. -.It dired-flag-file-deletion +If the cursor is on a directory, it will be opened in dired mode. +.It Ic dired-flag-file-deletion Flag the file listed on the current line for deletion. This is indicated in the buffer by putting a D at the left margin. -No files are actually deleted until the function dired-do-flagged-delete +No files are actually deleted until the function +.Ic dired-do-flagged-delete is executed. -.It dired-find-file-other-window +.It Ic dired-find-file-other-window Open the file on the current line of the dired buffer in a different window. -.It dired-goto-file +.It Ic dired-goto-file Move the cursor to a file name in the dired buffer. -.It dired-next-line +.It Ic dired-next-line Move the cursor to the next line. -.It dired-other-window +.It Ic dired-other-window This function works just like dired, except that it puts the dired buffer in another window. -.It dired-previous-line +.It Ic dired-previous-line Move the cursor to the previous line. -.It dired-revert +.It Ic dired-revert Refresh the dired buffer while retaining any flags. -.It dired-scroll-down +.It Ic dired-scroll-down Scroll down the dired buffer. -.It dired-scroll-up +.It Ic dired-scroll-up Scroll up the dired buffer. -.It dired-shell-command +.It Ic dired-shell-command Pipe the file under the current cursor position through a shell command. -.It dired-unmark +.It Ic dired-unmark Remove the deletion flag for the file on the current line. -.It dired-unmark-backward +.It Ic dired-unmark-backward Remove the deletion flag from the file listed on the previous line of the dired buffer, then move up to that line. -.It quit-window +.It Ic quit-window Close the current dired buffer. .El .Sh CONFIGURATION FILES @@ -1134,7 +1186,7 @@ in startup files. .Pp In order to use 8-bit characters (such as German umlauts), the Meta key needs to be disabled via the -.Dq meta-key-mode +.Ic meta-key-mode command. .Pp Multi-byte character sets, such as UTF-8, are not supported. diff --git a/modes.c b/modes.c index 9d5e4ce..c95e1fd 100644 --- a/modes.c +++ b/modes.c @@ -1,4 +1,4 @@ -/* $OpenBSD: modes.c,v 1.21 2017/05/30 07:05:22 florian Exp $ */ +/* $OpenBSD: modes.c,v 1.22 2023/04/17 09:49:04 op Exp $ */ /* This file is in the public domain. */ @@ -78,7 +78,6 @@ fillmode(int f, int n) return (changemode(f, n, "fill")); } -#ifdef NOTAB int notabmode(int f, int n) { @@ -93,7 +92,6 @@ notabmode(int f, int n) curbp->b_flag ^= BFNOTAB; return (TRUE); } -#endif /* NOTAB */ int overwrite_mode(int f, int n) @@ -162,13 +160,11 @@ set_default_mode(int f, int n) else defb_flag |= BFOVERWRITE; } -#ifdef NOTAB if (strcmp(modebuf, "notab") == 0) { if (n <= 0) defb_flag &= ~BFNOTAB; else defb_flag |= BFNOTAB; } -#endif /* NOTAB */ return (TRUE); } diff --git a/paragraph.c b/paragraph.c index 694fcc9..4e35770 100644 --- a/paragraph.c +++ b/paragraph.c @@ -1,4 +1,4 @@ -/* $OpenBSD: paragraph.c,v 1.46 2018/11/17 09:52:34 lum Exp $ */ +/* $OpenBSD: paragraph.c,v 1.49 2023/04/21 13:39:37 op Exp $ */ /* This file is in the public domain. */ @@ -30,7 +30,6 @@ static int do_gotoeop(int, int, int *); * preceding line. Keep doing this until a line with only spaces is found or * the start of buffer. */ -/* ARGSUSED */ int gotobop(int f, int n) { @@ -69,7 +68,6 @@ gotobop(int f, int n) * Move to end of paragraph. * See comments for gotobop(). Same, but moving forwards. */ -/* ARGSUSED */ int gotoeop(int f, int n) { @@ -126,7 +124,6 @@ do_gotoeop(int f, int n, int *i) * Justify a paragraph. Fill the current paragraph according to the current * fill column. */ -/* ARGSUSED */ int fillpara(int f, int n) { @@ -264,7 +261,6 @@ fillpara(int f, int n) * the cursor is on an empty line, move down the buffer to the first line with * non-space characters. Then mark n paragraphs and delete. */ -/* ARGSUSED */ int killpara(int f, int n) { @@ -298,7 +294,6 @@ killpara(int f, int n) * This leaves the cursor at the beginning of the paragraph where markpara() * was invoked. */ -/* ARGSUSED */ int markpara(int f, int n) { @@ -328,7 +323,6 @@ markpara(int f, int n) * multiple times, transpose to the n'th paragraph. If invoked between * paragraphs, move to the previous paragraph, then continue. */ -/* ARGSUSED */ int transposepara(int f, int n) { @@ -408,7 +402,6 @@ findpara(void) * Insert char with work wrap. Check to see if we're past fillcol, and if so, * justify this line. As a last step, justify the line. */ -/* ARGSUSED */ int fillword(int f, int n) { @@ -419,12 +412,8 @@ fillword(int f, int n) if (i == curwp->w_doto) return selfinsert(f, n); c = lgetc(curwp->w_dotp, i); - if (c == '\t' -#ifdef NOTAB - && !(curbp->b_flag & BFNOTAB) -#endif - ) - col |= 0x07; + if (c == '\t') + col = ntabstop(col, curwp->w_bufp->b_tabw); else if (ISCTRL(c) != FALSE) ++col; } diff --git a/re_search.c b/re_search.c index eba9b03..81fb1dd 100644 --- a/re_search.c +++ b/re_search.c @@ -1,4 +1,4 @@ -/* $OpenBSD: re_search.c,v 1.36 2021/04/22 19:50:55 lum Exp $ */ +/* $OpenBSD: re_search.c,v 1.37 2023/03/08 04:43:11 guenther Exp $ */ /* This file is in the public domain. */ @@ -51,7 +51,6 @@ static int countmatches(int); * found, move "." to just after the matched characters. display does all * the hard stuff. If not found, it just prints a message. */ -/* ARGSUSED */ int re_forwsearch(int f, int n) { @@ -75,7 +74,6 @@ re_forwsearch(int f, int n) * pointing at the first character of the pattern [the last character that * was matched]. */ -/* ARGSUSED */ int re_backsearch(int f, int n) { @@ -100,7 +98,6 @@ re_backsearch(int f, int n) * XXX: This code has problems -- some incompatibility(?) with extend.c causes * match to fail when it should not. */ -/* ARGSUSED */ int re_searchagain(int f, int n) { @@ -135,7 +132,6 @@ static regmatch_t regex_match[RE_NMATCH]; * Re-Query Replace. * Replace strings selectively. Does a search and replace operation. */ -/* ARGSUSED */ int re_queryrepl(int f, int n) { @@ -498,7 +494,6 @@ re_readpattern(char *re_prompt) * Cause case to not matter in searches. This is the default. If called * with argument cause case to matter. */ -/* ARGSUSED*/ int setcasefold(int f, int n) { @@ -521,7 +516,6 @@ setcasefold(int f, int n) /* * Delete all lines after dot that contain a string matching regex. */ -/* ARGSUSED */ int delmatchlines(int f, int n) { @@ -538,7 +532,6 @@ delmatchlines(int f, int n) /* * Delete all lines after dot that don't contain a string matching regex. */ -/* ARGSUSED */ int delnonmatchlines(int f, int n) { @@ -598,7 +591,6 @@ killmatches(int cond) /* * Count lines matching regex. */ -/* ARGSUSED */ int cntmatchlines(int f, int n) { @@ -614,7 +606,6 @@ cntmatchlines(int f, int n) /* * Count lines that fail to match regex. */ -/* ARGSUSED */ int cntnonmatchlines(int f, int n) { diff --git a/region.c b/region.c index 21c5174..afed531 100644 --- a/region.c +++ b/region.c @@ -1,4 +1,4 @@ -/* $OpenBSD: region.c,v 1.39 2021/03/01 10:51:14 lum Exp $ */ +/* $OpenBSD: region.c,v 1.44 2023/03/28 14:47:28 op Exp $ */ /* This file is in the public domain. */ @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -33,13 +34,12 @@ static int iomux(int, char * const, int, struct buffer *); static int preadin(int, struct buffer *); static void pwriteout(int, char **, int *); static int setsize(struct region *, RSIZE); -static int shellcmdoutput(char * const[], char * const, int); +static int shellcmdoutput(char * const, char * const, int); /* * Kill the region. Ask "getregion" to figure out the bounds of the region. * Move "." to the start, and kill the characters. Mark is cleared afterwards. */ -/* ARGSUSED */ int killregion(int f, int n) { @@ -66,7 +66,6 @@ killregion(int f, int n) * clearing the mark afterwards. * This is a bit like a kill region followed by a yank. */ -/* ARGSUSED */ int copyregion(int f, int n) { @@ -112,7 +111,6 @@ copyregion(int f, int n) * the changes. Call "lchange" to ensure that redisplay is done in all * buffers. */ -/* ARGSUSED */ int lowerregion(int f, int n) { @@ -156,7 +154,6 @@ lowerregion(int f, int n) * doing the changes. Call "lchange" to ensure that redisplay is done in all * buffers. */ -/* ARGSUSED */ int upperregion(int f, int n) { @@ -285,7 +282,6 @@ static char prefix_string[PREFIXLENGTH] = {'>', '\0'}; * beginning of the line after the end of the region. If an argument is * given, prompts for the line prefix string. */ -/* ARGSUSED */ int prefixregion(int f, int n) { @@ -332,7 +328,6 @@ prefixregion(int f, int n) /* * Set line prefix string. Used by prefixregion. */ -/* ARGSUSED */ int setprefix(int f, int n) { @@ -414,14 +409,12 @@ markbuffer(int f, int n) /* * Pipe text from current region to external command. */ -/*ARGSUSED */ int piperegion(int f, int n) { struct region region; int len; char *cmd, cmdbuf[NFILEN], *text; - char *argv[] = {"sh", "-c", (char *) NULL, (char *) NULL}; /* C-u M-| is not supported yet */ if (n > 1) @@ -437,8 +430,6 @@ piperegion(int f, int n) EFNEW | EFCR)) == NULL || (cmd[0] == '\0')) return (ABORT); - argv[2] = cmd; - if (getregion(®ion) != TRUE) return (FALSE); @@ -452,19 +443,16 @@ piperegion(int f, int n) region_get_data(®ion, text, len); - return shellcmdoutput(argv, text, len); + return shellcmdoutput(cmd, text, len); } /* * Get command from mini-buffer and execute externally. */ -/*ARGSUSED */ int shellcommand(int f, int n) { - char *cmd, cmdbuf[NFILEN]; - char *argv[] = {"sh", "-c", (char *) NULL, (char *) NULL}; if (n > 1) return (ABORT); @@ -473,17 +461,14 @@ shellcommand(int f, int n) EFNEW | EFCR)) == NULL || (cmd[0] == '\0')) return (ABORT); - argv[2] = cmd; - - return shellcmdoutput(argv, NULL, 0); + return shellcmdoutput(cmd, NULL, 0); } - int -shellcmdoutput(char* const argv[], char* const text, int len) +shellcmdoutput(char* const cmd, char* const text, int len) { - struct buffer *bp; + char *argv[] = {NULL, "-c", cmd, NULL}; char *shellp; int ret; @@ -494,7 +479,13 @@ shellcmdoutput(char* const argv[], char* const text, int len) return (FALSE); } - shellp = getenv("SHELL"); + if ((shellp = getenv("SHELL")) == NULL) + shellp = _PATH_BSHELL; + + if ((argv[0] = strrchr(shellp, '/')) != NULL) + argv[0]++; + else + argv[0] = shellp; ret = pipeio(shellp, argv, text, len, bp); @@ -541,8 +532,6 @@ pipeio(const char* const path, char* const argv[], char* const text, int len, _exit(1); if (dup2(s[1], STDERR_FILENO) == -1) _exit(1); - if (path == NULL) - _exit(1); execv(path, argv); err = strerror(errno); @@ -575,7 +564,7 @@ iomux(int fd, char* const text, int len, struct buffer *outbp) pfd[0].fd = fd; /* There is nothing to write if len is zero - * but the cmd's output should be read so shutdown + * but the cmd's output should be read so shutdown * the socket for writing only and don't wait for POLLOUT */ if (len == 0) { @@ -596,7 +585,7 @@ iomux(int fd, char* const text, int len, struct buffer *outbp) } close(fd); - /* In case if last line doesn't have a '\n' add the leftover + /* In case if last line doesn't have a '\n' add the leftover * characters to buffer. */ if (leftover[0] != '\0') { @@ -616,7 +605,7 @@ iomux(int fd, char* const text, int len, struct buffer *outbp) } /* - * Write some text from region to fd. Once done shutdown the + * Write some text from region to fd. Once done shutdown the * write end. */ void @@ -637,7 +626,7 @@ pwriteout(int fd, char **text, int *len) *text += w; if (*len <= 0) - shutdown(fd, SHUT_WR); + shutdown(fd, SHUT_WR); } /* diff --git a/search.c b/search.c index fa12b40..a6926e0 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.50 2023/03/08 04:43:11 guenther Exp $ */ /* This file is in the public domain. */ @@ -56,7 +56,6 @@ int srch_lastdir = SRCH_NOPR; /* Last search flags. */ * characters, and display does all the hard stuff. If not found, it just * prints a message. */ -/* ARGSUSED */ int forwsearch(int f, int n) { @@ -79,7 +78,6 @@ forwsearch(int f, int n) * left pointing at the first character of the pattern [the last character * that was matched]. */ -/* ARGSUSED */ int backsearch(int f, int n) { @@ -101,7 +99,6 @@ backsearch(int f, int n) * search command. The direction has been saved in "srch_lastdir", so you * know which way to go. */ -/* ARGSUSED */ int searchagain(int f, int n) { @@ -130,7 +127,6 @@ searchagain(int f, int n) * Use incremental searching, initially in the forward direction. * isearch ignores any explicit arguments. */ -/* ARGSUSED */ int forwisearch(int f, int n) { @@ -145,7 +141,6 @@ forwisearch(int f, int n) * Use incremental searching, initially in the reverse direction. * isearch ignores any explicit arguments. */ -/* ARGSUSED */ int backisearch(int f, int n) { @@ -558,7 +553,6 @@ is_dspl(char *i_prompt, int flag) * Query Replace. * Replace strings selectively. Does a search and replace operation. */ -/* ARGSUSED */ int queryrepl(int f, int n) { @@ -640,7 +634,6 @@ queryrepl(int f, int n) /* * Replace string globally without individual prompting. */ -/* ARGSUSED */ int replstr(int f, int n) { @@ -853,3 +846,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 character and deletes from the point up to, optionally + * including, the first instance of that character. 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); +} diff --git a/spawn.c b/spawn.c index 3d9ee95..9ef4a17 100644 --- a/spawn.c +++ b/spawn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: spawn.c,v 1.12 2015/03/19 21:22:15 bcallah Exp $ */ +/* $OpenBSD: spawn.c,v 1.13 2023/03/08 04:43:11 guenther Exp $ */ /* This file is in the public domain. */ @@ -10,7 +10,7 @@ #include #include #include -#include +#include "terminfo_term.h" #include #include "def.h" @@ -20,7 +20,6 @@ * shell supports POSIX job control. If the terminal supports an alternate * screen, we will switch to it. */ -/* ARGSUSED */ int spawncli(int f, int n) { diff --git a/tags.c b/tags.c index 5376364..be2a548 100644 --- a/tags.c +++ b/tags.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tags.c,v 1.16 2017/08/06 04:39:45 bcallah Exp $ */ +/* $OpenBSD: tags.c,v 1.27 2023/03/29 19:09:04 op Exp $ */ /* * This file is in the public domain. @@ -48,9 +48,6 @@ static void unloadtags(void); #define DEFAULTFN "tags" -char *tagsfn = NULL; -int loaded = FALSE; - /* ctags(1) entries are parsed and maintained in a tree. */ struct ctag { RB_ENTRY(ctag) entry; @@ -76,75 +73,40 @@ ctagcmp(struct ctag *s, struct ctag *t) } /* - * Record the filename that contain tags to be used while loading them - * on first use. If a filename is already recorded, ask user to retain - * already loaded tags (if any) and unload them if user chooses not to. + * Load a tags file. If a tags file is already loaded, ask the user to + * retain loaded tags (i any) and unload them if the user chooses not to. */ -/* ARGSUSED */ int tagsvisit(int f, int n) { char fname[NFILEN], *bufp, *temp; - struct stat sb; - + if (getbufcwd(fname, sizeof(fname)) == FALSE) fname[0] = '\0'; - + if (strlcat(fname, DEFAULTFN, sizeof(fname)) >= sizeof(fname)) { dobeep(); ewprintf("Filename too long"); return (FALSE); } - + bufp = eread("Visit tags table (default %s): ", fname, NFILEN, EFFILE | EFCR | EFNEW | EFDEF, DEFAULTFN); if (bufp == NULL) return (ABORT); - if (stat(bufp, &sb) == -1) { - dobeep(); - ewprintf("stat: %s", strerror(errno)); - return (FALSE); - } else if (S_ISREG(sb.st_mode) == 0) { - dobeep(); - ewprintf("Not a regular file"); - return (FALSE); - } else if (access(bufp, R_OK) == -1) { - dobeep(); - ewprintf("Cannot access file %s", bufp); - return (FALSE); - } - - if (tagsfn == NULL) { - if (bufp[0] == '\0') { - if ((tagsfn = strdup(fname)) == NULL) { - dobeep(); - ewprintf("Out of memory"); - return (FALSE); - } - } else { - /* bufp points to local variable, so duplicate. */ - if ((tagsfn = strdup(bufp)) == NULL) { - dobeep(); - ewprintf("Out of memory"); - return (FALSE); - } - } - } else { - if ((temp = strdup(bufp)) == NULL) { - dobeep(); - ewprintf("Out of memory"); - return (FALSE); - } - free(tagsfn); - tagsfn = temp; + if (!RB_EMPTY(&tags)) { if (eyorn("Keep current list of tags table also") == FALSE) { ewprintf("Starting a new list of tags table"); unloadtags(); } - loaded = FALSE; } - return (TRUE); + + temp = bufp; + if (temp[0] == '\0') + temp = fname; + + return (loadtags(temp)); } /* @@ -171,24 +133,16 @@ findtag(int f, int n) tok = dtok; else tok = utok; - + if (tok[0] == '\0') { dobeep(); ewprintf("There is no default tag"); return (FALSE); } - - if (tagsfn == NULL) + + if (RB_EMPTY(&tags)) if ((ret = tagsvisit(f, n)) != TRUE) return (ret); - if (!loaded) { - if (loadtags(tagsfn) == FALSE) { - free(tagsfn); - tagsfn = NULL; - return (FALSE); - } - loaded = TRUE; - } return pushtag(tok); } @@ -199,7 +153,7 @@ void unloadtags(void) { struct ctag *var, *nxt; - + for (var = RB_MIN(tagtree, &tags); var != NULL; var = nxt) { nxt = RB_NEXT(tagtree, &tags, var); RB_REMOVE(tagtree, &tags, var); @@ -210,11 +164,10 @@ unloadtags(void) } /* - * Lookup tag passed in tree and if found, push current location and + * Lookup tag passed in tree and if found, push current location and * buffername onto stack, load the file with tag definition into a new * buffer and position dot at the pattern. */ -/*ARGSUSED */ int pushtag(char *tok) { @@ -222,10 +175,10 @@ pushtag(char *tok) struct tagpos *s; char bname[NFILEN]; int doto, dotline; - + if ((res = searchtag(tok)) == NULL) return (FALSE); - + doto = curwp->w_doto; dotline = curwp->w_dotline; /* record absolute filenames. Fixes issues when mg's cwd is not the @@ -240,11 +193,11 @@ pushtag(char *tok) dobeep(); ewprintf("filename too long"); return (FALSE); - } + } if (loadbuffer(res->fname) == FALSE) return (FALSE); - + if (searchpat(res->pat) == TRUE) { if ((s = malloc(sizeof(struct tagpos))) == NULL) { dobeep(); @@ -273,13 +226,12 @@ pushtag(char *tok) /* * If tag stack is not empty pop stack and jump to recorded buffer, dot. */ -/* ARGSUSED */ int poptag(int f, int n) { struct line *dotp; struct tagpos *s; - + if (SLIST_EMPTY(&shead)) { dobeep(); ewprintf("No previous location for find-tag invocation"); @@ -287,19 +239,22 @@ poptag(int f, int n) } s = SLIST_FIRST(&shead); SLIST_REMOVE_HEAD(&shead, entry); - if (loadbuffer(s->bname) == FALSE) + if (loadbuffer(s->bname) == FALSE) { + free(s->bname); + free(s); return (FALSE); + } curwp->w_dotline = s->dotline; curwp->w_doto = s->doto; - + /* storing of dotp in tagpos wouldn't work out in cases when * that buffer is killed by user(dangling pointer). Explicitly - * traverse till dotline for correct handling. + * traverse till dotline for correct handling. */ dotp = curwp->w_bufp->b_headp; while (s->dotline--) dotp = dotp->l_fp; - + curwp->w_dotp = dotp; free(s->bname); free(s); @@ -307,20 +262,33 @@ poptag(int f, int n) } /* - * Parse the tags file and construct the tags tree. Remove escape + * Parse the tags file and construct the tags tree. Remove escape * characters while parsing the file. */ int loadtags(const char *fn) { + struct stat sb; char *l; FILE *fd; - + if ((fd = fopen(fn, "r")) == NULL) { dobeep(); ewprintf("Unable to open tags file: %s", fn); return (FALSE); } + if (fstat(fileno(fd), &sb) == -1) { + dobeep(); + ewprintf("fstat: %s", strerror(errno)); + fclose(fd); + return (FALSE); + } + if (!S_ISREG(sb.st_mode)) { + dobeep(); + ewprintf("Not a regular file"); + fclose(fd); + return (FALSE); + } while ((l = fparseln(fd, NULL, NULL, "\\\\\0", FPARSELN_UNESCCONT | FPARSELN_UNESCREST)) != NULL) { if (addctag(l) == FALSE) { @@ -338,8 +306,8 @@ loadtags(const char *fn) void closetags(void) { - struct tagpos *s; - + struct tagpos *s; + while (!SLIST_EMPTY(&shead)) { s = SLIST_FIRST(&shead); SLIST_REMOVE_HEAD(&shead, entry); @@ -347,30 +315,29 @@ closetags(void) free(s); } unloadtags(); - free(tagsfn); } /* * Strip away any special characters in pattern. * The pattern in ctags isn't a true regular expression. Its of the form - * /^xxx$/ or ?^xxx$? and in some cases the "$" would be missing. Strip + * /^xxx$/ or ?^xxx$? and in some cases the "$" would be missing. Strip * the leading and trailing special characters so the pattern matching - * would be a simple string compare. Escape character is taken care by + * would be a simple string compare. Escape character is taken care by * fparseln. */ char * strip(char *s, size_t len) { - /* first strip trailing special chars */ + /* first strip trailing special chars */ s[len - 1] = '\0'; if (s[len - 2] == '$') s[len - 2] = '\0'; - + /* then strip leading special chars */ s++; if (*s == '^') s++; - + return s; } @@ -380,17 +347,18 @@ strip(char *s, size_t len) * l, and can be freed during cleanup. */ int -addctag(char *l) +addctag(char *s) { - struct ctag *t; - + struct ctag *t = NULL; + char *l; + if ((t = malloc(sizeof(struct ctag))) == NULL) { dobeep(); ewprintf("Out of memory"); - return (FALSE); + goto cleanup; } - t->tag = l; - if ((l = strchr(l, '\t')) == NULL) + t->tag = s; + if ((l = strchr(s, '\t')) == NULL) goto cleanup; *l++ = '\0'; t->fname = l; @@ -400,11 +368,14 @@ addctag(char *l) if (*l == '\0') goto cleanup; t->pat = strip(l, strlen(l)); - RB_INSERT(tagtree, &tags, t); + if (RB_INSERT(tagtree, &tags, t) != NULL) { + free(t); + free(s); + } return (TRUE); cleanup: free(t); - free(l); + free(s); return (FALSE); } @@ -437,7 +408,7 @@ searchpat(char *s_pat) } /* - * Return TRUE if dot is at beginning of a word or at beginning + * Return TRUE if dot is at beginning of a word or at beginning * of line, else FALSE. */ int @@ -460,46 +431,46 @@ curtoken(int f, int n, char *token) struct line *odotp; int odoto, tdoto, odotline, size, r; char c; - + /* Underscore character is to be treated as "inword" while * processing tokens unlike mg's default word traversal. Save - * and restore it's cinfo value so that tag matching works for + * and restore its cinfo value so that tag matching works for * identifier with underscore. */ c = cinfo['_']; cinfo['_'] = _MG_W; - + odotp = curwp->w_dotp; odoto = curwp->w_doto; odotline = curwp->w_dotline; - - /* Move backword unless we are at the beginning of a word or at + + /* Move backward unless we are at the beginning of a word or at * beginning of line. */ if (!atbow()) if ((r = backword(f, n)) == FALSE) goto cleanup; - + tdoto = curwp->w_doto; if ((r = forwword(f, n)) == FALSE) goto cleanup; - + /* strip away leading whitespace if any like emacs. */ - while (ltext(curwp->w_dotp) && + while (ltext(curwp->w_dotp) && isspace(lgetc(curwp->w_dotp, tdoto))) tdoto++; size = curwp->w_doto - tdoto; - if (size <= 0 || size >= MAX_TOKEN || + if (size <= 0 || size >= MAX_TOKEN || ltext(curwp->w_dotp) == NULL) { r = FALSE; goto cleanup; - } + } strncpy(token, ltext(curwp->w_dotp) + tdoto, size); token[size] = '\0'; r = TRUE; - + cleanup: cinfo['_'] = c; curwp->w_dotp = odotp; @@ -529,7 +500,7 @@ searchtag(char *tok) * This is equivalent to filevisit from file.c. * Look around to see if we can find the file in another buffer; if we * can't find it, create a new buffer, read in the text, and switch to - * the new buffer. *scratch*, *grep*, *compile* needs to be handled + * the new buffer. *scratch*, *grep*, *compile* needs to be handled * differently from other buffers which have "filenames". */ int @@ -546,7 +517,7 @@ loadbuffer(char *bname) } else { return (FALSE); } - } else { + } else { if ((adjf = adjustname(bname, TRUE)) == NULL) return (FALSE); if ((bufp = findbuffer(adjf)) == NULL) diff --git a/tty.c b/tty.c index 6522a24..091a439 100644 --- a/tty.c +++ b/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.39 2021/03/20 09:00:49 lum Exp $ */ +/* $OpenBSD: tty.c,v 1.40 2023/03/08 04:43:11 guenther Exp $ */ /* This file is in the public domain. */ @@ -33,7 +33,7 @@ #include #include #include -#include +#include "terminfo_term.h" #include #include "def.h" @@ -51,7 +51,6 @@ int tceeol; int tcinsl; int tcdell; -/* ARGSUSED */ static void winchhandler(int sig) { @@ -440,7 +439,6 @@ ttresize(void) /* * fake char output for charcost() */ -/* ARGSUSED */ static int fakec(int c) { diff --git a/ttyio.c b/ttyio.c index 54ddd8e..4dcb31b 100644 --- a/ttyio.c +++ b/ttyio.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include "terminfo_term.h" #include #include diff --git a/ttykbd.c b/ttykbd.c index defb736..569697f 100644 --- a/ttykbd.c +++ b/ttykbd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ttykbd.c,v 1.20 2021/02/23 08:10:51 lum Exp $ */ +/* $OpenBSD: ttykbd.c,v 1.22 2023/03/30 19:00:02 op Exp $ */ /* This file is in the public domain. */ @@ -12,7 +12,7 @@ #include #include #include -#include +#include "terminfo_term.h" #include "def.h" #include "kbd.h" @@ -31,7 +31,8 @@ char *keystrings[] = {NULL}; void ttykeymapinit(void) { - char *cp; + char *cp, file[NFILEN]; + FILE *ffp; /* Bind keypad function keys. */ if (key_left) @@ -57,10 +58,11 @@ ttykeymapinit(void) if (key_dc) dobindkey(fundamental_map, "delete-char", key_dc); - if ((cp = getenv("TERM"))) { - if (((cp = startupfile(cp, NULL)) != NULL) && - (load(cp) != TRUE)) + if ((cp = getenv("TERM")) != NULL && + (ffp = startupfile(cp, NULL, file, sizeof(file))) != NULL) { + if (load(ffp, file) != TRUE) ewprintf("Error reading key initialization file"); + (void)ffclose(ffp, NULL); } if (keypad_xmit) /* turn on keypad */ @@ -77,4 +79,3 @@ ttykeymaptidy(void) /* turn off keypad */ putpad(keypad_local, 1); } - diff --git a/tutorial b/tutorial index 6897b1c..1e6e553 100644 --- a/tutorial +++ b/tutorial @@ -254,7 +254,7 @@ in the bottom of your screen. In general, it is a good idea to save quite often. When you save a file, mg saves a backup of the file with a tilde (~) character at the end. -If you decide to open a directory instead of a file, mg will transistion into a +If you decide to open a directory instead of a file, mg will transition into a mode called dired. Dired fills a buffer with the contents of the selected directory, one file or sub-directory's details per line. Some basic file management functions can be performed on the files and sub-directories in the diff --git a/undo.c b/undo.c index 6e87d9c..8f427de 100644 --- a/undo.c +++ b/undo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: undo.c,v 1.58 2016/09/05 08:10:58 lum Exp $ */ +/* $OpenBSD: undo.c,v 1.59 2023/03/08 04:43:11 guenther Exp $ */ /* * This file is in the public domain */ @@ -381,7 +381,6 @@ undo_add_change(struct line *lp, int offset, int size) /* * Show the undo records for the current buffer in a new buffer. */ -/* ARGSUSED */ int undo_dump(int f, int n) { @@ -479,7 +478,6 @@ undo_dump(int f, int n) * two undo actions, we make it point back at the topmost record. This is * how we handle redoing. */ -/* ARGSUSED */ int undo(int f, int n) { diff --git a/util.c b/util.c index 4d38284..dd42085 100644 --- a/util.c +++ b/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.43 2021/03/01 10:51:14 lum Exp $ */ +/* $OpenBSD: util.c,v 1.50 2023/04/28 10:02:03 op Exp $ */ /* This file is in the public domain. */ @@ -16,6 +16,18 @@ #include "def.h" +int doindent(int); + +/* + * Compute next tab stop, with `col' being the a column number and + * `tabw' the tab width. + */ +int +ntabstop(int col, int tabw) +{ + return (((col + tabw) / tabw) * tabw); +} + /* * Display a bunch of useful information about the current location of dot. * The character under the cursor (in octal), the current line, row, and @@ -27,7 +39,6 @@ * position display; it does not truncate just because the screen does. * This is normally bound to "C-x =". */ -/* ARGSUSED */ int showcpos(int f, int n) { @@ -101,13 +112,8 @@ getcolpos(struct mgwin *wp) for (i = 0; i < wp->w_doto; ++i) { c = lgetc(wp->w_dotp, i); - if (c == '\t' -#ifdef NOTAB - && !(wp->w_bufp->b_flag & BFNOTAB) -#endif /* NOTAB */ - ) { - col |= 0x07; - col++; + if (c == '\t') { + col = ntabstop(col, wp->w_bufp->b_tabw); } else if (ISCTRL(c) != FALSE) col += 2; else if (isprint(c)) { @@ -126,7 +132,6 @@ getcolpos(struct mgwin *wp) * Normally bound to "C-t". This always works within a line, so "WFEDIT" * is good enough. */ -/* ARGSUSED */ int twiddle(int f, int n) { @@ -180,7 +185,6 @@ twiddle(int f, int n) * subcommand processors. They even handle the looping. Normally this * is bound to "C-o". */ -/* ARGSUSED */ int openline(int f, int n) { @@ -208,7 +212,6 @@ openline(int f, int n) /* * Insert a newline. */ -/* ARGSUSED */ int enewline(int f, int n) { @@ -232,7 +235,6 @@ enewline(int f, int n) * the line. Normally this command is bound to "C-x C-o". Any argument is * ignored. */ -/* ARGSUSED */ int deblank(int f, int n) { @@ -269,7 +271,6 @@ justone(int f, int n) /* * Delete any whitespace around dot. */ -/* ARGSUSED */ int delwhite(int f, int n) { @@ -342,17 +343,32 @@ deltrailwhite(int f, int n) return (TRUE); } +/* + * Raw indent routine. Use spaces and tabs to fill the given number of + * cols, but respect no-tab-mode. + */ +int +doindent(int cols) +{ + int n; + if (curbp->b_flag & BFNOTAB) + return (linsert(cols, ' ')); + if ((n = cols / 8) != 0 && linsert(n, '\t') == FALSE) + return (FALSE); + if ((n = cols % 8) != 0 && linsert(n, ' ') == FALSE) + return (FALSE); + return (TRUE); +} /* * Insert a newline, then enough tabs and spaces to duplicate the indentation - * of the previous line. Assumes tabs are every eight characters. Quite - * simple. Figure out the indentation of the current line. Insert a newline - * by calling the standard routine. Insert the indentation by inserting the + * of the previous line, respecting no-tab-mode and the buffer tab width. + * Figure out the indentation of the current line. Insert a newline by + * calling the standard routine. Insert the indentation by inserting the * right number of tabs and spaces. Return TRUE if all ok. Return FALSE if * one of the subcommands failed. Normally bound to "C-m". */ -/* ARGSUSED */ int lfindent(int f, int n) { @@ -370,15 +386,13 @@ lfindent(int f, int n) if (c != ' ' && c != '\t') break; if (c == '\t') - nicol |= 0x07; - ++nicol; + nicol = ntabstop(nicol, curwp->w_bufp->b_tabw); + else + ++nicol; } - if (lnewline() == FALSE || (( -#ifdef NOTAB - curbp->b_flag & BFNOTAB) ? linsert(nicol, ' ') == FALSE : ( -#endif /* NOTAB */ - ((i = nicol / 8) != 0 && linsert(i, '\t') == FALSE) || - ((i = nicol % 8) != 0 && linsert(i, ' ') == FALSE)))) { + (void)delwhite(FFRAND, 1); + + if (lnewline() == FALSE || doindent(nicol) == FALSE) { s = FALSE; break; } @@ -395,7 +409,7 @@ lfindent(int f, int n) int indent(int f, int n) { - int soff, i; + int soff; if (n < 0) return (FALSE); @@ -409,12 +423,7 @@ indent(int f, int n) /* insert appropriate whitespace */ soff = curwp->w_doto; (void)gotobol(FFRAND, 1); - if ( -#ifdef NOTAB - (curbp->b_flag & BFNOTAB) ? linsert(n, ' ') == FALSE : -#endif /* NOTAB */ - (((i = n / 8) != 0 && linsert(i, '\t') == FALSE) || - ((i = n % 8) != 0 && linsert(i, ' ') == FALSE))) + if (doindent(n) == FALSE) return (FALSE); forwchar(FFRAND, soff); @@ -429,7 +438,6 @@ indent(int f, int n) * If any argument is present, it kills rather than deletes, to prevent loss * of text if typed with a big argument. Normally bound to "C-d". */ -/* ARGSUSED */ int forwdel(int f, int n) { @@ -451,7 +459,6 @@ forwdel(int f, int n) * other functions. Just move the cursor back, and delete forwards. Like * delete forward, this actually does a kill if presented with an argument. */ -/* ARGSUSED */ int backdel(int f, int n) { @@ -472,18 +479,21 @@ backdel(int f, int n) return (s); } -#ifdef NOTAB -/* ARGSUSED */ int space_to_tabstop(int f, int n) { + int col, target; + if (n < 0) return (FALSE); if (n == 0) return (TRUE); - return (linsert((n << 3) - (curwp->w_doto & 7), ' ')); + + col = target = getcolpos(curwp); + while (n-- > 0) + target = ntabstop(target, curbp->b_tabw); + return (linsert(target - col, ' ')); } -#endif /* NOTAB */ /* * Move the dot to the first non-whitespace character of the current line. diff --git a/version.c b/version.c index a917882..3604829 100644 --- a/version.c +++ b/version.c @@ -1,4 +1,4 @@ -/* $OpenBSD: version.c,v 1.10 2015/03/19 21:22:15 bcallah Exp $ */ +/* $OpenBSD: version.c,v 1.11 2023/03/08 04:43:11 guenther Exp $ */ /* This file is in the public domain. */ @@ -13,13 +13,12 @@ #include "def.h" -const char version[] = "Mg 2a portable 7.0"; +const char version[] = "Mg 2a portable 7.3"; /* * Display the version. All this does * is copy the version string onto the echo line. */ -/* ARGSUSED */ int showversion(int f, int n) { diff --git a/window.c b/window.c index ee61ca5..e51c9f3 100644 --- a/window.c +++ b/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.36 2015/11/18 18:21:06 jasper Exp $ */ +/* $OpenBSD: window.c,v 1.37 2023/03/08 04:43:11 guenther Exp $ */ /* This file is in the public domain. */ @@ -42,7 +42,6 @@ new_window(struct buffer *bp) * bottom. If it is 0 the window is centered (this is what the standard * redisplay code does). */ -/* ARGSUSED */ int reposition(int f, int n) { @@ -72,7 +71,6 @@ redraw(int f, int n) return (do_redraw(f, n, FALSE)); } -/* ARGSUSED */ int do_redraw(int f, int n, int force) { @@ -108,7 +106,6 @@ do_redraw(int f, int n, int force) * window. There are no real errors, although the command does nothing if * there is only 1 window on the screen. */ -/* ARGSUSED */ int nextwind(int f, int n) { @@ -127,7 +124,6 @@ nextwind(int f, int n) * current window. There are no errors, although the command does not do * a lot if there is only 1 window. */ -/* ARGSUSED */ int prevwind(int f, int n) { @@ -151,7 +147,6 @@ prevwind(int f, int n) * structures right if the destruction of a window makes a buffer become * undisplayed. */ -/* ARGSUSED */ int onlywind(int f, int n) { @@ -206,7 +201,6 @@ onlywind(int f, int n) * structure for the new window. * If called with a FFOTHARG, flags on the new window are set to 'n'. */ -/* ARGSUSED */ int splitwind(int f, int n) { @@ -297,7 +291,6 @@ splitwind(int f, int n) * to do all the hard work. You don't just set "force reframe" because dot * would move. */ -/* ARGSUSED */ int enlargewind(int f, int n) { @@ -404,7 +397,6 @@ shrinkwind(int f, int n) * Delete current window. Call shrink-window to do the screen updating, then * throw away the window. */ -/* ARGSUSED */ int delwind(int f, int n) { diff --git a/word.c b/word.c index abff762..2409bb4 100644 --- a/word.c +++ b/word.c @@ -1,4 +1,4 @@ -/* $OpenBSD: word.c,v 1.19 2015/12/30 20:51:51 lum Exp $ */ +/* $OpenBSD: word.c,v 1.21 2023/03/08 04:43:11 guenther Exp $ */ /* This file is in the public domain. */ @@ -24,7 +24,6 @@ int grabword(char **); * Move the cursor backward by "n" words. All of the details of motion are * performed by the "backchar" and "forwchar" routines. */ -/* ARGSUSED */ int backword(int f, int n) { @@ -49,7 +48,6 @@ backword(int f, int n) * Move the cursor forward by the specified number of words. All of the * motion is done by "forwchar". */ -/* ARGSUSED */ int forwword(int f, int n) { @@ -69,8 +67,8 @@ forwword(int f, int n) } /* - * Transpose 2 words. - * The function below is artifically restricted to only a maximum of 1 iteration + * Transpose 2 words. + * The function below is artificially restricted to only a maximum of 1 iteration * at the moment because the 'undo' functionality within mg needs amended for * multiple movements of point, backwards and forwards. */ @@ -227,7 +225,6 @@ grabword(char **word) * Move the cursor forward by the specified number of words. As you move, * convert any characters to upper case. */ -/* ARGSUSED */ int upperword(int f, int n) { @@ -270,7 +267,6 @@ upperword(int f, int n) * Move the cursor forward by the specified number of words. As you move * convert characters to lower case. */ -/* ARGSUSED */ int lowerword(int f, int n) { @@ -314,7 +310,6 @@ lowerword(int f, int n) * characters to lower case. Error if you try to move past the end of the * buffer. */ -/* ARGSUSED */ int capword(int f, int n) { @@ -393,7 +388,6 @@ countfword() /* * Kill forward by "n" words. */ -/* ARGSUSED */ int delfword(int f, int n) { @@ -450,7 +444,6 @@ delfword(int f, int n) * the first call to "backchar" special, but decided that that would just be * weird. Normally this is bound to "M-Rubout" and to "M-Backspace". */ -/* ARGSUSED */ int delbword(int f, int n) { diff --git a/yank.c b/yank.c index 2ada0ed..c215efe 100644 --- a/yank.c +++ b/yank.c @@ -1,4 +1,4 @@ -/* $OpenBSD: yank.c,v 1.15 2021/03/01 10:51:14 lum Exp $ */ +/* $OpenBSD: yank.c,v 1.16 2023/03/08 04:43:11 guenther Exp $ */ /* This file is in the public domain. */ @@ -148,7 +148,6 @@ kchunk(char *cp1, RSIZE chunk, int kflag) * it kills any text before dot on the current line, then it kills back * abs(arg) lines. */ -/* ARGSUSED */ int killline(int f, int n) { @@ -220,7 +219,6 @@ killline(int f, int n) * bug associated with a yank when dot is on the top line of the window * (nothing moves, because all of the new text landed off screen). */ -/* ARGSUSED */ int yank(int f, int n) {