update packages
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
;; Generated package description from persist.el -*- no-byte-compile: t -*-
|
||||
(define-package "persist" "0.6.1" "Persist Variables between Emacs Sessions" '((emacs "26.1")) :commit "5ea8f32ef50ce2b444d6918e17eedce9f74629af" :url "https://elpa.gnu.org/packages/persist.html" :authors '(("Phillip Lord" . "phillip.lord@russet.org.uk")) :maintainer '("Joseph Turner" . "persist-el@breatheoutbreathe.in"))
|
||||
(define-package "persist" "0.8" "Persist Variables between Emacs Sessions" '((emacs "26.1") (compat "30.0.2.0")) :commit "3b4b421d5185f2c33bae478aa057dff13701cc25" :url "https://elpa.gnu.org/packages/persist.html" :authors '(("Phillip Lord" . "phillip.lord@russet.org.uk")) :maintainer '("Joseph Turner" . "persist-el@breatheoutbreathe.in"))
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
;;; persist.el --- Persist Variables between Emacs Sessions -*- lexical-binding: t -*-
|
||||
|
||||
;; Copyright (C) 2019, 2024 Free Software Foundation, Inc.
|
||||
;; Copyright (C) 2019, 2024, 2025 Free Software Foundation, Inc.
|
||||
|
||||
;; Author: Phillip Lord <phillip.lord@russet.org.uk>
|
||||
;; Maintainer: Joseph Turner <persist-el@breatheoutbreathe.in>
|
||||
;; Package-Type: multi
|
||||
;; Package-Requires: ((emacs "26.1"))
|
||||
;; Version: 0.6.1
|
||||
;; Package-Requires: ((emacs "26.1") (compat "30.0.2.0"))
|
||||
;; Version: 0.8
|
||||
|
||||
;; The contents of this file are subject to the GPL License, Version 3.0.
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'compat)
|
||||
|
||||
(defvar persist--directory-location
|
||||
(locate-user-emacs-file "persist")
|
||||
"The location of persist directory.")
|
||||
@@ -64,18 +66,20 @@ variable is not set to the value.")
|
||||
(or (get symbol 'persist-location)
|
||||
persist--directory-location)))
|
||||
|
||||
(defun persist--defvar-1 (symbol location)
|
||||
(defun persist--defvar-1 (symbol location initvalue)
|
||||
"Set symbol up for persistence."
|
||||
(when location
|
||||
(persist-location symbol location))
|
||||
(persist-symbol symbol (symbol-value symbol))
|
||||
(persist-symbol symbol initvalue)
|
||||
(persist-load symbol))
|
||||
|
||||
(defmacro persist-defvar (symbol initvalue docstring &optional location)
|
||||
"Define SYMBOL as a persistent variable and return SYMBOL.
|
||||
|
||||
This form is nearly equivalent to `defvar', except that the
|
||||
variable persists between Emacs sessions.
|
||||
variable persists between Emacs sessions. When this form is
|
||||
evaluated, the variable's default value is always set to
|
||||
INITVALUE.
|
||||
|
||||
It does not support the optional parameters. Both INITVALUE and
|
||||
DOCSTRING need to be given."
|
||||
@@ -93,9 +97,12 @@ DOCSTRING need to be given."
|
||||
;; Define inside progn so the byte compiler sees defvar
|
||||
`(progn
|
||||
(defvar ,symbol ,initvalue ,docstring)
|
||||
;; Access initvalue through its symbol because the defvar form
|
||||
;; has to stay at first level within a progn
|
||||
(persist--defvar-1 ',symbol ,location)
|
||||
;; `defvar' must stay at top level within `progn'. Pass init
|
||||
;; value to `persist--defvar-1' since the `defvar' form may not
|
||||
;; set the symbol's value and we don't want to set the
|
||||
;; persist-default property to the current value of the symbol.
|
||||
;; See bug#75779 for details.
|
||||
(persist--defvar-1 ',symbol ,location ,initvalue)
|
||||
',symbol))
|
||||
|
||||
(defun persist-location (symbol directory)
|
||||
@@ -106,23 +113,19 @@ to persist a variable, you will normally need to call
|
||||
`persist-load' to load a previously saved location."
|
||||
(put symbol 'persist-location (expand-file-name directory)))
|
||||
|
||||
(defun persist-symbol (symbol &optional initvalue)
|
||||
(defun persist-symbol (symbol initvalue)
|
||||
"Make SYMBOL a persistent variable.
|
||||
|
||||
If non-nil, INITVALUE is the value to which SYMBOL will be set if
|
||||
`persist-reset' is called. Otherwise, the INITVALUE will be the
|
||||
current `symbol-value' of SYMBOL.
|
||||
|
||||
INITVALUE is set for the session and will itself not persist
|
||||
INITVALUE is the value to which SYMBOL will be set if `persist-reset' is
|
||||
called. INITVALUE is set for the session and will itself not persist
|
||||
across sessions.
|
||||
|
||||
This does force the loading of value from this directory, so to
|
||||
persist a variable, you will normally need to call `persist-load'
|
||||
to load a previously saved location."
|
||||
(let ((initvalue (or initvalue (symbol-value symbol))))
|
||||
(add-to-list 'persist--symbols symbol)
|
||||
(put symbol 'persist t)
|
||||
(put symbol 'persist-default (persist-copy initvalue))))
|
||||
(add-to-list 'persist--symbols symbol)
|
||||
(put symbol 'persist t)
|
||||
(put symbol 'persist-default (persist-copy initvalue)))
|
||||
|
||||
(defun persist--persistant-p (symbol)
|
||||
"Return non-nil if SYMBOL is a persistent variable."
|
||||
@@ -211,39 +214,11 @@ tables. In that case, the following are compared:
|
||||
t))
|
||||
(equal a b)))
|
||||
|
||||
(defun persist-copy-tree (tree &optional vectors-and-records)
|
||||
"Make a copy of TREE.
|
||||
If TREE is a cons cell, this recursively copies both its car and its cdr.
|
||||
Contrast to `copy-sequence', which copies only along the cdrs.
|
||||
With the second argument VECTORS-AND-RECORDS non-nil, this
|
||||
traverses and copies vectors and records as well as conses."
|
||||
(declare (side-effect-free error-free))
|
||||
(if (consp tree)
|
||||
(let (result)
|
||||
(while (consp tree)
|
||||
(let ((newcar (car tree)))
|
||||
(if (or (consp (car tree))
|
||||
(and vectors-and-records
|
||||
(or (vectorp (car tree)) (recordp (car tree)))))
|
||||
(setq newcar (persist-copy-tree (car tree) vectors-and-records)))
|
||||
(push newcar result))
|
||||
(setq tree (cdr tree)))
|
||||
(nconc (nreverse result)
|
||||
(if (and vectors-and-records (or (vectorp tree) (recordp tree)))
|
||||
(persist-copy-tree tree vectors-and-records)
|
||||
tree)))
|
||||
(if (and vectors-and-records (or (vectorp tree) (recordp tree)))
|
||||
(let ((i (length (setq tree (copy-sequence tree)))))
|
||||
(while (>= (setq i (1- i)) 0)
|
||||
(aset tree i (persist-copy-tree (aref tree i) vectors-and-records)))
|
||||
tree)
|
||||
tree)))
|
||||
|
||||
(defun persist-copy (obj)
|
||||
"Return copy of OBJ."
|
||||
(if (hash-table-p obj)
|
||||
(copy-hash-table obj)
|
||||
(persist-copy-tree obj t)))
|
||||
(compat-call copy-tree obj t)))
|
||||
|
||||
(provide 'persist)
|
||||
;;; persist.el ends here
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
(let ((persist--symbols nil)
|
||||
(sym (cl-gensym)))
|
||||
(persist-symbol sym 10)
|
||||
(seq-contains persist--symbols sym))))
|
||||
(seq-contains-p persist--symbols sym))))
|
||||
|
||||
(ert-deftest test-persist-save-only-persistant ()
|
||||
;; do not save not persist variables
|
||||
@@ -67,7 +67,9 @@
|
||||
(default (copy-hash-table hash)))
|
||||
(persist-test-persist-save hash default
|
||||
(puthash 'foo "bar" (symbol-value sym))
|
||||
"#s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8125 data (foo \"bar\"))")))
|
||||
(if (<= 30 emacs-major-version)
|
||||
"#s(hash-table data (foo \"bar\"))\n"
|
||||
"#s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8125 data (foo \"bar\"))"))))
|
||||
|
||||
(ert-deftest test-persist-save-record ()
|
||||
"Test saving record."
|
||||
@@ -108,6 +110,18 @@
|
||||
(should (= 20
|
||||
(persist-default 'test-persist-variable)))))
|
||||
|
||||
(ert-deftest test-persist-default-set-to-initvalue ()
|
||||
(persist-defvar test-persist-variable-default 'INIT "Docstring.")
|
||||
(setq test-persist-variable-default 'CHANGED)
|
||||
(persist-defvar test-persist-variable-default 'INIT "Docstring.")
|
||||
(should (equal 'INIT (persist-default 'test-persist-variable-default))))
|
||||
|
||||
(ert-deftest test-persist-default-nil-initvalue ()
|
||||
(persist-defvar test-persist-variable-default nil "Docstring.")
|
||||
(setq test-persist-variable-default 'CHANGED)
|
||||
(persist-defvar test-persist-variable-default nil "Docstring.")
|
||||
(should (null (persist-default 'test-persist-variable-default))))
|
||||
|
||||
(ert-deftest test-persist-location ()
|
||||
(unwind-protect
|
||||
(let ((sym (cl-gensym)))
|
||||
@@ -137,10 +151,17 @@
|
||||
|
||||
(ert-deftest test-persist-reset ()
|
||||
"Symbol should be reset to a copy of the default."
|
||||
(with-local-temp-persist
|
||||
(persist-defvar persist--test-reset-variable (make-hash-table) "docstring")
|
||||
(should-not (eq persist--test-reset-variable
|
||||
(persist-default 'persist--test-reset-variable)))
|
||||
(persist-reset 'persist--test-reset-variable)
|
||||
(should-not (eq persist--test-reset-variable
|
||||
(persist-default 'persist--test-reset-variable)))))
|
||||
(let ((initial-value (make-hash-table)))
|
||||
(with-local-temp-persist
|
||||
(persist-defvar persist--test-reset-variable initial-value "docstring")
|
||||
(should-not (eq persist--test-reset-variable
|
||||
(persist-default 'persist--test-reset-variable)))
|
||||
(should-not (eq persist--test-reset-variable initial-value))
|
||||
(should-not (eq initial-value
|
||||
(persist-default 'persist--test-reset-variable)))
|
||||
(persist-reset 'persist--test-reset-variable)
|
||||
(should-not (eq persist--test-reset-variable
|
||||
(persist-default 'persist--test-reset-variable)))
|
||||
(should-not (eq persist--test-reset-variable initial-value))
|
||||
(should-not (eq initial-value
|
||||
(persist-default 'persist--test-reset-variable))))))
|
||||
|
||||
Reference in New Issue
Block a user