From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Danan Subject: Re: [PATCH] org-bibtex.el: Make headline format costomizable Date: Wed, 7 Dec 2016 22:20:39 +0100 Message-ID: References: <87inr1cujf.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53225) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cEjfC-0000C4-DB for emacs-orgmode@gnu.org; Wed, 07 Dec 2016 16:22:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cEjf9-0007f0-54 for emacs-orgmode@gnu.org; Wed, 07 Dec 2016 16:22:06 -0500 Received: from mail-wm0-f51.google.com ([74.125.82.51]:35740) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cEjf8-0007aS-VT for emacs-orgmode@gnu.org; Wed, 07 Dec 2016 16:22:03 -0500 Received: by mail-wm0-f51.google.com with SMTP id a197so187924086wmd.0 for ; Wed, 07 Dec 2016 13:21:41 -0800 (PST) In-Reply-To: <87inr1cujf.fsf@nicolasgoaziou.fr> 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" To: Eric Danan , emacs-orgmode@gnu.org Here it is, hope I did everything correctly. * lisp/org-bibtex.el (org-bibtex-write): Make this function read the headline format from the newly created variable `org-bibtex-headline-format-function' instead of systematically using the entry title. (org-bibtex-headline-foramt-function): Create this variable to hold a function of one argument, the entry alist, and return the string to be inserted as headline. The default value replicates the current behavior of returning the entry title. TINYCHANGE --- etc/ORG-NEWS | 2 ++ lisp/org-bibtex.el | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 78f28cbe..056443ac 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -84,6 +84,8 @@ Where clue > 0 *** Horizontal rules are no longer ignored in LaTeX table math mode +*** Org-Bibtex +**** New variable : ~org-bibtex-headline-format-function~ ** Removed options *** ~org-agenda-repeating-timestamp-show-all~ is removed. diff --git a/lisp/org-bibtex.el b/lisp/org-bibtex.el index db5d97b3..3dabc68f 100644 --- a/lisp/org-bibtex.el +++ b/lisp/org-bibtex.el @@ -237,6 +237,18 @@ (defcustom org-bibtex-treat-headline-as-title t :version "24.1" :type 'boolean) +(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 + :version "25.1" + :package-version '(Org . "9.1") + :type 'function) + (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 @@ -678,7 +690,7 @@ (defun org-bibtex-write () (val (lambda (field) (cdr (assoc field entry)))) (togtag (lambda (tag) (org-toggle-tag tag 'on)))) (org-insert-heading) - (insert (funcall val :title)) + (insert (funcall org-bibtex-headline-format-function entry)) (org-bibtex-put "TITLE" (funcall val :title)) (org-bibtex-put org-bibtex-type-property-name (downcase (funcall val :type))) -- 2.8.3 On Sat, Dec 3, 2016 at 8:59 AM, Nicolas Goaziou wrote: > Hello, > > Eric Danan writes: > >> When adding an org-bibtex entry with `org-bibtex-write' (or any >> command relying on it), the headline is the title. The patch below >> simply makes the headline customizable through a new variable. > > Thank you. > >> If you find it worth to incorporate this into org-bibtex I should >> probably add a dosctring for the new variable > > Yes, please. Also, an entry in ORG-NEWS is welcome. > >> `org-bibtex-headline-format' and I would also have a few questions: >> 1. Should I name this variable differently? > > Indeed. It should indicate it represents a function: > `org-bibltex-headline-format-function' is better, IMO, since a "format" > could be a format string. > >> 2. Should I use `defcustom' instead of `defvar'? > > Correct. Mind the :version and :package-version keywords. > >> 3. Should I move the `defvar' / `defcustom' at the beginning of the file? > > Yes. > >> 4. In the default value of the variable should I make use of the `val' >> function that is let-bound inside `org-bibtex-write'? > > I think the default value is fine. Another option is to create a new > `org-bibtex-headline-default' function and bound the variable to that. > >> +(defvar org-bibtex-headline-format >> + (lambda (entry) >> + (cdr (assoc :title entry)))) > > Nitpick > > `assoc' -> `assq' > > Regards, > > -- > Nicolas Goaziou