1 ;;; org-track.el --- Track the most recent Org-mode version available.
3 ;; Copyright (C) 2009-2011
4 ;; Free Software Foundation, Inc.
6 ;; Author: Bastien Guerry <bzg at altern dot org>
7 ;; Eric S Fraga <e.fraga at ucl.ac dot uk>
8 ;; Sebastian Rose <sebastian_rose at gmx dot de>
9 ;; The Worg people http://orgmode.org/worg/
10 ;; Keywords: outlines, hypermedia, calendar, wp
11 ;; Homepage: http://orgmode.org
14 ;; Released under the GNU General Public License version 3
15 ;; see: http://www.gnu.org/licenses/gpl-3.0.html
17 ;; This file is part of GNU Emacs.
19 ;; GNU Emacs is free software: you can redistribute it and/or modify
20 ;; it under the terms of the GNU General Public License as published by
21 ;; the Free Software Foundation, either version 3 of the License, or
22 ;; (at your option) any later version.
24 ;; GNU Emacs is distributed in the hope that it will be useful,
25 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
26 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 ;; GNU General Public License for more details.
29 ;; You should have received a copy of the GNU General Public License
30 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
31 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
35 ;; Download the latest development tarball, unpack and optionally compile it
39 ;; (require 'org-track)
41 ;; ;; ... somewhere in your setup (use customize):
43 ;; (setq org-track-directory "~/test/")
44 ;; (setq org-track-compile-sources nil)
45 ;; (setq org-track-remove-package t)
47 ;; M-x org-track-update RET
52 (require 'url-handlers
)
53 (autoload 'url-file-local-copy
"url-handlers")
54 (autoload 'url-generic-parse-url
"url-parse")
62 (defgroup org-track nil
63 "Track the most recent Org-mode version available.
65 To use org-track, adjust `org-track-directory'.
66 Org will download the archived latest git version for you,
67 unpack it into that directory (i.e. a subdirectory
68 `org-mode/' is added), create the autoloads file
69 `org-install.el' for you and, optionally, compile the
71 All you'll have to do is call `M-x org-track-update' from
76 (defcustom org-track-directory
"~/.emacs.d/org/lisp"
77 "Directory where your org-mode/ directory lives.
78 If that directory does not exist, it will be created."
81 (defcustom org-track-compile-sources t
82 "If `nil', never compile org-sources.
83 Org will only create the autoloads file `org-install.el' for
84 you then. If `t', compile the sources, too.
85 Note, that emacs preferes compiled elisp files over
89 (defcustom org-track-org-url
"http://orgmode.org/"
90 "The URL where the package to download can be found.
91 Please append a slash."
94 (defcustom org-track-org-package
"org-latest.tar.gz"
95 "The basename of the package you use.
96 Defaults to the development version of Org-mode.
97 This should be a *.tar.gz package, since emacs provides all
98 you need to unpack it."
101 (defcustom org-track-remove-package nil
102 "Remove org-latest.tar.gz after updates?"
111 (defun org-track-update ()
112 "Update to current Org-mode version.
113 Also, generate autoloads and evtl. compile the sources."
115 (let* ((base (file-truename org-track-directory
))
116 (org-exists (file-exists-p
118 (concat base
"/org-mode/lisp/org.el"))))
119 (nobase (not (file-directory-p
120 (file-truename org-track-directory
)))))
123 (format "Directory %s does not exist. Create it?" base
))
124 (make-directory base t
)
127 (message "Not creating %s - giving up." org-track-directory
)
130 (org-track-fetch-package)
131 (org-track-compile-org))
132 (error (message "%s" (error-message-string err
)))))))
137 ;;; tar related functions
139 ;; `url-retrieve-synchronously' fetches files synchronously. How can we ensure
140 ;; that? If the maintainers of that package decide, that an assynchronous
141 ;; download might be better??? (used by `url-file-local-copy')
144 (defun org-track-fetch-package (&optional directory
)
145 "Fetch Org package depending on `org-track-fetch-package-extension'.
146 If DIRECTORY is defined, unpack the package there, i.e. add the
147 subdirectory org-mode/ to DIRECTORY."
148 (interactive "Dorg-track directory: ")
150 (if (string-match "/$" org-track-org-url
)
152 (concat org-track-org-url
"/"))
153 org-track-org-package
))
155 (or directory org-track-directory
)))
156 (target (file-truename
157 (concat base
"/" org-track-org-package
)))
158 url download tarbuff
)
159 (message "Fetching to %s - this might take some time..." base
)
160 (setq url
(url-generic-parse-url pack
))
161 (setq download
(url-file-local-copy url
)) ;; errors if fail
162 (copy-file download target t
)
163 (delete-file download
)
164 ;; (tar-mode) leads to dubious errors. We use the auto-mode-alist to
165 ;; ensure tar-mode is used:
166 (add-to-list 'auto-mode-alist
'("org-latest\\.tar\\.gz\\'" . tar-mode
))
167 (setq tarbuff
(find-file target
))
168 (with-current-buffer tarbuff
;; with-temp-buffer does not work with tar-mode??
170 (kill-buffer tarbuff
)
171 (if org-track-remove-package
172 (delete-file target
))))
177 ;;; Compile Org-mode sources
181 (defun org-track-compile-org (&optional directory
)
182 "Compile all *.el files that come with org-mode.
183 Generate the autoloads file `org-install.el'.
185 DIRECTORY is where the directory org-mode/ lives (i.e. the
186 parent directory of your local repo."
188 ;; file-truename expands the filename and removes double slash, if exists:
189 (setq directory
(file-truename
192 (file-truename (concat org-track-directory
"/org-mode/lisp")))
194 (add-to-list 'load-path directory
)
195 (let ((list-of-org-files (file-expand-wildcards (concat directory
"*.el"))))
196 ;; create the org-install file
198 (setq esf
/org-install-file
(concat directory
"org-install.el"))
199 (find-file esf
/org-install-file
)
202 (generate-file-autoloads x
))
204 (insert "\n(provide (quote org-install))\n")
207 (byte-compile-file esf
/org-install-file t
)
210 (if (file-exists-p (concat f
"c"))
211 (delete-file (concat f
"c"))))
213 (if org-track-compile-sources
214 (mapc (lambda (f) (byte-compile-file f
)) list-of-org-files
))))
219 ;;; org-track.el ends here