Fix: (--value-at) Clear value cache when buffer changes
Fixes #59. Thanks to Daniel Hubmann (@hubisan) for reporting.
This commit is contained in:
parent
02159a831a
commit
a1851ed0eb
2 changed files with 21 additions and 1 deletions
|
|
@ -470,7 +470,8 @@ Values compared with `equal'."
|
||||||
buffer-unmodified-p (eq (buffer-modified-tick) modified-tick))
|
buffer-unmodified-p (eq (buffer-modified-tick) modified-tick))
|
||||||
(unless (and buffer-cache buffer-unmodified-p)
|
(unless (and buffer-cache buffer-unmodified-p)
|
||||||
;; Buffer-local node cache empty or invalid: make new one.
|
;; Buffer-local node cache empty or invalid: make new one.
|
||||||
(setf position-cache (make-hash-table))
|
(setf position-cache (make-hash-table)
|
||||||
|
value-cache (gethash position position-cache))
|
||||||
(puthash (current-buffer)
|
(puthash (current-buffer)
|
||||||
(cons (buffer-modified-tick) position-cache)
|
(cons (buffer-modified-tick) position-cache)
|
||||||
org-ql-node-value-cache))
|
org-ql-node-value-cache))
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,25 @@ RESULTS should be a list of strings as returned by
|
||||||
(cl-loop while (re-search-forward org-heading-regexp nil t)
|
(cl-loop while (re-search-forward org-heading-regexp nil t)
|
||||||
sum 1)))))
|
sum 1)))))
|
||||||
|
|
||||||
|
(describe "Caching"
|
||||||
|
(it "Clears value cache after buffer changes"
|
||||||
|
;; See <https://github.com/alphapapa/org-ql/issues/59>.
|
||||||
|
(with-temp-buffer
|
||||||
|
(org-mode)
|
||||||
|
(insert "* Heading 1
|
||||||
|
* Heading 2")
|
||||||
|
;; FIXME: `--value-at' does not actually move point, so we do it here.
|
||||||
|
(goto-char (point-min))
|
||||||
|
(expect (org-ql--value-at (point-min) #'org-get-heading)
|
||||||
|
:to-equal "Heading 1")
|
||||||
|
(erase-buffer)
|
||||||
|
;; FIXME: See above.
|
||||||
|
(insert "* Heading 2")
|
||||||
|
(goto-char (point-min))
|
||||||
|
(org-ql--value-at (point-min) #'point)
|
||||||
|
(expect (org-ql--value-at (point-min) #'org-get-heading)
|
||||||
|
:to-equal "Heading 2"))))
|
||||||
|
|
||||||
(describe "Query functions/macros"
|
(describe "Query functions/macros"
|
||||||
|
|
||||||
(it "org-ql"
|
(it "org-ql"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue