Skip to content

Instantly share code, notes, and snippets.

@dmj
Created December 9, 2009 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmj/252402 to your computer and use it in GitHub Desktop.
Save dmj/252402 to your computer and use it in GitHub Desktop.
emacs vs. zotero
(defun dmj/zotero-export-bibtex ()
"Ask for a search query, export matching items to bibtex."
(interactive)
(require 'moz)
(let* ((query (read-string "Query: "))
(tmpfile (make-temp-name
(expand-file-name "zotemacs" temporary-file-directory)))
(js (list
"var file = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);"
(concat
"file.initWithPath('"
tmpfile
"');")
"var zotero = Components.classes['@zotero.org/Zotero;1'].getService(Components.interfaces.nsISupports).wrappedJSObject;"
"var s = new Zotero.Search();"
(concat
"s.addCondition('field','contains','"
query
"');")
"var ids = s.search();"
"var items = Zotero.Items.get(ids);"
"var t = new Zotero.Translate('export');"
"t.setLocation(file);";
"t.setTranslator('9cb70025-a888-4a29-a210-93ec52da40d4');"
"t.setItems(items);"
"t.translate();"))
l)
(dolist (l js)
(comint-send-string (inferior-moz-process) l))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment