PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/contrib/lisp/org-track.el

https://bitbucket.org/stepan-a/org-mode
Emacs Lisp | 212 lines | 123 code | 27 blank | 62 comment | 2 complexity | e76a6d891e7026be08e6ad758775a86a MD5 | raw file
  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. ;; 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.
  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.
  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. :group 'org)
  65. (defcustom org-track-directory (concat user-emacs-directory "org/lisp")
  66. "Directory where your org-mode/ directory lives.
  67. If that directory does not exist, it will be created."
  68. :type 'directory)
  69. (defcustom org-track-compile-sources t
  70. "If `nil', never compile org-sources.
  71. Org will only create the autoloads file `org-loaddefs.el' for
  72. you then. If `t', compile the sources, too.
  73. Note, that emacs preferes compiled elisp files over
  74. non-compiled ones."
  75. :type 'boolean)
  76. (defcustom org-track-org-url "http://orgmode.org/"
  77. "The URL where the package to download can be found.
  78. Please append a slash."
  79. :type 'string)
  80. (defcustom org-track-org-package "org-latest.tar.gz"
  81. "The basename of the package you use.
  82. Defaults to the development version of Org-mode.
  83. This should be a *.tar.gz package, since emacs provides all
  84. you need to unpack it."
  85. :type 'string)
  86. (defcustom org-track-remove-package nil
  87. "Remove org-latest.tar.gz after updates?"
  88. :type 'boolean)
  89. ;;; Frontend
  90. (defun org-track-update ()
  91. "Update to current Org-mode version.
  92. Also, generate autoloads and evtl. compile the sources."
  93. (interactive)
  94. (let* ((base (file-truename org-track-directory))
  95. (org-exists (file-exists-p
  96. (file-truename
  97. (concat base "/org-mode/lisp/org.el"))))
  98. (nobase (not (file-directory-p
  99. (file-truename org-track-directory)))))
  100. (if nobase
  101. (when (y-or-n-p
  102. (format "Directory %s does not exist. Create it?" base))
  103. (make-directory base t)
  104. (setq nobase nil)))
  105. (if nobase
  106. (message "Not creating %s - giving up." org-track-directory)
  107. (condition-case err
  108. (progn
  109. (org-track-fetch-package)
  110. (org-track-compile-org))
  111. (error (message "%s" (error-message-string err)))))))
  112. ;;; tar related functions
  113. ;; `url-retrieve-synchronously' fetches files synchronously. How can we ensure
  114. ;; that? If the maintainers of that package decide, that an assynchronous
  115. ;; download might be better??? (used by `url-file-local-copy')
  116. ;;;###autoload
  117. (defun org-track-fetch-package (&optional directory)
  118. "Fetch Org package depending on `org-track-fetch-package-extension'.
  119. If DIRECTORY is defined, unpack the package there, i.e. add the
  120. subdirectory org-mode/ to DIRECTORY."
  121. (interactive "Dorg-track directory: ")
  122. (let* ((pack (concat
  123. (if (string-match "/$" org-track-org-url)
  124. org-track-org-url
  125. (concat org-track-org-url "/"))
  126. org-track-org-package))
  127. (base (file-truename
  128. (or directory org-track-directory)))
  129. (target (file-truename
  130. (concat base "/" org-track-org-package)))
  131. url download tarbuff)
  132. (message "Fetching to %s - this might take some time..." base)
  133. (setq url (url-generic-parse-url pack))
  134. (setq download (url-file-local-copy url)) ;; errors if fail
  135. (copy-file download target t)
  136. (delete-file download)
  137. ;; (tar-mode) leads to dubious errors. We use the auto-mode-alist to
  138. ;; ensure tar-mode is used:
  139. (add-to-list 'auto-mode-alist '("org-latest\\.tar\\.gz\\'" . tar-mode))
  140. (setq tarbuff (find-file target))
  141. (with-current-buffer tarbuff ;; with-temp-buffer does not work with tar-mode??
  142. (tar-untar-buffer))
  143. (kill-buffer tarbuff)
  144. (if org-track-remove-package
  145. (delete-file target))))
  146. ;;; Compile Org-mode sources
  147. ;;;###autoload
  148. (defun org-track-compile-org (&optional directory)
  149. "Compile all *.el files that come with org-mode.
  150. Generate the autoloads file `org-loaddefs.el'.
  151. DIRECTORY is where the directory org-mode/ lives (i.e. the
  152. parent directory of your local repo."
  153. (interactive)
  154. ;; file-truename expands the filename and removes double slash, if exists:
  155. (setq directory (file-truename
  156. (concat
  157. (or directory
  158. (file-truename (concat org-track-directory "/org-mode/lisp")))
  159. "/")))
  160. (add-to-list 'load-path directory)
  161. (let ((list-of-org-files (file-expand-wildcards (concat directory "*.el"))))
  162. ;; create the org-loaddefs file
  163. (require 'autoload)
  164. (setq esf/org-install-file (concat directory "org-loaddefs.el"))
  165. (find-file esf/org-install-file)
  166. (erase-buffer)
  167. (mapc (lambda (x)
  168. (generate-file-autoloads x))
  169. list-of-org-files)
  170. (insert "\n(provide (quote org-loaddefs))\n")
  171. (save-buffer)
  172. (kill-buffer)
  173. (byte-compile-file esf/org-install-file t)
  174. (mapc (lambda (f)
  175. (if (file-exists-p (concat f "c"))
  176. (delete-file (concat f "c"))))
  177. list-of-org-files)
  178. (if org-track-compile-sources
  179. (mapc (lambda (f) (byte-compile-file f)) list-of-org-files))))
  180. (provide 'org-track)
  181. ;;; org-track.el ends here