aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/message.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2023-10-04 06:31:25 -0700
committerGitHub <noreply@github.com>2023-10-04 06:31:25 -0700
commit29fe883aa9166bdbcae3f935523c75a8aa56fe45 (patch)
tree40c1179d6d854acec5d044a94cc6111dc54883c7 /src/nvim/message.c
parent1e7e9ee91f73c62b8c5ba9dbdabba3a3b6dc0130 (diff)
downloadrneovim-29fe883aa9166bdbcae3f935523c75a8aa56fe45.tar.gz
rneovim-29fe883aa9166bdbcae3f935523c75a8aa56fe45.tar.bz2
rneovim-29fe883aa9166bdbcae3f935523c75a8aa56fe45.zip
feat: ignore swapfile for running Nvim processes #25336
Problem: The swapfile "E325: ATTENTION" dialog is displayed when editing a file already open in another (running) Nvim. Usually this behavior is annoying and irrelevant: - "Recover" and the other options ("Open readonly", "Quit", "Abort") are almost never wanted. - swapfiles are less relevant for "multi-Nvim" since 'autoread' is enabled by default. - Even less relevant if user enables 'autowrite'. Solution: Define a default SwapExists handler which does the following: 1. If the swapfile is owned by a running Nvim process, automatically chooses "(E)dit anyway" (caveat: this creates a new, extra swapfile, which is mostly harmless and ignored except by `:recover` or `nvim -r`. 2. Shows a 1-line "ignoring swapfile..." message. 3. Users can disable the default SwapExists handler via `autocmd! nvim_swapfile`.
Diffstat (limited to 'src/nvim/message.c')
-rw-r--r--src/nvim/message.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/nvim/message.c b/src/nvim/message.c
index af19d0ab87..97402276b2 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -475,7 +475,14 @@ void trunc_string(const char *s, char *buf, int room_in, int buflen)
}
}
-// Note: Caller of smsg() must check the resulting string is shorter than IOSIZE!!!
+/// Shows a printf-style message with attributes.
+///
+/// Note: Caller must check the resulting string is shorter than IOSIZE!!!
+///
+/// @see semsg
+/// @see swmsg
+///
+/// @param s printf-style format message
int smsg(int attr, const char *s, ...)
FUNC_ATTR_PRINTF(2, 3)
{
@@ -757,6 +764,8 @@ void emsg_invreg(int name)
}
/// Print an error message with unknown number of arguments
+///
+/// @return whether the message was displayed
bool semsg(const char *const fmt, ...)
FUNC_ATTR_PRINTF(1, 2)
{
@@ -3337,9 +3346,22 @@ void give_warning(const char *message, bool hl)
no_wait_return--;
}
-void give_warning2(const char *const message, const char *const a1, bool hl)
+/// Shows a warning, with optional highlighting.
+///
+/// @param hl enable highlighting
+/// @param fmt printf-style format message
+///
+/// @see smsg
+/// @see semsg
+void swmsg(bool hl, const char *const fmt, ...)
+ FUNC_ATTR_PRINTF(2, 3)
{
- vim_snprintf(IObuff, IOSIZE, message, a1);
+ va_list args;
+
+ va_start(args, fmt);
+ vim_vsnprintf(IObuff, IOSIZE, fmt, args);
+ va_end(args);
+
give_warning(IObuff, hl);
}