From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: [ANN] org-bibtex.el --- convert between Org headings and bibtex entries Date: Wed, 27 Apr 2011 16:16:37 -0600 Message-ID: <87sjt3p2ne.fsf@gmail.com> References: <87y6357q81.fsf@gmail.com> <027A8D96-05AB-452C-87D3-85D90D24AFB1@tsdye.com> <87vcy81xtv.fsf@gmail.com> <877hanwbyb.fsf@gmail.com> <89A178C3-C2E4-493D-BE84-12200512B766@tsdye.com> <87ei4sa3cz.fsf@fastmail.fm> <871v0rzp8v.fsf@gmail.com> <87oc3uweec.fsf@fastmail.fm> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([140.186.70.92]:48997) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QFGL3-0004g3-US for emacs-orgmode@gnu.org; Wed, 27 Apr 2011 21:48:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QFGL2-0004G0-6r for emacs-orgmode@gnu.org; Wed, 27 Apr 2011 21:48:17 -0400 Received: from mail-pz0-f41.google.com ([209.85.210.41]:62865) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QFGL1-0004Fr-OC for emacs-orgmode@gnu.org; Wed, 27 Apr 2011 21:48:16 -0400 Received: by pzk4 with SMTP id 4so1955465pzk.0 for ; Wed, 27 Apr 2011 18:48:13 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Matt Lundin Cc: Org Mode Hi Matt, Matt Lundin writes: > Hi Eric, > > "Eric Schulte" writes: > >> Matt Lundin writes: >> >> [...] >>>> I understand I may add to the types variable.=C2=A0 When using >>>> org-bibtex-create, I can enter any arbitrary field as a PROPERTY; >>>> however, org-bibtex ignores anything outside of the universe it knows >>>> about.=C2=A0 Would it be bad practice to allow the export of any arbit= rary >>>> field type one has recorded?=C2=A0 I think the emacs bibtex-mode may >>>> recognize erroneous bibtex entries.=C2=A0=C2=A0=20 >>> >>> Bibtex-mode does indeed allow for arbitrary fields, as do bibtex and >>> biblatex. AFAIK, they are simply ignored when processing a bib file. One >>> limitation that arises when storing bibtex data as org properties is >>> that properties drawers are used for much more. For instance, one would >>> probably not want to see "logging =3D {lognoterepeat}," in one's export= ed >>> bibtex file. >>> >>> But for biblatex users, it would indeed be prohibitively expensive to >>> have to inform org-mode ahead of time about the innumerable odd fields >>> that various biblatex backends define. >> >> There is already an option for an org-bibtex specific property name >> prefix, (namely `org-bibtex-prefix'). Perhaps when this prefix is used, >> and the `org-bibtex' functions is called with a prefix argument (note: >> entirely different usage of the term "prefix") then only entries which >> begin with the `org-bibtex-prefix' would be exported... I believe that >> should provide a natural way for arbitrary fields to pass through >> org-bibtex without the user needing to explicitly name them, or there >> being any danger of contamination from existing org-mode properties. > > I went ahead and implemented this. (Alas, it meant cluttering up your > very elegant org-bibtex-headline with another mapcar.)=20 > This looks great thanks. > > Assuming that not all users who use a prefix will want to export > arbitrary fields, I made the functionality dependent on two variables: > org-bibtex-prefix and a org-bibtex-export-arbitrary-fields. But this > could be simplified. > I think this is the best approach. > > I also made the key property configurable. > Nice, I think this is also an improvement. > > The patch was created against a patched org-bibtex.el, so I will wait > until your changes get merged into the repo before sending a formal > patch. But I thought I'd send it along to see if you think the changes > are appropriate. > Oh, I should have read this last paragraph. Having received confirmation from Bastien that it was alright to include this code into org-bibtex in the core, I have applied your patch on top of my own patches. The results are now in the Org-mode git repository. Please do let me know if anything looks amiss --- I mainly just expanded your patch to take into account my intervening changes, and to avoid lines longer than 80 characters. Thanks! -- Eric > > Best, > Matt=20 > > diff --git a/lisp/org-bibtex.el b/lisp/org-bibtex.el > index 9ee30f1..afa3764 100644 > --- a/lisp/org-bibtex.el > +++ b/lisp/org-bibtex.el > @@ -221,6 +221,24 @@ For example setting to 'BIB_' would allow interopera= bility with fireforg." > :group 'org-bibtex > :type 'string) >=20=20 > +(defcustom org-bibtex-export-arbitrary-fields nil > + "When converting to bibtex allow fields not defined in `org-bibtex-fie= lds'. > +This only has effect if org-bibtex-prefix is defined, so as to > +ensure that other org-properties, such as CATEGORY or LOGGING are > +not placed in the exported bibtex entry." > + :group 'org-bibtex > + :type 'boolean) > + > +;; TODO if ID, test to make sure ID is unique > +(defcustom org-bibtex-key-property "CUSTOM_ID" > + "Property that holds the bibtex key. > +By default, this is CUSTOM_ID, which enables easy linking to > +bibtex headlines from within an org file. This can be set to ID > +to enable global links, but only with great caution, as global > +IDs must be unique." > + :group 'org-bibtex > + :type 'string) > + > > ;;; Utility functions > (defun org-bibtex-get (property) > @@ -232,7 +250,7 @@ For example setting to 'BIB_' would allow interoperab= ility with fireforg." > (substring (symbol-name property) 1) > property)))) > (org-set-property > - (concat (unless (string=3D "CUSTOM_ID" prop) org-bibtex-prefix) pro= p) > + (concat (unless (string=3D org-bibtex-key-property prop) org-bibtex= -prefix) prop) > value))) >=20=20 > (defun org-bibtex-headline () > @@ -246,7 +264,7 @@ For example setting to 'BIB_' would allow interoperab= ility with fireforg." > (if (listp e) (apply #'flatten e) (= list e))) > lsts)))) > (let ((notes (buffer-string)) > - (id (org-bibtex-get "custom_id")) > + (id (org-bibtex-get org-bibtex-key-property)) > (type (org-bibtex-get "type"))) > (when type > (let ((entry (format > @@ -254,15 +272,23 @@ For example setting to 'BIB_' would allow interoper= ability with fireforg." > (mapconcat > (lambda (pair) (format " %s=3D{%s}" (car pair) (= cdr pair))) > (remove nil > - (mapcar > - (lambda (field) > - (let ((value (or (org-bibtex-get (from-k field)) > - (and (equal :title field) > - (org-get-heading))))) > - (when value (cons (from-k field) value)))) > - (flatten > - (get :required (get (to-k type) org-bibtex-types)) > - (get :optional (get (to-k type) org-bibtex-types))))) > + (if (and org-bibtex-export-arbitrary-fields org-bibtex-prefix) > + (mapcar=20 > + (lambda (kv) > + (when (string-match org-bibtex-prefix (car kv)) > + (cons (downcase (replace-regexp-in-string=20 > + org-bibtex-prefix "" (car kv))) > + (cdr kv)))) > + (org-entry-properties nil 'standard)) > + (mapcar > + (lambda (field) > + (let ((value (or (org-bibtex-get (from-k field)) > + (and (equal :title field) > + (org-get-heading))))) > + (when value (cons (from-k field) value)))) > + (flatten > + (get :required (get (to-k type) org-bibtex-types)) > + (get :optional (get (to-k type) org-bibtex-types)))))) > ",\n")))) > (with-temp-buffer > (insert entry) > @@ -283,7 +309,7 @@ For example setting to 'BIB_' would allow interoperab= ility with fireforg." >=20=20 > (defun org-bibtex-autokey () > "Generate an autokey for the current headline" > - (org-bibtex-put "CUSTOM_ID" > + (org-bibtex-put org-bibtex-key-property > (if org-bibtex-autogen-keys > (let ((entry (org-bibtex-headline))) > (with-temp-buffer > @@ -312,7 +338,7 @@ With optional argument OPTIONAL, also prompt for opti= onal fields." > (let ((prop (org-bibtex-ask field))) > (when prop (org-bibtex-put name prop))))))) > (when (and type (assoc type org-bibtex-types) > - (not (org-bibtex-get "CUSTOM_ID"))) > + (not (org-bibtex-get org-bibtex-key-property))) > (org-bibtex-autokey))) >=20=20 > > @@ -488,7 +514,7 @@ This uses `bibtex-parse-entry'." > (case (car pair) > (:title nil) > (:type nil) > - (:key (org-bibtex-put "CUSTOM_ID" (cdr pair))) > + (:key (org-bibtex-put org-bibtex-key-property (cdr pair))) > (otherwise (org-bibtex-put (car pair) (cdr pair)))))))) >=20=20 > (provide 'org-bibtex) --=20 Eric Schulte http://cs.unm.edu/~eschulte/