summaryrefslogtreecommitdiff
path: root/usr.bin/mg/line.c
diff options
context:
space:
mode:
authorKjell Wooding <kjell@cvs.openbsd.org>2008-09-15 16:11:36 +0000
committerKjell Wooding <kjell@cvs.openbsd.org>2008-09-15 16:11:36 +0000
commit0b98546c7b94e0858d8daad1b96091ba91734f4b (patch)
treea824218a33febe86c0f0ce465826995eb14ac4d4 /usr.bin/mg/line.c
parente6982e59f67d19b6b66304773514f3792a0c5eb6 (diff)
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
Diffstat (limited to 'usr.bin/mg/line.c')
-rw-r--r--usr.bin/mg/line.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/usr.bin/mg/line.c b/usr.bin/mg/line.c
index ac600887381..4d0565e0afe 100644
--- a/usr.bin/mg/line.c
+++ b/usr.bin/mg/line.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: line.c,v 1.44 2006/12/24 01:20:53 kjell Exp $ */
+/* $OpenBSD: line.c,v 1.45 2008/09/15 16:11:35 kjell Exp $ */
/* This file is in the public domain. */
@@ -142,7 +142,10 @@ linsert_str(const char *s, int n)
struct line *lp1;
struct mgwin *wp;
RSIZE i;
- int doto;
+ int doto, k;
+
+ if ((k = checkdirty(curbp)) != TRUE)
+ return (k);
if (curbp->b_flag & BFREADONLY) {
ewprintf("Buffer is read only");
@@ -233,10 +236,14 @@ linsert(int n, int c)
struct mgwin *wp;
RSIZE i;
int doto;
+ int s;
if (!n)
return (TRUE);
+ if ((s = checkdirty(curbp)) != TRUE)
+ return (s);
+
if (curbp->b_flag & BFREADONLY) {
ewprintf("Buffer is read only");
return (FALSE);
@@ -388,6 +395,10 @@ lnewline_at(struct line *lp1, int doto)
int
lnewline(void)
{
+ int s;
+
+ if ((s = checkdirty(curbp)) != TRUE)
+ return (s);
if (curbp->b_flag & BFREADONLY) {
ewprintf("Buffer is read only");
return (FALSE);
@@ -414,7 +425,10 @@ ldelete(RSIZE n, int kflag)
size_t len;
char *sv;
int end;
+ int s;
+ if ((s = checkdirty(curbp)) != TRUE)
+ return (s);
if (curbp->b_flag & BFREADONLY) {
ewprintf("Buffer is read only");
return (FALSE);
@@ -497,7 +511,10 @@ ldelnewline(void)
{
struct line *lp1, *lp2, *lp3;
struct mgwin *wp;
+ int s;
+ if ((s = checkdirty(curbp)) != TRUE)
+ return (s);
if (curbp->b_flag & BFREADONLY) {
ewprintf("Buffer is read only");
return (FALSE);
@@ -571,7 +588,10 @@ int
lreplace(RSIZE plen, char *st)
{
RSIZE rlen; /* replacement length */
+ int s;
+ if ((s = checkdirty(curbp)) != TRUE)
+ return (s);
if (curbp->b_flag & BFREADONLY) {
ewprintf("Buffer is read only");
return (FALSE);