From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Lundin Subject: Re: [PATCH] Remove unecesssary invocations of org-mode in ox-publish Date: Tue, 29 Jul 2014 13:55:27 -0500 Message-ID: <877g2wyoyo.fsf@fastmail.fm> References: <87mwbsn40z.fsf@fastmail.fm> <871tt4fggm.fsf@bzg.ath.cx> <87zjfsnsyf.fsf@fastmail.fm> <87fvhk9p0m.fsf@bzg.ath.cx> <87k36wnp7x.fsf@fastmail.fm> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37384) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XCCYs-0003rf-Fn for emacs-orgmode@gnu.org; Tue, 29 Jul 2014 14:55:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XCCYm-0001Vb-Qd for emacs-orgmode@gnu.org; Tue, 29 Jul 2014 14:55:46 -0400 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:44742) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XCCYm-0001VK-Ej for emacs-orgmode@gnu.org; Tue, 29 Jul 2014 14:55:40 -0400 In-Reply-To: <87k36wnp7x.fsf@fastmail.fm> (Matt Lundin's message of "Tue, 29 Jul 2014 10:45:22 -0500") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Bastien Cc: Org Mode --=-=-= Content-Type: text/plain Matt Lundin writes: > Bastien writes: > >> Matt Lundin writes: >> >>> So to be safe, we could do the following in org-publish-find-date and >>> org-publish-find-title... >>> >>> (org-export-with-buffer-copy (org-export-get-environment)) >>> >>> What do you think? >> >> Yes, this sounds right, please go ahead. >> >> I applied your fix in the maint branch, so if you need to revert it >> please do the revert from there first. > > Here's the patch. There's no need to revert anything, as this builds > upon my previous commit. > > From 72217e53103a82e0397d1435331e3eed10f0fbd5 Mon Sep 17 00:00:00 2001 > From: Matt Lundin > Date: Tue, 29 Jul 2014 10:39:57 -0500 > Subject: [PATCH 1/2] Call org-export-get-environment in buffer copy > > * lisp/ox-publish.el: (org-publish-find-title) (org-publish-find-date) > Make sure to call org-export-get-environment in copy of > buffer. Otherwise, #+bind variables meant for export can be set in > live buffers. Please *do not apply* the previous patch. Instead, I've attached an optimized version. All in all this patch + commit 507244d56b055e7595ba94fe89d45c7ddb2559df modestly improves the performance of org-publish-org-sitemap. On a directory of 104 files, it used to take this long... org-publish-org-sitemap 1 10.508871433 10.508871433 ...to generate a sitemap. With this patch and commit 507244d, it takes this long... org-publish-org-sitemap 1 7.700290794 7.700290794 Clearly, this is still very inadequate, but it is an improvement. I would love to use the built in site-map functions, but they are simply to slow for any larger projects. Could we do something like this to speed it up? --8<---------------cut here---------------start------------->8--- (with-temp-buffer (insert-file-contents file) (goto-char (point-min)) (when (re-search-forward "^#\\+TITLE:" nil t) (org-element-at-point))) --8<---------------cut here---------------end--------------->8--- Until then, here's the patch. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Protect-open-buffers-when-publishing-sitemap.patch >From 9260e6d4c5537994ffb6df2f2cc48c62ad4ffb63 Mon Sep 17 00:00:00 2001 From: Matt Lundin Date: Tue, 29 Jul 2014 13:35:41 -0500 Subject: [PATCH] Protect open buffers when publishing sitemap * lisp/ox-publish.el: (org-publish-find-title) (org-publish-find-date) Make sure to call org-export-get-environment in copy of buffer if emacs is already visiting. Otherwise, #+bind variables meant for export can be set in live buffers. This patch also optimizes the above functions by inhibiting org-startup on buffers emacs visits temporarily. --- lisp/ox-publish.el | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el index 94f12e9..df40572 100644 --- a/lisp/ox-publish.el +++ b/lisp/ox-publish.el @@ -806,11 +806,18 @@ Default for SITEMAP-FILENAME is 'sitemap.org'." "Find the title of FILE in project." (or (and (not reset) (org-publish-cache-get-file-property file :title nil t)) - (let* ((visiting (find-buffer-visiting file)) + (let* ((org-inhibit-startup t) + (visiting (find-buffer-visiting file)) (buffer (or visiting (find-file-noselect file)))) (with-current-buffer buffer (let ((title - (let ((property (plist-get (org-export-get-environment) :title))) + (let ((property + (plist-get + ;; protect local variables in open buffers + (if visiting + (org-export-with-buffer-copy (org-export-get-environment)) + (org-export-get-environment)) + :title))) (if property (org-no-properties (org-element-interpret-data property)) (file-name-nondirectory (file-name-sans-extension file)))))) @@ -825,11 +832,14 @@ If FILE is an Org file and provides a DATE keyword use it. In any other case use the file system's modification time. Return time in `current-time' format." (if (file-directory-p file) (nth 5 (file-attributes file)) - (let* ((visiting (find-buffer-visiting file)) + (let* ((org-inhibit-startup t) + (visiting (find-buffer-visiting file)) (file-buf (or visiting (find-file-noselect file nil))) (date (plist-get (with-current-buffer file-buf - (org-export-get-environment)) + (if visiting + (org-export-with-buffer-copy (org-export-get-environment)) + (org-export-get-environment))) :date))) (unless visiting (kill-buffer file-buf)) ;; DATE is either a timestamp object or a secondary string. If it -- 2.0.3 --=-=-=--