From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Ignored in-buffer settings and after-export hook Date: Thu, 24 Oct 2013 20:05:04 +0200 Message-ID: <87vc0msfxr.fsf@gmail.com> References: <5219F424.5030907@gmail.com> <877gf8k753.fsf@gmail.com> <521B5C9D.8070602@gmail.com> <87ob8hy53z.fsf@gmail.com> <521F1BDF.30909@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VZPHG-0008Ve-U8 for emacs-orgmode@gnu.org; Thu, 24 Oct 2013 14:05:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VZPH8-00063S-Fr for emacs-orgmode@gnu.org; Thu, 24 Oct 2013 14:04:58 -0400 Received: from mail-we0-x230.google.com ([2a00:1450:400c:c03::230]:58168) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VZPH8-00062h-5j for emacs-orgmode@gnu.org; Thu, 24 Oct 2013 14:04:50 -0400 Received: by mail-we0-f176.google.com with SMTP id w62so2693517wes.35 for ; Thu, 24 Oct 2013 11:04:48 -0700 (PDT) In-Reply-To: <521F1BDF.30909@gmail.com> (Daniel Gerber's message of "Thu, 29 Aug 2013 12:01:03 +0200") 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: Daniel Gerber Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hello, Daniel Gerber writes: > Hello, >>> I guess I can, but it means re-doing the mapping sources to exported >>> file names. >> AFAICT, there is only one place where both the source and the output >> name are known: in `org-publish-file', right after a file has been >> published. >> >> We may add a hook there. Since, at that time, the current buffer can be >> anything, both file names need to be passed as arguments to the hook. >> Also, files skipped during the publishing process won't trigger it. >> >> What do you think? > It would be fine! It has been a long time, but would you mind testing the following patch? Regards, -- Nicolas Goaziou --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-ox-publish-Introduce-org-publish-after-publishing-ho.patch >From 5b54cd3f1cef9ca4385da5d6e1d9b9d076847d3e Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Tue, 27 Aug 2013 10:12:41 +0200 Subject: [PATCH] ox-publish: Introduce `org-publish-after-publishing-hook' * lisp/ox-publish.el (org-publish-after-publishing-hook): New variable. (org-publish-file): Call hook with file name and output file name as arguments. Small refactoring. (org-publish-attachment): Return output file. --- lisp/ox-publish.el | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el index cfa7967..36cc790 100644 --- a/lisp/ox-publish.el +++ b/lisp/ox-publish.el @@ -54,6 +54,12 @@ "This will cache timestamps and titles for files in publishing projects. Blocks could hash sha1 values here.") +(defvar org-publish-after-publishing-hook nil + "Hook run each time a file is published. +Every function in this hook will be called with two arguments: +the name of the original file and the name of the file +produced.") + (defgroup org-publish nil "Options for publishing a set of Org-mode and related files." :tag "Org Publishing" @@ -600,11 +606,12 @@ publishing directory. Return output file name." (unless (file-directory-p pub-dir) (make-directory pub-dir t)) - (or (equal (expand-file-name (file-name-directory filename)) - (file-name-as-directory (expand-file-name pub-dir))) - (copy-file filename - (expand-file-name (file-name-nondirectory filename) pub-dir) - t))) + (let ((output (expand-file-name (file-name-nondirectory filename) pub-dir))) + (or (equal (expand-file-name (file-name-directory filename)) + (file-name-as-directory (expand-file-name pub-dir))) + (copy-file filename output t)) + ;; Return file name. + output)) @@ -625,8 +632,10 @@ See `org-publish-projects'." (project-plist (cdr project)) (ftname (expand-file-name filename)) (publishing-function - (or (plist-get project-plist :publishing-function) - (error "No publishing function chosen"))) + (let ((fun (plist-get project-plist :publishing-function))) + (cond ((null fun) (error "No publishing function chosen")) + ((listp fun) fun) + (t (list fun))))) (base-dir (file-name-as-directory (expand-file-name @@ -648,19 +657,14 @@ See `org-publish-projects'." (concat pub-dir (and (string-match (regexp-quote base-dir) ftname) (substring ftname (match-end 0)))))) - (if (listp publishing-function) - ;; allow chain of publishing functions - (mapc (lambda (f) - (when (org-publish-needed-p - filename pub-dir f tmp-pub-dir base-dir) - (funcall f project-plist filename tmp-pub-dir) - (org-publish-update-timestamp filename pub-dir f base-dir))) - publishing-function) - (when (org-publish-needed-p - filename pub-dir publishing-function tmp-pub-dir base-dir) - (funcall publishing-function project-plist filename tmp-pub-dir) - (org-publish-update-timestamp - filename pub-dir publishing-function base-dir))) + ;; Allow chain of publishing functions. + (dolist (f publishing-function) + (when (org-publish-needed-p filename pub-dir f tmp-pub-dir base-dir) + (let ((output (funcall f project-plist filename tmp-pub-dir))) + (org-publish-update-timestamp filename pub-dir f base-dir) + (run-hook-with-args 'org-publish-after-publishing-hook + filename + output)))) (unless no-cache (org-publish-write-cache-file)))) (defun org-publish-projects (projects) -- 1.8.4.1 --=-=-=--