1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-06-03 19:10:42 +00:00

Review windows update when reading or writing buffers to file.

This commit is contained in:
Renaud 2016-04-01 13:25:05 +08:00
parent af23c6b3b5
commit 16e6f87ad5

115
file.c
View File

@ -64,7 +64,7 @@ boolean resterr( void) {
/* /*
* Read a file into the current * Read a file into the current
* buffer. This is really easy; all you do it * buffer. This is really easy; all you do is
* find the name of the file, and call the standard * find the name of the file, and call the standard
* "read a file into the current buffer" code. * "read a file into the current buffer" code.
* Bound to "C-X C-R". * Bound to "C-X C-R".
@ -87,7 +87,7 @@ int fileread( int f, int n) {
/* /*
* Insert a file into the current * Insert a file into the current
* buffer. This is really easy; all you do it * buffer. This is really easy; all you do is
* find the name of the file, and call the standard * find the name of the file, and call the standard
* "insert a file into the current buffer" code. * "insert a file into the current buffer" code.
* Bound to "C-X C-I". * Bound to "C-X C-I".
@ -111,7 +111,7 @@ int insfile( int f, int n) {
if( status != TRUE) if( status != TRUE)
return status ; return status ;
return reposition( TRUE, -1) ; return reposition( TRUE, -1) ; /* Redraw with dot at bottom of window */
} }
/* /*
@ -139,6 +139,15 @@ int filefind( int f, int n) {
return status ; return status ;
} }
static void upd_mode( void) {
struct window *wp ;
/* Update mode lines */
for( wp = wheadp ; wp != NULL ; wp = wp->w_wndp)
if( wp->w_bufp == curbp)
wp->w_flag |= WFMODE ;
}
int viewfile( int f, int n) { /* visit a file in VIEW mode */ int viewfile( int f, int n) { /* visit a file in VIEW mode */
char *fname ; /* file user wishes to find */ char *fname ; /* file user wishes to find */
int status ; /* status return */ int status ; /* status return */
@ -150,18 +159,10 @@ int viewfile( int f, int n) { /* visit a file in VIEW mode */
if( status == TRUE) { if( status == TRUE) {
status = getfile(fname, FALSE) ; status = getfile(fname, FALSE) ;
free( fname) ; free( fname) ;
}
if( status == TRUE) { /* if we succeed, put it in view mode */ if( status == TRUE) { /* if we succeed, put it in view mode */
struct window *wp ; /* scan for windows that need updating */
curwp->w_bufp->b_mode |= MDVIEW ; curwp->w_bufp->b_mode |= MDVIEW ;
upd_mode() ;
/* scan through and update mode lines of all windows */
wp = wheadp ;
while( wp != NULL) {
wp->w_flag |= WFMODE ;
wp = wp->w_wndp ;
} }
} }
@ -174,32 +175,42 @@ int viewfile( int f, int n) { /* visit a file in VIEW mode */
* char fname[]; file name to find * char fname[]; file name to find
* boolean lockfl; check the file for locks? * boolean lockfl; check the file for locks?
*/ */
int getfile( const char *fname, boolean lockfl) int getfile( const char *fname, boolean lockfl) {
{
struct buffer *bp; struct buffer *bp;
struct line *lp;
int i;
int s; int s;
bname_t bname ; /* buffer name to put file */ bname_t bname ; /* buffer name to put file */
#if MSDOS /* Is the file in current buffer? */
mklower(fname); /* msdos isn't case sensitive */ if( strcmp( curbp->b_fname, fname) == 0) {
#endif mloutstr( "(Current buffer)") ;
for (bp = bheadp; bp != NULL; bp = bp->b_bufp) { return TRUE ;
if ((bp->b_flag & BFINVS) == 0 }
&& strcmp(bp->b_fname, fname) == 0) {
swbuffer(bp); /* Is the file in any buffer? */
lp = curwp->w_dotp; for( bp = bheadp; bp != NULL; bp = bp->b_bufp) {
i = curwp->w_ntrows / 2; if( (bp->b_flag & BFINVS) == 0
while (i-- && lback(lp) != curbp->b_linep) && strcmp( bp->b_fname, fname) == 0) {
lp = lback(lp); line_p lp ;
curwp->w_linep = lp; int i ;
curwp->w_flag |= WFMODE | WFHARD;
cknewwindow(); swbuffer( bp) ;
/* Center dotted line in window */
i = curwp->w_ntrows / 2 ;
for( lp = curwp->w_dotp ; lback( lp) != curbp->b_linep ; lp = lback( lp))
if( i-- == 0)
break ;
curwp->w_linep = lp ;
/* Refresh window */
curwp->w_flag |= WFMODE | WFHARD ;
cknewwindow() ;
mloutstr( "(Old buffer)") ; mloutstr( "(Old buffer)") ;
return TRUE; return TRUE ;
} }
} }
makename(bname, fname); /* New buffer name. */ makename(bname, fname); /* New buffer name. */
while ((bp = bfind(bname, FALSE, 0)) != NULL) { while ((bp = bfind(bname, FALSE, 0)) != NULL) {
char *new_bname ; char *new_bname ;
@ -450,19 +461,8 @@ int filewrite( int f, int n) {
status = FALSE ; status = FALSE ;
else { else {
status = writeout( fname) ; status = writeout( fname) ;
if( status == TRUE) { if( status == TRUE)
struct window *wp ;
strcpy( curbp->b_fname, fname) ; strcpy( curbp->b_fname, fname) ;
curbp->b_flag &= ~BFCHG ;
wp = wheadp ; /* Update mode lines. */
while( wp != NULL) {
if( wp->w_bufp == curbp)
wp->w_flag |= WFMODE ;
wp = wp->w_wndp ;
}
}
} }
free( fname) ; free( fname) ;
@ -479,11 +479,7 @@ int filewrite( int f, int n) {
* name for the buffer. Bound to "C-X C-S". May * name for the buffer. Bound to "C-X C-S". May
* get called by "C-Z". * get called by "C-Z".
*/ */
int filesave(int f, int n) int filesave( int f, int n) {
{
struct window *wp;
int s;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */ return rdonly(); /* we are in read only mode */
if ((curbp->b_flag & BFCHG) == 0) /* Return, no changes. */ if ((curbp->b_flag & BFCHG) == 0) /* Return, no changes. */
@ -501,16 +497,7 @@ int filesave(int f, int n)
} }
} }
if ((s = writeout(curbp->b_fname)) == TRUE) { return writeout( curbp->b_fname) ;
curbp->b_flag &= ~BFCHG;
wp = wheadp; /* Update mode lines. */
while (wp != NULL) {
if (wp->w_bufp == curbp)
wp->w_flag |= WFMODE;
wp = wp->w_wndp;
}
}
return s;
} }
/* /*
@ -548,6 +535,8 @@ int writeout( const char *fn) {
mloutstr( "Error closing file") ; mloutstr( "Error closing file") ;
else { /* Successfull write and close. */ else { /* Successfull write and close. */
mloutfmt( "(Wrote %d line%s)", nline, &"s"[ nline == 1]) ; mloutfmt( "(Wrote %d line%s)", nline, &"s"[ nline == 1]) ;
curbp->b_flag &= ~BFCHG ;
upd_mode() ;
return TRUE ; return TRUE ;
} }
} }
@ -565,7 +554,6 @@ int writeout( const char *fn) {
* prompt if you wish. * prompt if you wish.
*/ */
int filename( int f, int n) { int filename( int f, int n) {
struct window *wp ;
int status ; int status ;
char *fname ; char *fname ;
@ -583,15 +571,8 @@ int filename( int f, int n) {
free( fname) ; free( fname) ;
} }
wp = wheadp ; /* Update mode lines. */
while( wp != NULL) {
if( wp->w_bufp == curbp)
wp->w_flag |= WFMODE ;
wp = wp->w_wndp ;
}
curbp->b_mode &= ~MDVIEW ; /* no longer read only mode */ curbp->b_mode &= ~MDVIEW ; /* no longer read only mode */
upd_mode() ;
return TRUE ; return TRUE ;
} }