ox-publish: Change signature for preparation and completion functions

* doc/org.texi (Sources and destinations): Document new signature.
* lisp/ox-publish.el (org-publish-project-alist): Update docstring.
(org-publish-projects): Call preparation and
completion functions with the project properties as the sole argument.

`project-plist' used to be dynamically scoped.  This is no longer
possible due to the switch to lexical binding.

Reported-by: Arun Isaac <arunisaac@systemreboot.net>
<http://permalink.gmane.org/gmane.emacs.orgmode/107856>
This commit is contained in:
Nicolas Goaziou 2016-06-22 15:28:05 +02:00
parent 6b7944805f
commit 5cd793c59a
3 changed files with 21 additions and 14 deletions

View File

@ -14250,13 +14250,13 @@ use external tools to upload your website (@pxref{Uploading files}).
@item @code{:preparation-function}
@tab Function or list of functions to be called before starting the
publishing process, for example, to run @code{make} for updating files to be
published. The project property list is scoped into this call as the
variable @code{project-plist}.
published. Each preparation function is called with a single argument, the
project property.
@item @code{:completion-function}
@tab Function or list of functions called after finishing the publishing
process, for example, to change permissions of the resulting files. The
project property list is scoped into this call as the variable
@code{project-plist}.
process, for example, to change permissions of the resulting files. Each
completion function is called with a single argument, the project property
list.
@end multitable
@noindent

View File

@ -104,10 +104,13 @@ is straightforward. For example
becomes
: ("pdf" . (lambda (file link) (foo)))
*** The ~{{{modification-time}}}~ macro can obtain time via =vc=
The modification time will be determined via =vc.el= if the second
argument is non-nil. See the manual for details.
*** Preparation and completion functions in publishing projects change signature
Preparation and completion functions are now called with an argument,
which is the project property list. It used to be dynamically scoped
through the ~project-plist~ variable.
** New features
*** New org-protocol key=value syntax

View File

@ -144,12 +144,16 @@ date.
`:preparation-function'
Function to be called before publishing this project. This
may also be a list of functions.
may also be a list of functions. Preparation functions are
called with the project properties list as their sole
argument.
`:completion-function'
Function to be called after publishing this project. This
may also be a list of functions.
may also be a list of functions. Completion functions are
called with the project properties list as their sole
argument.
Some properties control details of the Org publishing process,
and are equivalent to the corresponding user variables listed in
@ -673,9 +677,9 @@ If `:auto-sitemap' is set, publish the sitemap too. If
`:makeindex' is set, also produce a file \"theindex.org\"."
(dolist (project (org-publish-expand-projects projects))
(let ((project-plist (cdr project)))
(let ((f (plist-get project-plist :preparation-function)))
(cond ((consp f) (mapc #'funcall f))
((functionp f) (funcall f))))
(let ((fun (plist-get project-plist :preparation-function)))
(cond ((consp fun) (dolist (f fun) (funcall f project-plist)))
((functionp fun) (funcall fun project-plist))))
;; Each project uses its own cache file.
(org-publish-initialize-cache (car project))
(when (plist-get project-plist :auto-sitemap)
@ -707,9 +711,9 @@ If `:auto-sitemap' is set, publish the sitemap too. If
(org-publish-index-generate-theindex
project (plist-get project-plist :base-directory))
(org-publish-file theindex project t)))
(let ((f (plist-get project-plist :completion-function)))
(cond ((consp f) (mapc #'funcall f))
((functionp f) (funcall f))))
(let ((fun (plist-get project-plist :completion-function)))
(cond ((consp fun) (dolist (f fun) (funcall f project-plist)))
((functionp fun) (funcall fun project-plist))))
(org-publish-write-cache-file))))
(defun org-publish-org-sitemap (project &optional sitemap-filename)