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

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

[elpa] externals/org e675affe93 2/3: org-macs: Add new macro `org-with-b


From: ELPA Syncer
Subject: [elpa] externals/org e675affe93 2/3: org-macs: Add new macro `org-with-base-buffer'
Date: Sat, 29 Oct 2022 22:57:52 -0400 (EDT)

branch: externals/org
commit e675affe93b8d4bc0a896867c9776301f7131950
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    org-macs: Add new macro `org-with-base-buffer'
    
    * lisp/org-macs.el (org-with-base-buffer): New macro to run code in
    base buffer of current or given buffer.
    * lisp/org-element.el (org-element-org-data-parser):
    (org-element--cache-find):
    (org-element--cache-sync):
    (org-element--cache-before-change):
    (org-element--cache-after-change):
    (org-element--cache-submit-request):
    (org-persist-after-read-hook): Use the new macro.
---
 lisp/org-element.el | 23 ++++++++---------------
 lisp/org-macs.el    |  8 ++++++++
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index ce6daaef84..4707038b07 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -1287,15 +1287,11 @@ parser (e.g. `:end' and :END:).  Return value is a 
plist."
                               (min robust-end (point))))
                            (+ 2 contents-begin))))
           (category (cond ((null org-category)
-                          (when (with-current-buffer
-                                     (or (buffer-base-buffer)
-                                         (current-buffer))
+                          (when (org-with-base-buffer nil
                                    buffer-file-name)
                             (file-name-sans-extension
                              (file-name-nondirectory
-                               (with-current-buffer
-                                   (or (buffer-base-buffer)
-                                       (current-buffer))
+                               (org-with-base-buffer nil
                                  buffer-file-name)))))
                          ((symbolp org-category) (symbol-name org-category))
                          (t org-category)))
@@ -5755,7 +5751,7 @@ after POS.
 
 The function can only find elements in the synchronized part of
 the cache."
-  (with-current-buffer (or (buffer-base-buffer) (current-buffer))
+  (org-with-base-buffer nil
     (let* ((limit (and org-element--cache-sync-requests
                        (org-element--request-key (car 
org-element--cache-sync-requests))))
           (node (org-element--cache-root))
@@ -5970,7 +5966,7 @@ change offset.  It is used in 
`org-element--cache-submit-request',
 where cache is partially updated before current modification are
 actually submitted."
   (when (buffer-live-p buffer)
-    (with-current-buffer (or (buffer-base-buffer buffer) buffer)
+    (org-with-base-buffer buffer
       ;; Do not sync when, for example, in the middle of
       ;; `combine-change-calls'.  See the commentary inside
       ;; `org-element--cache-active-p'.
@@ -6665,8 +6661,7 @@ BEG and END are the beginning and end of the range of 
changed
 text.  See `before-change-functions' for more information.
 
 The function returns the new value of `org-element--cache-change-warning'."
-  (with-current-buffer (or (buffer-base-buffer (current-buffer))
-                           (current-buffer))
+  (org-with-base-buffer nil
     (when (org-element--cache-active-p t)
       (org-with-wide-buffer
        (setq org-element--cache-change-tic (buffer-chars-modified-tick))
@@ -6745,8 +6740,7 @@ The function returns the new value of 
`org-element--cache-change-warning'."
 BEG and END are the beginning and end of the range of changed
 text, and the length in bytes of the pre-change text replaced by
 that range.  See `after-change-functions' for more information."
-  (with-current-buffer (or (buffer-base-buffer (current-buffer))
-                           (current-buffer))
+  (org-with-base-buffer nil
     (when (org-element--cache-active-p t)
       (when (not (eq org-element--cache-change-tic 
(buffer-chars-modified-tick)))
         (org-element--cache-log-message "After change")
@@ -6960,8 +6954,7 @@ change, as an integer."
   (org-element--cache-log-message
    "Submitting new synchronization request for [%S..%S]𝝙%S"
    beg end offset)
-  (with-current-buffer (or (buffer-base-buffer (current-buffer))
-                           (current-buffer))
+  (org-with-base-buffer nil
     (let ((next (car org-element--cache-sync-requests))
          delete-to delete-from)
       (if (and next
@@ -7253,7 +7246,7 @@ When optional argument NO-PERSISTANCE is non-nil, do not 
try to update
 the cache persistence in the buffer."
   (interactive "P")
   (dolist (buffer (if all (buffer-list) (list (current-buffer))))
-    (with-current-buffer (or (buffer-base-buffer buffer) buffer)
+    (org-with-base-buffer buffer
       (when (and org-element-use-cache (derived-mode-p 'org-mode))
         ;; Only persist cache in file buffers.
         (when (and (buffer-file-name) (not no-persistance))
diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index c858f3695a..2eb1a8b628 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -123,6 +123,14 @@ Version mismatch is commonly encountered in the following 
situations:
             ,@body)
         (set-buffer-modified-p ,was-modified)))))
 
+(defmacro org-with-base-buffer (buffer &rest body)
+  "Run BODY in base buffer for BUFFER.
+If BUFFER is nil, use base buffer for `current-buffer'."
+  (declare (debug (body)) (indent 1))
+  `(with-current-buffer (or (buffer-base-buffer ,buffer)
+                            (or ,buffer (current-buffer)))
+     ,@body))
+
 (defmacro org-with-point-at (pom &rest body)
   "Move to buffer and point of point-or-marker POM for the duration of BODY."
   (declare (debug (form body)) (indent 1))



reply via email to

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