Commit Graph

35 Commits

Author SHA1 Message Date
Ihor Radchenko 1084566322
Fix org-persist-unregister 2022-01-29 17:04:41 +08:00
Ihor Radchenko 703df9310a
org-persist: Cleanup on removal and version mismatch
* lisp/org-persist.el (org-persist--remove-from-index):
(org-persist-load:index): Garbage collect caches.
2022-01-29 17:04:18 +08:00
Ihor Radchenko dafa32da49
org-persist: Update index version 2022-01-29 17:04:11 +08:00
Ihor Radchenko 1c79af13df
org-persist-gc: Fix when expiry is days and data is freshly created 2022-01-29 17:03:46 +08:00
Ihor Radchenko 7c2d93560c
org-persist-default-expiry: Introduce and change default
* lisp/org-persist.el: New customisation controlling default persist
data expiry.  Defaults to 30 days from last access.
(org-persist-register): Change default value of `:expiry' key to
`org-persist-default-expiry'.
2022-01-29 17:03:09 +08:00
Ihor Radchenko 2a4e5a8e58
org-persist--normalize-associated: Use cache to calculate buffer hash 2022-01-29 16:56:14 +08:00
Ihor Radchenko edd7f2962f
org-persist: Reimplement using more generic approach 2022-01-29 16:55:57 +08:00
Kyle Meyer b8656a2cef Update main-only copyright years 2022-01-01 15:25:06 -05:00
Ihor Radchenko d012350dad
org-persist: Report read/write duration
* lisp/org-persist.el (org-persist--report-time): New variable
controlling time reporting.  The default value is to report if
read/write opeartion takes over 0.5 sec.
(org-persist-write):
(org-persist-read): Display message about read/write duration for each
variable according to `org-persist--report-time'.
2021-12-25 23:36:26 +08:00
Ihor Radchenko e0b1a05460
org-persist-unregister: Fix when BUFFER is not 'all
* lisp/org-persist.el (org-persist-unregister): Use `string=' instead
of `eq' to compare strings.  `eq' always returns nil here.
2021-12-22 10:22:04 +08:00
Ihor Radchenko 0b670aa8e8
org-persist: Support old Emacs without file-attribute-inode-number
* lisp/org-persist.el (org-persist--get-index): Check is
`file-attribute-inode-number' function exists.  It was not there in
Emacs 25.

Fixes https://list.orgmode.org/CAJcAo8s21R1dRrxpaHV=h68RtWctLd6giFskw1vpt9fQh81dDw@mail.gmail.com/T/#u
2021-12-20 23:00:01 +08:00
Ihor Radchenko 344b99070f
org-persist.el: Make org-persist-directory a custom variable
* lisp/org-persist.el (org-persist): Create org-persist customisation
group.
(org-persist-directory): Convert into defcustom.
2021-12-20 23:00:00 +08:00
Ihor Radchenko fefb867d91
org-persist-write-all: Fix when BUFFER is nil 2021-11-15 19:39:17 +08:00
Ihor Radchenko 876e813334
org-persist.el: Fix Emacs versions where xdg.el is not available
* lisp/org-persist.el (org-persist-directory): Make `xdg-cache-home'
call optional.  Prefer cache directory in `user-emacs-directory' when
the cache already exists there.

Fixes https://list.orgmode.org/CAFqubHf+WpuNEEapKcG94WjHFcRxVSF+j-7Ut3b_roMfKQchhg@mail.gmail.com/T/#m99c63439a745c07fd7c30cde0b49b3d5bd1757f0
2021-11-10 09:45:16 +08:00
Ihor Radchenko 7a6f48ab4a
org-persist-read: Do not raise warning on known read error 2021-11-01 20:47:11 +08:00
Ihor Radchenko 6621ee32e4
org-persist.el: Do not try to follow XDG on Windows
* lisp/org-persist.el (org-persist-directory): `xdg-cache-home'
apparently returns "~/.cache" even on Windows.  Fallback to
`user-emacs-directory' when the directory returned by `xdg-cache-home'
does not exist.

Reported in https://list.orgmode.org/CAPY3P0RWTkUv_5q0aJjgmpaDGzxYYrs0z4vyEF2Sxpua7BtztA@mail.gmail.com/T/#u
2021-11-01 19:28:16 +08:00
Ihor Radchenko 1b2d06880f
org-persist.el: Do not write global variables on buffer kill
* lisp/org-persist.el (org-persist-write-all): Prevent writing global
variables when BUFFER arg is provided.
(org-persist-gc): Handle case when :persist-file is set to nil in the
index.

Fixes https://list.orgmode.org/DB9PR08MB66336CDF0F43DE3DB1D08649A3869@DB9PR08MB6633.eurprd08.prod.outlook.com/T/#m40fcc5ea8ba0ef52518a58713cf9ad3d1fffa33d
2021-10-28 22:32:50 +08:00
Ihor Radchenko 5abd149cf1
org-persist-write: Do not try to write cache when killing indirect buffer 2021-10-28 09:11:14 +08:00
Ihor Radchenko 5ca866d08a
org-persist.el: Detect buffer-locals vars for moved files
* lisp/org-persist.el (org-persist--get-index): Match buffer inode and
hash if path does not match.
(org-persist-read-all): Do not require file path match before trying
to read local variables.
(org-persist-read): Do not try to read non-existing data.
2021-10-27 22:51:43 +08:00
Ihor Radchenko 5315773e8a
Fix "Variable binding depth exceeds max-specpdl-size"
* lisp/org-persist.el (org-persist-register): Fix `add-hook' args.

Reported in:
https://list.orgmode.org/8735ouxz6y.fsf@yandex.com/
https://list.orgmode.org/1012598.1634829727@apollo2.minshall.org/T/#u
2021-10-21 23:58:03 +08:00
Ihor Radchenko a78282746d
org-persist.el/org-persist--read-index: Provide warning if reader fails
* lisp/org-persist.el (org-persist--read-index): Inform user when
reader fails to read existing index file.
2021-10-21 14:57:42 +08:00
Ihor Radchenko 849dd68b27
org-persist.el/org-persist--read-index: Handle reader errors
* lisp/org-persist.el (org-persist--read-index): Do not emit
unrecoverable error if index file is corrupted (i.e. empty).
2021-10-20 20:33:55 +08:00
Ihor Radchenko b9d0d06ca5
org-persist.el: Do not use hook depth unnecessarily
* lisp/org-persist.el: Do not use hook depth to define the order of
`org-persist-gc' and `org-persist-write-all'.  Rely on default
behaviour of `add-hook' instead.
(org-persist-register): Use default hook depth.
2021-10-20 14:17:44 +08:00
Ihor Radchenko 350fa065b4
org-persist.el/org-persist--get-index: Do not show warning
* lisp/org-persist.el (org-persist--read-index): Disable warning when
`org-persist-index-file' does not exist.  The warning would spam the
users with disabled cache persistance unnecessarily.

Link: https://list.orgmode.org/87o87kb64s.fsf@yandex.com/T/#u
2021-10-20 14:14:46 +08:00
Ihor Radchenko ccb0271e1a
org-persist.el: Do not add write hooks when there is no write access 2021-10-19 20:17:27 +08:00
Ihor Radchenko 2b33ef3c97
org-persist.el/org-persist-write: Do not write when no write access 2021-10-19 20:10:27 +08:00
Ihor Radchenko 46da64c4cf
org-persist.el: Fix `add-hook' priority argument 2021-10-19 20:07:31 +08:00
Ihor Radchenko c130f71036
org-persist.el: Fix typo 2021-10-19 20:07:18 +08:00
Ihor Radchenko bad854d5fa
org-persist.el: Catch write errors
* lisp/org-persist.el (org-persist--get-index): Check index file.
(org-persist--read-index): Warn when index file is missing.
(org-persist-write): Report write access errors.
2021-10-19 20:06:08 +08:00
Ihor Radchenko 3b48224994
org-persist.el: Rename `org-persist-path' to `org-persist-directory' 2021-10-19 20:05:30 +08:00
Ihor Radchenko 0e912bd288
org-persist.el: Make sure that org-persist-path is absolute 2021-10-18 13:37:02 +08:00
Ihor Radchenko 004ac14a5b
Fix compatibility with Emacs 26
* lisp/org-compat.el (org-file-name-concat): Do not use
`string-empty-p'.
(combine-change-calls): Create a stub when `combine-change-calls' were
not yet available.
(org-replace-buffer-contents): Add compatibility function for
`replace-buffer-contents'.

* lisp/org-element.el (org-element--current-element): Do not use
`if-let'.
* lisp/org-persist.el (org-persist-gc): Do not use `when-let'.
* lisp/org-plot.el (org-plot/gnuplot): Do not use `if-let'.
* lisp/org-src.el (org-edit-src-save, org-edit-src-exit): Use
`org-replace-buffer-contents'.

* lisp/org.el (org-narrow-to-subtree, org--property-local-values,
org-entry-get-with-inheritance, org-in-commented-heading-p,
org-up-heading-safe, org-goto-first-child): Do not use
`if-let'/`when-let'.

* testing/org-test.el (org-test-at-time): Fallback to old
`decode-time' specification in older Emacs.
2021-10-17 14:34:10 +08:00
Ihor Radchenko eeb04504ef
Use XDG cache dir as default dir for cache persistance
* lisp/org-persist.el (org-persist-path): Change default dir to XDG
cache dir and fall back to `user-emacs-directory' as the last resort.
2021-10-17 12:24:32 +08:00
Ihor Radchenko 07ca988bb4
Fix compatibility with Emacs 27
* lisp/org-compat.el: Remove `length>' alias
* lisp/org-element.el (org-element-cache-map): Suppress compiler
warning.
* lisp/org-persist.el (org-persist-register): Do not `push' into
`plist-get'.  Not supported yet in Emacs 27.
(org-persist-unregister): Do not use `length>'.  Use
`org-directory-empty-p'.
(org-persist-gc): Use `org-directory-empty-p'.
2021-10-17 11:44:33 +08:00
Ihor Radchenko 6933c1ad78
lisp/org-persist.el: New library to store data across sessions 2021-10-16 21:16:11 +08:00