Permalink
Browse files

Add turning off mappings, expose other features, and update help

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...
1 parent acf6fc6 commit ca152205e835df142b53298907d49ab9edac933f @coledarr committed Oct 8, 2012
Showing with 105 additions and 43 deletions.
  1. +49 −24 doc/xqmarklogic.txt
  2. +56 −19 ftplugin/xquery.vim
View
@@ -4,7 +4,7 @@
Author: Darren Cole http://github.com/coledarr/vim-xqmarklogic
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.
1. Introduction |xqmarklogic-intro|
@@ -19,10 +19,10 @@ file.
==============================================================================
INTRODUCTION *xqmarklogic-intro*
-xqmarklogic maps <LEADER>B and <C-CR> (CTRL-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 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:
http://superiorautomaticdictionary.com/vim-nirvana-interactive-xquery-with-marklogic
Git repository at: http://github.com/coledarr/vim-xqmarklogic
@@ -33,7 +33,7 @@ INSTALLATION *xqmarklogic-install*
This plugin will need to be installed.
Couple ways to do this:
1. copy the doc/* and ftplugin/* to your cooresponding ~/.vim/
- directories
+ directories. Run :helptags
2. pathogen.vim https://github.com/tpope/vim-pathogen
3. vundle https://github.com/gmarik/vundle
@@ -54,7 +54,7 @@ earlier and probably later versions.
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
-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|
section. This probably shouldn't be on the production server, and should be
protected.
@@ -96,7 +96,7 @@ These settings can be set differently in different buffers.
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
+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
doesn't support ssl now, but that could be added (patches welcome). So be
aware.
@@ -111,9 +111,11 @@ stored in the viminfo file. Pull requests with fixes for this are welcome.
==============================================================================
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
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
window in an XML comment. It is off by default since
@@ -123,6 +125,10 @@ XQtoggleShowCurlCmd toggles showing curl command used in the output
XQtoggleShowDuration toggle showing the duration of the query. On by
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
XQsetPassword sets the password to use for login to the string
@@ -141,6 +147,7 @@ XQsetDatabase sets the database to query against to the string
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.
==============================================================================
@@ -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
uses '/xq.xqy'
g:xqmarklogic_defaultDb - the default Database to query against, if
- not set uses 'Documents'
-
-g:xqmarklogic_noMappings - if set \B and <C-CR> wont be mapped
- Example: >
+ not set uses 'Documents'
+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
+ 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_defaultPassword='barbados_or_hermes'
+ let g:xqmarklogic_noMappings=1
<
- Several of these values can be set on a per buffer basis, here are
-the corresponding
-
-b:xqmarklogic_host corresponds to: g:xqmarklogic_defaultHost
-b:xqmarklogic_uri corresponds to: g:xqmarklogic_defaultURI
-b:xqmarklogic_port corresponds to: g:xqmarklogic_defaultPort
-b:xqmarklogic_user corresponds to: g:xqmarklogic_defaultUser
-b:xqmarklogic_password corresponds to: g:xqmarklogic_defaultPassword
-b:xqmarklogic_script corresponds to: g:xqmarklogic_defaultScript
-b:xqmarklogic_db corresponds to: g:xqmarklogic_defaultDb
- Example run when the cursor is in the xquery file you want it set to: >
+ These values can be set on a per buffer basis through
+various commands described in |xqmarklogic-commands|. They can be set via
+buffer variables below
+
+b:xqmarklogic_user corresponds to g:xqmarklogic_defaultUser
+b:xqmarklogic_password corresponds to g:xqmarklogic_defaultPassword
+b:xqmarklogic_uri corresponds to g:xqmarklogic_defaultURI
+b:xqmarklogic_host corresponds to g:xqmarklogic_defaultHost
+b:xqmarklogic_port corresponds to g:xqmarklogic_defaultPort
+b:xqmarklogic_script corresponds to g:xqmarklogic_defaultScript
+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'
<
View
@@ -1,8 +1,8 @@
" 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.0
+" Version: 1.0.1
" 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
"
@@ -36,30 +36,35 @@ if exists('b:loaded_xqmarklogic')
endif
let b:loaded_xqmarklogic=1
-" Options
-let s:showCurlCmd=0
-let s:showDuration=1
-
" Toggle Options
command -buffer XQtoggleShowCurlCmd :execute s:toggleShowCurlCmd()
function! s:toggleShowCurlCmd()
- if (s:showCurlCmd)
- let s:showCurlCmd=0
+ if (b:xqmarklogic_showCurlCmd)
+ let b:xqmarklogic_showCurlCmd=0
else
- let s:showCurlCmd=1
+ let b:xqmarklogic_showCurlCmd=1
endif
endfunction
command -buffer XQtoggleShowDuration :execute s:toggleShowDuration()
function! s:toggleShowDuration()
- if (s:showDuration)
- let s:showDuration=0
+ if (b:xqmarklogic_showDuration)
+ 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
- let s:showDuration=1
+ let b:xqmarklogic_noOutCleanup=1
endif
endfunction
" Settings, init, & Commands to change them
function! s:initSettings()
+ " Buffer settings
if !exists('g:xqmarklogic_defaultUser')
let g:xqmarklogic_defaultUser='admin'
endif
@@ -91,10 +96,30 @@ function! s:initSettings()
let g:xqmarklogic_defaultDb="Documents"
endif
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
call s:initSettings()
+command -buffer -nargs=1 XQsetUser :execute s:setUser(<args>)
function! s:setUser(user)
let b:xqmarklogic_user = a:user
endfunction
@@ -139,10 +164,16 @@ function! s:DisplaySettings()
echo 'b:xqmarklogic_port = ' . b:xqmarklogic_port
echo 'b:xqmarklogic_script = ' . b:xqmarklogic_script
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
" Running the Query
-if !exists('g:xqmarklogic_noMappings')
+if (!g:xqmarklogic_noMappings)
map <Leader>B :XQmlquery<cr>
map <C-CR> :XQmlquery<cr>
endif
@@ -156,8 +187,11 @@ function! s:QueryMarkLogic(fname)
let l:uri = b:xqmarklogic_uri
let l:host = b:xqmarklogic_host
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:noOutClean = b:xqmarklogic_noOutCleanup
+ let l:showCurlCmd = b:xqmarklogic_showCurlCmd
+ let l:showDuration = b:xqmarklogic_showDuration
" Could use preview window
"let s:out = tempname()
@@ -174,22 +208,25 @@ function! s:QueryMarkLogic(fname)
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
- if (s:showCurlCmd)
+ if (l:showCurlCmd)
call append(0, '<!-- ' . curlCmd . ' -->')
endif
let start=reltime()
execute 'r! ' . curlCmd
- if (s:showDuration)
+ if (l:showDuration)
let end=reltimestr(reltime(start))
let info .= ' query_duration="' . end . '"'
endif
call append(0, '<!-- ' . info .'" -->')
" cleanup output
- silent! :%s/></></g
- normal gg=G
+ if (!l:noOutClean)
+ silent! :%s/></></g
+ normal gg=G
+ setlocal foldlevel=10
+ endif
endfunction
" vim: foldmethod=marker foldlevel=5:

0 comments on commit ca15220

Please sign in to comment.