org-track.el 7.1 KB

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