Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Version 3.00

NF: Added new menu links so that commonly used options can be quickly and easily toggled without having to remember the global variable names or values.  For example, if you cut the menu so that it floats beside your buffer you can easily hit "Toggle Align Where" or "Uppercase Keywords".
NF: Using the menu_mode option you can control if and where the SQLUtil menu is created.  See the menu_mode option for more details.
NF: Added the default maps to the menus.  If you use a floating menu, or simply view the menu you can more easily memorize your most commonly used maps.
BF: UPPER and lower case of keywords did not work for multi-word keywords (ORDER BY, LEFT OUTER JOIN, ...).
  • Loading branch information...
commit 73e4fa1a3d2a50e7f91e6d1dd4835bbb19d6b756 1 parent d40872b
@dfishburn dfishburn authored committed
Showing with 163 additions and 41 deletions.
  1. +22 −19 autoload/SQLUtilities.vim
  2. +37 −1 doc/SQLUtilities.txt
  3. +104 −21 plugin/SQLUtilities.vim
View
41 autoload/SQLUtilities.vim
@@ -1,8 +1,8 @@
" SQLUtilities: Variety of tools for writing SQL
-" Author: David Fishburn <fishburn@ianywhere.com>
+" Author: David Fishburn <dfishburn dot vim at gmail dot com>
" Date: Nov 23, 2002
-" Last Changed: Sun 09 Sep 2007 10:26:27 PM Eastern Daylight Time
-" Version: 2.0.0
+" Last Changed: 2008 Nov 14
+" Version: 3.0
" Script: http://www.vim.org/script.php?script_id=492
" License: GPL (http://www.gnu.org/licenses/gpl.html)
"
@@ -22,7 +22,7 @@ if v:version < 700
echomsg "SQLUtilities: Version 2.0.0 or higher requires Vim7. Version 1.4.1 can stil be used with Vim6."
finish
endif
-let g:loaded_sqlutilities_auto = 200
+let g:loaded_sqlutilities_auto = 300
" SQLU_Formatter: align selected text based on alignment pattern(s)
function! SQLUtilities#SQLU_Formatter(...) range
@@ -330,7 +330,7 @@ function! s:SQLU_ReformatStatement()
let sql_join_type_keywords = '' .
\ '\%(' .
\ '\%(inner\|' .
- \ '\%(\%(\%(left\|right\|full\)\s*\%(outer\)\?\s*\)\?\)' .
+ \ '\%(\%(\%(left\|right\|full\)\%(\s\+outer\)\?\s*\)\?\)' .
\ '\)\?\s*\)\?'
" Decho 'join types: ' . sql_join_type_keywords
" join operator syntax
@@ -358,8 +358,7 @@ function! s:SQLU_ReformatStatement()
\ sql_connect_by_keywords . '\|' .
\ sql_merge_keywords . '\|' .
\ sql_ora_keywords . '\|' .
- \ 'on\|where\|or\|order\s\+\%(\w\+\s\+\)\?by\|'.
- \ 'group\s\+by\|' .
+ \ 'on\|where\|or\|\%(order\|group\)\s\+\%(\w\+\s\+\)\?\<by\>\|'.
\ sql_window_keywords . '\|' .
\ 'having\|for\|insert\|using\|' .
\ 'intersect\|except\|window\|' .
@@ -426,18 +425,6 @@ function! s:SQLU_ReformatStatement()
" so that the keywords are RIGHT justified
AlignCtrl default
- let cmd = "'y+1,'z-1".'s/\<\(' .
- \ sql_keywords .
- \ '\|' .
- \ sql_case_keywords .
- \ '\|' .
- \ sql_join_type_keywords .
- \ '\|OUTER' .
- \ '\)\>/' .
- \ g:sqlutil_keyword_case .
- \ '\1/gei'
- silent! exec cmd
-
if g:sqlutil_align_comma == 1
call s:SQLU_WrapAtCommas()
endif
@@ -457,6 +444,22 @@ function! s:SQLU_ReformatStatement()
silent! 'y+1,'z-1Align -@-
silent! 'y+1,'z-1s/-@-/ /ge
+ " Now that we have removed the special alignment marker
+ " upper or lower case all the keywords only if the user
+ " has specified an override.
+ if g:sqlutil_keyword_case != ''
+ let cmd = "'y+1,'z-1".'s/\<\(' .
+ \ sql_keywords .
+ \ '\|' .
+ \ sql_case_keywords .
+ \ '\|' .
+ \ sql_join_type_keywords .
+ \ '\)\>/' .
+ \ g:sqlutil_keyword_case .
+ \ '\1/gei'
+ silent! exec cmd
+ endif
+
" Now align the operators
" and the operators are CENTER justified
if g:sqlutil_align_where == 1
View
38 doc/SQLUtilities.txt
@@ -538,9 +538,45 @@ For instructions on installing this file, type
(note: using double quotes is necessary when using \n): >
let g:sqlutil_cmd_terminator = "\ngo"
<
+ By default a menu is created under the Plugin menu. Menus are useful for a
+ number of reasons:
+ - See a list of available commands
+ - Remember what the shortcut maps are
+ - Have a floating menu when using the plugin a lot
+ - Allow you to quickly and easily toggle various formatting
+ options on a per statement basis. Especially useful when
+ used with the floating menu.
+ - Quick reference guide
+
+ You have several choices on where to place the menu. There are four
+ settings that will control the placement of the menu:
+ "0": Turns the menu off.
+ "1": Turns the 'SQLUtil' menu on with no menu shortcut.
+ "2": Turns the 'SQLUtil 'menu on with <alt>-d as the shortcut.
+ "3": Turns the 'Plugin -> SQLUtil' menu on with <alt>-s as
+ the shortcut.
+ The option, g:sqlutil_default_menu_mode defaults to a value of 3 and can be
+ changed by adding the following to your vimrc: >
+ :let g:sqlutil_default_menu_mode = 3
+<
==============================================================================
5. History *sqlutil-history*
+ 3.0.0: November 20, 2008:
+ NF: Added new menu links so that commonly used options can be
+ quickly and easily toggled without having to remember the
+ global variable names or values. For example, if you cut the
+ menu so that it floats beside your buffer you can easily
+ hit "Toggle Align Where" or "Uppercase Keywords".
+ NF: Using the menu_mode option you can control if and where the
+ SQLUtil menu is created. See the menu_mode option for more
+ details.
+ NF: Added the default maps to the menus. If you use a floating
+ menu, or simply view the menu you can more easily memorize
+ your most commonly used maps.
+ BF: UPPER and lower case of keywords did not work for multi-word
+ keywords (ORDER BY, LEFT OUTER JOIN, ...).
+
2.0.0: September 09, 2007:
NF: Added support for Vim 7's autoload functionality
@@ -674,7 +710,7 @@ For instructions on installing this file, type
8. TODO *sqlutil-todo*
TODO:
- 1. Suggestions welcome email <fishburn@ianywhere.com>
+ 1. Suggestions welcome email <dfishburn dot vim at gmail dot com>
==============================================================================
View
125 plugin/SQLUtilities.vim
@@ -1,8 +1,8 @@
" SQLUtilities: Variety of tools for writing SQL
-" Author: David Fishburn <fishburn@ianywhere.com>
+" Author: David Fishburn <dfishburn dot vim at gmail dot com>
" Date: Nov 23, 2002
-" Last Changed: Sun 09 Sep 2007 10:26:40 PM Eastern Daylight Time
-" Version: 2.0.0
+" Last Changed: 2009 Jan 15
+" Version: 3.0.0
" Script: http://www.vim.org/script.php?script_id=492
" License: GPL (http://www.gnu.org/licenses/gpl.html)
"
@@ -18,7 +18,7 @@
if exists("g:loaded_sqlutilities") || &cp
finish
endif
-let g:loaded_sqlutilities = 200
+let g:loaded_sqlutilities = 300
if !exists('g:sqlutil_align_where')
let g:sqlutil_align_where = 1
@@ -47,7 +47,7 @@ endif
if !exists('g:sqlutil_keyword_case')
" This controls whether keywords should be made
" upper or lower case.
- " The default is to leave in current case.
+ " The default is to leave them in current case.
let g:sqlutil_keyword_case = ''
endif
@@ -96,6 +96,8 @@ if !exists('g:sqlutil_col_list_terminators')
\ ',constraint' .
\ ',\%(not\s\+null\s\+\)\?foreign'
endif
+" Determines which menu items will be recreated
+let s:sqlutil_menus_created = 0
" Public Interface:
command! -range=% -nargs=* SQLUFormatStmts <line1>,<line2>
@@ -110,6 +112,8 @@ command! -nargs=* SQLUGetColumnDataType
\ call SQLU_GetColumnDef(expand("<cword>"), 1)
command! -nargs=* SQLUCreateProcedure
\ call SQLU_CreateProcedure(<f-args>)
+command! -nargs=* SQLUToggleValue
+ \ call SQLU_ToggleValue(<f-args>)
if !exists("g:sqlutil_load_default_maps")
let g:sqlutil_load_default_maps = 1
@@ -162,24 +166,76 @@ nmap <unique> <script> <Plug>SQLUGetColumnDataType :SQLUGetColumnDataType<CR>
nmap <unique> <script> <Plug>SQLUCreateProcedure :SQLUCreateProcedure<CR>
let g:loaded_sqlutilities_global_maps = 1
-if has("menu")
- vnoremenu <script> Plugin.SQLUtil.Format\ Range\ Stmts :SQLUFormatStmts<CR>
- noremenu <script> Plugin.SQLUtil.Format\ Range\ Stmts :SQLUFormatStmts<CR>
- vnoremenu <script> Plugin.SQLUtil.Format\ Statement :SQLUFormatter<CR>
- noremenu <script> Plugin.SQLUtil.Format\ Statement :SQLUFormatter<CR>
- noremenu <script> Plugin.SQLUtil.Create\ Procedure :SQLUCreateProcedure<CR>
- inoremenu <script> Plugin.SQLUtil.Create\ Procedure
- \ <C-O>:SQLUCreateProcedure<CR>
- noremenu <script> Plugin.SQLUtil.Create\ Column\ List
- \ :SQLUCreateColumnList<CR>
- inoremenu <script> Plugin.SQLUtil.Create\ Column\ List
- \ <C-O>:SQLUCreateColumnList<CR>
- noremenu <script> Plugin.SQLUtil.Column\ Definition
- \ :SQLUGetColumnDef<CR>
- inoremenu <script> Plugin.SQLUtil.Column\ Definition
- \ <C-O>:SQLUGetColumnDef<CR>
+if !exists('g:sqlutil_default_menu_mode')
+ let g:sqlutil_default_menu_mode = 3
endif
+function! SQLU_Menu()
+ if has("menu") && g:sqlutil_default_menu_mode != 0
+ if g:sqlutil_default_menu_mode == 1
+ let menuRoot = 'SQLUtil'
+ elseif g:sqlutil_default_menu_mode == 2
+ let menuRoot = '&SQLUtil'
+ else
+ let menuRoot = '&Plugin.&SQLUtil'
+ endif
+
+ let leader = '\'
+ if exists('g:mapleader')
+ let leader = g:mapleader
+ endif
+ let leader = escape(leader, '\')
+
+ if s:sqlutil_menus_created == 0
+ exec 'vnoremenu <script> '.menuRoot.'.Format\ Range\ Stmts<TAB>'.leader.'sfr :SQLUFormatStmts<CR>'
+ exec 'noremenu <script> '.menuRoot.'.Format\ Range\ Stmts<TAB>'.leader.'sfr :SQLUFormatStmts<CR>'
+ exec 'vnoremenu <script> '.menuRoot.'.Format\ Statement<TAB>'.leader.'sfs :SQLUFormatter<CR>'
+ exec 'noremenu <script> '.menuRoot.'.Format\ Statement<TAB>'.leader.'sfs :SQLUFormatter<CR>'
+ exec 'noremenu <script> '.menuRoot.'.Create\ Procedure<TAB>'.leader.'scp :SQLUCreateProcedure<CR>'
+ exec 'inoremenu <script> '.menuRoot.'.Create\ Procedure<TAB>'.leader.'scp
+ \ <C-O>:SQLUCreateProcedure<CR>'
+ exec 'noremenu <script> '.menuRoot.'.Create\ Column\ List<TAB>'.leader.'sl
+ \ :SQLUCreateColumnList<CR>'
+ exec 'inoremenu <script> '.menuRoot.'.Create\ Column\ List<TAB>'.leader.'sl
+ \ <C-O>:SQLUCreateColumnList<CR>'
+ exec 'noremenu <script> '.menuRoot.'.Column\ Definition<TAB>'.leader.'scd
+ \ :SQLUGetColumnDef<CR>'
+ exec 'inoremenu <script> '.menuRoot.'.Column\ Definition<TAB>'.leader.'scd
+ \ <C-O>:SQLUGetColumnDef<CR>'
+ exec 'noremenu <script> '.menuRoot.'.Column\ Datatype<TAB>'.leader.'scdt
+ \ :SQLUGetColumnDataType<CR>'
+ exec 'inoremenu <script> '.menuRoot.'.Column\ Datatype<TAB>'.leader.'scdt
+ \ <C-O>:SQLUGetColumnDataType<CR>'
+
+ let s:sqlutil_menus_created = 1
+ endif
+ silent! exec 'aunmenu <script> '.menuRoot.'.Toggle\ Align\ Where'
+ exec 'noremenu <script> '.menuRoot.'.Toggle\ Align\ Where'.
+ \ (g:sqlutil_align_where==1?'<TAB>(on) ':'<TAB>(off) ').
+ \ ':SQLUToggleValue g:sqlutil_align_where<CR>'
+ silent! exec 'aunmenu '.menuRoot.'.Toggle\ Align\ Comma'
+ exec 'noremenu <script> '.menuRoot.'.Toggle\ Align\ Comma'.
+ \ (g:sqlutil_align_comma==1?'<TAB>(on) ':'<TAB>(off) ').
+ \ ':SQLUToggleValue g:sqlutil_align_comma<CR>'
+ silent! exec 'aunmenu '.menuRoot.'.Toggle\ Align\ First\ Word'
+ exec 'noremenu <script> '.menuRoot.'.Toggle\ Align\ First\ Word'.
+ \ (g:sqlutil_align_first_word==1?'<TAB>(on) ':'<TAB>(off) ').
+ \ ':SQLUToggleValue g:sqlutil_align_first_word<CR>'
+ silent! exec 'aunmenu '.menuRoot.'.Uppercase\ Keywords'
+ exec 'noremenu <script> '.menuRoot.'.Uppercase\ Keywords'.
+ \ (g:sqlutil_keyword_case=='\U'?'<TAB>(on) ':' ').
+ \ ':SQLUToggleValue g:sqlutil_keyword_case \U<CR>'
+ silent! exec 'aunmenu '.menuRoot.'.Lowercase\ Keywords'
+ exec 'noremenu <script> '.menuRoot.'.Lowercase\ Keywords'.
+ \ (g:sqlutil_keyword_case=='\L'?'<TAB>(on) ':' ').
+ \ ':SQLUToggleValue g:sqlutil_keyword_case \L<CR>'
+ silent! exec 'aunmenu '.menuRoot.'.Default\ Case\ Keywords'
+ exec 'noremenu <script> '.menuRoot.'.Default\ Case\ Keywords'.
+ \ (g:sqlutil_keyword_case==''?'<TAB>(on) ':' ').
+ \ ':SQLUToggleValue g:sqlutil_keyword_case default<CR>'
+ endif
+endfunction
+
" Puts a command separate list of columns given a table name
" Will search through the file looking for the create table command
" It assumes that each column is on a separate line
@@ -236,4 +292,31 @@ function! SQLU_RemoveMatchingColumns( full_col_list, dup_col_list )
return SQLUtilities#SQLU_RemoveMatchingColumns( a:full_col_list, a:dup_col_list )
endfunction
+
+
+" Toggles the value of some configuration parameters.
+" Mainly used by the menu.
+function! SQLU_ToggleValue( ... )
+ if (a:0 == 0)
+ echohl WarningMsg
+ echomsg "SQLUToggle value requires at least 1 parameter"
+ echohl None
+ elseif (a:0 == 1)
+ if exists('{a:1}')
+ let {a:1} = (({a:1} == 0)?1:0)
+ endif
+ else
+ if exists('{a:1}')
+ " Use defaults as the default for this function
+ if a:2 == 'default'
+ let {a:1} = ''
+ else
+ let {a:1} = a:2
+ endif
+ endif
+ endif
+ call SQLU_Menu()
+endfunction
+
+call SQLU_Menu()
" vim:fdm=marker:nowrap:ts=4:expandtab:ff=unix:
Please sign in to comment.
Something went wrong with that request. Please try again.