fix: show autocmd output when F is in shortmess (#18251)

The default value of including F in 'shortmess' has the unfortunate side
effect of hiding output from autocommands. This is a common source of
confusion and often leads people to think their autocommands are not
working when they are. There is a small snippet in the docs for
'shortmess' indicating that the F flag suppresses autocmd output, but
it's not easy to find if you don't already know to look for it.

This commit removes that behavior of the F flag to make it only suppress
file info when opening a new file.
This commit is contained in:
Gregory Anders 2022-04-25 08:44:18 -06:00 committed by GitHub
parent 440b65c338
commit 2dddc86a42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 32 deletions

View File

@ -5532,8 +5532,7 @@ A jump table for the options with a short description can be found at |Q_op|.
"Pattern not found", "Back at original", etc.
q use "recording" instead of "recording @a"
F don't give the file info when editing a file, like `:silent`
was used for the command; note that this also affects messages
from autocommands
was used for the command
S do not show search count message when searching, e.g.
"[1/5]"

View File

@ -375,6 +375,7 @@ Normal commands:
Options:
'ttimeout', 'ttimeoutlen' behavior was simplified
|jumpoptions| "stack" behavior
'shortmess' the "F" flag does not affect output from autocommands
Shell:
Shell output (|:!|, |:make|, …) is always routed through the UI, so it

View File

@ -109,6 +109,7 @@ static int read_buffer(int read_stdin, exarg_T *eap, int flags)
{
int retval = OK;
linenr_T line_count;
bool silent = shortmess(SHM_FILEINFO);
// 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
@ -117,7 +118,7 @@ static int read_buffer(int read_stdin, exarg_T *eap, int flags)
retval = readfile(read_stdin ? NULL : curbuf->b_ffname,
read_stdin ? NULL : curbuf->b_fname,
line_count, (linenr_T)0, (linenr_T)MAXLNUM, eap,
flags | READ_BUFFER);
flags | READ_BUFFER, silent);
if (retval == OK) {
// Delete the binary lines.
while (--line_count >= 0) {
@ -162,6 +163,7 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags)
bufref_T old_curbuf;
long old_tw = curbuf->b_p_tw;
int read_fifo = false;
bool silent = shortmess(SHM_FILEINFO);
// The 'readonly' flag is only set when BF_NEVERLOADED is being reset.
// When re-entering the same buffer, it should not change, because the
@ -212,7 +214,6 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags)
curwin->w_valid = 0;
if (curbuf->b_ffname != NULL) {
int old_msg_silent = msg_silent;
#ifdef UNIX
int save_bin = curbuf->b_p_bin;
int perm;
@ -231,13 +232,10 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags)
curbuf->b_p_bin = true;
}
#endif
if (shortmess(SHM_FILEINFO)) {
msg_silent = 1;
}
retval = readfile(curbuf->b_ffname, curbuf->b_fname,
(linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, eap,
flags | READ_NEW | (read_fifo ? READ_FIFO : 0));
flags | READ_NEW | (read_fifo ? READ_FIFO : 0), silent);
#ifdef UNIX
if (read_fifo) {
curbuf->b_p_bin = save_bin;
@ -246,7 +244,6 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags)
}
}
#endif
msg_silent = old_msg_silent;
// Help buffer is filtered.
if (bt_help(curbuf)) {
@ -262,7 +259,7 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags)
curbuf->b_p_bin = true;
retval = readfile(NULL, NULL, (linenr_T)0,
(linenr_T)0, (linenr_T)MAXLNUM, NULL,
flags | (READ_NEW + READ_STDIN));
flags | (READ_NEW + READ_STDIN), silent);
curbuf->b_p_bin = save_bin;
if (retval == OK) {
retval = read_buffer(true, eap, flags);
@ -903,14 +900,7 @@ void handle_swap_exists(bufref_T *old_curbuf)
buf = old_curbuf->br_buf;
}
if (buf != NULL) {
int old_msg_silent = msg_silent;
if (shortmess(SHM_FILEINFO)) {
msg_silent = 1; // prevent fileinfo message
}
enter_buffer(buf);
// restore msg_silent, so that the command line will be shown
msg_silent = old_msg_silent;
if (old_tw != curbuf->b_p_tw) {
check_colorcolumn(curwin);
@ -5611,7 +5601,7 @@ bool buf_contents_changed(buf_T *buf)
if (ml_open(curbuf) == OK
&& readfile(buf->b_ffname, buf->b_fname,
(linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM,
&ea, READ_NEW | READ_DUMMY) == OK) {
&ea, READ_NEW | READ_DUMMY, false) == OK) {
// compare the two files line by line
if (buf->b_ml.ml_line_count == curbuf->b_ml.ml_line_count) {
differ = false;

View File

@ -1387,7 +1387,7 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char_u *cmd,
if (do_out) {
if (otmp != NULL) {
if (readfile(otmp, NULL, line2, (linenr_T)0, (linenr_T)MAXLNUM, eap,
READ_FILTER) != OK) {
READ_FILTER, false) != OK) {
if (!aborting()) {
msg_putchar('\n');
semsg(_(e_notread), otmp);

View File

@ -7702,13 +7702,13 @@ static void ex_read(exarg_T *eap)
return;
}
i = readfile(curbuf->b_ffname, curbuf->b_fname,
eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0);
eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0, false);
} else {
if (vim_strchr(p_cpo, CPO_ALTREAD) != NULL) {
(void)setaltfname(eap->arg, eap->arg, (linenr_T)1);
}
i = readfile(eap->arg, NULL,
eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0);
eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0, false);
}
if (i != OK) {
if (!aborting()) {

View File

@ -176,7 +176,7 @@ void filemess(buf_T *buf, char_u *name, char_u *s, int attr)
///
/// @return FAIL for failure, NOTDONE for directory (failure), or OK
int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_skip,
linenr_T lines_to_read, exarg_T *eap, int flags)
linenr_T lines_to_read, exarg_T *eap, int flags, bool silent)
{
int fd = 0;
int newfile = (flags & READ_NEW);
@ -472,10 +472,12 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski
return FAIL;
}
}
if (dir_of_file_exists(fname)) {
filemess(curbuf, sfname, (char_u *)new_file_message(), 0);
} else {
filemess(curbuf, sfname, (char_u *)_("[New DIRECTORY]"), 0);
if (!silent) {
if (dir_of_file_exists(fname)) {
filemess(curbuf, sfname, (char_u *)new_file_message(), 0);
} else {
filemess(curbuf, sfname, (char_u *)_("[New DIRECTORY]"), 0);
}
}
// Even though this is a new file, it might have been
// edited before and deleted. Get the old marks.
@ -658,7 +660,7 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski
// Autocommands may add lines to the file, need to check if it is empty
wasempty = (curbuf->b_ml.ml_flags & ML_EMPTY);
if (!recoverymode && !filtering && !(flags & READ_DUMMY)) {
if (!recoverymode && !filtering && !(flags & READ_DUMMY) && !silent) {
if (!read_stdin && !read_buffer) {
filemess(curbuf, sfname, (char_u *)"", 0);
}
@ -1788,7 +1790,7 @@ failed:
return OK; // an interrupt isn't really an error
}
if (!filtering && !(flags & READ_DUMMY)) {
if (!filtering && !(flags & READ_DUMMY) && !silent) {
add_quoted_fname((char *)IObuff, IOSIZE, curbuf, (const char *)sfname);
c = false;
@ -5191,7 +5193,7 @@ void buf_reload(buf_T *buf, int orig_mode, bool reload_options)
curbuf->b_flags |= BF_CHECK_RO; // check for RO again
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) != OK) {
(linenr_T)MAXLNUM, &ea, flags, false) != OK) {
if (!aborting()) {
semsg(_("E321: Could not reload \"%s\""), buf->b_fname);
}

View File

@ -994,7 +994,7 @@ void ml_recover(bool checkext)
*/
if (curbuf->b_ffname != NULL) {
orig_file_status = readfile(curbuf->b_ffname, NULL, (linenr_T)0,
(linenr_T)0, (linenr_T)MAXLNUM, NULL, READ_NEW);
(linenr_T)0, (linenr_T)MAXLNUM, NULL, READ_NEW, false);
}
// Use the 'fileformat' and 'fileencoding' as stored in the swap file.
@ -1069,7 +1069,7 @@ void ml_recover(bool checkext)
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) != OK) {
NULL, 0, false) != OK) {
cannot_open = true;
} else {
lnum += line_count;

View File

@ -5753,7 +5753,7 @@ static buf_T *load_dummy_buffer(char_u *fname, char_u *dirname_start, char_u *re
newbuf_to_wipe.br_buf = NULL;
readfile_result = readfile(fname, NULL, (linenr_T)0, (linenr_T)0,
(linenr_T)MAXLNUM, NULL,
READ_NEW | READ_DUMMY);
READ_NEW | READ_DUMMY, false);
newbuf->b_locked--;
if (readfile_result == OK
&& !got_int