diff options
author | Kyle Meyer <kyle@kyleam.com> | 2014-02-03 00:00:36 -0500 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2014-02-03 00:50:18 -0500 |
commit | 68e1df6a74e6791bef21b6c295ddc056cfe4d3e5 (patch) | |
tree | 4c4b94aa824054bfbfe2889e1825002203e22413 | |
parent | 5164c4d378ed8bb9a6335dd6c177be7027140014 (diff) | |
download | bog-68e1df6a74e6791bef21b6c295ddc056cfe4d3e5.tar.gz |
Add function to search citekey on Google Scholar
-rw-r--r-- | bog.el | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -93,6 +93,13 @@ then lower case letters." :type 'string :group 'bog) +(defcustom bog-web-search-url + "http://scholar.google.com/scholar?q=%s" + "URL to use for CITEKEY search. +It should contain the placeholder \"%s\" for the query." + :type 'string + :group 'bog) + ;;; General utilities @@ -114,6 +121,20 @@ ACTION will be called with the resulting citekey as an argument." "Prompt for citekey from CITEKEYS" (funcall bog-completing-read "Select citekey: " citekeys)) +(defun bog-citekey-groups-with-delim (citekey &optional delim groups) + "Return groups of `bog-citekey-format', seperated by DELIM. + +If DELIM is nil, space is used. + +If GROUPS is nil, groups 1, 2, and 3 are selected (which +corresponds to the last name of the first author, the publication +year, and the first meaningful word in the title)." + (let ((groups (or groups '(1 2 3))) + (delim (or delim " "))) + (string-match bog-citekey-format citekey) + (mapconcat '(lambda (g) (match-string-no-properties g citekey)) + groups delim))) + (defun bog-citekey-at-point () (let ((maybe-citekey (thing-at-point 'word))) (when (and maybe-citekey @@ -299,6 +320,31 @@ occur in buffer instead of alphabetical order." (file-name-as-directory bog-bib-directory) "*.bib")))) + +;;; Web + +;;;###autoload +(defun bog-search-citekey-on-web () + "Open browser and perform query based for a citekey. + +The URL will be taken from `bog-web-search-url'. + +The citekey is split by groups in `bog-citekey-format' and joined by +\"+\" to form the query string." + (interactive) + (bog-citekey-action 'bog-open-citekey-on-web + nil + nil)) + +(defun bog-open-citekey-on-web (citekey) + (let ((url (bog-citekey-as-search-url citekey))) + (browse-url url))) + +(defun bog-citekey-as-search-url (citekey) + "Return URL to use for search." + (let ((query (bog-citekey-groups-with-delim citekey "+"))) + (format bog-web-search-url query))) + (provide 'bog) ;; bog.el ends here |