Permalink
Browse files

Version 1.0.7

Add settings to customize mappings
Add mappings to results window
Update docs
  • Loading branch information...
1 parent ff33309 commit 98655cfb012b2517f596f1734999d55f935a530f @coledarr coledarr committed with Oct 24, 2012
Showing with 185 additions and 99 deletions.
  1. +76 −40 doc/xqmarklogic.txt
  2. +109 −59 ftplugin/xquery.vim
View
116 doc/xqmarklogic.txt
@@ -8,27 +8,33 @@ window. This is a filetype plugin that is only available when in an XQuery
file.
Note Vim 7.3 and later hides '|' and '*'. If using an earlier version ignore
-any '*' or '|' surrounding Command and variable names.
+any '*' or '|' surrounding Commands or variables names.
-1. Introduction |xqmarklogic-intro|
-2 Installation |xqmarklogic-install|
+Introduction |xqmarklogic-intro|
+Installation |xqmarklogic-install|
MarkLogic configuration |xqmarklogic-config-marklogic|
vimrc configuration |xqmarklogic-config-vimrc|
-3. Security Considerations |xqmarklogic-security|
-4. Commands |xqmarklogic-commands|
-5. Customization:
+Security Considerations |xqmarklogic-security|
+Mappings and Commands |xqmarklogic-map-cmds|
+ Mappings |xqmarklogic-mappings|
+ Commands |xqmarklogic-commands|
+Results Window |xqmarklogic-results|
+Customization:
Options and Settings |xqmarklogic-options|
==============================================================================
INTRODUCTION *xqmarklogic-intro*
-xqmarklogic maps <LEADER>B and <C-CR> (CONTROL-RETURN like QueryConsole) to
-run a XQuery against MarkLogic server using curl and a custom App Server
-running a short XQuery file. It displays the results in a new window. It was
-inspired by this webpage:
+xqmarklogic maps <LEADER>B and <C-CR> (CONTROL-RETURN like MarkLogic Query
+Console) to run an XQuery against MarkLogic server using curl and a custom App
+Server running a short XQuery file. It displays the results in a new
+|xmarklogic-results| window.
+
+It was inspired by this webpage:
http://superiorautomaticdictionary.com/vim-nirvana-interactive-xquery-with-marklogic
Git repository at: http://github.com/coledarr/vim-xqmarklogic
+ Pull requests welcome.
==============================================================================
INSTALLATION *xqmarklogic-install*
@@ -95,9 +101,10 @@ well >
<
For more details and other options and setting see |xqmarklogic-options|
-These settings can be set differently in different buffers.
+These settings are per buffers.
-SECURITY CONSIDERATIONS *xqmarklogic-security*
+==============================================================================
+SECURITY CONSIDERATIONS *xqmarklogic-security*
As mentioned above xq.xqy has some security considerations. It can run any
XQuery against any of the MarkLogic databases. It is only as protected as the
@@ -111,24 +118,28 @@ history in ~/.viminfo. If you set and use |xqmarklogic-options| below (particula
the one for the MarkLogic password) from command mode, those commands are
stored in the viminfo file. Pull requests with fixes for this are welcome.
-
==============================================================================
-3. Commands *xqmarklogic-commands*
+COMMANDS AND MAPPINGS *xqmarklogic-map-cmds*
+
+MAPPINGS *xqmarklogic-mappings*
<LEADER>B Run current buffer as an XQuery against the MarkLogic
App Server you setup earlier. This mapping runs XQmlquery, so
- it is easy to remap this if needed.
-<CTRL-CR> same as above. Control-Return that MarkLogic QueryConsole
- uses
+ it is easy to remap this if desired. Set to something else
+ with |g:xqmarklogic_ExecQueryKey|
+
+<CTRL-CR> Same as above. Control-Return that MarkLogic QueryConsole
+ uses. Set to something else with |g:xqmarklogic_MLExecQueryKey|
+
<LEADER>E Run XQexploreDb which will list for each document, a database
- uri, the root element, and any collections it is part of.
- It is somewhat like the "Explore" button for a database in
- MarkLogic's Query Console.
+ URI, the root element, and any collections it is part of.
+ It is somewhat like the "Explore" button for a database in Set
+ to something else with |g:xqmarklogic_ExploreDBKey|
-NOTE If you want your own mappings set |g:xqmarklogic_noMappings| in your
-vimrc to skip setting the above.
+These can be turned off with |g:xqmarklogic_noMappings| in your vimrc to turn off
-*XQtoggleShowCurlCmd* toggles showing curl command used in the output
+COMMANDS *xqmarklogic-commands*
+*XQtoggleShowCurlCmd* toggles showing curl command used in the results
window in an XML comment. It is off by default since
the command contains "--" and thus can't be in a valid
XML comment.
@@ -164,51 +175,76 @@ vimrc to skip setting the above.
*XQdisplaySettings* Displays what the current buffer settings are.
*XQmlquery* Run the current buffer against the MarkLogic server
- and display the output in a new window.
+ and display the output in a new results window.
-*XQexploreDb* Display in a new window each document in the current database, a
+*XQexploreDb* Display in a new results window each document in the current database, a
database uri, the root element, and any collections it
is part of. This is very similar to the "Explore"
button in MarkLogic's Query Console.
+==============================================================================
+RESULTS WINDOW *xqmarklogic-results*
+
+The results window is a |buftype| nofile, with the filetype set to xml, and
+has a few mappings for convience. These mappings are only set for the results
+window, and are not affected by |g:xqmarklogic_noMappings|.
+
+q Close the results window.
+
+<LEADER>B Will refresh the output of the window. Set to something else
+ with |g:xqmarklogic_ExecQueryKey|
+<C-CR> Will refresh the output of the window. Set to something else
+ with |g:xqmarklogic_MLExecQueryKey|
+<LEADER>E Will to list document URIs and other
+ information. Will refresh the results window if it was a
+ database listing, otherwise opens a new window. Set to
+ something else with |g:xqmarklogic_ExploreDBKey|
==============================================================================
-4. Customization: Options and Settings *xqmarklogic-options*
+CUSTOMIZATION *xqmarklogic-options*
+ Options and Settings
- Global default values can be set in you |vimrc| file.
+Global default values can be set in you |vimrc| file.
-*g:xqmarklogic_defaultHost* - the default Host name to use, if not set
+*g:xqmarklogic_defaultHost* The default Host name to use, if not set
uses 'localhost'
-*g:xqmarklogic_defaultURI* - the default URI, if not set uses 'http://'
-*g:xqmarklogic_defaultPort* - the default Port, if not set uses 8002
+*g:xqmarklogic_defaultURI* The default URI, if not set uses 'http://'
+*g:xqmarklogic_defaultPort* The default Port, if not set uses 8002
(which is used by MarkLogic by default and
wont work)
-*g:xqmarklogic_defaultUser* - the default User, if not set uses 'admin'
-*g:xqmarklogic_defaultPassword* - the default password to use, if not set
+*g:xqmarklogic_defaultUser* The default User, if not set uses 'admin'
+*g:xqmarklogic_defaultPassword* The default password to use, if not set
you will probably have problems.
-*g:xqmarklogic_defaultScript* - the default name of the xq.xqy, if not set
+*g:xqmarklogic_defaultScript* The default name of the xq.xqy, if not set
uses '/xq.xqy'
-*g:xqmarklogic_defaultDb* - the default Database to query against, if
+*g:xqmarklogic_defaultDb* The default Database to query against, if
not set uses 'Documents'
-*g:xqmarklogic_defaultMaxLinesIndent* - if results are longer than this many
+*g:xqmarklogic_defaultMaxLinesIndent* If results are longer than this many
lines skip trying to indent them. Defaults to
400.
-*g:xqmarklogic_defaultNoOutCleanup* - Turns on (1) or off (0) Output
+*g:xqmarklogic_defaultNoOutCleanup* Turns on (1) or off (0) Output
Cleanup. Default true (1). Cleanup: split
lines where tags are not separated by a
space, reindent XML, and set foldlevel=10
-*g:xqmarklogic_defaultShowDuration* - Turns on (1) or off (0) query
+*g:xqmarklogic_defaultShowDuration* Turns on (1) or off (0) query
duration in output. Default true (1). Is
included in output in xml comment. Shown in
same comment that database used is output in.
-*g:xqmarklogic_defaultShowDb* - Turns on (1) or off (0) showing the Database
+*g:xqmarklogic_defaultShowDb* Turns on (1) or off (0) showing the Database
in query output. Default to True (1). Shown
in same comment that duration output is in.
-*g:xqmarklogic_defaultShowCurlCmd* - turns on (1) or off (0) query curl
+*g:xqmarklogic_defaultShowCurlCmd* Turns on (1) or off (0) query curl
command used in query output. Defaults to off
since command contains "--" which is invalid
in the XML comments. Shown in comment
separate from other above settings.
-*g:xqmarklogic_noMappings* - if true (set to 1) then \B and <C-CR> wont be mapped
+*g:xqmarklogic_noMappings* If true (set to 1) then \B and <C-CR> wont be mapped
+*g:xqmarklogic_ExploreDBKey* Sets the keys for the ExploreDB mapping.
+ Default <Leader>E
+*g:xqmarklogic_ExecQueryKey* Sets the keys for the ExecQueryKey mapping.
+ Default <Leader>B
+*g:xqmarklogic_MLExecQueryKey* Sets the keys for the MLExecQueryKey Mapping.
+ Default <C-CR>
+
Examples: >
let g:xqmarklogic_defaultUser='labarbara_conrad'
let g:xqmarklogic_defaultPassword='barbados_or_hermes'
View
168 ftplugin/xquery.vim
@@ -1,6 +1,6 @@
" xquery.vim - <Leader>B or <C-CR> run buffer against marklogic as an xquery
" Maintainer: Darren Cole <http://github.com/coledarr/vim-xqmarklogic>
-" Version: 1.0.5
+" Version: 1.0.7
" TODO: Add support for: GetLatestVimScripts: ### ### :AutoInstall: xqmarklogic
" TODO: see *glvs-plugins* might not work, but should at least try
"
@@ -28,51 +28,17 @@
" large responses this can be slow
"
" TODO Prompt for password if unset
-" TODO output something useful when curl returns an error
+" TODO output something more useful when curl returns an error
if exists('b:loaded_xqmarklogic')
finish
endif
let b:loaded_xqmarklogic=1
-" Toggle Options
-command -buffer XQtoggleShowCurlCmd :execute s:toggleShowCurlCmd()
-function! s:toggleShowCurlCmd()
- if (b:xqmarklogic_showCurlCmd)
- let b:xqmarklogic_showCurlCmd=0
- else
- let b:xqmarklogic_showCurlCmd=1
- endif
-endfunction
-command -buffer XQtoggleShowDuration :execute s:toggleShowDuration()
-function! s:toggleShowDuration()
- if (b:xqmarklogic_showDuration)
- let b:xqmarklogic_showDuration=0
- else
- let b:xqmarklogic_showDuration=1
- endif
-endfunction
-command -buffer XQtoggleShowDb :execute s:toggleShowDb()
-function! s:toggleShowDb()
- if (b:xqmarklogic_showDb)
- let b:xqmarklogic_showDb=0
- else
- let b:xqmarklogic_showDb=1
- endif
-endfunction
-command -buffer XQtoggleOutCleanup :execute s:toggleOutCleanup()
-function! s:toggleOutCleanup()
- if (b:xqmarklogic_noOutCleanup)
- let b:xqmarklogic_noOutCleanup=0
- else
- let b:xqmarklogic_noOutCleanup=1
- endif
-endfunction
-
-" Settings, init, & Commands to change them
-function! s:initSettings()
- " Buffer settings
+" Settings, init, & Commands to change them
+function! s:initSettings() "{{{
+ " Buffer settings {{{
if !exists('g:xqmarklogic_defaultUser')
let g:xqmarklogic_defaultUser='admin'
endif
@@ -108,8 +74,9 @@ function! s:initSettings()
let g:xqmarklogic_defaultMaxLinesIndent='400'
endif
let b:xqmarklogic_maxLinesIndent=g:xqmarklogic_defaultMaxLinesIndent
+ " }}}
- " Buffer options
+ " Buffer options {{{
if !exists('g:xqmarklogic_defaultShowCurlCmd')
let g:xqmarklogic_defaultShowCurlCmd=0
endif
@@ -127,14 +94,33 @@ function! s:initSettings()
let g:xqmarklogic_defaultNoOutCleanup=0
endif
let b:xqmarklogic_noOutCleanup=g:xqmarklogic_defaultNoOutCleanup
+ " }}}
" global settings
if !exists('g:xqmarklogic_noMappings')
let g:xqmarklogic_noMappings=0
endif
+ if exists('g:mapleader')
+ let l:leader = g:mapleader
+ else
+ let l:leader = '\'
+ endif
+ if !exists('g:xqmarklogic_ExploreDBKey')
+ let g:xqmarklogic_ExploreDBKey = l:leader . 'E'
+ endif
+ if !exists('g:xqmarklogic_ExecQueryKey')
+ let g:xqmarklogic_ExecQueryKey = l:leader . 'B'
+ endif
+ if !exists('g:xqmarklogic_MLExecQueryKey')
+ let g:xqmarklogic_MLExecQueryKey = '<C-CR>'
+ endif
+
+
endfunction
call s:initSettings()
+" }}}
+" set option & commands {{{
command -buffer -nargs=1 XQsetUser :execute s:setUser(<args>)
function! s:setUser(user)
let b:xqmarklogic_user = a:user
@@ -174,57 +160,103 @@ command -buffer -nargs=1 XQsetMaxLinesIndent :execute s:setMaxLinesIndent(<args>
function! s:setMaxLinesIndent(lines)
let b:xqmarklogic_maxLinesIndent=a:lines
endfunction
+" end of set option & commands }}}
+
+" Toggle Options & Commands {{{
+command -buffer XQtoggleShowCurlCmd :execute s:toggleShowCurlCmd()
+function! s:toggleShowCurlCmd()
+ if (b:xqmarklogic_showCurlCmd)
+ let b:xqmarklogic_showCurlCmd=0
+ else
+ let b:xqmarklogic_showCurlCmd=1
+ endif
+endfunction
+command -buffer XQtoggleShowDuration :execute s:toggleShowDuration()
+function! s:toggleShowDuration()
+ if (b:xqmarklogic_showDuration)
+ let b:xqmarklogic_showDuration=0
+ else
+ let b:xqmarklogic_showDuration=1
+ endif
+endfunction
+command -buffer XQtoggleShowDb :execute s:toggleShowDb()
+function! s:toggleShowDb()
+ if (b:xqmarklogic_showDb)
+ let b:xqmarklogic_showDb=0
+ else
+ let b:xqmarklogic_showDb=1
+ endif
+endfunction
+command -buffer XQtoggleOutCleanup :execute s:toggleOutCleanup()
+function! s:toggleOutCleanup()
+ if (b:xqmarklogic_noOutCleanup)
+ let b:xqmarklogic_noOutCleanup=0
+ else
+ let b:xqmarklogic_noOutCleanup=1
+ endif
+endfunction
+" end of toggle commands }}}
-" Display settings
+" Display settings {{{
command -buffer XQdisplaySettings :execute s:DisplaySettings()
function! s:DisplaySettings()
- echo 'b:xqmarklogic_user = ' . b:xqmarklogic_user
- echo 'b:xqmarklogic_password = ' . b:xqmarklogic_password
- echo 'b:xqmarklogic_uri = ' . b:xqmarklogic_uri
+ echo ' --- settings --- '
echo 'b:xqmarklogic_host = ' . b:xqmarklogic_host
+ echo 'b:xqmarklogic_uri = ' . b:xqmarklogic_uri
echo 'b:xqmarklogic_port = ' . b:xqmarklogic_port
+ echo 'b:xqmarklogic_user = ' . b:xqmarklogic_user
+ echo 'b:xqmarklogic_password = ' . b:xqmarklogic_password
echo 'b:xqmarklogic_script = ' . b:xqmarklogic_script
echo 'b:xqmarklogic_db = ' . b:xqmarklogic_db
+ echo 'b:xqmarklogic_maxLinesIndent = ' . b:xqmarklogic_maxLinesIndent
echo ' --- options --- '
echo 'b:xqmarklogic_noOutCleanup = ' . b:xqmarklogic_noOutCleanup
- echo 'b:xqmarklogic_showCurlCmd = ' . b:xqmarklogic_showCurlCmd
echo 'b:xqmarklogic_showDuration = ' . b:xqmarklogic_showDuration
echo 'b:xqmarklogic_showDb = ' . b:xqmarklogic_showDb
+ echo 'b:xqmarklogic_showCurlCmd = ' . b:xqmarklogic_showCurlCmd
echo ' --- global ---'
echo 'g:xqmarklogic_noMappings = ' . g:xqmarklogic_noMappings
-endfunction
+ echo 'g:xqmarklogic_ExploreDBKey = ' . g:xqmarklogic_ExploreDBKey
+ echo 'g:xqmarklogic_ExecQueryKey = ' . g:xqmarklogic_ExecQueryKey
+ echo 'g:xqmarklogic_MLExecQueryKey = ' . g:xqmarklogic_MLExecQueryKey
+endfunction "}}}
" List the documents in database
let s:thisfile = expand('<sfile>')
+" Mappings, commands, and functions {{{
if (!g:xqmarklogic_noMappings)
- map <Leader>E :XQexploreDb<cr>
+ if g:xqmarklogic_ExploreDBKey != ''
+ exec 'map <buffer> ' . g:xqmarklogic_ExploreDBKey . ' :XQexploreDb<cr>'
+ endif
endif
command -buffer XQexploreDb :execute s:ExploreDatabase()
function! s:ExploreDatabase()
- "let l:old = b:xqmarklogic_noOutCleanup
- "let b:xqmarklogic_noOutCleanup = 1
- call s:QueryGenericMarkLogic('@'.fnameescape(fnamemodify(s:thisfile, ':p:h'). '/exploreDb.xqy'))
- "let b:xqmarklogic_noOutCleanup = l:old
+ call s:QueryGenericMarkLogic('@'.fnameescape(fnamemodify(s:thisfile, ':p:h'). '/exploreDb.xqy'), 0)
endfunction
-command -buffer XQlistDocsA :execute s:QueryGenericMarkLogic(<args>)
" Running the Buffer as a Query
if (!g:xqmarklogic_noMappings)
- map <Leader>B :XQmlquery<cr>
- map <C-CR> :XQmlquery<cr>
+ if g:xqmarklogic_ExecQueryKey != ''
+ exec 'map <buffer> ' . g:xqmarklogic_ExecQueryKey . ' :XQmlquery<cr>'
+ endif
+ if g:xqmarklogic_MLExecQueryKey != ''
+ exec 'map <buffer> ' . g:xqmarklogic_MLExecQueryKey . ' :XQmlquery<cr>'
+ endif
endif
command -buffer XQmlquery :execute s:QueryMarkLogic(expand('%'))
function! s:QueryMarkLogic(fname)
if &modified
echoerr 'Buffer has been changed, using last saved version'
endif
- call s:QueryGenericMarkLogic('@'.a:fname)
+ call s:QueryGenericMarkLogic('@'.a:fname, 1)
endfunction
+" }}}
" Runs the query using curl
" a:data - what to put after the -d" in the curl command
-function! s:QueryGenericMarkLogic(data)
+command -buffer XQmlqueryArgs :execute s:QueryGenericMarkLogic(<args>)
+function! s:QueryGenericMarkLogic(data, bufferQuery)
" setup local settings
let l:user = b:xqmarklogic_user
let l:password = b:xqmarklogic_password
@@ -248,13 +280,31 @@ function! s:QueryGenericMarkLogic(data)
" Use a 'nofile' window
"botright new
belowright new
+ setlocal buftype=nofile
+ setlocal filetype=xml
+
+ " Buffer Mappings for Result window
+ if (a:bufferQuery)
+ if g:xqmarklogic_ExploreDBKey != ''
+ exec "map <buffer> " . g:xqmarklogic_ExploreDBKey . " <C-W><C-P>:XQexploreDb<cr>"
+ endif
+ else
+ if g:xqmarklogic_ExploreDBKey != ''
+ exec "map <buffer> " . g:xqmarklogic_ExploreDBKey . " :q<CR>:XQexploreDb<cr>"
+ endif
+ endif
+ if g:xqmarklogic_ExecQueryKey != ''
+ exec "map <buffer> " . g:xqmarklogic_ExecQueryKey . " :q<CR>:XQmlqueryArgs \"" . a:data . "\", 1<CR>"
+ endif
+ if g:xqmarklogic_MLExecQueryKey != ''
+ exec "map <buffer> " . g:xqmarklogic_MLExecQueryKey . " :q<CR>:XQmlqueryArgs \"" . a:data . "\", 1<cr>"
+ endif
+ map <buffer> q :q<CR>
if (l:showDb)
let l:info .= ' db="' . l:db . '"'
endif
- setlocal buftype=nofile
- setlocal filetype=xml
let curlCmd='curl --digest --user ' . l:user . ':' . l:password . ' -s -X PUT -d"' . a:data . '" ' . l:uri . l:host . ':' . l:port . l:script . '?db='.l:db
if (l:showCurlCmd)
@@ -282,4 +332,4 @@ function! s:QueryGenericMarkLogic(data)
endif
endif
endfunction
-
+

0 comments on commit 98655cf

Please sign in to comment.