emacs-citar / citar

Emacs package to quickly find and act on bibliographic references, and edit org, markdown, and latex academic documents.
GNU General Public License v3.0
514 stars 55 forks source link

add date formatting for templates #313

Open bdarcus opened 3 years ago

bdarcus commented 3 years ago

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?

aikrahguzar commented 3 years ago

@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.

bdarcus commented 3 years ago

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?

dschrempf commented 3 years ago

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!

bdarcus commented 3 years ago

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.

dschrempf commented 3 years ago

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...

bdarcus commented 3 years ago

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

aikrahguzar commented 3 years ago

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.

dschrempf commented 3 years ago

@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.

bdarcus commented 3 years ago

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.

dschrempf commented 3 years ago

I agree.

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

Thanks!