1 ;;;_ elinstall.el --- Automatically and flexibly install elisp files
5 ;; Copyright (C) 2010 Tom Breton (Tehom)
7 ;; Author: Tom Breton (Tehom) <tehom@panix.com>
8 ;; Keywords: maint, tools, internal
10 ;; This file is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This file is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
30 ;; elinstall Use this for overall loading
32 ;; elinstall-update-directory-autoloads
33 ;; elinstall-update-file-autoloads
34 ;; elinstall-update-directory
35 ;; elinstall-update-file
42 (require 'cus-edit
) ;;Because we save "installedness" manually
43 (require 'byte-compile nil t
) ;;
51 "Customizations for elinstall"
53 ;;;_ . elinstall-default-priority
54 (defcustom elinstall-default-priority
56 "Default priority for site-start"
59 ;;;_ . elinstall-default-preload-target
60 (defcustom elinstall-default-preload-target
61 "~/.emacs.d/site-start.d/"
62 "Default preload-target for registering autoloads"
66 (const "~/.emacs.d/site-start.d/")
67 (const "/etc/emacs/site-start.d/")
71 ;;;_ . elinstall-restrain-install
72 (defcustom elinstall-restrain-install
'()
73 "Restrain elinstall for specific packages"
78 (choice :format
"%[%t%]: %v"
79 (string :tag
"Package name")
80 (const :tag
"All packages" t
))
81 (repeat :tag
"Actions to restrain:"
90 (const customizations
)
92 (const :tag
"Use as default" t
))
95 :tag
"Do this unless it's up to date"
98 :tag
"Use the package spec for this"
101 :tag
"Don't do this at all"
107 :tag
"Ask only when it's up-to-date."
110 :tag
"Do everything even if it's up to date."
114 ;;;_ . elinstall-already-installed
116 (defcustom elinstall-already-installed
118 "(AUTOMATIC) Things that have already been installed.
119 This exists for recording what has been installed.
121 Though it's saved as customizable, user interaction is not
123 ;;Tell the byte-compiler it's a variable.
124 (defvar elinstall-already-installed
)
126 ;;;_ . elinstall-stages
127 (defstruct (elinstall-stages
128 (:constructor elinstall-make-stages
)
129 (:conc-name elinstall-stages-
>)
131 "The elinstall stages"
137 ;;;_ . Regular expressions
138 ;;;_ , elinstall-elisp-regexp
139 (defconst elinstall-elisp-regexp
142 (suf (get-load-suffixes))
143 (unless (string-match "\\.elc" suf
) (push suf tmp
)))
144 (concat "^[^=.].*" (regexp-opt tmp t
) "\\'"))
145 "Regular expression that matches elisp files" )
147 ;;;_ . elinstall-file-mod-time
148 (defsubst elinstall-file-mod-time
(file)
149 "Return the modification time of FILE"
150 (nth 5 (file-attributes file
)))
152 ;;;_ . elinstall-directory-true-name
153 (defun elinstall-directory-true-name ()
154 "Get the true name of the directory the calling code lives in.
155 CAUTION: This is sensitive to where it's called. That's the point of it."
158 (file-truename load-file-name
)
159 (file-truename buffer-file-name
))))
160 ;;;_ . Checking installedness
161 ;;;_ , elinstall-get-installation-record
162 (defun elinstall-get-installation-record (project-name)
163 "Return the installation record for PROJECT-NAME."
165 (assoc project-name elinstall-already-installed
))
167 ;;;_ , elinstall-already-installed
168 (defun elinstall-already-installed (project-name)
169 "Return non-nil if PROJECT-NAME has been installed."
170 (elinstall-get-installation-record project-name
))
172 ;;;_ , elinstall-record-installed
173 (defun elinstall-record-installed (project-name &optional version
)
174 "Record that PROJECT-NAME has been installed."
183 (elinstall-get-installation-record project-name
))
187 (setq elinstall-already-installed
188 (delete old-item elinstall-already-installed
)))
189 (push new-item elinstall-already-installed
)
190 (customize-save-variable
191 'elinstall-already-installed
192 elinstall-already-installed
193 "Set by elinstall-record-installed")))
194 ;;;_ . Finding deffiles
195 ;;;_ , elinstall-expand-deffile-name
196 (defun elinstall-expand-deffile-name (deffile)
197 "Expand DEFFILE autoload.el's way."
199 (expand-file-name (or deffile
"loaddefs.el")
200 (expand-file-name "lisp"
202 ;;;_ . Checking restraint specs
203 ;;;_ , elinstall-call-with-restraints
204 (defun elinstall-call-with-restraints (restraints package func
&rest args
)
205 "Call FUNC with ARGS, in scope of RESTRAINTS.
206 RESTRAINTS is a list of package restraints. User restraints for the
207 given package will also be applied in scope.
209 PACKAGE can be `t' or a string naming a package."
212 ((elinstall:*pkg-restraints
* restraints
)
213 (elinstall:*user-restraints
*
217 (assoc package elinstall-restrain-install
)
218 (assoc t elinstall-restrain-install
))))
223 elinstall
:*pkg-restraints
*
224 elinstall
:*user-restraints
*))
226 ;;;_ , elinstall-get-restraint
227 (defun elinstall-get-restraint (topic)
228 "Get the applicable restraint symbol for TOPIC.
229 Call this transitively only thru `elinstall-call-with-restraints'."
230 (check-type topic symbol
)
232 elinstall
:*pkg-restraints
*
233 elinstall
:*user-restraints
*))
235 (boundp 'elinstall
:*pkg-restraints
*)
236 (boundp 'elinstall
:*user-restraints
*))
237 (error "elinstall-proceed-p called out of scope"))
242 (assq topic elinstall
:*user-restraints
*)
243 (assq t elinstall
:*user-restraints
*)))
245 ;;`t' means use the pkg-restraints value instead.
247 (or (not cell
) (eq (second cell
) t
))
249 (assq topic elinstall
:*pkg-restraints
*)
250 (assq t elinstall
:*pkg-restraints
*))
252 ;;Default is to just update.
253 (if cell
(second cell
) 'update
)))
255 ;;;_ , elinstall-proceed-p
256 (defun elinstall-proceed-p
257 (topic message-params
&optional already-p
)
258 "Return non-nil if actions on TOPIC should proceed.
259 Call this transitively only thru `elinstall-call-with-restraints'.
260 TOPIC is a symbol indicating the topic, such as `byte-compile'.
261 MESSAGE-PARAMS is a cons of:
262 * A list of format strings:
263 * To ask whether to do this action
264 * To ask whether to redo this action, for `ask-for-old'
265 * To report that this action was skipped because already done.
266 * The arguments to the formatter.
267 ALREADY-P is an extended boolean whether the task has been done
268 before, if caller can tell."
272 ((ask-prompt &optional redo-prompt noredo-msg
) &rest message-args
)
274 (case (elinstall-get-restraint topic
)
282 (apply #'message noredo-msg message-args
)
287 (y-or-n-p (apply #'format redo-prompt message-args
))
291 (apply #'format ask-prompt message-args
))))))
292 ;;;_ , elinstall-proceed-at-all-p
293 (defsubst elinstall-proceed-at-all-p
(topic)
294 "Return non-nil if there's any possibility that actions on TOPIC should proceed."
295 ;;It just so happens that `nil' treatment corresponds to `nil'
297 (elinstall-get-restraint topic
))
302 ;;;_ , Doing autoload actions (adapted from autoload.el)
303 ;;;_ . Utilities about the action list
304 ;;;_ , elinstall-remove-autogen-action
305 (defun elinstall-remove-autogen-action (file actions
)
306 "Return ACTIONS minus any add-file-autoloads on FILE removed."
313 (if (equal file
(third act
))
318 ;;;_ , elinstall-get-autogen-action
319 (defun elinstall-get-autogen-action (file actions
)
323 (dolist (act actions
)
326 (when (equal file
(third act
))
327 (setq the-act act
)))))
329 ;;;_ . About printing to autoload file
330 ;;;_ , elinstall-insert-section-header
331 (defun elinstall-insert-section-header (outbuf form
)
332 "Insert the section-header line,
333 which lists the file name and which functions are in it, etc."
334 (insert generate-autoload-section-header
)
337 ;; Break that line at spaces, to avoid very long lines.
338 ;; Make each sub-line into a comment.
339 (with-current-buffer outbuf
344 (skip-chars-forward "^ \n")
346 (insert "\n" generate-autoload-section-continuation
))))))
348 ;;;_ , elinstall-insert-autoload-section
349 (defun elinstall-insert-autoload-section (text form
&optional comment-string
)
350 "Insert TEXT into current buffer as an autoload section"
355 ;; This does something in Lucid Emacs.
357 (float-output-format nil
))
359 (elinstall-insert-section-header (current-buffer) form
)
361 (insert ";;; " comment-string
"\n"))
363 (insert generate-autoload-section-trailer
)))
365 ;;;_ . Making autoloads
366 ;;;_ , elinstall-make-autoload-action
367 (defun elinstall-make-autoload-action (buf def-file load-path-element full-path
)
368 "Return the autoloads for current buffer as a string"
370 ;;We put all the text into a temp buffer, then get that buffer's
374 (generate-new-buffer " *temp*"))
377 (file-name-nondirectory full-path
))
381 ;; Apparently this does something in Lucid Emacs.
383 (float-output-format nil
)
385 ;;load-name relative to a member of load-path.
387 (file-name-sans-extension
390 load-path-element
))))
392 (with-current-buffer buf
397 (goto-char (point-min))
398 (message "Finding autoloads for %s..." short-name
)
400 (skip-chars-forward " \t\n\f")
402 ((looking-at (regexp-quote generate-autoload-cookie
))
403 (search-forward generate-autoload-cookie
)
404 (skip-chars-forward " \t")
406 ;; Read the next form and make an autoload.
407 (let* ((form (prog1 (read (current-buffer))
408 (or (bolp) (forward-line 1))))
410 (make-autoload form relative-name
)))
412 (push (nth 1 form
) autoloads-done
)
413 (setq autoload form
))
414 (let ((autoload-print-form-outbuf outbuf
))
415 (autoload-print-form autoload
)))
417 ;; Copy the rest of the line to the output.
418 (princ (buffer-substring
420 ;; Back up over whitespace,
422 (skip-chars-backward " \f\t")
423 (if (= (char-after (1+ (point))) ?
)
427 (progn (forward-line 1) (point)))
430 ;; Don't read the comment.
435 (message "Finding autoloads for %s...done" short-name
))
437 ;;Return this action. The temp buffer's contents is
443 ,(with-current-buffer outbuf
(buffer-string))
446 ;;This in unwind-protected
447 (when (buffer-live-p outbuf
) (kill-buffer outbuf
))))))
450 ;;;_ , elinstall-generate-file-autoloads
452 (defun elinstall-generate-file-autoloads
453 (relative-name full-name text autoloads-done
)
454 "Insert at point a loaddefs autoload section for FILE.
455 Autoloads are generated for defuns and defmacros in FILE
456 marked by `generate-autoload-cookie' (which see).
457 If FILE is being visited in a buffer, the contents of the buffer
459 Return non-nil in the case where no autoloads were added at point.
461 FULL-NAME is the absolute name of the file.
462 RELATIVE-NAME is its name respective to some component of load-path."
463 (if (not (equal text
""))
464 ;; Insert the section-header line which lists the file name and
465 ;; which functions are in it, etc.
466 (elinstall-insert-autoload-section
471 (autoload-trim-file-name full-name
)
472 (elinstall-file-mod-time full-name
))
474 "Generated autoloads from "
475 (autoload-trim-file-name full-name
)))
478 ;;;_ , elinstall-deffile-insert-autoloads
479 (defun elinstall-deffile-insert-autoloads (file args
)
480 "Update the autoloads for FILE in current buffer.
481 Return FILE if there was no autoload cookie in it, else nil.
483 Current buffer must be a loaddef-style file.
485 LOAD-NAME is the absolute name of the file.
486 RELATIVE-NAME is its name respective to some component of load-path."
494 (goto-char (point-min))
495 ;; Look for the section for FILE
496 (while (and (not found
)
497 (search-forward generate-autoload-section-header nil t
))
498 (let ((form (autoload-read-section-header)))
500 ((equal (nth 2 form
) file
)
501 ;; We found the section for this file.
502 (let ((begin (match-beginning 0)))
504 (search-forward generate-autoload-section-trailer
)
505 (delete-region begin
(point))
507 ((string< file
(nth 2 form
))
508 ;; We've come to a section alphabetically later than
509 ;; FILE. We assume the file is in order and so
510 ;; there must be no section for FILE. We will
511 ;; insert one before the section here.
512 (goto-char (match-beginning 0))
513 (setq found
'new
)))))
517 ;; No later sections in the file. Put before the last page.
518 (goto-char (point-max))
519 (search-backward "\f" nil t
)))
521 (apply #'elinstall-generate-file-autoloads
524 (if no-autoloads file nil
)))
525 ;;;_ . Arranging to add to info-path and load-path
526 ;;;_ , elinstall-generate-add-to-path
527 (defun elinstall-generate-add-to-path (path-element type
)
528 "Insert code at point to add PATH-ELEMENT to a path.
530 * `add-to-load-path', add to load-path
531 * `add-to-info-path', add to Info-additional-directory-list
533 Current buffer must be a loaddef-style file."
536 (add-to-load-path 'load-path
)
537 (add-to-info-path 'Info-additional-directory-list
)
538 (t (error "Type not recognized"))))
541 (add-to-load-path "load-path")
542 (add-to-info-path "info-path")))
546 ;; This does something in Lucid Emacs.
548 (float-output-format nil
))
550 (message "Generating %s additions..." description
)
552 (elinstall-insert-autoload-section
554 `(add-to-list ',path-symbol
556 ,(file-relative-name path-element
)
559 (file-truename load-file-name
))))))
560 (list type
(list path-element
) nil nil nil
)
562 (message "Generating %s additions...done" description
)))
565 ;;;_ , elinstall-deffile-insert-add-to-path
566 (defun elinstall-deffile-insert-add-to-path (path-element type
)
567 "Insert code in current buffer to add PATH-ELEMENT to a path.
569 * `add-to-load-path', add to load-path
570 * `add-to-info-path', add to Info-default-directory-list
572 Current buffer must be a loaddef-style file."
580 (goto-char (point-min))
581 ;; Look for the section for PATH-ELEMENT
582 (while (and (not found
)
583 (search-forward generate-autoload-section-header nil t
))
584 (let ((form (autoload-read-section-header)))
587 (equal (nth 0 form
) type
)
588 (member path-element
(nth 1 form
)))
590 ;; We found the section for this add.
591 (let ((begin (match-beginning 0)))
593 (search-forward generate-autoload-section-trailer
)
594 (delete-region begin
(point))
600 ;; No later sections in the file. Put before the last page.
601 (goto-char (point-max))
602 (search-backward "\f" nil t
)))
604 (elinstall-generate-add-to-path path-element type
)))
606 ;;This never belongs in the no-autoloads section.
608 ;;;_ . elinstall-deffile-insert
610 (defun elinstall-deffile-insert (action)
611 "Insert autoloads etc into current file according to ACTION.
612 The format of ACTION is described in the design docs.
614 Return filename if this action belongs in the no-autoload section."
619 (elinstall-deffile-insert-autoloads
624 (elinstall-deffile-insert-add-to-path
630 (elinstall-deffile-insert-add-to-path
635 ((preload-file run-tests byte-compile
)
636 (error "This case should not come here.")))))
638 ;;;_ . elinstall-prepare-deffile
639 (defun elinstall-prepare-deffile (deffile)
640 "Try to ensure that DEFFILE is available for receiving autoloads"
642 (autoload-ensure-default-file deffile
)
643 (with-current-buffer (find-file-noselect deffile
)
646 ;; We must read/write the file without any code conversion,
647 ;; but still decode EOLs.
648 (let ((coding-system-for-read 'raw-text
))
650 ;; This is to make generated-autoload-file have Unix EOLs, so
651 ;; that it is portable to all platforms.
652 (setq buffer-file-coding-system
'raw-text-unix
))
653 (or (> (buffer-size) 0)
654 (error "Autoloads file %s does not exist" buffer-file-name
))
655 (or (file-writable-p buffer-file-name
)
656 (error "Autoloads file %s is not writable"
659 ;;;_ . elinstall-update-deffile
661 ;;Adapted from autoload.el `update-directory-autoloads'.
663 (defun elinstall-update-deffile (target actions
&optional use-load-path
)
665 Update file TARGET with current autoloads as specified by ACTIONS.
666 Also remove any old definitions pointing to libraries that can no
669 ACTIONS must be a list of actions (See the format doc). Each one's
670 filename must be relative to some element of load-path.
672 USE-LOAD-PATH is a list to use as load-path. It should include
673 any new load-path that we are arranging to create. If it's not given,
674 load-path itself is used.
676 This uses `update-file-autoloads' (which see) to do its work.
677 In an interactive call, you must give one argument, the name
678 of a single directory."
681 (use-load-path (or use-load-path load-path
))
682 (this-time (current-time))
683 ;;files with no autoload cookies.
686 (elinstall-prepare-deffile target
)
688 (find-file-noselect target
)
691 (elinstall-remove-autogen-action
692 (autoload-trim-file-name target
)
695 (goto-char (point-min))
696 (while (search-forward generate-autoload-section-header nil t
)
697 (let* ((form (autoload-read-section-header))
699 (cond ((and (consp file
) (stringp (car file
)))
700 ;; This is a list of files that have no
702 ;; There shouldn't be more than one such entry.
703 ;; Remove the obsolete section.
704 (autoload-remove-section (match-beginning 0))
705 (let ((last-time (nth 4 form
)))
707 (let ((file-time (elinstall-file-mod-time file
)))
709 (not (time-less-p last-time file-time
)))
711 (push file no-autoloads
)
713 (elinstall-remove-autogen-action
715 ((not (stringp file
)))
719 (locate-library file nil use-load-path
)))
721 ;;$$MAKE ME SAFER Also check normal
722 ;;load-path in case `use-load-path' is
724 ;;$$MAKE ME SAFER Don't do this for a
725 ;;file we are inserting. Need a boolean
726 ;;return for checking that.
727 ;;File doesn't exist, so remove its
730 (autoload-remove-section
731 (match-beginning 0)))
732 ;;$$IMPROVE ME Consult elinstall-proceed-p.
733 ;; File hasn't changed, so do nothing.
736 (elinstall-file-mod-time file-path
))
739 (elinstall-deffile-insert
740 (elinstall-get-autogen-action
744 (elinstall-remove-autogen-action
747 ;; Remaining actions have no existing autoload sections yet.
750 (delq nil
(mapcar #'elinstall-deffile-insert actions
))))
752 ;; Sort them for better readability.
753 (setq no-autoloads
(sort no-autoloads
'string
<))
754 ;; Add the `no-autoloads' section.
755 (goto-char (point-max))
756 (search-backward "\f" nil t
)
757 (elinstall-insert-autoload-section
759 (list 'autoloads nil nil no-autoloads this-time
)))
762 ;;;_ . elinstall-stage-update-deffiles
763 (defun elinstall-stage-update-deffiles (segment-list use-load-path
)
764 "Update any deffiles mentioned in SEGMENT-LIST.
765 FORCE and USE-LOAD-PATH have the same meaning as in
766 `elinstall-update-deffile'.
771 ((deffile (car segment
)))
772 (if (stringp deffile
)
773 (elinstall-update-deffile
779 ;;;_ , Doing actions to arrange preloads
780 ;;;_ . elinstall-symlink-on-emacs-start
781 (defun elinstall-symlink-on-emacs-start
782 (filename target-basename target-dir
&optional priority
)
783 "Symlink to TARGET-BASENAME.el in TARGET-DIR
785 If PRIORITY is given, it will be used as the priority prefix,
786 otherwise elinstall-default-priority will be.
787 PRIORITY must be an integer or nil."
790 (priority (or priority elinstall-default-priority
))
797 (expand-file-name target-name-nodir target-dir
)))
801 ;;Path should already exist.
803 (file-exists-p target-dir
))
804 (message "The target directory doesn't exist."))
805 ;;$$IMPROVE ME If it is a symlink pointing to the same place,
808 ;;$$IMPROVE ME The condition here is really not updating but
809 ;;bulldozing a possibly different symlink. Add another
810 ;;treatment symbol meaning to bulldoze what's in the way.
811 ((elinstall-proceed-p 'preloads
814 "Really overwrite %s? "
815 "File %s already exists")
817 (file-exists-p target
))
818 ;;Does nothing if file already exists.
819 (make-directory (file-name-directory target
) t
)
823 ;;We already checked file-existence wrt user
824 ;;preferences, so force creation.
827 ;;;_ . elinstall-add-to-dot-emacs
828 (defun elinstall-add-to-dot-emacs (dot-emacs-name filename
&rest r
)
829 "Add code to load FILENAME to .emacs.
830 FILENAME should not have an extension"
833 (with-current-buffer (find-file-noselect dot-emacs-name
)
836 (goto-char (point-max))
837 (insert "\n;;Added by elinstall")
838 (insert "\n;;Consider using my-site-start to manage .emacs\n")
839 (pp `(load ,filename
) (current-buffer))
843 ;;;_ . elinstall-arrange-preload
844 (defun elinstall-arrange-preload (filename basename
&optional priority
)
845 "Arrange for FILENAME to be loaded on emacs start.
846 BASENAME and PRIORITY are used as arguments to
847 `elinstall-symlink-on-emacs-start'.
849 For non-autogenerated files that need to be linked in.
851 Calling this explicitly is deprecated. Instead, write a spec
852 containing \(preload Filename nil Basename Priority)."
855 ((preload-target elinstall-default-preload-target
))
857 ;;Dispatch the possibilities.
859 ((eq preload-target
'dot-emacs
)
860 (elinstall-add-to-dot-emacs "~/.emacs" filename
))
861 ((stringp preload-target
)
862 (elinstall-symlink-on-emacs-start
863 filename basename preload-target priority
))
864 ((null preload-target
)
865 (message "Not arranging for preloads"))
867 (message "I don't recognize that")))))
868 ;;;_ . elinstall-stage-arrange-preloads
869 (defun elinstall-stage-arrange-preloads (actions deffiles-used
)
870 "Arrange any preloads mentioned in ACTIONS."
884 (member filename deffiles-used
)))))
888 #'elinstall-arrange-preload
892 "elinstall-stage-arrange-preloads: Action not
898 ;;;_ . elinstall-stage-run-tests
899 (defun elinstall-stage-run-tests (actions)
900 "Run any tests mentioned in ACTIONS."
906 ;;$$WRITE ME - not a high priority right now.
910 "elinstall-stage-run-tests: Action not
916 ;;;_ . elinstall-stage-byte-compile
917 (defun elinstall-stage-byte-compile (actions)
918 "Do any byte-compilation mentioned in ACTIONS."
923 ;;$$IMPROVE ME Understand flags to control second
924 ;;argument (whether to load file after
927 (byte-compile-file (second act
)))
930 "elinstall-stage-byte-compile: Action not
933 ;;;_ . Segregating actions
934 ;;;_ , elinstall-remove-empty-segs
935 (defun elinstall-remove-empty-segs (segment-list)
936 "Return SEGMENT-LIST minus any segments that have no actions.
937 Intended only for the deffile stage data."
946 ;;;_ , elinstall-segregate-actions
947 (defun elinstall-segregate-actions (actions)
948 "Return actions segregated by deffile.
950 Returns a list whose elements are each a cons of:
951 * deffile filename or nil
952 * A list of actions to be done for that deffile."
959 (arrange-preloads '()))
961 (dolist (act actions
)
968 ((deffile-name (second act
))
970 (assoc deffile-name build-deffiles
)))
972 ;;There are already actions on this deffile.
973 ;;Splice this action in.
975 (cons act
(cdr cell-already
)))
976 ;;There are no actions on this deffile. Add a
977 ;;place for them and include this action.
978 (push (list deffile-name act
) build-deffiles
))))
980 (push act arrange-preloads
))
982 (push act run-tests
))
984 (push act byte-compile
)))))
986 (elinstall-make-stages
988 (elinstall-remove-empty-segs build-deffiles
)
995 ;;;_ . Finding actions
997 ;;;_ . elinstall-dir-has-info
999 ;;$$IMPROVE ME - Can this test be made more precise?
1000 (defun elinstall-dir-has-info (dir)
1001 "Return non-nil if DIR has info files in it.
1002 DIR should be an absolute path."
1004 (string-match "/info/" dir
)
1005 (directory-files dir nil
"\\.info\\(-[0-9]+\\)?\\(\\.gz\\)?$")))
1006 ;;;_ . elinstall-directory-files
1007 (defun elinstall-directory-files (dirname)
1008 "Return a list of files in directory DIRNAME, minus certain files.
1009 The following files are omitted:
1011 * Files that match an entry in `block-in-subtree'.
1012 Filenames are relative."
1014 def-file block-in-dir block-in-subtree
))
1017 ;;Relative filenames of this directory's files.
1019 ;; Don't include dot files. If user really wants to
1020 ;;explore one he can use (dir ".NAME") or (file ".NAME")
1021 (directory-files dirname nil
"[^\\.]"))
1022 ;;We know our def-file isn't really source so remove it.
1023 ;;We'd have removed it anyways after seeing file local vars.
1025 (remove def-file all-files
))
1030 #'(lambda (filename)
1036 (string-match blocked filename
))
1045 ;;;_ . List of special variables used in this section
1046 ;;load-path-element - The relevant element of load-path
1047 ;;def-file - The file the autoload definitions etc will go into.
1048 ;;add-to-load-path-p - Controls whether to add to load-path.
1049 ;;recurse-dirs-p - Whether to recurse into subdirectories.
1051 ;;block-in-dir - (NOT IMPLEMENTED) List of filenames to reject. They
1052 ;;may include wildcards. They apply wrt the original directory.
1054 ;;block-in-subtree - (NOT IMPLEMENTED) List of filenames to reject.
1055 ;;They may include wildcards. They apply wrt any directory in the
1056 ;;tree. Specifically, in the spec tree, which may differ from the
1058 ;;byte-compile - whether to byte-compile at all, t by default.
1059 ;;autoloads - boolean whether to make autoloads, t by default.
1060 ;;preloads - boolean whether to set up preloads, t by default.
1061 (defconst elinstall-find-actions-control-vars
1062 '(add-to-load-path-p recurse-dirs-p byte-compile
1064 "Control special variables that the find-actions tree recognizes" )
1065 ;;;_ . elinstall-actions-for-source-file
1066 (defun elinstall-actions-for-source-file (filename dir
)
1067 "Return a list of actions to do for FILENAME in DIR.
1068 Special variables are as noted in \"List of special variables\"."
1070 load-path-element def-file byte-compile
))
1073 (expand-file-name filename dir
)))
1076 (file-readable-p full-path
)
1077 (not (auto-save-file-name-p full-path
))
1078 (string-match emacs-lisp-file-regexp filename
))
1081 (visited (get-file-buffer full-path
))
1085 ;;Visit the file cheaply.
1086 ;;hack-local-variables can give errors.
1087 (ignore-errors (autoload-find-file full-path
))))
1091 (with-current-buffer buf
1092 (if (local-variable-p 'generated-autoload-file
)
1093 (elinstall-expand-deffile-name
1094 generated-autoload-file
)
1097 ;;Figure out whether to run some actions, by file local vars.
1101 (with-current-buffer buf
1102 (not no-update-autoloads
)))
1103 (elinstall-proceed-p 'autoloads
1105 '( "Do autoloads for %s? ")
1111 (featurep 'byte-compile
)
1113 (with-current-buffer buf
1114 (not no-byte-compile
)))
1115 (elinstall-proceed-p 'byte-compile
1119 "Already compiled %s.")
1122 (file-newer-than-file-p
1124 (byte-compile-dest-file full-path
)))))))
1129 `(byte-compile ,full-path
)
1132 (elinstall-make-autoload-action
1133 buf def-file load-path-element full-path
)
1135 (unless visited
(kill-buffer-if-not-modified buf
)))))))
1136 ;;;_ . elinstall-actions-for-dir
1137 (defun elinstall-actions-for-dir (dirname &optional recurse-dirs-p
)
1138 "Make actions for DIR.
1139 Recurse just if RECURSE-DIRS-P"
1141 load-path-element def-file add-to-load-path-p
))
1142 ;;This does not treat symlinks specially. $$IMPROVE ME it could
1143 ;;treat/not treat them conditional on control variables.
1146 (files (elinstall-directory-files dirname
))
1148 ;;Relative filenames of elisp source
1152 #'(lambda (filename)
1154 (string-match elinstall-elisp-regexp filename
)
1159 ;;Absolute filenames of subdirectories.
1164 #'(lambda (filename)
1166 ((fn (expand-file-name filename dirname
)))
1168 (file-directory-p fn
)
1176 elisp-source-files
;;If list is not empty.
1177 add-to-load-path-p
))
1179 (if load-path-here-p
1181 load-path-element
)))
1184 ;;$$IMPROVE ME - check `elinstall-proceed-p'. But even if
1185 ;;that says no, we still must use it as our load-path
1186 ;;element, we just don't add it to def-file.
1188 ;;Sometimes arrange to add this directory to load-path.
1189 (if load-path-here-p
1192 ,load-path-element
))
1195 ;;$$IMPROVE ME - check a control variable and
1196 ;;`elinstall-proceed-p'.
1197 ;;Sometimes add this directory to info path.
1199 (elinstall-dir-has-info dirname
)
1207 #'(lambda (filename)
1208 (elinstall-actions-for-source-file
1211 elisp-source-files
))
1216 #'(lambda (filename)
1217 (elinstall-find-actions-by-spec-x
1225 ;;;_ . elinstall-find-actions-by-spec-x
1227 (defun elinstall-find-actions-by-spec-x (spec dir
)
1228 "Return a list of actions to do, controlled by SPEC."
1230 load-path-element def-file add-to-load-path-p
1231 recurse-dirs-p block-in-dir block-in-subtree
))
1239 #'(lambda (sub-spec)
1240 (elinstall-find-actions-by-spec-x
1245 ;;(block-in-subtree (* FN) SPEC)
1247 ((block-in-subtree (second spec
)))
1248 (elinstall-find-actions-by-spec-x
1252 ;;Rather than trying to bind all control variables each time
1253 ;;thru, we use `set' and `unwind-protect'.
1255 ;;control TYPE DISPOSITION SPEC
1257 ((key (second spec
))
1259 (if (memq key elinstall-find-actions-control-vars
)
1262 (setq old-value
(symbol-value key
))
1263 (set key
(third spec
))
1264 (elinstall-find-actions-by-spec-x
1267 (set key old-value
))
1268 (error "Unrecognized control variable %s" key
))))
1272 ;;(def-file FN ARGS SPEC)
1278 (for-preload (third spec
)))
1279 (assert (listp for-preload
))
1283 (and for-preload
(car for-preload
))
1287 ,@(cdr for-preload
))
1290 (elinstall-find-actions-by-spec-x
1291 (fourth spec
) dir
))))
1295 (elinstall-actions-for-dir
1303 (elinstall-actions-for-source-file
1314 (elinstall-find-actions-by-spec-x
1321 `((add-to-load-path ,def-file
,dir
))
1323 ((load-path-element dir
)
1324 (add-to-load-path-p nil
))
1325 (elinstall-find-actions-by-spec-x
1330 ;;(matching PATTERN SPEC)
1334 ;;$$PUNT Assume that `block-in-subtree' and
1335 ;;`block-in-dir' aren't matched.
1336 (elinstall-find-actions-by-spec-x
1340 dir t
(second spec
)))))
1342 ;;(preload FN SYM &rest ARGS)
1344 ((key (third spec
)))
1346 (and (symbolp key
) (symbol-value key
))
1349 ,(expand-file-name (second spec
) dir
)
1356 (elinstall-actions-for-dir dir nil
))
1358 (elinstall-actions-for-dir dir t
)))))
1360 ;;;_ . elinstall-find-actions-by-spec
1361 (defun elinstall-find-actions-by-spec
1362 (spec load-path-element dir def-file
)
1363 "Find the list of actions to do according to SPEC."
1367 (def-file-time (elinstall-file-mod-time def-file
))
1368 (add-to-load-path-p t
)
1374 (block-in-subtree '(".git" "RCS" "CVS" "SVN" "^tests\.el")))
1377 load-path-element def-file add-to-load-path-p
1378 recurse-dirs-p byte-compile
1379 block-in-dir block-in-subtree
))
1381 (elinstall-find-actions-by-spec-x spec dir
)))
1383 ;;;_ . high-level work
1384 ;;;_ , elinstall-get-relevant-load-path
1385 (defun elinstall-get-relevant-load-path (actions)
1395 ;;;_ , elinstall-get-deffile-list
1396 (defun elinstall-get-deffile-list (stages)
1397 "Get a list of deffile names"
1401 (elinstall-stages->build-deffiles stages
)))
1403 (defun elinstall-x (dir spec
)
1404 "High-level worker function to install elisp files."
1407 ;;This is just the default deffile, spec can override it.
1409 (elinstall-expand-deffile-name nil
))
1411 (elinstall-find-actions-by-spec
1416 (stages (elinstall-segregate-actions actions
))
1418 (elinstall-get-relevant-load-path
1421 (elinstall-stage-update-deffiles
1422 (elinstall-stages->build-deffiles stages
)
1424 (when (elinstall-proceed-at-all-p 'preloads
)
1425 (elinstall-stage-arrange-preloads
1426 (elinstall-stages->arrange-preloads stages
)
1427 (elinstall-get-deffile-list stages
)))
1428 (when (elinstall-proceed-at-all-p 'byte-compile
)
1429 (elinstall-stage-byte-compile
1430 (elinstall-stages->byte-compile stages
)))
1432 ;;;_ , elinstall-package
1433 (defun elinstall-package (project-name path spec version-string
)
1434 "Install elisp files. See doc for `elinstall'."
1436 (elinstall-proceed-p 'install
1440 "Already installed %s.")
1442 (elinstall-already-installed project-name
))
1445 `(def-file "loaddefs.el" (if-used ,project-name
) ,spec
))
1446 (elinstall-record-installed project-name version-string
)))
1451 (defun elinstall (project-name path spec
&optional force version-string
)
1452 "Install elisp files.
1453 They need not be a formal package.
1457 PROJECT-NAME - the name of the project
1459 PATH - Path to the project.
1460 Suggestion: Use (elinstall-directory-true-name) to get the real
1461 current directoery name even from loaded files.
1463 SPEC - a spec for the autoloads etc to make. It can be as simple
1466 If FORCE is `t', install a package even if it has already been
1467 installed. If it's a list or `nil', it's treated as a list of
1468 installation restraints. User customizations override this
1471 VERSION-STRING, if given, must be a string of the version for this package."
1473 (elinstall-call-with-restraints
1479 project-name path spec version-string
))
1481 ;;;_ . elinstall-update-directory-autoloads
1484 (defun elinstall-update-directory-autoloads (dir)
1485 "Update autoloads for directory DIR"
1487 (interactive "DUpdate autoloads for all elisp files from directory: ")
1488 (elinstall-call-with-restraints
1496 ;;;_ . elinstall-update-directory
1498 (defun elinstall-update-directory (dir)
1499 "Update autoloads for directory DIR"
1501 (interactive "DInstall all elisp files from directory: ")
1502 (elinstall-call-with-restraints
1509 ;;;_ . elinstall-update-file-autoloads
1511 (defun elinstall-update-file-autoloads (file)
1512 "Update autoloads for elisp file FILE"
1514 (interactive "fUpdate autoloads for elisp file: ")
1515 (elinstall-call-with-restraints
1519 (file-name-directory file
)
1520 `(file ,(file-name-nondirectory file
))))
1522 ;;;_ . elinstall-update-file
1524 (defun elinstall-update-file (file)
1525 "Install elisp file FILE"
1527 (interactive "fInstall elisp file: ")
1528 (elinstall-call-with-restraints
1533 (file-name-directory file
)
1534 `(file ,(file-name-nondirectory file
))))
1539 (provide 'elinstall
)
1541 ;;;_ * Local emacs vars.
1542 ;;;_ + Local variables:
1547 ;;; elinstall.el ends here