org-element-cache: Fix when edit extends previous element
* lisp/org-element.el (org-element--cache-after-change): Always extend changed region to bol. * testing/lisp/test-org-element.el (test-org-element/cache): Add test checking the new fix. Amend some tests around making sure that cache is active during testing.
This commit is contained in:
parent
d6e6a9a3bc
commit
e2a8e95576
|
@ -6602,10 +6602,8 @@ that range. See `after-change-functions' for more information."
|
||||||
;; sure that we capture preceding element.
|
;; sure that we capture preceding element.
|
||||||
(setq beg (save-excursion
|
(setq beg (save-excursion
|
||||||
(goto-char beg)
|
(goto-char beg)
|
||||||
(skip-chars-backward " \t")
|
(cl-incf pre (- beg (line-beginning-position)))
|
||||||
(if (not (bolp)) beg
|
(line-beginning-position)))
|
||||||
(cl-incf pre (- beg (point)))
|
|
||||||
(point))))
|
|
||||||
;; Store synchronization request.
|
;; Store synchronization request.
|
||||||
(let ((offset (- end beg pre)))
|
(let ((offset (- end beg pre)))
|
||||||
(save-match-data
|
(save-match-data
|
||||||
|
|
|
@ -4080,19 +4080,30 @@ Text
|
||||||
;; Test edits near :end of element
|
;; Test edits near :end of element
|
||||||
(should-not (eq 'headline
|
(should-not (eq 'headline
|
||||||
(org-test-with-temp-text "* H1\nP1\n<point>*H2\n"
|
(org-test-with-temp-text "* H1\nP1\n<point>*H2\n"
|
||||||
(org-element-cache-map #'ignore :granularity 'element)
|
(let ((org-element-use-cache t))
|
||||||
(insert "Blah")
|
(org-element-cache-map #'ignore :granularity 'element)
|
||||||
(org-element-type (org-element-at-point)))))
|
(insert "Blah")
|
||||||
|
(org-element-type (org-element-at-point))))))
|
||||||
(should-not (eq 'headline
|
(should-not (eq 'headline
|
||||||
(org-test-with-temp-text "* H1\nP1\n<point>*H2\n"
|
(org-test-with-temp-text "* H1\nP1\n<point>*H2\n"
|
||||||
(org-element-cache-map #'ignore :granularity 'element)
|
(let ((org-element-use-cache t))
|
||||||
(backward-delete-char 1)
|
(org-element-cache-map #'ignore :granularity 'element)
|
||||||
(org-element-type (org-element-at-point)))))
|
(backward-delete-char 1)
|
||||||
|
(org-element-type (org-element-at-point))))))
|
||||||
|
(org-test-with-temp-text "Paragraph.\n #<point> comment"
|
||||||
|
(let ((org-element-use-cache t))
|
||||||
|
(org-element-cache-map #'ignore :granularity 'element)
|
||||||
|
(should (eq 'comment (org-element-type (org-element-at-point))))
|
||||||
|
(insert "not comment anymore")
|
||||||
|
(org-element-cache-map #'ignore :granularity 'element)
|
||||||
|
(should-not (eq 'comment (org-element-type (org-element-at-point))))
|
||||||
|
(should (eq (org-element-at-point) (org-element-at-point 1)))))
|
||||||
(should (eq 'headline
|
(should (eq 'headline
|
||||||
(org-test-with-temp-text "* H1\nP1\n<point*H2\n"
|
(org-test-with-temp-text "* H1\nP1\n<point*H2\n"
|
||||||
(org-element-cache-map #'ignore :granularity 'element)
|
(let ((org-element-use-cache t))
|
||||||
(insert "Blah\n")
|
(org-element-cache-map #'ignore :granularity 'element)
|
||||||
(org-element-type (org-element-at-point)))))
|
(insert "Blah\n")
|
||||||
|
(org-element-type (org-element-at-point))))))
|
||||||
;; Corner case: watch out drawers named "PROPERTIES" as they are
|
;; Corner case: watch out drawers named "PROPERTIES" as they are
|
||||||
;; fragile, unlike to other drawers.
|
;; fragile, unlike to other drawers.
|
||||||
(should
|
(should
|
||||||
|
|
Loading…
Reference in New Issue