org-track.el 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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
  13. ;;
  14. ;; Released under the GNU General Public License version 3
  15. ;; see: http://www.gnu.org/licenses/gpl-3.0.html
  16. ;;
  17. ;; This file is not part of GNU Emacs.
  18. ;;
  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.
  23. ;; GNU Emacs 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.
  27. ;; You should have received a copy of the GNU General Public License
  28. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  29. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  30. ;;
  31. ;;; Commentary:
  32. ;;
  33. ;; WARNING: This library is obsolete, you should use the make targets
  34. ;; to keep track of Org latest developments.
  35. ;;
  36. ;; Download the latest development tarball, unpack and optionally compile it
  37. ;;
  38. ;; Usage:
  39. ;;
  40. ;; (require 'org-track)
  41. ;;
  42. ;; ;; ... somewhere in your setup (use customize):
  43. ;;
  44. ;; (setq org-track-directory "~/test/")
  45. ;; (setq org-track-compile-sources nil)
  46. ;; (setq org-track-remove-package t)
  47. ;;
  48. ;; M-x org-track-update RET
  49. (require 'url-parse)
  50. (require 'url-handlers)
  51. (autoload 'url-file-local-copy "url-handlers")
  52. (autoload 'url-generic-parse-url "url-parse")
  53. ;;; Variables:
  54. (defgroup org-track nil
  55. "Track the most recent Org-mode version available.
  56. To use org-track, adjust `org-track-directory'.
  57. Org will download the archived latest git version for you,
  58. unpack it into that directory (i.e. a subdirectory
  59. `org-mode/' is added), create the autoloads file
  60. `org-loaddefs.el' for you and, optionally, compile the
  61. sources.
  62. All you'll have to do is call `M-x org-track-update' from
  63. time to time."
  64. :version "22.1"
  65. :group 'org)
  66. (defcustom org-track-directory (concat user-emacs-directory "org/lisp")
  67. "Directory where your org-mode/ directory lives.
  68. If that directory does not exist, it will be created."
  69. :type 'directory)
  70. (defcustom org-track-compile-sources t
  71. "If `nil', never compile org-sources.
  72. Org will only create the autoloads file `org-loaddefs.el' for
  73. you then. If `t', compile the sources, too.
  74. Note, that emacs preferes compiled elisp files over
  75. non-compiled ones."
  76. :type 'boolean)
  77. (defcustom org-track-org-url "http://orgmode.org/"
  78. "The URL where the package to download can be found.
  79. Please append a slash."
  80. :type 'string)
  81. (defcustom org-track-org-package "org-latest.tar.gz"
  82. "The basename of the package you use.
  83. Defaults to the development version of Org-mode.
  84. This should be a *.tar.gz package, since emacs provides all
  85. you need to unpack it."
  86. :type 'string)
  87. (defcustom org-track-remove-package nil
  88. "Remove org-latest.tar.gz after updates?"
  89. :type 'boolean)
  90. ;;; Frontend
  91. (defun org-track-update ()
  92. "Update to current Org-mode version.
  93. Also, generate autoloads and evtl. compile the sources."
  94. (interactive)
  95. (let* ((base (file-truename org-track-directory))
  96. (org-exists (file-exists-p
  97. (file-truename
  98. (concat base "/org-mode/lisp/org.el"))))
  99. (nobase (not (file-directory-p
  100. (file-truename org-track-directory)))))
  101. (if nobase
  102. (when (y-or-n-p
  103. (format "Directory %s does not exist. Create it?" base))
  104. (make-directory base t)
  105. (setq nobase nil)))
  106. (if nobase
  107. (message "Not creating %s - giving up." org-track-directory)
  108. (condition-case err
  109. (progn
  110. (org-track-fetch-package)
  111. (org-track-compile-org))
  112. (error (message "%s" (error-message-string err)))))))
  113. ;;; tar related functions
  114. ;; `url-retrieve-synchronously' fetches files synchronously. How can we ensure
  115. ;; that? If the maintainers of that package decide, that an assynchronous
  116. ;; download might be better??? (used by `url-file-local-copy')
  117. ;;;###autoload
  118. (defun org-track-fetch-package (&optional directory)
  119. "Fetch Org package depending on `org-track-fetch-package-extension'.
  120. If DIRECTORY is defined, unpack the package there, i.e. add the
  121. subdirectory org-mode/ to DIRECTORY."
  122. (interactive "Dorg-track directory: ")
  123. (let* ((pack (concat
  124. (if (string-match "/$" org-track-org-url)
  125. org-track-org-url
  126. (concat org-track-org-url "/"))
  127. org-track-org-package))
  128. (base (file-truename
  129. (or directory org-track-directory)))
  130. (target (file-truename
  131. (concat base "/" org-track-org-package)))
  132. url download tarbuff)
  133. (message "Fetching to %s - this might take some time..." base)
  134. (setq url (url-generic-parse-url pack))
  135. (setq download (url-file-local-copy url)) ;; errors if fail
  136. (copy-file download target t)
  137. (delete-file download)
  138. ;; (tar-mode) leads to dubious errors. We use the auto-mode-alist to
  139. ;; ensure tar-mode is used:
  140. (add-to-list 'auto-mode-alist '("org-latest\\.tar\\.gz\\'" . tar-mode))
  141. (setq tarbuff (find-file target))
  142. (with-current-buffer tarbuff ;; with-temp-buffer does not work with tar-mode??
  143. (tar-untar-buffer))
  144. (kill-buffer tarbuff)
  145. (if org-track-remove-package
  146. (delete-file target))))
  147. ;;; Compile Org-mode sources
  148. ;;;###autoload
  149. (defun org-track-compile-org (&optional directory)
  150. "Compile all *.el files that come with org-mode.
  151. Generate the autoloads file `org-loaddefs.el'.
  152. DIRECTORY is where the directory org-mode/ lives (i.e. the
  153. parent directory of your local repo."
  154. (interactive)
  155. ;; file-truename expands the filename and removes double slash, if exists:
  156. (setq directory (file-truename
  157. (concat
  158. (or directory
  159. (file-truename (concat org-track-directory "/org-mode/lisp")))
  160. "/")))
  161. (add-to-list 'load-path directory)
  162. (let ((list-of-org-files (file-expand-wildcards (concat directory "*.el"))))
  163. ;; create the org-loaddefs file
  164. (require 'autoload)
  165. (setq esf/org-install-file (concat directory "org-loaddefs.el"))
  166. (find-file esf/org-install-file)
  167. (erase-buffer)
  168. (mapc (lambda (x)
  169. (generate-file-autoloads x))
  170. list-of-org-files)
  171. (insert "\n(provide (quote org-loaddefs))\n")
  172. (save-buffer)
  173. (kill-buffer)
  174. (byte-compile-file esf/org-install-file t)
  175. (mapc (lambda (f)
  176. (if (file-exists-p (concat f "c"))
  177. (delete-file (concat f "c"))))
  178. list-of-org-files)
  179. (if org-track-compile-sources
  180. (mapc (lambda (f) (byte-compile-file f)) list-of-org-files))))
  181. (provide 'org-track)
  182. ;;; org-track.el ends here