From c9cab5ac7f12bb3b0291e8601c56e2bb44a9ce3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Volbers?= Date: Sun, 9 May 2021 21:09:35 +0200 Subject: [PATCH 1/6] Add customizable variable bibtex-actions-initial-inputs --- bibtex-actions.el | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/bibtex-actions.el b/bibtex-actions.el index 02c548cb..f6d74a63 100644 --- a/bibtex-actions.el +++ b/bibtex-actions.el @@ -97,6 +97,30 @@ manager like Zotero or JabRef." :group 'bibtex-actions :type '(repeat function)) +(defcustom bibtex-actions-initial-inputs + '((pdf . "has:pdf") + (note . "has:note") + (link . "has:link") + (source . "has:link\\|has:pdf")) + "Alist defining the initial input for some bibtex open actions. +Given a flexible completion style, this will restrict the list of +available candidates to those matching the initial input. + +The association key can be one of the symbols `pdf', `note', +`link' or `source' and defines the input for the function +`bibtex-action-open-pdf', `bibtex-action-open-link', etc. The +associated value must be nil, meaning that there will be no +initial input, or a string. + +To match entries with certain properties (e.g. files attached), +you can use the following initial inputs: \"has:pdf\", +\"has:link\" and \"has:note\"." + :group 'bibtex-actions + :type '(alist :key-type symbol + :value-type (choice string + (const :tag "No initial input" nil)))) + + ;;; History, including future history list. (defvar bibtex-actions-history nil From fee6dd9e415b8a6c1ecfdd0b620e77d93f07afff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Volbers?= Date: Sun, 9 May 2021 21:16:09 +0200 Subject: [PATCH 2/6] (bibtex-action-read) Change meaning of argument :initial --- bibtex-actions.el | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/bibtex-actions.el b/bibtex-actions.el index f6d74a63..88eb687d 100644 --- a/bibtex-actions.el +++ b/bibtex-actions.el @@ -157,13 +157,15 @@ you can use the following initial inputs: \"has:pdf\", This provides a wrapper around 'completing-read-multiple', with the following optional arguments: -'INITIAL' provides the initial value, for pre-filtering the -candidate list +If 'INITIAL' matches one of the keys defined in +`bibtex-actions-initial-inputs', use the associated initial +input. 'REBUILD-CACHE' if t, forces rebuilding the cache before offering the selection candidates" (let* ((crm-separator "\\s-*&\\s-*") (candidates (bibtex-actions--get-candidates rebuild-cache)) + (initial-input (assoc-default initial bibtex-actions-initial-inputs)) (chosen (completing-read-multiple "BibTeX entries: " @@ -173,7 +175,12 @@ offering the selection candidates" (affixation-function . bibtex-actions--affixation) (category . bibtex)) (complete-with-action action candidates string predicate))) - nil nil initial 'bibtex-actions-history bibtex-actions-presets nil))) + nil + nil + (and initial-input + (stringp initial-input) + (concat initial-input " ")) + 'bibtex-actions-history bibtex-actions-presets nil))) (cl-loop for choice in chosen ;; Collect citation keys of selected candidate(s). collect (cdr (assoc choice candidates))))) @@ -354,7 +361,7 @@ Opens the PDF(s) associated with the KEYS. If multiple PDFs are found, ask for the one to open using ‘completing-read’. If no PDF is found, try to open a URL or DOI in the browser instead. With prefix, rebuild the cache before offering candidates." - (interactive (list (bibtex-actions-read :initial "has:link\\|has:pdf " + (interactive (list (bibtex-actions-read :initial 'source :rebuild-cache current-prefix-arg))) (bibtex-completion-open-any keys)) @@ -364,7 +371,7 @@ With prefix, rebuild the cache before offering candidates." If multiple PDFs are found, ask for the one to open using ‘completing-read’. With prefix, rebuild the cache before offering candidates." - (interactive (list (bibtex-actions-read :initial "has:pdf " + (interactive (list (bibtex-actions-read :initial 'pdf :rebuild-cache current-prefix-arg))) (bibtex-completion-open-pdf keys)) @@ -372,7 +379,7 @@ With prefix, rebuild the cache before offering candidates." (defun bibtex-actions-open-link (keys) "Open URL or DOI link associated with the KEYS in a browser. With prefix, rebuild the cache before offering candidates." - (interactive (list (bibtex-actions-read :initial "has:link " + (interactive (list (bibtex-actions-read :initial 'link :rebuild-cache current-prefix-arg))) (bibtex-completion-open-url-or-doi keys)) @@ -415,7 +422,7 @@ With prefix, rebuild the cache before offering candidates." (defun bibtex-actions-open-notes (keys) "Open notes associated with the KEYS. With prefix, rebuild the cache before offering candidates." - (interactive (list (bibtex-actions-read :initial "has:note " + (interactive (list (bibtex-actions-read :initial 'note :rebuild-cache current-prefix-arg))) (bibtex-completion-edit-notes keys)) From 210fbb6ff04de4d1d286a0a7d7426531930ae842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Volbers?= Date: Sun, 9 May 2021 21:21:03 +0200 Subject: [PATCH 3/6] Remove extra line --- bibtex-actions.el | 1 - 1 file changed, 1 deletion(-) diff --git a/bibtex-actions.el b/bibtex-actions.el index 88eb687d..5b56b744 100644 --- a/bibtex-actions.el +++ b/bibtex-actions.el @@ -119,7 +119,6 @@ you can use the following initial inputs: \"has:pdf\", :type '(alist :key-type symbol :value-type (choice string (const :tag "No initial input" nil)))) - ;;; History, including future history list. From 85dfd8593904b6f34fe038064ae7e33a205d7288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Volbers?= Date: Sun, 9 May 2021 21:22:28 +0200 Subject: [PATCH 4/6] checkdoc --- bibtex-actions.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bibtex-actions.el b/bibtex-actions.el index 5b56b744..41d362ea 100644 --- a/bibtex-actions.el +++ b/bibtex-actions.el @@ -108,7 +108,7 @@ available candidates to those matching the initial input. The association key can be one of the symbols `pdf', `note', `link' or `source' and defines the input for the function -`bibtex-action-open-pdf', `bibtex-action-open-link', etc. The +`bibtex-action-open-pdf', `bibtex-action-open-link', etc. The associated value must be nil, meaning that there will be no initial input, or a string. From 2e8bfb57d57f5f897cad5a96c045389ceae7e811 Mon Sep 17 00:00:00 2001 From: Bruce D'Arcus Date: Mon, 10 May 2021 20:02:44 -0400 Subject: [PATCH 5/6] Update README.org --- README.org | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/README.org b/README.org index 3f5e83a6..5d059ee8 100644 --- a/README.org +++ b/README.org @@ -154,7 +154,10 @@ Here's how to configure it to use =all-the-icons=: :group 'all-the-icons-faces) #+END_SRC -*** History and Predefined searches +*** History and predefined searches + :PROPERTIES: + :CUSTOM_ID: history-and-predefined-searches + :END: =Bibtex-actions= has functionality similar to the [[https://github.com/tmalsburg/helm-bibtex#p][predefined search]] functionality in =helm-bibtex= and =ivy-bibtex=, but with a different implementation. Rather than create a new command with the search terms as argument, you just set the =bibtex-actions-presets= variable, and add the strings you want to access: @@ -171,6 +174,33 @@ You then have two ways to access these strings from the completion prompt: =Bibtex-actions= also preserves the history of your selections (see caveat below about multiple candidate selection though), which are also accessible in your completion UI, but by using =M-p=. You can save this history across sessions by adding =bibtex-actions-history= to =savehist-additional-variables=. +*** Pre-filtering entries + :PROPERTIES: + :CUSTOM_ID: prefiltering-entries + :END: + +By default, =bibtex-actions= will, assuming you are using =orderless= or =prescient= to filter candidates, pre-filter entries for the following commands. + +1. =bibtex-actions-open=: pre-narrows the list to those which have associated pdf or links +2. =bibtex-actions-open-link=: pre-narrows the list to those which have associated links +3. =bibtex-actions-open-pdf=: -pre-narrows the list to those which have associated pdf(s) + +That is, upon running the command, an =initial-input= value will be inserted to narrow the results. +You can also delete that if you prefer to see the full list of candidates. + +By default, pre-filtering of =bibtex-actions-open-notes= is off, because the command by default will create a new note if none is available, and therefore it makes sense to have access to your full library. +But you can customize this to pre-filter if you prefer. + +If you want to modify those values, or remove them entirely, you can set =bibtex-actions-initial-inputs= like so; in this case turning off pre-filtering for =bibtex-actions-open-pdf=: + +#+begin_src elisp +(setq bibtex-actions-initial-inputs + '((pdf . nil) + (note . nil) + (link . "has:link") + (source . "has:link\\|has:pdf")) +#+end_src + *** Refreshing the library display :PROPERTIES: :CUSTOM_ID: refreshing-the-library-display From f14ec2579041d9336610812e8f5479f9d5d164fa Mon Sep 17 00:00:00 2001 From: Bruce D'Arcus Date: Mon, 10 May 2021 20:05:03 -0400 Subject: [PATCH 6/6] make note initial-value nil --- bibtex-actions.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bibtex-actions.el b/bibtex-actions.el index 41d362ea..4e76b391 100644 --- a/bibtex-actions.el +++ b/bibtex-actions.el @@ -99,7 +99,7 @@ manager like Zotero or JabRef." (defcustom bibtex-actions-initial-inputs '((pdf . "has:pdf") - (note . "has:note") + (note . nil) (link . "has:link") (source . "has:link\\|has:pdf")) "Alist defining the initial input for some bibtex open actions.