Merge branch 'maint'
[org-mode.git] / contrib / lisp / org-track.el
blob36724decc5a4922a934d7fb07073e35adb13427e
1 ;;; org-track.el --- Track the most recent Org-mode version available.
2 ;;
3 ;; Copyright (C) 2009-2017 Free Software Foundation, Inc.
4 ;;
5 ;; Author: Bastien Guerry <bzg@gnu.org>
6 ;; Eric S Fraga <e.fraga at ucl.ac dot uk>
7 ;; Sebastian Rose <sebastian_rose at gmx dot de>
8 ;; The Worg people http://orgmode.org/worg/
9 ;; Keywords: outlines, hypermedia, calendar, wp
10 ;; Homepage: http://orgmode.org
11 ;; Version: 6.29a
13 ;; Released under the GNU General Public License version 3
14 ;; see: http://www.gnu.org/licenses/gpl-3.0.html
16 ;; This file is not part of GNU Emacs.
18 ;; This program is free software: you can redistribute it and/or modify
19 ;; it under the terms of the GNU General Public License as published by
20 ;; the Free Software Foundation, either version 3 of the License, or
21 ;; (at your option) any later version.
23 ;; This program is distributed in the hope that it will be useful,
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 ;; GNU General Public License for more details.
28 ;; You should have received a copy of the GNU General Public License
29 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
30 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
32 ;;; Commentary:
34 ;; WARNING: This library is obsolete, you should use the make targets
35 ;; to keep track of Org latest developments.
37 ;; Download the latest development tarball, unpack and optionally compile it
39 ;; Usage:
41 ;; (require 'org-track)
43 ;; ;; ... somewhere in your setup (use customize):
45 ;; (setq org-track-directory "~/test/")
46 ;; (setq org-track-compile-sources nil)
47 ;; (setq org-track-remove-package t)
49 ;; M-x org-track-update RET
51 (require 'url-parse)
52 (require 'url-handlers)
53 (autoload 'url-file-local-copy "url-handlers")
54 (autoload 'url-generic-parse-url "url-parse")
58 ;;; Variables:
60 (defgroup org-track nil
61 "Track the most recent Org-mode version available.
63 To use org-track, adjust `org-track-directory'.
64 Org will download the archived latest git version for you,
65 unpack it into that directory (i.e. a subdirectory
66 `org-mode/' is added), create the autoloads file
67 `org-loaddefs.el' for you and, optionally, compile the
68 sources.
69 All you'll have to do is call `M-x org-track-update' from
70 time to time."
71 :group 'org)
73 (defcustom org-track-directory (concat user-emacs-directory "org/lisp")
74 "Directory where your org-mode/ directory lives.
75 If that directory does not exist, it will be created."
76 :type 'directory)
78 (defcustom org-track-compile-sources t
79 "If `nil', never compile org-sources.
80 Org will only create the autoloads file `org-loaddefs.el' for
81 you then. If `t', compile the sources, too.
82 Note, that emacs preferes compiled elisp files over
83 non-compiled ones."
84 :type 'boolean)
86 (defcustom org-track-org-url "http://orgmode.org/"
87 "The URL where the package to download can be found.
88 Please append a slash."
89 :type 'string)
91 (defcustom org-track-org-package "org-latest.tar.gz"
92 "The basename of the package you use.
93 Defaults to the development version of Org-mode.
94 This should be a *.tar.gz package, since emacs provides all
95 you need to unpack it."
96 :type 'string)
98 (defcustom org-track-remove-package nil
99 "Remove org-latest.tar.gz after updates?"
100 :type 'boolean)
104 ;;; Frontend
106 (defun org-track-update ()
107 "Update to current Org-mode version.
108 Also, generate autoloads and evtl. compile the sources."
109 (interactive)
110 (let* ((base (file-truename org-track-directory))
111 (org-exists (file-exists-p
112 (file-truename
113 (concat base "/org-mode/lisp/org.el"))))
114 (nobase (not (file-directory-p
115 (file-truename org-track-directory)))))
116 (if nobase
117 (when (y-or-n-p
118 (format "Directory %s does not exist. Create it?" base))
119 (make-directory base t)
120 (setq nobase nil)))
121 (if nobase
122 (message "Not creating %s - giving up." org-track-directory)
123 (condition-case err
124 (progn
125 (org-track-fetch-package)
126 (org-track-compile-org))
127 (error (message "%s" (error-message-string err)))))))
131 ;;; tar related functions
133 ;; `url-retrieve-synchronously' fetches files synchronously. How can we ensure
134 ;; that? If the maintainers of that package decide, that an assynchronous
135 ;; download might be better??? (used by `url-file-local-copy')
137 ;;;###autoload
138 (defun org-track-fetch-package (&optional directory)
139 "Fetch Org package depending on `org-track-fetch-package-extension'.
140 If DIRECTORY is defined, unpack the package there, i.e. add the
141 subdirectory org-mode/ to DIRECTORY."
142 (interactive "Dorg-track directory: ")
143 (let* ((pack (concat
144 (if (string-match "/$" org-track-org-url)
145 org-track-org-url
146 (concat org-track-org-url "/"))
147 org-track-org-package))
148 (base (file-truename
149 (or directory org-track-directory)))
150 (target (file-truename
151 (concat base "/" org-track-org-package)))
152 url download tarbuff)
153 (message "Fetching to %s - this might take some time..." base)
154 (setq url (url-generic-parse-url pack))
155 (setq download (url-file-local-copy url)) ;; errors if fail
156 (copy-file download target t)
157 (delete-file download)
158 ;; (tar-mode) leads to dubious errors. We use the auto-mode-alist to
159 ;; ensure tar-mode is used:
160 (add-to-list 'auto-mode-alist '("org-latest\\.tar\\.gz\\'" . tar-mode))
161 (setq tarbuff (find-file target))
162 (with-current-buffer tarbuff ;; with-temp-buffer does not work with tar-mode??
163 (tar-untar-buffer))
164 (kill-buffer tarbuff)
165 (if org-track-remove-package
166 (delete-file target))))
170 ;;; Compile Org-mode sources
173 ;;;###autoload
174 (defun org-track-compile-org (&optional directory)
175 "Compile all *.el files that come with org-mode.
176 Generate the autoloads file `org-loaddefs.el'.
178 DIRECTORY is where the directory org-mode/ lives (i.e. the
179 parent directory of your local repo."
180 (interactive)
181 ;; file-truename expands the filename and removes double slash, if exists:
182 (setq directory (file-truename
183 (concat
184 (or directory
185 (file-truename (concat org-track-directory "/org-mode/lisp")))
186 "/")))
187 (add-to-list 'load-path directory)
188 (let ((list-of-org-files (file-expand-wildcards (concat directory "*.el"))))
189 ;; create the org-loaddefs file
190 (require 'autoload)
191 (setq esf/org-install-file (concat directory "org-loaddefs.el"))
192 (find-file esf/org-install-file)
193 (erase-buffer)
194 (mapc (lambda (x)
195 (generate-file-autoloads x))
196 list-of-org-files)
197 (insert "\n(provide (quote org-loaddefs))\n")
198 (save-buffer)
199 (kill-buffer)
200 (byte-compile-file esf/org-install-file t)
202 (mapc (lambda (f)
203 (if (file-exists-p (concat f "c"))
204 (delete-file (concat f "c"))))
205 list-of-org-files)
206 (if org-track-compile-sources
207 (mapc (lambda (f) (byte-compile-file f)) list-of-org-files))))
209 (provide 'org-track)
211 ;;; org-track.el ends here