emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org d267486 1/3: org-element-cache: Fix some edits righ


From: ELPA Syncer
Subject: [elpa] externals/org d267486 1/3: org-element-cache: Fix some edits right after indent at :begin
Date: Thu, 16 Dec 2021 08:57:31 -0500 (EST)

branch: externals/org
commit d26748600229213acb806c0c7683e3c6595d7f94
Author: Ihor Radchenko <yantar92@gmail.com>
Commit: Ihor Radchenko <yantar92@gmail.com>

    org-element-cache: Fix some edits right after indent at :begin
    
    * lisp/org-element.el (org-element--cache-after-change): Extend
    changed region to bol when we are editing near beginning of an element
    within or right after indentation.  Such edits potentially change
    :post-blank value of the previous element.
    * testing/lisp/test-org-element.el (test-org-element/cache): Add test
    checking one of such cases.
---
 lisp/org-element.el              | 9 +++++++++
 testing/lisp/test-org-element.el | 9 +++++++++
 2 files changed, 18 insertions(+)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index 4ed2408..9b52372 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -6585,6 +6585,15 @@ that range.  See `after-change-functions' for more 
information."
       (when (not (eq org-element--cache-change-tic 
(buffer-chars-modified-tick)))
         (org-element--cache-log-message "After change")
         (setq org-element--cache-change-warning 
(org-element--cache-before-change beg end))
+        ;; If beg is right after spaces in front of an element, we
+        ;; risk affecting previous element, so move beg to bol, making
+        ;; sure that we capture preceding element.
+        (setq beg (save-excursion
+                    (goto-char beg)
+                    (skip-chars-backward " \t")
+                    (if (not (bolp)) beg
+                      (cl-incf pre (- beg (point)))
+                      (point))))
         ;; Store synchronization request.
         (let ((offset (- end beg pre)))
           (save-match-data
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index 0f66d6c..83a96e1 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -4004,6 +4004,15 @@ Text
         (equal (cons (org-element-property :begin element)
                      (org-element-property :end element))
                (cons (point-min) (point-max)))))))
+  (org-test-with-temp-text ":DRAWER:\ntest\n:END:\n <point>#\nParagraph"
+    (let ((org-element-use-cache t))
+      (org-element-cache-map #'ignore :granularity 'element)
+      (should (eq 'comment (org-element-type (org-element-at-point))))
+      (should (eq 0 (org-element-property :post-blank (org-element-at-point 
(point-min)))))
+      (insert " ") (delete-char -1)
+      (org-element-cache-map #'ignore :granularity 'element)
+      (delete-char 1)
+      (should (eq 1 (org-element-property :post-blank (org-element-at-point 
(point-min)))))))
   ;; Sensitive change: adding a line alters document structure both
   ;; above and below.
   (should



reply via email to

[Prev in Thread] Current Thread [Next in Thread]