Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add database/file annotation to completions #695

Closed
jsilve24 opened this issue Oct 3, 2022 · 7 comments
Closed

Add database/file annotation to completions #695

jsilve24 opened this issue Oct 3, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@jsilve24
Copy link

jsilve24 commented Oct 3, 2022

Is your feature request related to a problem? Please describe.
Yes. I have my own bibtex database which is my main / global / default database. I also frequently work with others on local databases that are in a given folder with a document we are working on. Others may add citations to the local bibtex file that are duplicates of something in my database but has a different key. This can cause problems when I am trying to figure out which of two seemingly identical (save different keys) completion candidates to use. In those cases I would prefer to just use the one that is in the local bibtex file.

Describe the solution you'd like
I think its too hard to automate the choice between two candidates but a simple option / annotation in the completions buffer would be enough. Would it be possible to show whether something is from a global file or the local file? This could simply be a ("global"/"local") indicator or simply just given the filename for where the candidate is comming from.

Describe alternatives you've considered
none. automating seems like more of a pain, indicating which file seems easiest.

@jsilve24 jsilve24 added the enhancement New feature or request label Oct 3, 2022
@bdarcus
Copy link
Contributor

bdarcus commented Oct 3, 2022

It's an interesting problem.

This could simply be a ("global"/"local") indicator or simply just given the filename for where the candidate is coming from.

Keep in mind, however, one can in theory have multiple global and/or local bibliographies associated with a buffer.

In that situation, I would think the first option likely wouldn't be very useful, and the second could get unwieldy.

But this is also tied to broader issues, like how citar merges multiple bibliographies. In theory, there should not really be duplicate entries with different keys, but we currently don't check for that.

I could imagine a feature where we did, and we have some customization option on what to do with duplicates (and a related feature we may have previously discussed where one could import local entries into a global file).

Also related, potentially: #645.

@jsilve24
Copy link
Author

jsilve24 commented Oct 3, 2022

While I appreciate the long-term goal / vision of having some complete method of handling duplicates. I think a very simple solution would be to simply check whether the database is included in the variable org-cite-global-bibliography or whatnot and just have a binary label (yes/no)/(global/local). Yes you could have multiple global bibliographies with duplicates but how common is that? Or perhaps its just a placeholder annotation that has access to some key variables allowing user to write their own function with that info.

@bdarcus
Copy link
Contributor

bdarcus commented Oct 3, 2022

Right, but we have to think about the bigger picture before considering hard coding something like this.

I don't use local files, for example, so I don't really want such an indicator taking up real estate.

Which is why #645 may well be a better, more flexible and general, solution?

WDYT?

@jsilve24
Copy link
Author

jsilve24 commented Oct 3, 2022 via email

@jsilve24
Copy link
Author

jsilve24 commented Oct 6, 2022

In case it is of use to others, I wrote some helper functions which help to determine if a given citar function should prioritize global versus local bibliographies. I am sure these could be improved but they seem to work for me at the moment.

;;;###autoload
(defun jds~citar-prioritize-local-bib (fun)
  "Run command FUN interactively setting citar-bibliography to local-bibliography if present."
  (let ((local-latex (citar-latex-local-bib-files))
	(local-org (citar-org-local-bib-files)))
    (if (or local-latex local-org)
	(let ((citar-bibliography (if local-latex
				      local-latex
				    local-org)))
	  (call-interactively fun))
      (call-interactively fun))))

;;;###autoload
(defun jds~citar-prioritize-global-bib (fun)
  "Run command FUN interactively setting citardybibliography to local-bibliography if present. C-u passed to fun."
  ;; use temp-buffer to ensure citar-bibliography does not include local bibs.
  (let ((global-bib (with-temp-buffer citar-bibliography)))
    (if global-bib
	(let ((citar-bibliography global-bib))
	  (call-interactively fun))
      (call-interactively fun))))


;;;###autoload
(defun jds/citar-insert-cite-prioritize-local-bib ()
  "Run citar-insert-cite but pioritize local bibliographies if present, otherwise use global."
  (interactive)
  (jds~citar-prioritize-local-bib #'citar-insert-citation))

;;;###autoload
(defun jds/citar-open-prioritize-global-bib ()
  "Run citar-open but prioritize global bibliographies if present, otherwise use local."
  (interactive)
  (jds~citar-prioritize-global-bib #'citar-open))

@bdarcus
Copy link
Contributor

bdarcus commented Oct 6, 2022

I pulled out a separate issue since there's really two issues here:

  1. UI indicators (this issue)
  2. how we merge global and local entries (right now, it's not smart or customizable, but is fast)

@bdarcus
Copy link
Contributor

bdarcus commented Aug 24, 2023

... #645 may well be a better, more flexible and general, solution?

Since you opened this issue, @jsilve24, I've merged configurable indicators. I'm going to close this then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants