From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?B?Sm/Do28gVMOhdm9yYQ==?= Newsgroups: gmane.emacs.devel Subject: Re: Permanently fix org versioning breakage during builds? Date: Sun, 24 Dec 2023 17:04:08 +0000 Message-ID: References: <25989.50971.995591.385250@google.com> <87a5q0dc9m.fsf@localhost> <87edfbbyzm.fsf@localhost> <875y0n4px0.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22060"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "T.V Raman" , emacs-devel To: Ihor Radchenko Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Dec 24 18:01:25 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rHRqv-0005bH-6J for ged-emacs-devel@m.gmane-mx.org; Sun, 24 Dec 2023 18:01:25 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rHRqY-0000Kb-DJ; Sun, 24 Dec 2023 12:01:02 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rHRqW-0000K6-RS for emacs-devel@gnu.org; Sun, 24 Dec 2023 12:01:00 -0500 Original-Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rHRqU-0001an-UH for emacs-devel@gnu.org; Sun, 24 Dec 2023 12:01:00 -0500 Original-Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-50e6ee5b7ffso1483623e87.3 for ; Sun, 24 Dec 2023 09:00:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703437257; x=1704042057; darn=gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=bao+95JZvdlSdUhw64B9q91AL2is0GtnbWul9pG3tD8=; b=SseO37BQhqX9HNyAJRjaNJwCm0BRRa/StQw2RHh3+7YZGmTee1KEkm6xuNfSyv07gh tVLVV3b4O6dfuSj/nUG9pQoTUyMGxwz+BhJfeJ/+71hm+NuKmmmCbYhzAqAT/RZDCDhZ Z/tkAdknzJgq4LV3c3NrJ5kkvivMrLQuCqZYr2OsZ8FWp6HhKriBHbFibkZ+qRpIhQFE e2FkoeQjwOSPTmg9utOjXQ61fKcT6pJxpdNfgfaZEEv4Oqsf4VOxdegaD8Mx7xHvnoLw GIRn9TCnexhA2I3d2H0XC9LWPf5oz7Ma5RJEf1dP3A28ov40HD3wAFPQ1mJIOnXgpZL/ fEdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703437257; x=1704042057; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bao+95JZvdlSdUhw64B9q91AL2is0GtnbWul9pG3tD8=; b=h8ONfQNETRUUzBs3e+dVnuWS5JEB/mOmTP3/87jPTAKRIpDLrX2MqhNsv9kp2jHku/ CtvKqn16a3ZKibTTxGsAD7YNyk7Ly+5erhvzgmtmsJXOUJ4pc5Zeycqjept3dDJKW1Re lq2ZYbXyiemgslx5jb1FyGTo2/BxG5OmUwKGc02KYxAH18Z4g4io/K4yCDkhyv01AleL /HVtSTF644ZcS4mK8kaHJ77j/UeoYDtAG5XxrT6wWjHlZme6K4gEmNoN2ZQ/nU4GLyDL pwvOZXWaimgIuH66t3zBrZZEREuaHFGD9mTsaUELp77GHi9Mqa1n3Gzzkb05X1xK1H+C 6AVg== X-Gm-Message-State: AOJu0Yy+RBo9SMaRr1MNwzBxeI74+mPJ8eBtCXAx4Uv2QUaai8WD6nVp sTGFokLAD7LYY2LwileB6GFVv0hAFIJ+82dThSI= X-Google-Smtp-Source: AGHT+IGj0t4kBrTreeHJBP2+l0aOR45cGFfgqNZZ4FZ8ZIYYVrwb3ijqjAkZ4P1YskPgEdT2KWqYURs4mHnKARn99O4= X-Received: by 2002:ac2:5f55:0:b0:50e:758f:b2ce with SMTP id 21-20020ac25f55000000b0050e758fb2cemr530640lfz.52.1703437256657; Sun, 24 Dec 2023 09:00:56 -0800 (PST) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::130; envelope-from=joaotavora@gmail.com; helo=mail-lf1-x130.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:314148 Archived-At: On Sun, Dec 24, 2023 at 4:32=E2=80=AFPM Jo=C3=A3o T=C3=A1vora 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-visibil= ity drop-narrowing drop-content= s 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=C3=A3o 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-visibi= lity + drop-narrowing drop-conten= ts + 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