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
479 stars 53 forks source link

prefixes and suffixes in `citar-markdown-insert-citation` #786

Closed benthamite closed 12 months ago

benthamite commented 12 months ago

When I run citar-insert-citation in a Markdown buffer and select the work I want to cite, the identifier is inserted preceded by a space and followed by a comma and a space, e.g. [ @Ord2020PrecipiceExistentialRisk, ]. The function responsible for this behavior is citar-markdown-insert-citation (specifically, the lines (prenote (if (string= "" prenote) "" (concat prenote " "))) and (postnote (if (string= "" postnote) "" (concat ", " postnote))). ) I would prefer not to have these extra characters inserted when no prefix or suffix is provided, which would also be consistent with how citations are inserted in org-mode buffers. Would it make sense to add a user option to control this behavior?

bdarcus commented 12 months ago

That's weird; testing just now, I don't see that. This is what I get when inserting without affix and with respectively.

# Testing ...

[@burwell2014]

[see  @kohn2008, p12]
benthamite commented 12 months ago

Okay, I now realize that this is not an intended behavior: looking at citar-markdown-insert-citation more carefully, I see that when the value of prenote and postnote is an empty string, it should not insert any extra characters. When I run edebug on citar-markdown-insert-citation, I see that prenote and postnote are evaluated to nil, so (string= "" prenote) and (string= "" postnote) evaluate to nil, and as a consequence prenote and postnote are assigned the values (concat prenote " ") and (concat ", " postnote), respectively.

Presumably in your case the value of prenote and postnote is an empty string rather than nil, which would explain why the citations are inserted without any extra characters. Do you have a sense of what might be causing the difference in the values of those two variables between us?

bdarcus commented 12 months ago

No; I tried in both my default doom setup, and a minimal custom one.

Seems regardless it would be better for it to check for a non-empty string?

Care to submit a PR for that?

benthamite commented 12 months ago

Sure. To confirm, this would just involve replacing (string= "" prenote) with (= (length prenote) 0), and (string= "" postnote) with (= (length postnote) 0), in citar-markdown-insert-citation, right?

bdarcus commented 12 months ago

I believe so.

benthamite commented 12 months ago

By the way, in case this is helpful to others, the reason we were getting different values for prenote and postnote (as I just realized) is that I have citar-markdown-prompt-for-extra-arguments set to nil. Because I am not prompted for a prefix or a suffix, the value of those variables ends up being nil rather than an empty string.