emacs-devel
[Top][All Lists]
Advanced

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

Re: Permanently fix org versioning breakage during builds?


From: João Távora
Subject: Re: Permanently fix org versioning breakage during builds?
Date: Sun, 24 Dec 2023 17:04:08 +0000

On Sun, Dec 24, 2023 at 4:32 PM João Távora <joaotavora@gmail.com> wrote:

>
> No, it didn't, I'm afraid.  If you know one of these macros (you alluded
> earlier to "some macros"), type its name here, please.

IIn the absence of examples (so far), I went looking for one myself.
I found 'org-export-with-buffer-copy' in lisp/org/ox.el.  It's expanded
in ox-html.el and ox-publish.el in the same directory.

As far as I can see, it falls right into the category of
expansion-site-recompilation problem that may happen if the macro's
implementation details, which are reasonably lengthy, are changed
in ox.el.  If ox-html.el and ox-publish.el aren't changed as well,
our build system will fail to recompile them and Org will malfunction.

[  Tangent: one thing I notice is that the expansion in ox-html.el is
buggy.  It evaluates the keyword arguments to the macros multiple times
for no effect.  The solution would be to change the macro calling
convention to be:

(cl-defmacro org-export-with-buffer-copy ((&key to-buffer drop-visibility
                                          drop-narrowing drop-contents
                                          drop-locals
                                          &allow-other-keys) &body body)
  ...)


But this is not the problem in this thread, of course (though I do
heavily recommend doing so if it's feasible: it might not be if
this macro is used outside of Org) ]

Anyway, let's apply the "CALL-WITH" technique:

(cl-defmacro org-export-with-buffer-copy ( &rest body
                                           &key to-buffer drop-visibility
                                           drop-narrowing drop-contents
                                           drop-locals
                                           &allow-other-keys)
  "..."
  `(org-export--call-with-buffer-copy (lambda () ,@body)
                                      :to-buffer ,to-buffer
                                      :drop-visibility ,drop-visibility
                                      :drop-narrowing ,drop-narrowing
                                      :drop-contents ,drop-contents
                                      :drop-locals ,drop-locals))

(cl-defun org-export--call-with-buffer-copy (fn &key to-buffer drop-visibility
                                                drop-narrowing drop-contents
                                                drop-locals
                                                &allow-other-keys)
  (let ((buf-copy (org-export-copy-buffer
                   :to-buffer to-buffer
                   :drop-visibility drop-visibility
                   :drop-narrowing drop-narrowing
                   :drop-contents drop-contents
                   :drop-locals drop-locals)))
    (unwind-protect
(with-current-buffer buf-copy
 (goto-char (point-min))
          (prog1
     (funcall fn)
            ;; `org-export-copy-buffer' carried the value of
            ;; `buffer-file-name' from the original buffer.  When not
            ;; killed, the new buffer copy may become a target of
            ;; `find-file'.  Prevent this.
            (setq buffer-file-name nil)))
      (and (buffer-live-p buf-copy)
  ;; Kill copy without confirmation.
  (progn (with-current-buffer buf-copy
   (restore-buffer-modified-p nil))
                  (unless to-buffer
   (kill-buffer buf-copy)))))))


As a bonus, no more "with-gensyms" needed or hairy commas.  Easier
debugging.  I did a make -C test org/tests but that doesn't have any
good tests and I don't know how to exercise the "publish" and "html"
functionality, so I ask that you test.

The full patch is after my sig.

João

diff --git a/lisp/org/ox.el b/lisp/org/ox.el
index e9cc0ed8fc7..d742172a4c7 100644
--- a/lisp/org/ox.el
+++ b/lisp/org/ox.el
@@ -2597,30 +2597,39 @@ org-export-with-buffer-copy
 copy.  `:to-buffer', `:drop-visibility', `:drop-narrowing',
 `:drop-contents', and `:drop-locals' are passed as arguments to
 `org-export-copy-buffer'."
-  (declare (debug t))
-  (org-with-gensyms (buf-copy)
-    `(let ((,buf-copy (org-export-copy-buffer
-                       :to-buffer ,to-buffer
-                       :drop-visibility ,drop-visibility
-                       :drop-narrowing ,drop-narrowing
-                       :drop-contents ,drop-contents
-                       :drop-locals ,drop-locals)))
-       (unwind-protect
-   (with-current-buffer ,buf-copy
-     (goto-char (point-min))
-             (prog1
-         (progn ,@body)
-               ;; `org-export-copy-buffer' carried the value of
-               ;; `buffer-file-name' from the original buffer.  When not
-               ;; killed, the new buffer copy may become a target of
-               ;; `find-file'.  Prevent this.
-               (setq buffer-file-name nil)))
- (and (buffer-live-p ,buf-copy)
-      ;; Kill copy without confirmation.
-      (progn (with-current-buffer ,buf-copy
-       (restore-buffer-modified-p nil))
-                     (unless ,to-buffer
-       (kill-buffer ,buf-copy))))))))
+  `(org-export--call-with-buffer-copy (lambda () ,@body)
+                                      :to-buffer ,to-buffer
+                                      :drop-visibility ,drop-visibility
+                                      :drop-narrowing ,drop-narrowing
+                                      :drop-contents ,drop-contents
+                                      :drop-locals ,drop-locals))
+
+(cl-defun org-export--call-with-buffer-copy (fn &key to-buffer drop-visibility
+                                                drop-narrowing drop-contents
+                                                drop-locals
+                                                &allow-other-keys)
+  (let ((buf-copy (org-export-copy-buffer
+                   :to-buffer to-buffer
+                   :drop-visibility drop-visibility
+                   :drop-narrowing drop-narrowing
+                   :drop-contents drop-contents
+                   :drop-locals drop-locals)))
+    (unwind-protect
+ (with-current-buffer buf-copy
+  (goto-char (point-min))
+          (prog1
+      (funcall fn)
+            ;; `org-export-copy-buffer' carried the value of
+            ;; `buffer-file-name' from the original buffer.  When not
+            ;; killed, the new buffer copy may become a target of
+            ;; `find-file'.  Prevent this.
+            (setq buffer-file-name nil)))
+      (and (buffer-live-p buf-copy)
+   ;; Kill copy without confirmation.
+   (progn (with-current-buffer buf-copy
+    (restore-buffer-modified-p nil))
+                  (unless to-buffer
+    (kill-buffer buf-copy)))))))

 (cl-defun org-export--generate-copy-script (buffer
                                             &key



reply via email to

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