From 28a044cad4bbd96308d0a508a5ecafd14ab6569e Mon Sep 17 00:00:00 2001 From: Balakrishnan Balasubramanian Date: Tue, 1 Nov 2022 22:44:06 -0400 Subject: [PATCH] move function to autoload --- autoload/logrotate.vim | 19 +++++++++++++++++++ ftplugin/logrotate.vim | 25 +++++-------------------- 2 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 autoload/logrotate.vim diff --git a/autoload/logrotate.vim b/autoload/logrotate.vim new file mode 100644 index 0000000..57adbbf --- /dev/null +++ b/autoload/logrotate.vim @@ -0,0 +1,19 @@ +vim9script + +export def LogrotateHelp(awkcmd: string, word: string) + + const searchcmd =<< trim eval END + echo "<=== man logrotate ===>" + COLUMNS=80 man logrotate 2>/dev/null | + {awkcmd} '/^CONFIGURATION FILE DIRECTIVES/,/^SCRIPTS/' | {awkcmd} ' + /^ {{7}}{word}/,false {{ + if(firstLineDone && /^ {{0,7}}[^ ]/ && !/endscript/) exit + firstLineDone = 1 + print(substr($0, 8)) + }}' + END + searchcmd + ->join("\n") + ->systemlist() + ->popup_atcursor({ "padding": [0, 1, 1, 1] }) +enddef diff --git a/ftplugin/logrotate.vim b/ftplugin/logrotate.vim index 3edfd79..a54632d 100644 --- a/ftplugin/logrotate.vim +++ b/ftplugin/logrotate.vim @@ -3,7 +3,7 @@ vim9script # Language: logrotate # if exists("b:did_ftplugin") - finish + finish endif b:did_ftplugin = 1 @@ -14,28 +14,13 @@ var awkcmd: string if exists("g:logrotate_awk") awkcmd = g:logrotate_awk else + # Have to use gawk, default awk (i.e. mawk) does not support {0,7} regex syntax awkcmd = "gawk" endif -# Have to use gawk, default awk (mawk) does not support {0,7} syntax -if awkcmd != "disable" && executable(awkcmd) - def LogrotateHelp(word: string) - const searchcmd =<< trim eval END - echo "<=== man logrotate ===>" - COLUMNS=80 man logrotate 2>/dev/null | - {awkcmd} '/^CONFIGURATION FILE DIRECTIVES/,/^SCRIPTS/' | {awkcmd} ' - /^ {{7}}{word}/,false {{ - if(firstLineDone && /^ {{0,7}}[^ ]/ && !/endscript/) exit - firstLineDone = 1 - print(substr($0, 8)) - }}' - END - searchcmd - ->join("\n") - ->systemlist() - ->popup_atcursor({ "padding": [0, 1, 1, 1] }) - enddef - command -nargs=1 LogRotateHelpCmd :call LogrotateHelp() +if awkcmd != "disable" && executable(awkcmd) + + command -nargs=1 LogRotateHelpCmd :call g:logrotate#LogrotateHelp(awkcmd, ) setlocal keywordprg=:LogRotateHelpCmd b:undo_ftplugin = b:undo_ftplugin .. " keywordprg<" endif