Klimi's new dotfiles with stow.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

106 行
4.1 KiB

  1. ;;; biblio-hal.el --- Lookup and import bibliographic entries from HAL (archives ouvertes) -*- lexical-binding: t -*-
  2. ;; Copyright (C) 2016 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 HAL using `hal-lookup'.
  20. ;;
  21. ;; This file implements a backend for the for the `biblio' package (which see for more
  22. ;; documentation).
  23. ;;; Code:
  24. (require 'biblio-core)
  25. (defun biblio-hal--forward-bibtex (metadata forward-to)
  26. "Forward BibTeX for HAL entry METADATA to FORWARD-TO."
  27. (funcall forward-to (biblio-alist-get 'bibtex metadata)))
  28. ;; (defun biblio-hal--format-author (author)
  29. ;; "Format AUTHOR for HAL search results."
  30. ;; (pcase author
  31. ;; (`(,author . ,affiliation)
  32. ;; (biblio-join " " author (biblio-parenthesize affiliation)))))
  33. (defun biblio-hal--extract-interesting-fields (item)
  34. "Prepare a HAL search result ITEM for display."
  35. (let-alist item
  36. (list (cons 'doi .doiId_s)
  37. (cons 'year (aref (timezone-parse-date .producedDate_tdate) 0))
  38. (cons 'bibtex .label_bibtex)
  39. (cons 'title (biblio-join " "
  40. (biblio-join-1 ", " .title_s)
  41. (biblio-parenthesize
  42. (biblio-join-1 ", " .subtitle_s))))
  43. (cons 'authors .authFullName_s)
  44. ;; Too many institutions? (biblio-parenthesize (biblio-join-1 ", " .structName_s))
  45. (cons 'publisher .journalPublisher_s)
  46. (cons 'container .journalTitle_s)
  47. (cons 'references (biblio-remove-empty
  48. (list .doiId_s .halId_s .arxivId_s)))
  49. (cons 'type .submitType_s)
  50. (cons 'url .uri_s)
  51. (cons 'direct-url (car (append .files_s nil))))))
  52. (defun biblio-hal--parse-search-results ()
  53. "Extract search results from HAL response."
  54. (biblio-decode-url-buffer 'utf-8)
  55. (let-alist (json-read)
  56. (unless .response
  57. (display-warning 'biblio-hal "HAL query failed"))
  58. (seq-map #'biblio-hal--extract-interesting-fields .response.docs)))
  59. (defun biblio-hal--url (query)
  60. "Create a HAL url to look up QUERY."
  61. (format "https://api.archives-ouvertes.fr/search/?q=%s&wt=%s&fl=%s"
  62. (url-encode-url query) "json"
  63. (biblio-join "," ;; Use ‘*’ to show all fields
  64. "arxivId_s" "halId_s" "doiId_s" ;; "journalIssn_s"
  65. "title_s" "subtitle_s" "authFullName_s" "structName_s"
  66. "journalPublisher_s" "submitType_s" ;; "abstract_s"
  67. ;; "journalTitle_s" "volume_s" "issue_s" "page_s" "writingDate_s"
  68. "label_bibtex" "files_s" "uri_s" "producedDate_tdate")))
  69. ;;;###autoload
  70. (defun biblio-hal-backend (command &optional arg &rest more)
  71. "A HAL backend for biblio.el.
  72. COMMAND, ARG, MORE: See `biblio-backends'."
  73. (pcase command
  74. (`name "HAL")
  75. (`prompt "HAL (archives ouvertes) query: ")
  76. (`url (biblio-hal--url arg))
  77. (`parse-buffer (biblio-hal--parse-search-results))
  78. (`forward-bibtex (biblio-hal--forward-bibtex arg (car more)))
  79. (`register (add-to-list 'biblio-backends #'biblio-hal-backend))))
  80. ;;;###autoload
  81. (add-hook 'biblio-init-hook #'biblio-hal-backend)
  82. ;;;###autoload
  83. (defun biblio-hal-lookup (&optional query)
  84. "Start a HAL search for QUERY, prompting if needed."
  85. (interactive)
  86. (biblio-lookup #'biblio-hal-backend query))
  87. ;;;###autoload
  88. (defalias 'hal-lookup 'biblio-hal-lookup)
  89. (provide 'biblio-hal)
  90. ;;; biblio-hal.el ends here