2019-03-02 00:01:32 +00:00
;;; ol-bibtex.el --- Links to BibTeX entries -*- lexical-binding: t; -*-
2008-01-31 15:04:26 +00:00
;;
2022-01-01 20:10:55 +00:00
;; Copyright (C) 2007-2022 Free Software Foundation, Inc.
2008-01-31 15:04:26 +00:00
;;
2013-10-08 06:07:21 +00:00
;; Authors: Bastien Guerry <bzg@gnu.org>
2012-04-01 22:53:28 +00:00
;; Carsten Dominik <carsten dot dominik at gmail dot com>
;; Eric Schulte <schulte dot eric at gmail dot com>
2013-02-22 10:44:29 +00:00
;; Keywords: org, wp, capture
2008-01-31 15:04:26 +00:00
;;
2008-04-03 11:21:45 +00:00
;; This file is part of GNU Emacs.
;;
2008-05-06 12:45:52 +00:00
;; GNU Emacs is free software: you can redistribute it and/or modify
2008-01-31 15:04:26 +00:00
;; it under the terms of the GNU General Public License as published by
2008-05-06 12:45:52 +00:00
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
2008-04-03 11:21:45 +00:00
;; GNU Emacs is distributed in the hope that it will be useful,
2008-01-31 15:04:26 +00:00
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
2008-04-03 11:21:45 +00:00
2008-01-31 15:04:26 +00:00
;; You should have received a copy of the GNU General Public License
2017-09-13 22:52:52 +00:00
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
2008-01-31 15:04:26 +00:00
;;
;;; Commentary:
;;
2008-04-03 11:21:45 +00:00
;; This file implements links to database entries in BibTeX files.
;; Instead of defining a special link prefix, it uses the normal file
;; links combined with a custom search mechanism to find entries
2008-12-16 14:31:29 +00:00
;; by reference key. And it constructs a nice description tag for
2008-04-03 11:21:45 +00:00
;; the link that contains the author name, the year and a short title.
2008-01-31 15:04:26 +00:00
;;
2008-04-03 11:21:45 +00:00
;; It also stores detailed information about the entry so that
2013-02-22 10:44:29 +00:00
;; capture templates can access and enter this information easily.
2008-01-31 15:04:26 +00:00
;;
;; The available properties for each entry are listed here:
;;
;; :author :publisher :volume :pages
;; :editor :url :number :journal
;; :title :year :series :address
;; :booktitle :month :annote :abstract
;; :key :btype
2008-04-24 08:29:47 +00:00
;;
2013-02-22 10:44:29 +00:00
;; Here is an example of a capture template that use some of this
2008-01-31 15:04:26 +00:00
;; information (:author :year :title :journal :pages):
2008-04-24 08:29:47 +00:00
;;
2013-11-17 08:12:41 +00:00
;; (setq org-capture-templates
2008-01-31 15:04:26 +00:00
;; '((?b "* READ %?\n\n%a\n\n%:author (%:year): %:title\n \
;; In %:journal, %:pages.")))
2008-04-24 08:29:47 +00:00
;;
2013-02-22 10:44:29 +00:00
;; Let's say you want to capture this BibTeX entry:
2008-04-24 08:29:47 +00:00
;;
2008-01-31 15:04:26 +00:00
;; @Article{dolev83,
;; author = {Danny Dolev and Andrew C. Yao},
;; title = {On the security of public-key protocols},
;; journal = {IEEE Transaction on Information Theory},
;; year = 1983,
;; volume = 2,
;; number = 29,
;; pages = {198--208},
;; month = {Mars}
;; }
2008-04-24 08:29:47 +00:00
;;
2013-02-22 10:44:29 +00:00
;; M-x `org-capture' on this entry will produce this buffer:
2008-04-24 08:29:47 +00:00
;;
2008-01-31 15:04:26 +00:00
;; =====================================================================
;; * READ <== [point here]
2008-04-24 08:29:47 +00:00
;;
2011-04-22 12:19:30 +00:00
;; [[file:file.bib::dolev83][Dolev & Yao 1983: security of public key protocols]]
2008-04-24 08:29:47 +00:00
;;
2008-01-31 15:04:26 +00:00
;; Danny Dolev and Andrew C. Yao (1983): On the security of public-key protocols
;; In IEEE Transaction on Information Theory, 198--208.
;; =====================================================================
;;
2011-04-22 12:19:30 +00:00
;; Additionally, the following functions are now available for storing
2016-08-23 20:13:56 +00:00
;; bibtex entries within Org documents.
2011-04-22 12:19:30 +00:00
;;
;; - Run `org-bibtex' to export the current file to a .bib.
;;
;; - Run `org-bibtex-check' or `org-bibtex-check-all' to check and
;; fill in missing field of either the current, or all headlines
;;
;; - Run `org-bibtex-create' to add a bibtex entry
;;
;; - Use `org-bibtex-read' to read a bibtex entry after `point' or in
;; the active region, then call `org-bibtex-write' in a .org file to
;; insert a heading for the read bibtex entry
;;
;; - All Bibtex information is taken from the document compiled by
;; Andrew Roberts from the Bibtex manual, available at
2021-03-21 18:55:14 +00:00
;; https://www.andy-roberts.net/res/writing/latex/bibentries.pdf
2011-04-22 12:19:30 +00:00
;;
2008-01-31 15:04:26 +00:00
;;; History:
2008-04-24 08:29:47 +00:00
;;
2016-08-23 20:13:56 +00:00
;; The link creation part has been part of Org for a long time.
2008-04-24 08:29:47 +00:00
;;
2013-02-22 10:44:29 +00:00
;; Creating better capture template information was inspired by a request
2020-06-05 08:39:52 +00:00
;; of Austin Frank: https://orgmode.org/list/m0myu03vbx.fsf@gmail.com
2009-11-12 12:39:29 +00:00
;; and then implemented by Bastien Guerry.
2008-01-31 15:04:26 +00:00
;;
2011-04-22 12:19:30 +00:00
;; Eric Schulte eventually added the functions for translating between
2016-08-23 20:13:56 +00:00
;; Org headlines and Bibtex entries, and for fleshing out the Bibtex
;; fields of existing Org headlines.
2011-04-22 12:19:30 +00:00
;;
2016-08-23 20:13:56 +00:00
;; Org mode loads this module by default - if this is not what you want,
2008-04-03 11:21:45 +00:00
;; configure the variable `org-modules'.
2008-01-31 15:04:26 +00:00
;;; Code:
2022-08-04 13:53:05 +00:00
( require 'org-macs )
( org-assert-version )
2011-04-22 12:19:30 +00:00
( require 'bibtex )
2015-12-20 21:48:05 +00:00
( require 'cl-lib )
2012-08-13 03:59:44 +00:00
( require 'org-compat )
2019-03-02 00:01:32 +00:00
( require 'org-macs )
( require 'ol )
2008-01-31 15:04:26 +00:00
2015-12-20 21:48:05 +00:00
( defvar org-agenda-overriding-header )
( defvar org-agenda-search-view-always-boolean )
2022-01-30 08:42:58 +00:00
( defvar org-bibtex-description nil )
2011-06-01 05:55:45 +00:00
( defvar org-id-locations )
2019-03-02 00:01:32 +00:00
( defvar org-property-end-re )
( defvar org-special-properties )
( defvar org-window-config-before-follow-link )
2008-04-03 11:21:45 +00:00
( 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 ) )
2008-01-31 15:04:26 +00:00
2019-03-02 00:01:32 +00:00
( declare-function org-back-to-heading " org " ( &optional invisible-ok ) )
( declare-function org-entry-get " org " ( pom property &optional inherit literal-nil ) )
( declare-function org-entry-properties " org " ( &optional pom which ) )
( declare-function org-get-tags " org " ( &optional pos local ) )
( declare-function org-heading-components " org " ( ) )
( declare-function org-insert-heading " org " ( &optional arg invisible-ok top ) )
( declare-function org-map-entries " org " ( func &optional match scope &rest skip ) )
2021-10-16 16:01:56 +00:00
( declare-function org-narrow-to-subtree " org " ( &optional element ) )
2019-03-02 00:01:32 +00:00
( declare-function org-set-property " org " ( property value ) )
( declare-function org-toggle-tag " org " ( tag &optional onoff ) )
2020-12-13 18:56:29 +00:00
( declare-function org-search-view " org-agenda " ( &optional todo-only string edit-at ) )
2011-04-22 12:19:30 +00:00
;;; Bibtex data
( defvar org-bibtex-types
' ( ( :article
( :description . " An article from a journal or magazine " )
( :required :author :title :journal :year )
2021-06-28 12:35:34 +00:00
( :optional :volume :number :pages :month :note :doi ) )
2011-04-22 12:19:30 +00:00
( :book
( :description . " A book with an explicit publisher " )
( :required ( :editor :author ) :title :publisher :year )
2021-06-28 12:35:34 +00:00
( :optional ( :volume :number ) :series :address :edition :month :note :doi ) )
2011-04-22 12:19:30 +00:00
( :booklet
( :description . " A work that is printed and bound, but without a named publisher or sponsoring institution. " )
( :required :title )
2021-06-28 12:35:34 +00:00
( :optional :author :howpublished :address :month :year :note :doi :url ) )
2011-04-22 12:19:30 +00:00
( :conference
( :description . " " )
( :required :author :title :booktitle :year )
2021-06-28 12:35:34 +00:00
( :optional :editor :pages :organization :publisher :address :month :note :doi :url ) )
2011-04-22 12:19:30 +00:00
( :inbook
( :description . " A part of a book, which may be a chapter (or section or whatever) and/or a range of pages. " )
( :required ( :author :editor ) :title ( :chapter :pages ) :publisher :year )
2021-06-28 12:35:34 +00:00
( :optional :crossref ( :volume :number ) :series :type :address :edition :month :note :doi ) )
2011-04-22 12:19:30 +00:00
( :incollection
( :description . " A part of a book having its own title. " )
( :required :author :title :booktitle :publisher :year )
2021-06-28 12:35:34 +00:00
( :optional :crossref :editor ( :volume :number ) :series :type :chapter :pages :address :edition :month :note :doi ) )
2011-04-22 12:19:30 +00:00
( :inproceedings
( :description . " An article in a conference proceedings " )
( :required :author :title :booktitle :year )
2021-06-28 12:35:34 +00:00
( :optional :crossref :editor ( :volume :number ) :series :pages :address :month :organization :publisher :note :doi ) )
2011-04-22 12:19:30 +00:00
( :manual
( :description . " Technical documentation. " )
( :required :title )
2021-06-28 12:35:34 +00:00
( :optional :author :organization :address :edition :month :year :note :doi :url ) )
2011-04-22 12:19:30 +00:00
( :mastersthesis
( :description . " A Master’ s thesis. " )
( :required :author :title :school :year )
2021-06-28 12:35:34 +00:00
( :optional :type :address :month :note :doi :url ) )
2011-04-22 12:19:30 +00:00
( :misc
( :description . " Use this type when nothing else fits. " )
( :required )
2021-06-28 12:35:34 +00:00
( :optional :author :title :howpublished :month :year :note :doi :url ) )
2011-04-22 12:19:30 +00:00
( :phdthesis
( :description . " A PhD thesis. " )
( :required :author :title :school :year )
2021-06-28 12:35:34 +00:00
( :optional :type :address :month :note :doi :url ) )
2011-04-22 12:19:30 +00:00
( :proceedings
( :description . " The proceedings of a conference. " )
( :required :title :year )
2021-06-28 12:35:34 +00:00
( :optional :editor ( :volume :number ) :series :address :month :organization :publisher :note :doi ) )
2011-04-22 12:19:30 +00:00
( :techreport
( :description . " A report published by a school or other institution. " )
( :required :author :title :institution :year )
2021-06-28 12:35:34 +00:00
( :optional :type :address :month :note :doi :url ) )
2011-04-22 12:19:30 +00:00
( :unpublished
( :description . " A document having an author and title, but not formally published. " )
( :required :author :title :note )
2021-06-28 12:35:34 +00:00
( :optional :month :year :doi :url ) ) )
2011-04-22 12:19:30 +00:00
" Bibtex entry types with required and optional parameters. " )
( defvar org-bibtex-fields
2012-08-11 17:10:44 +00:00
' ( ( :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. " )
( :annote . " An annotation. It is not used by the standard bibliography styles, but may be used by others that produce an annotated bibliography. " )
2011-04-22 12:19:30 +00:00
( :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. " )
2012-08-11 17:10:44 +00:00
( :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. " )
2011-04-22 12:19:30 +00:00
( :chapter . " A chapter (or section or whatever) number. " )
( :crossref . " The database key of the entry being cross referenced. " )
2021-06-28 12:35:34 +00:00
( :doi . " The digital object identifier. " )
2012-08-11 17:10:44 +00:00
( :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. " )
( :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. " )
( :howpublished . " How something strange has been published. The first word should be capitalized. " )
2011-04-22 12:19:30 +00:00
( :institution . " The sponsoring institution of a technical report. " )
( :journal . " A journal name. " )
2015-09-17 19:28:45 +00:00
( :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. " )
2012-08-11 17:10:44 +00:00
( :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. " )
2011-04-22 12:19:30 +00:00
( :organization . " The organization that sponsors a conference or that publishes a manual. " )
( :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. " )
2014-06-23 07:40:19 +00:00
( :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. " )
2011-04-22 12:19:30 +00:00
( :title . " The work’ s title, typed as explained in the LaTeX book. " )
( :type . " The type of a technical report for example, 'Research Note'. " )
2021-06-28 12:35:34 +00:00
( :url . " Uniform resource locator. " )
2011-04-22 12:19:30 +00:00
( :volume . " The volume of a journal or multi-volume book. " )
( :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)' " ) )
" Bibtex fields with descriptions. " )
2012-05-21 16:30:09 +00:00
( defvar org-bibtex-entries nil
2011-04-22 12:19:30 +00:00
" List to hold parsed bibtex entries. " )
( defcustom org-bibtex-autogen-keys nil
2011-11-28 14:11:52 +00:00
" Set to a truth value to use `bibtex-generate-autokey' to generate keys. "
2011-04-22 12:19:30 +00:00
:group 'org-bibtex
2012-04-03 11:21:04 +00:00
:version " 24.1 "
2011-04-22 12:19:30 +00:00
:type 'boolean )
( defcustom org-bibtex-prefix nil
" Optional prefix for all bibtex property names.
2015-09-21 04:23:36 +00:00
For example setting to ` BIB_ ' would allow interoperability with fireforg. "
2011-04-22 12:19:30 +00:00
:group 'org-bibtex
2012-04-03 11:21:04 +00:00
:version " 24.1 "
2013-05-09 13:19:02 +00:00
:type ' ( choice
( const nil )
( string ) ) )
2011-04-22 12:19:30 +00:00
2011-04-30 18:03:37 +00:00
( defcustom org-bibtex-treat-headline-as-title t
" Treat headline text as title if title property is absent.
If an entry is missing a title property, use the headline text as
2012-08-11 17:10:44 +00:00
the property. If this value is t , ` org-bibtex-check ' will ignore
2011-04-30 18:03:37 +00:00
a missing title field. "
:group 'org-bibtex
2012-04-03 11:21:04 +00:00
:version " 24.1 "
2011-04-30 18:03:37 +00:00
:type 'boolean )
2016-12-09 20:44:06 +00:00
( defcustom org-bibtex-headline-format-function
( lambda ( entry ) ( cdr ( assq :title entry ) ) )
" Function returning the headline text for `org-bibtex-write' .
It should take a single argument, the bibtex entry ( an alist as
returned by ` org-bibtex-read ' ) . The default value simply returns
the entry title. "
:group 'org-bibtex
2017-01-26 05:06:04 +00:00
:version " 26.1 "
2016-12-09 20:44:06 +00:00
:package-version ' ( Org . " 9.1 " )
:type 'function )
2011-04-27 21:31:30 +00:00
( defcustom org-bibtex-export-arbitrary-fields nil
" When converting to bibtex allow fields not defined in `org-bibtex-fields' .
2011-05-01 21:01:59 +00:00
This only has effect if ` org-bibtex-prefix ' is defined, so as to
2011-04-27 21:31:30 +00:00
ensure that other org-properties, such as CATEGORY or LOGGING are
not placed in the exported bibtex entry. "
:group 'org-bibtex
2012-04-03 11:21:04 +00:00
:version " 24.1 "
2011-04-27 21:31:30 +00:00
:type 'boolean )
( defcustom org-bibtex-key-property " CUSTOM_ID "
" Property that holds the bibtex key.
By default, this is CUSTOM_ID, which enables easy linking to
2012-08-11 17:10:44 +00:00
bibtex headlines from within an org file. This can be set to ID
2011-04-27 21:31:30 +00:00
to enable global links, but only with great caution, as global
IDs must be unique. "
:group 'org-bibtex
2012-04-03 11:21:04 +00:00
:version " 24.1 "
2011-04-27 21:31:30 +00:00
:type 'string )
2011-05-01 20:54:01 +00:00
( defcustom org-bibtex-tags nil
" List of tag(s) that should be added to new bib entries. "
:group 'org-bibtex
2012-04-03 11:21:04 +00:00
:version " 24.1 "
2011-05-01 20:54:01 +00:00
:type ' ( repeat :tag " Tag " ( string ) ) )
( defcustom org-bibtex-tags-are-keywords nil
" Convert the value of the keywords field to tags and vice versa.
2014-04-18 19:39:35 +00:00
When non-nil, comma-separated entries in a bibtex entry 's keywords
field will be converted to Org tags. Note: spaces will be escaped
with underscores, and characters that are not permitted in Org
2011-05-01 20:54:01 +00:00
tags will be removed.
2014-04-18 19:39:35 +00:00
When non-nil, local tags in an Org entry will be exported as
a comma-separated string of keywords when exported to bibtex.
If ` org-bibtex-inherit-tags ' is non-nil, inherited tags will also
be exported as keywords. Tags defined in ` org-bibtex-tags ' or
` org-bibtex-no-export-tags ' will not be exported. "
2011-05-01 20:54:01 +00:00
:group 'org-bibtex
2012-04-03 11:21:04 +00:00
:version " 24.1 "
2011-05-01 20:54:01 +00:00
:type 'boolean )
( defcustom org-bibtex-no-export-tags nil
" List of tag(s) that should not be converted to keywords.
2014-04-18 19:39:35 +00:00
This variable is relevant only if ` org-bibtex-tags-are-keywords '
is non-nil. "
2011-05-01 20:54:01 +00:00
:group 'org-bibtex
2012-04-03 11:21:04 +00:00
:version " 24.1 "
2011-05-01 20:54:01 +00:00
:type ' ( repeat :tag " Tag " ( string ) ) )
2014-04-18 14:45:44 +00:00
( defcustom org-bibtex-inherit-tags nil
" Controls whether inherited tags are converted to bibtex keywords.
2014-04-18 19:39:35 +00:00
It is relevant only if ` org-bibtex-tags-are-keywords ' is non-nil.
2017-07-06 07:23:30 +00:00
Tag inheritance itself is controlled by ` org-use-tag-inheritance '
2020-09-23 11:35:55 +00:00
and ` org-tags-exclude-from-inheritance '. "
2014-04-18 14:45:44 +00:00
:group 'org-bibtex
2017-01-26 04:39:18 +00:00
:version " 26.1 "
2014-04-18 14:45:44 +00:00
:package-version ' ( Org . " 8.3 " )
:type 'boolean )
2011-09-20 15:20:53 +00:00
( defcustom org-bibtex-type-property-name " btype "
" Property in which to store bibtex entry type (e.g., article). "
:group 'org-bibtex
2012-04-03 11:21:04 +00:00
:version " 24.1 "
2011-09-20 15:20:53 +00:00
:type 'string )
2011-04-22 12:19:30 +00:00
;;; Utility functions
( defun org-bibtex-get ( property )
Backport changes from Emacs revs 115081 and 115082
2013-11-12 Stefan Monnier <monnier@iro.umontreal.ca>
Address some byte-compiler warnings.
* ob-abc.el (org-babel-expand-body:abc): Use dolist.
(org-babel-execute:abc): Fix regexp quoting.
* ob-calc.el (org--var-syms): Rename from `var-syms'.
* ob-lilypond.el (ly-compile-lilyfile): Remove redundant let-binding.
* ob-table.el (sbe): Move debug declaration.
* org-clock.el (org--msg-extra): Rename from `msg-extra'.
* org.el (org-version): Avoid var name starting with _.
(org-inhibit-startup, org-called-with-limited-levels)
(org-link-search-inhibit-query, org-time-was-given)
(org-end-time-was-given, org-def, org-defdecode, org-with-time):
* org-colview.el (org-agenda-overriding-columns-format):
* org-agenda.el (org-agenda-multi, org-depend-tag-blocked)
(org-agenda-show-log-scoped):
* ob-python.el (py-which-bufname, python-shell-buffer-name):
* ob-haskell.el (org-export-copy-to-kill-ring):
* ob-exp.el (org-link-search-inhibit-query):
* ob-R.el (ess-eval-visibly-p):
* ob-core.el (org-src-window-setup): Declare before use.
(org-babel-expand-noweb-references): Remove unused `blocks-in-buffer'.
* ox-odt.el (org-odt-hfy-face-to-css):
* org-src.el (org-src-associate-babel-session, org-src-get-lang-mode):
* org-bibtex.el (org-bibtex-get, org-bibtex-ask, org-bibtex)
(org-bibtex-check):
* ob-tangle.el (org-babel-tangle, org-babel-spec-to-string)
(org-babel-tangle-single-block, org-babel-tangle-comment-links):
* ob-table.el (sbe):
* ob-sqlite.el (org-babel-sqlite-expand-vars):
* ob-sql.el (org-babel-sql-expand-vars):
* ob-shen.el (org-babel-execute:shen):
* ob-sh.el (org-babel-execute:sh, org-babel-sh-evaluate):
* ob-scala.el (org-babel-scala-evaluate):
* ob-ruby.el (org-babel-ruby-table-or-string)
(org-babel-ruby-evaluate):
* ob-python.el (org-babel-python-table-or-string)
(org-babel-python-evaluate-external-process)
(org-babel-python-evaluate-session):
* ob-picolisp.el (org-babel-execute:picolisp):
* ob-perl.el (org-babel-perl-evaluate):
* ob-maxima.el (org-babel-execute:maxima):
* ob-lisp.el (org-babel-execute:lisp):
* ob-java.el (org-babel-execute:java):
* ob-io.el (org-babel-io-evaluate):
* ob-haskell.el (org-babel-execute:haskell):
* ob-fortran.el (org-babel-execute:fortran):
* ob-exp.el (org-babel-exp-code):
* ob-emacs-lisp.el (org-babel-execute:emacs-lisp):
* ob-ditaa.el (org-babel-execute:ditaa):
* ob-core.el (org-babel-execute-src-block, org-babel-sha1-hash)
(org-babel-parse-header-arguments, org-babel-reassemble-table)
(org-babel-goto-src-block-head, org-babel-mark-block)
(org-babel-expand-noweb-references, org-babel-script-escape)
(org-babel-process-file-name):
* ob-clojure.el (org-babel-execute:clojure):
* ob-calc.el (org-babel-execute:calc):
* ob-awk.el (org-babel-execute:awk):
* ob-abc.el (org-babel-execute:abc):
* ob-R.el (org-babel-expand-body:R):
* ob-C.el (org-babel-C-execute): Avoid deprecated ((lambda) ...).
2013-11-12 Glenn Morris <rgm@gnu.org>
* ox-html.el (org-html-scripts): Add 2013 to copyright years.
(org-html-infojs-template): Copyright holder to FSF.
2013-11-12 19:57:31 +00:00
( 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 ) ) ) ) ) ) )
2016-06-21 13:24:06 +00:00
( when it ( org-trim it ) ) ) )
2011-04-22 12:19:30 +00:00
2022-08-27 04:09:31 +00:00
( defun org-bibtex-put ( property value &optional insert-raw )
" Set PROPERTY of headline at point to VALUE.
The PROPERTY will be prefixed with ` org-bibtex-prefix ' when necessary.
With non-nil optional argument INSERT-RAW, insert node property string
at point. "
( let* ( ( prop ( upcase ( if ( keywordp property )
( substring ( symbol-name property ) 1 )
property ) ) )
( prop ( concat ( unless ( string= org-bibtex-key-property prop )
org-bibtex-prefix )
prop ) ) )
( if insert-raw
( insert ( format " :%s: %s \n " prop value ) )
( org-set-property prop value ) ) ) )
2011-04-22 12:19:30 +00:00
( defun org-bibtex-headline ( )
" Return a bibtex entry of the given headline as a string. "
2015-12-20 21:48:05 +00:00
( letrec ( ( val ( lambda ( key lst ) ( cdr ( assoc key lst ) ) ) )
( to ( lambda ( string ) ( intern ( concat " : " string ) ) ) )
( from ( lambda ( key ) ( substring ( symbol-name key ) 1 ) ) )
( flatten ( lambda ( &rest lsts )
( apply #' append ( mapcar
( lambda ( e )
( if ( listp e ) ( apply flatten e ) ( list e ) ) )
lsts ) ) ) )
( id ( org-bibtex-get org-bibtex-key-property ) )
( type ( org-bibtex-get org-bibtex-type-property-name ) )
( tags ( when org-bibtex-tags-are-keywords
( delq nil
( mapcar
( lambda ( tag )
( unless ( member tag
( append org-bibtex-tags
org-bibtex-no-export-tags ) )
tag ) )
2018-04-18 16:07:29 +00:00
( if org-bibtex-inherit-tags ( org-get-tags )
( org-get-tags nil t ) ) ) ) ) ) )
2012-08-15 07:56:35 +00:00
( when type
( let ( ( entry ( format
" @%s{%s, \n %s \n } \n " type id
( mapconcat
( lambda ( pair )
( format " %s={%s} " ( car pair ) ( cdr pair ) ) )
( remove nil
( if ( and org-bibtex-export-arbitrary-fields
org-bibtex-prefix )
2012-08-10 13:17:16 +00:00
( mapcar
2012-08-15 07:56:35 +00:00
( lambda ( kv )
( let ( ( key ( car kv ) ) ( val0 ( cdr kv ) ) )
( 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 ) )
val0 ) ) ) )
( org-entry-properties nil 'standard ) )
( mapcar
( lambda ( field )
( let ( ( value ( or ( org-bibtex-get ( funcall from field ) )
2016-09-25 15:29:06 +00:00
( and ( eq :title field )
2012-08-15 07:56:35 +00:00
( nth 4 ( org-heading-components ) ) ) ) ) )
( when value ( cons ( funcall from field ) value ) ) ) )
( funcall flatten
( funcall val :required ( funcall val ( funcall to type ) org-bibtex-types ) )
( funcall val :optional ( funcall val ( funcall to type ) org-bibtex-types ) ) ) ) ) )
" , \n " ) ) ) )
( with-temp-buffer
( insert entry )
( when tags
( bibtex-beginning-of-entry )
( if ( re-search-forward " keywords.*=.*{ \\ (.* \\ )} " nil t )
( progn ( goto-char ( match-end 1 ) ) ( insert " , " ) )
2014-04-20 08:14:03 +00:00
( search-forward " , \n " nil t )
( insert " keywords={}, \n " )
( search-backward " }, " nil t ) )
2012-08-15 07:56:35 +00:00
( insert ( mapconcat #' identity tags " , " ) ) )
( buffer-string ) ) ) ) ) )
2011-04-22 12:19:30 +00:00
( defun org-bibtex-ask ( field )
( unless ( assoc field org-bibtex-fields )
2012-08-13 03:59:44 +00:00
( error " Field:%s is not known " field ) )
2011-04-22 12:19:30 +00:00
( save-window-excursion
2011-04-23 13:53:41 +00:00
( let* ( ( name ( substring ( symbol-name field ) 1 ) )
( buf-name ( format " *Bibtex Help %s* " name ) ) )
( with-output-to-temp-buffer buf-name
( princ ( cdr ( assoc field org-bibtex-fields ) ) ) )
2013-02-14 20:22:10 +00:00
( with-current-buffer buf-name ( visual-line-mode 1 ) )
2011-04-23 13:53:41 +00:00
( org-fit-window-to-buffer ( get-buffer-window buf-name ) )
Backport changes from Emacs revs 115081 and 115082
2013-11-12 Stefan Monnier <monnier@iro.umontreal.ca>
Address some byte-compiler warnings.
* ob-abc.el (org-babel-expand-body:abc): Use dolist.
(org-babel-execute:abc): Fix regexp quoting.
* ob-calc.el (org--var-syms): Rename from `var-syms'.
* ob-lilypond.el (ly-compile-lilyfile): Remove redundant let-binding.
* ob-table.el (sbe): Move debug declaration.
* org-clock.el (org--msg-extra): Rename from `msg-extra'.
* org.el (org-version): Avoid var name starting with _.
(org-inhibit-startup, org-called-with-limited-levels)
(org-link-search-inhibit-query, org-time-was-given)
(org-end-time-was-given, org-def, org-defdecode, org-with-time):
* org-colview.el (org-agenda-overriding-columns-format):
* org-agenda.el (org-agenda-multi, org-depend-tag-blocked)
(org-agenda-show-log-scoped):
* ob-python.el (py-which-bufname, python-shell-buffer-name):
* ob-haskell.el (org-export-copy-to-kill-ring):
* ob-exp.el (org-link-search-inhibit-query):
* ob-R.el (ess-eval-visibly-p):
* ob-core.el (org-src-window-setup): Declare before use.
(org-babel-expand-noweb-references): Remove unused `blocks-in-buffer'.
* ox-odt.el (org-odt-hfy-face-to-css):
* org-src.el (org-src-associate-babel-session, org-src-get-lang-mode):
* org-bibtex.el (org-bibtex-get, org-bibtex-ask, org-bibtex)
(org-bibtex-check):
* ob-tangle.el (org-babel-tangle, org-babel-spec-to-string)
(org-babel-tangle-single-block, org-babel-tangle-comment-links):
* ob-table.el (sbe):
* ob-sqlite.el (org-babel-sqlite-expand-vars):
* ob-sql.el (org-babel-sql-expand-vars):
* ob-shen.el (org-babel-execute:shen):
* ob-sh.el (org-babel-execute:sh, org-babel-sh-evaluate):
* ob-scala.el (org-babel-scala-evaluate):
* ob-ruby.el (org-babel-ruby-table-or-string)
(org-babel-ruby-evaluate):
* ob-python.el (org-babel-python-table-or-string)
(org-babel-python-evaluate-external-process)
(org-babel-python-evaluate-session):
* ob-picolisp.el (org-babel-execute:picolisp):
* ob-perl.el (org-babel-perl-evaluate):
* ob-maxima.el (org-babel-execute:maxima):
* ob-lisp.el (org-babel-execute:lisp):
* ob-java.el (org-babel-execute:java):
* ob-io.el (org-babel-io-evaluate):
* ob-haskell.el (org-babel-execute:haskell):
* ob-fortran.el (org-babel-execute:fortran):
* ob-exp.el (org-babel-exp-code):
* ob-emacs-lisp.el (org-babel-execute:emacs-lisp):
* ob-ditaa.el (org-babel-execute:ditaa):
* ob-core.el (org-babel-execute-src-block, org-babel-sha1-hash)
(org-babel-parse-header-arguments, org-babel-reassemble-table)
(org-babel-goto-src-block-head, org-babel-mark-block)
(org-babel-expand-noweb-references, org-babel-script-escape)
(org-babel-process-file-name):
* ob-clojure.el (org-babel-execute:clojure):
* ob-calc.el (org-babel-execute:calc):
* ob-awk.el (org-babel-execute:awk):
* ob-abc.el (org-babel-execute:abc):
* ob-R.el (org-babel-expand-body:R):
* ob-C.el (org-babel-C-execute): Avoid deprecated ((lambda) ...).
2013-11-12 Glenn Morris <rgm@gnu.org>
* ox-html.el (org-html-scripts): Add 2013 to copyright years.
(org-html-infojs-template): Copyright holder to FSF.
2013-11-12 19:57:31 +00:00
( let ( ( result ( read-from-minibuffer ( format " %s: " name ) ) ) )
( when ( > ( length result ) 0 ) result ) ) ) ) )
2011-04-22 12:19:30 +00:00
( defun org-bibtex-autokey ( )
2012-07-30 08:08:15 +00:00
" Generate an autokey for the current headline. "
2011-04-27 21:31:30 +00:00
( org-bibtex-put org-bibtex-key-property
2011-04-22 12:19:30 +00:00
( if org-bibtex-autogen-keys
2011-05-01 20:55:29 +00:00
( let* ( ( entry ( org-bibtex-headline ) )
2011-05-01 21:01:59 +00:00
( key
2011-05-01 20:55:29 +00:00
( with-temp-buffer
( insert entry )
( bibtex-generate-autokey ) ) ) )
;; test for duplicate IDs if using global ID
( when ( and
( equal org-bibtex-key-property " ID " )
( featurep 'org-id )
( hash-table-p org-id-locations )
( gethash key org-id-locations ) )
( warn " Another entry has the same ID " ) )
key )
2011-04-22 12:19:30 +00:00
( read-from-minibuffer " id: " ) ) ) )
( defun org-bibtex-fleshout ( type &optional optional )
2012-08-10 13:17:16 +00:00
" Fleshout current heading, ensuring all required fields are present.
2011-04-22 12:19:30 +00:00
With optional argument OPTIONAL, also prompt for optional fields. "
2012-08-10 13:17:16 +00:00
( let ( ( val ( lambda ( key lst ) ( cdr ( assoc key lst ) ) ) )
( keyword ( lambda ( name ) ( intern ( concat " : " ( downcase name ) ) ) ) )
( name ( lambda ( keyword ) ( substring ( symbol-name keyword ) 1 ) ) ) )
2011-04-22 12:19:30 +00:00
( dolist ( field ( append
2011-04-30 18:03:37 +00:00
( if org-bibtex-treat-headline-as-title
2012-08-10 13:17:16 +00:00
( remove :title ( funcall val :required ( funcall val type org-bibtex-types ) ) )
( funcall val :required ( funcall val type org-bibtex-types ) ) )
( when optional ( funcall val :optional ( funcall val type org-bibtex-types ) ) ) ) )
2011-04-22 12:19:30 +00:00
( when ( consp field ) ; or'd pair of fields e.g., (:editor :author)
2016-07-25 14:34:48 +00:00
( let ( ( present ( nth 0 ( remove
2012-08-10 13:17:16 +00:00
nil
( mapcar
2016-07-25 14:34:48 +00:00
( lambda ( f )
( when ( org-bibtex-get ( funcall name f ) ) f ) )
2012-08-10 13:17:16 +00:00
field ) ) ) ) )
( setf field ( or present ( funcall keyword
2015-12-22 13:49:23 +00:00
( completing-read
2012-08-10 13:17:16 +00:00
" Field: " ( mapcar name field ) ) ) ) ) ) )
( let ( ( name ( funcall name field ) ) )
2011-04-22 12:19:30 +00:00
( unless ( org-bibtex-get name )
( let ( ( prop ( org-bibtex-ask field ) ) )
( when prop ( org-bibtex-put name prop ) ) ) ) ) ) )
( when ( and type ( assoc type org-bibtex-types )
2011-04-27 21:31:30 +00:00
( not ( org-bibtex-get org-bibtex-key-property ) ) )
2011-04-22 12:19:30 +00:00
( org-bibtex-autokey ) ) )
;;; Bibtex link functions
2016-07-05 14:26:04 +00:00
( org-link-set-parameters " bibtex "
:follow #' org-bibtex-open
:store #' org-bibtex-store-link )
2008-01-31 15:04:26 +00:00
2020-02-17 10:28:50 +00:00
( defun org-bibtex-open ( path arg )
" Visit the bibliography entry on PATH.
ARG, when non-nil, is a universal prefix argument. See
` org-open-file ' for details. "
( org-link-open-as-file path arg ) )
2008-01-31 15:04:26 +00:00
( defun org-bibtex-store-link ( )
" Store a link to a BibTeX entry. "
( when ( eq major-mode 'bibtex-mode )
2008-04-03 11:21:45 +00:00
( let* ( ( search ( org-create-file-search-in-bibtex ) )
2008-01-31 15:04:26 +00:00
( link ( concat " file: " ( abbreviate-file-name buffer-file-name )
" :: " search ) )
( entry ( mapcar ; repair strings enclosed in "..." or {...}
( 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 ) ) ) ) )
2018-11-26 23:04:41 +00:00
( org-link-store-props
2008-01-31 15:04:26 +00:00
:key ( cdr ( assoc " =key= " entry ) )
:author ( or ( cdr ( assoc " author " entry ) ) " [no author] " )
2021-06-28 12:35:34 +00:00
:doi ( or ( cdr ( assoc " doi " entry ) ) " [no doi] " )
2008-01-31 15:04:26 +00:00
: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
2012-03-30 19:48:58 +00:00
:description org-bibtex-description ) ) ) )
2008-01-31 15:04:26 +00:00
2008-04-03 11:21:45 +00:00
( defun org-create-file-search-in-bibtex ( )
" Create the search string and description for a BibTeX database entry. "
;; Make a good description for this entry, using names, year and the title
;; Put it into the `description' variable which is dynamically scoped.
( 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 " : " ) )
2012-03-30 19:48:58 +00:00
( setq org-bibtex-description ( bibtex-generate-autokey ) ) )
2008-04-03 11:21:45 +00:00
;; Now parse the entry, get the key and return it.
( save-excursion
( bibtex-beginning-of-entry )
( cdr ( assoc " =key= " ( bibtex-parse-entry ) ) ) ) )
2008-01-31 15:04:26 +00:00
2008-04-03 11:21:45 +00:00
( 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 )
;; Yes, we want to do the search in this file.
;; We construct a regexp that searches for "@entrytype{" followed by the key
( goto-char ( point-min ) )
( and ( re-search-forward ( concat " @[a-zA-Z]+[ \t \n ]*{[ \t \n ]* "
2020-02-18 21:57:37 +00:00
( regexp-quote s ) " [ \t \n ]*, " )
nil t )
2008-04-03 11:21:45 +00:00
( goto-char ( match-beginning 0 ) ) )
( if ( and ( match-beginning 0 ) ( equal current-prefix-arg ' ( 16 ) ) )
;; Use double prefix to indicate that any web link should be browsed
( let ( ( b ( current-buffer ) ) ( p ( point ) ) )
;; Restore the window configuration because we just use the web link
( set-window-configuration org-window-config-before-follow-link )
2009-11-05 21:51:50 +00:00
( with-current-buffer b
( goto-char p )
2008-04-03 11:21:45 +00:00
( bibtex-url ) ) )
( recenter 0 ) ) ; Move entry start to beginning of window
2011-04-24 00:26:22 +00:00
;; return t to indicate that the search is done.
2008-04-03 11:21:45 +00:00
t ) )
;; Finally add the link search function to the right hook.
( add-hook 'org-execute-file-search-functions 'org-execute-file-search-in-bibtex )
2008-01-31 15:04:26 +00:00
2011-04-22 12:19:30 +00:00
2016-08-23 20:13:56 +00:00
;;; Bibtex <-> Org headline translation functions
2016-01-13 05:16:07 +00:00
( defun org-bibtex ( filename )
2011-04-22 12:19:30 +00:00
" Export each headline in the current file to a bibtex entry.
2014-04-19 14:22:15 +00:00
Headlines are exported using ` org-bibtex-headline '. "
2011-04-28 16:02:33 +00:00
( interactive
( list ( read-file-name
" Bibtex file: " nil nil nil
2016-01-13 05:18:42 +00:00
( let ( ( file ( buffer-file-name ( buffer-base-buffer ) ) ) )
( and file
( file-name-nondirectory
( concat ( file-name-sans-extension file ) " .bib " ) ) ) ) ) ) )
Backport changes from Emacs revs 115081 and 115082
2013-11-12 Stefan Monnier <monnier@iro.umontreal.ca>
Address some byte-compiler warnings.
* ob-abc.el (org-babel-expand-body:abc): Use dolist.
(org-babel-execute:abc): Fix regexp quoting.
* ob-calc.el (org--var-syms): Rename from `var-syms'.
* ob-lilypond.el (ly-compile-lilyfile): Remove redundant let-binding.
* ob-table.el (sbe): Move debug declaration.
* org-clock.el (org--msg-extra): Rename from `msg-extra'.
* org.el (org-version): Avoid var name starting with _.
(org-inhibit-startup, org-called-with-limited-levels)
(org-link-search-inhibit-query, org-time-was-given)
(org-end-time-was-given, org-def, org-defdecode, org-with-time):
* org-colview.el (org-agenda-overriding-columns-format):
* org-agenda.el (org-agenda-multi, org-depend-tag-blocked)
(org-agenda-show-log-scoped):
* ob-python.el (py-which-bufname, python-shell-buffer-name):
* ob-haskell.el (org-export-copy-to-kill-ring):
* ob-exp.el (org-link-search-inhibit-query):
* ob-R.el (ess-eval-visibly-p):
* ob-core.el (org-src-window-setup): Declare before use.
(org-babel-expand-noweb-references): Remove unused `blocks-in-buffer'.
* ox-odt.el (org-odt-hfy-face-to-css):
* org-src.el (org-src-associate-babel-session, org-src-get-lang-mode):
* org-bibtex.el (org-bibtex-get, org-bibtex-ask, org-bibtex)
(org-bibtex-check):
* ob-tangle.el (org-babel-tangle, org-babel-spec-to-string)
(org-babel-tangle-single-block, org-babel-tangle-comment-links):
* ob-table.el (sbe):
* ob-sqlite.el (org-babel-sqlite-expand-vars):
* ob-sql.el (org-babel-sql-expand-vars):
* ob-shen.el (org-babel-execute:shen):
* ob-sh.el (org-babel-execute:sh, org-babel-sh-evaluate):
* ob-scala.el (org-babel-scala-evaluate):
* ob-ruby.el (org-babel-ruby-table-or-string)
(org-babel-ruby-evaluate):
* ob-python.el (org-babel-python-table-or-string)
(org-babel-python-evaluate-external-process)
(org-babel-python-evaluate-session):
* ob-picolisp.el (org-babel-execute:picolisp):
* ob-perl.el (org-babel-perl-evaluate):
* ob-maxima.el (org-babel-execute:maxima):
* ob-lisp.el (org-babel-execute:lisp):
* ob-java.el (org-babel-execute:java):
* ob-io.el (org-babel-io-evaluate):
* ob-haskell.el (org-babel-execute:haskell):
* ob-fortran.el (org-babel-execute:fortran):
* ob-exp.el (org-babel-exp-code):
* ob-emacs-lisp.el (org-babel-execute:emacs-lisp):
* ob-ditaa.el (org-babel-execute:ditaa):
* ob-core.el (org-babel-execute-src-block, org-babel-sha1-hash)
(org-babel-parse-header-arguments, org-babel-reassemble-table)
(org-babel-goto-src-block-head, org-babel-mark-block)
(org-babel-expand-noweb-references, org-babel-script-escape)
(org-babel-process-file-name):
* ob-clojure.el (org-babel-execute:clojure):
* ob-calc.el (org-babel-execute:calc):
* ob-awk.el (org-babel-execute:awk):
* ob-abc.el (org-babel-execute:abc):
* ob-R.el (org-babel-expand-body:R):
* ob-C.el (org-babel-C-execute): Avoid deprecated ((lambda) ...).
2013-11-12 Glenn Morris <rgm@gnu.org>
* ox-html.el (org-html-scripts): Add 2013 to copyright years.
(org-html-infojs-template): Copyright holder to FSF.
2013-11-12 19:57:31 +00:00
( let ( ( error-point
( catch 'bib
( let ( ( bibtex-entries
( remove nil ( org-map-entries
( lambda ( )
2015-12-20 21:48:05 +00:00
( condition-case nil
Backport changes from Emacs revs 115081 and 115082
2013-11-12 Stefan Monnier <monnier@iro.umontreal.ca>
Address some byte-compiler warnings.
* ob-abc.el (org-babel-expand-body:abc): Use dolist.
(org-babel-execute:abc): Fix regexp quoting.
* ob-calc.el (org--var-syms): Rename from `var-syms'.
* ob-lilypond.el (ly-compile-lilyfile): Remove redundant let-binding.
* ob-table.el (sbe): Move debug declaration.
* org-clock.el (org--msg-extra): Rename from `msg-extra'.
* org.el (org-version): Avoid var name starting with _.
(org-inhibit-startup, org-called-with-limited-levels)
(org-link-search-inhibit-query, org-time-was-given)
(org-end-time-was-given, org-def, org-defdecode, org-with-time):
* org-colview.el (org-agenda-overriding-columns-format):
* org-agenda.el (org-agenda-multi, org-depend-tag-blocked)
(org-agenda-show-log-scoped):
* ob-python.el (py-which-bufname, python-shell-buffer-name):
* ob-haskell.el (org-export-copy-to-kill-ring):
* ob-exp.el (org-link-search-inhibit-query):
* ob-R.el (ess-eval-visibly-p):
* ob-core.el (org-src-window-setup): Declare before use.
(org-babel-expand-noweb-references): Remove unused `blocks-in-buffer'.
* ox-odt.el (org-odt-hfy-face-to-css):
* org-src.el (org-src-associate-babel-session, org-src-get-lang-mode):
* org-bibtex.el (org-bibtex-get, org-bibtex-ask, org-bibtex)
(org-bibtex-check):
* ob-tangle.el (org-babel-tangle, org-babel-spec-to-string)
(org-babel-tangle-single-block, org-babel-tangle-comment-links):
* ob-table.el (sbe):
* ob-sqlite.el (org-babel-sqlite-expand-vars):
* ob-sql.el (org-babel-sql-expand-vars):
* ob-shen.el (org-babel-execute:shen):
* ob-sh.el (org-babel-execute:sh, org-babel-sh-evaluate):
* ob-scala.el (org-babel-scala-evaluate):
* ob-ruby.el (org-babel-ruby-table-or-string)
(org-babel-ruby-evaluate):
* ob-python.el (org-babel-python-table-or-string)
(org-babel-python-evaluate-external-process)
(org-babel-python-evaluate-session):
* ob-picolisp.el (org-babel-execute:picolisp):
* ob-perl.el (org-babel-perl-evaluate):
* ob-maxima.el (org-babel-execute:maxima):
* ob-lisp.el (org-babel-execute:lisp):
* ob-java.el (org-babel-execute:java):
* ob-io.el (org-babel-io-evaluate):
* ob-haskell.el (org-babel-execute:haskell):
* ob-fortran.el (org-babel-execute:fortran):
* ob-exp.el (org-babel-exp-code):
* ob-emacs-lisp.el (org-babel-execute:emacs-lisp):
* ob-ditaa.el (org-babel-execute:ditaa):
* ob-core.el (org-babel-execute-src-block, org-babel-sha1-hash)
(org-babel-parse-header-arguments, org-babel-reassemble-table)
(org-babel-goto-src-block-head, org-babel-mark-block)
(org-babel-expand-noweb-references, org-babel-script-escape)
(org-babel-process-file-name):
* ob-clojure.el (org-babel-execute:clojure):
* ob-calc.el (org-babel-execute:calc):
* ob-awk.el (org-babel-execute:awk):
* ob-abc.el (org-babel-execute:abc):
* ob-R.el (org-babel-expand-body:R):
* ob-C.el (org-babel-C-execute): Avoid deprecated ((lambda) ...).
2013-11-12 Glenn Morris <rgm@gnu.org>
* ox-html.el (org-html-scripts): Add 2013 to copyright years.
(org-html-infojs-template): Copyright holder to FSF.
2013-11-12 19:57:31 +00:00
( 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 "
2020-02-18 21:57:37 +00:00
( length bibtex-entries ) filename )
nil ) ) ) )
Backport changes from Emacs revs 115081 and 115082
2013-11-12 Stefan Monnier <monnier@iro.umontreal.ca>
Address some byte-compiler warnings.
* ob-abc.el (org-babel-expand-body:abc): Use dolist.
(org-babel-execute:abc): Fix regexp quoting.
* ob-calc.el (org--var-syms): Rename from `var-syms'.
* ob-lilypond.el (ly-compile-lilyfile): Remove redundant let-binding.
* ob-table.el (sbe): Move debug declaration.
* org-clock.el (org--msg-extra): Rename from `msg-extra'.
* org.el (org-version): Avoid var name starting with _.
(org-inhibit-startup, org-called-with-limited-levels)
(org-link-search-inhibit-query, org-time-was-given)
(org-end-time-was-given, org-def, org-defdecode, org-with-time):
* org-colview.el (org-agenda-overriding-columns-format):
* org-agenda.el (org-agenda-multi, org-depend-tag-blocked)
(org-agenda-show-log-scoped):
* ob-python.el (py-which-bufname, python-shell-buffer-name):
* ob-haskell.el (org-export-copy-to-kill-ring):
* ob-exp.el (org-link-search-inhibit-query):
* ob-R.el (ess-eval-visibly-p):
* ob-core.el (org-src-window-setup): Declare before use.
(org-babel-expand-noweb-references): Remove unused `blocks-in-buffer'.
* ox-odt.el (org-odt-hfy-face-to-css):
* org-src.el (org-src-associate-babel-session, org-src-get-lang-mode):
* org-bibtex.el (org-bibtex-get, org-bibtex-ask, org-bibtex)
(org-bibtex-check):
* ob-tangle.el (org-babel-tangle, org-babel-spec-to-string)
(org-babel-tangle-single-block, org-babel-tangle-comment-links):
* ob-table.el (sbe):
* ob-sqlite.el (org-babel-sqlite-expand-vars):
* ob-sql.el (org-babel-sql-expand-vars):
* ob-shen.el (org-babel-execute:shen):
* ob-sh.el (org-babel-execute:sh, org-babel-sh-evaluate):
* ob-scala.el (org-babel-scala-evaluate):
* ob-ruby.el (org-babel-ruby-table-or-string)
(org-babel-ruby-evaluate):
* ob-python.el (org-babel-python-table-or-string)
(org-babel-python-evaluate-external-process)
(org-babel-python-evaluate-session):
* ob-picolisp.el (org-babel-execute:picolisp):
* ob-perl.el (org-babel-perl-evaluate):
* ob-maxima.el (org-babel-execute:maxima):
* ob-lisp.el (org-babel-execute:lisp):
* ob-java.el (org-babel-execute:java):
* ob-io.el (org-babel-io-evaluate):
* ob-haskell.el (org-babel-execute:haskell):
* ob-fortran.el (org-babel-execute:fortran):
* ob-exp.el (org-babel-exp-code):
* ob-emacs-lisp.el (org-babel-execute:emacs-lisp):
* ob-ditaa.el (org-babel-execute:ditaa):
* ob-core.el (org-babel-execute-src-block, org-babel-sha1-hash)
(org-babel-parse-header-arguments, org-babel-reassemble-table)
(org-babel-goto-src-block-head, org-babel-mark-block)
(org-babel-expand-noweb-references, org-babel-script-escape)
(org-babel-process-file-name):
* ob-clojure.el (org-babel-execute:clojure):
* ob-calc.el (org-babel-execute:calc):
* ob-awk.el (org-babel-execute:awk):
* ob-abc.el (org-babel-execute:abc):
* ob-R.el (org-babel-expand-body:R):
* ob-C.el (org-babel-C-execute): Avoid deprecated ((lambda) ...).
2013-11-12 Glenn Morris <rgm@gnu.org>
* ox-html.el (org-html-scripts): Add 2013 to copyright years.
(org-html-infojs-template): Copyright holder to FSF.
2013-11-12 19:57:31 +00:00
( when error-point
( goto-char error-point )
( message " Bibtex error at %S " ( nth 4 ( org-heading-components ) ) ) ) ) )
2011-04-22 12:19:30 +00:00
( defun org-bibtex-check ( &optional optional )
" Check the current headline for required fields.
With prefix argument OPTIONAL also prompt for optional fields. "
( interactive " P " )
( save-restriction
( org-narrow-to-subtree )
Backport changes from Emacs revs 115081 and 115082
2013-11-12 Stefan Monnier <monnier@iro.umontreal.ca>
Address some byte-compiler warnings.
* ob-abc.el (org-babel-expand-body:abc): Use dolist.
(org-babel-execute:abc): Fix regexp quoting.
* ob-calc.el (org--var-syms): Rename from `var-syms'.
* ob-lilypond.el (ly-compile-lilyfile): Remove redundant let-binding.
* ob-table.el (sbe): Move debug declaration.
* org-clock.el (org--msg-extra): Rename from `msg-extra'.
* org.el (org-version): Avoid var name starting with _.
(org-inhibit-startup, org-called-with-limited-levels)
(org-link-search-inhibit-query, org-time-was-given)
(org-end-time-was-given, org-def, org-defdecode, org-with-time):
* org-colview.el (org-agenda-overriding-columns-format):
* org-agenda.el (org-agenda-multi, org-depend-tag-blocked)
(org-agenda-show-log-scoped):
* ob-python.el (py-which-bufname, python-shell-buffer-name):
* ob-haskell.el (org-export-copy-to-kill-ring):
* ob-exp.el (org-link-search-inhibit-query):
* ob-R.el (ess-eval-visibly-p):
* ob-core.el (org-src-window-setup): Declare before use.
(org-babel-expand-noweb-references): Remove unused `blocks-in-buffer'.
* ox-odt.el (org-odt-hfy-face-to-css):
* org-src.el (org-src-associate-babel-session, org-src-get-lang-mode):
* org-bibtex.el (org-bibtex-get, org-bibtex-ask, org-bibtex)
(org-bibtex-check):
* ob-tangle.el (org-babel-tangle, org-babel-spec-to-string)
(org-babel-tangle-single-block, org-babel-tangle-comment-links):
* ob-table.el (sbe):
* ob-sqlite.el (org-babel-sqlite-expand-vars):
* ob-sql.el (org-babel-sql-expand-vars):
* ob-shen.el (org-babel-execute:shen):
* ob-sh.el (org-babel-execute:sh, org-babel-sh-evaluate):
* ob-scala.el (org-babel-scala-evaluate):
* ob-ruby.el (org-babel-ruby-table-or-string)
(org-babel-ruby-evaluate):
* ob-python.el (org-babel-python-table-or-string)
(org-babel-python-evaluate-external-process)
(org-babel-python-evaluate-session):
* ob-picolisp.el (org-babel-execute:picolisp):
* ob-perl.el (org-babel-perl-evaluate):
* ob-maxima.el (org-babel-execute:maxima):
* ob-lisp.el (org-babel-execute:lisp):
* ob-java.el (org-babel-execute:java):
* ob-io.el (org-babel-io-evaluate):
* ob-haskell.el (org-babel-execute:haskell):
* ob-fortran.el (org-babel-execute:fortran):
* ob-exp.el (org-babel-exp-code):
* ob-emacs-lisp.el (org-babel-execute:emacs-lisp):
* ob-ditaa.el (org-babel-execute:ditaa):
* ob-core.el (org-babel-execute-src-block, org-babel-sha1-hash)
(org-babel-parse-header-arguments, org-babel-reassemble-table)
(org-babel-goto-src-block-head, org-babel-mark-block)
(org-babel-expand-noweb-references, org-babel-script-escape)
(org-babel-process-file-name):
* ob-clojure.el (org-babel-execute:clojure):
* ob-calc.el (org-babel-execute:calc):
* ob-awk.el (org-babel-execute:awk):
* ob-abc.el (org-babel-execute:abc):
* ob-R.el (org-babel-expand-body:R):
* ob-C.el (org-babel-C-execute): Avoid deprecated ((lambda) ...).
2013-11-12 Glenn Morris <rgm@gnu.org>
* ox-html.el (org-html-scripts): Add 2013 to copyright years.
(org-html-infojs-template): Copyright holder to FSF.
2013-11-12 19:57:31 +00:00
( let ( ( type ( let ( ( name ( org-bibtex-get org-bibtex-type-property-name ) ) )
( when name ( intern ( concat " : " name ) ) ) ) ) )
2011-04-22 12:19:30 +00:00
( when type ( org-bibtex-fleshout type optional ) ) ) ) )
( defun org-bibtex-check-all ( &optional optional )
" Check all headlines in the current file.
With prefix argument OPTIONAL also prompt for optional fields. "
( interactive ) ( org-map-entries ( lambda ( ) ( org-bibtex-check optional ) ) ) )
2011-05-01 21:01:59 +00:00
( defun org-bibtex-create ( &optional arg nonew )
" Create a new entry at the given level.
With a prefix arg, query for optional fields as well.
If nonew is t , add data to the headline of the entry at point. "
2011-04-28 15:46:35 +00:00
( interactive " P " )
2015-12-22 13:49:23 +00:00
( let* ( ( type ( completing-read
2011-05-01 21:01:59 +00:00
" Type: " ( mapcar ( lambda ( type )
( substring ( symbol-name ( car type ) ) 1 ) )
org-bibtex-types )
2011-09-20 15:20:53 +00:00
nil nil ( when nonew
( org-bibtex-get org-bibtex-type-property-name ) ) ) )
2011-05-01 21:01:59 +00:00
( type ( if ( keywordp type ) type ( intern ( concat " : " type ) ) ) )
( org-bibtex-treat-headline-as-title ( if nonew nil t ) ) )
2011-04-22 12:19:30 +00:00
( unless ( assoc type org-bibtex-types )
2012-08-13 03:59:44 +00:00
( error " Type:%s is not known " type ) )
2011-05-01 21:01:59 +00:00
( if nonew
( org-back-to-heading )
( org-insert-heading )
( let ( ( title ( org-bibtex-ask :title ) ) )
( insert title )
( org-bibtex-put " TITLE " title ) ) )
2011-09-20 15:20:53 +00:00
( org-bibtex-put org-bibtex-type-property-name
( substring ( symbol-name type ) 1 ) )
2011-05-01 20:54:01 +00:00
( org-bibtex-fleshout type arg )
2015-12-20 21:48:05 +00:00
( dolist ( tag org-bibtex-tags ) ( org-toggle-tag tag 'on ) ) ) )
2011-04-22 12:19:30 +00:00
2011-05-01 21:01:59 +00:00
( defun org-bibtex-create-in-current-entry ( &optional arg )
" Add bibliographical data to the current entry.
With a prefix arg, query for optional fields. "
( interactive " P " )
( org-bibtex-create arg t ) )
2011-04-22 12:19:30 +00:00
( defun org-bibtex-read ( )
2012-05-21 16:30:09 +00:00
" Read a bibtex entry and save to `org-bibtex-entries' .
2022-02-05 11:06:45 +00:00
This uses ` bibtex-parse-entry '.
Return the new value of ` org-bibtex-entries '. "
2011-04-22 12:19:30 +00:00
( interactive )
2012-08-10 13:17:16 +00:00
( let ( ( keyword ( lambda ( str ) ( intern ( concat " : " ( downcase str ) ) ) ) )
( clean-space ( lambda ( str ) ( replace-regexp-in-string
2021-09-29 07:22:47 +00:00
" [[:space:] \n \r ]+ " " " str ) ) )
2012-08-10 13:17:16 +00:00
( strip-delim
2016-07-25 14:34:48 +00:00
( lambda ( str ) ; strip enclosing "..." and {...}
2016-04-20 20:59:55 +00:00
( dolist ( pair ' ( ( 34 . 34 ) ( 123 . 125 ) ) )
2014-02-21 16:19:39 +00:00
( when ( and ( > ( length str ) 1 )
( = ( aref str 0 ) ( car pair ) )
2012-08-10 13:17:16 +00:00
( = ( aref str ( 1- ( length str ) ) ) ( cdr pair ) ) )
2020-02-18 21:57:37 +00:00
( setf str ( substring str 1 ( 1- ( length str ) ) ) ) ) )
str ) ) )
2011-04-22 12:19:30 +00:00
( push ( mapcar
( lambda ( pair )
2012-08-10 13:17:16 +00:00
( cons ( let ( ( field ( funcall keyword ( car pair ) ) ) )
2016-07-25 14:34:48 +00:00
( pcase field
2011-04-22 12:19:30 +00:00
( :=type= :type )
( :=key= :key )
2016-07-25 14:34:48 +00:00
( _ field ) ) )
2012-08-10 13:17:16 +00:00
( funcall clean-space ( funcall strip-delim ( cdr pair ) ) ) ) )
2011-04-22 12:19:30 +00:00
( save-excursion ( bibtex-beginning-of-entry ) ( bibtex-parse-entry ) ) )
2021-08-28 13:23:43 +00:00
org-bibtex-entries )
2022-02-05 11:06:45 +00:00
( unless ( car org-bibtex-entries ) ( pop org-bibtex-entries ) )
org-bibtex-entries ) )
2011-04-22 12:19:30 +00:00
2012-12-26 15:39:53 +00:00
( defun org-bibtex-read-buffer ( buffer )
" Read all bibtex entries in BUFFER and save to `org-bibtex-entries' .
Return the number of saved entries. "
2014-03-19 11:01:57 +00:00
( interactive " bBuffer: " )
2012-12-26 15:39:53 +00:00
( let ( ( start-length ( length org-bibtex-entries ) ) )
( with-current-buffer buffer
( save-excursion
( goto-char ( point-max ) )
( while ( not ( = ( point ) ( point-min ) ) )
( backward-char 1 )
( org-bibtex-read )
( bibtex-beginning-of-entry ) ) ) )
( let ( ( added ( - ( length org-bibtex-entries ) start-length ) ) )
2014-03-19 11:01:57 +00:00
( message " Parsed %d entries " added )
2012-12-26 15:39:53 +00:00
added ) ) )
( defun org-bibtex-read-file ( file )
" Read FILE with `org-bibtex-read-buffer' . "
2014-03-19 11:01:57 +00:00
( interactive " fFile: " )
2012-12-26 15:39:53 +00:00
( org-bibtex-read-buffer ( find-file-noselect file 'nowarn 'rawfile ) ) )
2022-08-27 04:09:31 +00:00
( defun org-bibtex-write ( &optional noindent )
" Insert a heading built from the first element of `org-bibtex-entries' .
When optional argument NOINDENT is non-nil, do not indent the properties
drawer. "
2011-04-22 12:19:30 +00:00
( interactive )
2022-08-27 04:09:31 +00:00
( unless org-bibtex-entries
2012-09-28 15:47:48 +00:00
( error " No entries in `org-bibtex-entries' " ) )
2012-08-10 13:32:24 +00:00
( let* ( ( entry ( pop org-bibtex-entries ) )
( org-special-properties nil ) ; avoids errors with `org-entry-put'
( val ( lambda ( field ) ( cdr ( assoc field entry ) ) ) )
( togtag ( lambda ( tag ) ( org-toggle-tag tag 'on ) ) ) )
2012-08-10 13:17:16 +00:00
( org-insert-heading )
2016-12-09 20:44:06 +00:00
( insert ( funcall org-bibtex-headline-format-function entry ) )
2022-08-27 04:09:31 +00:00
( insert " \n :PROPERTIES: \n " )
( org-bibtex-put " TITLE " ( funcall val :title ) 'insert )
2012-08-10 13:17:16 +00:00
( org-bibtex-put org-bibtex-type-property-name
2022-08-27 04:09:31 +00:00
( downcase ( funcall val :type ) )
'insert )
2012-08-10 13:17:16 +00:00
( dolist ( pair entry )
2016-07-25 14:34:48 +00:00
( pcase ( car pair )
2012-08-10 13:17:16 +00:00
( :title nil )
( :type nil )
2022-08-27 04:09:31 +00:00
( :key ( org-bibtex-put org-bibtex-key-property ( cdr pair ) 'insert ) )
2012-08-10 13:17:16 +00:00
( :keywords ( if org-bibtex-tags-are-keywords
2015-12-20 21:48:05 +00:00
( dolist ( kw ( split-string ( cdr pair ) " , * " ) )
( funcall
togtag
( replace-regexp-in-string
" [^[:alnum:]_@#%] " " "
( replace-regexp-in-string " [ \t ]+ " " _ " kw ) ) ) )
2022-08-27 04:09:31 +00:00
( org-bibtex-put ( car pair ) ( cdr pair ) 'insert ) ) )
( _ ( org-bibtex-put ( car pair ) ( cdr pair ) 'insert ) ) ) )
( insert " :END: \n " )
( mapc togtag org-bibtex-tags )
( unless noindent
( org-indent-region
( save-excursion ( org-back-to-heading t ) ( point ) )
( point ) ) ) ) )
2011-04-22 12:19:30 +00:00
2011-04-24 00:26:22 +00:00
( defun org-bibtex-yank ( )
2016-08-23 20:13:56 +00:00
" If kill ring holds a bibtex entry yank it as an Org headline. "
2011-04-24 00:26:22 +00:00
( interactive )
( let ( entry )
( with-temp-buffer ( yank 1 ) ( setf entry ( org-bibtex-read ) ) )
( if entry
( org-bibtex-write )
2012-08-13 03:59:44 +00:00
( error " Yanked text does not appear to contain a BibTeX entry " ) ) ) )
2011-04-24 00:26:22 +00:00
2012-12-26 15:39:53 +00:00
( defun org-bibtex-import-from-file ( file )
2016-08-23 20:13:56 +00:00
" Read bibtex entries from FILE and insert as Org headlines after point. "
2014-03-19 11:01:57 +00:00
( interactive " fFile: " )
2022-08-27 04:09:31 +00:00
( let ( ( pos ( point ) ) )
( dotimes ( i ( org-bibtex-read-file file ) )
( save-excursion ( org-bibtex-write 'noindent ) )
( re-search-forward org-property-end-re )
( insert " \n " ) )
( org-indent-region pos ( point ) ) ) )
2012-12-26 15:39:53 +00:00
2011-05-01 21:01:59 +00:00
( defun org-bibtex-export-to-kill-ring ( )
" Export current headline to kill ring as bibtex entry. "
( interactive )
2012-04-26 16:51:36 +00:00
( let ( ( result ( org-bibtex-headline ) ) )
( kill-new result ) result ) )
2011-05-01 21:01:59 +00:00
( defun org-bibtex-search ( string )
" Search for bibliographical entries in agenda files.
This function relies ` org-search-view ' to locate results. "
( interactive " sSearch string: " )
( let ( ( org-agenda-overriding-header " Bib search results: " )
( org-agenda-search-view-always-boolean t ) )
( org-search-view nil
2011-09-20 15:20:53 +00:00
( format " %s +{:%s%s:} "
2013-01-30 10:42:17 +00:00
string ( or org-bibtex-prefix " " )
2011-09-20 15:20:53 +00:00
org-bibtex-type-property-name ) ) ) )
2011-05-01 21:01:59 +00:00
2019-03-02 00:01:32 +00:00
( provide 'ol-bibtex )
2008-01-31 15:04:26 +00:00
2019-03-02 00:01:32 +00:00
;;; ol-bibtex.el ends here