vim_pandoc/citeproc.py

Initial work on the pandoc-citeproc based bibliography collator.

Can currently be used to search within multiple bibliographies, with the
arguments passed as an OR'ed query:

    ./citeproc.py kant kripke
Merge in work from bibliography_refactor_old

Primarily adding functions written in the (now abandoned) branch bibliography_refactor.

Stuff added:
* (New) Class CSLItem
	- __init__
		+ Takes CSL formatted dict.
	- citekey method
	- as_array(variable name) method.
		+ returns variable as array of strings. Not sure why I thought this was
		  a good idea...
		+ Currently unfunctional.
	- match(query) method.
		+ returns a 'match' value for a regexp query. Potentially will be rewritten
		  later to accept strings and remove the CiteprocQuery class.
		+ 'match' value is currently integer, but may be float in future.
	- matches(query) method.
		+ False if match(query) zero. True otherwise.
	- formatted method.
		+ returns a formatted name/date/title string. Currently placeholder only.

* (New) Class CiteprocQuery
	- __init__
		+ takes string, splits at whitespace, compiles into regexps.
	- match(entry)
		+ takes CSLItem, and checks for match with each regexp. Returns a float
		  between 0 and 1 corresponding to number of matches.
	- matches(entry)
		+ returns true if there is a match.

* class CiteprocSource:
	- __init__
		+ rewritten to cope with malformed bibliographies. Doesn't yet raise
		  an error though.
		+ creates self.data, an array of CSLItems.
	- __iter__
		+ iterates over self.data

* class SourceCollator:
	- find_bibfiles(filename, sources, local_bib_extensions)
		+ wholesale rewrite/copy from bibliography_refactor.
		+ returns list of paths for bibliography files.
		+ all variables are optional.
	- collate()
		+ rewritten to work with new functions &c.
Fix CSLItem.match

Previously CSLItem.match would not pick up words in the middle of a phrase.
Now it will.
Implement CSLItem.as_array.name

Also some minor changes to CSLItem.as_array.number and CSLItem.as_array.plain.
Modify CSLItem.match

Searches tokens directly rather than searching joined arrays.
Make CiteprocSource.find_bibfiles clearer.
Rewrite CSLItem.as_array.name
pandoc/chdir: pass over error E472

fixes issue #93
Comment initial variables and switch to hash
Create CSLItem.buffered_as_array
Define date variable parser in CSLItem.as_array
Create CiteprocQuery.easy_matches
Change SourceCollator.collate
Merge branch 'bibliography_refactor' of https://github.com/dfaligertwood/vim-pandoc into next-biblio
bibliography, completion: mayor restructuring of the bibliographic completion

started work on integrating citeproc-based completion.

introduced new config, g:pandoc#completion#bib#mode, that sets which
backend to use for information retrieval.

the new entry point is vim_pandoc.bib.vim_completer, which is the only
point where the completion system interacts with vim.

split SourceCollator from citeproc.py, and made it the root class of
completion backends. it handles the location of bibliographic databases.
The SourceCollator API has changed, queries are given in initialization
instead of on collate().

turned the old mechanism (fallback) into an subclass of the new collator
system. it is used by default while the citeproc-based mechanism is
being worked on.

MODS support removed from fallback system (it was buggy).
makes citeproc-based completer functional

Note it is quite limited yet.

I had to revert some of @dfalingertwood's work, because
CiteprocQuery.easy_matches() returned bad results (the criterion was too
lenient).

Implemented suggestions parser in vim_completer.py, should expand
fallback methods to use it.
improved relevance sorter of search results.

Based on @dfaligertwood's ideas in CiteprocQuery.match()

It should be possible to incorporate this into CSLItem.match() (so the
item gets assigned a value and we don't have to redo the search).
enable citeproc completion by default, if pandoc-citeproc is available
add initial support for previews on completion
completion: bibliographic item preview improvements

* use the preview by default
* try to enable the preview if not already enabled
* auto close the preview window