branch: externals/org
commit def8e57c18b7a875c4a367d4a29d82b27e67ce16
Author: Ihor Radchenko <[email protected]>
Commit: Ihor Radchenko <[email protected]>

    Fix Emacs 28 compatibility
    
    * lisp/org-compat.el (fboundp): Add `org-with-undo-amalgamate' wrapper
    for Emacs <29.
    * lisp/org.el (map): Add missing require.
    (org-indent-line): Use `org-with-undo-amalgamate'.
    * testing/lisp/test-org-src.el (test-org-src/preserve-syntax-table):
    Do not yet use `pos-bol' and `pos-eol'.
---
 lisp/org-compat.el           | 27 +++++++++++++++++++++++++++
 lisp/org.el                  | 23 ++++++++++++-----------
 testing/lisp/test-org-src.el | 12 ++++++++++--
 3 files changed, 49 insertions(+), 13 deletions(-)

diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 67686047a9..d67f706749 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -191,6 +191,33 @@ back to `window-text-pixel-size' otherwise."
           (set-window-buffer nil oldbuffer)
           (set-window-dedicated-p nil dedicatedp))))))
 
+
+(if (fboundp 'with-undo-amalgamate)
+    (defalias 'org-with-undo-amalgamate 'with-undo-amalgamate)
+  ;; Copied from Emacs source.
+  (defmacro org-with-undo-amalgamate (&rest body)
+    "Like `progn' but perform BODY with amalgamated undo barriers.
+
+This allows multiple operations to be undone in a single step.
+When undo is disabled this behaves like `progn'."
+    (declare (indent 0) (debug t))
+    (let ((handle (make-symbol "--change-group-handle--")))
+      `(let ((,handle (prepare-change-group))
+             ;; Don't truncate any undo data in the middle of this,
+             ;; otherwise Emacs might truncate part of the resulting
+             ;; undo step: we want to mimic the behavior we'd get if the
+             ;; undo-boundaries were never added in the first place.
+             (undo-outer-limit nil)
+             (undo-limit most-positive-fixnum)
+             (undo-strong-limit most-positive-fixnum))
+         (unwind-protect
+             (progn
+               (activate-change-group ,handle)
+               ,@body)
+           (progn
+             (accept-change-group ,handle)
+             (undo-amalgamate-change-group ,handle)))))))
+
 
 ;;; Emacs < 28.1 compatibility
 
diff --git a/lisp/org.el b/lisp/org.el
index 5c97d13c4d..5e9def3af7 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -75,6 +75,7 @@
 (org-assert-version)
 
 (require 'cl-lib)
+(require 'map)
 
 (eval-when-compile (require 'gnus-sum))
 
@@ -19606,17 +19607,17 @@ Also align node properties according to 
`org-property-format'."
                            org-edit-src-content-indentation)))))
                ;; Avoid over-indenting when beginning of a new line is not 
empty.
                ;; https://list.orgmode.org/[email protected]/
-               (with-undo-amalgamate
-                 (when block-content-ind
-                   (save-excursion (indent-line-to block-content-ind)))
-                 (ignore-errors ; do not err when there is no proper major mode
-                   ;; It is important to call `indent-according-to-mode'
-                   ;; rather than `indent-line-function' here or we may
-                   ;; sometimes break `electric-indent-mode'
-                   ;; 
https://orgmode.org/list/5O9VMGb6WRaqeHR5_NXTb832Z2Lek_5L40YPDA52-S3kPwGYJspI8kLWaGtuq3DXyhtHpj1J7jTIXb39RX9BtCa2ecrWHjijZqI8QAD742U=@proton.me
-                   (org-babel-do-in-edit-buffer (indent-according-to-mode)))
-                 (when (and block-content-ind (looking-at-p "^$"))
-                   (indent-line-to block-content-ind)))))
+               (org-with-undo-amalgamate
+                (when block-content-ind
+                  (save-excursion (indent-line-to block-content-ind)))
+                (ignore-errors ; do not err when there is no proper major mode
+                  ;; It is important to call `indent-according-to-mode'
+                  ;; rather than `indent-line-function' here or we may
+                  ;; sometimes break `electric-indent-mode'
+                  ;; 
https://orgmode.org/list/5O9VMGb6WRaqeHR5_NXTb832Z2Lek_5L40YPDA52-S3kPwGYJspI8kLWaGtuq3DXyhtHpj1J7jTIXb39RX9BtCa2ecrWHjijZqI8QAD742U=@proton.me
+                  (org-babel-do-in-edit-buffer (indent-according-to-mode)))
+                (when (and block-content-ind (looking-at-p "^$"))
+                  (indent-line-to block-content-ind)))))
            (t
             (let ((column (org--get-expected-indentation element nil)))
               ;; Preserve current column.
diff --git a/testing/lisp/test-org-src.el b/testing/lisp/test-org-src.el
index ec7c0601ad..e9fa9babd6 100644
--- a/testing/lisp/test-org-src.el
+++ b/testing/lisp/test-org-src.el
@@ -586,11 +586,19 @@ This is a tab:\t.
    (should (equal (get-text-property (point) 'syntax-table)
                   (string-to-syntax ".")))
    ;; Everywhere else should use the mode's syntax table.
-   (dolist (pos (list (1+ (point)) (1- (point)) (pos-bol) (pos-eol)))
+   (dolist (pos (list (1+ (point)) (1- (point))
+                      (let ((inhibit-field-text-motion t))
+                        (line-beginning-position))
+                      (let ((inhibit-field-text-motion t))
+                        (line-end-position))))
      (should (equal (get-text-property pos 'syntax-table)
                     nxml-mode-syntax-table)))
    ;; But not outside the source code.
-   (dolist (pos (list (1- (pos-bol)) (1+ (pos-eol))))
+   (dolist (pos (list
+                 (let ((inhibit-field-text-motion t))
+                   (1- (line-beginning-position)))
+                 (let ((inhibit-field-text-motion t))
+                   (1+ (line-end-position)))))
      (should-not (get-text-property pos 'syntax-table))))
   ;; Inline source.
   (org-test-with-temp-text

Reply via email to