From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: [PATCH 4/4] Add helper functions to org-bibtex Date: Mon, 02 May 2011 10:29:19 -0600 Message-ID: References: <87iptunn4m.fsf@fastmail.fm> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([140.186.70.92]:46501) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QGw1u-0007D7-1M for emacs-orgmode@gnu.org; Mon, 02 May 2011 12:31:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QGw1s-0006LL-Ca for emacs-orgmode@gnu.org; Mon, 02 May 2011 12:31:25 -0400 Received: from mail-px0-f175.google.com ([209.85.212.175]:53809) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QGw1s-0006Ku-3N for emacs-orgmode@gnu.org; Mon, 02 May 2011 12:31:24 -0400 Received: by pxi17 with SMTP id 17so2100155pxi.34 for ; Mon, 02 May 2011 09:31:22 -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, Thanks for these patches, they all look great. I've just applied the first three, however this last patch does not apply to the current head. For example the first chunk alters a variable named `org-bibtex-treat-headline-as-title' which does not exist in the current git head. Perhaps you are missing an intervening patch? Thanks! -- Eric Matt Lundin writes: > * lisp/org-bibtex.el: (org-bibtex-search): New function. > (org-bibtex-export-to-kill-ring): New function. Export to kill ring. > (org-bibtex-create-in-current-entry): New function > (org-bibtex-create): Make it easier to add bib fields to an > existing headline > (org-bibtex-export-arbitrary-fields) > (org-bibtex-treat-headline-as-title): Fix typos > (org-bibtex-fleshout): Don't upcase optional field; remove ":" from > type completion > > This patch implements several helper functions: exporting to kill > ring, searching only for entries with bib fields, and creating bib > fields in an existing headline. It makes the UI of org-bibtex-fleshout > more consistent. > --- > lisp/org-bibtex.el | 51 ++++++++++++++++++++++++++++++++++++++++----------- > 1 files changed, 40 insertions(+), 11 deletions(-) > > diff --git a/lisp/org-bibtex.el b/lisp/org-bibtex.el > index 513519b..868535d 100644 > --- a/lisp/org-bibtex.el > +++ b/lisp/org-bibtex.el > @@ -226,14 +226,14 @@ For example setting to 'BIB_' would allow interoperability with fireforg." > (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 > -the property. If this value is t, `org-bibtex-check` will ignore > +the property. If this value is t, `org-bibtex-check' will ignore > a missing title field." > :group 'org-bibtex > :type 'boolean) > > (defcustom org-bibtex-export-arbitrary-fields nil > "When converting to bibtex allow fields not defined in `org-bibtex-fields'. > -This only has effect if org-bibtex-prefix is defined, so as to > +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 > @@ -385,7 +385,7 @@ This variable is relevant only if `org-bibtex-export-tags-as-keywords` is t." > With optional argument OPTIONAL, also prompt for optional fields." > (flet ((val (key lst) (cdr (assoc key lst))) > (keyword (name) (intern (concat ":" (downcase name)))) > - (name (keyword) (upcase (substring (symbol-name keyword) 1)))) > + (name (keyword) (substring (symbol-name keyword) 1))) > (dolist (field (append > (if org-bibtex-treat-headline-as-title > (remove :title (val :required (val type org-bibtex-types))) > @@ -530,22 +530,36 @@ With prefix argument OPTIONAL also prompt for optional fields." > With prefix argument OPTIONAL also prompt for optional fields." > (interactive) (org-map-entries (lambda () (org-bibtex-check optional)))) > > -(defun org-bibtex-create (&optional arg) > - "Create a new entry at the given level." > +(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." > (interactive "P") > (let* ((type (org-icompleting-read > - "Type: " (mapcar (lambda (type) (symbol-name (car type))) > - org-bibtex-types))) > - (type (if (keywordp type) type (intern type)))) > + "Type: " (mapcar (lambda (type) > + (substring (symbol-name (car type)) 1)) > + org-bibtex-types) > + nil nil (when nonew (org-bibtex-get "TYPE")))) > + (type (if (keywordp type) type (intern (concat ":" type)))) > + (org-bibtex-treat-headline-as-title (if nonew nil t))) > (unless (assoc type org-bibtex-types) > (error "type:%s is not known" type)) > - (org-insert-heading) > - (let ((title (org-bibtex-ask :title))) > - (insert title) (org-bibtex-put "TITLE" title)) > + (if nonew > + (org-back-to-heading) > + (org-insert-heading) > + (let ((title (org-bibtex-ask :title))) > + (insert title) > + (org-bibtex-put "TITLE" title))) > (org-bibtex-put "TYPE" (substring (symbol-name type) 1)) > (org-bibtex-fleshout type arg) > (mapc (lambda (tag) (org-toggle-tag tag t)) org-bibtex-tags))) > > +(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)) > + > (defun org-bibtex-read () > "Read a bibtex entry and save to `*org-bibtex-entries*'. > This uses `bibtex-parse-entry'." > @@ -608,6 +622,21 @@ This uses `bibtex-parse-entry'." > (org-bibtex-write) > (error "yanked text does not appear to contain a bibtex entry")))) > > +(defun org-bibtex-export-to-kill-ring () > + "Export current headline to kill ring as bibtex entry." > + (interactive) > + (kill-new (org-bibtex-headline))) > + > +(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 > + (format "%s +{:%sTYPE:}" > + string org-bibtex-prefix)))) > + > (provide 'org-bibtex) > > ;; arch-tag: 83987d5a-01b8-41c7-85bc-77700f1285f5 -- Eric Schulte http://cs.unm.edu/~eschulte/