From c414612d6e77a2a4ba8ae2ad4be6d10964b8144c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Gro=C3=9F?= Date: Sun, 18 Feb 2024 18:49:12 +0100 Subject: [PATCH] Add a callback to provide external statusline sizes This is necessary if the statusline is not embedded in tmux, but in a different external statusline (e.g. the statusline of the window manager or the kitty statusline). This was one of the missing pieces to allow embedding the statusline properly in arbitrary external statuslines. Fixes #60 --- autoload/tpipeline.vim | 5 ++++- autoload/tpipeline/util.vim | 6 ++++++ doc/tpipeline-external.txt | 4 ++++ doc/tpipeline.txt | 20 ++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/autoload/tpipeline.vim b/autoload/tpipeline.vim index 212ef73..b2dc8d0 100644 --- a/autoload/tpipeline.vim +++ b/autoload/tpipeline.vim @@ -126,7 +126,10 @@ func tpipeline#initialize() if s:is_nvim let g:tpipeline_fillchar = "" - if !exists('g:tpipeline_size') + if exists('#User#TpipelineSize') + call tpipeline#util#set_custom_size() + au VimResized * call tpipeline#util#set_custom_size() + elseif !exists('g:tpipeline_size') call tpipeline#util#set_size() au VimResized * call tpipeline#util#set_size() endif diff --git a/autoload/tpipeline/util.vim b/autoload/tpipeline/util.vim index de3c4e8..6e58c3e 100644 --- a/autoload/tpipeline/util.vim +++ b/autoload/tpipeline/util.vim @@ -15,6 +15,12 @@ func tpipeline#util#set_size() let g:tpipeline_size = str2nr(systemlist("sh -c 'echo \"\"; tmux display-message -p \"#{window_width}\"'")[-1]) endfunc +func tpipeline#util#set_custom_size() + if exists('#User#TpipelineSize') + doautocmd User TpipelineSize + endif +endfunc + func tpipeline#util#check_gui() if (v:event['chan'] && !has('nvim-0.9')) || has('gui_running') call tpipeline#state#restore() diff --git a/doc/tpipeline-external.txt b/doc/tpipeline-external.txt index 351c8d6..f214cd5 100644 --- a/doc/tpipeline-external.txt +++ b/doc/tpipeline-external.txt @@ -13,6 +13,10 @@ statusline can be embedded in arbitrary external programs. The |g:tpipeline_refreshcmd| option already allows running arbitrary commands to trigger the update of an external statusline. +The |g:tpipeline_size| option allows to configure the size of the rendered +statusline, which usually should be set to the numerical size of the external +statusline, i.e. the number of characters or columns that fit into it. + Depending on the external program, some integration needs to be done on that side as well. There exists full documentation for some external programs in |tpipeline-external-examples|. diff --git a/doc/tpipeline.txt b/doc/tpipeline.txt index e8192f8..f069203 100644 --- a/doc/tpipeline.txt +++ b/doc/tpipeline.txt @@ -7,6 +7,7 @@ Introduction |tpipeline-introduction| Tmux Integration |tpipeline-tmux| Configuration |tpipeline-configure| Api |tpipeline-api| +Autocommands |tpipeline-autocommands| ============================================================================== INTRODUCTION *tpipeline-introduction* @@ -165,6 +166,14 @@ CONFIGURATION *tpipeline-configure* set -g pane-border-format '#{pane_title}' < + g:tpipeline_size *g:tpipeline_size* + By default the statusline size is calculated automatically to + span the entire tmux window size. With this option you can + overwrite a custom statusline size to be used. If the size is + not constant and should be recalculated on every statusline + evaluation, then the |User_TpipelineSize| autocommand can be + used. + ------------------------------------------------------------------------------ API *tpipeline-api* @@ -198,5 +207,16 @@ API *tpipeline-api* Toggles the active state. See also |tpipeline#state#restore()| and |tpipeline#state#reload()|. +------------------------------------------------------------------------------ +AUTOCOMMANDS *tpipeline-autocommands* + +A few |User| |autocommands| are provided to allow extending this +plugin's functionality. Example usage: +> + autocmd User TpipelineSize let g:tpipeline_size = &co +< + *User_TpipelineSize* +TpipelineSize When calculating a custom statusline size. See |g:tpipeline_size|. + ============================================================================== vim:tw=78:sw=4:ts=8:ft=help:norl:noet: