Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 line
3.7 KiB

4 年之前
  1. ;;; biblio-ieee.el --- Lookup and import bibliographic entries from IEEE -*- lexical-binding: t -*-
  2. ;; Copyright (C) 2019 Clément Pit-Claudel
  3. ;; Author: Clément Pit-Claudel <clement.pitclaudel@live.com>
  4. ;; URL: http://github.com/cpitclaudel/biblio.el
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;;
  10. ;; This program is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;;
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;;
  19. ;; Lookup and download bibliographic records from IEEE Xplore using
  20. ;; `ieee-lookup'.
  21. ;;
  22. ;; This package uses `biblio-selection-mode', and plugs into the more general
  23. ;; `biblio' package (which see for more documentation).
  24. ;;; Code:
  25. (require 'biblio-core)
  26. (require 'biblio-doi)
  27. (defconst biblio-ieee--api-key "rfwzcsz3f9fkhklhii84xdfz"
  28. "API key used to query IEEE; for use only with biblio.el!")
  29. (defconst biblio-ieee--api-root-url
  30. "http://ieeexploreapi.ieee.org/api/v1/search/articles")
  31. (defun biblio-ieee--forward-bibtex (metadata forward-to)
  32. "Forward BibTeX for IEEE Xplore entry METADATA to FORWARD-TO."
  33. (biblio-doi-forward-bibtex (biblio-alist-get 'doi metadata) forward-to))
  34. (defun biblio-ieee--format-author (author)
  35. "Format AUTHOR for IEEE Xplore search results."
  36. (let-alist author
  37. (biblio-join " " .full_name (biblio-parenthesize .affiliation))))
  38. (defun biblio-ieee--extract-interesting-fields (item)
  39. "Prepare a IEEE Xplore search result ITEM for display."
  40. (let-alist item
  41. (list (cons 'doi .doi)
  42. (cons 'year .publication_year)
  43. (cons 'title .title)
  44. (cons 'authors (seq-map #'biblio-ieee--format-author .authors.authors))
  45. (cons 'publisher .publisher)
  46. (cons 'container .publication_title)
  47. (cons 'references (list .doi .isbn))
  48. (cons 'type (or .index_terms.author_terms.terms
  49. .index_terms.ieee_terms.terms))
  50. (cons 'url .abstract_url)
  51. (cons 'direct-url .pdf_url)
  52. (cons 'open-access-status .access_type))))
  53. (defun biblio-ieee--parse-search-results ()
  54. "Extract search results from IEEE Xplore response."
  55. (biblio-decode-url-buffer 'utf-8)
  56. (let-alist (json-read)
  57. (seq-map #'biblio-ieee--extract-interesting-fields .articles)))
  58. (defun biblio-ieee--url (query)
  59. "Create an IEEE Xplore url to look up QUERY."
  60. (format "%s?querytext=%s&apikey=%s"
  61. biblio-ieee--api-root-url
  62. (url-encode-url query)
  63. (rot13 biblio-ieee--api-key)))
  64. ;;;###autoload
  65. (defun biblio-ieee-backend (command &optional arg &rest more)
  66. "A IEEE Xplore backend for biblio.el.
  67. COMMAND, ARG, MORE: See `biblio-backends'."
  68. (pcase command
  69. (`name "IEEE Xplore")
  70. (`prompt "IEEE Xplore query: ")
  71. (`url (biblio-ieee--url arg))
  72. (`parse-buffer (biblio-ieee--parse-search-results))
  73. (`forward-bibtex (biblio-ieee--forward-bibtex arg (car more)))
  74. (`register (add-to-list 'biblio-backends #'biblio-ieee-backend))))
  75. ;;;###autoload
  76. (add-hook 'biblio-init-hook #'biblio-ieee-backend)
  77. ;;;###autoload
  78. (defun biblio-ieee-lookup (&optional query)
  79. "Start a IEEE search for QUERY, prompting if needed."
  80. (interactive)
  81. (biblio-lookup #'biblio-ieee-backend query))
  82. ;;;###autoload
  83. (defalias 'ieee-lookup 'biblio-ieee-lookup)
  84. (provide 'biblio-ieee)
  85. ;;; biblio-ieee.el ends here