123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- (provide 'org-bibtex)
- (require 'org)
- (defvar description nil)
- (org-add-link-type "bibtex" 'org-bibtex-open)
- (add-hook 'org-store-link-functions 'org-bibtex-store-link)
- (defun org-bibtex-open (path)
- "Visit the bibliography entry on PATH."
- (let* ((search (when (string-match "::\\(.+\\)\\'" path)
- (match-string 1 path)))
- (path (substring path 0 (match-beginning 0))))
- (org-open-file path t nil search)))
- (defun org-bibtex-store-link ()
- "Store a link to a BibTeX entry."
- (when (eq major-mode 'bibtex-mode)
- (let* ((search (run-hook-with-args-until-success
- 'org-create-file-search-functions))
- (link (concat "file:" (abbreviate-file-name buffer-file-name)
- "::" search))
- (entry (mapcar
- (lambda(c)
- (if (string-match
- "^\\(?:{\\|\"\\)\\(.*\\)\\(?:}\\|\"\\)$" (cdr c))
- (cons (car c) (match-string 1 (cdr c))) c))
- (save-excursion
- (bibtex-beginning-of-entry)
- (bibtex-parse-entry)))))
- (org-store-link-props
- :key (cdr (assoc "=key=" entry))
- :author (or (cdr (assoc "author" entry)) "[no author]")
- :editor (or (cdr (assoc "editor" entry)) "[no editor]")
- :title (or (cdr (assoc "title" entry)) "[no title]")
- :booktitle (or (cdr (assoc "booktitle" entry)) "[no booktitle]")
- :journal (or (cdr (assoc "journal" entry)) "[no journal]")
- :publisher (or (cdr (assoc "publisher" entry)) "[no publisher]")
- :pages (or (cdr (assoc "pages" entry)) "[no pages]")
- :url (or (cdr (assoc "url" entry)) "[no url]")
- :year (or (cdr (assoc "year" entry)) "[no year]")
- :month (or (cdr (assoc "month" entry)) "[no month]")
- :address (or (cdr (assoc "address" entry)) "[no address]")
- :volume (or (cdr (assoc "volume" entry)) "[no volume]")
- :number (or (cdr (assoc "number" entry)) "[no number]")
- :annote (or (cdr (assoc "annote" entry)) "[no annotation]")
- :series (or (cdr (assoc "series" entry)) "[no series]")
- :abstract (or (cdr (assoc "abstract" entry)) "[no abstract]")
- :btype (or (cdr (assoc "=type=" entry)) "[no type]")
- :type "bibtex"
- :link link
- :description description))))
- (provide 'org-bibtex)
|