123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- (require 'org)
- (defvar description nil)
- (declare-function bibtex-beginning-of-entry "bibtex" ())
- (declare-function bibtex-generate-autokey "bibtex" ())
- (declare-function bibtex-parse-entry "bibtex" (&optional content))
- (declare-function bibtex-url "bibtex" (&optional pos no-browse))
- (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 (org-create-file-search-in-bibtex))
- (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))))
- (defun org-create-file-search-in-bibtex ()
- "Create the search string and description for a BibTeX database entry."
-
-
- (let ((bibtex-autokey-names 1)
- (bibtex-autokey-names-stretch 1)
- (bibtex-autokey-name-case-convert-function 'identity)
- (bibtex-autokey-name-separator " & ")
- (bibtex-autokey-additional-names " et al.")
- (bibtex-autokey-year-length 4)
- (bibtex-autokey-name-year-separator " ")
- (bibtex-autokey-titlewords 3)
- (bibtex-autokey-titleword-separator " ")
- (bibtex-autokey-titleword-case-convert-function 'identity)
- (bibtex-autokey-titleword-length 'infty)
- (bibtex-autokey-year-title-separator ": "))
- (setq description (bibtex-generate-autokey)))
-
- (save-excursion
- (bibtex-beginning-of-entry)
- (cdr (assoc "=key=" (bibtex-parse-entry)))))
- (defun org-execute-file-search-in-bibtex (s)
- "Find the link search string S as a key for a database entry."
- (when (eq major-mode 'bibtex-mode)
-
-
- (goto-char (point-min))
- (and (re-search-forward (concat "@[a-zA-Z]+[ \t\n]*{[ \t\n]*"
- (regexp-quote s) "[ \t\n]*,") nil t)
- (goto-char (match-beginning 0)))
- (if (and (match-beginning 0) (equal current-prefix-arg '(16)))
-
- (let ((b (current-buffer)) (p (point)))
-
- (set-window-configuration org-window-config-before-follow-link)
- (save-excursion (set-buffer b) (goto-char p)
- (bibtex-url)))
- (recenter 0))
-
- t))
- (add-hook 'org-execute-file-search-functions 'org-execute-file-search-in-bibtex)
- (provide 'org-bibtex)
|