From 15ff91c3e41d30fc6ab4cc727fdb8a9b13cb127c Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Sun, 15 Jun 2008 08:03:45 +0200 Subject: [PATCH] Small fixes and extensions for org-publish. --- doc/org.texi | 5 ++++- lisp/org-publish.el | 57 +++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 473366803..38e4a0ad6 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -7633,8 +7633,11 @@ and where to put published files. @item @code{:publishing-directory} @tab Directory (possibly remote) where output files will be published. @item @code{:preparation-function} -@tab Function called before starting publishing process, for example to +@tab Function called before starting the publishing process, for example to run @code{make} for updating files to be published. +@item @code{:completion-function} +@tab Function called after finishing the publishing process, for example to +change permissions of the resulting files. @end multitable @noindent diff --git a/lisp/org-publish.el b/lisp/org-publish.el index 54d489c68..e485dbef1 100644 --- a/lisp/org-publish.el +++ b/lisp/org-publish.el @@ -155,9 +155,9 @@ (defmacro declare-function (fn file &optional arglist fileonly)))) (defgroup org-publish nil - "Options for publishing a set of Org-mode and related files." - :tag "Org Publishing" - :group 'org) + "Options for publishing a set of Org-mode and related files." + :tag "Org Publishing" + :group 'org) (defcustom org-publish-project-alist nil "Association list to control publishing behavior. @@ -219,6 +219,8 @@ certain makefile, to ensure published files are built up to date. :preparation-function Function to be called before publishing this project. + :completion-function Function to be called after publishing + this project. Some properties control details of the Org publishing process, and are equivalent to the corresponding user variables listed in @@ -449,6 +451,11 @@ matching filenames." ;; FIXME distinguish exclude regexp ;; for skip-file and skip-dir? exclude-regexp exclude-regexp) + (mapc (lambda (f) + (pushnew + (expand-file-name (concat base-dir f)) + org-publish-temp-files)) + include-list) org-publish-temp-files)) (defun org-publish-get-project-from-filename (filename) @@ -561,19 +568,22 @@ See `org-publish-org-to' to the list of arguments." If :auto-index is set, publish the index too." (mapc (lambda (project) - (let* ((project-plist (cdr project)) - (exclude-regexp (plist-get project-plist :exclude)) - (index-p (plist-get project-plist :auto-index)) - (index-filename (or (plist-get project-plist :index-filename) - "index.org")) - (index-function (or (plist-get project-plist :index-function) - 'org-publish-org-index)) - (preparation-function (plist-get project-plist :preparation-function)) - (files (org-publish-get-base-files project exclude-regexp)) file) + (let* + ((project-plist (cdr project)) + (exclude-regexp (plist-get project-plist :exclude)) + (index-p (plist-get project-plist :auto-index)) + (index-filename (or (plist-get project-plist :index-filename) + "index.org")) + (index-function (or (plist-get project-plist :index-function) + 'org-publish-org-index)) + (preparation-function (plist-get project-plist :preparation-function)) + (completion-function (plist-get project-plist :completion-function)) + (files (org-publish-get-base-files project exclude-regexp)) file) (when preparation-function (funcall preparation-function)) (if index-p (funcall index-function project index-filename)) (while (setq file (pop files)) - (org-publish-file file project)))) + (org-publish-file file project)) + (when completion-function (funcall completion-function)))) (org-publish-expand-projects projects))) (defun org-publish-org-index (project &optional index-filename) @@ -586,8 +596,8 @@ Default for INDEX-FILENAME is 'index.org'." (exclude-regexp (plist-get project-plist :exclude)) (files (org-publish-get-base-files project exclude-regexp)) (index-filename (concat dir (or index-filename "index.org"))) - (index-title (or (plist-get project-plist :index-title) - (concat "Index for project " (car project)))) + (index-title (or (plist-get project-plist :index-title) + (concat "Index for project " (car project)))) (index-buffer (find-buffer-visiting index-filename)) (ifn (file-name-nondirectory index-filename)) file) @@ -597,15 +607,28 @@ Default for INDEX-FILENAME is 'index.org'." (with-temp-buffer (insert (concat index-title "\n\n")) (while (setq file (pop files)) - (let ((fn (file-name-nondirectory file))) + (let ((fn (substring (expand-file-name file) + (length (expand-file-name dir))))) ;; index shouldn't index itself (unless (string= fn ifn) (insert (concat " + [[file:" fn "][" - (file-name-sans-extension fn) + (org-publish-find-title (concat dir fn)) "]]\n"))))) (write-file index-filename) (kill-buffer (current-buffer))))) +(defun org-publish-find-title (file) + "Find the title of file in project." + (save-excursion + (set-buffer (find-file-noselect file)) + (let* ((opt-plist (org-combine-plists (org-default-export-plist) + (org-infile-export-plist)))) + (or (plist-get opt-plist :title) + (and (not + (plist-get opt-plist :skip-before-1st-heading)) + (org-export-grab-title-from-buffer)) + (file-name-sans-extension file))))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Interactive publishing functions -- 2.11.4.GIT