org-odt.el (and org-e-odt.el): Simplify the way style/schema files are found

* org-odt.el (org-odt-lib-dir, org-odt-data-dir)
(org-odt-schema-dir-list, org-odt-styles-dir-list): Delete.
(org-export-odt-schema-dir, org-odt-styles-dir): Infer the
correct directories without requiring other variables.

* org-fixup.el (org-make-org-version, org-make-autoloads):
Don't define `org-odt-data-dir' in org-version.el.

* contrib/lisp/org-e-odt.el (org-e-odt-lib-dir, org-e-odt-data-dir)
(org-e-odt-schema-dir-list, org-e-odt-styles-dir-list): Delete.
(org-e-odt-schema-dir, org-e-odt-styles-dir): Infer the
correct directories without requiring other variables.
This commit is contained in:
Bastien Guerry 2012-10-02 14:46:44 +02:00
parent 16e0730342
commit d042e3add1
3 changed files with 99 additions and 215 deletions

View file

@ -107,18 +107,6 @@
;;; Internal Variables ;;; Internal Variables
(defconst org-e-odt-lib-dir
(file-name-directory load-file-name)
"Location of ODT exporter.
Use this to infer values of `org-e-odt-styles-dir' and
`org-e-odt-schema-dir'.")
(defvar org-e-odt-data-dir
(expand-file-name "../../etc/" org-e-odt-lib-dir)
"Data directory for ODT exporter.
Use this to infer values of `org-e-odt-styles-dir' and
`org-e-odt-schema-dir'.")
(defconst org-e-odt-special-string-regexps (defconst org-e-odt-special-string-regexps
'(("\\\\-" . "­\\1") ; shy '(("\\\\-" . "­\\1") ; shy
("---\\([^-]\\)" . "—\\1") ; mdash ("---\\([^-]\\)" . "—\\1") ; mdash
@ -126,69 +114,34 @@ Use this to infer values of `org-e-odt-styles-dir' and
("\\.\\.\\." . "…")) ; hellip ("\\.\\.\\." . "…")) ; hellip
"Regular expressions for special string conversion.") "Regular expressions for special string conversion.")
(defconst org-e-odt-schema-dir-list
(list
(and org-e-odt-data-dir
(expand-file-name "./schema/" org-e-odt-data-dir)) ; bail out
(eval-when-compile
(and (boundp 'org-e-odt-data-dir) org-e-odt-data-dir ; see make install
(expand-file-name "./schema/" org-e-odt-data-dir))))
"List of directories to search for OpenDocument schema files.
Use this list to set the default value of
`org-e-odt-schema-dir'. The entries in this list are
populated heuristically based on the values of `org-e-odt-lib-dir'
and `org-e-odt-data-dir'.")
(defconst org-e-odt-styles-dir-list
(list
(and org-e-odt-data-dir
(expand-file-name "./styles/" org-e-odt-data-dir)) ; bail out
(eval-when-compile
(and (boundp 'org-e-odt-data-dir) org-e-odt-data-dir ; see make install
(expand-file-name "./styles/" org-e-odt-data-dir)))
(expand-file-name "../../etc/styles/" org-e-odt-lib-dir) ; git
(expand-file-name "./etc/styles/" org-e-odt-lib-dir) ; elpa
(expand-file-name "./org/" data-directory) ; system
)
"List of directories to search for OpenDocument styles files.
See `org-e-odt-styles-dir'. The entries in this list are populated
heuristically based on the values of `org-e-odt-lib-dir' and
`org-e-odt-data-dir'.")
(defconst org-e-odt-styles-dir (defconst org-e-odt-styles-dir
(let* ((styles-dir (let* ((d (expand-file-name (org-find-library-dir "org-e-odt.el")))
(catch 'styles-dir (styles-dir-list (list
(message "Debug (org-e-odt): Searching for OpenDocument styles files...") (concat d "../../etc/styles/") ;; Git
(mapc (lambda (styles-dir) (concat d "../../etc/org/") ;; system
(when styles-dir (concat d "../etc/org/"))) ;; ELPA org-plus
(message "Debug (org-e-odt): Trying %s..." styles-dir) styles-dir)
(when (and (file-readable-p (setq styles-dir
(expand-file-name (car
"OrgOdtContentTemplate.xml" styles-dir)) (delq nil
(file-readable-p (mapcar (lambda (sd)
(expand-file-name (when (and (file-readable-p
"OrgOdtStyles.xml" styles-dir))) (expand-file-name
(message "Debug (org-e-odt): Using styles under %s" "OrgOdtContentTemplate.xml" sd))
styles-dir) (file-readable-p
(throw 'styles-dir styles-dir)))) (expand-file-name
org-e-odt-styles-dir-list) "OrgOdtStyles.xml" sd)))
nil))) sd))
(unless styles-dir styles-dir-list))))
(error "Error (org-e-odt): Cannot find factory styles files, aborting")) (or styles-dir
styles-dir) (error "Cannot find factory styles files for Org ODT, aborting")))
"Directory that holds auxiliary XML files used by the ODT exporter. "Directory that holds auxiliary XML files used by the ODT exporter.
This directory contains the following XML files - This directory contains the following XML files -
\"OrgOdtStyles.xml\" and \"OrgOdtContentTemplate.xml\". These \"OrgOdtStyles.xml\" and \"OrgOdtContentTemplate.xml\".
XML files are used as the default values of These XML files are used as the default values of
`org-e-odt-styles-file' and `org-export-odt-styles-file' and
`org-e-odt-content-template-file'. `org-export-odt-content-template-file'.")
The default value of this variable varies depending on the
version of org in use and is initialized from
`org-e-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-e-odt-bookmark-prefix "OrgXref.") (defconst org-e-odt-bookmark-prefix "OrgXref.")
@ -380,28 +333,26 @@ visually."
;;;; Document schema ;;;; Document schema
(defcustom org-e-odt-schema-dir (defcustom org-e-odt-schema-dir
(let* ((schema-dir (let* ((d (expand-file-name (org-find-library-dir "org-e-odt.el")))
(catch 'schema-dir (schema-dir-list (list (concat d "../etc/schema/"))) ;; ELPA and Git
(message "Debug (org-e-odt): Searching for OpenDocument schema files...") schema-dir)
(mapc (setq schema-dir
(lambda (schema-dir) (car
(when schema-dir (delq nil
(message "Debug (org-e-odt): Trying %s..." schema-dir) (mapcar (lambda (sd)
(when (and (file-readable-p (when (and (file-readable-p
(expand-file-name "od-manifest-schema-v1.2-cs01.rnc" (expand-file-name
schema-dir)) "od-manifest-schema-v1.2-cs01.rnc" sd))
(file-readable-p (file-readable-p
(expand-file-name "od-schema-v1.2-cs01.rnc" (expand-file-name
schema-dir)) "od-schema-v1.2-cs01.rnc" sd))
(file-readable-p (file-readable-p
(expand-file-name "schemas.xml" schema-dir))) (expand-file-name
(message "Debug (org-e-odt): Using schema files under %s" "schemas.xml" sd)))
schema-dir) sd))
(throw 'schema-dir schema-dir)))) schema-dir-list))))
org-e-odt-schema-dir-list) (or schema-dir
(message "Debug (org-e-odt): No OpenDocument schema files installed") (message "No OpenDocument schema files installed")))
nil)))
schema-dir)
"Directory that contains OpenDocument schema files. "Directory that contains OpenDocument schema files.
This directory contains: This directory contains:
@ -414,15 +365,13 @@ that `rng-schema-locating-files' is updated and auto-validation
of OpenDocument XML takes place based on the value of OpenDocument XML takes place based on the value
`rng-nxml-auto-validate-flag'. `rng-nxml-auto-validate-flag'.
The default value of this variable varies depending on the The OASIS schema files are available only in the Org's private
version of org in use and is initialized from git repository. It is *not* bundled with GNU ELPA tar or
`org-e-odt-schema-dir-list'. The OASIS schema files are available standard Emacs distribution."
only in the org's private git repository. It is *not* bundled
with GNU ELPA tar or standard Emacs distribution."
:type '(choice :type '(choice
(const :tag "Not set" nil) (const :tag "Not set" nil)
(directory :tag "Schema directory")) (directory :tag "Schema directory"))
:group 'org-export-e-odt :group 'org-e-odt
:version "24.1" :version "24.1"
:set :set
(lambda (var value) (lambda (var value)
@ -439,16 +388,13 @@ Also add it to `rng-schema-locating-files'."
(expand-file-name "schemas.xml" schema-dir))) (expand-file-name "schemas.xml" schema-dir)))
schema-dir schema-dir
(when value (when value
(message "Error (org-e-odt): %s has no OpenDocument schema files" (message "No OpenDocument schema files" value))
value))
nil))) nil)))
(when org-e-odt-schema-dir (when org-e-odt-schema-dir
(eval-after-load 'rng-loc (eval-after-load 'rng-loc
'(add-to-list 'rng-schema-locating-files '(add-to-list 'rng-schema-locating-files
(expand-file-name "schemas.xml" (expand-file-name "schemas.xml"
org-e-odt-schema-dir)))))) org-e-odt-schema-dir))))))
;;;; Document styles ;;;; Document styles
(defcustom org-e-odt-content-template-file nil (defcustom org-e-odt-content-template-file nil
@ -1882,8 +1828,7 @@ CONTENTS is nil. INFO is a plist holding contextual information."
;;;; Latex Environment ;;;; Latex Environment
(eval-after-load 'org-e-odt
(eval-after-load 'org-odt
'(ad-deactivate 'org-format-latex-as-mathml)) '(ad-deactivate 'org-format-latex-as-mathml))
;; (defadvice org-format-latex-as-mathml ; FIXME ;; (defadvice org-format-latex-as-mathml ; FIXME

View file

@ -84,52 +84,27 @@
("\\.\\.\\." . "…")) ; hellip ("\\.\\.\\." . "…")) ; hellip
"Regular expressions for special string conversion.") "Regular expressions for special string conversion.")
(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-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))))
"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 (defcustom org-export-odt-schema-dir
(let* ((schema-dir (let* ((d (expand-file-name "../" (org-find-library-dir "org-odt.el")))
(catch 'schema-dir (schema-dir-list (list (concat d "etc/schema/"))) ;; ELPA and Git
(message "Debug (org-odt): Searching for OpenDocument schema files...") schema-dir)
(mapc (setq schema-dir
(lambda (schema-dir) (car
(when schema-dir (delq nil
(message "Debug (org-odt): Trying %s..." schema-dir) (mapcar (lambda (sd)
(when (and (file-readable-p (when (and (file-readable-p
(expand-file-name "od-manifest-schema-v1.2-cs01.rnc" (expand-file-name
schema-dir)) "od-manifest-schema-v1.2-cs01.rnc" sd))
(file-readable-p (file-readable-p
(expand-file-name "od-schema-v1.2-cs01.rnc" (expand-file-name
schema-dir)) "od-schema-v1.2-cs01.rnc" sd))
(file-readable-p (file-readable-p
(expand-file-name "schemas.xml" schema-dir))) (expand-file-name
(message "Debug (org-odt): Using schema files under %s" "schemas.xml" sd)))
schema-dir) sd))
(throw 'schema-dir schema-dir)))) schema-dir-list))))
org-odt-schema-dir-list) (or schema-dir
(message "Debug (org-odt): No OpenDocument schema files installed") (message "No OpenDocument schema files installed")))
nil)))
schema-dir)
"Directory that contains OpenDocument schema files. "Directory that contains OpenDocument schema files.
This directory contains: This directory contains:
@ -142,11 +117,9 @@ that `rng-schema-locating-files' is updated and auto-validation
of OpenDocument XML takes place based on the value of OpenDocument XML takes place based on the value
`rng-nxml-auto-validate-flag'. `rng-nxml-auto-validate-flag'.
The default value of this variable varies depending on the The OASIS schema files are available only in the Org's private
version of org in use and is initialized from git repository. It is *not* bundled with GNU ELPA tar or
`org-odt-schema-dir-list'. The OASIS schema files are available standard Emacs distribution."
only in the org's private git repository. It is *not* bundled
with GNU ELPA tar or standard Emacs distribution."
:type '(choice :type '(choice
(const :tag "Not set" nil) (const :tag "Not set" nil)
(directory :tag "Schema directory")) (directory :tag "Schema directory"))
@ -167,8 +140,7 @@ Also add it to `rng-schema-locating-files'."
(expand-file-name "schemas.xml" schema-dir))) (expand-file-name "schemas.xml" schema-dir)))
schema-dir schema-dir
(when value (when value
(message "Error (org-odt): %s has no OpenDocument schema files" (message "No OpenDocument schema files" value))
value))
nil))) nil)))
(when org-export-odt-schema-dir (when org-export-odt-schema-dir
(eval-after-load 'rng-loc (eval-after-load 'rng-loc
@ -176,56 +148,33 @@ Also add it to `rng-schema-locating-files'."
(expand-file-name "schemas.xml" (expand-file-name "schemas.xml"
org-export-odt-schema-dir)))))) 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 (defconst org-odt-styles-dir
(let* ((styles-dir (let* ((d (expand-file-name "../" (org-find-library-dir "org-odt.el")))
(catch 'styles-dir (styles-dir-list (list
(message "Debug (org-odt): Searching for OpenDocument styles files...") (concat d "etc/styles/") ;; ELPA and Git
(mapc (lambda (styles-dir) (concat d "etc/org/")))
(when styles-dir styles-dir)
(message "Debug (org-odt): Trying %s..." styles-dir) (setq styles-dir
(when (and (file-readable-p (car
(expand-file-name (delq nil
"OrgOdtContentTemplate.xml" styles-dir)) (mapcar (lambda (sd)
(file-readable-p (when (and (file-readable-p
(expand-file-name (expand-file-name
"OrgOdtStyles.xml" styles-dir))) "OrgOdtContentTemplate.xml" sd))
(message "Debug (org-odt): Using styles under %s" (file-readable-p
styles-dir) (expand-file-name
(throw 'styles-dir styles-dir)))) "OrgOdtStyles.xml" sd)))
org-odt-styles-dir-list) sd))
nil))) styles-dir-list))))
(unless styles-dir (or styles-dir
(error "Error (org-odt): Cannot find factory styles files, aborting")) (error "Cannot find factory styles files for Org ODT, aborting")))
styles-dir)
"Directory that holds auxiliary XML files used by the ODT exporter. "Directory that holds auxiliary XML files used by the ODT exporter.
This directory contains the following XML files - This directory contains the following XML files -
\"OrgOdtStyles.xml\" and \"OrgOdtContentTemplate.xml\". These \"OrgOdtStyles.xml\" and \"OrgOdtContentTemplate.xml\".
XML files are used as the default values of These XML files are used as the default values of
`org-export-odt-styles-file' and `org-export-odt-styles-file' and
`org-export-odt-content-template-file'. `org-export-odt-content-template-file'.")
The default value of this variable varies depending on the
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.")
(defvar org-odt-file-extensions (defvar org-odt-file-extensions
'(("odt" . "OpenDocument Text") '(("odt" . "OpenDocument Text")

View file

@ -50,14 +50,7 @@ the Git work tree)."
\"The Git version of org-mode. \"The Git version of org-mode.
Inserted by installing org-mode or when a release is made.\" Inserted by installing org-mode or when a release is made.\"
(let ((org-git-version \"" org-git-version "\")) (let ((org-git-version \"" org-git-version "\"))
org-git-version)) org-git-version))")
;;;\#\#\#autoload
\(defvar org-odt-data-dir \"" odt-dir "\"
\"The location of ODT styles.\")
\f\n\(provide 'org-version\)
\f\n;; Local Variables:\n;; version-control: never
;; no-byte-compile: t
;; coding: utf-8\n;; End:\n;;; org-version.el ends here\n")
(toggle-read-only 0) (toggle-read-only 0)
(write-file "org-version.el"))) (write-file "org-version.el")))
@ -87,10 +80,7 @@ force re-compilation. This function is provided for easier
manual install when the build system can't be used." manual install when the build system can't be used."
(let* ((origin default-directory) (let* ((origin default-directory)
(dirlisp (org-find-library-dir "org")) (dirlisp (org-find-library-dir "org"))
(dirorg (concat dirlisp "../" )) (dirorg (concat dirlisp "../" )))
(dirodt (if (boundp 'org-odt-data-dir)
org-odt-data-dir
(concat dirorg "etc/"))))
(unwind-protect (unwind-protect
(progn (progn
(cd dirlisp) (cd dirlisp)