From fcb86e9bed72f8e4da68b7f2f6306c69a4548dd4 Mon Sep 17 00:00:00 2001 From: Andrey Orst Date: Thu, 9 May 2019 18:12:06 +0300 Subject: [PATCH] use provides requires --- rc/fzf.kak | 8 ++++++-- rc/modules/VCS/fzf-bzr.kak | 4 +++- rc/modules/VCS/fzf-git.kak | 4 +++- rc/modules/VCS/fzf-hg.kak | 4 +++- rc/modules/VCS/fzf-svn.kak | 3 ++- rc/modules/fzf-buffer.kak | 5 ++++- rc/modules/fzf-cd.kak | 4 +++- rc/modules/fzf-ctags.kak | 5 ++++- rc/modules/fzf-file.kak | 4 +++- rc/modules/fzf-project.kak | 11 +++++++---- rc/modules/fzf-search.kak | 4 +++- rc/modules/fzf-vcs.kak | 14 ++++++++++---- rc/modules/fzf-yank-ring.kak | 3 ++- rc/modules/sk-grep.kak | 3 ++- 14 files changed, 55 insertions(+), 21 deletions(-) diff --git a/rc/fzf.kak b/rc/fzf.kak index 8891836..c3f3743 100644 --- a/rc/fzf.kak +++ b/rc/fzf.kak @@ -8,7 +8,6 @@ # │ different fzf commands. │ # ╰─────────────────────────────────╯ -try %{ declare-user-mode fzf } # Options declare-option -docstring 'implementation of fzf that you want to use. @@ -73,7 +72,11 @@ fzf-mode contains mnemonic key bindings for every fzf.kak command Best used with mapping like: map global normal '' ': fzf-mode' " \ -fzf-mode %{ try %{ evaluate-commands 'enter-user-mode fzf' } } +fzf-mode %{ require-module fzf; evaluate-commands 'enter-user-mode fzf' } + +provide-module fzf %§ + +try %{ declare-user-mode fzf } define-command -hidden -docstring "wrapper command to create new vertical split" \ fzf-vertical -params .. %{ try %{ @@ -230,3 +233,4 @@ fzf -params .. %{ evaluate-commands %sh{ ) > /dev/null 2>&1 < /dev/null & }} +§ diff --git a/rc/modules/VCS/fzf-bzr.kak b/rc/modules/VCS/fzf-bzr.kak index ee98886..29baf92 100644 --- a/rc/modules/VCS/fzf-bzr.kak +++ b/rc/modules/VCS/fzf-bzr.kak @@ -17,7 +17,8 @@ Default arguments: " \ str fzf_bzr_command "bzr" -try %{ declare-user-mode fzf-vcs } +hook global ModuleLoad fzf_vcs %§ + map global fzf-vcs -docstring "edit file from GNU Bazaar tree" 'b' ': fzf-bzr' define-command -hidden fzf-bzr %{ evaluate-commands %sh{ @@ -33,3 +34,4 @@ define-command -hidden fzf-bzr %{ evaluate-commands %sh{ printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags} -post-action %{cd $current_path}" }} +§ diff --git a/rc/modules/VCS/fzf-git.kak b/rc/modules/VCS/fzf-git.kak index d43e5d0..9d54a99 100644 --- a/rc/modules/VCS/fzf-git.kak +++ b/rc/modules/VCS/fzf-git.kak @@ -17,7 +17,8 @@ Default arguments: " \ str fzf_git_command "git" -try %{ declare-user-mode fzf-vcs } +hook global ModuleLoad fzf_vcs %§ + map global fzf-vcs -docstring "edit file from Git tree" 'g' ': fzf-git' define-command -override -hidden fzf-git %{ evaluate-commands %sh{ @@ -33,3 +34,4 @@ define-command -override -hidden fzf-git %{ evaluate-commands %sh{ printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags} -post-action %{cd $current_path}" }} +§ diff --git a/rc/modules/VCS/fzf-hg.kak b/rc/modules/VCS/fzf-hg.kak index 300f178..0409451 100644 --- a/rc/modules/VCS/fzf-hg.kak +++ b/rc/modules/VCS/fzf-hg.kak @@ -17,7 +17,8 @@ Default arguments: " \ str fzf_hg_command "hg" -try %{ declare-user-mode fzf-vcs } +hook global ModuleLoad fzf_vcs %§ + map global fzf-vcs -docstring "edit file from mercurial tree" 'h' ': fzf-hg' define-command -hidden fzf-hg %{ evaluate-commands %sh{ @@ -33,3 +34,4 @@ define-command -hidden fzf-hg %{ evaluate-commands %sh{ printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags} -post-action %{cd $current_path}" }} +§ diff --git a/rc/modules/VCS/fzf-svn.kak b/rc/modules/VCS/fzf-svn.kak index 965d58f..a5305b8 100644 --- a/rc/modules/VCS/fzf-svn.kak +++ b/rc/modules/VCS/fzf-svn.kak @@ -17,7 +17,7 @@ Default arguments: " \ str fzf_svn_command "svn" -try %{ declare-user-mode fzf-vcs } +hook global ModuleLoad fzf_vcs %§ map global fzf-vcs -docstring "edit file from Subversion tree" 's' ': fzf-svn' define-command -hidden fzf-svn %{ evaluate-commands %sh{ @@ -33,3 +33,4 @@ define-command -hidden fzf-svn %{ evaluate-commands %sh{ printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags} -post-action %{cd $current_path}" }} +§ diff --git a/rc/modules/fzf-buffer.kak b/rc/modules/fzf-buffer.kak index 3652376..aa32522 100644 --- a/rc/modules/fzf-buffer.kak +++ b/rc/modules/fzf-buffer.kak @@ -8,7 +8,8 @@ # │ GitHub.com/andreyorst/fzf.kak │ # ╰──────────────────────────────────────╯ -try %{ declare-user-mode fzf } +hook global ModuleLoad fzf %§ + map global fzf -docstring "open buffer" 'b' ': fzf-buffer' define-command -hidden fzf-buffer %{ evaluate-commands %sh{ @@ -30,3 +31,5 @@ define-command -hidden fzf-buffer %{ evaluate-commands %sh{ printf "%s\n" "fzf -kak-cmd %{buffer} -items-cmd %{(cat $buffers; rm $buffers)} -fzf-args %{--expect ctrl-w $additional_flags}" }} + +§ diff --git a/rc/modules/fzf-cd.kak b/rc/modules/fzf-cd.kak index 1445bc9..f11a942 100644 --- a/rc/modules/fzf-cd.kak +++ b/rc/modules/fzf-cd.kak @@ -29,7 +29,8 @@ str cd_preview_cmd "tree -d {}" declare-option -docstring 'maximum amount of previewed directories' \ int fzf_preview_dirs '300' -try %{ declare-user-mode fzf } +hook global ModuleLoad fzf %§ + map global fzf -docstring "change directory" 'c' ': fzf-cd' define-command -hidden fzf-cd %{ evaluate-commands %sh{ @@ -50,3 +51,4 @@ current path: $(pwd)}" printf "%s\n" "fzf $preview_flag -kak-cmd %{change-directory} -items-cmd %{$items_command} -preview-cmd %{$preview} -post-action %{fzf-cd}" }} +§ diff --git a/rc/modules/fzf-ctags.kak b/rc/modules/fzf-ctags.kak index 97a0782..b6941e7 100644 --- a/rc/modules/fzf-ctags.kak +++ b/rc/modules/fzf-ctags.kak @@ -11,7 +11,8 @@ declare-option -docstring "file that should be used by fzf-tag to provide tags. Default value: tags" \ str fzf_tag_file_name "tags" -try %{ declare-user-mode fzf } +hook global ModuleLoad fzf %§ + map global fzf -docstring "find tag" 't' ': fzf-tag' # this huge try block defines filetype aware filter mappings for separate fzf-ctags mode @@ -826,3 +827,5 @@ define-command -hidden fzf-tag -params ..2 %{ evaluate-commands %sh{ printf "%s\n" "set-option -add window ctagsfiles %{$path/$kak_opt_fzf_tag_file_name}" printf "%s\n" "fzf -kak-cmd %{ctags-search} -items-cmd %{$cmd | awk '!a[\$0]++'} -fzf-args %{--expect ctrl-w $additional_flags}" }} + +§ diff --git a/rc/modules/fzf-file.kak b/rc/modules/fzf-file.kak index 5431016..aafeed7 100644 --- a/rc/modules/fzf-file.kak +++ b/rc/modules/fzf-file.kak @@ -24,7 +24,8 @@ Default arguments: " \ str fzf_file_command "find" -try %{ declare-user-mode fzf } +hook global ModuleLoad fzf %§ + map global fzf -docstring "open file" 'f' ': fzf-file' define-command -hidden fzf-file %{ evaluate-commands %sh{ @@ -62,3 +63,4 @@ define-command -hidden fzf-file %{ evaluate-commands %sh{ printf "%s\n" "fzf -preview -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags}" }} +§ diff --git a/rc/modules/fzf-project.kak b/rc/modules/fzf-project.kak index e2b96dc..7cba51c 100644 --- a/rc/modules/fzf-project.kak +++ b/rc/modules/fzf-project.kak @@ -8,10 +8,15 @@ # │ GitHub.com/andreyorst/fzf.kak │ # ╰──────────────────────────────────────╯ -try %{ declare-user-mode fzf } +declare-option -docstring "file where saved projects are stored" str fzf_project_file "%val{config}/.fzf-projects" +declare-option -docstring %sh{ printf "%s\n" "use '~/' instead of '${HOME}'" } bool fzf_project_use_tilda false + +hook global ModuleLoad fzf %§ + map global fzf -docstring "open project" 'p' ': fzf-project' try %{ declare-user-mode fzf-project } + map global fzf -docstring "project menu" '' ': enter-user-mode fzf-project' map global fzf-project -docstring "save current path as project" 's' ': fzf-save-path-as-project' map global fzf-project -docstring "save current path as project (use basename)" '' ': fzf-save-path-as-project-no-prompt' @@ -19,9 +24,6 @@ map global fzf-project -docstring "update project" 'u' ': fzf-update-projec map global fzf-project -docstring "delete project from project list" 'd' ': fzf-delete-project' map global fzf-project -docstring "rename project" 'r' ': fzf-rename-project' -declare-option -docstring "file where saved projects are stored" str fzf_project_file "%val{config}/.fzf-projects" -declare-option -docstring %sh{ printf "%s\n" "use '~/' instead of '${HOME}'" } bool fzf_project_use_tilda false - define-command -hidden fzf-project %{ evaluate-commands %sh{ if [ -s ${kak_opt_fzf_project_file} ]; then printf '%s\n' "info -title %{fzf open project} %{Change the server's working directory to selected project}" @@ -159,3 +161,4 @@ define-command -hidden fzf-rename-project %{ }} } +§ diff --git a/rc/modules/fzf-search.kak b/rc/modules/fzf-search.kak index e4af11a..4890cc0 100644 --- a/rc/modules/fzf-search.kak +++ b/rc/modules/fzf-search.kak @@ -8,7 +8,8 @@ # │ GitHub.com/andreyorst/fzf.kak │ # ╰──────────────────────────────────────╯ -try %{ declare-user-mode fzf } +hook global ModuleLoad fzf %§ + map global fzf -docstring "search in buffer" 's' ': fzf-buffer-search' define-command -hidden fzf-buffer-search %{ evaluate-commands %sh{ @@ -20,3 +21,4 @@ define-command -hidden fzf-buffer-search %{ evaluate-commands %sh{ printf "%s\n" "fzf -kak-cmd %{execute-keys} -items-cmd %{(nl -b a -n ln $buffer_content; rm $buffer_content)} -fzf-args %{--reverse} -filter %{cut -f 1} -post-action %{execute-keys gx}" }} +§ diff --git a/rc/modules/fzf-vcs.kak b/rc/modules/fzf-vcs.kak index 4bd71d3..da0f5d4 100644 --- a/rc/modules/fzf-vcs.kak +++ b/rc/modules/fzf-vcs.kak @@ -9,15 +9,20 @@ # │ GitHub.com/andreyorst/fzf.kak │ # ╰──────────────────────────────────────╯ -try %{ declare-user-mode fzf-vcs } catch %{echo -markup "{Error}Can't declare mode 'fzf-vcs' - already exists"} +hook global ModuleLoad fzf %§ -try %{ declare-user-mode fzf } -map global fzf -docstring "edit file from vcs repo" 'v' ': fzf-vcs' +map global fzf -docstring "edit file from vcs repo" 'v' ': require-module fzf_vcs; fzf-vcs' map global fzf -docstring "svitch to vcs selection mode" '' ': fzf-vcs-mode' define-command -docstring "Enter fzf-vcs-mode. This mode allows selecting specific vcs command." \ -fzf-vcs-mode %{ try %{ evaluate-commands 'enter-user-mode fzf-vcs' } } +fzf-vcs-mode %{ require-module fzf_vcs; evaluate-commands 'enter-user-mode fzf-vcs' } + +§ + +provide-module fzf_vcs %§ + +declare-user-mode fzf-vcs define-command -hidden -docstring 'Wrapper command for fzf vcs to automatically decect used version control system. @@ -55,3 +60,4 @@ bzr status" printf "%s\n" "echo -markup '{Information}No VCS found in current folder'" }} +§ diff --git a/rc/modules/fzf-yank-ring.kak b/rc/modules/fzf-yank-ring.kak index b977e03..59b15bd 100644 --- a/rc/modules/fzf-yank-ring.kak +++ b/rc/modules/fzf-yank-ring.kak @@ -10,7 +10,7 @@ # │ GitHub.com/alexherbo2/yank-ring.kak │ # ╰─────────────────────────────────────╯ -try %{ declare-user-mode fzf } +hook global ModuleLoad fzf %§ # this will fail if yank-ring.kak isn't installed hook global -once WinCreate .* %{ try %{ @@ -35,3 +35,4 @@ define-command -hidden fzf-yank-ring-set-dquote -params 1 %{ set-register dquote %sh{ printf "%s\n" "$1" | sed "s/␤/\n/g" } } +§ diff --git a/rc/modules/sk-grep.kak b/rc/modules/sk-grep.kak index 477318e..f52544c 100644 --- a/rc/modules/sk-grep.kak +++ b/rc/modules/sk-grep.kak @@ -17,7 +17,7 @@ str fzf_sk_grep_command 'grep -RHn' declare-option -hidden str fzf_sk_first_file '' -try %{ declare-user-mode fzf } +hook global ModuleLoad fzf %§ evaluate-commands %sh{ if [ -n "$(command -v sk)" ]; then @@ -68,3 +68,4 @@ define-command -hidden fzf-sk-populate-grep -params 1 %{ } } +§