From 5319cec24ea2e500500661e8748bc3072c5febf5 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Thu, 6 Dec 2012 22:15:27 +0100 Subject: [PATCH] org-e-publish: Activate asynchronous publishing * contrib/lisp/org-e-publish.el (org-e-publish, org-e-publish-all, org-e-publish-current-file, org-e-publish-current-project): Activate asynchronous publishing. (org-e-publish-initial-buffer): Remove unused variable. * contrib/lisp/org-export.el (org-export-dispatch): Send asynchronous flag to publishing functions, when needed. --- contrib/lisp/org-e-publish.el | 90 +++++++++++++++++++++-------------- contrib/lisp/org-export.el | 19 ++++---- 2 files changed, 66 insertions(+), 43 deletions(-) diff --git a/contrib/lisp/org-e-publish.el b/contrib/lisp/org-e-publish.el index 4f8f7d7e8..53b7d985a 100644 --- a/contrib/lisp/org-e-publish.el +++ b/contrib/lisp/org-e-publish.el @@ -42,13 +42,9 @@ (require 'format-spec) (require 'org-export) -(declare-function org-e-latex-compile "org-e-latex" (texfile)) - ;;; Variables -(defvar org-e-publish-initial-buffer nil - "The buffer `org-e-publish' has been called from.") (defvar org-e-publish-temp-files nil "Temporary list of files to be published.") @@ -817,8 +813,15 @@ It returns time in `current-time' format." (defalias 'org-e-publish-project 'org-e-publish) ;;;###autoload -(defun org-e-publish (project &optional force) - "Publish PROJECT." +(defun org-e-publish (project &optional force async) + "Publish PROJECT. + +PROJECT is either a project name, as a string, or a project +alist (see `org-e-publish-project-alist' variable). + +When optional argument FORCE is non-nil, force publishing all +files in PROJECT. With a non-nil optional argument ASYNC, +publishing will be done asynchronously, in another process." (interactive (list (assoc (org-icompleting-read @@ -826,52 +829,69 @@ It returns time in `current-time' format." org-e-publish-project-alist nil t) org-e-publish-project-alist) current-prefix-arg)) - (setq org-e-publish-initial-buffer (current-buffer)) - (save-window-excursion - (let* ((org-e-publish-use-timestamps-flag - (if force nil org-e-publish-use-timestamps-flag))) - (org-e-publish-projects - (if (stringp project) - ;; If this function is called in batch mode, project is - ;; still a string here. - (list (assoc project org-e-publish-project-alist)) - (list project)))))) + (let ((project-alist (if (not (stringp project)) (list project) + ;; If this function is called in batch mode, + ;; project is still a string here. + (list (assoc project org-e-publish-project-alist))))) + (if async + (org-export-async-start 'ignore + `(let ((org-e-publish-use-timestamps-flag + (if ',force nil ,org-e-publish-use-timestamps-flag))) + (org-e-publish-projects ',project-alist))) + (save-window-excursion + (let* ((org-e-publish-use-timestamps-flag + (if force nil org-e-publish-use-timestamps-flag))) + (org-e-publish-projects project-alist)))))) ;;;###autoload -(defun org-e-publish-all (&optional force) +(defun org-e-publish-all (&optional force async) "Publish all projects. -With prefix argument, remove all files in the timestamp -directory and force publishing all files." +With prefix argument FORCE, remove all files in the timestamp +directory and force publishing all projects. With a non-nil +optional argument ASYNC, publishing will be done asynchronously, +in another process." (interactive "P") - (when force (org-e-publish-remove-all-timestamps)) - (save-window-excursion - (let ((org-e-publish-use-timestamps-flag - (if force nil org-e-publish-use-timestamps-flag))) - (org-e-publish-projects org-e-publish-project-alist)))) + (if async + (org-export-async-start 'ignore + `(when ',force (org-e-publish-remove-all-timestamps)) + `(let ((org-e-publish-use-timestamps-flag + (if ',force nil ,org-e-publish-use-timestamps-flag))) + (org-e-publish-projects ',org-e-publish-project-alist))) + (when force (org-e-publish-remove-all-timestamps)) + (save-window-excursion + (let ((org-e-publish-use-timestamps-flag + (if force nil org-e-publish-use-timestamps-flag))) + (org-e-publish-projects org-e-publish-project-alist))))) ;;;###autoload -(defun org-e-publish-current-file (&optional force) +(defun org-e-publish-current-file (&optional force async) "Publish the current file. -With prefix argument, force publish the file." +With prefix argument FORCE, force publish the file. When +optional argument ASYNC is non-nil, publishing will be done +asynchronously, in another process." (interactive "P") - (save-window-excursion - (let ((org-e-publish-use-timestamps-flag - (if force nil org-e-publish-use-timestamps-flag))) - (org-e-publish-file (buffer-file-name (buffer-base-buffer)))))) + (let ((file (buffer-file-name (buffer-base-buffer)))) + (if async + (org-export-async-start 'ignore + `(let ((org-e-publish-use-timestamps-flag + (if ',force nil ,org-e-publish-use-timestamps-flag))) + (org-e-publish-file ,file))) + (save-window-excursion + (let ((org-e-publish-use-timestamps-flag + (if force nil org-e-publish-use-timestamps-flag))) + (org-e-publish-file file)))))) ;;;###autoload -(defun org-e-publish-current-project (&optional force) +(defun org-e-publish-current-project (&optional force async) "Publish the project associated with the current file. With a prefix argument, force publishing of all files in the project." (interactive "P") (save-window-excursion (let ((project (org-e-publish-get-project-from-filename - (buffer-file-name (buffer-base-buffer)) 'up)) - (org-e-publish-use-timestamps-flag - (if force nil org-e-publish-use-timestamps-flag))) - (if project (org-e-publish project) + (buffer-file-name (buffer-base-buffer)) 'up))) + (if project (org-e-publish project force async) (error "File %s is not part of any known project" (buffer-file-name (buffer-base-buffer))))))) diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el index acf84ff40..6b93292da 100644 --- a/contrib/lisp/org-export.el +++ b/contrib/lisp/org-export.el @@ -80,11 +80,12 @@ (require 'org-element) (require 'ob-exp) -(declare-function org-e-publish "org-e-publish" (project &optional force)) -(declare-function org-e-publish-all "org-e-publish" (&optional force)) -(declare-function org-e-publish-current-file "org-e-publish" (&optional force)) +(declare-function org-e-publish "org-e-publish" (project &optional force async)) +(declare-function org-e-publish-all "org-e-publish" (&optional force async)) +(declare-function + org-e-publish-current-file "org-e-publish" (&optional force async)) (declare-function org-e-publish-current-project "org-e-publish" - (&optional force)) + (&optional force async)) (defvar org-e-publish-project-alist) (defvar org-table-number-fraction) @@ -5249,16 +5250,18 @@ asynchronous export stack directly." (case action ;; First handle special hard-coded actions. (stack (org-export-stack)) - (publish-current-file (org-e-publish-current-file (memq 'force optns))) + (publish-current-file + (org-e-publish-current-file (memq 'force optns) (memq 'async optns))) (publish-current-project - (org-e-publish-current-project (memq 'force optns))) + (org-e-publish-current-project (memq 'force optns) (memq 'async optns))) (publish-choose-project (org-e-publish (assoc (org-icompleting-read "Publish project: " org-e-publish-project-alist nil t) org-e-publish-project-alist) - (memq 'force optns))) - (publish-all (org-e-publish-all (memq 'force optns))) + (memq 'force optns) + (memq 'async optns))) + (publish-all (org-e-publish-all (memq 'force optns) (memq 'async optns))) (otherwise (funcall action ;; Return a symbol instead of a list to ease ;; asynchronous export macro use.