mirror of
https://github.com/rfivet/uemacs.git
synced 2024-12-18 15:26:23 -05:00
Review windows update when reading or writing buffers to file.
This commit is contained in:
parent
af23c6b3b5
commit
16e6f87ad5
97
file.c
97
file.c
@ -64,7 +64,7 @@ boolean resterr( void) {
|
||||
|
||||
/*
|
||||
* 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
|
||||
* "read a file into the current buffer" code.
|
||||
* Bound to "C-X C-R".
|
||||
@ -87,7 +87,7 @@ int fileread( int f, int n) {
|
||||
|
||||
/*
|
||||
* 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
|
||||
* "insert a file into the current buffer" code.
|
||||
* Bound to "C-X C-I".
|
||||
@ -111,7 +111,7 @@ int insfile( int f, int n) {
|
||||
if( status != TRUE)
|
||||
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 ;
|
||||
}
|
||||
|
||||
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 */
|
||||
char *fname ; /* file user wishes to find */
|
||||
int status ; /* status return */
|
||||
@ -150,18 +159,10 @@ int viewfile( int f, int n) { /* visit a file in VIEW mode */
|
||||
if( status == TRUE) {
|
||||
status = getfile(fname, FALSE) ;
|
||||
free( fname) ;
|
||||
}
|
||||
|
||||
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 ;
|
||||
|
||||
/* scan through and update mode lines of all windows */
|
||||
wp = wheadp ;
|
||||
while( wp != NULL) {
|
||||
wp->w_flag |= WFMODE ;
|
||||
wp = wp->w_wndp ;
|
||||
upd_mode() ;
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,32 +175,42 @@ int viewfile( int f, int n) { /* visit a file in VIEW mode */
|
||||
* char fname[]; file name to find
|
||||
* 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 line *lp;
|
||||
int i;
|
||||
int s;
|
||||
bname_t bname ; /* buffer name to put file */
|
||||
|
||||
#if MSDOS
|
||||
mklower(fname); /* msdos isn't case sensitive */
|
||||
#endif
|
||||
/* Is the file in current buffer? */
|
||||
if( strcmp( curbp->b_fname, fname) == 0) {
|
||||
mloutstr( "(Current buffer)") ;
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
/* Is the file in any buffer? */
|
||||
for( bp = bheadp; bp != NULL; bp = bp->b_bufp) {
|
||||
if( (bp->b_flag & BFINVS) == 0
|
||||
&& strcmp( bp->b_fname, fname) == 0) {
|
||||
line_p lp ;
|
||||
int i ;
|
||||
|
||||
swbuffer( bp) ;
|
||||
lp = curwp->w_dotp;
|
||||
|
||||
/* Center dotted line in window */
|
||||
i = curwp->w_ntrows / 2 ;
|
||||
while (i-- && lback(lp) != curbp->b_linep)
|
||||
lp = lback(lp);
|
||||
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)") ;
|
||||
return TRUE ;
|
||||
}
|
||||
}
|
||||
|
||||
makename(bname, fname); /* New buffer name. */
|
||||
while ((bp = bfind(bname, FALSE, 0)) != NULL) {
|
||||
char *new_bname ;
|
||||
@ -450,19 +461,8 @@ int filewrite( int f, int n) {
|
||||
status = FALSE ;
|
||||
else {
|
||||
status = writeout( fname) ;
|
||||
if( status == TRUE) {
|
||||
struct window *wp ;
|
||||
|
||||
if( status == TRUE)
|
||||
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) ;
|
||||
@ -479,11 +479,7 @@ int filewrite( int f, int n) {
|
||||
* name for the buffer. Bound to "C-X C-S". May
|
||||
* get called by "C-Z".
|
||||
*/
|
||||
int filesave(int f, int n)
|
||||
{
|
||||
struct window *wp;
|
||||
int s;
|
||||
|
||||
int filesave( int f, int n) {
|
||||
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
||||
return rdonly(); /* we are in read only mode */
|
||||
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) {
|
||||
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;
|
||||
return writeout( curbp->b_fname) ;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -548,6 +535,8 @@ int writeout( const char *fn) {
|
||||
mloutstr( "Error closing file") ;
|
||||
else { /* Successfull write and close. */
|
||||
mloutfmt( "(Wrote %d line%s)", nline, &"s"[ nline == 1]) ;
|
||||
curbp->b_flag &= ~BFCHG ;
|
||||
upd_mode() ;
|
||||
return TRUE ;
|
||||
}
|
||||
}
|
||||
@ -565,7 +554,6 @@ int writeout( const char *fn) {
|
||||
* prompt if you wish.
|
||||
*/
|
||||
int filename( int f, int n) {
|
||||
struct window *wp ;
|
||||
int status ;
|
||||
char *fname ;
|
||||
|
||||
@ -583,15 +571,8 @@ int filename( int f, int n) {
|
||||
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 */
|
||||
upd_mode() ;
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user