From d7c2ca6e43fa8677714150c837c8b06e35b659f2 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Sun, 2 May 2021 19:08:41 +0530 Subject: [PATCH] nvim: ftplugin/autoload: C: Run gst-indent on save --- nvim/.config/nvim/after/ftplugin/c.vim | 9 +++++++++ nvim/.config/nvim/autoload/c.vim | 5 +++++ 2 files changed, 14 insertions(+) create mode 100644 nvim/.config/nvim/autoload/c.vim diff --git a/nvim/.config/nvim/after/ftplugin/c.vim b/nvim/.config/nvim/after/ftplugin/c.vim index 54fbeee..a1cf433 100644 --- a/nvim/.config/nvim/after/ftplugin/c.vim +++ b/nvim/.config/nvim/after/ftplugin/c.vim @@ -18,3 +18,12 @@ nmap e (quickr_cscope_egrep) nmap f (quickr_cscope_files) nmap i (quickr_cscope_includes) nmap a (quickr_cscope_assignments) + +" If we are working with any of the gstreamer projects in C, run gst-ident +" before saving. Assume gst-ident from gstreamer/tools/gst-indent has been +" made available in path. +" +" The '!' after autocmd is required without which, the command gets triggered +" multiple times. Basically, we clear the autocmd. +autocmd! BufWritePost */gst-*/*.c call c#format_with_gst_indent() +autocmd! BufWritePost */gstreamer-*/*.c call c#format_with_gst_indent() diff --git a/nvim/.config/nvim/autoload/c.vim b/nvim/.config/nvim/autoload/c.vim new file mode 100644 index 0000000..389dbaf --- /dev/null +++ b/nvim/.config/nvim/autoload/c.vim @@ -0,0 +1,5 @@ +function! c#format_with_gst_indent() abort + let file = expand('%:p') + silent execute "!gst-indent " . file + silent execute "e" . file +endfunction