org-bibtex.el 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. ;;; org-bibtex.el --- Org links to BibTeX entries
  2. ;;
  3. ;; Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
  4. ;;
  5. ;; Author: Bastien Guerry <bzg at altern dot org>
  6. ;; Carsten Dominik <carsten dot dominik at gmail dot com>
  7. ;; Eric Schulte <schulte dot eric at gmail dot com>
  8. ;; Keywords: org, wp, remember
  9. ;; Version: 7.5
  10. ;;
  11. ;; This file is part of GNU Emacs.
  12. ;;
  13. ;; GNU Emacs is free software: you can redistribute it and/or modify
  14. ;; it under the terms of the GNU General Public License as published by
  15. ;; the Free Software Foundation, either version 3 of the License, or
  16. ;; (at your option) any later version.
  17. ;; GNU Emacs is distributed in the hope that it will be useful,
  18. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. ;; GNU General Public License for more details.
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  23. ;;
  24. ;;; Commentary:
  25. ;;
  26. ;; This file implements links to database entries in BibTeX files.
  27. ;; Instead of defining a special link prefix, it uses the normal file
  28. ;; links combined with a custom search mechanism to find entries
  29. ;; by reference key. And it constructs a nice description tag for
  30. ;; the link that contains the author name, the year and a short title.
  31. ;;
  32. ;; It also stores detailed information about the entry so that
  33. ;; remember templates can access and enter this information easily.
  34. ;;
  35. ;; The available properties for each entry are listed here:
  36. ;;
  37. ;; :author :publisher :volume :pages
  38. ;; :editor :url :number :journal
  39. ;; :title :year :series :address
  40. ;; :booktitle :month :annote :abstract
  41. ;; :key :btype
  42. ;;
  43. ;; Here is an example of a remember template that use some of this
  44. ;; information (:author :year :title :journal :pages):
  45. ;;
  46. ;; (setq org-remember-templates
  47. ;; '((?b "* READ %?\n\n%a\n\n%:author (%:year): %:title\n \
  48. ;; In %:journal, %:pages.")))
  49. ;;
  50. ;; Let's say you want to remember this BibTeX entry:
  51. ;;
  52. ;; @Article{dolev83,
  53. ;; author = {Danny Dolev and Andrew C. Yao},
  54. ;; title = {On the security of public-key protocols},
  55. ;; journal = {IEEE Transaction on Information Theory},
  56. ;; year = 1983,
  57. ;; volume = 2,
  58. ;; number = 29,
  59. ;; pages = {198--208},
  60. ;; month = {Mars}
  61. ;; }
  62. ;;
  63. ;; M-x `org-remember' on this entry will produce this buffer:
  64. ;;
  65. ;; =====================================================================
  66. ;; * READ <== [point here]
  67. ;;
  68. ;; [[file:file.bib::dolev83][Dolev & Yao 1983: security of public key protocols]]
  69. ;;
  70. ;; Danny Dolev and Andrew C. Yao (1983): On the security of public-key protocols
  71. ;; In IEEE Transaction on Information Theory, 198--208.
  72. ;; =====================================================================
  73. ;;
  74. ;; Additionally, the following functions are now available for storing
  75. ;; bibtex entries within Org-mode documents.
  76. ;;
  77. ;; - Run `org-bibtex' to export the current file to a .bib.
  78. ;;
  79. ;; - Run `org-bibtex-check' or `org-bibtex-check-all' to check and
  80. ;; fill in missing field of either the current, or all headlines
  81. ;;
  82. ;; - Run `org-bibtex-create' to add a bibtex entry
  83. ;;
  84. ;; - Use `org-bibtex-read' to read a bibtex entry after `point' or in
  85. ;; the active region, then call `org-bibtex-write' in a .org file to
  86. ;; insert a heading for the read bibtex entry
  87. ;;
  88. ;; - All Bibtex information is taken from the document compiled by
  89. ;; Andrew Roberts from the Bibtex manual, available at
  90. ;; http://www.andy-roberts.net/misc/latex/sessions/bibtex/bibentries.pdf
  91. ;;
  92. ;;; History:
  93. ;;
  94. ;; The link creation part has been part of Org-mode for a long time.
  95. ;;
  96. ;; Creating better remember template information was inspired by a request
  97. ;; of Austin Frank: http://article.gmane.org/gmane.emacs.orgmode/4112
  98. ;; and then implemented by Bastien Guerry.
  99. ;;
  100. ;; Eric Schulte eventually added the functions for translating between
  101. ;; Org-mode headlines and Bibtex entries, and for fleshing out the Bibtex
  102. ;; fields of existing Org-mode headlines.
  103. ;;
  104. ;; Org-mode loads this module by default - if this is not what you want,
  105. ;; configure the variable `org-modules'.
  106. ;;; Code:
  107. (require 'org)
  108. (require 'bibtex)
  109. (defvar description nil) ; dynamically scoped from org.el
  110. (declare-function bibtex-beginning-of-entry "bibtex" ())
  111. (declare-function bibtex-generate-autokey "bibtex" ())
  112. (declare-function bibtex-parse-entry "bibtex" (&optional content))
  113. (declare-function bibtex-url "bibtex" (&optional pos no-browse))
  114. (declare-function longlines-mode "longlines" (&optional arg))
  115. ;;; Bibtex data
  116. (defvar org-bibtex-types
  117. '((:article
  118. (:description . "An article from a journal or magazine")
  119. (:required :author :title :journal :year)
  120. (:optional :volume :number :pages :month :note))
  121. (:book
  122. (:description . "A book with an explicit publisher")
  123. (:required (:editor :author) :title :publisher :year)
  124. (:optional (:volume :number) :series :address :edition :month :note))
  125. (:booklet
  126. (:description . "A work that is printed and bound, but without a named publisher or sponsoring institution.")
  127. (:required :title)
  128. (:optional :author :howpublished :address :month :year :note))
  129. (:conference
  130. (:description . "")
  131. (:required :author :title :booktitle :year)
  132. (:optional :editor :pages :organization :publisher :address :month :note))
  133. (:inbook
  134. (:description . "A part of a book, which may be a chapter (or section or whatever) and/or a range of pages.")
  135. (:required (:author :editor) :title (:chapter :pages) :publisher :year)
  136. (:optional (:volume :number) :series :type :address :edition :month :note))
  137. (:incollection
  138. (:description . "A part of a book having its own title.")
  139. (:required :author :title :booktitle :publisher :year)
  140. (:optional :editor (:volume :number) :series :type :chapter :pages :address :edition :month :note))
  141. (:inproceedings
  142. (:description . "An article in a conference proceedings")
  143. (:required :author :title :booktitle :year)
  144. (:optional :editor (:volume :number) :series :pages :address :month :organization :publisher :note))
  145. (:manual
  146. (:description . "Technical documentation.")
  147. (:required :title)
  148. (:optional :author :organization :address :edition :month :year :note))
  149. (:mastersthesis
  150. (:description . "A Master’s thesis.")
  151. (:required :author :title :school :year)
  152. (:optional :type :address :month :note))
  153. (:misc
  154. (:description . "Use this type when nothing else fits.")
  155. (:required)
  156. (:optional :author :title :howpublished :month :year :note))
  157. (:phdthesis
  158. (:description . "A PhD thesis.")
  159. (:required :author :title :school :year)
  160. (:optional :type :address :month :note))
  161. (:proceedings
  162. (:description . "The proceedings of a conference.")
  163. (:required :title :year)
  164. (:optional :editor (:volume :number) :series :address :month :organization :publisher :note))
  165. (:techreport
  166. (:description . "A report published by a school or other institution.")
  167. (:required :author :title :institution :year)
  168. (:optional :type :address :month :note))
  169. (:unpublished
  170. (:description . "A document having an author and title, but not formally published.")
  171. (:required :author :title :note)
  172. (:optional :month :year)))
  173. "Bibtex entry types with required and optional parameters.")
  174. (defvar org-bibtex-fields
  175. '((:address . "Usually the address of the publisher or other type of institution. For major publishing houses, van Leunen recommends omitting the information entirely. For small publishers, on the other hand, you can help the reader by giving the complete address.")
  176. (:annote . "An annotation. It is not used by the standard bibliography styles, but may be used by others that produce an annotated bibliography.")
  177. (:author . "The name(s) of the author(s), in the format described in the LaTeX book. Remember, all names are separated with the and keyword, and not commas.")
  178. (:booktitle . "Title of a book, part of which is being cited. See the LaTeX book for how to type titles. For book entries, use the title field instead.")
  179. (:chapter . "A chapter (or section or whatever) number.")
  180. (:crossref . "The database key of the entry being cross referenced.")
  181. (:edition . "The edition of a book for example, 'Second'. This should be an ordinal, and should have the first letter capitalized, as shown here; the standard styles convert to lower case when necessary.")
  182. (:editor . "Name(s) of editor(s), typed as indicated in the LaTeX book. If there is also an author field, then the editor field gives the editor of the book or collection in which the reference appears.")
  183. (:howpublished . "How something strange has been published. The first word should be capitalized.")
  184. (:institution . "The sponsoring institution of a technical report.")
  185. (:journal . "A journal name.")
  186. (:key . "Used for alphabetizing, cross-referencing, and creating a label when the author information is missing. This field should not be confused with the key that appears in the \cite command and at the beginning of the database entry.")
  187. (:month . "The month in which the work was published or, for an unpublished work, in which it was written. You should use the standard three-letter abbreviation,")
  188. (:note . "Any additional information that can help the reader. The first word should be capitalized.")
  189. (:number . "Any additional information that can help the reader. The first word should be capitalized.")
  190. (:organization . "The organization that sponsors a conference or that publishes a manual.")
  191. (:pages . "One or more page numbers or range of numbers, such as 42-111 or 7,41,73-97 or 43+ (the ‘+’ in this last example indicates pages following that don’t form simple range). BibTEX requires double dashes for page ranges (--).")
  192. (:publisher . "The publisher’s name.")
  193. (:school . "The name of the school where a thesis was written.")
  194. (:series . "The name of a series or set of books. When citing an entire book, the the title field gives its title and an optional series field gives the name of a series or multi-volume set in which the book is published.")
  195. (:title . "The work’s title, typed as explained in the LaTeX book.")
  196. (:type . "The type of a technical report for example, 'Research Note'.")
  197. (:volume . "The volume of a journal or multi-volume book.")
  198. (:year . "The year of publication or, for an unpublished work, the year it was written. Generally it should consist of four numerals, such as 1984, although the standard styles can handle any year whose last four nonpunctuation characters are numerals, such as '(about 1984)'"))
  199. "Bibtex fields with descriptions.")
  200. (defvar *org-bibtex-entries* nil
  201. "List to hold parsed bibtex entries.")
  202. (defcustom org-bibtex-autogen-keys nil
  203. "Set to a truthy value to use `bibtex-generate-autokey' to generate keys."
  204. :group 'org-bibtex
  205. :type 'boolean)
  206. (defcustom org-bibtex-prefix nil
  207. "Optional prefix for all bibtex property names.
  208. For example setting to 'BIB_' would allow interoperability with fireforg."
  209. :group 'org-bibtex
  210. :type 'string)
  211. ;;; Utility functions
  212. (defun org-bibtex-get (property)
  213. (or (org-entry-get (point) (upcase property))
  214. (org-entry-get (point) (concat org-bibtex-prefix (upcase property)))))
  215. (defun org-bibtex-put (property value)
  216. (let ((prop (upcase (if (keywordp property)
  217. (substring (symbol-name property) 1)
  218. property))))
  219. (org-set-property
  220. (concat (unless (string= "CUSTOM_ID" prop) org-bibtex-prefix) prop)
  221. value)))
  222. (defun org-bibtex-headline ()
  223. "Return a bibtex entry of the given headline as a string."
  224. (flet ((get (key lst) (cdr (assoc key lst)))
  225. (to-k (string) (intern (concat ":" string)))
  226. (from-k (key) (substring (symbol-name key) 1))
  227. (flatten (&rest lsts)
  228. (apply #'append (mapcar
  229. (lambda (e)
  230. (if (listp e) (apply #'flatten e) (list e)))
  231. lsts))))
  232. (let ((notes (buffer-string))
  233. (id (org-bibtex-get "custom_id"))
  234. (type (org-bibtex-get "type")))
  235. (when type
  236. (let ((entry (format
  237. "@%s{%s,\n%s\n}\n" type id
  238. (mapconcat
  239. (lambda (pair) (format " %s={%s}" (car pair) (cdr pair)))
  240. (remove nil
  241. (mapcar
  242. (lambda (field)
  243. (let ((value (or (org-bibtex-get (from-k field))
  244. (and (equal :title field)
  245. (org-get-heading)))))
  246. (when value (cons (from-k field) value))))
  247. (flatten
  248. (get :required (get (to-k type) org-bibtex-types))
  249. (get :optional (get (to-k type) org-bibtex-types)))))
  250. ",\n"))))
  251. (with-temp-buffer
  252. (insert entry)
  253. (bibtex-reformat) (buffer-string)))))))
  254. (defun org-bibtex-ask (field)
  255. (unless (assoc field org-bibtex-fields)
  256. (error "field:%s is not known" field))
  257. (save-window-excursion
  258. (let* ((name (substring (symbol-name field) 1))
  259. (buf-name (format "*Bibtex Help %s*" name)))
  260. (with-output-to-temp-buffer buf-name
  261. (princ (cdr (assoc field org-bibtex-fields))))
  262. (with-current-buffer buf-name (longlines-mode t))
  263. (org-fit-window-to-buffer (get-buffer-window buf-name))
  264. ((lambda (result) (when (> (length result) 0) result))
  265. (read-from-minibuffer (format "%s: " name))))))
  266. (defun org-bibtex-autokey ()
  267. "Generate an autokey for the current headline"
  268. (org-bibtex-put "CUSTOM_ID"
  269. (if org-bibtex-autogen-keys
  270. (let ((entry (org-bibtex-headline)))
  271. (with-temp-buffer
  272. (insert entry)
  273. (bibtex-generate-autokey)))
  274. (read-from-minibuffer "id: "))))
  275. (defun org-bibtex-fleshout (type &optional optional)
  276. "Fleshout the current heading, ensuring that all required fields are present.
  277. With optional argument OPTIONAL, also prompt for optional fields."
  278. (flet ((get (key lst) (cdr (assoc key lst)))
  279. (keyword (name) (intern (concat ":" (downcase name))))
  280. (name (keyword) (upcase (substring (symbol-name keyword) 1))))
  281. (dolist (field (append
  282. (remove :title (get :required (get type org-bibtex-types)))
  283. (when optional (get :optional (get type org-bibtex-types)))))
  284. (when (consp field) ; or'd pair of fields e.g., (:editor :author)
  285. (let ((present (first (remove nil
  286. (mapcar
  287. (lambda (f) (when (org-bibtex-get (name f)) f))
  288. field)))))
  289. (setf field (or present (keyword (org-icompleting-read
  290. "Field: " (mapcar #'name field)))))))
  291. (let ((name (name field)))
  292. (unless (org-bibtex-get name)
  293. (let ((prop (org-bibtex-ask field)))
  294. (when prop (org-bibtex-put name prop)))))))
  295. (when (and type (assoc type org-bibtex-types)
  296. (not (org-bibtex-get "CUSTOM_ID")))
  297. (org-bibtex-autokey)))
  298. ;;; Bibtex link functions
  299. (org-add-link-type "bibtex" 'org-bibtex-open)
  300. (add-hook 'org-store-link-functions 'org-bibtex-store-link)
  301. (defun org-bibtex-open (path)
  302. "Visit the bibliography entry on PATH."
  303. (let* ((search (when (string-match "::\\(.+\\)\\'" path)
  304. (match-string 1 path)))
  305. (path (substring path 0 (match-beginning 0))))
  306. (org-open-file path t nil search)))
  307. (defun org-bibtex-store-link ()
  308. "Store a link to a BibTeX entry."
  309. (when (eq major-mode 'bibtex-mode)
  310. (let* ((search (org-create-file-search-in-bibtex))
  311. (link (concat "file:" (abbreviate-file-name buffer-file-name)
  312. "::" search))
  313. (entry (mapcar ; repair strings enclosed in "..." or {...}
  314. (lambda(c)
  315. (if (string-match
  316. "^\\(?:{\\|\"\\)\\(.*\\)\\(?:}\\|\"\\)$" (cdr c))
  317. (cons (car c) (match-string 1 (cdr c))) c))
  318. (save-excursion
  319. (bibtex-beginning-of-entry)
  320. (bibtex-parse-entry)))))
  321. (org-store-link-props
  322. :key (cdr (assoc "=key=" entry))
  323. :author (or (cdr (assoc "author" entry)) "[no author]")
  324. :editor (or (cdr (assoc "editor" entry)) "[no editor]")
  325. :title (or (cdr (assoc "title" entry)) "[no title]")
  326. :booktitle (or (cdr (assoc "booktitle" entry)) "[no booktitle]")
  327. :journal (or (cdr (assoc "journal" entry)) "[no journal]")
  328. :publisher (or (cdr (assoc "publisher" entry)) "[no publisher]")
  329. :pages (or (cdr (assoc "pages" entry)) "[no pages]")
  330. :url (or (cdr (assoc "url" entry)) "[no url]")
  331. :year (or (cdr (assoc "year" entry)) "[no year]")
  332. :month (or (cdr (assoc "month" entry)) "[no month]")
  333. :address (or (cdr (assoc "address" entry)) "[no address]")
  334. :volume (or (cdr (assoc "volume" entry)) "[no volume]")
  335. :number (or (cdr (assoc "number" entry)) "[no number]")
  336. :annote (or (cdr (assoc "annote" entry)) "[no annotation]")
  337. :series (or (cdr (assoc "series" entry)) "[no series]")
  338. :abstract (or (cdr (assoc "abstract" entry)) "[no abstract]")
  339. :btype (or (cdr (assoc "=type=" entry)) "[no type]")
  340. :type "bibtex"
  341. :link link
  342. :description description))))
  343. (defun org-create-file-search-in-bibtex ()
  344. "Create the search string and description for a BibTeX database entry."
  345. ;; Make a good description for this entry, using names, year and the title
  346. ;; Put it into the `description' variable which is dynamically scoped.
  347. (let ((bibtex-autokey-names 1)
  348. (bibtex-autokey-names-stretch 1)
  349. (bibtex-autokey-name-case-convert-function 'identity)
  350. (bibtex-autokey-name-separator " & ")
  351. (bibtex-autokey-additional-names " et al.")
  352. (bibtex-autokey-year-length 4)
  353. (bibtex-autokey-name-year-separator " ")
  354. (bibtex-autokey-titlewords 3)
  355. (bibtex-autokey-titleword-separator " ")
  356. (bibtex-autokey-titleword-case-convert-function 'identity)
  357. (bibtex-autokey-titleword-length 'infty)
  358. (bibtex-autokey-year-title-separator ": "))
  359. (setq description (bibtex-generate-autokey)))
  360. ;; Now parse the entry, get the key and return it.
  361. (save-excursion
  362. (bibtex-beginning-of-entry)
  363. (cdr (assoc "=key=" (bibtex-parse-entry)))))
  364. (defun org-execute-file-search-in-bibtex (s)
  365. "Find the link search string S as a key for a database entry."
  366. (when (eq major-mode 'bibtex-mode)
  367. ;; Yes, we want to do the search in this file.
  368. ;; We construct a regexp that searches for "@entrytype{" followed by the key
  369. (goto-char (point-min))
  370. (and (re-search-forward (concat "@[a-zA-Z]+[ \t\n]*{[ \t\n]*"
  371. (regexp-quote s) "[ \t\n]*,") nil t)
  372. (goto-char (match-beginning 0)))
  373. (if (and (match-beginning 0) (equal current-prefix-arg '(16)))
  374. ;; Use double prefix to indicate that any web link should be browsed
  375. (let ((b (current-buffer)) (p (point)))
  376. ;; Restore the window configuration because we just use the web link
  377. (set-window-configuration org-window-config-before-follow-link)
  378. (with-current-buffer b
  379. (goto-char p)
  380. (bibtex-url)))
  381. (recenter 0)) ; Move entry start to beginning of window
  382. ;; return t to indicate that the search is done.
  383. t))
  384. ;; Finally add the link search function to the right hook.
  385. (add-hook 'org-execute-file-search-functions 'org-execute-file-search-in-bibtex)
  386. ;;; Bibtex <-> Org-mode headline translation functions
  387. (defun org-bibtex ()
  388. "Export each headline in the current file to a bibtex entry.
  389. Headlines are exported using `org-bibtex-export-headline'."
  390. (interactive)
  391. (let ((bibtex-entries (remove nil (org-map-entries #'org-bibtex-headline))))
  392. (with-temp-file (concat (file-name-sans-extension (buffer-file-name)) ".bib")
  393. (insert (mapconcat #'identity bibtex-entries "\n")))))
  394. (defun org-bibtex-check (&optional optional)
  395. "Check the current headline for required fields.
  396. With prefix argument OPTIONAL also prompt for optional fields."
  397. (interactive "P")
  398. (save-restriction
  399. (org-narrow-to-subtree)
  400. (let ((type ((lambda (name) (when name (intern (concat ":" name))))
  401. (org-bibtex-get "TYPE"))))
  402. (when type (org-bibtex-fleshout type optional)))))
  403. (defun org-bibtex-check-all (&optional optional)
  404. "Check all headlines in the current file.
  405. With prefix argument OPTIONAL also prompt for optional fields."
  406. (interactive) (org-map-entries (lambda () (org-bibtex-check optional))))
  407. (defun org-bibtex-create (type)
  408. "Create a new entry at the given level."
  409. (interactive
  410. (list (org-icompleting-read
  411. "Type: "
  412. (mapcar (lambda (type) (symbol-name (car type))) org-bibtex-types))))
  413. (let ((type (if (keywordp type) type (intern type))))
  414. (unless (assoc type org-bibtex-types)
  415. (error "type:%s is not known" type))
  416. (org-insert-heading)
  417. (let ((title (org-bibtex-ask :title)))
  418. (insert title) (org-bibtex-put "TITLE" title))
  419. (org-bibtex-put "TYPE" (substring (symbol-name type) 1))
  420. (org-bibtex-fleshout type)))
  421. (defun org-bibtex-read ()
  422. "Read a bibtex entry and save to `*org-bibtex-entries*'.
  423. This uses `bibtex-parse-entry'."
  424. (interactive)
  425. (flet ((keyword (str) (intern (concat ":" (downcase str))))
  426. (clean-space (str) (replace-regexp-in-string
  427. "[[:space:]\n\r]+" " " str))
  428. (strip-delim (str) ; strip enclosing "..." and {...}
  429. (dolist (pair '((34 . 34) (123 . 125)))
  430. (when (and (= (aref str 0) (car pair))
  431. (= (aref str (1- (length str))) (cdr pair)))
  432. (setf str (subseq str 1 (1- (length str)))))) str))
  433. (push (mapcar
  434. (lambda (pair)
  435. (cons (let ((field (keyword (car pair))))
  436. (case field
  437. (:=type= :type)
  438. (:=key= :key)
  439. (otherwise field)))
  440. (clean-space (strip-delim (cdr pair)))))
  441. (save-excursion (bibtex-beginning-of-entry) (bibtex-parse-entry)))
  442. *org-bibtex-entries*)))
  443. (defun org-bibtex-write ()
  444. "Insert a heading built from the first element of `*org-bibtex-entries*'."
  445. (interactive)
  446. (when (= (length *org-bibtex-entries*) 0)
  447. (error "No entries in `*org-bibtex-entries*'."))
  448. (let ((entry (pop *org-bibtex-entries*)))
  449. (flet ((get (field) (cdr (assoc field entry))))
  450. (org-insert-heading)
  451. (insert (get :title))
  452. (org-bibtex-put "TITLE" (get :title))
  453. (org-bibtex-put "TYPE" (downcase (get :type)))
  454. (dolist (pair entry)
  455. (case (car pair)
  456. (:title nil)
  457. (:type nil)
  458. (:key (org-bibtex-put "CUSTOM_ID" (cdr pair)))
  459. (otherwise (org-bibtex-put (car pair) (cdr pair))))))))
  460. (provide 'org-bibtex)
  461. ;; arch-tag: 83987d5a-01b8-41c7-85bc-77700f1285f5
  462. ;;; org-bibtex.el ends here