Permalink
Browse files

Add mappings to result window, and fixup documentation

Add \B, <C-CR>, and \E to results window (refresh window, refresh
window, refresh window unless in a database listing)
Fixup documentation, and in particular add results window mappings
Make \B, <C-CR, and \E buffer local mappings in all cases (results
windwo and xquery file)
  • Loading branch information...
1 parent 819b8c2 commit f4f102977b0a176b3a154ebce80af66e8db4cabb @coledarr committed Oct 22, 2012
Showing with 66 additions and 31 deletions.
  1. +42 −21 doc/xqmarklogic.txt
  2. +24 −10 ftplugin/xquery.vim
View
@@ -10,25 +10,29 @@ 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|
+Introduction |xqmarklogic-intro|
+Installation |xqmarklogic-install|
MarkLogic configuration |xqmarklogic-config-marklogic|
vimrc configuration |xqmarklogic-config-vimrc|
-3. Security Considerations |xqmarklogic-security|
-4. Commands |xqmarklogic-commands|
-5. Customization:
+Security Considerations |xqmarklogic-security|
+Mappings and Commands |xqmarklogic-commands|
+Results Window |xqmarklogic-results|
+Customization:
Options and Settings |xqmarklogic-options|
==============================================================================
INTRODUCTION *xqmarklogic-intro*
-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:
+xqmarklogic maps <LEADER>B and <C-CR> (CONTROL-RETURN like MarkLogic Query
+Console) to run an XQuery against MarkLogic server using curl and a custom App
+Server running a short XQuery file. It displays the results in a new
+|xmarklogic-results| 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
+ Pull requests welcome.
==============================================================================
INSTALLATION *xqmarklogic-install*
@@ -97,7 +101,8 @@ well >
For more details and other options and setting see |xqmarklogic-options|
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
XQuery against any of the MarkLogic databases. It is only as protected as the
@@ -113,22 +118,23 @@ stored in the viminfo file. Pull requests with fixes for this are welcome.
==============================================================================
-3. Commands *xqmarklogic-commands*
+MAPPINGS AND COMMANDS *xqmarklogic-commands*
+ *xqmarklogic-mappings*
<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
+ it is easy to remap this if desired.
+<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.
+ 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.
+vimrc to turn off the above.
-*XQtoggleShowCurlCmd* toggles showing curl command used in the output
+*XQtoggleShowCurlCmd* toggles showing curl command used in the results
window in an XML comment. It is off by default since
the command contains "--" and thus can't be in a valid
XML comment.
@@ -164,17 +170,32 @@ vimrc to skip setting the above.
*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.
+ and display the output in a new results window.
-*XQexploreDb* Display in a new window each document in the current database, a
+*XQexploreDb* Display in a new results 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.
+==============================================================================
+RESULTS WINDOW *xqmarklogic-results*
+
+The results window is a |buftype| nofile, with the filetype set to xml, and
+has a few mappings for convience. These mappings are only set for the results
+window, and are not affected by |g:xqmarklogic_noMappings|.
+
+q Close the results window.
+
+<LEADER>B Will refresh the output of the window.
+<C-CR> Will refresh the output of the window.
+<LEADER>E Will to list document URIs and other
+ information. Will refresh the results window if it was a
+database listing, otherwise opens a new window.
==============================================================================
-4. Customization: Options and Settings *xqmarklogic-options*
+CUSTOMIZATION *xqmarklogic-options*
+ Options and Settings
- Global default values can be set in you |vimrc| file.
+Global default values can be set in you |vimrc| file.
*g:xqmarklogic_defaultHost* - the default Host name to use, if not set
uses 'localhost'
View
@@ -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.5
+" Version: 1.0.6
" TODO: Add support for: GetLatestVimScripts: ### ### :AutoInstall: xqmarklogic
" TODO: see *glvs-plugins* might not work, but should at least try
"
@@ -29,6 +29,8 @@
"
" TODO Prompt for password if unset
" TODO output something useful when curl returns an error
+" TODO should provide a way to set customize mappings so that the results
+" window mappings can match
if exists('b:loaded_xqmarklogic')
@@ -198,33 +200,33 @@ endfunction
let s:thisfile = expand('<sfile>')
if (!g:xqmarklogic_noMappings)
- map <Leader>E :XQexploreDb<cr>
+ map <buffer> <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'))
+ call s:QueryGenericMarkLogic('@'.fnameescape(fnamemodify(s:thisfile, ':p:h'). '/exploreDb.xqy'), 0)
"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>
+ map <buffer> <Leader>B :XQmlquery<cr>
+ map <buffer> <C-CR> :XQmlquery<cr>
endif
command -buffer XQmlquery :execute s:QueryMarkLogic(expand('%'))
function! s:QueryMarkLogic(fname)
if &modified
echoerr 'Buffer has been changed, using last saved version'
endif
- call s:QueryGenericMarkLogic('@'.a:fname)
+ call s:QueryGenericMarkLogic('@'.a:fname, 1)
endfunction
" Runs the query using curl
" a:data - what to put after the -d" in the curl command
-function! s:QueryGenericMarkLogic(data)
+command -buffer XQmlqueryArgs :execute s:QueryGenericMarkLogic(<args>)
+function! s:QueryGenericMarkLogic(data, bufferQuery)
" setup local settings
let l:user = b:xqmarklogic_user
let l:password = b:xqmarklogic_password
@@ -248,13 +250,25 @@ function! s:QueryGenericMarkLogic(data)
" Use a 'nofile' window
"botright new
belowright new
+ setlocal buftype=nofile
+ setlocal filetype=xml
+
+ " Buffer Mappings for Result window
+ if (a:bufferQuery)
+ exec "map <buffer> <LEADER>B :q<CR>:XQmlqueryArgs \"" . a:data . "\", 1<CR>"
+ exec "map <buffer> <C-CR> :q<CR>:XQmlqueryArgs \"" . a:data . "\", 1<cr>"
+ map <buffer> <Leader>E <C-W><C-P>:XQexploreDb<cr>
+ else
+ exec "map <buffer> <LEADER>B :q<CR>:XQmlqueryArgs \"" . a:data . "\", 1<CR>"
+ exec "map <buffer> <C-CR> :q<CR>:XQmlqueryArgs \"" . a:data . "\", 1<cr>"
+ map <buffer> <Leader>E :q<CR>:XQexploreDb<cr>
+ endif
+ map <buffer> q :q<CR>
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:data . '" ' . l:uri . l:host . ':' . l:port . l:script . '?db='.l:db
if (l:showCurlCmd)

0 comments on commit f4f1029

Please sign in to comment.