org-track.el 7.0 KB

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