summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAchim Gratz <Stromeko@Stromeko.DE>2012-05-07 21:21:28 +0200
committerBastien Guerry <bzg@altern.org>2012-05-18 07:45:45 +0200
commite7d2e4e18694cb8c4bec5a81815bf7ef9c8078a6 (patch)
tree4f4f3bb9904a8e6bb78e44511491699231434830
parentbcced6a51d792f79afd4bb3b366820ec28759664 (diff)
downloadorg-mode-e7d2e4e18694cb8c4bec5a81815bf7ef9c8078a6.tar.gz
ensure that M-x org-version always delivers something useful
* UTILITIES/org-fixup.el (org-make-org-version): change defconst to defun for org-release and org-git-version and close over those variables (do not make them global anymore). * UTILITIES/org-fixup.el (org-fixup): check for org-version.el or try to use git to get the version from the worktree (code uses parts of the former implementation from org.el). * lisp/org.el (org-version): use functions instead of global variables to get the version strings and remove the defvaralias to org-version. Warn when encountering a mixed installation (org and org-install.el should be found in the same directory). Supported use-cases: 1) Org uninstalled (and possibly uncompiled) from Git or tarball. 1a) No org-version.el or org-install.el exists in worktree. Partially supported configuration, org version is determined from git if possible via UTILITIES/org-fixup.el. However, Emacs versions delivered with orgmode will provide autoloads that may or may not work with that version of org (mixed installation). If such a situation is encountered, warn the user. It can work if the autoloads from the installation match the ones that would be generated for the worktree, which generelly is only the case if there is a relatively recent installation in site-lisp. 1b) Autoload file org-install.el exists in worktree. Fully supported configuration, org version is determined from git if possible via UTILITIES/org-fixup.el. 1c) Both org-version.el or org-install.el exist in worktree. Recommended configuration for 1), org version is taken from org-version.el (git never gets invoked). 2) Org installed. Both org-version.el and org-install.el must exist in install directory. Only supported configuration for 2), org version is taken from org-version.el (git never gets invoked since UTILITIES/org-fixup.el is not available). Any unsupported configuration should still yield a version string, but it will contain "N/A" to alert the user about a botched org installation.
-rw-r--r--UTILITIES/org-fixup.el74
-rw-r--r--lisp/org.el35
2 files changed, 76 insertions, 33 deletions
diff --git a/UTILITIES/org-fixup.el b/UTILITIES/org-fixup.el
index 17f8057..9d0dfa2 100644
--- a/UTILITIES/org-fixup.el
+++ b/UTILITIES/org-fixup.el
@@ -24,28 +24,34 @@
;;
;;; Commentary:
-(require 'find-func)
(require 'org-compat)
(require 'autoload)
(defun org-make-org-version (org-release org-git-version odt-dir)
(find-file "org-version.el")
(erase-buffer)
- (insert ";;; org-version.el --- autogenerated file, do not edit\n;;\n;;; Code:\n")
- (insert ";;;\#\#\#autoload\n")
- (insert "(defconst org-release \"" org-release "\"\n")
- (insert " \"The release version of org-mode.\n")
- (insert " Inserted by installing org-mode or when a release is made.\")\n")
- (insert ";;;\#\#\#autoload\n")
- (insert "(defconst org-git-version \"" org-git-version "\"\n")
- (insert " \"The Git version of org-mode.\n")
- (insert " Inserted by installing org-mode or when a release is made.\")\n")
- (insert ";;;\#\#\#autoload\n")
- (insert "(defconst org-odt-data-dir \"" odt-dir "\"\n")
- (insert " \"The location of ODT styles.\")\n")
- (insert "\f\n;; Local Variables:\n;; version-control: never\n")
- (insert ";; no-byte-compile: t\n")
- (insert ";; coding: utf-8\n;; End:\n;;; org-version.el ends here\n")
+ (insert "\
+;;; org-version.el --- autogenerated file, do not edit
+;;
+;;; Code:
+;;;\#\#\#autoload
+\(defun org-release ()
+ \"The release version of org-mode.
+ Inserted by installing org-mode or when a release is made.\"
+ (let ((org-release \"" org-release "\"))
+ org-release))
+;;;\#\#\#autoload
+\(defun org-git-version ()
+ \"The Git version of org-mode.
+ Inserted by installing org-mode or when a release is made.\"
+ (let ((org-git-version \"" org-git-version "\"))
+ org-git-version))
+;;;\#\#\#autoload
+\(defconst org-odt-data-dir \"" odt-dir "\"
+ \"The location of ODT styles.\")
+\f\n;; Local Variables:\n;; version-control: never
+;; no-byte-compile: t
+;; coding: utf-8\n;; End:\n;;; org-version.el ends here\n")
(save-buffer))
(defun org-make-org-install (absfile)
@@ -60,12 +66,40 @@
(insert ";; coding: utf-8\n;; End:\n;;; org-install.el ends here\n")
(save-buffer))
-(defun org-fixup ()
- (message "might as well do something, but not now")
-)
+(defmacro org-fixup ()
+ (let* ((origin default-directory)
+ (dirlisp (org-find-library-name "org"))
+ (dirorg (concat dirlisp "../" ))
+ (dirgit (concat dirorg ".git/" ))
+ (org-version "N/A-fixup")
+ (org-git-version "N/A-fixup !!check installation!!"))
+ (if (load (concat dirlisp "org-version.el") 'noerror 'nomessage 'nosuffix 'mustsuffix)
+ (setq org-version (org-release)
+ org-git-version (org-git-version))
+ (when (and (file-exists-p dirgit)
+ (executable-find "git"))
+ (unwind-protect
+ (progn
+ (cd dirorg)
+ (when (eql 0 (shell-command "git describe --abbrev=6 HEAD"))
+ (with-current-buffer "*Shell Command Output*"
+ (goto-char (point-min))
+ (setq git-version (buffer-substring (point) (point-at-eol))))
+ (when (string-match "\\S-"
+ (shell-command-to-string
+ "git diff-index --name-only HEAD --"))
+ (setq git-version (concat git-version "-dirty")))
+ (setq org-version (and (string-match "_\\([^-]+\\)-" git-version)
+ (match-string 1 git-version)))
+ (setq org-git-version git-version)))
+ (cd origin))))
+ `(progn
+ (defun org-release () ,org-version)
+ (defun org-git-version () ,org-git-version)
+ "org-fixup.el: redefined org version."
+ )))
(provide 'org-fixup)
-
;; Local Variables:
;; no-byte-compile: t
diff --git a/lisp/org.el b/lisp/org.el
index 24efc40..8825d6c 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -208,25 +208,34 @@ identifier."
:group 'org-id)
;;; Version
-
-(defvaralias 'org-version 'org-release)
+(eval-when-compile
+ (defun org-release () "N/A")
+ (defun org-git-version () "N/A !!check installation!!")
+ (and (load (concat (org-find-library-name "org") "../UTILITIES/org-fixup.el")
+ 'noerror 'nomessage 'nosuffix 'mustsuffix)
+ (org-fixup)))
;;;###autoload
(defun org-version (&optional here)
"Show the org-mode version in the echo area.
With prefix arg HERE, insert it at point."
(interactive "P")
- (let* ((origin default-directory)
- (version (if (boundp 'org-release) org-release "N/A"))
- (git-version (if (boundp 'org-git-version) org-git-version "N/A"))
- (org-install (ignore-errors (find-library-name "org-install")))
- (version_ (format "Org-mode version %s (%s @ %s)"
- version
- git-version
- (if org-install org-install "org-install.el can not be found!"))))
+ (let* ((org-dir (ignore-errors (org-find-library-name "org")))
+ (org-install-dir (ignore-errors (org-find-library-name "org-install.el")))
+ (org-version (org-release))
+ (git-version (org-git-version))
+ (version (format "Org-mode version %s (%s @ %s)"
+ org-version
+ git-version
+ (if org-install-dir
+ (if (string= org-dir org-install-dir)
+ org-install-dir
+ (concat "mixed installation! " org-install-dir " and " org-dir))
+ "org-install.el can not be found!"))))
(if (org-called-interactively-p 'interactive)
- (if here (insert version_)
- (message version_))
- version)))
+ (if here
+ (insert version)
+ (message version))
+ org-version)))
;;; Compatibility constants