Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Change it to a filetype plugin

  • Loading branch information...
commit b91db762b254680275bc3b92756d72953390d6b7 1 parent 5676000
@coledarr authored
Showing with 84 additions and 56 deletions.
  1. +21 −8 doc/xqmarklogic.txt
  2. +63 −48 plugin/xqmarklogic.vim → ftplugin/xquery.vim
View
29 doc/xqmarklogic.txt
@@ -1,4 +1,4 @@
- xqmarklogic.vim Documentation *xqmarklogic*
+ xqmarklogic Documentation *xqmarklogic*
Integrating MarkLogic xqueries into vim, and displays the result in another
window
@@ -13,7 +13,7 @@ window
==============================================================================
1. Introduction *xqmarklogic-intro*
-xqmarklogic.vim maps <LEADER>B to run a xquery against MarkLogic
+xqmarklogic maps <LEADER>B 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
@@ -24,8 +24,8 @@ Git repository at: github.com/coledarr/vim-xqmarklogic
2.1. Installation *xqmarklogic-install*
You will need MarkLogic running, a MarkLogic App Server setup to run a xquery,
-curl, and this xqmarklogic.vim plugin. MarkLogic provides an XML database,
-and even has a free version called MarkLogic Express.
+curl, and this xqmarklogic file type plugin. MarkLogic provides an XML
+database, and even has a free version called MarkLogic Express.
See: <http://www.marklogic.com/>
This plugin was developed and used with MarkLogic6, but should work with
@@ -52,7 +52,7 @@ welcome. wget doesn't work, again patches welcome.
This plugin will need to be installed.
Couple ways to do this:
- 1. copy the doc/* and plugin/* to your cooresponding ~/.vim/
+ 1. copy the doc/* and ftplugin/* to your cooresponding ~/.vim/
directories
2. pathogen.vim <https://github.com/tpope/vim-pathogen>
3. vundle <https://github.com/gmarik/vundle>
@@ -82,7 +82,7 @@ These settings can be set differently in different buffers.
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
-App Server (password in the clear with http by default). The xqmarklogic.vim
+App Server (password in the clear with http by default). The xqmarklogic
doesn't support ssl now, but that could be added. So be aware.
Second issue is less obvious and has the potential to expose the MarkLogic
@@ -107,6 +107,18 @@ XQtoggleShowCurlCmd toggles showing curl command used in the output
XQtoggleShowDuration toggle showing the duration of the query. On by
default.
+XQsetUser sets the user to use for login to the string argument
+
+XQsetPassword sets the password to use for login to the string
+ argument
+XQsetURI sets the URI to use to the string argument
+
+XQsetHost sets the host to use to the string argument
+
+XQsetPort sets the port to use to the argument
+
+XQsetScript sets the script to use to the string argument
+
XQsetDatabase sets the database to query against to the string
argument.
@@ -114,6 +126,7 @@ XQdisplaySettings Displays what the current buffer settings are, they
are currentlyt NOT initialized until after the first
query.
+
==============================================================================
4. Customization: Options and Settings *xqmarklogic-options*
@@ -128,7 +141,7 @@ g:xqmarklogic_defaultPort - the default Port, if not set uses 8002
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_defaultXq - 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
not set uses 'Documents'
@@ -143,7 +156,7 @@ 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_xq corresponds to: g:xqmarklogic_defaultXq
+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
:let b:xqmarklogic_password='flexo_is_the_greatest'
View
111 plugin/xqmarklogic.vim → ftplugin/xquery.vim
@@ -1,10 +1,11 @@
-" xqmarklogic.vim - man <Leader>B run against marklogic
+" xquery.vim - man <Leader>B run against marklogic
" Maintainer: Darren Cole <http://github.com/coledarr/xqmarklogic>
-" Version: 0.6.1
+" Version: 0.7.0
" TODO: GetLatestVimScripts: ### ### :AutoInstall: xqmarklogic
" TODO: see *glvs-plugins*
"
" Inspired partly by: http://superiorautomaticdictionary.com/vim-nirvana-interactive-xquery-with-marklogic
+"
" Assumes xq is setup
" ==== xq.xqy ====
" xquery version "1.0-ml";
@@ -20,7 +21,7 @@
" $e
" }
" ==== end xq.xqy ====
-" This script is will execute whatever it is sent with xdmp:eval, so it can do
+" The above script will execute whatever it is sent with xdmp:eval, so it can do
" pretty anything to the database
"
" Assumes xml responses, for now tries to break up lines and re-indent (TODO better
@@ -34,22 +35,40 @@
" TODO only load for xquery files, and better initialization
" TODO output something useful when curl returns an error
-if exists('g:loaded_xqmarklogic')
+
+if exists('b:loaded_xqmarklogic')
finish
endif
-let g:loaded_xqmarklogic=1
+let b:loaded_xqmarklogic=1
" Options
let s:showCurlCmd=0
let s:showDuration=1
-" initialize Default Settings {{{
-function! s:initDefaultSettings()
+" Toggle Options
+command -buffer XQtoggleShowCurlCmd :execute s:toggleShowCurlCmd()
+function! s:toggleShowCurlCmd()
+ if (s:showCurlCmd)
+ let s:showCurlCmd=0
+ else
+ let s:showCurlCmd=1
+ endif
+endfunction
+command -buffer XQtoggleShowDuration :execute s:toggleShowDuration()
+function! s:toggleShowDuration()
+ if (s:showDuration)
+ let s:showDuration=0
+ else
+ let s:showDuration=1
+ endif
+endfunction
+
+" Settings, init, & Commands to change them
+function! s:initSettings()
if !exists('g:xqmarklogic_defaultUser')
let g:xqmarklogic_defaultUser='admin'
endif
let b:xqmarklogic_user=g:xqmarklogic_defaultUser
-
" TODO Want error if no global password set
if !exists('g:xqmarklogic_defaultPassword')
let g:xqmarklogic_defaultPassword=''
@@ -57,93 +76,89 @@ function! s:initDefaultSettings()
unlet b:xqmarklogic_password
endif
let b:xqmarklogic_password=g:xqmarklogic_defaultPassword
-
if !exists('g:xqmarklogic_defaultURI')
let g:xqmarklogic_defaultURI='http://'
endif
let b:xqmarklogic_uri=g:xqmarklogic_defaultURI
-
if !exists('g:xqmarklogic_defaultHost')
let g:xqmarklogic_defaultHost='localhost'
endif
let b:xqmarklogic_host=g:xqmarklogic_defaultHost
-
if !exists('g:xqmarklogic_defaultPort')
let g:xqmarklogic_defaultPort='8002'
endif
let b:xqmarklogic_port=g:xqmarklogic_defaultPort
-
- if !exists('g:xqmarklogic_defaultXq')
- let g:xqmarklogic_defaultXq='/xq.xqy'
+ if !exists('g:xqmarklogic_defaultScript')
+ let g:xqmarklogic_defaultScript='/xq.xqy'
endif
- let b:xqmarklogic_xq=g:xqmarklogic_defaultXq
-
+ let b:xqmarklogic_script=g:xqmarklogic_defaultScript
if !exists('g:xqmarklogic_defaultDb')
let g:xqmarklogic_defaultDb="Documents"
endif
let b:xqmarklogic_db=g:xqmarklogic_defaultDb
+ command -buffer -nargs=1 XQsetUser :execute s:setUser(<args>)
+endfunction
+call s:initSettings()
- let b:xqmarklogic_initialized=1
+function! s:setUser(user)
+ let b:xqmarklogic_user = a:user
endfunction
-" end of default Settings }}}
-" Toggle Options
-command XQtoggleShowCurlCmd :execute s:toggleShowCurlCmd()
-function! s:toggleShowCurlCmd()
- if (s:showCurlCmd)
- let s:showCurlCmd=0
- else
- let s:showCurlCmd=1
- endif
+command -buffer -nargs=1 XQsetPassword :execute s:setPort(<args>)
+function! s:setPassword(password)
+ let b:xqmarklogic_password = a:password
endfunction
-command XQtoggleShowDuration :execute s:toggleShowDuration()
-function! s:toggleShowDuration()
- if (s:showDuration)
- let s:showDuration=0
- else
- let s:showDuration=1
- endif
+
+command -buffer -nargs=1 XQsetURI :execute s:setURI(<args>)
+function! s:setURI(uri)
+ let b:xqmarklogic_uri = a:uri
+endfunction
+
+command -buffer -nargs=1 XQsetHost :execute s:setHost(<args>)
+function! s:setHost(host)
+ let b:xqmarklogic_host = a:host
+endfunction
+
+command -buffer -nargs=1 XQsetPort :execute s:setPort(<args>)
+function! s:setPort(port)
+ let b:xqmarklogic_port = a:port
endfunction
-" Settings
-command -nargs=1 XQsetDatabase :execute s:setDatabase(<args>)
+command -buffer -nargs=1 XQsetScript :execute s:setScript(<args>)
+function! s:setScript(script)
+ let b:xqmarklogic_script = a:script
+endfunction
+command -buffer -nargs=1 XQsetDatabase :execute s:setDatabase(<args>)
function! s:setDatabase(db)
let b:xqmarklogic_db = a:db
endfunction
" Display settings
-command XQdisplaySettings :execute s:DisplaySettings()
+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 'b:xqmarklogic_host = ' . b:xqmarklogic_host
echo 'b:xqmarklogic_port = ' . b:xqmarklogic_port
- echo 'b:xqmarklogic_xq = ' . b:xqmarklogic_xq
+ echo 'b:xqmarklogic_script = ' . b:xqmarklogic_script
echo 'b:xqmarklogic_db = ' . b:xqmarklogic_db
endfunction
" Running the Query
map <Leader>B :XQmlquery<cr>
-
-command XQmlquery :execute s:QueryMarkLogic(expand("%"))
-
-" Used for preview window
+command -buffer XQmlquery :execute s:QueryMarkLogic(expand("%"))
function! s:QueryMarkLogic(fname)
let info = ''
- if !exists('b:xqmarklogic_initialized')
- call s:initDefaultSettings()
- endif
-
" setup local settings
let l:user = b:xqmarklogic_user
let l:password = b:xqmarklogic_password
let l:uri = b:xqmarklogic_uri
let l:host = b:xqmarklogic_host
let l:port = b:xqmarklogic_port
- let l:xq = b:xqmarklogic_xq
+ let l:script = b:xqmarklogic_script
let l:db = b:xqmarklogic_db
" Could use preview window
@@ -159,7 +174,7 @@ function! s:QueryMarkLogic(fname)
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:xq . '?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)
call append(0, '<!-- ' . curlCmd . ' -->')
@@ -174,7 +189,7 @@ function! s:QueryMarkLogic(fname)
endif
call append(0, '<!-- ' . info .'" -->')
-
+ " cleanup output
silent! :%s/></>
</g
normal gg=G
Please sign in to comment.
Something went wrong with that request. Please try again.