Skip to content

Commit

Permalink
Use new citekey param for zotxt
Browse files Browse the repository at this point in the history
  • Loading branch information
egh committed Nov 23, 2020
1 parent 14d874f commit 7a71684
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 31 deletions.
4 changes: 2 additions & 2 deletions mock-server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'text' => 'Doe, John. First Book. Cambridge: Cambridge University Press, 2005.'
}
].to_json
elsif format == 'easykey'
elsif format == 'citekey'
return ['doe:2005first'].to_json
elsif format == '248bebf1-46ab-4067-9f93-ec3d2960d0cd'
return '{ | Doe, 2005 | | |zu:1254:ZBZQ4KMP}'
Expand All @@ -41,7 +41,7 @@
'text' => 'Doe, John, and Jenny Roe. “Why Water Is Wet.” In Third Book, edited by Sam Smith. Oxford: Oxford University Press, 2007.'
}
].to_json
elsif format == 'easykey'
elsif format == 'citekey'
return ['doe:2007why'].to_json
end
elsif key == '0_4T8MCITQ'
Expand Down
9 changes: 3 additions & 6 deletions org-zotxt.el
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
:citation
"Style to use for org zotxt link texts."
:group 'org-zotxt
:type '(choice (const :tag "citekey" :easykey)
(const :tag "better BibTeX" :betterbibtexkey)
:type '(choice (const :tag "citekey" :citekey)
(const :tag "citation" :citation)))

(defcustom org-zotxt-default-search-method nil
Expand Down Expand Up @@ -73,8 +72,7 @@ prefix argument (C-u C-u) to `org-zotxt-insert-reference-link'"
"Return an Org mode link for ITEM as a string."
(org-make-link-string (format "zotero://select/items/%s"
(plist-get item :key))
(if (or (eq org-zotxt-link-description-style :easykey)
(eq org-zotxt-link-description-style :betterbibtexkey))
(if (eq org-zotxt-link-description-style :citekey)
(concat "@" (plist-get item org-zotxt-link-description-style))
(plist-get item :citation))))

Expand Down Expand Up @@ -131,8 +129,7 @@ prefix argument (C-u C-u) to `org-zotxt-insert-reference-link'"
"Get the link text for ITEM.
May be either an citekey or bibliography, depending on the value
of `org-zotxt-link-description-style'."
(if (or (eq org-zotxt-link-description-style :easykey)
(eq org-zotxt-link-description-style :betterbibtexkey))
(if (eq org-zotxt-link-description-style :citekey)
(zotxt-get-item-deferred item org-zotxt-link-description-style)
(zotxt-get-item-bibliography-deferred item)))

Expand Down
26 changes: 8 additions & 18 deletions test/zotxt-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
'(:key "0_ZBZQ4KMP")))
(deferred:nextc it
(lambda (item)
(zotxt-get-item-deferred item :easykey)))
(zotxt-get-item-deferred item :citekey)))
(deferred:sync! it))))
(plist-get item :easykey))
(plist-get item :citekey))
"doe:2005first")))

(ert-deftest zotxt-test-get-item-uuid-deferred ()
Expand Down Expand Up @@ -73,11 +73,11 @@
(lambda (items)
(zotxt-mapcar-deferred
(lambda (item)
(zotxt-get-item-deferred item :easykey))
(zotxt-get-item-deferred item :citekey))
items)))
(deferred:sync! it)))
(citekeys (mapcar (lambda (item)
(plist-get item :easykey)) items)))
(plist-get item :citekey)) items)))
(sort citekeys #'string-lessp))
'("doe:2005first" "doe:2007why"))))

Expand Down Expand Up @@ -117,10 +117,10 @@
(deferred:next (lambda () '(:key "0_ZBZQ4KMP")))
(deferred:nextc it
(lambda (item)
(let ((org-zotxt-link-description-style :easykey))
(let ((org-zotxt-link-description-style :citekey))
(org-zotxt-get-item-link-text-deferred item))))
(deferred:sync! it))))
(should (equal text (plist-get item :easykey)))))
(should (equal text (plist-get item :citekey)))))

(ert-deftest org-zotxt-test-extract-link-id-at-point ()
(with-temp-buffer
Expand Down Expand Up @@ -185,19 +185,9 @@
(should (equal (buffer-string) text)))))

(ert-deftest org-zotxt-test-insert-reference-link-to-item-with-citekey ()
(let ((org-zotxt-link-description-style :easykey)
(let ((org-zotxt-link-description-style :citekey)
(text "[[zotero://select/items/foo][@foo:2014bar]]")
(item '(:key "foo" :easykey "foo:2014bar")))
(with-temp-buffer
(org-mode)
(org-zotxt-mode)
(org-zotxt-insert-reference-link-to-item item)
(should (equal (buffer-string) text)))))

(ert-deftest org-zotxt-test-insert-reference-link-to-item-with-betterbibtexkey ()
(let ((org-zotxt-link-description-style :betterbibtexkey)
(text "[[zotero://select/items/foo][@foo:2014bar]]")
(item '(:key "foo" :betterbibtexkey "foo:2014bar")))
(item '(:key "foo" :citekey "foo:2014bar")))
(with-temp-buffer
(org-mode)
(org-zotxt-mode)
Expand Down
10 changes: 5 additions & 5 deletions zotxt.el
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
(:everything . "everything")))

(defconst zotxt--json-formats
'(:easykey :betterbibtexkey :json :paths :quickBib)
'(:citekey :json :paths :quickBib)
"Formats to parse as JSON.")

(defconst zotxt-quicksearch-method-names
Expand Down Expand Up @@ -267,7 +267,7 @@ method will have to be selected even if
"Select the item identified by CITEKEY in Zotero."
(request
(format "%s/select" zotxt-url-base)
:params `(("easykey" . ,citekey))))
:params `(("citekey" . ,citekey))))

(defun zotxt-select-key (key)
"Select the item identified by KEY in Zotero."
Expand Down Expand Up @@ -317,7 +317,7 @@ not be returned."
(deferred:$
(zotxt--request-deferred
(format "%s/complete" zotxt-url-base)
:params `(("easykey" . ,key))
:params `(("citekey" . ,key))
:parser #'zotxt--json-read)
(deferred:nextc it
(lambda (response)
Expand Down Expand Up @@ -368,15 +368,15 @@ selected even if `org-zotxt-default-search-method' is non-nil"
(deferred:nextc it
(lambda (items)
(zotxt-mapcar-deferred (lambda (item)
(zotxt-get-item-deferred item :easykey))
(zotxt-get-item-deferred item :citekey))
items)))
(deferred:nextc it
(lambda (items)
(with-current-buffer (marker-buffer mk)
(goto-char (marker-position mk))
(insert (mapconcat
(lambda (item)
(format "@%s" (plist-get item :easykey)))
(format "@%s" (plist-get item :citekey)))
items " ")))))
(deferred:error it #'zotxt--deferred-handle-error)
(if zotxt--debug-sync (deferred:sync! it)))))
Expand Down

0 comments on commit 7a71684

Please sign in to comment.