d0581358f1005505384cc37b6ee6118f34bb679a
[org-mode.git] / contrib / lisp / org-track.el
blobd0581358f1005505384cc37b6ee6118f34bb679a
1 ;;; org-track.el --- Track the most recent Org-mode version available.
2 ;;
3 ;; Copyright (C) 2009-2013
4 ;; Free Software Foundation, Inc.
5 ;;
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
12 ;; Version: 6.29a
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 not 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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 ;;; Commentary:
35 ;; WARNING: This library is obsolete, you should use the make targets
36 ;; to keep track of Org latest developments.
38 ;; Download the latest development tarball, unpack and optionally compile it
40 ;; Usage:
42 ;; (require 'org-track)
44 ;; ;; ... somewhere in your setup (use customize):
46 ;; (setq org-track-directory "~/test/")
47 ;; (setq org-track-compile-sources nil)
48 ;; (setq org-track-remove-package t)
50 ;; M-x org-track-update RET
52 (require 'url-parse)
53 (require 'url-handlers)
54 (autoload 'url-file-local-copy "url-handlers")
55 (autoload 'url-generic-parse-url "url-parse")
59 ;;; Variables:
61 (defgroup org-track nil
62 "Track the most recent Org-mode version available.
64 To use org-track, adjust `org-track-directory'.
65 Org will download the archived latest git version for you,
66 unpack it into that directory (i.e. a subdirectory
67 `org-mode/' is added), create the autoloads file
68 `org-loaddefs.el' for you and, optionally, compile the
69 sources.
70 All you'll have to do is call `M-x org-track-update' from
71 time to time."
72 :version "22.1"
73 :group 'org)
75 (defcustom org-track-directory "~/.emacs.d/org/lisp"
76 "Directory where your org-mode/ directory lives.
77 If that directory does not exist, it will be created."
78 :type 'directory)
80 (defcustom org-track-compile-sources t
81 "If `nil', never compile org-sources.
82 Org will only create the autoloads file `org-loaddefs.el' for
83 you then. If `t', compile the sources, too.
84 Note, that emacs preferes compiled elisp files over
85 non-compiled ones."
86 :type 'boolean)
88 (defcustom org-track-org-url "http://orgmode.org/"
89 "The URL where the package to download can be found.
90 Please append a slash."
91 :type 'string)
93 (defcustom org-track-org-package "org-latest.tar.gz"
94 "The basename of the package you use.
95 Defaults to the development version of Org-mode.
96 This should be a *.tar.gz package, since emacs provides all
97 you need to unpack it."
98 :type 'string)
100 (defcustom org-track-remove-package nil
101 "Remove org-latest.tar.gz after updates?"
102 :type 'boolean)
106 ;;; Frontend
108 (defun org-track-update ()
109 "Update to current Org-mode version.
110 Also, generate autoloads and evtl. compile the sources."
111 (interactive)
112 (let* ((base (file-truename org-track-directory))
113 (org-exists (file-exists-p
114 (file-truename
115 (concat base "/org-mode/lisp/org.el"))))
116 (nobase (not (file-directory-p
117 (file-truename org-track-directory)))))
118 (if nobase
119 (when (y-or-n-p
120 (format "Directory %s does not exist. Create it?" base))
121 (make-directory base t)
122 (setq nobase nil)))
123 (if nobase
124 (message "Not creating %s - giving up." org-track-directory)
125 (condition-case err
126 (progn
127 (org-track-fetch-package)
128 (org-track-compile-org))
129 (error (message "%s" (error-message-string err)))))))
133 ;;; tar related functions
135 ;; `url-retrieve-synchronously' fetches files synchronously. How can we ensure
136 ;; that? If the maintainers of that package decide, that an assynchronous
137 ;; download might be better??? (used by `url-file-local-copy')
139 ;;;###autoload
140 (defun org-track-fetch-package (&optional directory)
141 "Fetch Org package depending on `org-track-fetch-package-extension'.
142 If DIRECTORY is defined, unpack the package there, i.e. add the
143 subdirectory org-mode/ to DIRECTORY."
144 (interactive "Dorg-track directory: ")
145 (let* ((pack (concat
146 (if (string-match "/$" org-track-org-url)
147 org-track-org-url
148 (concat org-track-org-url "/"))
149 org-track-org-package))
150 (base (file-truename
151 (or directory org-track-directory)))
152 (target (file-truename
153 (concat base "/" org-track-org-package)))
154 url download tarbuff)
155 (message "Fetching to %s - this might take some time..." base)
156 (setq url (url-generic-parse-url pack))
157 (setq download (url-file-local-copy url)) ;; errors if fail
158 (copy-file download target t)
159 (delete-file download)
160 ;; (tar-mode) leads to dubious errors. We use the auto-mode-alist to
161 ;; ensure tar-mode is used:
162 (add-to-list 'auto-mode-alist '("org-latest\\.tar\\.gz\\'" . tar-mode))
163 (setq tarbuff (find-file target))
164 (with-current-buffer tarbuff ;; with-temp-buffer does not work with tar-mode??
165 (tar-untar-buffer))
166 (kill-buffer tarbuff)
167 (if org-track-remove-package
168 (delete-file target))))
172 ;;; Compile Org-mode sources
175 ;;;###autoload
176 (defun org-track-compile-org (&optional directory)
177 "Compile all *.el files that come with org-mode.
178 Generate the autoloads file `org-loaddefs.el'.
180 DIRECTORY is where the directory org-mode/ lives (i.e. the
181 parent directory of your local repo."
182 (interactive)
183 ;; file-truename expands the filename and removes double slash, if exists:
184 (setq directory (file-truename
185 (concat
186 (or directory
187 (file-truename (concat org-track-directory "/org-mode/lisp")))
188 "/")))
189 (add-to-list 'load-path directory)
190 (let ((list-of-org-files (file-expand-wildcards (concat directory "*.el"))))
191 ;; create the org-loaddefs file
192 (require 'autoload)
193 (setq esf/org-install-file (concat directory "org-loaddefs.el"))
194 (find-file esf/org-install-file)
195 (erase-buffer)
196 (mapc (lambda (x)
197 (generate-file-autoloads x))
198 list-of-org-files)
199 (insert "\n(provide (quote org-loaddefs))\n")
200 (save-buffer)
201 (kill-buffer)
202 (byte-compile-file esf/org-install-file t)
204 (mapc (lambda (f)
205 (if (file-exists-p (concat f "c"))
206 (delete-file (concat f "c"))))
207 list-of-org-files)
208 (if org-track-compile-sources
209 (mapc (lambda (f) (byte-compile-file f)) list-of-org-files))))
211 (provide 'org-track)
213 ;;; org-track.el ends here