-
Notifications
You must be signed in to change notification settings - Fork 54
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
support local bibs #208
support local bibs #208
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,8 +207,26 @@ offering the selection candidates" | |
collect (cdr (or (assoc choice candidates) | ||
(rassoc choice candidates)))))) | ||
|
||
(defun bibtex-actions--format-candidates () | ||
"Transform candidates from 'bibtex-completion-candidates'. | ||
(defun bibtex-actions--normalize-paths (file-paths) | ||
"Return a list of FILE-PATHS normalized with truename." | ||
(if (stringp file-paths) | ||
;; If path is a string, return as a list. | ||
(list (file-truename file-paths)) | ||
(delete-dups (mapcar (lambda (p) (file-truename p)) file-paths)))) | ||
|
||
(defun bibtex-actions--local-files-to-cache () | ||
"The local bibliographic files not included in the global bibliography." | ||
;; We cache these locally to the buffer. | ||
(let* ((local-bib-files | ||
(bibtex-actions--normalize-paths | ||
(bibtex-completion-find-local-bibliography))) | ||
(global-bib-files | ||
(bibtex-actions--normalize-paths | ||
bibtex-completion-bibliography))) | ||
(seq-difference local-bib-files global-bib-files))) | ||
bdarcus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
(defun bibtex-actions--format-candidates (&optional context) | ||
"Format candidates, with optional hidden CONTEXT metadata. | ||
This both propertizes the candidates for display, and grabs the | ||
key associated with each one." | ||
(let* ((main-template | ||
|
@@ -240,7 +258,7 @@ key associated with each one." | |
;; We display this content already using symbols; here we add back | ||
;; text to allow it to be searched, and citekey to ensure uniqueness | ||
;; of the candidate. | ||
(candidate-hidden (s-join " " (list pdf note link citekey)))) | ||
(candidate-hidden (s-join " " (list pdf note link context citekey)))) | ||
(cons | ||
;; If we don't trim the trailing whitespace, 'completing-read-multiple' will | ||
;; get confused when there are multiple selected candidates. | ||
|
@@ -275,17 +293,24 @@ key associated with each one." | |
(s-join bibtex-actions-symbol-separator | ||
(list pdf note link))" ") suffix)))) | ||
|
||
(defvar bibtex-actions--candidates-cache nil | ||
"Store the candidates list.") | ||
(defvar bibtex-actions--candidates-cache 'uninitialized | ||
"Store the global candidates list.") | ||
|
||
(defvar-local bibtex-actions--local-candidates-cache 'uninitialized | ||
;; We use defvar-local so can maintain per-buffer candidate caches. | ||
"Store the local (per-buffer) candidates list.") | ||
|
||
(defun bibtex-actions--get-candidates (&optional force-rebuild-cache) | ||
"Get the cached candidates. | ||
If the cache is nil, this will load the cache. | ||
If FORCE-REBUILD-CACHE is t, force reloading the cache." | ||
(when (or force-rebuild-cache | ||
(not bibtex-actions--candidates-cache)) | ||
(eq 'uninitialized bibtex-actions--candidates-cache) | ||
(eq 'uninitialized bibtex-actions--local-candidates-cache)) | ||
(bibtex-actions-refresh force-rebuild-cache)) | ||
bibtex-actions--candidates-cache) | ||
(seq-concatenate 'list | ||
bibtex-actions--local-candidates-cache | ||
bibtex-actions--candidates-cache)) | ||
|
||
;;;###autoload | ||
(defun bibtex-actions-refresh (&optional force-rebuild-cache) | ||
|
@@ -295,8 +320,14 @@ is non-nil, also run the `bibtex-actions-before-refresh-hook' hook." | |
(interactive "P") | ||
(when force-rebuild-cache | ||
(run-hooks 'bibtex-actions-force-refresh-hook)) | ||
;; t in the result indicates that cache was computed but came out nil nil | ||
;; itself is used to indicate a cache that hasn't been computed this is to | ||
;; work around the fact that we can't differentiate between empty list and nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is outdated now. I forgot to remove it earlier. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops; I merged it. You can remove it when you do the related PR :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was quick. I hope these late changes don't introduce any errors. They are pretty trivial but still fingers crossed. |
||
(setq bibtex-actions--candidates-cache | ||
(bibtex-actions--format-candidates))) | ||
(bibtex-actions--format-candidates)) | ||
(let ((bibtex-completion-bibliography (bibtex-actions--local-files-to-cache))) | ||
(setq bibtex-actions--local-candidates-cache | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
(bibtex-actions--format-candidates "is:local")))) | ||
|
||
;;;###autoload | ||
(defun bibtex-actions-insert-preset () | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hook won't help with stale cache, I include it so that the cache is generated when a new buffer is opened making the ui seem more responsive.
For stale cache
filenotify
is the solution though it won't work with local cache as is.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As in, they conflict, or (as I assume) they are complementary? If the latter, I'll add it back and adjust the language.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are complemtary. I think another hook will be needed that adds a watch on the files returned by
bibtex-completion-find-local-bibliography
to make it work with local cache.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you just use "suggested changes" to suggest the specific line changes then? Just click the left most icon on the toolbar.
Allows me to just click to accept, and then you get credit in the git history.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I adjusted the language, I will have to look into filenotify a bit to write and test the hook for cache update.