summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2005-06-07 21:02:10 +0000
committerBram Moolenaar <Bram@vim.org>2005-06-07 21:02:10 +0000
commit631d6f6847c5566e574ab25558747f2e13f97580 (patch)
tree8ed726a37cce32a4b56a7cb6959fc71def41482b
parentb765d63491c7daec0654a4139bb3b45ceab6c218 (diff)
updated for version 7.0082
-rw-r--r--src/fileio.c245
1 files changed, 128 insertions, 117 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 5b27b6243a..e239b5cd88 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -6156,154 +6156,165 @@ buf_check_timestamp(buf, focus)
}
if (reload)
- {
- exarg_T ea;
- pos_T old_cursor;
- linenr_T old_topline;
- int old_ro = buf->b_p_ro;
- buf_T *savebuf;
- int saved = OK;
+ /* Reload the buffer. */
+ buf_reload(buf);
+
+#ifdef FEAT_GUI
+ /* restore this in case an autocommand has set it; it would break
+ * 'mousefocus' */
+ need_mouse_correct = save_mouse_correct;
+#endif
+
+ return retval;
+}
+
+/*
+ * Reload a buffer that is already loaded.
+ * Used when the file was changed outside of Vim.
+ */
+ void
+buf_reload(buf)
+ buf_T *buf;
+{
+ exarg_T ea;
+ pos_T old_cursor;
+ linenr_T old_topline;
+ int old_ro = buf->b_p_ro;
+ int orig_mode = buf->b_orig_mode;
+ buf_T *savebuf;
+ int saved = OK;
#ifdef FEAT_AUTOCMD
- aco_save_T aco;
+ aco_save_T aco;
- /* set curwin/curbuf for "buf" and save some things */
- aucmd_prepbuf(&aco, buf);
+ /* set curwin/curbuf for "buf" and save some things */
+ aucmd_prepbuf(&aco, buf);
#else
- buf_T *save_curbuf = curbuf;
+ buf_T *save_curbuf = curbuf;
- curbuf = buf;
- curwin->w_buffer = buf;
+ curbuf = buf;
+ curwin->w_buffer = buf;
#endif
- /* We only want to read the text from the file, not reset the syntax
- * highlighting, clear marks, diff status, etc. Force the fileformat
- * and encoding to be the same. */
- if (prep_exarg(&ea, buf) == OK)
- {
- old_cursor = curwin->w_cursor;
- old_topline = curwin->w_topline;
+ /* We only want to read the text from the file, not reset the syntax
+ * highlighting, clear marks, diff status, etc. Force the fileformat
+ * and encoding to be the same. */
+ if (prep_exarg(&ea, buf) == OK)
+ {
+ old_cursor = curwin->w_cursor;
+ old_topline = curwin->w_topline;
- /*
- * To behave like when a new file is edited (matters for
- * BufReadPost autocommands) we first need to delete the current
- * buffer contents. But if reading the file fails we should keep
- * the old contents. Can't use memory only, the file might be
- * too big. Use a hidden buffer to move the buffer contents to.
- */
- if (bufempty())
- savebuf = NULL;
- else
+ /*
+ * To behave like when a new file is edited (matters for
+ * BufReadPost autocommands) we first need to delete the current
+ * buffer contents. But if reading the file fails we should keep
+ * the old contents. Can't use memory only, the file might be
+ * too big. Use a hidden buffer to move the buffer contents to.
+ */
+ if (bufempty())
+ savebuf = NULL;
+ else
+ {
+ /* Allocate a buffer without putting it in the buffer list. */
+ savebuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY);
+ if (savebuf != NULL)
{
- /* Allocate a buffer without putting it in the buffer list. */
- savebuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY);
- if (savebuf != NULL)
- {
- /* Open the memline. */
- curbuf = savebuf;
- curwin->w_buffer = savebuf;
- saved = ml_open();
- curbuf = buf;
- curwin->w_buffer = buf;
- }
- if (savebuf == NULL || saved == FAIL
- || move_lines(buf, savebuf) == FAIL)
- {
- EMSG2(_("E462: Could not prepare for reloading \"%s\""),
- buf->b_fname);
- saved = FAIL;
- }
+ /* Open the memline. */
+ curbuf = savebuf;
+ curwin->w_buffer = savebuf;
+ saved = ml_open();
+ curbuf = buf;
+ curwin->w_buffer = buf;
}
-
- if (saved == OK)
+ if (savebuf == NULL || saved == FAIL
+ || move_lines(buf, savebuf) == FAIL)
{
- curbuf->b_flags |= BF_CHECK_RO; /* check for RO again */
+ EMSG2(_("E462: Could not prepare for reloading \"%s\""),
+ buf->b_fname);
+ saved = FAIL;
+ }
+ }
+
+ if (saved == OK)
+ {
+ curbuf->b_flags |= BF_CHECK_RO; /* check for RO again */
#ifdef FEAT_AUTOCMD
- keep_filetype = TRUE; /* don't detect 'filetype' */
+ keep_filetype = TRUE; /* don't detect 'filetype' */
#endif
- if (readfile(buf->b_ffname, buf->b_fname, (linenr_T)0,
- (linenr_T)0,
- (linenr_T)MAXLNUM, &ea, READ_NEW) == FAIL)
- {
+ if (readfile(buf->b_ffname, buf->b_fname, (linenr_T)0,
+ (linenr_T)0,
+ (linenr_T)MAXLNUM, &ea, READ_NEW) == FAIL)
+ {
#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
- if (!aborting())
+ if (!aborting())
#endif
- EMSG2(_("E321: Could not reload \"%s\""), buf->b_fname);
- if (savebuf != NULL)
- {
- /* Put the text back from the save buffer. First
- * delete any lines that readfile() added. */
- while (!bufempty())
- if (ml_delete(curbuf->b_ml.ml_line_count, FALSE)
- == FAIL)
- break;
- (void)move_lines(savebuf, buf);
- }
- }
- else
+ EMSG2(_("E321: Could not reload \"%s\""), buf->b_fname);
+ if (savebuf != NULL)
{
- /* Mark the buffer as unmodified and free undo info. */
- unchanged(buf, TRUE);
- u_blockfree(buf);
- u_clearall(buf);
+ /* Put the text back from the save buffer. First
+ * delete any lines that readfile() added. */
+ while (!bufempty())
+ if (ml_delete(curbuf->b_ml.ml_line_count, FALSE)
+ == FAIL)
+ break;
+ (void)move_lines(savebuf, buf);
}
}
- vim_free(ea.cmd);
+ else
+ {
+ /* Mark the buffer as unmodified and free undo info. */
+ unchanged(buf, TRUE);
+ u_blockfree(buf);
+ u_clearall(buf);
+ }
+ }
+ vim_free(ea.cmd);
- if (savebuf != NULL)
- wipe_buffer(savebuf, FALSE);
+ if (savebuf != NULL)
+ wipe_buffer(savebuf, FALSE);
#ifdef FEAT_DIFF
- /* Invalidate diff info if necessary. */
- diff_invalidate();
+ /* Invalidate diff info if necessary. */
+ diff_invalidate();
#endif
- /* Restore the topline and cursor position and check it (lines may
- * have been removed). */
- if (old_topline > curbuf->b_ml.ml_line_count)
- curwin->w_topline = curbuf->b_ml.ml_line_count;
- else
- curwin->w_topline = old_topline;
- curwin->w_cursor = old_cursor;
- check_cursor();
- update_topline();
+ /* Restore the topline and cursor position and check it (lines may
+ * have been removed). */
+ if (old_topline > curbuf->b_ml.ml_line_count)
+ curwin->w_topline = curbuf->b_ml.ml_line_count;
+ else
+ curwin->w_topline = old_topline;
+ curwin->w_cursor = old_cursor;
+ check_cursor();
+ update_topline();
#ifdef FEAT_AUTOCMD
- keep_filetype = FALSE;
+ keep_filetype = FALSE;
#endif
#ifdef FEAT_FOLDING
- {
- win_T *wp;
+ {
+ win_T *wp;
- /* Update folds unless they are defined manually. */
- FOR_ALL_WINDOWS(wp)
- if (wp->w_buffer == curwin->w_buffer
- && !foldmethodIsManual(wp))
- foldUpdateAll(wp);
- }
-#endif
- /* If the mode didn't change and 'readonly' was set, keep the old
- * value; the user probably used the ":view" command. But don't
- * reset it, might have had a read error. */
- if (orig_mode == curbuf->b_orig_mode)
- curbuf->b_p_ro |= old_ro;
+ /* Update folds unless they are defined manually. */
+ FOR_ALL_WINDOWS(wp)
+ if (wp->w_buffer == curwin->w_buffer
+ && !foldmethodIsManual(wp))
+ foldUpdateAll(wp);
}
-
-#ifdef FEAT_AUTOCMD
- /* restore curwin/curbuf and a few other things */
- aucmd_restbuf(&aco);
- /* Careful: autocommands may have made "buf" invalid! */
-#else
- curwin->w_buffer = save_curbuf;
- curbuf = save_curbuf;
#endif
+ /* If the mode didn't change and 'readonly' was set, keep the old
+ * value; the user probably used the ":view" command. But don't
+ * reset it, might have had a read error. */
+ if (orig_mode == curbuf->b_orig_mode)
+ curbuf->b_p_ro |= old_ro;
}
-#ifdef FEAT_GUI
- /* restore this in case an autocommand has set it; it would break
- * 'mousefocus' */
- need_mouse_correct = save_mouse_correct;
+#ifdef FEAT_AUTOCMD
+ /* restore curwin/curbuf and a few other things */
+ aucmd_restbuf(&aco);
+ /* Careful: autocommands may have made "buf" invalid! */
+#else
+ curwin->w_buffer = save_curbuf;
+ curbuf = save_curbuf;
#endif
-
- return retval;
}
/*ARGSUSED*/