Made package support more extensible and maintainable
This commit is contained in:
parent
a567abcf7c
commit
58f654c35d
2 changed files with 40 additions and 11 deletions
22
README.org
22
README.org
|
@ -5,9 +5,25 @@
|
||||||
|
|
||||||
I don't leave Emacs often, but sometimes Emacs leaves me.
|
I don't leave Emacs often, but sometimes Emacs leaves me.
|
||||||
|
|
||||||
At moments like these, it's convenient to have a reasonably up to date state of recent files, bookmarks, history variables, etc. saved.
|
At moments like these, it's convenient to have a reasonably up to date state of recent files, bookmarks, history variables, etc. available when you restart Emacs again.
|
||||||
|
|
||||||
This package contains allows you to execute a function at a regular interval, and then waits for a few seconds of idleness to actually execute the function.
|
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:
|
||||||
|
|
||||||
|
#+begin_src elisp :exports results :results list
|
||||||
|
(mapcar (lambda (package)
|
||||||
|
(or (plist-get (cdr package) :label)
|
||||||
|
(car package)))
|
||||||
|
persist-state-supported-packages-alist)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+RESULTS:
|
||||||
|
- bookmark
|
||||||
|
- desktop
|
||||||
|
- Eshell history
|
||||||
|
- recentf
|
||||||
|
- savehist
|
||||||
|
|
||||||
* Installation and usage
|
* Installation and usage
|
||||||
|
|
||||||
|
@ -29,6 +45,8 @@ Then, add functions to =persist-state-functions= which should be executed, e.g.
|
||||||
|
|
||||||
* Configuration
|
* Configuration
|
||||||
|
|
||||||
|
This table shows which variables can be customized.
|
||||||
|
|
||||||
#+begin_src emacs-lisp :exports results :results table :colnames '("Custom variable" "Description")
|
#+begin_src emacs-lisp :exports results :results table :colnames '("Custom variable" "Description")
|
||||||
(let ((rows))
|
(let ((rows))
|
||||||
(mapatoms
|
(mapatoms
|
||||||
|
|
|
@ -41,15 +41,17 @@
|
||||||
:group 'persist-state)
|
:group 'persist-state)
|
||||||
|
|
||||||
(defvar persist-state-supported-packages
|
(defvar persist-state-supported-packages
|
||||||
'((bookmark . bookmark-save)
|
`((bookmark . (:function bookmark-save))
|
||||||
(desktop . (lambda () (desktop-save (car desktop-path))))
|
(desktop . (:function desktop-save :args (desktop-path)))
|
||||||
(em-hist . eshell-save-some-history)
|
(em-hist . (:function eshell-save-some-history :label "Eshell history"))
|
||||||
(recentf . recentf-save-list)
|
(recentf . (:function recentf-save-list))
|
||||||
(savehist . savehist-autosave))
|
(savehist . (:function 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 the
|
Each package is a cons cell with the package name and a plist with:
|
||||||
function name that is responsible for saving 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).")
|
||||||
|
|
||||||
(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."
|
||||||
|
@ -65,10 +67,19 @@ function name that is responsible for saving state.")
|
||||||
(mapc 'funcall persist-state-saving-functions)))
|
(mapc 'funcall persist-state-saving-functions)))
|
||||||
|
|
||||||
(defun persist-state--enable-packages ()
|
(defun persist-state--enable-packages ()
|
||||||
"Enables all supported packages."
|
"Enables all supported packages.
|
||||||
|
|
||||||
|
If a package has no argumunts (no `:args' attribute, the function
|
||||||
|
is added as-is, otherwise it's wrapped in a lambda performing an
|
||||||
|
`apply' call.)"
|
||||||
(mapc (lambda (package)
|
(mapc (lambda (package)
|
||||||
(with-eval-after-load (car package)
|
(with-eval-after-load (car package)
|
||||||
(add-to-list 'persist-state-saving-functions (cdr package))))
|
(let ((attrs (cdr package)))
|
||||||
|
(add-to-list 'persist-state-saving-functions
|
||||||
|
(if (plist-member attrs :args)
|
||||||
|
(lambda () (apply (plist-get attrs :function)
|
||||||
|
(plist-get attrs :args)))
|
||||||
|
(plist-get attrs :function))))))
|
||||||
persist-state-supported-packages))
|
persist-state-supported-packages))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
|
Loading…
Reference in a new issue