summaryrefslogtreecommitdiff
path: root/lisp/org/org-bibtex.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/org/org-bibtex.el')
-rw-r--r--lisp/org/org-bibtex.el67
1 files changed, 45 insertions, 22 deletions
diff --git a/lisp/org/org-bibtex.el b/lisp/org/org-bibtex.el
index 3607458a41..17cdbc27f2 100644
--- a/lisp/org/org-bibtex.el
+++ b/lisp/org/org-bibtex.el
@@ -1,12 +1,11 @@
;;; org-bibtex.el --- Org links to BibTeX entries
;;
-;; Copyright (C) 2007-2011 Free Software Foundation, Inc.
+;; Copyright (C) 2007-2012 Free Software Foundation, Inc.
;;
;; Author: Bastien Guerry <bzg at altern dot org>
;; Carsten Dominik <carsten dot dominik at gmail dot com>
;; Eric Schulte <schulte dot eric at gmail dot com>
;; Keywords: org, wp, remember
-;; Version: 7.7
;;
;; This file is part of GNU Emacs.
;;
@@ -204,7 +203,7 @@
(: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 (--).")
(:publisher . "The publisher’s name.")
(:school . "The name of the school where a thesis was written.")
- (:series . "The name of a series or set of books. When citing an entire book, 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.")
+ (: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.")
(:title . "The work’s title, typed as explained in the LaTeX book.")
(:type . "The type of a technical report for example, 'Research Note'.")
(:volume . "The volume of a journal or multi-volume book.")
@@ -221,7 +220,7 @@
(defcustom org-bibtex-prefix nil
"Optional prefix for all bibtex property names.
-For example setting to 'BIB_' would allow interoperability with Fireforg."
+For example setting to 'BIB_' would allow interoperability with fireforg."
:group 'org-bibtex
:type 'string)
@@ -275,12 +274,20 @@ This variable is relevant only if `org-bibtex-export-tags-as-keywords` is t."
:group 'org-bibtex
:type '(repeat :tag "Tag" (string)))
+(defcustom org-bibtex-type-property-name "btype"
+ "Property in which to store bibtex entry type (e.g., article)."
+ :group 'org-bibtex
+ :type 'string)
+
;;; Utility functions
(defun org-bibtex-get (property)
((lambda (it) (when it (org-babel-trim it)))
- (or (org-entry-get (point) (upcase property))
- (org-entry-get (point) (concat org-bibtex-prefix (upcase property))))))
+ (let ((org-special-properties
+ (delete "FILE" (copy-sequence org-special-properties))))
+ (or
+ (org-entry-get (point) (upcase property))
+ (org-entry-get (point) (concat org-bibtex-prefix (upcase property)))))))
(defun org-bibtex-put (property value)
(let ((prop (upcase (if (keywordp property)
@@ -303,7 +310,7 @@ This variable is relevant only if `org-bibtex-export-tags-as-keywords` is t."
lsts))))
(let ((notes (buffer-string))
(id (org-bibtex-get org-bibtex-key-property))
- (type (org-bibtex-get "type"))
+ (type (org-bibtex-get org-bibtex-type-property-name))
(tags (when org-bibtex-tags-are-keywords
(delq nil
(mapcar
@@ -317,16 +324,20 @@ This variable is relevant only if `org-bibtex-export-tags-as-keywords` is t."
(let ((entry (format
"@%s{%s,\n%s\n}\n" type id
(mapconcat
- (lambda (pair) (format " %s={%s}" (car pair) (cdr pair)))
+ (lambda (pair)
+ (format " %s={%s}" (car pair) (cdr pair)))
(remove nil
(if (and org-bibtex-export-arbitrary-fields
org-bibtex-prefix)
(mapcar
(lambda (kv)
(let ((key (car kv)) (val (cdr kv)))
- (when (and (string-match org-bibtex-prefix key)
- (not (string=
- (downcase (concat org-bibtex-prefix "TYPE")) (downcase key))))
+ (when (and
+ (string-match org-bibtex-prefix key)
+ (not (string=
+ (downcase (concat org-bibtex-prefix
+ org-bibtex-type-property-name))
+ (downcase key))))
(cons (downcase (replace-regexp-in-string
org-bibtex-prefix "" key))
val))))
@@ -514,9 +525,20 @@ Headlines are exported using `org-bibtex-export-headline'."
"Bibtex file: " nil nil nil
(file-name-nondirectory
(concat (file-name-sans-extension (buffer-file-name)) ".bib")))))
- (let ((bibtex-entries (remove nil (org-map-entries #'org-bibtex-headline))))
- (with-temp-file filename
- (insert (mapconcat #'identity bibtex-entries "\n")))))
+ ((lambda (error-point)
+ (when error-point
+ (goto-char error-point)
+ (message "Bibtex error at %S" (nth 4 (org-heading-components)))))
+ (catch 'bib
+ (let ((bibtex-entries (remove nil (org-map-entries
+ (lambda ()
+ (condition-case foo
+ (org-bibtex-headline)
+ (error (throw 'bib (point)))))))))
+ (with-temp-file filename
+ (insert (mapconcat #'identity bibtex-entries "\n")))
+ (message "Successfully exported %d bibtex entries to %s"
+ (length bibtex-entries) filename) nil))))
(defun org-bibtex-check (&optional optional)
"Check the current headline for required fields.
@@ -525,7 +547,7 @@ With prefix argument OPTIONAL also prompt for optional fields."
(save-restriction
(org-narrow-to-subtree)
(let ((type ((lambda (name) (when name (intern (concat ":" name))))
- (org-bibtex-get "TYPE"))))
+ (org-bibtex-get org-bibtex-type-property-name))))
(when type (org-bibtex-fleshout type optional)))))
(defun org-bibtex-check-all (&optional optional)
@@ -542,7 +564,8 @@ If nonew is t, add data to the headline of the entry at point."
"Type: " (mapcar (lambda (type)
(substring (symbol-name (car type)) 1))
org-bibtex-types)
- nil nil (when nonew (org-bibtex-get "TYPE"))))
+ nil nil (when nonew
+ (org-bibtex-get org-bibtex-type-property-name))))
(type (if (keywordp type) type (intern (concat ":" type))))
(org-bibtex-treat-headline-as-title (if nonew nil t)))
(unless (assoc type org-bibtex-types)
@@ -553,7 +576,8 @@ If nonew is t, add data to the headline of the entry at point."
(let ((title (org-bibtex-ask :title)))
(insert title)
(org-bibtex-put "TITLE" title)))
- (org-bibtex-put "TYPE" (substring (symbol-name type) 1))
+ (org-bibtex-put org-bibtex-type-property-name
+ (substring (symbol-name type) 1))
(org-bibtex-fleshout type arg)
(mapc (lambda (tag) (org-toggle-tag tag 'on)) org-bibtex-tags)))
@@ -598,7 +622,7 @@ This uses `bibtex-parse-entry'."
(org-insert-heading)
(insert (val :title))
(org-bibtex-put "TITLE" (val :title))
- (org-bibtex-put "TYPE" (downcase (val :type)))
+ (org-bibtex-put org-bibtex-type-property-name (downcase (val :type)))
(dolist (pair entry)
(case (car pair)
(:title nil)
@@ -637,11 +661,10 @@ This function relies `org-search-view' to locate results."
(let ((org-agenda-overriding-header "Bib search results:")
(org-agenda-search-view-always-boolean t))
(org-search-view nil
- (format "%s +{:%sTYPE:}"
- string org-bibtex-prefix))))
+ (format "%s +{:%s%s:}"
+ string org-bibtex-prefix
+ org-bibtex-type-property-name))))
(provide 'org-bibtex)
-
-
;;; org-bibtex.el ends here