This commit is contained in:
ckelsel
2017-07-11 09:07:18 +08:00
committed by James McCoy
parent 2999d7c0e8
commit 462a6148a6
3 changed files with 57 additions and 49 deletions

View File

@@ -91,21 +91,21 @@ static char *e_auabort = N_("E855: Autocommands caused command to abort");
// Number of times free_buffer() was called. // Number of times free_buffer() was called.
static int buf_free_count = 0; static int buf_free_count = 0;
/* Read data from buffer for retrying. */ // Read data from buffer for retrying.
static int static int
read_buffer( read_buffer(
int read_stdin, /* read file from stdin, otherwise fifo */ int read_stdin, // read file from stdin, otherwise fifo
exarg_T *eap, /* for forced 'ff' and 'fenc' or NULL */ exarg_T *eap, // for forced 'ff' and 'fenc' or NULL
int flags) /* extra flags for readfile() */ int flags) // extra flags for readfile()
{ {
int retval = OK; int retval = OK;
linenr_T line_count; linenr_T line_count;
/* //
* Read from the buffer which the text is already filled in and append at // Read from the buffer which the text is already filled in and append at
* the end. This makes it possible to retry when 'fileformat' or // the end. This makes it possible to retry when 'fileformat' or
* 'fileencoding' was guessed wrong. // 'fileencoding' was guessed wrong.
*/ //
line_count = curbuf->b_ml.ml_line_count; line_count = curbuf->b_ml.ml_line_count;
retval = readfile( retval = readfile(
read_stdin ? NULL : curbuf->b_ffname, read_stdin ? NULL : curbuf->b_ffname,
@@ -113,27 +113,30 @@ read_buffer(
(linenr_T)line_count, (linenr_T)0, (linenr_T)MAXLNUM, eap, (linenr_T)line_count, (linenr_T)0, (linenr_T)MAXLNUM, eap,
flags | READ_BUFFER); flags | READ_BUFFER);
if (retval == OK) { if (retval == OK) {
/* Delete the binary lines. */ // Delete the binary lines.
while (--line_count >= 0) while (--line_count >= 0) {
ml_delete((linenr_T)1, FALSE); ml_delete((linenr_T)1, false);
}
} else { } else {
/* Delete the converted lines. */ // Delete the converted lines.
while (curbuf->b_ml.ml_line_count > line_count) while (curbuf->b_ml.ml_line_count > line_count) {
ml_delete(line_count, FALSE); ml_delete(line_count, false);
}
} }
/* Put the cursor on the first line. */ // Put the cursor on the first line.
curwin->w_cursor.lnum = 1; curwin->w_cursor.lnum = 1;
curwin->w_cursor.col = 0; curwin->w_cursor.col = 0;
if (read_stdin) { if (read_stdin) {
/* Set or reset 'modified' before executing autocommands, so that // Set or reset 'modified' before executing autocommands, so that
* it can be changed there. */ // it can be changed there.
if (!readonlymode && !bufempty()) if (!readonlymode && !bufempty()) {
changed(); changed();
else if (retval != FAIL) } else if (retval != FAIL) {
unchanged(curbuf, FALSE); unchanged(curbuf, false);
}
apply_autocmds_retval(EVENT_STDINREADPOST, NULL, NULL, FALSE, apply_autocmds_retval(EVENT_STDINREADPOST, NULL, NULL, false,
curbuf, &retval); curbuf, &retval);
} }
return retval; return retval;
@@ -154,7 +157,7 @@ open_buffer (
int retval = OK; int retval = OK;
bufref_T old_curbuf; bufref_T old_curbuf;
long old_tw = curbuf->b_p_tw; long old_tw = curbuf->b_p_tw;
int read_fifo = FALSE; int read_fifo = false;
/* /*
* The 'readonly' flag is only set when BF_NEVERLOADED is being reset. * The 'readonly' flag is only set when BF_NEVERLOADED is being reset.
@@ -212,18 +215,22 @@ open_buffer (
perm = os_getperm((const char *)curbuf->b_ffname); perm = os_getperm((const char *)curbuf->b_ffname);
if (perm >= 0 && (0 if (perm >= 0 && (0
# ifdef S_ISFIFO # ifdef S_ISFIFO
|| S_ISFIFO(perm) || S_ISFIFO(perm)
# endif # endif
# ifdef S_ISSOCK # ifdef S_ISSOCK
|| S_ISSOCK(perm) || S_ISSOCK(perm)
# endif # endif
# ifdef OPEN_CHR_FILES # ifdef OPEN_CHR_FILES
|| (S_ISCHR(perm) && is_dev_fd_file(curbuf->b_ffname)) || (S_ISCHR(perm)
&& is_dev_fd_file(curbuf->b_ffname))
# endif # endif
)) )
read_fifo = TRUE; ) {
if (read_fifo) read_fifo = true;
curbuf->b_p_bin = TRUE; }
if (read_fifo) {
curbuf->b_p_bin = true;
}
#endif #endif
if (shortmess(SHM_FILEINFO)) { if (shortmess(SHM_FILEINFO)) {
msg_silent = 1; msg_silent = 1;
@@ -235,8 +242,9 @@ open_buffer (
#ifdef UNIX #ifdef UNIX
if (read_fifo) { if (read_fifo) {
curbuf->b_p_bin = save_bin; curbuf->b_p_bin = save_bin;
if (retval == OK) if (retval == OK) {
retval = read_buffer(FALSE, eap, flags); retval = read_buffer(false, eap, flags);
}
} }
#endif #endif
msg_silent = old_msg_silent; msg_silent = old_msg_silent;
@@ -246,7 +254,7 @@ open_buffer (
fix_help_buffer(); fix_help_buffer();
} }
} else if (read_stdin) { } else if (read_stdin) {
int save_bin = curbuf->b_p_bin; int save_bin = curbuf->b_p_bin;
/* /*
* First read the text in binary mode into the buffer. * First read the text in binary mode into the buffer.
@@ -259,14 +267,14 @@ open_buffer (
(linenr_T)0, (linenr_T)MAXLNUM, NULL, (linenr_T)0, (linenr_T)MAXLNUM, NULL,
flags | (READ_NEW + READ_STDIN)); flags | (READ_NEW + READ_STDIN));
curbuf->b_p_bin = save_bin; curbuf->b_p_bin = save_bin;
if (retval == OK) if (retval == OK) {
retval = read_buffer(TRUE, eap, flags); retval = read_buffer(true, eap, flags);
}
} }
/* if first time loading this buffer, init b_chartab[] */ /* if first time loading this buffer, init b_chartab[] */
if (curbuf->b_flags & BF_NEVERLOADED) { if (curbuf->b_flags & BF_NEVERLOADED) {
(void)buf_init_chartab(curbuf, FALSE); (void)buf_init_chartab(curbuf, false);
parse_cino(curbuf); parse_cino(curbuf);
} }
@@ -463,8 +471,8 @@ void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last)
return; return;
} }
/* When the buffer becomes hidden, but is not unloaded, trigger // When the buffer becomes hidden, but is not unloaded, trigger
* BufHidden */ // BufHidden
if (!unload_buf) { if (!unload_buf) {
buf->b_locked++; buf->b_locked++;
if (apply_autocmds(EVENT_BUFHIDDEN, buf->b_fname, buf->b_fname, false, if (apply_autocmds(EVENT_BUFHIDDEN, buf->b_fname, buf->b_fname, false,

View File

@@ -268,7 +268,7 @@ readfile (
int filtering = (flags & READ_FILTER); int filtering = (flags & READ_FILTER);
int read_stdin = (flags & READ_STDIN); int read_stdin = (flags & READ_STDIN);
int read_buffer = (flags & READ_BUFFER); int read_buffer = (flags & READ_BUFFER);
int read_fifo = (flags & READ_FIFO); int read_fifo = (flags & READ_FIFO);
int set_options = newfile || read_buffer int set_options = newfile || read_buffer
|| (eap != NULL && eap->read_edit); || (eap != NULL && eap->read_edit);
linenr_T read_buf_lnum = 1; /* next line to read from curbuf */ linenr_T read_buf_lnum = 1; /* next line to read from curbuf */
@@ -471,7 +471,7 @@ readfile (
curbuf->b_p_ro = FALSE; curbuf->b_p_ro = FALSE;
if (newfile && !read_stdin && !read_buffer && !read_fifo) { if (newfile && !read_stdin && !read_buffer && !read_fifo) {
/* Remember time of file. */ // Remember time of file.
FileInfo file_info; FileInfo file_info;
if (os_fileinfo((char *)fname, &file_info)) { if (os_fileinfo((char *)fname, &file_info)) {
buf_store_file_info(curbuf, &file_info); buf_store_file_info(curbuf, &file_info);

View File

@@ -4,14 +4,14 @@
#include "nvim/buffer_defs.h" #include "nvim/buffer_defs.h"
#include "nvim/os/os.h" #include "nvim/os/os.h"
/* Values for readfile() flags */ // Values for readfile() flags
#define READ_NEW 0x01 /* read a file into a new buffer */ #define READ_NEW 0x01 // read a file into a new buffer
#define READ_FILTER 0x02 /* read filter output */ #define READ_FILTER 0x02 // read filter output
#define READ_STDIN 0x04 /* read from stdin */ #define READ_STDIN 0x04 // read from stdin
#define READ_BUFFER 0x08 /* read from curbuf (converting stdin) */ #define READ_BUFFER 0x08 // read from curbuf (converting stdin)
#define READ_DUMMY 0x10 /* reading into a dummy buffer */ #define READ_DUMMY 0x10 // reading into a dummy buffer
#define READ_KEEP_UNDO 0x20 /* keep undo info */ #define READ_KEEP_UNDO 0x20 // keep undo info
#define READ_FIFO 0x40 /* read from fifo or socket */ #define READ_FIFO 0x40 // read from fifo or socket
#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) #define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))