History log of /openbsd-current/usr.bin/mg/def.h
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.181 21-May-2024 jsg

remove prototypes with no matching function and externs with no var
partly checked by millert@


Revision tags: OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.180 21-Apr-2023 op

mg: allow to change the tab width

This makes the tab width customizable per-buffer. The new function
`set-tab-width' changes it for the current buffer or the default value
for new buffers if called with a prefix argument (or from the startup
file.)

The default tab width is still 8 column.

Together with the newly resurrected no-tab-mode, allows to use mg for a
variety of programming languages and coding styles.

Note that it's not possible to call set-tab-width with auto-execute in
the startup file due to limitations in how auto-execute and the parser
work.

ok tb@


# 1.179 17-Apr-2023 op

resurrect mg' no-tab-mode

It's a mode that makes mg insert spaces up to the next tab stop upon
pressing TAB, along with the various tweaks needed in other places so
for e.g. auto-indent-mode also uses spaces.

This is not just an unifdef NOTAB: even under no-tab-mode mg should
consider literal TAB characters wide up to the next tab stop, while the
hidden code considered hard tabs to be just control character (i.e. ^I)
with width of two columns. I'm also introducing the helper function
doindent() in utils.c to de-obfuscate the insertion of tabs/spaces until
the given column.

ok tb@


# 1.178 30-Mar-2023 op

don't access(conffile)

This removes a few access(2) calls in the configuration file handling.
startupfile() now opens and return the file and to avoid surprises it
also uses a caller-provided buffer to store the filename. This also
removes the extra adjustpath() that load() did: it has been moved to
evalfile() only.

with help, fixes and ok tb@


Revision tags: OPENBSD_7_3_BASE
# 1.177 20-Oct-2022 op

add zap-to-char and zap-up-to-char; bind zap-to-char to M-z.

ok florian@


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.176 06-May-2021 lum

Add the line number of an error to error messages.


# 1.175 06-May-2021 lum

Add a number to parameters for ewprintf() via beeping.


# 1.174 03-May-2021 lum

When parsing a variable value within double quotes, allow an escaped
\" to be accomodated for. Also, move the variable structure to be
global in scope within mg.


# 1.173 22-Apr-2021 lum

Add a non-interactive version of query-replace-regexp function called
replace-regexp. Unfortunately query-replace-regexp can't be used in a
startup file.


# 1.172 20-Apr-2021 lum

Add 'dired-jump' from Philip K. <philip@warpmail.net> sent to tech@
over a year ago. Comments and testing from gkoehler@. Thanks to both.
Also, some modifications from me.


Revision tags: OPENBSD_6_9_BASE
# 1.171 25-Mar-2021 lum

Use length of line to indicate end of characters to process in
foundparen(). No intended functional change. regress tests ok and they
all use excline().


# 1.170 21-Mar-2021 lum

Add quoted strings capability in list values, no special chars
detection in between them though. Add limitation to characters
allowed in symbol names, equivalent to mg function names (A-Za-z-),
quite restrictive but can grow of course. If value is not quoted and
is not a variable, give an error.


# 1.169 20-Mar-2021 lum

Add a 'batch' mode to mg via the '-b' command line option which will
initialise a pty, run the specified file of mg commands and then exit.

This is to facilitate mg fitting into the OpenBSD regress test
framework and be able to run via a cron job.


# 1.168 01-Mar-2021 lum

Put the hardcoded '\n' character which is found throughout mg into a
buffer specific variable. The diff should not produce any behavourial
changes in mg.


# 1.167 23-Feb-2021 lum

Allow the user to specify a path to the mg startup file on the command line.


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.166 09-Feb-2020 florian

Do not define variables in def.h since this will lead to duplicate definitions
in every source file that includes def.h
Found by gcc10 in portable in gentoo and fedora.
Patch from Ulrich Mueller (ulm AT gentoo.org) via Han Boetes, thanks!
Ok tb


Revision tags: OPENBSD_6_6_BASE
# 1.165 18-Jul-2019 lum

Make indentation consistent. This has been bugging me for a while now.


# 1.164 18-Jul-2019 lum

Add some more basic interpreter functionality to mg. Needs a lot more
work, including a proper parser.


# 1.163 17-Jul-2019 lum

Add two dobeep functions to make calls to the system bell require
fewer lines. While working in extend.c change relevant calls to
dobeep.


# 1.162 03-Jul-2019 lum

selfinsert() can't be called directly from a startup file or by
'eval-current-buffer' since it is by design, meant to be called interactively
as characters are typed in a buffer. ask_selfinsert() allows selfinsert() to
be used by excline(). Having ask_selfinsert() helps with regression testing.
No manual page entry since use case is a bit obscure. See 'insert' command.


# 1.161 02-Jul-2019 lum

I totally forgot about the instance where blink-and-insert can be
called from the mg startup file. My previous diff broke that instance.
So this diff reverts my change but adds a man page line to
blink-and-insert in case someone should try to use it interactively,
again. Also, should anyone ever want to add an interactive version of
blink-and-insert in the future, the code is there. And the code could
be useful in another, related instance.


# 1.160 26-Jun-2019 lum

This diff makes blink-and-insert do as the man page says it should do.
If you do 'M-x blink-and-insert', you are asked for a character. mg
will then insert it at the current cursor position and then search
backwards for a corresponding match.


# 1.159 22-Jun-2019 lum

Tidy up the comments:
1. two spelling mistakes.
2. change references to keystrokes, same as man page (UP-low).
3. update a filename reference to reality.


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.180 21-Apr-2023 op

mg: allow to change the tab width

This makes the tab width customizable per-buffer. The new function
`set-tab-width' changes it for the current buffer or the default value
for new buffers if called with a prefix argument (or from the startup
file.)

The default tab width is still 8 column.

Together with the newly resurrected no-tab-mode, allows to use mg for a
variety of programming languages and coding styles.

Note that it's not possible to call set-tab-width with auto-execute in
the startup file due to limitations in how auto-execute and the parser
work.

ok tb@


# 1.179 17-Apr-2023 op

resurrect mg' no-tab-mode

It's a mode that makes mg insert spaces up to the next tab stop upon
pressing TAB, along with the various tweaks needed in other places so
for e.g. auto-indent-mode also uses spaces.

This is not just an unifdef NOTAB: even under no-tab-mode mg should
consider literal TAB characters wide up to the next tab stop, while the
hidden code considered hard tabs to be just control character (i.e. ^I)
with width of two columns. I'm also introducing the helper function
doindent() in utils.c to de-obfuscate the insertion of tabs/spaces until
the given column.

ok tb@


# 1.178 30-Mar-2023 op

don't access(conffile)

This removes a few access(2) calls in the configuration file handling.
startupfile() now opens and return the file and to avoid surprises it
also uses a caller-provided buffer to store the filename. This also
removes the extra adjustpath() that load() did: it has been moved to
evalfile() only.

with help, fixes and ok tb@


Revision tags: OPENBSD_7_3_BASE
# 1.177 20-Oct-2022 op

add zap-to-char and zap-up-to-char; bind zap-to-char to M-z.

ok florian@


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.176 06-May-2021 lum

Add the line number of an error to error messages.


# 1.175 06-May-2021 lum

Add a number to parameters for ewprintf() via beeping.


# 1.174 03-May-2021 lum

When parsing a variable value within double quotes, allow an escaped
\" to be accomodated for. Also, move the variable structure to be
global in scope within mg.


# 1.173 22-Apr-2021 lum

Add a non-interactive version of query-replace-regexp function called
replace-regexp. Unfortunately query-replace-regexp can't be used in a
startup file.


# 1.172 20-Apr-2021 lum

Add 'dired-jump' from Philip K. <philip@warpmail.net> sent to tech@
over a year ago. Comments and testing from gkoehler@. Thanks to both.
Also, some modifications from me.


Revision tags: OPENBSD_6_9_BASE
# 1.171 25-Mar-2021 lum

Use length of line to indicate end of characters to process in
foundparen(). No intended functional change. regress tests ok and they
all use excline().


# 1.170 21-Mar-2021 lum

Add quoted strings capability in list values, no special chars
detection in between them though. Add limitation to characters
allowed in symbol names, equivalent to mg function names (A-Za-z-),
quite restrictive but can grow of course. If value is not quoted and
is not a variable, give an error.


# 1.169 20-Mar-2021 lum

Add a 'batch' mode to mg via the '-b' command line option which will
initialise a pty, run the specified file of mg commands and then exit.

This is to facilitate mg fitting into the OpenBSD regress test
framework and be able to run via a cron job.


# 1.168 01-Mar-2021 lum

Put the hardcoded '\n' character which is found throughout mg into a
buffer specific variable. The diff should not produce any behavourial
changes in mg.


# 1.167 23-Feb-2021 lum

Allow the user to specify a path to the mg startup file on the command line.


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.166 09-Feb-2020 florian

Do not define variables in def.h since this will lead to duplicate definitions
in every source file that includes def.h
Found by gcc10 in portable in gentoo and fedora.
Patch from Ulrich Mueller (ulm AT gentoo.org) via Han Boetes, thanks!
Ok tb


Revision tags: OPENBSD_6_6_BASE
# 1.165 18-Jul-2019 lum

Make indentation consistent. This has been bugging me for a while now.


# 1.164 18-Jul-2019 lum

Add some more basic interpreter functionality to mg. Needs a lot more
work, including a proper parser.


# 1.163 17-Jul-2019 lum

Add two dobeep functions to make calls to the system bell require
fewer lines. While working in extend.c change relevant calls to
dobeep.


# 1.162 03-Jul-2019 lum

selfinsert() can't be called directly from a startup file or by
'eval-current-buffer' since it is by design, meant to be called interactively
as characters are typed in a buffer. ask_selfinsert() allows selfinsert() to
be used by excline(). Having ask_selfinsert() helps with regression testing.
No manual page entry since use case is a bit obscure. See 'insert' command.


# 1.161 02-Jul-2019 lum

I totally forgot about the instance where blink-and-insert can be
called from the mg startup file. My previous diff broke that instance.
So this diff reverts my change but adds a man page line to
blink-and-insert in case someone should try to use it interactively,
again. Also, should anyone ever want to add an interactive version of
blink-and-insert in the future, the code is there. And the code could
be useful in another, related instance.


# 1.160 26-Jun-2019 lum

This diff makes blink-and-insert do as the man page says it should do.
If you do 'M-x blink-and-insert', you are asked for a character. mg
will then insert it at the current cursor position and then search
backwards for a corresponding match.


# 1.159 22-Jun-2019 lum

Tidy up the comments:
1. two spelling mistakes.
2. change references to keystrokes, same as man page (UP-low).
3. update a filename reference to reality.


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.179 17-Apr-2023 op

resurrect mg' no-tab-mode

It's a mode that makes mg insert spaces up to the next tab stop upon
pressing TAB, along with the various tweaks needed in other places so
for e.g. auto-indent-mode also uses spaces.

This is not just an unifdef NOTAB: even under no-tab-mode mg should
consider literal TAB characters wide up to the next tab stop, while the
hidden code considered hard tabs to be just control character (i.e. ^I)
with width of two columns. I'm also introducing the helper function
doindent() in utils.c to de-obfuscate the insertion of tabs/spaces until
the given column.

ok tb@


# 1.178 30-Mar-2023 op

don't access(conffile)

This removes a few access(2) calls in the configuration file handling.
startupfile() now opens and return the file and to avoid surprises it
also uses a caller-provided buffer to store the filename. This also
removes the extra adjustpath() that load() did: it has been moved to
evalfile() only.

with help, fixes and ok tb@


Revision tags: OPENBSD_7_3_BASE
# 1.177 20-Oct-2022 op

add zap-to-char and zap-up-to-char; bind zap-to-char to M-z.

ok florian@


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.176 06-May-2021 lum

Add the line number of an error to error messages.


# 1.175 06-May-2021 lum

Add a number to parameters for ewprintf() via beeping.


# 1.174 03-May-2021 lum

When parsing a variable value within double quotes, allow an escaped
\" to be accomodated for. Also, move the variable structure to be
global in scope within mg.


# 1.173 22-Apr-2021 lum

Add a non-interactive version of query-replace-regexp function called
replace-regexp. Unfortunately query-replace-regexp can't be used in a
startup file.


# 1.172 20-Apr-2021 lum

Add 'dired-jump' from Philip K. <philip@warpmail.net> sent to tech@
over a year ago. Comments and testing from gkoehler@. Thanks to both.
Also, some modifications from me.


Revision tags: OPENBSD_6_9_BASE
# 1.171 25-Mar-2021 lum

Use length of line to indicate end of characters to process in
foundparen(). No intended functional change. regress tests ok and they
all use excline().


# 1.170 21-Mar-2021 lum

Add quoted strings capability in list values, no special chars
detection in between them though. Add limitation to characters
allowed in symbol names, equivalent to mg function names (A-Za-z-),
quite restrictive but can grow of course. If value is not quoted and
is not a variable, give an error.


# 1.169 20-Mar-2021 lum

Add a 'batch' mode to mg via the '-b' command line option which will
initialise a pty, run the specified file of mg commands and then exit.

This is to facilitate mg fitting into the OpenBSD regress test
framework and be able to run via a cron job.


# 1.168 01-Mar-2021 lum

Put the hardcoded '\n' character which is found throughout mg into a
buffer specific variable. The diff should not produce any behavourial
changes in mg.


# 1.167 23-Feb-2021 lum

Allow the user to specify a path to the mg startup file on the command line.


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.166 09-Feb-2020 florian

Do not define variables in def.h since this will lead to duplicate definitions
in every source file that includes def.h
Found by gcc10 in portable in gentoo and fedora.
Patch from Ulrich Mueller (ulm AT gentoo.org) via Han Boetes, thanks!
Ok tb


Revision tags: OPENBSD_6_6_BASE
# 1.165 18-Jul-2019 lum

Make indentation consistent. This has been bugging me for a while now.


# 1.164 18-Jul-2019 lum

Add some more basic interpreter functionality to mg. Needs a lot more
work, including a proper parser.


# 1.163 17-Jul-2019 lum

Add two dobeep functions to make calls to the system bell require
fewer lines. While working in extend.c change relevant calls to
dobeep.


# 1.162 03-Jul-2019 lum

selfinsert() can't be called directly from a startup file or by
'eval-current-buffer' since it is by design, meant to be called interactively
as characters are typed in a buffer. ask_selfinsert() allows selfinsert() to
be used by excline(). Having ask_selfinsert() helps with regression testing.
No manual page entry since use case is a bit obscure. See 'insert' command.


# 1.161 02-Jul-2019 lum

I totally forgot about the instance where blink-and-insert can be
called from the mg startup file. My previous diff broke that instance.
So this diff reverts my change but adds a man page line to
blink-and-insert in case someone should try to use it interactively,
again. Also, should anyone ever want to add an interactive version of
blink-and-insert in the future, the code is there. And the code could
be useful in another, related instance.


# 1.160 26-Jun-2019 lum

This diff makes blink-and-insert do as the man page says it should do.
If you do 'M-x blink-and-insert', you are asked for a character. mg
will then insert it at the current cursor position and then search
backwards for a corresponding match.


# 1.159 22-Jun-2019 lum

Tidy up the comments:
1. two spelling mistakes.
2. change references to keystrokes, same as man page (UP-low).
3. update a filename reference to reality.


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.177 20-Oct-2022 op

add zap-to-char and zap-up-to-char; bind zap-to-char to M-z.

ok florian@


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.176 06-May-2021 lum

Add the line number of an error to error messages.


# 1.175 06-May-2021 lum

Add a number to parameters for ewprintf() via beeping.


# 1.174 03-May-2021 lum

When parsing a variable value within double quotes, allow an escaped
\" to be accomodated for. Also, move the variable structure to be
global in scope within mg.


# 1.173 22-Apr-2021 lum

Add a non-interactive version of query-replace-regexp function called
replace-regexp. Unfortunately query-replace-regexp can't be used in a
startup file.


# 1.172 20-Apr-2021 lum

Add 'dired-jump' from Philip K. <philip@warpmail.net> sent to tech@
over a year ago. Comments and testing from gkoehler@. Thanks to both.
Also, some modifications from me.


Revision tags: OPENBSD_6_9_BASE
# 1.171 25-Mar-2021 lum

Use length of line to indicate end of characters to process in
foundparen(). No intended functional change. regress tests ok and they
all use excline().


# 1.170 21-Mar-2021 lum

Add quoted strings capability in list values, no special chars
detection in between them though. Add limitation to characters
allowed in symbol names, equivalent to mg function names (A-Za-z-),
quite restrictive but can grow of course. If value is not quoted and
is not a variable, give an error.


# 1.169 20-Mar-2021 lum

Add a 'batch' mode to mg via the '-b' command line option which will
initialise a pty, run the specified file of mg commands and then exit.

This is to facilitate mg fitting into the OpenBSD regress test
framework and be able to run via a cron job.


# 1.168 01-Mar-2021 lum

Put the hardcoded '\n' character which is found throughout mg into a
buffer specific variable. The diff should not produce any behavourial
changes in mg.


# 1.167 23-Feb-2021 lum

Allow the user to specify a path to the mg startup file on the command line.


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.166 09-Feb-2020 florian

Do not define variables in def.h since this will lead to duplicate definitions
in every source file that includes def.h
Found by gcc10 in portable in gentoo and fedora.
Patch from Ulrich Mueller (ulm AT gentoo.org) via Han Boetes, thanks!
Ok tb


Revision tags: OPENBSD_6_6_BASE
# 1.165 18-Jul-2019 lum

Make indentation consistent. This has been bugging me for a while now.


# 1.164 18-Jul-2019 lum

Add some more basic interpreter functionality to mg. Needs a lot more
work, including a proper parser.


# 1.163 17-Jul-2019 lum

Add two dobeep functions to make calls to the system bell require
fewer lines. While working in extend.c change relevant calls to
dobeep.


# 1.162 03-Jul-2019 lum

selfinsert() can't be called directly from a startup file or by
'eval-current-buffer' since it is by design, meant to be called interactively
as characters are typed in a buffer. ask_selfinsert() allows selfinsert() to
be used by excline(). Having ask_selfinsert() helps with regression testing.
No manual page entry since use case is a bit obscure. See 'insert' command.


# 1.161 02-Jul-2019 lum

I totally forgot about the instance where blink-and-insert can be
called from the mg startup file. My previous diff broke that instance.
So this diff reverts my change but adds a man page line to
blink-and-insert in case someone should try to use it interactively,
again. Also, should anyone ever want to add an interactive version of
blink-and-insert in the future, the code is there. And the code could
be useful in another, related instance.


# 1.160 26-Jun-2019 lum

This diff makes blink-and-insert do as the man page says it should do.
If you do 'M-x blink-and-insert', you are asked for a character. mg
will then insert it at the current cursor position and then search
backwards for a corresponding match.


# 1.159 22-Jun-2019 lum

Tidy up the comments:
1. two spelling mistakes.
2. change references to keystrokes, same as man page (UP-low).
3. update a filename reference to reality.


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.176 06-May-2021 lum

Add the line number of an error to error messages.


# 1.175 06-May-2021 lum

Add a number to parameters for ewprintf() via beeping.


# 1.174 03-May-2021 lum

When parsing a variable value within double quotes, allow an escaped
\" to be accomodated for. Also, move the variable structure to be
global in scope within mg.


# 1.173 22-Apr-2021 lum

Add a non-interactive version of query-replace-regexp function called
replace-regexp. Unfortunately query-replace-regexp can't be used in a
startup file.


# 1.172 20-Apr-2021 lum

Add 'dired-jump' from Philip K. <philip@warpmail.net> sent to tech@
over a year ago. Comments and testing from gkoehler@. Thanks to both.
Also, some modifications from me.


Revision tags: OPENBSD_6_9_BASE
# 1.171 25-Mar-2021 lum

Use length of line to indicate end of characters to process in
foundparen(). No intended functional change. regress tests ok and they
all use excline().


# 1.170 21-Mar-2021 lum

Add quoted strings capability in list values, no special chars
detection in between them though. Add limitation to characters
allowed in symbol names, equivalent to mg function names (A-Za-z-),
quite restrictive but can grow of course. If value is not quoted and
is not a variable, give an error.


# 1.169 20-Mar-2021 lum

Add a 'batch' mode to mg via the '-b' command line option which will
initialise a pty, run the specified file of mg commands and then exit.

This is to facilitate mg fitting into the OpenBSD regress test
framework and be able to run via a cron job.


# 1.168 01-Mar-2021 lum

Put the hardcoded '\n' character which is found throughout mg into a
buffer specific variable. The diff should not produce any behavourial
changes in mg.


# 1.167 23-Feb-2021 lum

Allow the user to specify a path to the mg startup file on the command line.


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.166 09-Feb-2020 florian

Do not define variables in def.h since this will lead to duplicate definitions
in every source file that includes def.h
Found by gcc10 in portable in gentoo and fedora.
Patch from Ulrich Mueller (ulm AT gentoo.org) via Han Boetes, thanks!
Ok tb


Revision tags: OPENBSD_6_6_BASE
# 1.165 18-Jul-2019 lum

Make indentation consistent. This has been bugging me for a while now.


# 1.164 18-Jul-2019 lum

Add some more basic interpreter functionality to mg. Needs a lot more
work, including a proper parser.


# 1.163 17-Jul-2019 lum

Add two dobeep functions to make calls to the system bell require
fewer lines. While working in extend.c change relevant calls to
dobeep.


# 1.162 03-Jul-2019 lum

selfinsert() can't be called directly from a startup file or by
'eval-current-buffer' since it is by design, meant to be called interactively
as characters are typed in a buffer. ask_selfinsert() allows selfinsert() to
be used by excline(). Having ask_selfinsert() helps with regression testing.
No manual page entry since use case is a bit obscure. See 'insert' command.


# 1.161 02-Jul-2019 lum

I totally forgot about the instance where blink-and-insert can be
called from the mg startup file. My previous diff broke that instance.
So this diff reverts my change but adds a man page line to
blink-and-insert in case someone should try to use it interactively,
again. Also, should anyone ever want to add an interactive version of
blink-and-insert in the future, the code is there. And the code could
be useful in another, related instance.


# 1.160 26-Jun-2019 lum

This diff makes blink-and-insert do as the man page says it should do.
If you do 'M-x blink-and-insert', you are asked for a character. mg
will then insert it at the current cursor position and then search
backwards for a corresponding match.


# 1.159 22-Jun-2019 lum

Tidy up the comments:
1. two spelling mistakes.
2. change references to keystrokes, same as man page (UP-low).
3. update a filename reference to reality.


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.174 03-May-2021 lum

When parsing a variable value within double quotes, allow an escaped
\" to be accomodated for. Also, move the variable structure to be
global in scope within mg.


# 1.173 22-Apr-2021 lum

Add a non-interactive version of query-replace-regexp function called
replace-regexp. Unfortunately query-replace-regexp can't be used in a
startup file.


# 1.172 20-Apr-2021 lum

Add 'dired-jump' from Philip K. <philip@warpmail.net> sent to tech@
over a year ago. Comments and testing from gkoehler@. Thanks to both.
Also, some modifications from me.


Revision tags: OPENBSD_6_9_BASE
# 1.171 25-Mar-2021 lum

Use length of line to indicate end of characters to process in
foundparen(). No intended functional change. regress tests ok and they
all use excline().


# 1.170 21-Mar-2021 lum

Add quoted strings capability in list values, no special chars
detection in between them though. Add limitation to characters
allowed in symbol names, equivalent to mg function names (A-Za-z-),
quite restrictive but can grow of course. If value is not quoted and
is not a variable, give an error.


# 1.169 20-Mar-2021 lum

Add a 'batch' mode to mg via the '-b' command line option which will
initialise a pty, run the specified file of mg commands and then exit.

This is to facilitate mg fitting into the OpenBSD regress test
framework and be able to run via a cron job.


# 1.168 01-Mar-2021 lum

Put the hardcoded '\n' character which is found throughout mg into a
buffer specific variable. The diff should not produce any behavourial
changes in mg.


# 1.167 23-Feb-2021 lum

Allow the user to specify a path to the mg startup file on the command line.


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.166 09-Feb-2020 florian

Do not define variables in def.h since this will lead to duplicate definitions
in every source file that includes def.h
Found by gcc10 in portable in gentoo and fedora.
Patch from Ulrich Mueller (ulm AT gentoo.org) via Han Boetes, thanks!
Ok tb


Revision tags: OPENBSD_6_6_BASE
# 1.165 18-Jul-2019 lum

Make indentation consistent. This has been bugging me for a while now.


# 1.164 18-Jul-2019 lum

Add some more basic interpreter functionality to mg. Needs a lot more
work, including a proper parser.


# 1.163 17-Jul-2019 lum

Add two dobeep functions to make calls to the system bell require
fewer lines. While working in extend.c change relevant calls to
dobeep.


# 1.162 03-Jul-2019 lum

selfinsert() can't be called directly from a startup file or by
'eval-current-buffer' since it is by design, meant to be called interactively
as characters are typed in a buffer. ask_selfinsert() allows selfinsert() to
be used by excline(). Having ask_selfinsert() helps with regression testing.
No manual page entry since use case is a bit obscure. See 'insert' command.


# 1.161 02-Jul-2019 lum

I totally forgot about the instance where blink-and-insert can be
called from the mg startup file. My previous diff broke that instance.
So this diff reverts my change but adds a man page line to
blink-and-insert in case someone should try to use it interactively,
again. Also, should anyone ever want to add an interactive version of
blink-and-insert in the future, the code is there. And the code could
be useful in another, related instance.


# 1.160 26-Jun-2019 lum

This diff makes blink-and-insert do as the man page says it should do.
If you do 'M-x blink-and-insert', you are asked for a character. mg
will then insert it at the current cursor position and then search
backwards for a corresponding match.


# 1.159 22-Jun-2019 lum

Tidy up the comments:
1. two spelling mistakes.
2. change references to keystrokes, same as man page (UP-low).
3. update a filename reference to reality.


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.173 22-Apr-2021 lum

Add a non-interactive version of query-replace-regexp function called
replace-regexp. Unfortunately query-replace-regexp can't be used in a
startup file.


# 1.172 20-Apr-2021 lum

Add 'dired-jump' from Philip K. <philip@warpmail.net> sent to tech@
over a year ago. Comments and testing from gkoehler@. Thanks to both.
Also, some modifications from me.


Revision tags: OPENBSD_6_9_BASE
# 1.171 25-Mar-2021 lum

Use length of line to indicate end of characters to process in
foundparen(). No intended functional change. regress tests ok and they
all use excline().


# 1.170 21-Mar-2021 lum

Add quoted strings capability in list values, no special chars
detection in between them though. Add limitation to characters
allowed in symbol names, equivalent to mg function names (A-Za-z-),
quite restrictive but can grow of course. If value is not quoted and
is not a variable, give an error.


# 1.169 20-Mar-2021 lum

Add a 'batch' mode to mg via the '-b' command line option which will
initialise a pty, run the specified file of mg commands and then exit.

This is to facilitate mg fitting into the OpenBSD regress test
framework and be able to run via a cron job.


# 1.168 01-Mar-2021 lum

Put the hardcoded '\n' character which is found throughout mg into a
buffer specific variable. The diff should not produce any behavourial
changes in mg.


# 1.167 23-Feb-2021 lum

Allow the user to specify a path to the mg startup file on the command line.


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.166 09-Feb-2020 florian

Do not define variables in def.h since this will lead to duplicate definitions
in every source file that includes def.h
Found by gcc10 in portable in gentoo and fedora.
Patch from Ulrich Mueller (ulm AT gentoo.org) via Han Boetes, thanks!
Ok tb


Revision tags: OPENBSD_6_6_BASE
# 1.165 18-Jul-2019 lum

Make indentation consistent. This has been bugging me for a while now.


# 1.164 18-Jul-2019 lum

Add some more basic interpreter functionality to mg. Needs a lot more
work, including a proper parser.


# 1.163 17-Jul-2019 lum

Add two dobeep functions to make calls to the system bell require
fewer lines. While working in extend.c change relevant calls to
dobeep.


# 1.162 03-Jul-2019 lum

selfinsert() can't be called directly from a startup file or by
'eval-current-buffer' since it is by design, meant to be called interactively
as characters are typed in a buffer. ask_selfinsert() allows selfinsert() to
be used by excline(). Having ask_selfinsert() helps with regression testing.
No manual page entry since use case is a bit obscure. See 'insert' command.


# 1.161 02-Jul-2019 lum

I totally forgot about the instance where blink-and-insert can be
called from the mg startup file. My previous diff broke that instance.
So this diff reverts my change but adds a man page line to
blink-and-insert in case someone should try to use it interactively,
again. Also, should anyone ever want to add an interactive version of
blink-and-insert in the future, the code is there. And the code could
be useful in another, related instance.


# 1.160 26-Jun-2019 lum

This diff makes blink-and-insert do as the man page says it should do.
If you do 'M-x blink-and-insert', you are asked for a character. mg
will then insert it at the current cursor position and then search
backwards for a corresponding match.


# 1.159 22-Jun-2019 lum

Tidy up the comments:
1. two spelling mistakes.
2. change references to keystrokes, same as man page (UP-low).
3. update a filename reference to reality.


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.172 20-Apr-2021 lum

Add 'dired-jump' from Philip K. <philip@warpmail.net> sent to tech@
over a year ago. Comments and testing from gkoehler@. Thanks to both.
Also, some modifications from me.


Revision tags: OPENBSD_6_9_BASE
# 1.171 25-Mar-2021 lum

Use length of line to indicate end of characters to process in
foundparen(). No intended functional change. regress tests ok and they
all use excline().


# 1.170 21-Mar-2021 lum

Add quoted strings capability in list values, no special chars
detection in between them though. Add limitation to characters
allowed in symbol names, equivalent to mg function names (A-Za-z-),
quite restrictive but can grow of course. If value is not quoted and
is not a variable, give an error.


# 1.169 20-Mar-2021 lum

Add a 'batch' mode to mg via the '-b' command line option which will
initialise a pty, run the specified file of mg commands and then exit.

This is to facilitate mg fitting into the OpenBSD regress test
framework and be able to run via a cron job.


# 1.168 01-Mar-2021 lum

Put the hardcoded '\n' character which is found throughout mg into a
buffer specific variable. The diff should not produce any behavourial
changes in mg.


# 1.167 23-Feb-2021 lum

Allow the user to specify a path to the mg startup file on the command line.


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.166 09-Feb-2020 florian

Do not define variables in def.h since this will lead to duplicate definitions
in every source file that includes def.h
Found by gcc10 in portable in gentoo and fedora.
Patch from Ulrich Mueller (ulm AT gentoo.org) via Han Boetes, thanks!
Ok tb


Revision tags: OPENBSD_6_6_BASE
# 1.165 18-Jul-2019 lum

Make indentation consistent. This has been bugging me for a while now.


# 1.164 18-Jul-2019 lum

Add some more basic interpreter functionality to mg. Needs a lot more
work, including a proper parser.


# 1.163 17-Jul-2019 lum

Add two dobeep functions to make calls to the system bell require
fewer lines. While working in extend.c change relevant calls to
dobeep.


# 1.162 03-Jul-2019 lum

selfinsert() can't be called directly from a startup file or by
'eval-current-buffer' since it is by design, meant to be called interactively
as characters are typed in a buffer. ask_selfinsert() allows selfinsert() to
be used by excline(). Having ask_selfinsert() helps with regression testing.
No manual page entry since use case is a bit obscure. See 'insert' command.


# 1.161 02-Jul-2019 lum

I totally forgot about the instance where blink-and-insert can be
called from the mg startup file. My previous diff broke that instance.
So this diff reverts my change but adds a man page line to
blink-and-insert in case someone should try to use it interactively,
again. Also, should anyone ever want to add an interactive version of
blink-and-insert in the future, the code is there. And the code could
be useful in another, related instance.


# 1.160 26-Jun-2019 lum

This diff makes blink-and-insert do as the man page says it should do.
If you do 'M-x blink-and-insert', you are asked for a character. mg
will then insert it at the current cursor position and then search
backwards for a corresponding match.


# 1.159 22-Jun-2019 lum

Tidy up the comments:
1. two spelling mistakes.
2. change references to keystrokes, same as man page (UP-low).
3. update a filename reference to reality.


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.171 25-Mar-2021 lum

Use length of line to indicate end of characters to process in
foundparen(). No intended functional change. regress tests ok and they
all use excline().


# 1.170 21-Mar-2021 lum

Add quoted strings capability in list values, no special chars
detection in between them though. Add limitation to characters
allowed in symbol names, equivalent to mg function names (A-Za-z-),
quite restrictive but can grow of course. If value is not quoted and
is not a variable, give an error.


# 1.169 20-Mar-2021 lum

Add a 'batch' mode to mg via the '-b' command line option which will
initialise a pty, run the specified file of mg commands and then exit.

This is to facilitate mg fitting into the OpenBSD regress test
framework and be able to run via a cron job.


# 1.168 01-Mar-2021 lum

Put the hardcoded '\n' character which is found throughout mg into a
buffer specific variable. The diff should not produce any behavourial
changes in mg.


# 1.167 23-Feb-2021 lum

Allow the user to specify a path to the mg startup file on the command line.


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.166 09-Feb-2020 florian

Do not define variables in def.h since this will lead to duplicate definitions
in every source file that includes def.h
Found by gcc10 in portable in gentoo and fedora.
Patch from Ulrich Mueller (ulm AT gentoo.org) via Han Boetes, thanks!
Ok tb


Revision tags: OPENBSD_6_6_BASE
# 1.165 18-Jul-2019 lum

Make indentation consistent. This has been bugging me for a while now.


# 1.164 18-Jul-2019 lum

Add some more basic interpreter functionality to mg. Needs a lot more
work, including a proper parser.


# 1.163 17-Jul-2019 lum

Add two dobeep functions to make calls to the system bell require
fewer lines. While working in extend.c change relevant calls to
dobeep.


# 1.162 03-Jul-2019 lum

selfinsert() can't be called directly from a startup file or by
'eval-current-buffer' since it is by design, meant to be called interactively
as characters are typed in a buffer. ask_selfinsert() allows selfinsert() to
be used by excline(). Having ask_selfinsert() helps with regression testing.
No manual page entry since use case is a bit obscure. See 'insert' command.


# 1.161 02-Jul-2019 lum

I totally forgot about the instance where blink-and-insert can be
called from the mg startup file. My previous diff broke that instance.
So this diff reverts my change but adds a man page line to
blink-and-insert in case someone should try to use it interactively,
again. Also, should anyone ever want to add an interactive version of
blink-and-insert in the future, the code is there. And the code could
be useful in another, related instance.


# 1.160 26-Jun-2019 lum

This diff makes blink-and-insert do as the man page says it should do.
If you do 'M-x blink-and-insert', you are asked for a character. mg
will then insert it at the current cursor position and then search
backwards for a corresponding match.


# 1.159 22-Jun-2019 lum

Tidy up the comments:
1. two spelling mistakes.
2. change references to keystrokes, same as man page (UP-low).
3. update a filename reference to reality.


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.170 21-Mar-2021 lum

Add quoted strings capability in list values, no special chars
detection in between them though. Add limitation to characters
allowed in symbol names, equivalent to mg function names (A-Za-z-),
quite restrictive but can grow of course. If value is not quoted and
is not a variable, give an error.


# 1.169 20-Mar-2021 lum

Add a 'batch' mode to mg via the '-b' command line option which will
initialise a pty, run the specified file of mg commands and then exit.

This is to facilitate mg fitting into the OpenBSD regress test
framework and be able to run via a cron job.


# 1.168 01-Mar-2021 lum

Put the hardcoded '\n' character which is found throughout mg into a
buffer specific variable. The diff should not produce any behavourial
changes in mg.


# 1.167 23-Feb-2021 lum

Allow the user to specify a path to the mg startup file on the command line.


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.166 09-Feb-2020 florian

Do not define variables in def.h since this will lead to duplicate definitions
in every source file that includes def.h
Found by gcc10 in portable in gentoo and fedora.
Patch from Ulrich Mueller (ulm AT gentoo.org) via Han Boetes, thanks!
Ok tb


Revision tags: OPENBSD_6_6_BASE
# 1.165 18-Jul-2019 lum

Make indentation consistent. This has been bugging me for a while now.


# 1.164 18-Jul-2019 lum

Add some more basic interpreter functionality to mg. Needs a lot more
work, including a proper parser.


# 1.163 17-Jul-2019 lum

Add two dobeep functions to make calls to the system bell require
fewer lines. While working in extend.c change relevant calls to
dobeep.


# 1.162 03-Jul-2019 lum

selfinsert() can't be called directly from a startup file or by
'eval-current-buffer' since it is by design, meant to be called interactively
as characters are typed in a buffer. ask_selfinsert() allows selfinsert() to
be used by excline(). Having ask_selfinsert() helps with regression testing.
No manual page entry since use case is a bit obscure. See 'insert' command.


# 1.161 02-Jul-2019 lum

I totally forgot about the instance where blink-and-insert can be
called from the mg startup file. My previous diff broke that instance.
So this diff reverts my change but adds a man page line to
blink-and-insert in case someone should try to use it interactively,
again. Also, should anyone ever want to add an interactive version of
blink-and-insert in the future, the code is there. And the code could
be useful in another, related instance.


# 1.160 26-Jun-2019 lum

This diff makes blink-and-insert do as the man page says it should do.
If you do 'M-x blink-and-insert', you are asked for a character. mg
will then insert it at the current cursor position and then search
backwards for a corresponding match.


# 1.159 22-Jun-2019 lum

Tidy up the comments:
1. two spelling mistakes.
2. change references to keystrokes, same as man page (UP-low).
3. update a filename reference to reality.


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.169 20-Mar-2021 lum

Add a 'batch' mode to mg via the '-b' command line option which will
initialise a pty, run the specified file of mg commands and then exit.

This is to facilitate mg fitting into the OpenBSD regress test
framework and be able to run via a cron job.


# 1.168 01-Mar-2021 lum

Put the hardcoded '\n' character which is found throughout mg into a
buffer specific variable. The diff should not produce any behavourial
changes in mg.


# 1.167 23-Feb-2021 lum

Allow the user to specify a path to the mg startup file on the command line.


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.166 09-Feb-2020 florian

Do not define variables in def.h since this will lead to duplicate definitions
in every source file that includes def.h
Found by gcc10 in portable in gentoo and fedora.
Patch from Ulrich Mueller (ulm AT gentoo.org) via Han Boetes, thanks!
Ok tb


Revision tags: OPENBSD_6_6_BASE
# 1.165 18-Jul-2019 lum

Make indentation consistent. This has been bugging me for a while now.


# 1.164 18-Jul-2019 lum

Add some more basic interpreter functionality to mg. Needs a lot more
work, including a proper parser.


# 1.163 17-Jul-2019 lum

Add two dobeep functions to make calls to the system bell require
fewer lines. While working in extend.c change relevant calls to
dobeep.


# 1.162 03-Jul-2019 lum

selfinsert() can't be called directly from a startup file or by
'eval-current-buffer' since it is by design, meant to be called interactively
as characters are typed in a buffer. ask_selfinsert() allows selfinsert() to
be used by excline(). Having ask_selfinsert() helps with regression testing.
No manual page entry since use case is a bit obscure. See 'insert' command.


# 1.161 02-Jul-2019 lum

I totally forgot about the instance where blink-and-insert can be
called from the mg startup file. My previous diff broke that instance.
So this diff reverts my change but adds a man page line to
blink-and-insert in case someone should try to use it interactively,
again. Also, should anyone ever want to add an interactive version of
blink-and-insert in the future, the code is there. And the code could
be useful in another, related instance.


# 1.160 26-Jun-2019 lum

This diff makes blink-and-insert do as the man page says it should do.
If you do 'M-x blink-and-insert', you are asked for a character. mg
will then insert it at the current cursor position and then search
backwards for a corresponding match.


# 1.159 22-Jun-2019 lum

Tidy up the comments:
1. two spelling mistakes.
2. change references to keystrokes, same as man page (UP-low).
3. update a filename reference to reality.


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.168 01-Mar-2021 lum

Put the hardcoded '\n' character which is found throughout mg into a
buffer specific variable. The diff should not produce any behavourial
changes in mg.


# 1.167 23-Feb-2021 lum

Allow the user to specify a path to the mg startup file on the command line.


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.166 09-Feb-2020 florian

Do not define variables in def.h since this will lead to duplicate definitions
in every source file that includes def.h
Found by gcc10 in portable in gentoo and fedora.
Patch from Ulrich Mueller (ulm AT gentoo.org) via Han Boetes, thanks!
Ok tb


Revision tags: OPENBSD_6_6_BASE
# 1.165 18-Jul-2019 lum

Make indentation consistent. This has been bugging me for a while now.


# 1.164 18-Jul-2019 lum

Add some more basic interpreter functionality to mg. Needs a lot more
work, including a proper parser.


# 1.163 17-Jul-2019 lum

Add two dobeep functions to make calls to the system bell require
fewer lines. While working in extend.c change relevant calls to
dobeep.


# 1.162 03-Jul-2019 lum

selfinsert() can't be called directly from a startup file or by
'eval-current-buffer' since it is by design, meant to be called interactively
as characters are typed in a buffer. ask_selfinsert() allows selfinsert() to
be used by excline(). Having ask_selfinsert() helps with regression testing.
No manual page entry since use case is a bit obscure. See 'insert' command.


# 1.161 02-Jul-2019 lum

I totally forgot about the instance where blink-and-insert can be
called from the mg startup file. My previous diff broke that instance.
So this diff reverts my change but adds a man page line to
blink-and-insert in case someone should try to use it interactively,
again. Also, should anyone ever want to add an interactive version of
blink-and-insert in the future, the code is there. And the code could
be useful in another, related instance.


# 1.160 26-Jun-2019 lum

This diff makes blink-and-insert do as the man page says it should do.
If you do 'M-x blink-and-insert', you are asked for a character. mg
will then insert it at the current cursor position and then search
backwards for a corresponding match.


# 1.159 22-Jun-2019 lum

Tidy up the comments:
1. two spelling mistakes.
2. change references to keystrokes, same as man page (UP-low).
3. update a filename reference to reality.


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.167 23-Feb-2021 lum

Allow the user to specify a path to the mg startup file on the command line.


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.166 09-Feb-2020 florian

Do not define variables in def.h since this will lead to duplicate definitions
in every source file that includes def.h
Found by gcc10 in portable in gentoo and fedora.
Patch from Ulrich Mueller (ulm AT gentoo.org) via Han Boetes, thanks!
Ok tb


Revision tags: OPENBSD_6_6_BASE
# 1.165 18-Jul-2019 lum

Make indentation consistent. This has been bugging me for a while now.


# 1.164 18-Jul-2019 lum

Add some more basic interpreter functionality to mg. Needs a lot more
work, including a proper parser.


# 1.163 17-Jul-2019 lum

Add two dobeep functions to make calls to the system bell require
fewer lines. While working in extend.c change relevant calls to
dobeep.


# 1.162 03-Jul-2019 lum

selfinsert() can't be called directly from a startup file or by
'eval-current-buffer' since it is by design, meant to be called interactively
as characters are typed in a buffer. ask_selfinsert() allows selfinsert() to
be used by excline(). Having ask_selfinsert() helps with regression testing.
No manual page entry since use case is a bit obscure. See 'insert' command.


# 1.161 02-Jul-2019 lum

I totally forgot about the instance where blink-and-insert can be
called from the mg startup file. My previous diff broke that instance.
So this diff reverts my change but adds a man page line to
blink-and-insert in case someone should try to use it interactively,
again. Also, should anyone ever want to add an interactive version of
blink-and-insert in the future, the code is there. And the code could
be useful in another, related instance.


# 1.160 26-Jun-2019 lum

This diff makes blink-and-insert do as the man page says it should do.
If you do 'M-x blink-and-insert', you are asked for a character. mg
will then insert it at the current cursor position and then search
backwards for a corresponding match.


# 1.159 22-Jun-2019 lum

Tidy up the comments:
1. two spelling mistakes.
2. change references to keystrokes, same as man page (UP-low).
3. update a filename reference to reality.


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.166 09-Feb-2020 florian

Do not define variables in def.h since this will lead to duplicate definitions
in every source file that includes def.h
Found by gcc10 in portable in gentoo and fedora.
Patch from Ulrich Mueller (ulm AT gentoo.org) via Han Boetes, thanks!
Ok tb


Revision tags: OPENBSD_6_6_BASE
# 1.165 18-Jul-2019 lum

Make indentation consistent. This has been bugging me for a while now.


# 1.164 18-Jul-2019 lum

Add some more basic interpreter functionality to mg. Needs a lot more
work, including a proper parser.


# 1.163 17-Jul-2019 lum

Add two dobeep functions to make calls to the system bell require
fewer lines. While working in extend.c change relevant calls to
dobeep.


# 1.162 03-Jul-2019 lum

selfinsert() can't be called directly from a startup file or by
'eval-current-buffer' since it is by design, meant to be called interactively
as characters are typed in a buffer. ask_selfinsert() allows selfinsert() to
be used by excline(). Having ask_selfinsert() helps with regression testing.
No manual page entry since use case is a bit obscure. See 'insert' command.


# 1.161 02-Jul-2019 lum

I totally forgot about the instance where blink-and-insert can be
called from the mg startup file. My previous diff broke that instance.
So this diff reverts my change but adds a man page line to
blink-and-insert in case someone should try to use it interactively,
again. Also, should anyone ever want to add an interactive version of
blink-and-insert in the future, the code is there. And the code could
be useful in another, related instance.


# 1.160 26-Jun-2019 lum

This diff makes blink-and-insert do as the man page says it should do.
If you do 'M-x blink-and-insert', you are asked for a character. mg
will then insert it at the current cursor position and then search
backwards for a corresponding match.


# 1.159 22-Jun-2019 lum

Tidy up the comments:
1. two spelling mistakes.
2. change references to keystrokes, same as man page (UP-low).
3. update a filename reference to reality.


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.165 18-Jul-2019 lum

Make indentation consistent. This has been bugging me for a while now.


# 1.164 18-Jul-2019 lum

Add some more basic interpreter functionality to mg. Needs a lot more
work, including a proper parser.


# 1.163 17-Jul-2019 lum

Add two dobeep functions to make calls to the system bell require
fewer lines. While working in extend.c change relevant calls to
dobeep.


# 1.162 03-Jul-2019 lum

selfinsert() can't be called directly from a startup file or by
'eval-current-buffer' since it is by design, meant to be called interactively
as characters are typed in a buffer. ask_selfinsert() allows selfinsert() to
be used by excline(). Having ask_selfinsert() helps with regression testing.
No manual page entry since use case is a bit obscure. See 'insert' command.


# 1.161 02-Jul-2019 lum

I totally forgot about the instance where blink-and-insert can be
called from the mg startup file. My previous diff broke that instance.
So this diff reverts my change but adds a man page line to
blink-and-insert in case someone should try to use it interactively,
again. Also, should anyone ever want to add an interactive version of
blink-and-insert in the future, the code is there. And the code could
be useful in another, related instance.


# 1.160 26-Jun-2019 lum

This diff makes blink-and-insert do as the man page says it should do.
If you do 'M-x blink-and-insert', you are asked for a character. mg
will then insert it at the current cursor position and then search
backwards for a corresponding match.


# 1.159 22-Jun-2019 lum

Tidy up the comments:
1. two spelling mistakes.
2. change references to keystrokes, same as man page (UP-low).
3. update a filename reference to reality.


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.162 03-Jul-2019 lum

selfinsert() can't be called directly from a startup file or by
'eval-current-buffer' since it is by design, meant to be called interactively
as characters are typed in a buffer. ask_selfinsert() allows selfinsert() to
be used by excline(). Having ask_selfinsert() helps with regression testing.
No manual page entry since use case is a bit obscure. See 'insert' command.


# 1.161 02-Jul-2019 lum

I totally forgot about the instance where blink-and-insert can be
called from the mg startup file. My previous diff broke that instance.
So this diff reverts my change but adds a man page line to
blink-and-insert in case someone should try to use it interactively,
again. Also, should anyone ever want to add an interactive version of
blink-and-insert in the future, the code is there. And the code could
be useful in another, related instance.


# 1.160 26-Jun-2019 lum

This diff makes blink-and-insert do as the man page says it should do.
If you do 'M-x blink-and-insert', you are asked for a character. mg
will then insert it at the current cursor position and then search
backwards for a corresponding match.


# 1.159 22-Jun-2019 lum

Tidy up the comments:
1. two spelling mistakes.
2. change references to keystrokes, same as man page (UP-low).
3. update a filename reference to reality.


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.161 02-Jul-2019 lum

I totally forgot about the instance where blink-and-insert can be
called from the mg startup file. My previous diff broke that instance.
So this diff reverts my change but adds a man page line to
blink-and-insert in case someone should try to use it interactively,
again. Also, should anyone ever want to add an interactive version of
blink-and-insert in the future, the code is there. And the code could
be useful in another, related instance.


# 1.160 26-Jun-2019 lum

This diff makes blink-and-insert do as the man page says it should do.
If you do 'M-x blink-and-insert', you are asked for a character. mg
will then insert it at the current cursor position and then search
backwards for a corresponding match.


# 1.159 22-Jun-2019 lum

Tidy up the comments:
1. two spelling mistakes.
2. change references to keystrokes, same as man page (UP-low).
3. update a filename reference to reality.


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.160 26-Jun-2019 lum

This diff makes blink-and-insert do as the man page says it should do.
If you do 'M-x blink-and-insert', you are asked for a character. mg
will then insert it at the current cursor position and then search
backwards for a corresponding match.


# 1.159 22-Jun-2019 lum

Tidy up the comments:
1. two spelling mistakes.
2. change references to keystrokes, same as man page (UP-low).
3. update a filename reference to reality.


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.159 22-Jun-2019 lum

Tidy up the comments:
1. two spelling mistakes.
2. change references to keystrokes, same as man page (UP-low).
3. update a filename reference to reality.


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.158 22-Jun-2019 lum

This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.


Revision tags: OPENBSD_6_5_BASE
# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.157 13-Dec-2018 lum

Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all


Revision tags: OPENBSD_6_4_BASE
# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


# 1.156 29-Aug-2018 reyk

Add set-case-replaced to toggle case-preserving replace on or off.

By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".

OK florian@ tb@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.155 14-Apr-2016 lum

Add 'sentence-end-double-space'.

If you prefer "lighter" punctuation and one space between sentences,
for example:

Mr and Mrs Jones are from the UK. They arrived today.

over more liberal use of full stops and double spaces between
sentences:

Mr. and Mrs. Jones are from the U.K. They arrived today.

then toggling 'sentence-end-double-space' will make mg's
fill-paragraph function format text using one space instead of two
(the default) between sentences. However, be careful, should you have
a double spaced document and accidentally "format" it to have single
spaces, then you may have a problem. mg won't be able to revert the
formatting for you (unless you have a previous version of the text in
the "undo" history, or are using mg's backup facility and haven't
opened and saved multiple times!).

Comments from schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.154 02-Jan-2016 lum

Add dired-find-alternate-file.


# 1.153 29-Dec-2015 lum

Add transpose-words, ok jasper@.
Limited to one iteration until 'undo' is looked into.


# 1.152 29-Oct-2015 lum

Fix opening dired from the command line. Incorrect cursor placement
and make the error more useful when there is a problem opening a
directory. Reported by and ok jasper@


# 1.151 12-Oct-2015 lum

Maintain a list of files marked for deletion while refreshing a dired
buffer. Previously, when refreshing the buffer the files marked for
deletion would be lost.

Since the relationship between the files that have been marked for
deletion and those that exist on disk is volatile, I have chosen to
implement the discovery of marked files during the refresh function as
opposed to maintaining a dired buffer specific list.


# 1.150 29-Sep-2015 guenther

Mark eread(), veread(), and eformat() as printf-like and
Convert eread(buf, a2, a3, a4) to eread("%s", a2, a3, a4, buf)

ok millert@ lum@


# 1.149 26-Sep-2015 lum

Add transpose-paragraphs. ok jasper@


# 1.148 24-Sep-2015 lum

Add mark-paragraph. ok jasper@


Revision tags: OPENBSD_5_8_BASE
# 1.147 03-Jun-2015 bcallah

Remove unused defines and functions.
"Looks fine." deraadt@


# 1.146 08-May-2015 bcallah

Remove ereply prototype since it is never used. Tweak a comment to reflect
ereply removal.
ok jasper@ florian@


# 1.145 25-Mar-2015 bcallah

unifdef -U NO_DPROMPT and GOSREC.
NO_DPROMPT has been around since the import of mg2a and it has never been
considered a "(Common) compile-time option" in the Makefile.
Assume everyone has been running mg this way since at least 2000 if not
already in the 90s.

Same with GOSREC. Has always been there but it looks like no one noticed
it (and no one was running with it). Indeed, the mg tutorial appears to be
oblivious to GOSREC being an option.

With this commit there are no more #ifndef blocks in mg. Only a couple of
#ifdef blocks remain.

ok lum@


# 1.144 25-Mar-2015 bcallah

We really don't need ttydef.h -- it is like sysdef.h -- once useful because
supported a lot of systems and nothing was standardized. But now it only
4 defines. Move those defines into def.h since ttydef.h is only sourced in
def.h

While here, MAKEBACKUP has the same #ifdef dance that LINENOMODE had. Set
it directly to TRUE and remove the #ifdef block.

ok florian@


# 1.143 19-Mar-2015 bcallah

Clean up the includes in mg.
This does the following:
Moves all POSIX headers from sysdef.h into the individual .c files so that
each file now only includes what it needs. All headers are properly sorted.
Moves the remainder of sysdef.h to other files (mostly def.h) and deletes
sysdef.h now that it's no longer contains anything.
Tweak a comment that references sysdef.h so that it no longer does that.
ok florian@


# 1.142 16-Mar-2015 bcallah

Change the internal name of the newline function to deconflict with a
function of the same name in term.h. This is the first step towards
cleaning up mg's includes. No user-visible changes.
ok florian@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.141 03-Apr-2014 lum

When finding a file in a non-existant directory:

C-x C-f ~/no/dir/here/fn

offer to make the directory by pressing 'y', instead of suggesting the
make-directory command. ok jasper@


# 1.140 22-Mar-2014 lum

donebell is no longer required.


Revision tags: OPENBSD_5_5_BASE
# 1.139 23-Dec-2013 lum

Move findbuffer() to buffer.c.
ok florian@


Revision tags: OPENBSD_5_4_BASE
# 1.138 31-May-2013 lum

Make the system bell toggleable via 'audible-bell', and if switched
off, make available an alternative 'visible-bell'.

ok florian@ jasper@ Feedback Sunil Nimmagadda.


# 1.137 30-May-2013 lum

Reuse the makedir() function in dir.c for dired's
dired-create-directory command.
ok jasper@


# 1.136 22-May-2013 lum

Shuffle shell-command-on-region around to give shell-command.
ok florian@ jasper@
Testing Sunil Nimmagadda


# 1.135 25-Mar-2013 florian

Display the window's column number in mode line not the
column number of the active window.
OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.134 27-Dec-2012 florian

diff-buffer-with-file
input gsoares@, Sunil Nimmagadda, jasper@
ok jasper@, benno@


# 1.133 27-Dec-2012 florian

Move code for shell-command-on-region around to make pipeio() usable
in other functions.
ok jasper@, benno@


# 1.132 04-Dec-2012 florian

Bring back column numbers and make them configurable, off by default
to not kill slow serial lines.
Committing my independently written, slightly different version, as
requested by jasper@.

OK jasper@, OK reyk@ for jasper@'s version of the diff
"Sure, if you think so then." deraadt@


# 1.131 27-Nov-2012 jasper

- add 'make-directory' (not bound to any shortcut).

feedback from florian@ lum@
ok florian@


# 1.130 27-Nov-2012 jasper

- move prototype of expandtilder() to def.h; needed by an upcoming diff.


# 1.129 06-Nov-2012 florian

Remove never read struct member, found while investigating a llvm
report.

ok lum, jasper, benno


# 1.128 03-Nov-2012 haesbaert

This should be void.


# 1.127 22-Oct-2012 florian

Add (r)evert prompt to "File changed on disk; really edit the buffer"
prompt.

input, ok lum@, man bit ok jmc@, ok benno@


# 1.126 12-Oct-2012 jasper

- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()

input/ok florian@ haesbaert@


# 1.125 31-Aug-2012 lum

Allow an error message for a filename that is too long to be seen and
let the error stop mg exiting when C-x C-c is called.


Revision tags: OPENBSD_5_2_BASE
# 1.124 14-Jun-2012 lum

Allow mg to save backup files to a users home directory.
Suggestions from eric@ and Sunil Nimmagadda.
Remarks deraadt@.


# 1.123 07-Jun-2012 lum

Add some cscope support to mg. From Sunil Nimmagadda. Due to some
structural limitations in mg, mg doesn't behave exactly the same as
emacs cscope (see the README) but is still very usable.

man page bits reviewed by jmc@, otherwise tested and reviewed by
myself.


# 1.122 29-May-2012 lum

Increase the size of some window variables from char to int. This diff
improves mg on screens (xterms) with lots of lines. Testing done by
naddy@ and myself.


# 1.121 25-May-2012 lum

Remove static FILE pointer used for handling files in fileio.c. Pass
by reference instead. This allows the mg startup file to open other
files without unexpected things happening.

Discussed with Sunil Nimmagadda.


# 1.120 12-Apr-2012 lum

Remove the conditional directives NO_MACRO and NO_STARTUP.
They have not compiled for numerous years.
ok kjell@ millert@


# 1.119 11-Apr-2012 lum

Add:
1. C-x h to mark whole buffer.
2. M-| to pipe current region to external command.
From Sunil Nimmagadda.

Feedback from deraadt@ and myself. ok for man page amendments from jmc@


Revision tags: OPENBSD_5_1_BASE
# 1.118 10-Dec-2011 lum

mail.c was removed 3 yrs 5 months ago.


# 1.117 28-Nov-2011 lum

Add some ctags support to mg. From Sunil Nimmagadda.

Man page review and suggestions from jmc@

Revewied and tested by myself, and ok deraadt@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.116 23-Jan-2011 kjell

Wrap basename,dirname with xbasename, xdirname funtions,
which have fewer special cases, and use the strlcpy/strlcat
src/dst/buffer len semantic. More portable to boot.
Discussion and feedback from Henri Kemppainen


# 1.115 18-Jan-2011 kjell

Add join-line, bound to M-^
Join the current line to the previous.

original diff by Henri Kemppainen. minor mod to add undo boundaries.
Thanks!


# 1.114 17-Jan-2011 kjell

Add back-to-indentation. (M-m)
Move the dot to the first non-whitespace character on the current line.
from Henri Kemppainen . ok theo


Revision tags: OPENBSD_4_8_BASE
# 1.113 30-Jun-2010 oga

you keep saying LIST_END. I do not think it means what you think it
means.

If we hit an OOM condition, mg started to try and dump the older undo buffer
entries in order to be able to continue. OTOH, it was grabbing this entry with
LIST_END, which like all *_END() list macros evaluates to NULL.

Do what we actually want and switch that list to a TAILQ and use
TAILQ_LAST to grab the last entry.

Wrote this a loooooong time ago after a mail from Matthew Dempsky on
bugs@. ok kjell@, beck@ also looked at this months ago and thought it
was alright.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.112 05-Jun-2009 kjell

emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end,
the latter at the beginning of the region.

emacs is wacky.

Make mg undo do the same. ok deraadt


# 1.111 04-Jun-2009 kjell

Add the notion of an "ephemeral" popup, so we can flag a window
for destruction at a later date. (in the process, add a window flag field)

This fixes an issue noted by maja: namely, the *completion*
window that pops up when you try to complete a filename on
buffer load would destroy any second window that you happened
to have open.

ok maja@


# 1.110 04-Jun-2009 kjell

Fix problem where line numbers get out of sync on a region-kill (C-w).
Noticed and ok matthieu@


# 1.109 04-Jun-2009 kjell

Rename w_flag to w_rflag. This is not a general purpose
flag: it is for redisplay options only. I need an additional all-purpose
flag, so renaming removes the desire to wrongly overload the existing one.

Turdshine. No functional chage.


Revision tags: OPENBSD_4_5_BASE
# 1.108 15-Sep-2008 kjell

Expose the undo commands as proper mg functions.
This should have no functional change on undo, but it does facilitate
testing undo behavior.


# 1.107 15-Sep-2008 kjell

Enable dirty buffer detection in mg.
Emulate the emacs behavior: after suspend/resume, buffer switch,
or at save time, warn (prompt) the user if the file has been modified
on disk in the interim.
This has already saved my butt numerous times.
ok phessler


Revision tags: OPENBSD_4_4_BASE
# 1.106 14-Jun-2008 kjell

Add compile (c-C c-P) to the c-mode keymap (export from grep.c)
Also, attempt to make indent an atomic undo operation.


# 1.105 14-Jun-2008 kjell

unf*ck undo.
No seriously. Reposition the cursor to the start of the redo
position, like emacs. This gets us halfway to being emacs-finger-friendly.
For the rest, introduce a rptcount variable to count successive invocations
of the same function. This means undo will abort properly on C-g, and
other such interruptions.
This is a lot of diff for a simple-seeming problem. Emacs undo is hard.


# 1.104 13-Jun-2008 kjell

phessler noted that c-mode ignored blinking braces.
Add "c-handle-special-brace" which does a blink and indent, rather
than just a selfinsert and indent


# 1.103 12-Jun-2008 kjell

Introduce a basic c-mode to mg.

The intent of this mode is NOT to copy emacs's monster cc-mode.
It is intended to handle basic KNF-format C, assisting
with indentation (to catch obvious typos), and strip
trailing whitespace. It is NOT enabled unless you ask for it (c-mode).

Basically, tab on start-of-line whitespace acts like tab.
Otherwise, tab indents.

Please try it out and let me know where it falls down.

Feedback Reyk, phessler. "hack in tree" from henning, theo


# 1.102 11-Jun-2008 kjell

Add delete-leading-space, delete-trailing-space,
indent-current-line utility functions for stripping leading/trailing
whitespace, and setting a fixed indent respectively.


# 1.101 10-Jun-2008 kjell

Add a clear-mark function.
Use it to clear the region it is copied (M-w), or yanked (C-w).
This matches xemacs behavior, is not horribly different from gnu
emacs, and way less wrong than the current behavior.
Noticed by Han Boetes. ok otto@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.100 28-May-2007 kjell

Add a global-wd-mode command, which toggles between the current
behavior (every buffer maintains its own cwd) and the old behavior of
one global working directory. This makes it slightly easier to hack
on things like kernel code, where compilation, etc, are initiated from
a different directory than you are working in.
While here, fix setting/handling of global wd.


Revision tags: OPENBSD_4_1_BASE
# 1.99 21-Feb-2007 deanna

Fix a reference to WFHARD in a comment; it was renamed WFFULL months
ago.

ok kjell


# 1.98 19-Nov-2006 deraadt

spacing


# 1.97 17-Nov-2006 kjell

Fix a needless inversion of flag names; i.e. change them from the
negative to the positive. undo_boundary_enable(TRUE) makes a LOT more
sense than undo_no_boundary(FALSE).
While here, whack a global, and fix a bug noted by otto:
undoing a file insertion sometimes left stray characters around.
ok beck@, otto@


Revision tags: OPENBSD_4_0_BASE
# 1.96 01-Aug-2006 jason

* move sys/queue.h inclusion to sysdef.h (it's system specific)
* add <signal.h> to sysdef.h (needed for sig_atomic_t on linux, and
we get it by accident on OpenBSD)
* remove <signal.h> from tty.c/spawn.c (not needed now that it's in sysdef.h)
ok beck


# 1.95 25-Jul-2006 kjell

Add bfirstlp(), blastlp() macros, returning the first and last lines
of a buffer respectively. Removes an ugly construction than necessitated
"go to first line"-type comments throughout the code.
No binary change


# 1.94 25-Jul-2006 kjell

Rename the header line of a buffer to b_headp, from the remarkably
unintuitive b_linep. No binary change.


# 1.93 08-Jul-2006 kjell

Introduce a 'MODIFIED' boundary type for undo records.
This allows undo to clear the modified flag when undo-ing all the way
from a loaded buffer.
Originally whipped up at c2k6 after proddings from beck.
jason@ ok.


# 1.92 01-Jun-2006 kjell

Display line number in the mg statusbar. Yes, it seems like a fugly
way to do it, but all the clever and pretty ways utterly failed.
Basic use seems fine. We'll turdshine the special cases later.

If it bothers you, use M-x line-number-mode, or put same in your ~/.mg
file to disable.

ok cloder, jason


# 1.91 01-Jun-2006 jason

make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder


# 1.90 29-May-2006 kjell

Another mnemonic rename, missed the first time.
Also missed the ok cloder.


# 1.89 28-May-2006 kjell

Make Window Flags more mnemonic (and less dumb); i.e.
WFHARD -> WFFULL (Redraw full window)
WFFORCE -> WFFRAME (Reframe window).
No binary change


# 1.88 27-May-2006 kjell

Move mg "line to c-string" functionality to a function.


# 1.87 08-May-2006 kjell

spacing


# 1.86 02-May-2006 kjell

Make buffers store their own working directory. This makes things like
grep, compile, lint work as expected (act on current buffer's cwd).
Display this path when opening or replacing a file, rather than
relying on the user to guess, or remember.


# 1.85 06-Apr-2006 kjell

Fix a bug whereby a written buffer (^X^W) would not have the correct
trailing buffer number appended (e.g. "file<2>") in case an existing
buffer shared its basename().


# 1.84 03-Apr-2006 kjell

fixed "text in message line would get stuck there" issue.
feedback from Philip Guenther and Han Boetes


Revision tags: OPENBSD_3_9_BASE
# 1.83 25-Feb-2006 otto

Fix a coredump occurring when the terminal is resized while mg is
suspended. Problem reported and fixed tested by reyk@; tweak by
kjell@; ok kjell@


# 1.82 20-Dec-2005 kjell

Clean up the ugly casted frees. In one case, this meant eliminating a nasty
struct/union/casting nightmare when building the list of names for filename
completion. In particular, be consistent about strduping and freeing
the list data.


# 1.81 13-Dec-2005 kjell

Last round of easy delinting.


# 1.80 13-Dec-2005 kjell

More name-clash delinting


# 1.79 13-Dec-2005 kjell

If you're going to pass a length parameter, you should use it.


# 1.78 22-Nov-2005 kjell

Move kill-related commands to their own file.
This will help move to a kill-ring.


# 1.77 20-Nov-2005 deraadt

toast NO_DIRED #ifdef; ok kjell


# 1.76 18-Nov-2005 kjell

Split kill buffer code into a separate function.


# 1.75 18-Nov-2005 kjell

clean up some comments after theo's cleanup


# 1.74 18-Nov-2005 deraadt

greedy use of typedef struct was making code harder to read; ok kjell cloder


# 1.73 18-Nov-2005 kjell

Casefold on replace was killed ages ago (it was wrong). Remove a
leftover (unused) variable.


# 1.72 07-Nov-2005 kjell

Move most of the dired hooks into dired.c. While here, enable some
dired functions that were written, but not bound to keys. No other
functional change.

Tested by Han Boetes.


# 1.71 14-Oct-2005 kjell

move the dired routines into dired.c where they belong.
ok cloder@


# 1.70 13-Oct-2005 kjell

Make dired buffer read-only by default.
Noticed by Han Boetes


# 1.69 13-Oct-2005 kjell

Use dired mode automatically if file specified for loading is
a directory. Modified version of patch from Han Boetes.
ok cloder@


# 1.68 13-Oct-2005 kjell

Make mg's grep and compile more path-aware, by defaulting to
the path of the invoking buffer.
Also, make subshell output look more like emacs (show directory,
completion time). oked at one point by deraadt@


# 1.67 11-Oct-2005 kjell

A while back, undo records were moved from the BUFFER struct to MGWIN.
This is nonsensical, and utterly broken if you are undo-ing across
multiple buffers. Change them back to being associated with the BUFFER
struct. (effectively, just revert the original change)

ok deraadt@


# 1.66 11-Oct-2005 kjell

Enable the 'next-error' (C-x `) keybinding by default.
Niklas, this one is for you.
ok deraadt@, cloder@


# 1.65 06-Oct-2005 kjell

Make mg undo much more emacs like (and correct).
Undo boundaries are now placed at newlines, and undo
of search-replace works as expected. Fixes bad behaviour
reported by matthieu

Ok deraadt@, beck@


Revision tags: OPENBSD_3_8_BASE
# 1.64 14-Jun-2005 kjell

Add explicit public domain notices to all public domain files.
ok millert@, deraadt@


# 1.63 31-May-2005 kjell

fix broken minibuffer defaults introduced in echo.c:1.33
adds eread flag EFDEF allowing null minibuffer response
noticed by otto
ok cloder@ jason@, works otto@


# 1.62 30-May-2005 jason

add find-alternate-file command and binding for ^X^V; ok cloder
(you're welcome kjell)


# 1.61 27-May-2005 cloder

Add emacs-style replace-string function that does not prompt you
to confirm replacements.
OK jason, deraadt


# 1.60 03-Apr-2005 db

This is a no binary change which does:

- spelling, punctuation fixes
- variable declaration lineup
- use parentheses for return and sizeof
- K&R function declarations -> ANSI
- other minor code beautification

ok henning@


Revision tags: OPENBSD_3_7_BASE
# 1.59 12-Mar-2005 deraadt

spacing


# 1.58 10-Mar-2005 henning

fix more BACKUP/NOBACKUP/NO_BACKUP confusion, again no binary change.
spotted by jmc@


# 1.57 09-Mar-2005 jfb

fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.

ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@


Revision tags: OPENBSD_3_6_BASE
# 1.56 22-Jul-2004 vincent

stage 1 of the infinite minibuffer work - add support for on the fly
buffer reallocation in veread(). This commit only changes the API.
All the buffers have exactly the same bounds as before for now.

tested by a couple of my very helpful testers!


# 1.55 09-Jul-2004 vincent

when saving a file, check whether it is newline terminated and if it is not,
prompt the user and add the newline if he agrees.

tested by a lot of helpful tech@ guys, approved by henning


Revision tags: OPENBSD_3_5_BASE
# 1.54 27-Jan-2004 vincent

make mail-mode more intelligent on middle-of-line insertions, and add a
comment to change the wrapping column. (mail-set-margin)

tested by henning and phessler, thanks!


# 1.53 29-Nov-2003 vincent

save the previous undo position as an offset in the buffer instead of
a line/offset pair


# 1.52 09-Nov-2003 vincent

remove the only use of the hackish undo_add_custom function.


# 1.51 09-Nov-2003 vincent

remove unused structure element


# 1.50 27-Oct-2003 vincent

fix crash on startup by using the good allocation routine in edinit()

spotted and ok by henning


# 1.49 21-Oct-2003 vincent

make undo records per MGWIN, not per BUFFER...


Revision tags: OPENBSD_3_4_BASE
# 1.48 15-Aug-2003 vincent

make dired work more like emacs. (well, make it _work_, and then add a
bunch of missing commands)


# 1.47 26-Jun-2003 vincent

protos

ok deraadt


# 1.46 05-May-2003 vincent

add a mail-mode, to do automatic line-wrapping.

(at the same time, change the command line parsing to support a
-f <mode> that is slightly different from the one in gnu emacs,
we apply it to all buffers created from command line arguments,
so you can use "mg -f mail-mode" as your editor. manpage change
coming soon)

ok henning


Revision tags: OPENBSD_3_3_BASE
# 1.45 06-Jan-2003 deraadt

support +number; rewritten from buggy code by mjc@bitz.ca, vincent ok


Revision tags: OPENBSD_3_2_BASE
# 1.44 24-Jul-2002 vincent

remove the CHANGE undo record type, use a combination of delete and insert
to have the same behavior in a simpler way.

ok art@


# 1.43 01-Jul-2002 vincent

KNF + ansi; from zyrnix (only the easy part of his diffs)


# 1.42 21-Jun-2002 vincent

remove the "extern" for a variable that does not exist anymore.


# 1.41 29-May-2002 vincent

add an "auto-execute" feature, that allows binding function calls to
certain patterns. for example, `auto-execute "*.c" auto-indent-mode'.

ok art@


# 1.40 29-May-2002 vincent

add a function to visit a file read-only mapped to C-x C-v

ok art@


Revision tags: OPENBSD_3_1_BASE
# 1.39 18-Mar-2002 vincent

Enter the new undo code. it is still disabled since it has bugs, but it's
somewhat more useful....

ok millert@ + no objections on ICB


# 1.38 16-Mar-2002 vincent

This should've been commited yesterday, before the funmap change.

ok millert@


# 1.37 16-Mar-2002 vincent

add readonly buffer support
plus some KNF

ok art@


# 1.36 11-Mar-2002 vincent

* Move to ANSI function definitions.
* Add a whole lot of consts where I thought it made sense

no ok, but no objections either...


# 1.35 26-Feb-2002 vincent

keep undo records in the BUFFER structures insteda of having a huge list.


# 1.34 21-Feb-2002 deraadt

KNF


# 1.33 21-Feb-2002 vincent

Save undo records for newline insertions.

That makes mg behave more like GNU emacs.


# 1.32 21-Feb-2002 vincent

Don't ignore the argument to undo. (makes ^U work)


# 1.31 21-Feb-2002 deraadt

signal-safe window size changing


# 1.30 20-Feb-2002 vincent

Add undo code to mg.

needs further hacking.

ok `whole bunch of people on icb'@


# 1.29 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.28 14-Feb-2002 vincent

d_makename now takes a length parameter so we can remove the
strcpy call.


# 1.27 14-Feb-2002 deraadt

spelling


# 1.26 13-Feb-2002 vincent

Make mg malloc the l_text element instead of reallocating whole LINE
structures all the time.


# 1.25 13-Feb-2002 vincent

* Replace unsafe strcpy and strcat calls to safe strlcpy and strlcat.
* Be a little bit more verbose about some errors
* Fix some memory leaks in fileio.c

ok deraadt@, art@


# 1.24 18-Jan-2002 art

Remove the NROW and NCOL limits. The static arrays are now replaced with
dynamically allocated memory.
Code written by Vincent Labrecque <limitln@Psyfreaks.CA> with some minor
tweaks by me.


# 1.23 10-Jan-2002 art

Clean up tty resizing code.
Catch SIGWINCH and resize and refresh the screen.


# 1.22 08-Jan-2002 millert

typo; mjc@bitz.ca


Revision tags: OPENBSD_3_0_BASE
# 1.21 24-May-2001 art

Make the keymap/mode table growable in runtime.


# 1.20 24-May-2001 art

Add a missing piece of something I committed by accident that I
planned to add later.

A new flag to veread (and caller) called EFDEF that indicates that
when a user is prompted for input, a default value is given from start
in the output buffer.


# 1.19 24-May-2001 art

Break out function -> name mappings to an own file.
Add a possibility to dynamically extend the function table.


# 1.18 24-May-2001 mickey

spaces


# 1.17 23-May-2001 mickey

cinfo is const, keyname() and findbind() take buffer size to use strlcpy vs cpy+len


# 1.16 23-May-2001 art

remove VOID. We're way beyond the point where this could build with an
ancient compiler.


# 1.15 23-May-2001 art

No need to export nfunct and functnames now that help doesn't use them
anymore. nfunct isn't used anywhere.


# 1.14 23-May-2001 art

export free_file_list. XXX - it doesn't belong in echo.c and it's the wrong name.


# 1.13 23-May-2001 art

kill complete_function. Not used anymore.


# 1.12 23-May-2001 art

It's unnecessary to have addline as a function. Make it a macro.


# 1.11 23-May-2001 art

Add addlinef that's an addline with printf-style format arguments.
Make addline a wrapper around addlinef. (should go away)


# 1.10 04-May-2001 art

Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.


# 1.9 03-May-2001 art

Add a delay (in miliseconds) argument to ttwait.


# 1.8 03-May-2001 art

* Let make_file_list always append a '/' at the end of directories.
This makes filename TAB-completion more useful, now you don't need to
write that '/' manually.
* random cleanups including using snprintf and memcmp where open-coded
equivalents were used, waitpid instead of 'while (wait() != pid);', etc.


# 1.7 01-May-2001 art

raise the file name and buffer name sizes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 01-Sep-2000 millert

More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org


Revision tags: OPENBSD_2_7_BASE
# 1.4 13-Apr-2000 millert

The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...


# 1.3 26-Feb-2000 millert

change WINDOW -> MGWIN to avoid curses type conflict
convert to terminfo in tty*.c
add support for some keypad function keys (arrows, pgup, pgdown)


# 1.2 25-Feb-2000 deraadt

further pruning


# 1.1 25-Feb-2000 deraadt

initial import of mg2a