diff --git a/Makefile b/Makefile index 459487075..520b0fdb6 100644 --- a/Makefile +++ b/Makefile @@ -19,11 +19,10 @@ prefix=/usr/local # Where local lisp files go lispdir = $(prefix)/share/emacs/site-lisp -# Where etc files go -etcdir = $(lispdir)/../etc - -# Where style files go -stylesdir = $(etcdir)/styles +# Where data files go +# $(datadir) contains auxiliary files for use with ODT exporter. +# See comments under DATAFILES. +datadir = $(prefix)/share/emacs/etc # Where info files go infodir = $(prefix)/share/info @@ -35,7 +34,7 @@ infodir = $(prefix)/share/info # Using emacs in batch mode. BATCH=$(EMACS) -batch -q -no-site-file -eval \ - "(setq load-path (cons (expand-file-name \"./lisp/\") (cons \"$(lispdir)\" load-path)))" + "(setq load-path (cons (expand-file-name \"./lisp/\") (cons \"$(lispdir)\" load-path)))" $(BATCH_EXTRA) # Specify the byte-compiler for compiling org-mode files ELC= $(BATCH) -f batch-byte-compile @@ -54,7 +53,7 @@ TEXI2HTML = makeinfo --html --number-sections TEXI2HTMLNOPSLIT = makeinfo --html --no-split --number-sections # How to copy the lisp files and elc files to their distination. -CP = cp -p +CP = cp -pr # Name of the program to install info files INSTALL_INFO=install-info @@ -182,7 +181,26 @@ DOCFILES = doc/org.texi doc/org.pdf doc/org doc/dir \ CARDFILES = doc/orgcard.tex doc/orgcard.pdf doc/orgcard_letter.pdf TEXIFILES = doc/org.texi INFOFILES = doc/org -STYLESFILES = etc/styles/OrgOdtContentTemplate.xml etc/styles/OrgOdtStyles.xml + +# etc/styles contains OpenDocument style files. These files *must* be +# installed for the ODT exporter to function. These files are +# distirbuted with GNU ELPA as well as with stock Emacs >= 24.1. + +# contrib/odt/etc/schema contains OpenDocument schema files. It is +# *desirable* but *not* mandatory that these files be installed. +# These files are not distributed with stock Emacs. This is because +# the terms under which OASIS distributes these files are not +# agreeable to FSF. + +# BasicODConverter-x.y.z.oxt is a LibreOffice extension for converting +# OpenDocument files to numerous other formats. It is similar to +# unoconv and is implemented in StarBasic. It is *desirable* but +# *not* *mandatory* that the converter be installed. It is +# distributed under the same license as GNU Emacs. This file is *not* +# part of GNU Emacs. +DATAFILES = etc/styles \ + # contrib/odt/BasicODConverter/BasicODConverter*.oxt \ + # contrib/odt/etc/schema \ # Package Manager (ELPA) PKG_TAG = $(shell date +%Y%m%d) @@ -219,7 +237,7 @@ update: compile: $(ELCFILES0) $(ELCBFILES) -install: install-lisp install-etc +install: install-lisp install-data doc: doc/org.html doc/org.pdf doc/orgcard.pdf doc/orgcard_letter.pdf doc/orgguide.pdf doc/orgcard.txt @@ -229,6 +247,15 @@ p: g: ${MAKE} pdf && open doc/orgguide.pdf +# Always force re-compilation of org-odt +lisp/org-odt.elc: org-odt-data-dir +org-odt-data-dir: + +# Sleight of hand to "hard code" the value of $(datadir) in +# org-odt.el. See variables `org-odt-styles-dir-list' and +# `org-odt-schema-dir-list'. +install-lisp: BATCH_EXTRA = -eval "(setq org-odt-data-dir (expand-file-name \"$(datadir)\"))" + install-lisp: $(LISPFILES) $(ELCFILES) if [ ! -d $(lispdir) ]; then $(MKDIR) $(lispdir); else true; fi ; $(CP) $(LISPFILES) $(lispdir) @@ -239,9 +266,9 @@ install-info: $(INFOFILES) $(CP) $(INFOFILES) $(infodir) $(INSTALL_INFO) --infodir=$(infodir) $(INFOFILES) -install-etc: $(STYLESFILES) - if [ ! -d $(stylesdir) ]; then $(MKDIR) $(stylesdir); else true; fi ; - $(CP) $(STYLESFILES) $(stylesdir) +install-data: $(DATAFILES) + if [ ! -d $(datadir) ]; then $(MKDIR) $(datadir); else true; fi ; + $(CP) $(DATAFILES) $(datadir) autoloads: lisp/org-install.el diff --git a/lisp/org-odt.el b/lisp/org-odt.el index a81ff2e60..dfba6de1b 100644 --- a/lisp/org-odt.el +++ b/lisp/org-odt.el @@ -72,25 +72,52 @@ ("\\.\\.\\." . "…")) ; hellip "Regular expressions for special string conversion.") -(defconst org-odt-lib-dir (file-name-directory load-file-name)) +(defconst org-odt-lib-dir (file-name-directory load-file-name) + "Location of ODT exporter. +Use this to infer values of `org-odt-styles-dir' and +`org-export-odt-schema-dir'.") + +(defvar org-odt-data-dir nil + "Data directory for ODT exporter. +Use this to infer values of `org-odt-styles-dir' and +`org-export-odt-schema-dir'.") + +(defconst org-odt-styles-dir-list + (list + (and org-odt-data-dir + (expand-file-name "./styles/" org-odt-data-dir)) ; bail out + (eval-when-compile + (and (boundp 'org-odt-data-dir) org-odt-data-dir ; see make install + (expand-file-name "./styles/" org-odt-data-dir))) + (expand-file-name "../etc/styles/" org-odt-lib-dir) ; git + (expand-file-name "./etc/styles/" org-odt-lib-dir) ; elpa + (expand-file-name "./org/" data-directory) ; system + ) + "List of directories to search for OpenDocument styles files. +See `org-odt-styles-dir'. The entries in this list are populated +heuristically based on the values of `org-odt-lib-dir' and +`org-odt-data-dir'.") + (defconst org-odt-styles-dir - (let* ((styles-dir1 (expand-file-name "../etc/styles/" org-odt-lib-dir)) ; git - (styles-dir2 (expand-file-name "./etc/styles/" org-odt-lib-dir)) ; elpa - (styles-dir3 (expand-file-name "./etc/org/" data-directory)) ; system - (styles-dir + (let* ((styles-dir (catch 'styles-dir + (message "Debug (org-odt): Searching for OpenDocument styles files...") (mapc (lambda (styles-dir) - (when (and (file-readable-p - (expand-file-name - "OrgOdtContentTemplate.xml" styles-dir)) - (file-readable-p - (expand-file-name - "OrgOdtStyles.xml" styles-dir))) - (throw 'styles-dir styles-dir))) - (list styles-dir1 styles-dir2 styles-dir3)) + (when styles-dir + (message "Debug (org-odt): Trying %s..." styles-dir) + (when (and (file-readable-p + (expand-file-name + "OrgOdtContentTemplate.xml" styles-dir)) + (file-readable-p + (expand-file-name + "OrgOdtStyles.xml" styles-dir))) + (message "Debug (org-odt): Using styles under %s" + styles-dir) + (throw 'styles-dir styles-dir)))) + org-odt-styles-dir-list) nil))) (unless styles-dir - (error "Cannot find factory styles file. Check package dir layout")) + (error "Error (org-odt): Cannot find factory styles files. Aborting.")) styles-dir) "Directory that holds auxiliary XML files used by the ODT exporter. @@ -101,21 +128,49 @@ This directory contains the following XML files - `org-export-odt-content-template-file'. The default value of this variable varies depending on the -version of org in use. Note that the user could be using org +version of org in use and is initialized from +`org-odt-styles-dir-list'. Note that the user could be using org from one of: org's own private git repository, GNU ELPA tar or standard Emacs.") +(defconst org-odt-schema-dir-list + (list + (and org-odt-data-dir + (expand-file-name "./schema/" org-odt-data-dir)) ; bail out + (eval-when-compile + (and (boundp 'org-odt-data-dir) org-odt-data-dir ; see make install + (expand-file-name "./schema/" org-odt-data-dir))) + (expand-file-name "../contrib/odt/etc/schema/" org-odt-lib-dir) ; git + ) + "List of directories to search for OpenDocument schema files. +Use this list to set the default value of +`org-export-odt-schema-dir'. The entries in this list are +populated heuristically based on the values of `org-odt-lib-dir' +and `org-odt-data-dir'.") + (defcustom org-export-odt-schema-dir - (let ((schema-dir (expand-file-name - "../contrib/odt/etc/schema/" org-odt-lib-dir))) - (if (and (file-readable-p - (expand-file-name "od-manifest-schema-v1.2-cs01.rnc" schema-dir)) - (file-readable-p - (expand-file-name "od-schema-v1.2-cs01.rnc" schema-dir)) - (file-readable-p - (expand-file-name "schemas.xml" schema-dir))) - schema-dir - (prog1 nil (message "Unable to locate OpenDocument schema files.")))) + (let* ((schema-dir + (catch 'schema-dir + (message "Debug (org-odt): Searching for OpenDocument schema files...") + (mapc + (lambda (schema-dir) + (when schema-dir + (message "Debug (org-odt): Trying %s..." schema-dir) + (when (and (file-readable-p + (expand-file-name "od-manifest-schema-v1.2-cs01.rnc" + schema-dir)) + (file-readable-p + (expand-file-name "od-schema-v1.2-cs01.rnc" + schema-dir)) + (file-readable-p + (expand-file-name "schemas.xml" schema-dir))) + (message "Debug (org-odt): Success. Using schema files under %s" + schema-dir) + (throw 'schema-dir schema-dir)))) + org-odt-schema-dir-list) + (message "Debug (org-odt): No OpenDocument schema files installed") + nil))) + schema-dir) "Directory that contains OpenDocument schema files. This directory contains: @@ -129,9 +184,10 @@ of OpenDocument XML takes place based on the value `rng-nxml-auto-validate-flag'. The default value of this variable varies depending on the -version of org in use. The OASIS schema files are available only -in the org's private git repository. It is *not* bundled with -GNU ELPA tar or standard Emacs distribution." +version of org in use and is initialized from +`org-odt-schema-dir-list'. The OASIS schema files are available +only in the org's private git repository. It is *not* bundled +with GNU ELPA tar or standard Emacs distribution." :type '(choice (const :tag "Not set" nil) (directory :tag "Schema directory")) @@ -150,8 +206,10 @@ Also add it to `rng-schema-locating-files'." (file-readable-p (expand-file-name "schemas.xml" schema-dir))) schema-dir - (prog1 nil - (message "Warning (org-odt): Unable to locate OpenDocument schema files."))))) + (when value + (message "Error (org-odt): %s has no OpenDocument schema files" + value)) + nil))) (when org-export-odt-schema-dir (eval-after-load 'rng-loc '(add-to-list 'rng-schema-locating-files