To: vim_dev@googlegroups.com Subject: Patch 8.2.0952 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0952 Problem: No simple way to interrupt Vim. Solution: Add the SigUSR1 autocommand, triggered by SIGUSR1. (Jacob Hayes, closes #1718) Files: runtime/doc/autocmd.txt, src/vim.h, src/autocmd.c, src/getchar.c, src/globals.h, src/os_unix.c, src/testdir/test_autocmd.vim *** ../vim-8.2.0951/runtime/doc/autocmd.txt 2020-01-26 22:43:27.484098902 +0100 --- runtime/doc/autocmd.txt 2020-06-10 20:51:20.082265245 +0200 *************** *** 380,385 **** --- 380,386 ---- info |User| to be used in combination with ":doautocmd" + |SigUSR1| after the SIGUSR1 signal has been detected The alphabetical list of autocommand events: *autocmd-events-abc* *************** *** 1158,1163 **** --- 1159,1165 ---- It is not allowed to change the buffer text, see |textlock|. {only when compiled with the +eval feature} + *User* User Never executed automatically. To be used for autocommands that are only executed with *************** *** 1166,1171 **** --- 1168,1182 ---- used while there are no matching autocommands, you will get an error. If you don't want that, define a dummy autocommand yourself. + + *SigUSR1* + SigUSR1 After the SIGUSR1 signal has been detected. + Could be used if other ways of notifying Vim + are not feasible. E.g. to check for the + result of a build that takes a long time, or + when a motion sensor is triggered. + {only on Unix} + *UserGettingBored* UserGettingBored When the user presses the same key 42 times. Just kidding! :-) *** ../vim-8.2.0951/src/vim.h 2020-06-02 21:38:18.719856309 +0200 --- src/vim.h 2020-06-10 20:46:29.255207577 +0200 *************** *** 1316,1321 **** --- 1316,1322 ---- EVENT_SESSIONLOADPOST, // after loading a session file EVENT_SHELLCMDPOST, // after ":!cmd" EVENT_SHELLFILTERPOST, // after ":1,2!cmd", ":w !cmd", ":r !cmd". + EVENT_SIGUSR1, // after the SIGUSR1 signal EVENT_SOURCECMD, // sourcing a Vim script using command EVENT_SOURCEPRE, // before sourcing a Vim script EVENT_SOURCEPOST, // after sourcing a Vim script *** ../vim-8.2.0951/src/autocmd.c 2020-06-07 20:49:02.073891895 +0200 --- src/autocmd.c 2020-06-10 20:38:01.432851577 +0200 *************** *** 161,166 **** --- 161,167 ---- {"SessionLoadPost", EVENT_SESSIONLOADPOST}, {"ShellCmdPost", EVENT_SHELLCMDPOST}, {"ShellFilterPost", EVENT_SHELLFILTERPOST}, + {"SigUSR1", EVENT_SIGUSR1}, {"SourceCmd", EVENT_SOURCECMD}, {"SourcePre", EVENT_SOURCEPRE}, {"SourcePost", EVENT_SOURCEPOST}, *** ../vim-8.2.0951/src/getchar.c 2020-06-07 15:46:08.314414830 +0200 --- src/getchar.c 2020-06-10 20:51:59.330138046 +0200 *************** *** 2204,2209 **** --- 2204,2216 ---- if (has_sound_callback_in_queue()) invoke_sound_callback(); # endif + #ifdef SIGUSR1 + if (got_sigusr1) + { + apply_autocmds(EVENT_SIGUSR1, NULL, NULL, FALSE, curbuf); + got_sigusr1 = FALSE; + } + #endif break; } *** ../vim-8.2.0951/src/globals.h 2020-06-10 15:32:04.455653633 +0200 --- src/globals.h 2020-06-10 20:40:23.164392743 +0200 *************** *** 1171,1179 **** EXTERN FILE *scriptout INIT(= NULL); // stream to write script to EXTERN int read_cmd_fd INIT(= 0); // fd to read commands from ! // volatile because it is used in signal handler catch_sigint(). ! EXTERN volatile sig_atomic_t got_int INIT(= FALSE); // set to TRUE when interrupt ! // signal occurred #ifdef USE_TERM_CONSOLE EXTERN int term_console INIT(= FALSE); // set to TRUE when console used #endif --- 1171,1184 ---- EXTERN FILE *scriptout INIT(= NULL); // stream to write script to EXTERN int read_cmd_fd INIT(= 0); // fd to read commands from ! // Set to TRUE when an interrupt signal occurred. ! // Volatile because it is used in signal handler catch_sigint(). ! EXTERN volatile sig_atomic_t got_int INIT(= FALSE); ! ! // Set to TRUE when SIGUSR1 signal was detected. ! // Volatile because it is used in signal handler catch_sigint(). ! EXTERN volatile sig_atomic_t got_sigusr1 INIT(= FALSE); ! #ifdef USE_TERM_CONSOLE EXTERN int term_console INIT(= FALSE); // set to TRUE when console used #endif *** ../vim-8.2.0951/src/os_unix.c 2020-05-31 13:09:43.894293957 +0200 --- src/os_unix.c 2020-06-10 20:43:47.731730642 +0200 *************** *** 164,169 **** --- 164,172 ---- #if defined(SIGINT) static RETSIGTYPE catch_sigint SIGPROTOARG; #endif + #if defined(SIGUSR1) + static RETSIGTYPE catch_sigusr1 SIGPROTOARG; + #endif #if defined(SIGPWR) static RETSIGTYPE catch_sigpwr SIGPROTOARG; #endif *************** *** 297,303 **** {SIGXFSZ, "XFSZ", TRUE}, #endif #ifdef SIGUSR1 ! {SIGUSR1, "USR1", TRUE}, #endif #if defined(SIGUSR2) && !defined(FEAT_SYSMOUSE) // Used for sysmouse handling --- 300,306 ---- {SIGXFSZ, "XFSZ", TRUE}, #endif #ifdef SIGUSR1 ! {SIGUSR1, "USR1", FALSE}, #endif #if defined(SIGUSR2) && !defined(FEAT_SYSMOUSE) // Used for sysmouse handling *************** *** 837,842 **** --- 840,856 ---- } #endif + #if defined(SIGUSR1) + static RETSIGTYPE + catch_sigusr1 SIGDEFARG(sigarg) + { + // this is not required on all systems, but it doesn't hurt anybody + signal(SIGUSR1, (RETSIGTYPE (*)())catch_sigusr1); + got_sigusr1 = TRUE; + SIGRETURN; + } + #endif + #if defined(SIGPWR) static RETSIGTYPE catch_sigpwr SIGDEFARG(sigarg) *************** *** 1323,1332 **** #if defined(SIGCONT) signal(SIGCONT, sigcont_handler); #endif /* * We want to ignore breaking of PIPEs. */ - #ifdef SIGPIPE signal(SIGPIPE, SIG_IGN); #endif --- 1337,1346 ---- #if defined(SIGCONT) signal(SIGCONT, sigcont_handler); #endif + #ifdef SIGPIPE /* * We want to ignore breaking of PIPEs. */ signal(SIGPIPE, SIG_IGN); #endif *************** *** 1334,1339 **** --- 1348,1360 ---- catch_int_signal(); #endif + #ifdef SIGUSR1 + /* + * Call user's handler on SIGUSR1 + */ + signal(SIGUSR1, (RETSIGTYPE (*)())catch_sigusr1); + #endif + /* * Ignore alarm signals (Perl's alarm() generates it). */ *************** *** 1341,1351 **** signal(SIGALRM, SIG_IGN); #endif /* * Catch SIGPWR (power failure?) to preserve the swap files, so that no * work will be lost. */ - #ifdef SIGPWR signal(SIGPWR, (RETSIGTYPE (*)())catch_sigpwr); #endif --- 1362,1372 ---- signal(SIGALRM, SIG_IGN); #endif + #ifdef SIGPWR /* * Catch SIGPWR (power failure?) to preserve the swap files, so that no * work will be lost. */ signal(SIGPWR, (RETSIGTYPE (*)())catch_sigpwr); #endif *** ../vim-8.2.0951/src/testdir/test_autocmd.vim 2020-04-21 22:19:26.055486850 +0200 --- src/testdir/test_autocmd.vim 2020-06-10 20:45:24.551417142 +0200 *************** *** 2509,2512 **** --- 2509,2525 ---- autocmd! BufEnter Xfile endfunc + " Tests for SigUSR1 autocmd event, which is only available on posix systems. + func Test_autocmd_sigusr1() + CheckUnix + + let g:sigusr1_passed = 0 + au SigUSR1 * let g:sigusr1_passed = 1 + call system('/bin/kill -s usr1 ' . getpid()) + call WaitForAssert({-> assert_true(g:sigusr1_passed)}) + + au! SigUSR1 + unlet g:sigusr1_passed + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.0951/src/version.c 2020-06-10 20:21:06.344121264 +0200 --- src/version.c 2020-06-10 20:37:17.024995300 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 952, /**/ -- A real patriot is the fellow who gets a parking ticket and rejoices that the system works. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///