emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* :completion function isn't run anymore?
@ 2015-11-26 23:01 Julien Cubizolles
  2015-11-27 15:49 ` Julien Cubizolles
  0 siblings, 1 reply; 7+ messages in thread
From: Julien Cubizolles @ 2015-11-26 23:01 UTC (permalink / raw)
  To: emacs-orgmode


I noticed that the :preparation-function defined in
org-publish-project-alist isn't run anymore when publishing a project.

Consider the following, it's a stripped-down version of the setup I have
been using on many documents for a few years.

--8<---------------cut here---------------start------------->8---
#+begin_src emacs-lisp :tangle none :exports none
  (setq org-export-in-background nil)
  (defun remove-org-suffix (name)
  "Remove the .org from a file name"
  (if (string-match "\\(.*\\)\\.org" name)
      (substring name (match-beginning 1) (match-end 1))
    name))
  (defun jc-org-publish-rename (suffix version)
    "Rename file.suffix to file-version.suffix when buffer is visiting file.org"
    (let*   ((file-base-name (remove-org-suffix (buffer-file-name)))
             (file-suffix-name (concat file-base-name "." suffix))
             (file-version-suffix-name (concat file-base-name "-" version  "." suffix)))
    (if (file-exists-p file-suffix-name)
        (rename-file file-suffix-name file-version-suffix-name t))
    )
    )
  (defun jc-org-publish-rename-pdf (suffix)
    "Rename file.pdf to file-suffix.pdf when buffer is visiting file.org"
  (let*   ((file-base-name (remove-org-suffix (buffer-file-name)))
  (file-pdf-name (concat file-base-name ".pdf"))
  (file-suffix-pdf-name (concat file-base-name "-" suffix  ".pdf")))
  (if (file-exists-p file-pdf-name)
      (rename-file file-pdf-name file-suffix-pdf-name 1))
    )
  )
  (defun jc-org-publish-rename-beamer-pdf ()
  "Rename file.pdf to file-beamer.pdf and file.tex to file-beamer.tex when buffer is visiting file.org"
  (jc-org-publish-rename '"pdf" '"beamer")
  (jc-org-publish-rename '"tex" '"beamer"))

  (setq org-publish-project-alist
        `(("beamer"
           :base-directory "./"
           :publishing-directory "./"
           :publishing-function org-beamer-publish-to-pdf
           :exclude ".*"
           :include ,(list (file-name-nondirectory buffer-file-name))
           :completion-function jc-org-publish-rename-beamer-pdf
           )
          ))
#+end_src

#+RESULTS:
| beamer | :base-directory | ./ | :publishing-directory | ./ | :publishing-function | org-beamer-publish-to-pdf | :exclude | .* | :include | (test.org) | :completion-function | jc-org-publish-rename-beamer-pdf |

* 1st section
** 1st subsection
** 2nd subsection
--8<---------------cut here---------------end--------------->8---

Save the to test.org and publish using the "beamer"
project. org-beamer-publish-to-pdf creates test.pdf as it should but the
completion-function should rename test.tex and test.pdf test-beamer.tex
and test-beamer.pdf. It doesn't. Even worse, you can type whatever
function name for :completion-function, even if it's not defined, and
the exporter won't complain.

However, with emacs -Q (and the version of org-mode shipped with it), I
recover the expected behaviour

With  emacs -Q -l ~/test.el, the problem reoccurs

~/test.el
--8<---------------cut here---------------start------------->8---
(add-to-list 'load-path "~/info/emacs/org-mode/lisp")
(add-to-list 'load-path "~/info/emacs/org-mode/contrib/lisp")
--8<---------------cut here---------------end--------------->8---
~/info/emacs/org-mode/ is my git repo of org-mode.

I'm running GNU Emacs 25.0.50.2 (x86_64-pc-linux-gnu, GTK+ Version 3.14.13) of 2015-10-21

Julien.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: :completion function isn't run anymore?
  2015-11-26 23:01 :completion function isn't run anymore? Julien Cubizolles
@ 2015-11-27 15:49 ` Julien Cubizolles
  2015-11-29 13:20   ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: Julien Cubizolles @ 2015-11-27 15:49 UTC (permalink / raw)
  To: emacs-orgmode

Julien Cubizolles <j.cubizolles@free.fr> writes:

> I noticed that the :preparation-function defined in
> org-publish-project-alist isn't run anymore when publishing a project.

It seems the preparation-function isn't run either. Consider the
following more simple examples

--8<---------------cut here---------------start------------->8---

#+TITLE: Hello
#+begin_src emacs-lisp :tangle none :exports none
  (setq org-export-in-background nil)
  (defun jc-preparation ()
  "Preparation functions to be run before actually pubishing"
  (setq org-latex-title-command "")
  )
  (setq org-publish-project-alist
	`(("pdf"
           :base-directory "./"
           :publishing-directory "./"
           :preparation-function jc-preparation
           :publishing-function org-beamer-publish-to-pdf
           :exclude ".*"
           :include ,(list (file-name-nondirectory buffer-file-name))
           )
          ))
#+end_src

#+RESULTS:
| pdf | :base-directory | ./ | :publishing-directory | ./ | :preparation-function | jc-preparation | :publishing-function | org-beamer-publish-to-pdf | :exclude | .* | :include | (test.org) |

* 1st section
** 1st subsection
** 2nd subsection
--8<---------------cut here---------------end--------------->8---

Save the to test.org and publish using the "pdf"
project. org-beamer-publish-to-pdf creates test.pdf as it should but the
preparation-function should remove the titlepage wich it doesn't.

However, with emacs -Q (and the version of org-mode shipped with it), I
recover the expected behaviour.

With  emacs -Q -l ~/test.el, the problem reoccurs

~/test.el

--8<---------------cut here---------------start------------->8---
(add-to-list 'load-path "~/info/emacs/org-mode/lisp")
(add-to-list 'load-path "~/info/emacs/org-mode/contrib/lisp")
--8<---------------cut here---------------end--------------->8---

~/info/emacs/org-mode/ is my git repo of org-mode.

 I'm running GNU Emacs 25.0.50.2 (x86_64-pc-linux-gnu, GTK+ Version 3.14.13) of 2015-10-21

Julien.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: :completion function isn't run anymore?
  2015-11-27 15:49 ` Julien Cubizolles
@ 2015-11-29 13:20   ` Nicolas Goaziou
  2015-11-29 20:38     ` Julien Cubizolles
  0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2015-11-29 13:20 UTC (permalink / raw)
  To: Julien Cubizolles; +Cc: emacs-orgmode

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

Hello,

Julien Cubizolles <j.cubizolles@free.fr> writes:

> Julien Cubizolles <j.cubizolles@free.fr> writes:
>
>> I noticed that the :preparation-function defined in
>> org-publish-project-alist isn't run anymore when publishing a project.
>
> It seems the preparation-function isn't run either. Consider the
> following more simple examples
>
>
> #+TITLE: Hello
> #+begin_src emacs-lisp :tangle none :exports none
>   (setq org-export-in-background nil)
>   (defun jc-preparation ()
>   "Preparation functions to be run before actually pubishing"
>   (setq org-latex-title-command "")
>   )
>   (setq org-publish-project-alist
> 	`(("pdf"
>            :base-directory "./"
>            :publishing-directory "./"
>            :preparation-function jc-preparation
>            :publishing-function org-beamer-publish-to-pdf
>            :exclude ".*"
>            :include ,(list (file-name-nondirectory buffer-file-name))
>            )
>           ))
> #+end_src
>
> #+RESULTS:
> | pdf | :base-directory | ./ | :publishing-directory | ./ | :preparation-function | jc-preparation | :publishing-function | org-beamer-publish-to-pdf | :exclude | .* | :include | (test.org) |
>
> * 1st section
> ** 1st subsection
> ** 2nd subsection
>
> Save the to test.org and publish using the "pdf"
> project. org-beamer-publish-to-pdf creates test.pdf as it should but the
> preparation-function should remove the titlepage wich it doesn't.

I didn't investigate much the issue yet, but, out of curiosity, would
the following patch solve the issue:


Regards,

-- 
Nicolas Goaziou

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-publish.el-Fix-preparation-function-and-completio.patch --]
[-- Type: text/x-diff, Size: 1862 bytes --]

From 28dc2a08846992f0565897ae8e061da685cd776d Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Date: Sun, 29 Nov 2015 14:16:37 +0100
Subject: [PATCH] ox-publish.el: Fix :preparation-function and
 :completion-function

* lisp/ox-publish.el (org-publish-projects): Do not use `run-hooks' in
  a lexical binding environment.

Reported-by: Julien Cubizolles <j.cubizolles@free.fr>
<http://permalink.gmane.org/gmane.emacs.orgmode/103124>
---
 lisp/ox-publish.el | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el
index 90f307c..6c65e52 100644
--- a/lisp/ox-publish.el
+++ b/lisp/ox-publish.el
@@ -667,9 +667,7 @@ 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 ((preparation-function
-	     (plist-get project-plist :preparation-function)))
-	(when preparation-function (run-hooks 'preparation-function)))
+      (mapc #'funcall (plist-get project-plist :preparation-function))
       ;; Each project uses its own cache file.
       (org-publish-initialize-cache (car project))
       (when  (plist-get project-plist :auto-sitemap)
@@ -701,9 +699,7 @@ 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 ((completion-function
-	     (plist-get project-plist :completion-function)))
-	(when completion-function (run-hooks 'completion-function)))
+      (mapc #'funcall (plist-get project-plist :completion-function))
       (org-publish-write-cache-file))))
 
 (defun org-publish-org-sitemap (project &optional sitemap-filename)
-- 
2.6.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: :completion function isn't run anymore?
  2015-11-29 13:20   ` Nicolas Goaziou
@ 2015-11-29 20:38     ` Julien Cubizolles
  2015-11-29 20:53       ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: Julien Cubizolles @ 2015-11-29 20:38 UTC (permalink / raw)
  To: emacs-orgmode, Nicolas Goaziou

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:


> I didn't investigate much the issue yet, but, out of curiosity, would
> the following patch solve the issue:

Thanks for looking into it. It seems the completion-function is now
being accessed but unfortunately something is still wrong. The error
message is

--8<---------------cut here---------------start------------->8---
org-publish-projects: Wrong type argument: sequencep, jc-org-publish-rename-beamer-pdf
--8<---------------cut here---------------end--------------->8---

On a related note, I finally figured why rebasing the gif tree didn't
fix this problem: I was forgetting to recompile and was still using the
former .elc files...

If I'm to bisect, is it possible to reload all org-mode files without
restarting emacs ? Would M-x org-mode be enough ?

Julien.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: :completion function isn't run anymore?
  2015-11-29 20:38     ` Julien Cubizolles
@ 2015-11-29 20:53       ` Nicolas Goaziou
  2015-11-29 21:19         ` Julien Cubizolles
  0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2015-11-29 20:53 UTC (permalink / raw)
  To: Julien Cubizolles; +Cc: emacs-orgmode

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

Julien Cubizolles <j.cubizolles@free.fr> writes:

> Thanks for looking into it. It seems the completion-function is now
> being accessed but unfortunately something is still wrong. The error
> message is
>
> org-publish-projects: Wrong type argument: sequencep,
> jc-org-publish-rename-beamer-pdf

I forgot that :preparation-function could also be a single function.
Attached is the updated patch to test.

> If I'm to bisect, is it possible to reload all org-mode files without
> restarting emacs ? Would M-x org-mode be enough ?

See `org-reload'.

Regards,

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-publish.el-Fix-preparation-function-and-completio.patch --]
[-- Type: text/x-diff, Size: 2009 bytes --]

From 1180a87c002c8efc0687a051bec536ee6c34eec0 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Date: Sun, 29 Nov 2015 14:23:50 +0100
Subject: [PATCH] ox-publish.el: Fix :preparation-function and
 :completion-function

* lisp/ox-publish.el (org-publish-projects): Do not use `run-hooks' in
  a lexical binding environment.

Reported-by: Julien Cubizolles <j.cubizolles@free.fr>
<http://permalink.gmane.org/gmane.emacs.orgmode/103124>
---
 lisp/ox-publish.el | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el
index 90f307c..b49b9d3 100644
--- a/lisp/ox-publish.el
+++ b/lisp/ox-publish.el
@@ -667,9 +667,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 ((preparation-function
-	     (plist-get project-plist :preparation-function)))
-	(when preparation-function (run-hooks 'preparation-function)))
+      (let ((f (plist-get project-plist :preparation-function)))
+	(cond ((consp f) (mapc #'funcall f))
+	      ((functionp f) (funcall f))))
       ;; Each project uses its own cache file.
       (org-publish-initialize-cache (car project))
       (when  (plist-get project-plist :auto-sitemap)
@@ -701,9 +701,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 ((completion-function
-	     (plist-get project-plist :completion-function)))
-	(when completion-function (run-hooks 'completion-function)))
+      (let ((f (plist-get project-plist :completion-function)))
+	(cond ((consp f) (mapc #'funcall f))
+	      ((functionp f) (funcall f))))
       (org-publish-write-cache-file))))
 
 (defun org-publish-org-sitemap (project &optional sitemap-filename)
-- 
2.6.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: :completion function isn't run anymore?
  2015-11-29 20:53       ` Nicolas Goaziou
@ 2015-11-29 21:19         ` Julien Cubizolles
  2015-11-29 21:39           ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: Julien Cubizolles @ 2015-11-29 21:19 UTC (permalink / raw)
  To: emacs-orgmode, Nicolas Goaziou

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:


> I forgot that :preparation-function could also be a single function.
> Attached is the updated patch to test.

It's fixed, thanks. Once again, I'm amazed by the reactivity and
efficiency of everyone in the org-mode community.

> See `org-reload'.

Thanks for that too. That will come in handy.

Julien.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: :completion function isn't run anymore?
  2015-11-29 21:19         ` Julien Cubizolles
@ 2015-11-29 21:39           ` Nicolas Goaziou
  0 siblings, 0 replies; 7+ messages in thread
From: Nicolas Goaziou @ 2015-11-29 21:39 UTC (permalink / raw)
  To: Julien Cubizolles; +Cc: emacs-orgmode

Julien Cubizolles <j.cubizolles@free.fr> writes:

> It's fixed, thanks.

Applied. Thank you.

Regards,

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-11-29 21:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-26 23:01 :completion function isn't run anymore? Julien Cubizolles
2015-11-27 15:49 ` Julien Cubizolles
2015-11-29 13:20   ` Nicolas Goaziou
2015-11-29 20:38     ` Julien Cubizolles
2015-11-29 20:53       ` Nicolas Goaziou
2015-11-29 21:19         ` Julien Cubizolles
2015-11-29 21:39           ` Nicolas Goaziou

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).