Preconditions and arguments should be used within :function
Simplify the definition of functions. Also add some preconditions to some functions, to enable saving only when the corresponding saving mode is enabled.
This commit is contained in:
parent
d61ba29a76
commit
273102a287
2 changed files with 23 additions and 14 deletions
|
@ -9,7 +9,9 @@ At moments like these, it's convenient to have a reasonably up to date state of
|
||||||
|
|
||||||
This package allows you to execute a function at a regular interval. To minimize any disturbance while you're working, a few seconds of idleness will trigger the execution of all save functions.
|
This package allows you to execute a function at a regular interval. To minimize any disturbance while you're working, a few seconds of idleness will trigger the execution of all save functions.
|
||||||
|
|
||||||
Supported packages:
|
* Supported packages
|
||||||
|
|
||||||
|
persist-state supports a number of packages out of the box:
|
||||||
|
|
||||||
#+begin_src elisp :exports results :results list
|
#+begin_src elisp :exports results :results list
|
||||||
(mapcar (lambda (package)
|
(mapcar (lambda (package)
|
||||||
|
|
|
@ -41,20 +41,30 @@
|
||||||
:group 'persist-state)
|
:group 'persist-state)
|
||||||
|
|
||||||
(defvar persist-state-supported-packages-alist
|
(defvar persist-state-supported-packages-alist
|
||||||
`((bookmark . (:function bookmark-save))
|
`((bookmark . (:function (lambda () (when bookmark-save-flag
|
||||||
(desktop . (:function desktop-save :args (desktop-path)))
|
(bookmark-save)))))
|
||||||
(em-hist . (:function eshell-save-some-history :label "Eshell history"))
|
|
||||||
(prescient . (_ :function prescient--save
|
(desktop . (:function (lambda () (when desktop-save-mode
|
||||||
:label "Prescient.el"
|
(desktop-save desktop-path)))))
|
||||||
:url "https://github.com/radian-software/prescient.el"))
|
|
||||||
|
(em-hist . (:function eshell-save-some-history
|
||||||
|
:label "Eshell history"))
|
||||||
|
|
||||||
|
(prescient . (:function (lambda () (when prescient-persist-mode
|
||||||
|
(prescient--save)))
|
||||||
|
:label "Prescient.el"
|
||||||
|
:url "https://github.com/radian-software/prescient.el"))
|
||||||
|
|
||||||
(recentf . (:function recentf-save-list))
|
(recentf . (:function recentf-save-list))
|
||||||
(savehist . (:function savehist-autosave)))
|
|
||||||
|
(savehist . (:function (lambda () (when savehist-mode
|
||||||
|
savehist-autosave)))))
|
||||||
"A list of packages supported by persist-state.
|
"A list of packages supported by persist-state.
|
||||||
|
|
||||||
Each package is a cons cell with the package name and a plist with:
|
Each package is a cons cell with the package name and a plist with:
|
||||||
- :function (mandatory): function to call to save state;
|
- :function (mandatory): function to call to save state;
|
||||||
- :args (optional): arguments to be passed to the function;
|
- :label (optional): a readable package name (for the README);
|
||||||
- :label (optional): a readable package name (for the README).")
|
- :url (optional): URL to the package.")
|
||||||
|
|
||||||
(defun persist-state--regularly-run-on-idle (interval idle-seconds f &rest args)
|
(defun persist-state--regularly-run-on-idle (interval idle-seconds f &rest args)
|
||||||
"Run function F with ARGS every INTERVAL seconds, plus IDLE-SECONDS."
|
"Run function F with ARGS every INTERVAL seconds, plus IDLE-SECONDS."
|
||||||
|
@ -79,10 +89,7 @@ is added as-is, otherwise it's wrapped in a lambda performing an
|
||||||
(with-eval-after-load (car package)
|
(with-eval-after-load (car package)
|
||||||
(let ((attrs (cdr package)))
|
(let ((attrs (cdr package)))
|
||||||
(add-to-list 'persist-state-saving-functions
|
(add-to-list 'persist-state-saving-functions
|
||||||
(if (plist-member attrs :args)
|
(plist-get attrs :function)))))
|
||||||
(lambda () (apply (plist-get attrs :function)
|
|
||||||
(plist-get attrs :args)))
|
|
||||||
(plist-get attrs :function))))))
|
|
||||||
persist-state-supported-packages-alist))
|
persist-state-supported-packages-alist))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
|
Loading…
Reference in a new issue