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.

96 rivejä
3.6 KiB

4 vuotta sitten
  1. ;;; biblio-dblp.el --- Lookup and import bibliographic entries from DBLP -*- 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 DBLP (a great source of
  20. ;; references for Computer Science papers) using `dblp-lookup'.
  21. ;;
  22. ;; This file implements a backend for the for the `biblio' package (which see for more
  23. ;; documentation).
  24. ;;; Code:
  25. (require 'biblio-core)
  26. (defun biblio-dblp--forward-bibtex (metadata forward-to)
  27. "Forward BibTeX for DBLP entry METADATA to FORWARD-TO."
  28. (let* ((source-url (biblio-alist-get 'url metadata))
  29. (url (replace-regexp-in-string "/rec/" "/rec/bib2/" source-url t t)))
  30. (biblio-url-retrieve url (biblio-generic-url-callback
  31. (lambda () ;; No allowed errors, so no arguments
  32. "Parse DBLP BibTeX results."
  33. (funcall forward-to
  34. (biblio-format-bibtex
  35. (biblio-response-as-utf-8))))))))
  36. (defun biblio-dblp--extract-interesting-fields (item)
  37. "Prepare a DBLP search result ITEM for display."
  38. (let-alist (biblio-alist-get 'info item)
  39. (list (cons 'year (cadr .year))
  40. (cons 'title (cadr .title))
  41. (cons 'authors (seq-map #'cl-caddr (cdr .authors)))
  42. (cons 'container (cadr .venue))
  43. (cons 'references nil)
  44. (cons 'type (cadr .type))
  45. (cons 'url (cadr .url)))))
  46. (defun biblio-dblp--hitp (item)
  47. "Check if ITEM is a DBLP hit."
  48. (eq (car-safe item) 'hit))
  49. (defun biblio-dblp--parse-search-results ()
  50. "Extract search results from DBLP response."
  51. (biblio-decode-url-buffer 'utf-8)
  52. (let-alist (car (xml-parse-region (point-min) (point-max)))
  53. (unless (string= (cadr .status) "OK")
  54. (display-warning 'biblio-dblp "DBLP query failed"))
  55. (seq-map #'biblio-dblp--extract-interesting-fields (seq-filter #'biblio-dblp--hitp .hits))))
  56. (defun biblio-dblp--url (query)
  57. "Create a DBLP url to look up QUERY."
  58. (format "http://dblp.uni-trier.de/search/publ/api?q=%s&format=xml" (url-encode-url query)))
  59. ;;;###autoload
  60. (defun biblio-dblp-backend (command &optional arg &rest more)
  61. "A DBLP backend for biblio.el.
  62. COMMAND, ARG, MORE: See `biblio-backends'."
  63. (pcase command
  64. (`name "DBLP")
  65. (`prompt "DBLP query: ")
  66. (`url (biblio-dblp--url arg))
  67. (`parse-buffer (biblio-dblp--parse-search-results))
  68. (`forward-bibtex (biblio-dblp--forward-bibtex arg (car more)))
  69. (`register (add-to-list 'biblio-backends #'biblio-dblp-backend))))
  70. ;;;###autoload
  71. (add-hook 'biblio-init-hook #'biblio-dblp-backend)
  72. ;;;###autoload
  73. (defun biblio-dblp-lookup (&optional query)
  74. "Start a DBLP search for QUERY, prompting if needed."
  75. (interactive)
  76. (biblio-lookup #'biblio-dblp-backend query))
  77. ;;;###autoload
  78. (defalias 'dblp-lookup 'biblio-dblp-lookup)
  79. (provide 'biblio-dblp)
  80. ;;; biblio-dblp.el ends here