org.el (org-read-date-minibuffer-local-map): Check if we are at the beginning of...
[org-mode.git] / contrib / lisp / org-track.el
blobdb8c34ec669182772094480f82f12148a54f19e3
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 ;; This program 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 ;; This program 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 :group 'org)
74 (defcustom org-track-directory (concat user-emacs-directory "org/lisp")
75 "Directory where your org-mode/ directory lives.
76 If that directory does not exist, it will be created."
77 :type 'directory)
79 (defcustom org-track-compile-sources t
80 "If `nil', never compile org-sources.
81 Org will only create the autoloads file `org-loaddefs.el' for
82 you then. If `t', compile the sources, too.
83 Note, that emacs preferes compiled elisp files over
84 non-compiled ones."
85 :type 'boolean)
87 (defcustom org-track-org-url "http://orgmode.org/"
88 "The URL where the package to download can be found.
89 Please append a slash."
90 :type 'string)
92 (defcustom org-track-org-package "org-latest.tar.gz"
93 "The basename of the package you use.
94 Defaults to the development version of Org-mode.
95 This should be a *.tar.gz package, since emacs provides all
96 you need to unpack it."
97 :type 'string)
99 (defcustom org-track-remove-package nil
100 "Remove org-latest.tar.gz after updates?"
101 :type 'boolean)
105 ;;; Frontend
107 (defun org-track-update ()
108 "Update to current Org-mode version.
109 Also, generate autoloads and evtl. compile the sources."
110 (interactive)
111 (let* ((base (file-truename org-track-directory))
112 (org-exists (file-exists-p
113 (file-truename
114 (concat base "/org-mode/lisp/org.el"))))
115 (nobase (not (file-directory-p
116 (file-truename org-track-directory)))))
117 (if nobase
118 (when (y-or-n-p
119 (format "Directory %s does not exist. Create it?" base))
120 (make-directory base t)
121 (setq nobase nil)))
122 (if nobase
123 (message "Not creating %s - giving up." org-track-directory)
124 (condition-case err
125 (progn
126 (org-track-fetch-package)
127 (org-track-compile-org))
128 (error (message "%s" (error-message-string err)))))))
132 ;;; tar related functions
134 ;; `url-retrieve-synchronously' fetches files synchronously. How can we ensure
135 ;; that? If the maintainers of that package decide, that an assynchronous
136 ;; download might be better??? (used by `url-file-local-copy')
138 ;;;###autoload
139 (defun org-track-fetch-package (&optional directory)
140 "Fetch Org package depending on `org-track-fetch-package-extension'.
141 If DIRECTORY is defined, unpack the package there, i.e. add the
142 subdirectory org-mode/ to DIRECTORY."
143 (interactive "Dorg-track directory: ")
144 (let* ((pack (concat
145 (if (string-match "/$" org-track-org-url)
146 org-track-org-url
147 (concat org-track-org-url "/"))
148 org-track-org-package))
149 (base (file-truename
150 (or directory org-track-directory)))
151 (target (file-truename
152 (concat base "/" org-track-org-package)))
153 url download tarbuff)
154 (message "Fetching to %s - this might take some time..." base)
155 (setq url (url-generic-parse-url pack))
156 (setq download (url-file-local-copy url)) ;; errors if fail
157 (copy-file download target t)
158 (delete-file download)
159 ;; (tar-mode) leads to dubious errors. We use the auto-mode-alist to
160 ;; ensure tar-mode is used:
161 (add-to-list 'auto-mode-alist '("org-latest\\.tar\\.gz\\'" . tar-mode))
162 (setq tarbuff (find-file target))
163 (with-current-buffer tarbuff ;; with-temp-buffer does not work with tar-mode??
164 (tar-untar-buffer))
165 (kill-buffer tarbuff)
166 (if org-track-remove-package
167 (delete-file target))))
171 ;;; Compile Org-mode sources
174 ;;;###autoload
175 (defun org-track-compile-org (&optional directory)
176 "Compile all *.el files that come with org-mode.
177 Generate the autoloads file `org-loaddefs.el'.
179 DIRECTORY is where the directory org-mode/ lives (i.e. the
180 parent directory of your local repo."
181 (interactive)
182 ;; file-truename expands the filename and removes double slash, if exists:
183 (setq directory (file-truename
184 (concat
185 (or directory
186 (file-truename (concat org-track-directory "/org-mode/lisp")))
187 "/")))
188 (add-to-list 'load-path directory)
189 (let ((list-of-org-files (file-expand-wildcards (concat directory "*.el"))))
190 ;; create the org-loaddefs file
191 (require 'autoload)
192 (setq esf/org-install-file (concat directory "org-loaddefs.el"))
193 (find-file esf/org-install-file)
194 (erase-buffer)
195 (mapc (lambda (x)
196 (generate-file-autoloads x))
197 list-of-org-files)
198 (insert "\n(provide (quote org-loaddefs))\n")
199 (save-buffer)
200 (kill-buffer)
201 (byte-compile-file esf/org-install-file t)
203 (mapc (lambda (f)
204 (if (file-exists-p (concat f "c"))
205 (delete-file (concat f "c"))))
206 list-of-org-files)
207 (if org-track-compile-sources
208 (mapc (lambda (f) (byte-compile-file f)) list-of-org-files))))
210 (provide 'org-track)
212 ;;; org-track.el ends here