aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2017-01-12 02:33:15 +0100
committerJustin M. Keyes <justinkz@gmail.com>2017-01-12 23:10:38 +0100
commit42c922b32c0a22fbe078d03bac5de0cfa7bd0b9f (patch)
tree234c832182161724f9117e5e130279b4287ca915
parent50d0d891299c111c5e349c084ef146facfaad009 (diff)
downloadrneovim-42c922b32c0a22fbe078d03bac5de0cfa7bd0b9f.tar.gz
rneovim-42c922b32c0a22fbe078d03bac5de0cfa7bd0b9f.tar.bz2
rneovim-42c922b32c0a22fbe078d03bac5de0cfa7bd0b9f.zip
open_buffer(): Do `BufEnter` for directories.
Abuse NOTDONE to give some nuance to the return value of readfile(), so that open_buffer() can distinguish between "failed, lol" and "failed because the path is a directory". Before this change, Vim *already* creates a new buffer when a directory is edited. So there is no reason it should not raise BufEnter, that was an implementation detail of ye olde readfile(). Most of the changes in this commit merely preserve the old semantics. The "implicit" change that we actually are interested in, is this line in `open_buffer()`, where `retval` being non-FAIL allows EVENT_BUFENTER to be applied: apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf, &retval); References https://github.com/vim/vim/issues/1353
-rw-r--r--src/nvim/buffer.c11
-rw-r--r--src/nvim/ex_cmds.c4
-rw-r--r--src/nvim/ex_docmd.c5
-rw-r--r--src/nvim/fileio.c13
-rw-r--r--src/nvim/memline.c2
5 files changed, 20 insertions, 15 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index d9fdc80c60..5ab96ca67d 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -193,10 +193,13 @@ open_buffer (
* it can be changed there. */
if (!readonlymode && !bufempty())
changed();
- else if (retval != FAIL)
+ else if (retval == OK) {
unchanged(curbuf, FALSE);
- apply_autocmds_retval(EVENT_STDINREADPOST, NULL, NULL, FALSE,
- curbuf, &retval);
+ }
+ if (retval == OK) {
+ apply_autocmds_retval(EVENT_STDINREADPOST, NULL, NULL, FALSE,
+ curbuf, &retval);
+ }
}
}
@@ -219,7 +222,7 @@ open_buffer (
|| (aborting() && vim_strchr(p_cpo, CPO_INTMOD) != NULL)
)
changed();
- else if (retval != FAIL && !read_stdin)
+ else if (retval == OK && !read_stdin)
unchanged(curbuf, FALSE);
save_file_ff(curbuf); /* keep this fileformat */
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index b1404abc05..69eed33736 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -1193,8 +1193,8 @@ static void do_filter(
if (do_out) {
if (otmp != NULL) {
- if (readfile(otmp, NULL, line2, (linenr_T)0, (linenr_T)MAXLNUM,
- eap, READ_FILTER) == FAIL) {
+ if (readfile(otmp, NULL, line2, (linenr_T)0, (linenr_T)MAXLNUM, eap,
+ READ_FILTER) != OK) {
if (!aborting()) {
msg_putchar('\n');
EMSG2(_(e_notread), otmp);
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 19691ccc3a..5ff79bcfef 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -6910,9 +6910,10 @@ static void ex_read(exarg_T *eap)
eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0);
}
- if (i == FAIL) {
- if (!aborting())
+ if (i != OK) {
+ if (!aborting()) {
EMSG2(_(e_notopen), eap->arg);
+ }
} else {
if (empty && exmode_active) {
/* Delete the empty line that remains. Historically ex does
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 29114201d2..c075b05b46 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -249,7 +249,7 @@ void filemess(buf_T *buf, char_u *name, char_u *s, int attr)
* READ_DUMMY read into a dummy buffer (to check if file contents changed)
* READ_KEEP_UNDO don't clear undo info or read it from a file
*
- * return FAIL for failure, OK otherwise
+ * return FAIL for failure, NOTDONE for directory (failure), or OK
*/
int
readfile (
@@ -258,7 +258,7 @@ readfile (
linenr_T from,
linenr_T lines_to_skip,
linenr_T lines_to_read,
- exarg_T *eap, /* can be NULL! */
+ exarg_T *eap, // can be NULL!
int flags
)
{
@@ -444,13 +444,14 @@ readfile (
// ... or a character special file named /dev/fd/<n>
# endif
) {
- if (S_ISDIR(perm))
+ if (S_ISDIR(perm)) {
filemess(curbuf, fname, (char_u *)_("is a directory"), 0);
- else
+ } else {
filemess(curbuf, fname, (char_u *)_("is not a file"), 0);
+ }
msg_end();
msg_scroll = msg_save;
- return FAIL;
+ return S_ISDIR(perm) ? NOTDONE : FAIL;
}
#endif
}
@@ -5108,7 +5109,7 @@ void buf_reload(buf_T *buf, int orig_mode)
keep_filetype = TRUE; /* don't detect 'filetype' */
if (readfile(buf->b_ffname, buf->b_fname, (linenr_T)0,
(linenr_T)0,
- (linenr_T)MAXLNUM, &ea, flags) == FAIL) {
+ (linenr_T)MAXLNUM, &ea, flags) != OK) {
if (!aborting())
EMSG2(_("E321: Could not reload \"%s\""), buf->b_fname);
if (savebuf != NULL && buf_valid(savebuf) && buf == curbuf) {
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index a9a53ebca7..8deae54706 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -1064,7 +1064,7 @@ void ml_recover(void)
line_count = pp->pb_pointer[idx].pe_line_count;
if (readfile(curbuf->b_ffname, NULL, lnum,
pp->pb_pointer[idx].pe_old_lnum - 1,
- line_count, NULL, 0) == FAIL)
+ line_count, NULL, 0) != OK)
cannot_open = TRUE;
else
lnum += line_count;