Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Version 1.0.5

Skip indenting results if over 400 lines
Warn if xquery buffer has changed but was not saved
Add XQexploreDb command and Mapping
    List documents in database with some extra info
    (somewhat like "Explore" button in Query Console)
  • Loading branch information...
commit ff33309f7654c21276398cbb5c967ef8a01a1637 1 parent f4d33c2
@coledarr coledarr authored committed
View
6 README.md
@@ -15,7 +15,7 @@ vim (obviously), MarkLogic (probably obvious), and curl (not so obvious)
Installation
------------
-Can be broken into two steps. Setup vim and to setup MarkLogic
+Can be broken into two steps. Setup vim and setup MarkLogic
For setting up vim I'd suggest either
@@ -50,4 +50,6 @@ For more details and setting up MarkLogic run this in vim once you've done the a
:help xqmarklogic-install
-It works well with [xqyeryvim](http://www.vim.org/scripts/script.php?script_id=3611)
+It works well with [xqyeryvim](http://www.vim.org/scripts/script.php?script_id=3611) source:[xqueryvim](http://github.com/dlam26/xqueryvim)
+
+If you'd like to run XPath in vim see [vim-xpath](http://www.vim.org/scripts/script.php?script_id=3537) source:[vim-xpath](https://github.com/actionshrimp/vim-xpath)
View
114 doc/xqmarklogic.txt
@@ -7,6 +7,9 @@ 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
file.
+Note Vim 7.3 and later hides '|' and '*'. If using an earlier version ignore
+any '*' or '|' surrounding Command and variable names.
+
1. Introduction |xqmarklogic-intro|
2 Installation |xqmarklogic-install|
MarkLogic configuration |xqmarklogic-config-marklogic|
@@ -31,11 +34,12 @@ Git repository at: http://github.com/coledarr/vim-xqmarklogic
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. Run :helptags
- 2. pathogen.vim https://github.com/tpope/vim-pathogen
- 3. vundle https://github.com/gmarik/vundle
+Few ways to do this:
+ 1. use pathogen.vim https://github.com/tpope/vim-pathogen
+ 2. use vundle https://github.com/gmarik/vundle
+ 3. use another plugin manager
+ 4. Otherwise copy the doc/* and ftplugin/* to your cooresponding ~/.vim/
+ directories (create them if they don't exist yet). Run :helptags
See pathogen.vim's documentation to set it up (it's easy). Then put the
xqmarklogic directory in your ~/.vim/bundle directory, and run :Helptags
@@ -50,7 +54,7 @@ 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
-earlier and probably later versions.
+earlier and 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
@@ -103,7 +107,7 @@ aware.
Second issue is less obvious and has the potential to expose the MarkLogic
password to everyone who can login into the local machine. Vim stores command
-history in ~/.viminfo. If you set and |xqmarklogic-options| below (particularly
+history in ~/.viminfo. If you set and use |xqmarklogic-options| below (particularly
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.
@@ -111,83 +115,100 @@ 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
+<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.
+
+NOTE If you want your own mappings set |g:xqmarklogic_noMappings| in your
+vimrc to skip setting the above.
-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
the command contains "--" and thus can't be in a valid
XML comment.
-XQtoggleShowDuration toggle showing the duration of the query. On by
+*XQtoggleShowDuration* toggle showing the duration of the query. On by
default.
-XQtoggleShowDb toggle showing the Database used by the query. On by
+*XQtoggleShowDb* toggle showing the Database used by the query. On by
default.
-XQtoggleOutCleanup toggle if xml output is cleaned up or not. (insert
+*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
argument
-XQsetURI sets the URI to use to the string argument
+*XQsetURI* sets the URI to use to the string argument
-XQsetHost sets the host 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
+*XQsetPort* sets the port to use to the argument
-XQsetScript sets the script to use to the string argument
+*XQsetScript* sets the script to use to the string argument
-XQsetDatabase sets the database to query against to the string
+*XQsetDatabase* sets the database to query against to the string
argument.
-XQdisplaySettings Displays what the current buffer settings are.
+*XQsetMaxLinesIndent* sets the max lines to indent in the results window,
+ default to 400.
+
+*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.
+*XQexploreDb* Display in a new 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.
==============================================================================
4. Customization: Options and Settings *xqmarklogic-options*
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_defaultNoOutCleanup - Turns on (1) or off (0) Output
+*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
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_defaultCurlCmd - 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
Examples: >
let g:xqmarklogic_defaultUser='labarbara_conrad'
let g:xqmarklogic_defaultPassword='barbados_or_hermes'
@@ -198,19 +219,20 @@ g:xqmarklogic_noMappings - if true (set to 1) then \B and <C-CR> wont be mapped
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'
+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:xmarklogic_maxLinesIndent corresponds to |g:xqmarklogic_defaultMaxLinesIndent|
+b:xqmarklogic_showCurlCmd corresponds to |g:xqmarklogic_defaultShowCurlCmd|
+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 for: >
+ :let b:xqmarklogic_user='flexo'
:let b:xqmarklogic_password='flexo_is_the_greatest'
<
View
12 ftplugin/exploreDb.xqy
@@ -0,0 +1,12 @@
+xquery version "1.0-ml";
+
+for $doc in fn:doc()
+ let $uri := fn:document-uri($doc)
+return
+ <document db_uri="{$uri}">
+ {if ($doc/name(/*) = "")
+ (: Assume a binary document if root element name is "" :)
+ then <binary-node>1</binary-node>
+ else <root-element>{$doc/name(/*)}</root-element>}
+ <collections>{xdmp:document-get-collections($uri)}</collections>
+ </document>
View
57 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.2
+" Version: 1.0.5
" TODO: Add support for: GetLatestVimScripts: ### ### :AutoInstall: xqmarklogic
" TODO: see *glvs-plugins* might not work, but should at least try
"
@@ -101,9 +101,13 @@ function! s:initSettings()
endif
let b:xqmarklogic_script=g:xqmarklogic_defaultScript
if !exists('g:xqmarklogic_defaultDb')
- let g:xqmarklogic_defaultDb="Documents"
+ let g:xqmarklogic_defaultDb='Documents'
endif
let b:xqmarklogic_db=g:xqmarklogic_defaultDb
+ if !exists('g:xqmarklogic_defaultMaxLinesIndent')
+ let g:xqmarklogic_defaultMaxLinesIndent='400'
+ endif
+ let b:xqmarklogic_maxLinesIndent=g:xqmarklogic_defaultMaxLinesIndent
" Buffer options
if !exists('g:xqmarklogic_defaultShowCurlCmd')
@@ -166,6 +170,11 @@ function! s:setDatabase(db)
let b:xqmarklogic_db = a:db
endfunction
+command -buffer -nargs=1 XQsetMaxLinesIndent :execute s:setMaxLinesIndent(<args>)
+function! s:setMaxLinesIndent(lines)
+ let b:xqmarklogic_maxLinesIndent=a:lines
+endfunction
+
" Display settings
command -buffer XQdisplaySettings :execute s:DisplaySettings()
function! s:DisplaySettings()
@@ -185,15 +194,37 @@ function! s:DisplaySettings()
echo 'g:xqmarklogic_noMappings = ' . g:xqmarklogic_noMappings
endfunction
-" Running the Query
+" List the documents in database
+let s:thisfile = expand('<sfile>')
+
+if (!g:xqmarklogic_noMappings)
+ map <Leader>E :XQexploreDb<cr>
+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
+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>
endif
-command -buffer XQmlquery :execute s:QueryMarkLogic(expand("%"))
+command -buffer XQmlquery :execute s:QueryMarkLogic(expand('%'))
function! s:QueryMarkLogic(fname)
- let info = ''
+ if &modified
+ echoerr 'Buffer has been changed, using last saved version'
+ endif
+ call s:QueryGenericMarkLogic('@'.a:fname)
+endfunction
+" Runs the query using curl
+" a:data - what to put after the -d" in the curl command
+function! s:QueryGenericMarkLogic(data)
" setup local settings
let l:user = b:xqmarklogic_user
let l:password = b:xqmarklogic_password
@@ -202,11 +233,12 @@ function! s:QueryMarkLogic(fname)
let l:port = b:xqmarklogic_port
let l:script = b:xqmarklogic_script
let l:db = b:xqmarklogic_db
+ let l:maxLinesIndent = b:xqmarklogic_maxLinesIndent
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=""
+ let l:info=''
" Could use preview window
"let s:out = tempname()
@@ -216,7 +248,6 @@ function! s:QueryMarkLogic(fname)
" Use a 'nofile' window
"botright new
belowright new
-
if (l:showDb)
let l:info .= ' db="' . l:db . '"'
@@ -224,7 +255,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:script . '?db='.l:db
+ 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)
call append(0, '<!-- ' . curlCmd . ' -->')
@@ -237,15 +268,17 @@ function! s:QueryMarkLogic(fname)
let end=reltimestr(reltime(start))
let l:info .= ' query_duration="' . end . '"'
endif
- if (l:info != "" )
- call append(0, '<!-- ' . l:info .'" -->')
+ if (l:info != '' )
+ call append(0, '<!-- ' . l:info .' -->')
endif
" cleanup output
if (!l:noOutClean)
silent! :%s/></>
-</g
- normal gg=G
+</g
+ if line('$') < l:maxLinesIndent
+ normal gg=G
+ setlocal foldlevel=10
endif
endif
endfunction
Please sign in to comment.
Something went wrong with that request. Please try again.