emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-bibtex.el: Make headline format costomizable
@ 2016-11-24 21:22 Eric Danan
  2016-12-03  7:59 ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Danan @ 2016-11-24 21:22 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

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.

I tried to follow the contribution guidelines at

http://orgmode.org/worg/org-contribute.html#patches

but I am not familiar with the process of sending patches, please let
me know if I did not do it correctly.

If you find it worth to incorporate this into org-bibtex I should
probably add a dosctring for the new variable
`org-bibtex-headline-format' and I would also have a few questions:
1. Should I name this variable differently?
2. Should I use `defcustom' instead of `defvar'?
3. Should I move the `defvar' / `defcustom' at the beginning of the file?
4. In the default value of the variable should I make use of the `val'
function that is let-bound inside `org-bibtex-write'?

Thank you for your attention,

Eric


* lisp/org-bibtex.el (org-bibtex-write): Make this function reads the
  headline format from the newly created variable
  `org-bibtex-headline-format' instead of systematically using the entry
  title.
  (org-bibtex-headline-format): 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
---
 lisp/org-bibtex.el | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lisp/org-bibtex.el b/lisp/org-bibtex.el
index db5d97b3..b4b8b3c6 100644
--- a/lisp/org-bibtex.el
+++ b/lisp/org-bibtex.el
@@ -668,6 +668,10 @@ (defun org-bibtex-read-file (file)
   (interactive "fFile: ")
   (org-bibtex-read-buffer (find-file-noselect file 'nowarn 'rawfile)))

+(defvar org-bibtex-headline-format
+  (lambda (entry)
+    (cdr (assoc :title entry))))
+
 (defun org-bibtex-write ()
   "Insert a heading built from the first element of `org-bibtex-entries'."
   (interactive)
@@ -678,7 +682,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 entry))
     (org-bibtex-put "TITLE" (funcall val :title))
     (org-bibtex-put org-bibtex-type-property-name
             (downcase (funcall val :type)))
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] org-bibtex.el: Make headline format costomizable
  2016-11-24 21:22 [PATCH] org-bibtex.el: Make headline format costomizable Eric Danan
@ 2016-12-03  7:59 ` Nicolas Goaziou
  2016-12-07 21:20   ` Eric Danan
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2016-12-03  7:59 UTC (permalink / raw)
  To: Eric Danan; +Cc: emacs-orgmode

Hello,

Eric Danan <eric.danan@u-cergy.fr> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] org-bibtex.el: Make headline format costomizable
  2016-12-03  7:59 ` Nicolas Goaziou
@ 2016-12-07 21:20   ` Eric Danan
  2016-12-09 20:48     ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Danan @ 2016-12-07 21:20 UTC (permalink / raw)
  To: Eric Danan, emacs-orgmode

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 <mail@nicolasgoaziou.fr> wrote:
> Hello,
>
> Eric Danan <eric.danan@u-cergy.fr> 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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] org-bibtex.el: Make headline format costomizable
  2016-12-07 21:20   ` Eric Danan
@ 2016-12-09 20:48     ` Nicolas Goaziou
  2016-12-09 22:11       ` Eric Danan
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2016-12-09 20:48 UTC (permalink / raw)
  To: Eric Danan; +Cc: emacs-orgmode

Hello,

Eric Danan <eric.danan@u-cergy.fr> writes:

> Here it is, hope I did everything correctly.

Almost. I changed :version "25.1" to :version "25.2". Also, you seem to
create the entries in the commit message manually. If you are using
Magit, C within the diff buffer can create them for you.

Anyway, I applied your patch. Thank you.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] org-bibtex.el: Make headline format costomizable
  2016-12-09 20:48     ` Nicolas Goaziou
@ 2016-12-09 22:11       ` Eric Danan
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Danan @ 2016-12-09 22:11 UTC (permalink / raw)
  To: Eric Danan, emacs-orgmode

Thanks for the tip, indeed I use magit and was creating the entries manually.

On Fri, Dec 9, 2016 at 9:48 PM, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
> Hello,
>
> Eric Danan <eric.danan@u-cergy.fr> writes:
>
>> Here it is, hope I did everything correctly.
>
> Almost. I changed :version "25.1" to :version "25.2". Also, you seem to
> create the entries in the commit message manually. If you are using
> Magit, C within the diff buffer can create them for you.
>
> Anyway, I applied your patch. Thank you.
>
> Regards,
>
> --
> Nicolas Goaziou

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-12-09 22:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-24 21:22 [PATCH] org-bibtex.el: Make headline format costomizable Eric Danan
2016-12-03  7:59 ` Nicolas Goaziou
2016-12-07 21:20   ` Eric Danan
2016-12-09 20:48     ` Nicolas Goaziou
2016-12-09 22:11       ` Eric Danan

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).