Commit graph

146 commits

Author SHA1 Message Date
Ihor Radchenko e2366ac283
* lisp/org-persist.el: Do not litter /tmp when native compiling
Remove the directory created by `make-temp-file' when Emacs is called
with -Q command line argument.  Only use the return value as the
directory to be created when something is actually stored by
org-persist while running Emacs.

Reported-by: William Denton <wtd@pobox.com>
Link: https://orgmode.org/list/alpine.DEB.2.22.394.2212211213480.270543@shell3.miskatonic.org
2022-12-21 21:43:42 +03:00
Kyle Meyer d93df21835 Merge branch 'bugfix' 2022-12-17 17:05:23 -05:00
Kyle Meyer 47d1299e48 Merge branch 'km/from-emacs-29' into bugfix 2022-12-17 17:03:48 -05:00
Stefan Kangas c8b0a0d1b6 Backport commit a15cd5504 from Emacs
; Don't quote nil in comments
a15cd55044c6bb4d4e9f9aec23b8b5b9cbcb38ac
Stefan Kangas
Thu Dec 15 02:35:00 2022 +0100
2022-12-17 17:01:59 -05:00
Ihor Radchenko afe5f3f692
org-persist-gc: Fix edge case
* lisp/org-persist.el (org-persist-gc): Do not err when
`org-persist-directory' is absent.
2022-12-17 12:45:46 +03:00
Ihor Radchenko d52a775369
Merge branch 'bugfix'
Note the resolved conflict.
2022-12-17 12:45:14 +03:00
Ihor Radchenko 2944a2152d
org-persist: Use temporary index for emacs -Q
* lisp/org-persist.el (org-persist--disable-when-emacs-Q): Rename
`org-persist-disable-when-emacs-Q' to internal variable.  Update the
docstring.
(org-persist-read):
(org-persist-write):
(org-persist-gc): Do not disable persistence.  Persistence is
necessary for remote file caching to work within a single Emacs
session.  Instead, use temporary directory as index for emacs -Q.
2022-12-17 12:39:35 +03:00
Ihor Radchenko aa86ed534f
org-persist-write-all: Do not create index with no containers
* lisp/org-persist.el (org-persist-write-all): Do not create
`org-persist-directory' when index does not contain any data except
index version.

Link: https://orgmode.org/list/875yedw0ib.fsf@localhost
2022-12-17 12:36:51 +03:00
Timothy 555dacfa8b
org-persist: Merge index with index file content
* lisp/org-persist.el (org-persist-write, org-persist-load,
org-persist-write:index, org-persist-load:index): Check if the index
file has been externally updated since loading, and if so try to perform
basic merging of the current index file contents and the loaded index
before performing GC or overwriting the index file.
(org-persist--index-age, org-persist--merge-index-with-disk,
org-persist--merge-index): New variable and functions to keep track of
index age and perform merging.
2022-12-14 23:03:04 +08:00
Timothy 402d2421d9
org-persist: Do not re-download url files on write
* lisp/org-persist.el (org-persist-write:url): Since the url write
function is called as part of `org-persist-write-all', it is worth
adding a check to avoid re-downloading the file if a file already exists
in the expected location.
2022-12-14 12:35:12 +03:00
Timothy 6a126e40a7
org-persist: Ensure index instantiated before read
* lisp/org-persist.el (org-persist-read): If the index is empty at the
start of `org-persist-read', load it before continuing.
2022-12-14 12:33:39 +03:00
Timothy 92ac00051a
org-persist: Fix omitted argument
* lisp/org-persist.el (org-persist-associated-files:file): Add the
"container" argument used but omitted from the function declaration of
`org-persist-associated-files:file' in 534633d508.
2022-12-12 01:13:23 +08:00
Timothy 1a9d0850b6
org-persist: Do not re-download url files on write
* lisp/org-persist.el (org-persist-write:url): Since the url write
function is called as part of `org-persist-write-all', it is worth
adding a check to avoid re-downloading the file if a file already exists
in the expected location.
2022-12-11 15:47:33 +08:00
Timothy 534633d508
org-persist: Use associated file functions for GC
* lisp/org-persist.el (org-persist-gc, org-persist--remove-from-index,
org-persist-gc:file, org-persist-gc:url, org-persist-gc:version,
org-persist-gc:url, org-persist-associated-files:generic,
org-persist-associated-files:url, org-persist-associated-files:elisp,
org-persist-associated-files:index,
org-persist-associated-files:version,
org-persist-associated-files:file): Use associated files for GC, and
move the associated files functions into the public
namespace (i.e. remove the double dash).
2022-12-11 15:47:33 +08:00
Timothy 8b8a65ed02
org-persist: Introduce "associated files" for GC
* lisp/org-persist.el (org-persist-gc, org-persist--associated-files,
org-persist--associated-files:url): The url container stores downloaded
files separately within `org-persist-directory', which means that
`org-persist-gc' picks them up as "orphan files" and deletes them every
time it is called.  To avoid this collateral damage, a new family of
collection-specific functions is introduced,
"org-persist--associated-files:COLLECTION".  This allows collections to
tell GC about associated files that should be left alone, and is used
for url collections to preserve downloaded files.
2022-12-11 15:47:33 +08:00
Timothy c91226354a
org-persist: Fix attempted mapc-ing of macro
* lisp/org-persist.el (org-persist--gc-persist-file): Redefine
`org-persist--gc-persist-file' as a function so it can be mapc'd in
`org-persist-gc'.
2022-12-11 15:47:33 +08:00
Timothy 47654f844d
org-persist: Fix number of remote files kept
* lisp/org-persist.el (org-persist-gc): The `org-persist-remote-files'
documentation states that when set to a number (n) it will keep that
many files.  However, since a <= comparison is used with setting the
expired status of the files every remote file from n-th file onwards
/inclusive/ is marked as expired, and so only n-1 files were actually
kept.  With a less-than operator, the behaviour will actually match the
docstring.
2022-12-11 15:47:33 +08:00
Timothy e663b90fe5
org-persist: Fix unconditional gc of urls
* lisp/org-persist.el (org-persist-gc): The :file association of URL
containers lead to `file-exists-p' being called on them, which always
returns nil, causing URL containers to always be garbage collected.
Since the :file entry doesn't really represent a filesystem object, we
now check if the container is url and if so prevent the :file
association from being used in gc checks.
2022-12-11 15:47:33 +08:00
Timothy 3b1e7af166
org-persist: Ensure index instantiated before read
* lisp/org-persist.el (org-persist-read): If the index is empty at the
start of `org-persist-read', load it before continuing.
2022-12-11 15:47:33 +08:00
Timothy 5b076f5057
org-persist: Add missing end quote to docstrings
* lisp/org-persist.el (org-persist--load-index,
org-persist--save-index): Add missing end quote to the docstrings.
2022-12-11 15:47:33 +08:00
Ihor Radchenko 4cb39ba282
org-persist: Garbage-collect files outside index
* lisp/org-persist.el (org-persist-gc): Remove files from
`org-persist-directory' that are not listed in the index.  Update the
docstring accordingly.
2022-12-10 14:53:25 +03:00
Ihor Radchenko 3176ed9052
org-persist: Never write data associated with encrypted files
* lisp/org-persist.el (org-persist-write): Do not write data
associated with gpg-encrypted files.  This will avoid data leakage.
(org-persist--storage-version): Bump storage version to invalidate
previously stored, potentially leaked, data.

Reported-by: Clément Pit-Claudel <clement.pitclaudel@live.com>
2022-12-07 16:05:21 +03:00
Stefan Kangas c8ad9e4b28 Backport commit 8617edfff from Emacs
; Fix typos
8617edfffd07eb80561b4de6a37c5b0b5f442e07
Stefan Kangas
Wed Nov 30 16:59:41 2022 +0100
2022-11-30 17:19:12 -05:00
Mattias Engdegård 7ba099a3fd Backport commit c3466099c from Emacs
* lisp/org-element.el (org-element--get-node-properties):
Escape literal `+`.
* lisp/org-persist.el (org-persist-load:index):
Replace line-start with string-start when the latter is meant.

Org regexp style fixes
c3466099c5f44c52ec73a1bbbb2b42de6f29ac7f
Mattias Engdegård
Wed Nov 30 13:23:38 2022 +0100
2022-11-30 08:55:24 -05:00
Ihor Radchenko 5a10517d02
Add missing :package-version tags in changed `defcustom'
* lisp/ob-clojure.el (ob-clojure-babashka-command):
(ob-clojure-nbb-command):
* lisp/ob-exp.el (org-babel-exp-code-template):
* lisp/ob-latex.el (org-babel-latex-pdf-svg-process):
* lisp/org-agenda.el (org-agenda-show-outline-path):
* lisp/org-capture.el (org-capture-templates):
* lisp/org-clock.el (org-clocktable-defaults):
* lisp/org-persist.el (org-persist-directory):
(org-persist-remote-files):
(org-persist-default-expiry):
* lisp/org-refile.el (org-refile-use-outline-path):
* lisp/org-src.el (org-src-lang-modes):
* lisp/org.el (org-resource-download-policy):
(org-safe-remote-resources):
(org-time-stamp-custom-formats):
(org-property-separators):
(org-preview-latex-process-alist):
(org-structure-template-alist):
* lisp/ox-latex.el (org-latex-inline-image-rules):
(org-latex-src-block-backend):
(org-latex-engraved-options):
(org-latex-engraved-theme):
* lisp/ox-md.el (org-md-toplevel-hlevel):
* lisp/ox-texinfo.el (org-texinfo-with-latex): Add :package-version
keywords to the new custom options, and those with the value or
meaning changed.
2022-11-13 15:29:15 +08:00
Ihor Radchenko e81a094383
Assert all the Org files to load the same Org version
* lisp/org-compat.el (org-assert-version): New macro comparing Org
version at compile time and laod time.

Add `org-assert-version' call to all files:

* lisp/org-macs.el:
* lisp/org-crypt.el:
* lisp/org-ctags.el:
* lisp/org-cycle.el:
* lisp/org-datetree.el:
* lisp/org-duration.el:
* lisp/org-element.el (avl-tree):
* lisp/org-entities.el:
* lisp/org-faces.el:
* lisp/org-feed.el:
* lisp/org-fold-core.el:
* lisp/org-fold.el:
* lisp/org-footnote.el:
* lisp/org-goto.el:
* lisp/org-habit.el:
* lisp/org-id.el:
* lisp/org-indent.el:
* lisp/org-inlinetask.el:
* lisp/org-keys.el:
* lisp/org-lint.el:
* lisp/org-list.el:
* lisp/org-macro.el:
* lisp/org-mobile.el:
* lisp/org-mouse.el:
* lisp/org-num.el:
* lisp/org-pcomplete.el:
* lisp/org-persist.el:
* lisp/org-plot.el:
* lisp/org-protocol.el:
* lisp/org-refile.el:
* lisp/org-src.el:
* lisp/org-table.el:
* lisp/org-tempo.el:
* lisp/org-timer.el:
* lisp/org.el:
* lisp/ox-ascii.el:
* lisp/ox-beamer.el:
* lisp/ox-html.el:
* lisp/ox-icalendar.el:
* lisp/ox-koma-letter.el:
* lisp/ox-latex.el:
* lisp/ox-man.el:
* lisp/ox-md.el:
* lisp/ox-odt.el:
* lisp/ox-org.el:
* lisp/ox-publish.el:
* lisp/ox-texinfo.el:
* lisp/ox.el:
2022-09-04 12:24:55 +08:00
Ihor Radchenko 22de2e26e7
Fix Emacs 26 compatibility
* lisp/oc-biblatex.el (org-cite-biblatex-export-citation): Do not use
`seq-first'.
* lisp/org-persist.el (org-persist-collection-let): Suppress warnings.
* lisp/ox-latex.el (org-latex-src--engrave-mathescape-p): Do not use
`if-let'.
(org-latex-src--engrave-code): Do not use `string-trim-right'.
* lisp/ox.el (org-export-link-localise): Add require for subr-x for
`thread-first'.
2022-07-24 20:57:07 +08:00
TEC 0583a0c5ea
org: Add setting for remote file download policy
* lisp/org.el (org-resource-download-policy, org-safe-remote-resources):
Two new customisations to configure the policy for downloading remote
resources.
(org--should-fetch-remote-resource-p, org--safe-remote-resource-p,
org--confirm-resource-safe): Introduce the new function
`org--should-fetch-remote-resource-p' for internal use determining
whether a remote resource should be downloaded according to the download
policy.  This function makes use of two helper functions,
`org--safe-remote-resource-p' and `org--confirm-resource-safe'.
(org-file-contents): Apply `org--safe-remote-resource-p' to file
downloading.

* lisp/org-persist.el (org-persist-write): Apply
`org--safe-remote-resource-p' to url downloading.

* lisp/org-attach.el (org-attach-attach, org-attach-url): Apply
`org--safe-remote-resource-p' to url downloading.
2022-07-16 17:46:01 +08:00
Stefan Kangas 41e19f1d7a
; Fix typos 2022-07-01 17:42:52 +08:00
Ihor Radchenko 26878e28e7
org-persist: Bump storage version to ignore bugged persisted data
* lisp/org-persist.el (org-persist--storage-version): Bump version to
avoid loading recently broken persisted element cache.
2022-06-29 13:49:34 +08:00
Ihor Radchenko d788fe9927
org-persist: Remove read cache introduced in f77800c68
* lisp/org-persist.el (org-persist--read-cache): Remove variable.
(org-persist-read):
(org-persist-write): Do not use `org-persist--read-cache'.  Using
`sx-hash-equal' as unique key indicating as-read data is not
reliable for deeply nested structures like `org-element--cache'.  The
`sx-hash-equal' returns the same value regardless of the cache
contents.  See Emacs Bug#56255.
2022-06-29 09:06:12 +08:00
Ihor Radchenko f77800c68b
org-persist: Avoid overwriting / re-reading unchanged persisted data
* lisp/org-persist.el (org-persist--read-cache):
(org-persist--write-cache): New variables holding previously written /
read data.
(org-persist-read): Avoid re-reading data from FS when the writing has
been performed in the same Emacs session.
(org-persist-write): Do not overwrite unchanged data.
2022-06-21 09:46:59 +08:00
Ihor Radchenko d687aa1786
org-persist: Display read errors in echo area
* lisp/org-persist.el (org-persist--read-elisp-file): Do not silently
ignore "Invalid read syntax" error.  Report it via message.  Yet
making the error less intrusive compared to `warn'.
2022-06-21 09:46:58 +08:00
Ihor Radchenko 1c54d75cca
org-persist--gc-expired-p: Fix expiry check
* lisp/org-persist.el (org-persist--gc-expired-p): Fix comparison when
expiry date is set to number of days.  The old code flipped the check
and treated all the recent entries as expired.
2022-06-21 09:46:57 +08:00
Ihor Radchenko 9b00f4bf1d
org-persist: Fix expiry check
* lisp/org-persist.el (org-persist--gc-expired-p): Fix incorrect plist
key.
2022-06-17 19:23:28 +08:00
Robert Pluim 3baac35b55 Don't quote symbols in defcustom types
* lisp/org-fold-core.el (org-fold-core-style):
* lisp/org-persist.el (org-persist-remote-files):
(org-persist-default-expiry):
Don't quote the symbol given as value for a const.
2022-06-14 16:05:17 +03:00
Leo Vivier cde5c5d78f
lisp/org-persist.el (org-persist-gc): Fix pcase pattern
* lisp/org-persist.el (org-persist-gc): Fix pcase pattern.

Otherwise, `(pred #'numberp)' expands to `(function numberp foo)'
where foo is the first arg of pcase.
2022-06-04 19:13:58 +08:00
Ihor Radchenko b18635f745
org-persist: Disable when Emacs is called with -Q arg
* lisp/org-persist.el (org-persist-disable-when-emacs-Q): New
variable.
(org-persist-gc):
(org-persist-read):
(org-persist-write): Do nothing when
`org-persist-disable-when-emacs-Q' is non-nil and
`emacs-user-directory' is nil.
2022-06-02 11:06:53 +08:00
Stefan Monnier 6d73cd34a0 Replace all uses of the old defadvice with the new advice-add
* lisp/org.el (org-run-like-in-org-mode): Strength reduce `eval`
to `cl-progv`.
(org--check-org-structure-template-alist): Strength reduce `eval`
to `symbol-value`.
(org-map-entries, org-eval-in-calendar, org-diary-sexp-entry):
Make sure we use the new lexically scoped dialect.
(org--math-always-on): New function, extracted from advice.
(org-cdlatex-mode): Use it with `advice-add`.
(org-self-insert-command): Simplify `and`+`listp` into `consp`.
(org-submit-bug-report):
Make sure we use the new lexically scoped dialect.

* lisp/org-protocol.el (org-protocol-convert-query-to-plist):
Use `cl-mapcan`.
(org--protocol-detect-protocol-server): New function, extracted
from advice.
(server-visit-files): Use it with `advice-add`.

* lisp/org-mouse.el (org--mouse-dnd-insert-text): New function, extracted
from advice.
(dnd-insert-text): Use it with `advice-add`.
(org--mouse-dnd-open-file): New function, extracted from advice.
(dnd-open-file): Use it with `advice-add`.
(org--mouse-open-at-point): New function, extracted from advice.
(org-mode-hook): Advise `org-open-at-point` with `advice-add`.

* lisp/org-ctags.el (org--ctags-load-tag-list): New function, extracted
from advice.
(visit-tags-table): Use it with `advice-add`.
(org--ctags-set-org-mark-before-finding-tag): New function, extracted
from advice.
(xref-find-definitions): Use it with `advice-add`.

* lisp/org-compat.el (org-bookmark-jump-unhide): Accept (unused) args.
(save-place-find-file-hook): Use `advice-add`.
(org--ecb-show-context): New function, extracted from advice.
(ecb-method-clicked): Use it with `advice-add`.
(org-mark-jump-unhide): Accept (unused) args.
(pop-to-mark-command, exchange-point-and-mark, pop-global-mark):
Use `advice-add`.

Along the way, remove some redundant `:group` args
(redundant because they specify the same group as would be used by
default anyway) and make a few other simplifications.
Also don't bother putting `advice-add` within an eval-after-load
since the advice machinery already takes care of handling it.
2022-04-01 07:50:01 +02:00
Ihor Radchenko 0cb0760206
org-persist-write:elisp: Do not use `buffer-local-boundp'
* lisp/org-persist.el (org-persist-write:elisp): Use manual
implementation of `buffer-local-boundp' to make things work in Emacs
<28.

Reported in https://list.orgmode.org/87k0dyqy3d.fsf@kyleam.com/T/#u
2022-02-14 12:41:37 +08:00
Ihor Radchenko 27215ac5b5
org-persist: Handle undefined variables in elisp containers
* lisp/org-persist.el (org-persist-write:elisp): Do not try to write
elisp variable data when the variable is not defined.
(org-persist-load-all):
(org-persist-write-all): Cleanup containers that cannot be
read/written.
2022-02-13 16:53:59 +08:00
Ihor Radchenko 19a383d9f4
org-persist-write-all: Speed up writing
* lisp/org-persist.el (org-persist-write): New optional argument
bypassing extra `org-persist-read' invocation.
(org-persist-write-all): Call faster version of `org-persist-write'.
2022-01-29 17:08:57 +08:00
Ihor Radchenko 6b175fb227
org-persist-register: Make return value meaningful with :write-immidiately
* lisp/org-persist.el (org-persist-register): Return the return value
of `org-persist-write' when `:write-immediately' is non-nil.
2022-01-29 17:08:40 +08:00
Ihor Radchenko caccec2c54
org-persist: Use symbols as container names
* lisp/org-persist.el: Update commentary.
(org-persist--storage-version): Bump index version.
(org-persist--normalize-container):
(org-persist-read:index):
(org-persist--load-index):
(org-persist--save-index): Use symbol for container names.
2022-01-29 17:08:33 +08:00
Ihor Radchenko 6a5874bb26
org-persist-write: Overwrite existing copy if write is requested 2022-01-29 17:08:23 +08:00
Ihor Radchenko 0e18c617cf
org-persist-write:index: Return index path on write 2022-01-29 17:08:17 +08:00
Ihor Radchenko eca678195b
org-persist-write: Return the written value on success 2022-01-29 17:08:10 +08:00
Ihor Radchenko 0526acd16f
org-persist-register: New optional keyword to force immidiate write
* lisp/org-persist.el: Update commentary.
(org-persist-register): Add new keyword `write-immediately' to write
the newrly registerd container to disk immediately.
2022-01-29 17:08:02 +08:00
Ihor Radchenko 1bc8389871
org-persist-read: Check expiry 2022-01-29 17:07:56 +08:00
Ihor Radchenko f3bd1dcb77
org-persist: Fix compiler warnings 2022-01-29 17:07:48 +08:00
Ihor Radchenko ec787fb218
org-persist: Implement "file" and "url" containers linked to other file
* lisp/org-persist.el: Update commentary.
(org-persist--storage-version): Bump storage version.
(org-persist-write:file):
(org-persist-write:url): Support optional container setting.
2022-01-29 17:07:32 +08:00
Ihor Radchenko fca80139ee
org-persist: Fix compatibility with Emacs 27
* lisp/org-persist.el (org-persist--normalize-associated): Do not
expect that we can bind new vars in pacse forms.
(org-persist-read:elisp):
(org-persist-read:version):
(org-persist-read:file):
(org-persist-read:url): Avoid multiple `_' placeholders.
2022-01-29 17:06:40 +08:00
Ihor Radchenko dc52c0fe99
Fix native-comp warnings 2022-01-29 17:06:32 +08:00
Ihor Radchenko 4ec57a9453
org-persist: Update commentary 2022-01-29 17:06:23 +08:00
Ihor Radchenko d5fc159bf7
Fix compiler warnings 2022-01-29 17:06:14 +08:00
Ihor Radchenko f963d617a4
Fix checkdoc warnings 2022-01-29 17:06:08 +08:00
Ihor Radchenko 9b650938e7
org-persist: Provide human readable access time and make sure it exist
* lisp/org-persist.el (org-persist--storage-version): Bump version.
(org-persist-read:generic):
(org-persist-load:generic):
(org-persist-write:generic): Save access time in human-readable form.
2022-01-29 17:05:33 +08:00
Ihor Radchenko aca62116da
org-persist-write: Update buffer hash on save 2022-01-29 17:05:26 +08:00
Ihor Radchenko 203420504e
org-persist-load:elisp: fix loading 2022-01-29 17:05:13 +08:00
Ihor Radchenko 1869a37a2c
Fix org-persist--remove-from-index 2022-01-29 17:05:05 +08:00
Ihor Radchenko 8821ff5811
org-persist-read: Do not try to read non-existing containers 2022-01-29 17:04:52 +08:00
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