dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

org-track.el (7214B)


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