emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <n.goaziou@gmail.com>
To: Daniel Gerber <daniel.g.gerber@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Ignored in-buffer settings and after-export hook
Date: Thu, 24 Oct 2013 20:05:04 +0200	[thread overview]
Message-ID: <87vc0msfxr.fsf@gmail.com> (raw)
In-Reply-To: <521F1BDF.30909@gmail.com> (Daniel Gerber's message of "Thu, 29 Aug 2013 12:01:03 +0200")

[-- Attachment #1: Type: text/plain, Size: 686 bytes --]

Hello,

Daniel Gerber <daniel.g.gerber@gmail.com> 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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-publish-Introduce-org-publish-after-publishing-ho.patch --]
[-- Type: text/x-diff, Size: 3576 bytes --]

From 5b54cd3f1cef9ca4385da5d6e1d9b9d076847d3e Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
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))
 
 
 \f
@@ -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


  reply	other threads:[~2013-10-24 18:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-25 12:10 Ignored in-buffer settings and after-export hook Daniel Gerber
2013-08-26 11:45 ` Nicolas Goaziou
2013-08-26 13:48   ` Daniel Gerber
2013-08-28 19:42     ` Nicolas Goaziou
2013-08-29 10:01       ` Daniel Gerber
2013-10-24 18:05         ` Nicolas Goaziou [this message]
2013-12-03  8:52           ` Daniel Gerber
2013-12-03 20:12             ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vc0msfxr.fsf@gmail.com \
    --to=n.goaziou@gmail.com \
    --cc=daniel.g.gerber@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).