;;; org-bibtex.el --- Org links to BibTeX entries
;;
-;; Copyright (C) 2007-2013 Free Software Foundation, Inc.
+;; Copyright (C) 2007-2016 Free Software Foundation, Inc.
;;
;; Authors: Bastien Guerry <bzg@gnu.org>
;; Carsten Dominik <carsten dot dominik at gmail dot com>
;; Here is an example of a capture template that use some of this
;; information (:author :year :title :journal :pages):
;;
-;; (setq org-capure-templates
+;; (setq org-capture-templates
;; '((?b "* READ %?\n\n%a\n\n%:author (%:year): %:title\n \
;; In %:journal, %:pages.")))
;;
(:howpublished . "How something strange has been published. The first word should be capitalized.")
(:institution . "The sponsoring institution of a technical report.")
(:journal . "A journal name.")
- (: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.")
+ (: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.")
(: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,")
(:note . "Any additional information that can help the reader. The first word should be capitalized.")
(:number . "Any additional information that can help the reader. The first word should be capitalized.")
(: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 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 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.")
(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
:version "24.1"
:type '(choice
(defcustom org-bibtex-no-export-tags nil
"List of tag(s) that should not be converted to keywords.
-This variable is relevant only if `org-bibtex-export-tags-as-keywords' is t."
+This variable is relevant only if `org-bibtex-tags-are-keywords' is t."
:group 'org-bibtex
:version "24.1"
:type '(repeat :tag "Tag" (string)))
\f
;;; Utility functions
(defun org-bibtex-get (property)
- ((lambda (it) (when it (org-babel-trim it)))
- (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)))))))
+ (let ((it (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)))))))
+ (when it (org-babel-trim it))))
(defun org-bibtex-put (property value)
(let ((prop (upcase (if (keywordp property)
(bibtex-beginning-of-entry)
(if (re-search-forward "keywords.*=.*{\\(.*\\)}" nil t)
(progn (goto-char (match-end 1)) (insert ", "))
- (bibtex-make-field "keywords" t t))
+ (search-forward ",\n" nil t)
+ (insert " keywords={},\n")
+ (search-backward "}," nil t))
(insert (mapconcat #'identity tags ", ")))
(buffer-string))))))
(princ (cdr (assoc field org-bibtex-fields))))
(with-current-buffer buf-name (visual-line-mode 1))
(org-fit-window-to-buffer (get-buffer-window buf-name))
- ((lambda (result) (when (> (length result) 0) result))
- (read-from-minibuffer (format "%s: " name))))))
+ (let ((result (read-from-minibuffer (format "%s: " name))))
+ (when (> (length result) 0) result)))))
(defun org-bibtex-autokey ()
"Generate an autokey for the current headline."
;;; Bibtex <-> Org-mode headline translation functions
(defun org-bibtex (&optional filename)
"Export each headline in the current file to a bibtex entry.
-Headlines are exported using `org-bibtex-export-headline'."
+Headlines are exported using `org-bibtex-headline'."
(interactive
(list (read-file-name
"Bibtex file: " nil nil nil
(file-name-nondirectory
(concat (file-name-sans-extension (buffer-file-name)) ".bib")))))
- ((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))))
+ (let ((error-point
+ (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))))
+ (when error-point
+ (goto-char error-point)
+ (message "Bibtex error at %S" (nth 4 (org-heading-components))))))
(defun org-bibtex-check (&optional optional)
"Check the current headline for required fields.
(interactive "P")
(save-restriction
(org-narrow-to-subtree)
- (let ((type ((lambda (name) (when name (intern (concat ":" name))))
- (org-bibtex-get org-bibtex-type-property-name))))
+ (let ((type (let ((name (org-bibtex-get org-bibtex-type-property-name)))
+ (when name (intern (concat ":" name))))))
(when type (org-bibtex-fleshout type optional)))))
(defun org-bibtex-check-all (&optional optional)
(strip-delim
(lambda (str) ; strip enclosing "..." and {...}
(dolist (pair '((34 . 34) (123 . 125) (123 . 125)))
- (when (and (= (aref str 0) (car pair))
+ (when (and (> (length str) 1)
+ (= (aref str 0) (car pair))
(= (aref str (1- (length str))) (cdr pair)))
(setf str (substring str 1 (1- (length str)))))) str)))
(push (mapcar