Permalink
Browse files

Version 1.0.2

Can turn off setting mappings.
Can turn on or off showing in query of: curl command, query duration, database used.
Can turn off query cleanup
Update helpfile
  • Loading branch information...
1 parent e18f2fc commit f4d33c2083f6d1fccfe8f8e3ca8ff40663858b86 @coledarr coledarr committed with Oct 10, 2012
Showing with 139 additions and 49 deletions.
  1. +2 −2 README.md
  2. +57 −24 doc/xqmarklogic.txt
  3. +80 −23 ftplugin/xquery.vim
View
@@ -4,8 +4,8 @@ xqmarklogic
Vim filetype plugin enables you to run xqueries files against a MarkLogic
server, it displays the results in a separate window.
-* [See](http://www.vim.org)
-* [Source](github.com/coledarr/vim-xqmarklogic)
+* [See](http://www.vim.org/scripts/script.php?script_id=4255)
+* [Source](http://github.com/coledarr/vim-xqmarklogic)
Requirements
------------
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,13 @@ XQtoggleShowCurlCmd toggles showing curl command used in the output
XQtoggleShowDuration toggle showing the duration of the query. On by
default.
+XQtoggleShowDb toggle showing the Database used by 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 +150,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 +170,47 @@ 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. Shown in
+ same comment that database used is output in.
+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_defaultCurlCmd - 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
+ 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/xqmarklogic>
-" Version: 1.0.0
+" Maintainer: Darren Cole <http://github.com/coledarr/vim-xqmarklogic>
+" Version: 1.0.2
" 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,43 @@ 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 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 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 +104,34 @@ 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=1
+ endif
+ let b:xqmarklogic_showDuration=g:xqmarklogic_defaultShowDuration
+ if !exists('g:xqmarklogic_defaultshowDb')
+ let g:xqmarklogic_defaultShowDb=1
+ endif
+ let b:xqmarklogic_showDb=g:xqmarklogic_defaultShowDb
+
+ 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 +176,17 @@ 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:xqmarklogic_showCurlCmd = ' . b:xqmarklogic_showCurlCmd
+ echo 'b:xqmarklogic_showDuration = ' . b:xqmarklogic_showDuration
+ echo 'b:xqmarklogic_showDb = ' . b:xqmarklogic_showDb
+ 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 +200,13 @@ 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
+ let l:showDb = b:xqmarklogic_showDb
+ let l:info=""
" Could use preview window
"let s:out = tempname()
@@ -167,29 +216,37 @@ function! s:QueryMarkLogic(fname)
" Use a 'nofile' window
"botright new
belowright new
+
- let info .= ' db="' . l:db . '"'
+ 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: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 . '"'
+ let l:info .= ' query_duration="' . end . '"'
+ endif
+ if (l:info != "" )
+ call append(0, '<!-- ' . l:info .'" -->')
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 f4d33c2

Please sign in to comment.