jkitchin / org-ref

org-mode modules for citations, cross-references, bibliographies in org-mode and useful bibtex tools to go with it.
GNU General Public License v3.0
1.35k stars 242 forks source link

doi-utils-insert-bibtex-entry-from-doi: make save-buffer optional #1088

Closed piater closed 10 months ago

piater commented 10 months ago

Not saving is useful e.g. when inserting into a temp buffer.

If you agree to do me this favor :-) It will simplify my org-refman project (not (yet?) public). (There are no such uses inside org-ref for now.)

jkitchin commented 10 months ago

is this something you use programmatically? but otherwise doesn't change the default behavior?

piater commented 10 months ago

is this something you use programmatically?

Yes.

but otherwise doesn't change the default behavior?

Correct.

jkitchin commented 10 months ago

I wonder if a simpler way to do this is instead of using a new argument, just check if the buffer is visiting a file.

e.g.

(when (buffer-file-name)
  (save-buffer))

That should have an effect of not saving in a temp buffer that has no file.

I think the idiomatic way to write your small change is preferrably

(unless nosave
  (save-buffer))
piater commented 10 months ago

I updated the pull request according to your first suggestion, which I think perfectly expresses what's going on (save iff there is a file to save to).

Thanks also for reminding me of the unless function.