Skip to content

Commit

Permalink
Add turning off mappings, expose other features, and update help
Browse files Browse the repository at this point in the history
Add ability to turn off setting mappings
Explicitly expose options turn on or off: showing curl command, show
query duration, and output cleanup
Make those three above buffer specific settings
Add (or update) commands to toggle those settings per buffer
  • Loading branch information
coledarr committed Oct 8, 2012
1 parent acf6fc6 commit ca15220
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 43 deletions.
73 changes: 49 additions & 24 deletions doc/xqmarklogic.txt
Expand Up @@ -4,7 +4,7 @@
Author: Darren Cole http://github.com/coledarr/vim-xqmarklogic Author: Darren Cole http://github.com/coledarr/vim-xqmarklogic


Integrating MarkLogic xqueries into vim, and displays the result in another Integrating MarkLogic xqueries into vim, and displays the result in another
window. This is a filetype plugin that is only available when in an xquery window. This is a filetype plugin that is only available when in an XQuery
file. file.


1. Introduction |xqmarklogic-intro| 1. Introduction |xqmarklogic-intro|
Expand All @@ -19,10 +19,10 @@ file.
============================================================================== ==============================================================================
INTRODUCTION *xqmarklogic-intro* INTRODUCTION *xqmarklogic-intro*


xqmarklogic maps <LEADER>B and <C-CR> (CTRL-RETURN like QueryConsole) to run a xqmarklogic maps <LEADER>B and <C-CR> (CONTROL-RETURN like QueryConsole) to
xquery against MarkLogic server using curl and a custom App Server running a run a XQuery against MarkLogic server using curl and a custom App Server
short xquery file. It displays the results in a new window. It was inspired running a short XQuery file. It displays the results in a new window. It was
by this webpage: inspired by this webpage:
http://superiorautomaticdictionary.com/vim-nirvana-interactive-xquery-with-marklogic http://superiorautomaticdictionary.com/vim-nirvana-interactive-xquery-with-marklogic


Git repository at: http://github.com/coledarr/vim-xqmarklogic Git repository at: http://github.com/coledarr/vim-xqmarklogic
Expand All @@ -33,7 +33,7 @@ INSTALLATION *xqmarklogic-install*
This plugin will need to be installed. This plugin will need to be installed.
Couple ways to do this: Couple ways to do this:
1. copy the doc/* and ftplugin/* to your cooresponding ~/.vim/ 1. copy the doc/* and ftplugin/* to your cooresponding ~/.vim/
directories directories. Run :helptags
2. pathogen.vim https://github.com/tpope/vim-pathogen 2. pathogen.vim https://github.com/tpope/vim-pathogen
3. vundle https://github.com/gmarik/vundle 3. vundle https://github.com/gmarik/vundle


Expand All @@ -54,7 +54,7 @@ earlier and probably later versions.


Script is in the file xqmarklogic/xq.xqry. This script takes text input Script is in the file xqmarklogic/xq.xqry. This script takes text input
and runs it against the database using xdmp:eval. This opens up your whole and runs it against the database using xdmp:eval. This opens up your whole
MarkLogic server to have arbitrary xquery run against any database by whoever MarkLogic server to have arbitrary XQuery run against any database by whoever
is authorized to access this App Server. Read the |xqmarklogic-security| is authorized to access this App Server. Read the |xqmarklogic-security|
section. This probably shouldn't be on the production server, and should be section. This probably shouldn't be on the production server, and should be
protected. protected.
Expand Down Expand Up @@ -96,7 +96,7 @@ These settings can be set differently in different buffers.
SECURITY CONSIDERATIONS *xqmarklogic-security* SECURITY CONSIDERATIONS *xqmarklogic-security*


As mentioned above xq.xqy has some security considerations. It can run any 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 XQuery against any of the MarkLogic databases. It is only as protected as the
App Server (password in the clear with http by default). xqmarklogic App Server (password in the clear with http by default). xqmarklogic
doesn't support ssl now, but that could be added (patches welcome). So be doesn't support ssl now, but that could be added (patches welcome). So be
aware. aware.
Expand All @@ -111,9 +111,11 @@ stored in the viminfo file. Pull requests with fixes for this are welcome.
============================================================================== ==============================================================================
3. Commands *xqmarklogic-commands* 3. Commands *xqmarklogic-commands*


<leader>B Run current buffer as an xquery against the MarkLogic <leader>B Run current buffer as an XQuery against the MarkLogic
App Server you setup earlier. This mapping runs XQmlquery, so App Server you setup earlier. This mapping runs XQmlquery, so
it is easy to remap this if needed. it is easy to remap this if needed.
<CTRL-CR> same as above. Control-Return that MarkLogic QueryConsole
uses


XQtoggleShowCurlCmd toggles showing curl command used in the output XQtoggleShowCurlCmd toggles showing curl command used in the output
window in an XML comment. It is off by default since window in an XML comment. It is off by default since
Expand All @@ -123,6 +125,10 @@ XQtoggleShowCurlCmd toggles showing curl command used in the output
XQtoggleShowDuration toggle showing the duration of the query. On by XQtoggleShowDuration toggle showing the duration of the query. On by
default. default.


XQtoggleOutCleanup toggle if xml output is cleaned up or not. (insert
newlines between empty adjacent tags, reindent XML,
set foldlevel=10)

XQsetUser sets the user to use for login to the string argument XQsetUser sets the user to use for login to the string argument


XQsetPassword sets the password to use for login to the string XQsetPassword sets the password to use for login to the string
Expand All @@ -141,6 +147,7 @@ XQsetDatabase sets the database to query against to the string
XQdisplaySettings Displays what the current buffer settings are. XQdisplaySettings Displays what the current buffer settings are.


XQmlquery Run the current buffer against the MarkLogic server XQmlquery Run the current buffer against the MarkLogic server
and display the output in a new window.




============================================================================== ==============================================================================
Expand All @@ -160,24 +167,42 @@ g:xqmarklogic_defaultPassword - the default password to use, if not set
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' 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' not set uses 'Documents'

g:xqmarklogic_defaultNoOutCleanup - Turns on (1) or off (0) Output
g:xqmarklogic_noMappings - if set \B and <C-CR> wont be mapped Cleanup. Default true (1). Cleanup: split
Example: > 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
duration in output. Default true (1). Is
included in output in xml comment
g:xqmarklogic_defaultCurlCmd - turns on (1) or off (0) query curl
command used in query output. Defaults to off
since command contains "--" which is valid in
the XML comment information is included in
g:xqmarklogic_noMappings - if true (set to 1) then \B and <C-CR> wont be mapped
Examples: >
let g:xqmarklogic_defaultUser='labarbara_conrad' let g:xqmarklogic_defaultUser='labarbara_conrad'
let g:xqmarklogic_defaultPassword='barbados_or_hermes'
let g:xqmarklogic_noMappings=1
< <


Several of these values can be set on a per buffer basis, here are These values can be set on a per buffer basis through
the corresponding various commands described in |xqmarklogic-commands|. They can be set via

buffer variables below
b:xqmarklogic_host corresponds to: g:xqmarklogic_defaultHost
b:xqmarklogic_uri corresponds to: g:xqmarklogic_defaultURI b:xqmarklogic_user corresponds to g:xqmarklogic_defaultUser
b:xqmarklogic_port corresponds to: g:xqmarklogic_defaultPort b:xqmarklogic_password corresponds to g:xqmarklogic_defaultPassword
b:xqmarklogic_user corresponds to: g:xqmarklogic_defaultUser b:xqmarklogic_uri corresponds to g:xqmarklogic_defaultURI
b:xqmarklogic_password corresponds to: g:xqmarklogic_defaultPassword b:xqmarklogic_host corresponds to g:xqmarklogic_defaultHost
b:xqmarklogic_script corresponds to: g:xqmarklogic_defaultScript b:xqmarklogic_port corresponds to g:xqmarklogic_defaultPort
b:xqmarklogic_db corresponds to: g:xqmarklogic_defaultDb b:xqmarklogic_script corresponds to g:xqmarklogic_defaultScript
Example run when the cursor is in the xquery file you want it set to: > b:xqmarklogic_db corresponds to g:xqmarklogic_defaultDb
b:xqmarklogic_showCurlCmd corresponds to g:xqmarklogic_showCurlCmd
b:xqmarklogic_showDuration corresponds to g:xqmarklogic_defaultShowDuration
b:xqmarklogic_noOutCleanup corresponds to g:xqmarklogic_defaultNoOutCleanup

Example run when the cursor is in the XQuery file you want it set to: >
:let b:xqmarklogic_password='flexo'
:let b:xqmarklogic_password='flexo_is_the_greatest' :let b:xqmarklogic_password='flexo_is_the_greatest'
< <


Expand Down
75 changes: 56 additions & 19 deletions ftplugin/xquery.vim
@@ -1,8 +1,8 @@
" xquery.vim - <Leader>B or <C-CR> run buffer against marklogic as an xquery " xquery.vim - <Leader>B or <C-CR> run buffer against marklogic as an xquery
" Maintainer: Darren Cole <http://github.com/coledarr/vim-xqmarklogic> " Maintainer: Darren Cole <http://github.com/coledarr/vim-xqmarklogic>
" Version: 1.0.0 " Version: 1.0.1
" TODO: Add support for: GetLatestVimScripts: ### ### :AutoInstall: xqmarklogic " TODO: Add support for: GetLatestVimScripts: ### ### :AutoInstall: xqmarklogic
" TODO: see *glvs-plugins* " TODO: see *glvs-plugins* might not work, but should at least try
" "
" Inspired partly by: http://superiorautomaticdictionary.com/vim-nirvana-interactive-xquery-with-marklogic " Inspired partly by: http://superiorautomaticdictionary.com/vim-nirvana-interactive-xquery-with-marklogic
" "
Expand Down Expand Up @@ -36,30 +36,35 @@ if exists('b:loaded_xqmarklogic')
endif endif
let b:loaded_xqmarklogic=1 let b:loaded_xqmarklogic=1


" Options
let s:showCurlCmd=0
let s:showDuration=1

" Toggle Options " Toggle Options
command -buffer XQtoggleShowCurlCmd :execute s:toggleShowCurlCmd() command -buffer XQtoggleShowCurlCmd :execute s:toggleShowCurlCmd()
function! s:toggleShowCurlCmd() function! s:toggleShowCurlCmd()
if (s:showCurlCmd) if (b:xqmarklogic_showCurlCmd)
let s:showCurlCmd=0 let b:xqmarklogic_showCurlCmd=0
else else
let s:showCurlCmd=1 let b:xqmarklogic_showCurlCmd=1
endif endif
endfunction endfunction
command -buffer XQtoggleShowDuration :execute s:toggleShowDuration() command -buffer XQtoggleShowDuration :execute s:toggleShowDuration()
function! s:toggleShowDuration() function! s:toggleShowDuration()
if (s:showDuration) if (b:xqmarklogic_showDuration)
let s:showDuration=0 let b:xqmarklogic_showDuration=0
else
let b:xqmarklogic_showDuration=1
endif
endfunction
command -buffer XQtoggleOutCleanup :execute s:toggleOutCleanup()
function! s:toggleOutCleanup()
if (b:xqmarklogic_noOutCleanup)
let b:xqmarklogic_noOutCleanup=0
else else
let s:showDuration=1 let b:xqmarklogic_noOutCleanup=1
endif endif
endfunction endfunction


" Settings, init, & Commands to change them " Settings, init, & Commands to change them
function! s:initSettings() function! s:initSettings()
" Buffer settings
if !exists('g:xqmarklogic_defaultUser') if !exists('g:xqmarklogic_defaultUser')
let g:xqmarklogic_defaultUser='admin' let g:xqmarklogic_defaultUser='admin'
endif endif
Expand Down Expand Up @@ -91,10 +96,30 @@ function! s:initSettings()
let g:xqmarklogic_defaultDb="Documents" let g:xqmarklogic_defaultDb="Documents"
endif endif
let b:xqmarklogic_db=g:xqmarklogic_defaultDb let b:xqmarklogic_db=g:xqmarklogic_defaultDb
command -buffer -nargs=1 XQsetUser :execute s:setUser(<args>)
" Buffer options
if !exists('g:xqmarklogic_defaultShowCurlCmd')
let g:xqmarklogic_defaultShowCurlCmd=0
endif
let b:xqmarklogic_showCurlCmd=g:xqmarklogic_defaultShowCurlCmd
if !exists('g:xqmarklogic_defaultshowDuration')
let g:xqmarklogic_defaultShowDuration=0
endif
let b:xqmarklogic_showDuration=g:xqmarklogic_defaultShowDuration

if !exists('g:xqmarklogic_defaultNoOutCleanup')
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
endfunction endfunction
call s:initSettings() call s:initSettings()


command -buffer -nargs=1 XQsetUser :execute s:setUser(<args>)
function! s:setUser(user) function! s:setUser(user)
let b:xqmarklogic_user = a:user let b:xqmarklogic_user = a:user
endfunction endfunction
Expand Down Expand Up @@ -139,10 +164,16 @@ function! s:DisplaySettings()
echo 'b:xqmarklogic_port = ' . b:xqmarklogic_port echo 'b:xqmarklogic_port = ' . b:xqmarklogic_port
echo 'b:xqmarklogic_script = ' . b:xqmarklogic_script echo 'b:xqmarklogic_script = ' . b:xqmarklogic_script
echo 'b:xqmarklogic_db = ' . b:xqmarklogic_db echo 'b:xqmarklogic_db = ' . b:xqmarklogic_db
echo ' --- options --- '
echo 'b:xqmarklogic_noOutCleanup = ' . b:xqmarklogic_noOutCleanup
echo 'b:showCurlCmd = ' . b:showCurlCmd
echo 'b:showDuration = ' . b:showDuration
echo ' --- global ---'
echo 'g:xqmarklogic_noMappings = ' . g:xqmarklogic_noMappings
endfunction endfunction


" Running the Query " Running the Query
if !exists('g:xqmarklogic_noMappings') if (!g:xqmarklogic_noMappings)
map <Leader>B :XQmlquery<cr> map <Leader>B :XQmlquery<cr>
map <C-CR> :XQmlquery<cr> map <C-CR> :XQmlquery<cr>
endif endif
Expand All @@ -156,8 +187,11 @@ function! s:QueryMarkLogic(fname)
let l:uri = b:xqmarklogic_uri let l:uri = b:xqmarklogic_uri
let l:host = b:xqmarklogic_host let l:host = b:xqmarklogic_host
let l:port = b:xqmarklogic_port let l:port = b:xqmarklogic_port
let l:script = b:xqmarklogic_script let l:script = b:xqmarklogic_script
let l:db = b:xqmarklogic_db let l:db = b:xqmarklogic_db
let l:noOutClean = b:xqmarklogic_noOutCleanup
let l:showCurlCmd = b:xqmarklogic_showCurlCmd
let l:showDuration = b:xqmarklogic_showDuration


" Could use preview window " Could use preview window
"let s:out = tempname() "let s:out = tempname()
Expand All @@ -174,22 +208,25 @@ function! s:QueryMarkLogic(fname)
setlocal filetype=xml setlocal filetype=xml
let curlCmd='curl --digest --user ' . l:user . ':' . l:password . ' -s -X PUT -d@"' . a:fname . '" ' . l:uri . l:host . ':' . l:port . l:script . '?db='.l:db let curlCmd='curl --digest --user ' . l:user . ':' . l:password . ' -s -X PUT -d@"' . a:fname . '" ' . l:uri . l:host . ':' . l:port . l:script . '?db='.l:db


if (s:showCurlCmd) if (l:showCurlCmd)
call append(0, '<!-- ' . curlCmd . ' -->') call append(0, '<!-- ' . curlCmd . ' -->')
endif endif


let start=reltime() let start=reltime()
execute 'r! ' . curlCmd execute 'r! ' . curlCmd


if (s:showDuration) if (l:showDuration)
let end=reltimestr(reltime(start)) let end=reltimestr(reltime(start))
let info .= ' query_duration="' . end . '"' let info .= ' query_duration="' . end . '"'
endif endif
call append(0, '<!-- ' . info .'" -->') call append(0, '<!-- ' . info .'" -->')


" cleanup output " cleanup output
silent! :%s/></></g if (!l:noOutClean)
normal gg=G silent! :%s/></></g
normal gg=G
setlocal foldlevel=10
endif
endfunction endfunction


" vim: foldmethod=marker foldlevel=5: " vim: foldmethod=marker foldlevel=5:
Expand Down

0 comments on commit ca15220

Please sign in to comment.