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 bibtex-actions-history #120

Merged
merged 16 commits into from
Apr 30, 2021
14 changes: 14 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@ Here's how to configure it to use =all-the-icons=:
:group 'all-the-icons-faces)
#+END_SRC

*** History and Predefined searches

=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:

#+begin_src emacs-lisp
(setq bibtex-actions-presets '("one search string" "another search string"))
#+end_src

Internally, this is using the minibuffer "future history" functionality available in =completing-read=, which you access in =selectrum= by using =M-n= from the prompt.

=Bibtex-actions= also preserves the history of your selections (see caveat below about multiple candidate selection though), also accessible in =selectrum=, but by using =M-p=.
You can save this history across sessions by adding =bibtex-actions-history= to =savehist-additional-variables=.

*** Proactive reloading of library
:PROPERTIES:
:CUSTOM_ID: proactive-reloading-of-library
Expand Down
18 changes: 17 additions & 1 deletion bibtex-actions.el
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ may be indicated with the same icon but a different face."
:group 'bibtex-actions
:type 'string)

;;; History, including future history list.

(defvar bibtex-actions-history nil
"Search history for `bibtex-actions'.")

(defcustom bibtex-actions-presets nil
"List of predefined searches."
:group 'bibtex-actions
:type '(repeat string))

;;; Keymap

(defvar bibtex-actions-map
Expand Down Expand Up @@ -123,7 +133,7 @@ candidate list"
(affixation-function . bibtex-actions--affixation)
(category . bibtex))
(complete-with-action action candidates string predicate)))
nil nil initial nil nil nil)))
nil nil initial '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)))))
Expand Down Expand Up @@ -213,6 +223,12 @@ If the cache is nil, this will load the cache."
(setq bibtex-actions--candidates-cache
(bibtex-actions--format-candidates)))

(defun bibtex-actions-insert-preset ()
"Prompt for and insert a predefined search."
(interactive)
(when-let ((search (completing-read "Preset: " bibtex-actions-presets)))
(insert search)))

;;; Formatting functions
;; NOTE this section will be removed, or dramatically simplified, if and
;; when this PR is merged:
Expand Down