aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/input.c
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2021-12-10 10:56:17 +0100
committerGitHub <noreply@github.com>2021-12-10 10:56:17 +0100
commit26eb6051528186270b924c7c806a3f434c233530 (patch)
tree7229d143d9ce52354cd35d105054bf47d206a5bc /src/nvim/os/input.c
parentac2d140a33dfe88f882218e15a443b8300cca6b2 (diff)
parenta59589ca018425f672eb70bf7d2b54d24df49326 (diff)
downloadrneovim-26eb6051528186270b924c7c806a3f434c233530.tar.gz
rneovim-26eb6051528186270b924c7c806a3f434c233530.tar.bz2
rneovim-26eb6051528186270b924c7c806a3f434c233530.zip
Merge pull request #16597 from bfredl/nomisc1
refactor: move out some long-hanging fruit from misc1.c
Diffstat (limited to 'src/nvim/os/input.c')
-rw-r--r--src/nvim/os/input.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c
index 5b231f205b..fc9bbbc8b0 100644
--- a/src/nvim/os/input.c
+++ b/src/nvim/os/input.c
@@ -183,6 +183,40 @@ void os_breakcheck(void)
updating_screen = save_us;
}
+#define BREAKCHECK_SKIP 1000
+static int breakcheck_count = 0;
+
+/// Check for CTRL-C pressed, but only once in a while.
+///
+/// Should be used instead of os_breakcheck() for functions that check for
+/// each line in the file. Calling os_breakcheck() each time takes too much
+/// time, because it will use system calls to check for input.
+void line_breakcheck(void)
+{
+ if (++breakcheck_count >= BREAKCHECK_SKIP) {
+ breakcheck_count = 0;
+ os_breakcheck();
+ }
+}
+
+/// Like line_breakcheck() but check 10 times less often.
+void fast_breakcheck(void)
+{
+ if (++breakcheck_count >= BREAKCHECK_SKIP * 10) {
+ breakcheck_count = 0;
+ os_breakcheck();
+ }
+}
+
+/// Like line_breakcheck() but check 100 times less often.
+void veryfast_breakcheck(void)
+{
+ if (++breakcheck_count >= BREAKCHECK_SKIP * 100) {
+ breakcheck_count = 0;
+ os_breakcheck();
+ }
+}
+
/// Test whether a file descriptor refers to a terminal.
///