From 9f384959b23186cb5cf17cc7fb85c91d8086718c Mon Sep 17 00:00:00 2001 From: Gustavo Junior Alves Date: Sat, 16 Dec 2017 23:37:19 -0200 Subject: [PATCH] Support for VIM autocomplete --- README.md | 7 +++++-- pgscope.spec | 7 ++++++- sql.vim | 31 +++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 sql.vim diff --git a/README.md b/README.md index 5c8ce61..24baaea 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Embed seamlessly with vim ## Download -[Fedora 27 RPM Package](https://github.com/gjalves/pgscope/releases/download/0.0.1/pgscope-0.0.1-1.fc27.x86_64.rpm) +[Fedora 27 RPM Package](https://github.com/gjalves/pgscope/releases/download/0.0.2/pgscope-0.0.2-1.fc27.x86_64.rpm) ## Installation from source @@ -17,12 +17,15 @@ cd libpg_query make cd - make +mkdir ~/.vim/after/ftplugin/ +cp sql.vim .vim/after/ftplugin/sql.vim ``` ## Using -Type pgscope to index all .sql files in current and descending directories. After that, open your .sql file with vim and put cursor under any external function. Call it using CTRL+]. If you wish to came back to calling function, use CTRL+O +Type pgscope to index all .sql files in current and descending directories. After that, open your .sql file with vim and put cursor under any external function. Call it using CTRL+]. If you wish to came back to calling function, use CTRL+o +You can autocomplete functions using CTRL+x and CTRL+o If you need to reindex, use `:!pgscope` in vim. If you wish to reindex automatically after save, type in vim command mode: diff --git a/pgscope.spec b/pgscope.spec index 0619065..ebdfbf5 100644 --- a/pgscope.spec +++ b/pgscope.spec @@ -1,6 +1,6 @@ Name: pgscope Vendor: Gustavo Junior Alves -Version: 0.0.1 +Version: 0.0.2 Release: 1%{?dist} Summary: PL/pgSQL source code tree search and browse tool @@ -16,11 +16,15 @@ BuildRequires: coreutils %changelog +* Sun Dec 16 2017 Gustavo Junior Alves 0.0.2 +- Autocomplete VIM script file + * Sun Dec 10 2017 Gustavo Junior Alves 0.0.1 - Initial release %install install -D pgscope ${RPM_BUILD_ROOT}/usr/bin/pgscope +install -D sql.vim ${RPM_BUILD_ROOT}/usr/share/pgscope/sql.vim %description PL/pgSQL source code tree search and browse tool @@ -35,6 +39,7 @@ rm -rf $RPM_BUILD_ROOT %files %defattr(-,root,root,-) /usr/bin/pgscope +/usr/share/pgscope/sql.vim %post diff --git a/sql.vim b/sql.vim new file mode 100644 index 0000000..ff5d035 --- /dev/null +++ b/sql.vim @@ -0,0 +1,31 @@ +" Vim completion script +" Language: PL/pgSQL +" Maintainer: Gustavo Junior Alves +" Last Change: 2017 Dec 16 + +au! BufNewFile,BufRead *.sql call s:FTbtm() +function! s:FTbtm() + if exists("g:dosbatch_syntax_for_btm") && g:dosbatch_syntax_for_btm + setf dosbatch + else + setf btm + endif +endfunction + +fun! Pgscope_complete(findstart, base) + if(a:findstart == 1) && (a:base == '') + return 0 + endif + + for line in readfile("tags", '', 10) + if (strcharpart(line, 0, 1) != '!') + let parts = split(line) + if(stridx(parts[0], a:base) == 0) + call complete_add(parts[0]) + endif + endif + endfor + call complete_check() +endfun + +set omnifunc=Pgscope_complete