citar icon indicating copy to clipboard operation
citar copied to clipboard

add date formatting for templates

Open bdarcus opened this issue 3 years ago • 10 comments

Is it possible to format the date in the template? This was/is possible using bibtex-completion-notes-template-multiple-files and, e.g., date: %<%B %e, %Y>.

Originally posted by @dschrempf in https://github.com/bdarcus/bibtex-actions/issues/311#issuecomment-930429386

Not a high priority ATM, but should probably do this if there's a clean way.

@aikrahguzar - am I correct to assume that if this were feasible/convenient, it would be via bibtex-actions--format-entry-no-widths?

bdarcus avatar Sep 30 '21 11:09 bdarcus

@aikrahguzar - am I correct to assume that if this were feasible/convenient, it would be via bibtex-actions--format-entry-no-widths?

I would say that formatting should be done by adding a function to bibtex-actions-display-transform-functions e.g.

(add-to-list 'bibtex-actions-display-transform-functions '(("date" "year" "issued") . formatting-function))

This kind of field value processing is the purpose of that variable.

aikrahguzar avatar Sep 30 '21 21:09 aikrahguzar

But that's for global configuration; right?

E.g. it doesn't work if someone wants one formatting in the candidate list, and another in a note?

bdarcus avatar Sep 30 '21 21:09 bdarcus

I was actually reverting to a separate templating mechanism, just because I was so confused about which function replaces what and so on. At the moment, I just use a simple (yas)snippet. Maybe it is best to just provide an (oc-)bibtex-actions-open-note-hook, and then everybody can do as they please.

Thanks anyways for developing this package, it works great so far!

dschrempf avatar Oct 01 '21 10:10 dschrempf

Maybe it is best to just provide an (oc-)bibtex-actions-open-note-hook, and then everybody can do as they please

I'm not super knowledgeable about hooks. What advantage would that have over the already existing bibtex-actions-file-note-function?

The whole point of that is to give users flexibility.

bdarcus avatar Oct 01 '21 12:10 bdarcus

I think both are fine. A hook, however, would never really open a file (although it could do that, of course). Usually, hooks are run after everything has been set up.

This is nice becase the "find correct file and open if" function is separated from the "activate major mode, insert template" function. Not sure if I am explaining myself...

dschrempf avatar Oct 01 '21 12:10 dschrempf

But how would one use such a "note" hook in this case?

bdarcus avatar Oct 01 '21 13:10 bdarcus

E.g. it doesn't work if someone wants one formatting in the candidate list, and another in a note?

That is true. Though if we want to support this, I would say we should adjust the handling of 'bibtex-actions-display-transform-functions to able to accommodate different scenarios. Maybe by adding a additional argument to the function. I am not sure if that is a good idea.

aikrahguzar avatar Oct 01 '21 18:10 aikrahguzar

@bdarcus I am not sure if I understand. I could for instance, insert a template using the hook. One could also load a major mode or do anything else. The only problem I see is that the hook functions don't relaly have access to the bibliographic data like key, author, etc.

dschrempf avatar Oct 01 '21 19:10 dschrempf

Right, but I don't see how that's useful with notes, given the limitation you note at the end.

I mean, one could substitute a function that hooks into org-capture functionality, for example.

bdarcus avatar Oct 01 '21 21:10 bdarcus

I agree.

I am happy with anything as long as I can have an empty template :smile:.

Thanks!

dschrempf avatar Oct 01 '21 22:10 dschrempf