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-arrange-preload - Use this for non-autogenerated
33 ;; files that need to be linked in.
35 ;; elinstall-update-directory-autoloads
36 ;; elinstall-update-file-autoloads
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 :tag
"Use as default" t
))
93 :tag
"Do this unless it's up to date"
96 :tag
"Use the package spec for this"
99 :tag
"Don't do this at all"
105 :tag
"Ask only when it's up-to-date."
108 :tag
"Do everything even if it's up to date."
112 ;;;_ . elinstall-already-installed
114 (defcustom elinstall-already-installed
116 "(AUTOMATIC) Things that have already been installed.
117 This exists for recording what has been installed.
119 Though it's saved as customizable, user interaction is not
121 ;;Tell the byte-compiler it's a variable.
122 (defvar elinstall-already-installed
)
124 ;;;_ . elinstall-stages
125 (defstruct (elinstall-stages
126 (:constructor elinstall-make-stages
)
127 (:conc-name elinstall-stages-
>)
129 "The elinstall stages"
135 ;;;_ . Regular expressions
136 ;;;_ , elinstall-elisp-regexp
137 (defconst elinstall-elisp-regexp
140 (suf (get-load-suffixes))
141 (unless (string-match "\\.elc" suf
) (push suf tmp
)))
142 (concat "^[^=.].*" (regexp-opt tmp t
) "\\'"))
143 "Regular expression that matches elisp files" )
145 ;;;_ . elinstall-file-mod-time
146 (defsubst elinstall-file-mod-time
(file)
147 "Return the modification time of FILE"
148 (nth 5 (file-attributes file
)))
150 ;;;_ . elinstall-directory-true-name
151 (defun elinstall-directory-true-name ()
152 "Get the true name of the directory the calling code lives in.
153 CAUTION: This is sensitive to where it's called. That's the point of it."
156 (file-truename load-file-name
)
157 (file-truename buffer-file-name
))))
158 ;;;_ . Checking installedness
159 ;;;_ , elinstall-get-installation-record
160 (defun elinstall-get-installation-record (project-name)
161 "Return the installation record for PROJECT-NAME."
163 (assoc project-name elinstall-already-installed
))
165 ;;;_ , elinstall-already-installed
166 (defun elinstall-already-installed (project-name)
167 "Return non-nil if PROJECT-NAME has been installed."
168 (elinstall-get-installation-record project-name
))
170 ;;;_ , elinstall-record-installed
171 (defun elinstall-record-installed (project-name &optional version
)
172 "Record that PROJECT-NAME has been installed."
181 (elinstall-get-installation-record project-name
))
185 (setq elinstall-already-installed
186 (delete old-item elinstall-already-installed
)))
187 (push new-item elinstall-already-installed
)
188 (customize-save-variable
189 'elinstall-already-installed
190 elinstall-already-installed
191 "Set by elinstall-record-installed")))
192 ;;;_ . Finding deffiles
193 ;;;_ , elinstall-expand-deffile-name
194 (defun elinstall-expand-deffile-name (deffile)
195 "Expand DEFFILE autoload.el's way."
197 (expand-file-name (or deffile
"loaddefs.el")
198 (expand-file-name "lisp"
200 ;;;_ . Checking restraint specs
201 ;;;_ , elinstall-call-with-restraints
202 (defun elinstall-call-with-restraints (restraints package func
&rest args
)
203 "Call FUNC with ARGS, in scope of RESTRAINTS.
204 RESTRAINTS is a list of package restraints. User restraints for the
205 given package will also be applied in scope.
207 PACKAGE can be `t' or a string naming a package."
210 ((elinstall:*pkg-restraints
* restraints
)
211 (elinstall:*user-restraints
*
215 (assoc package elinstall-restrain-install
)
216 (assoc t elinstall-restrain-install
))))
221 elinstall
:*pkg-restraints
*
222 elinstall
:*user-restraints
*))
224 ;;;_ , elinstall-proceed-p
225 (defun elinstall-proceed-p
226 (topic message-params
&optional already-p
)
227 "Return non-nil if actions on TOPIC should proceed.
228 Call this transitively only thru `elinstall-call-with-restraints'.
229 TOPIC is a symbol indicating the topic, such as `byte-compile'.
230 MESSAGE-PARAMS is a cons of:
231 * A list of format strings:
232 * To ask whether to do this action
233 * To ask whether to redo this action, for `ask-for-old'
234 * To report that this action was skipped because already done.
235 * The arguments to the formatter.
236 ALREADY-P is an extended boolean whether the task has been done
237 before, if caller can tell."
239 (check-type topic symbol
)
241 elinstall
:*pkg-restraints
*
242 elinstall
:*user-restraints
*))
244 (boundp 'elinstall
:*pkg-restraints
*)
245 (boundp 'elinstall
:*user-restraints
*))
246 (error "elinstall-proceed-p called out of scope"))
249 ((ask-prompt &optional redo-prompt noredo-msg
) &rest message-args
)
252 ( ;;Get the applicable cell. We look in several places.
255 (assq topic elinstall
:*user-restraints
*)
256 (assq t elinstall
:*user-restraints
*)))
258 ;;`t' means use the pkg-restraints value instead.
260 (or (not cell
) (eq (second cell
) t
))
262 (assq topic elinstall
:*pkg-restraints
*)
263 (assq t elinstall
:*pkg-restraints
*))
266 ;;Default is to just update.
267 (if cell
(second cell
) 'update
)))
276 (apply #'message noredo-msg message-args
)
281 (y-or-n-p (apply #'format redo-prompt message-args
))
285 (apply #'format ask-prompt message-args
)))))))
290 ;;;_ , Doing autoload actions (adapted from autoload.el)
291 ;;;_ . Utilities about the action list
292 ;;;_ , elinstall-remove-autogen-action
293 (defun elinstall-remove-autogen-action (file actions
)
294 "Return ACTIONS minus any add-file-autoloads on FILE removed."
301 (if (equal file
(third act
))
306 ;;;_ , elinstall-get-autogen-action
307 (defun elinstall-get-autogen-action (file actions
)
311 (dolist (act actions
)
314 (when (equal file
(third act
))
315 (setq the-act act
)))))
317 ;;;_ . About printing to autoload file
318 ;;;_ , elinstall-insert-section-header
319 (defun elinstall-insert-section-header (outbuf form
)
320 "Insert the section-header line,
321 which lists the file name and which functions are in it, etc."
322 (insert generate-autoload-section-header
)
325 ;; Break that line at spaces, to avoid very long lines.
326 ;; Make each sub-line into a comment.
327 (with-current-buffer outbuf
332 (skip-chars-forward "^ \n")
334 (insert "\n" generate-autoload-section-continuation
))))))
336 ;;;_ , elinstall-insert-autoload-section
337 (defun elinstall-insert-autoload-section (text form
&optional comment-string
)
338 "Insert TEXT into current buffer as an autoload section"
343 ;; This does something in Lucid Emacs.
345 (float-output-format nil
))
347 (elinstall-insert-section-header (current-buffer) form
)
349 (insert ";;; " comment-string
"\n"))
351 (insert generate-autoload-section-trailer
)))
353 ;;;_ . Making autoloads
354 ;;;_ , elinstall-make-autoload-action
355 (defun elinstall-make-autoload-action (buf def-file load-path-element full-path
)
356 "Return the autoloads for current buffer as a string"
358 ;;We put all the text into a temp buffer, then get that buffer's
362 (generate-new-buffer " *temp*"))
365 (file-name-nondirectory full-path
))
369 ;; Apparently this does something in Lucid Emacs.
371 (float-output-format nil
)
373 ;;load-name relative to a member of load-path.
375 (file-name-sans-extension
378 load-path-element
))))
380 (with-current-buffer buf
385 (goto-char (point-min))
386 (message "Finding autoloads for %s..." short-name
)
388 (skip-chars-forward " \t\n\f")
390 ((looking-at (regexp-quote generate-autoload-cookie
))
391 (search-forward generate-autoload-cookie
)
392 (skip-chars-forward " \t")
394 ;; Read the next form and make an autoload.
395 (let* ((form (prog1 (read (current-buffer))
396 (or (bolp) (forward-line 1))))
398 (make-autoload form relative-name
)))
400 (push (nth 1 form
) autoloads-done
)
401 (setq autoload form
))
402 (let ((autoload-print-form-outbuf outbuf
))
403 (autoload-print-form autoload
)))
405 ;; Copy the rest of the line to the output.
406 (princ (buffer-substring
408 ;; Back up over whitespace,
410 (skip-chars-backward " \f\t")
411 (if (= (char-after (1+ (point))) ?
)
415 (progn (forward-line 1) (point)))
418 ;; Don't read the comment.
423 (message "Finding autoloads for %s...done" short-name
))
425 ;;Return this action. The temp buffer's contents is
431 ,(with-current-buffer outbuf
(buffer-string))
434 ;;This in unwind-protected
435 (when (buffer-live-p outbuf
) (kill-buffer outbuf
))))))
438 ;;;_ , elinstall-generate-file-autoloads
440 (defun elinstall-generate-file-autoloads
441 (relative-name full-name text autoloads-done
)
442 "Insert at point a loaddefs autoload section for FILE.
443 Autoloads are generated for defuns and defmacros in FILE
444 marked by `generate-autoload-cookie' (which see).
445 If FILE is being visited in a buffer, the contents of the buffer
447 Return non-nil in the case where no autoloads were added at point.
449 FULL-NAME is the absolute name of the file.
450 RELATIVE-NAME is its name respective to some component of load-path."
451 (if (not (equal text
""))
452 ;; Insert the section-header line which lists the file name and
453 ;; which functions are in it, etc.
454 (elinstall-insert-autoload-section
459 (autoload-trim-file-name full-name
)
460 (elinstall-file-mod-time full-name
))
462 "Generated autoloads from "
463 (autoload-trim-file-name full-name
)))
466 ;;;_ , elinstall-deffile-insert-autoloads
467 (defun elinstall-deffile-insert-autoloads (file args
)
468 "Update the autoloads for FILE in current buffer.
469 Return FILE if there was no autoload cookie in it, else nil.
471 Current buffer must be a loaddef-style file.
473 LOAD-NAME is the absolute name of the file.
474 RELATIVE-NAME is its name respective to some component of load-path."
482 (goto-char (point-min))
483 ;; Look for the section for FILE
484 (while (and (not found
)
485 (search-forward generate-autoload-section-header nil t
))
486 (let ((form (autoload-read-section-header)))
488 ((equal (nth 2 form
) file
)
489 ;; We found the section for this file.
490 (let ((begin (match-beginning 0)))
492 (search-forward generate-autoload-section-trailer
)
493 (delete-region begin
(point))
495 ((string< file
(nth 2 form
))
496 ;; We've come to a section alphabetically later than
497 ;; FILE. We assume the file is in order and so
498 ;; there must be no section for FILE. We will
499 ;; insert one before the section here.
500 (goto-char (match-beginning 0))
501 (setq found
'new
)))))
505 ;; No later sections in the file. Put before the last page.
506 (goto-char (point-max))
507 (search-backward "\f" nil t
)))
509 (apply #'elinstall-generate-file-autoloads
512 (if no-autoloads file nil
)))
513 ;;;_ . Arranging to add to info-path and load-path
514 ;;;_ , elinstall-generate-add-to-path
515 (defun elinstall-generate-add-to-path (path-element type
)
516 "Insert code at point to add PATH-ELEMENT to a path.
518 * `add-to-load-path', add to load-path
519 * `add-to-info-path', add to Info-additional-directory-list
521 Current buffer must be a loaddef-style file."
524 (add-to-load-path 'load-path
)
525 (add-to-info-path 'Info-additional-directory-list
)
526 (t (error "Type not recognized"))))
529 (add-to-load-path "load-path")
530 (add-to-info-path "info-path")))
534 ;; This does something in Lucid Emacs.
536 (float-output-format nil
))
538 (message "Generating %s additions..." description
)
540 (elinstall-insert-autoload-section
542 `(add-to-list ',path-symbol
544 ,(file-relative-name path-element
)
547 (file-truename load-file-name
))))))
548 (list type
(list path-element
) nil nil nil
)
550 (message "Generating %s additions...done" description
)))
553 ;;;_ , elinstall-deffile-insert-add-to-path
554 (defun elinstall-deffile-insert-add-to-path (path-element type
)
555 "Insert code in current buffer to add PATH-ELEMENT to a path.
557 * `add-to-load-path', add to load-path
558 * `add-to-info-path', add to Info-default-directory-list
560 Current buffer must be a loaddef-style file."
568 (goto-char (point-min))
569 ;; Look for the section for PATH-ELEMENT
570 (while (and (not found
)
571 (search-forward generate-autoload-section-header nil t
))
572 (let ((form (autoload-read-section-header)))
575 (equal (nth 0 form
) type
)
576 (member path-element
(nth 1 form
)))
578 ;; We found the section for this add.
579 (let ((begin (match-beginning 0)))
581 (search-forward generate-autoload-section-trailer
)
582 (delete-region begin
(point))
588 ;; No later sections in the file. Put before the last page.
589 (goto-char (point-max))
590 (search-backward "\f" nil t
)))
592 (elinstall-generate-add-to-path path-element type
)))
594 ;;This never belongs in the no-autoloads section.
596 ;;;_ . elinstall-deffile-insert
598 (defun elinstall-deffile-insert (action)
599 "Insert autoloads etc into current file according to ACTION.
600 The format of ACTION is described in the design docs.
602 Return filename if this action belongs in the no-autoload section."
607 (elinstall-deffile-insert-autoloads
612 (elinstall-deffile-insert-add-to-path
618 (elinstall-deffile-insert-add-to-path
623 ((preload-file run-tests byte-compile
)
624 (error "This case should not come here.")))))
626 ;;;_ . elinstall-prepare-deffile
627 (defun elinstall-prepare-deffile (deffile)
628 "Try to ensure that DEFFILE is available for receiving autoloads"
630 (autoload-ensure-default-file deffile
)
631 (with-current-buffer (find-file-noselect deffile
)
634 ;; We must read/write the file without any code conversion,
635 ;; but still decode EOLs.
636 (let ((coding-system-for-read 'raw-text
))
638 ;; This is to make generated-autoload-file have Unix EOLs, so
639 ;; that it is portable to all platforms.
640 (setq buffer-file-coding-system
'raw-text-unix
))
641 (or (> (buffer-size) 0)
642 (error "Autoloads file %s does not exist" buffer-file-name
))
643 (or (file-writable-p buffer-file-name
)
644 (error "Autoloads file %s is not writable"
647 ;;;_ . elinstall-update-deffile
649 ;;Adapted from autoload.el `update-directory-autoloads'.
651 (defun elinstall-update-deffile (target actions
&optional
654 Update file TARGET with current autoloads as specified by ACTIONS.
655 Also remove any old definitions pointing to libraries that can no
658 ACTIONS must be a list of actions (See the format doc). Each one's
659 filename must be relative to some element of load-path.
661 USE-LOAD-PATH is a list to use as load-path. It should include
662 any new load-path that we are arranging to create. If it's not given,
663 load-path itself is used.
665 If FORCE is `t', do it regardless of timestamps etc. (Not implemented)
666 Other non-nil cases of FORCE are reserved for future development.
668 This uses `update-file-autoloads' (which see) to do its work.
669 In an interactive call, you must give one argument, the name
670 of a single directory."
673 (use-load-path (or use-load-path load-path
))
674 (this-time (current-time))
675 ;;files with no autoload cookies.
678 (elinstall-prepare-deffile target
)
680 (find-file-noselect target
)
683 (elinstall-remove-autogen-action
684 (autoload-trim-file-name target
)
687 (goto-char (point-min))
688 (while (search-forward generate-autoload-section-header nil t
)
689 (let* ((form (autoload-read-section-header))
691 (cond ((and (consp file
) (stringp (car file
)))
692 ;; This is a list of files that have no
694 ;; There shouldn't be more than one such entry.
695 ;; Remove the obsolete section.
696 (autoload-remove-section (match-beginning 0))
697 (let ((last-time (nth 4 form
)))
699 (let ((file-time (elinstall-file-mod-time file
)))
701 (not (time-less-p last-time file-time
)))
703 (push file no-autoloads
)
705 (elinstall-remove-autogen-action
707 ((not (stringp file
)))
711 (locate-library file nil use-load-path
)))
713 ;;File doesn't exist, so remove its
716 (autoload-remove-section
717 (match-beginning 0)))
719 ;; File hasn't changed, so do nothing.
722 (elinstall-file-mod-time file-path
))
725 (elinstall-deffile-insert
726 (elinstall-get-autogen-action
730 (elinstall-remove-autogen-action
733 ;; Remaining actions have no existing autoload sections yet.
736 (delq nil
(mapcar #'elinstall-deffile-insert actions
))))
738 ;; Sort them for better readability.
739 (setq no-autoloads
(sort no-autoloads
'string
<))
740 ;; Add the `no-autoloads' section.
741 (goto-char (point-max))
742 (search-backward "\f" nil t
)
743 (elinstall-insert-autoload-section
745 (list 'autoloads nil nil no-autoloads this-time
)))
748 ;;;_ . elinstall-stage-update-deffiles
749 (defun elinstall-stage-update-deffiles (segment-list force use-load-path
)
750 "Update any deffiles mentioned in SEGMENT-LIST.
751 FORCE and USE-LOAD-PATH have the same meaning as in
752 `elinstall-update-deffile'.
757 ((deffile (car segment
)))
758 (if (stringp deffile
)
759 (elinstall-update-deffile deffile
(cdr segment
) force
763 ;;;_ , Doing actions to arrange preloads
764 ;;;_ . elinstall-symlink-on-emacs-start
765 (defun elinstall-symlink-on-emacs-start
766 (filename target-basename target-dir
&optional priority force
)
767 "Symlink to TARGET-BASENAME.el in TARGET-DIR
769 If PRIORITY is given, it will be used as the priority prefix,
770 otherwise elinstall-default-priority will be.
771 PRIORITY must be an integer or nil.
772 If FORCE is `t', do it regardless of timestamps etc.
773 Other non-nil cases of FORCE are reserved for future development."
776 (priority (or priority elinstall-default-priority
))
783 (expand-file-name target-name-nodir target-dir
)))
787 ;;Path should already exist.
789 (file-exists-p target-dir
))
790 (message "The target directory doesn't exist."))
791 ;;Target shouldn't already exist, but if force is given, let
793 ;;$$IMPROVE ME If it is a symlink pointing to the same place,
794 ;;do nothing even on force.
796 (file-exists-p target
)
801 (format "Really overwrite %s? " target
))))
802 (message "File %s already exists" target
)))
810 ;;;_ . elinstall-add-to-dot-emacs
811 (defun elinstall-add-to-dot-emacs (dot-emacs-name filename force
&rest r
)
812 "Add code to load FILENAME to .emacs.
813 FILENAME should not have an extension"
816 (with-current-buffer (find-file-noselect dot-emacs-name
)
819 (goto-char (point-max))
820 (insert "\n;;Added by elinstall")
821 (insert "\n;;Consider using my-site-start to manage .emacs\n")
822 (pp `(load ,filename
) (current-buffer))
826 ;;;_ . elinstall-arrange-preload
828 (defun elinstall-arrange-preload (force filename basename
&optional priority
)
829 "Arrange for FILENAME to be loaded on emacs start.
830 FORCE has its usual meaning.
831 BASENAME and PRIORITY are used as arguments to
832 `elinstall-symlink-on-emacs-start'.
836 ((preload-target elinstall-default-preload-target
))
838 ;;Dispatch the possibilities.
840 ((eq preload-target
'dot-emacs
)
841 (elinstall-add-to-dot-emacs "~/.emacs" filename force
))
842 ((stringp preload-target
)
843 (elinstall-symlink-on-emacs-start
844 filename basename preload-target priority force
))
845 ((null preload-target
)
846 (message "Not arranging for preloads"))
848 (message "I don't recognize that")))))
849 ;;;_ . elinstall-stage-arrange-preloads
850 (defun elinstall-stage-arrange-preloads (actions deffiles-used force
)
851 "Arrange any preloads mentioned in ACTIONS."
865 (member filename deffiles-used
)))))
869 #'elinstall-arrange-preload
874 "elinstall-stage-arrange-preloads: Action not
880 ;;;_ . elinstall-stage-run-tests
881 (defun elinstall-stage-run-tests (actions)
882 "Run any tests mentioned in ACTIONS."
888 ;;$$WRITE ME - not a high priority right now.
892 "elinstall-stage-run-tests: Action not
898 ;;;_ . elinstall-stage-byte-compile
899 (defun elinstall-stage-byte-compile (actions)
900 "Do any byte-compilation mentioned in ACTIONS."
905 ;;$$IMPROVE ME Understand flags to control second
906 ;;argument (whether to load file after
909 (byte-compile-file (second act
)))
912 "elinstall-stage-byte-compile: Action not
915 ;;;_ . Segregating actions
916 ;;;_ , elinstall-remove-empty-segs
917 (defun elinstall-remove-empty-segs (segment-list)
918 "Return SEGMENT-LIST minus any segments that have no actions.
919 Intended only for the deffile stage data."
928 ;;;_ , elinstall-segregate-actions
929 (defun elinstall-segregate-actions (actions)
930 "Return actions segregated by deffile.
932 Returns a list whose elements are each a cons of:
933 * deffile filename or nil
934 * A list of actions to be done for that deffile."
941 (arrange-preloads '()))
943 (dolist (act actions
)
950 ((deffile-name (second act
))
952 (assoc deffile-name build-deffiles
)))
954 ;;There are already actions on this deffile.
955 ;;Splice this action in.
957 (cons act
(cdr cell-already
)))
958 ;;There are no actions on this deffile. Add a
959 ;;place for them and include this action.
960 (push (list deffile-name act
) build-deffiles
))))
962 (push act arrange-preloads
))
964 (push act run-tests
))
966 (push act byte-compile
)))))
968 (elinstall-make-stages
970 (elinstall-remove-empty-segs build-deffiles
)
977 ;;;_ . Finding actions
979 ;;;_ . elinstall-dir-has-info
981 ;;$$IMPROVE ME - Can this test be made more precise?
982 (defun elinstall-dir-has-info (dir)
983 "Return non-nil if DIR has info files in it.
984 DIR should be an absolute path."
986 (string-match "/info/" dir
)
987 (directory-files dir nil
"\\.info\\(-[0-9]+\\)?\\(\\.gz\\)?$")))
988 ;;;_ . elinstall-directory-files
989 (defun elinstall-directory-files (dirname)
990 "Return a list of files in directory DIRNAME, minus certain files.
991 The following files are omitted:
993 * Files that match an entry in `block-in-subtree'.
994 Filenames are relative."
996 def-file block-in-dir block-in-subtree
))
999 ;;Relative filenames of this directory's files.
1001 ;; Don't include dot files. If user really wants to
1002 ;;explore one he can use (dir ".NAME") or (file ".NAME")
1003 (directory-files dirname nil
"[^\\.]"))
1004 ;;We know our def-file isn't really source so remove it.
1005 ;;We'd have removed it anyways after seeing file local vars.
1007 (remove def-file all-files
))
1012 #'(lambda (filename)
1018 (string-match blocked filename
))
1027 ;;;_ . List of special variables used in this section
1028 ;;load-path-element - The relevant element of load-path
1029 ;;def-file - The file the autoload definitions etc will go into.
1030 ;;add-to-load-path-p - Controls whether to add to load-path.
1031 ;;recurse-dirs-p - Whether to recurse into subdirectories.
1033 ;;block-in-dir - (NOT IMPLEMENTED) List of filenames to reject. They
1034 ;;may include wildcards. They apply wrt the original directory.
1036 ;;block-in-subtree - (NOT IMPLEMENTED) List of filenames to reject.
1037 ;;They may include wildcards. They apply wrt any directory in the
1038 ;;tree. Specifically, in the spec tree, which may differ from the
1040 ;;byte-compile - whether to byte-compile at all, t by default.
1041 ;;autoloads - boolean whether to make autoloads, t by default.
1042 ;;preloads - boolean whether to set up preloads, t by default.
1043 (defconst elinstall-find-actions-control-vars
1044 '(add-to-load-path-p recurse-dirs-p byte-compile
1046 "Control special variables that the find-actions tree recognizes" )
1047 ;;;_ . elinstall-actions-for-source-file
1048 (defun elinstall-actions-for-source-file (filename dir
)
1049 "Return a list of actions to do for FILENAME in DIR.
1050 Special variables are as noted in \"List of special variables\"."
1052 load-path-element def-file byte-compile
))
1055 (expand-file-name filename dir
)))
1058 (file-readable-p full-path
)
1059 (not (auto-save-file-name-p full-path
)))
1060 ;;$$IMPROVE ME Use more of the control variables.
1063 (visited (get-file-buffer full-path
))
1067 ;;Visit the file cheaply.
1068 ;;hack-local-variables can give errors.
1069 (ignore-errors (autoload-find-file full-path
))))
1073 (with-current-buffer buf
1074 (if (local-variable-p 'generated-autoload-file
)
1075 (elinstall-expand-deffile-name
1076 generated-autoload-file
)
1079 ;;Figure out whether to run some actions, by file local vars.
1082 (with-current-buffer buf
1083 (not no-update-autoloads
))))
1087 (featurep 'byte-compile
)
1088 (string-match emacs-lisp-file-regexp filename
)
1090 (with-current-buffer buf
1091 (not no-byte-compile
)))
1092 (elinstall-proceed-p 'byte-compile
1096 "Already compiled %s.")
1099 ((dest (byte-compile-dest-file full-path
)))
1101 (file-exists-p dest
)
1102 (file-newer-than-file-p full-path dest
)))))))
1107 `(byte-compile ,full-path
)
1110 (elinstall-make-autoload-action
1111 buf def-file load-path-element full-path
)
1113 (unless visited
(kill-buffer-if-not-modified buf
)))))))
1114 ;;;_ . elinstall-actions-for-dir
1115 (defun elinstall-actions-for-dir (dirname &optional recurse-dirs-p
)
1116 "Make actions for DIR.
1117 Recurse just if RECURSE-DIRS-P"
1119 load-path-element def-file add-to-load-path-p
))
1120 ;;This does not treat symlinks specially. $$IMPROVE ME it could
1121 ;;treat/not treat them conditional on control variables.
1124 (files (elinstall-directory-files dirname
))
1126 ;;Relative filenames of elisp source
1130 #'(lambda (filename)
1132 (string-match elinstall-elisp-regexp filename
)
1137 ;;Absolute filenames of subdirectories.
1142 #'(lambda (filename)
1144 ((fn (expand-file-name filename dirname
)))
1146 (file-directory-p fn
)
1154 elisp-source-files
;;If list is not empty.
1155 add-to-load-path-p
))
1157 (if load-path-here-p
1159 load-path-element
)))
1162 ;;Sometimes arrange to add this directory to load-path.
1163 (if load-path-here-p
1166 ,load-path-element
))
1169 ;;$$IMPROVE ME - be controlled by a control variable.
1170 ;;Sometimes add this directory to info path.
1172 (elinstall-dir-has-info dirname
)
1180 #'(lambda (filename)
1181 (elinstall-actions-for-source-file
1184 elisp-source-files
))
1189 #'(lambda (filename)
1190 (elinstall-find-actions-by-spec-x
1198 ;;;_ . elinstall-find-actions-by-spec-x
1200 (defun elinstall-find-actions-by-spec-x (spec dir
)
1201 "Return a list of actions to do, controlled by SPEC."
1203 load-path-element def-file add-to-load-path-p
1204 recurse-dirs-p block-in-dir block-in-subtree
))
1212 #'(lambda (sub-spec)
1213 (elinstall-find-actions-by-spec-x
1218 ;;(block-in-subtree (* FN) SPEC)
1220 ((block-in-subtree (second spec
)))
1221 (elinstall-find-actions-by-spec-x
1225 ;;Rather than trying to bind all control variables each time
1226 ;;thru, we use `set' and `unwind-protect'.
1228 ;;control TYPE DISPOSITION SPEC
1230 ((key (second spec
))
1232 (if (memq key elinstall-find-actions-control-vars
)
1235 (setq old-value
(symbol-value key
))
1236 (set key
(third spec
))
1237 (elinstall-find-actions-by-spec-x
1240 (set key old-value
))
1241 (error "Unrecognized control variable %s" key
))))
1245 ;;(def-file FN ARGS SPEC)
1251 (for-preload (third spec
)))
1252 (assert (listp for-preload
))
1256 (and for-preload
(car for-preload
))
1260 ,@(cdr for-preload
))
1263 (elinstall-find-actions-by-spec-x
1264 (fourth spec
) dir
))))
1268 (elinstall-actions-for-dir
1276 (elinstall-actions-for-source-file
1287 (elinstall-find-actions-by-spec-x
1294 `((add-to-load-path ,def-file
,dir
))
1296 ((load-path-element dir
)
1297 (add-to-load-path-p nil
))
1298 (elinstall-find-actions-by-spec-x
1303 ;;(matching PATTERN SPEC)
1307 ;;$$PUNT Assume that `block-in-subtree' and
1308 ;;`block-in-dir' aren't matched.
1309 (elinstall-find-actions-by-spec-x
1313 dir t
(second spec
)))))
1315 ;;(preload FN SYM &rest ARGS)
1317 ((key (third spec
)))
1319 (and (symbolp key
) (symbol-value key
))
1322 ,(expand-file-name (second spec
) dir
)
1329 (elinstall-actions-for-dir dir nil
))
1331 (elinstall-actions-for-dir dir t
)))))
1333 ;;;_ . elinstall-find-actions-by-spec
1334 (defun elinstall-find-actions-by-spec
1335 (spec load-path-element dir def-file redo-old
)
1336 "Find the list of actions to do according to SPEC."
1340 (def-file-time (elinstall-file-mod-time def-file
))
1341 (add-to-load-path-p t
)
1347 (block-in-subtree '(".git" "RCS" "CVS" "SVN" "^tests\.el")))
1350 load-path-element def-file add-to-load-path-p
1351 recurse-dirs-p byte-compile
1352 block-in-dir block-in-subtree
))
1354 (elinstall-find-actions-by-spec-x spec dir
)))
1356 ;;;_ . high-level work
1357 ;;;_ , elinstall-get-relevant-load-path
1358 (defun elinstall-get-relevant-load-path (actions)
1368 ;;;_ , elinstall-get-deffile-list
1369 (defun elinstall-get-deffile-list (stages)
1370 "Get a list of deffile names"
1374 (elinstall-stages->build-deffiles stages
)))
1376 (defun elinstall-x (dir spec
&optional force
)
1377 "High-level worker function to install elisp files."
1380 ;;This is just the default deffile, spec can override it.
1382 (elinstall-expand-deffile-name nil
))
1384 (elinstall-find-actions-by-spec
1389 (eq force
'redo-old
)))
1390 (stages (elinstall-segregate-actions actions
))
1392 (elinstall-get-relevant-load-path
1395 (elinstall-stage-update-deffiles
1396 (elinstall-stages->build-deffiles stages
)
1399 (elinstall-stage-arrange-preloads
1400 (elinstall-stages->arrange-preloads stages
)
1401 (elinstall-get-deffile-list stages
)
1403 (elinstall-stage-byte-compile
1404 (elinstall-stages->byte-compile stages
))
1406 ;;;_ , elinstall-package
1407 (defun elinstall-package (project-name path spec version-string
)
1408 "Install elisp files. See doc for `elinstall'."
1410 (elinstall-proceed-p 'install
1414 "Already installed %s.")
1416 (elinstall-already-installed project-name
))
1419 `(def-file "loaddefs.el" (if-used ,project-name
) ,spec
)
1421 (elinstall-record-installed project-name version-string
)))
1426 (defun elinstall (project-name path spec
&optional force version-string
)
1427 "Install elisp files.
1428 They need not be a formal package.
1432 PROJECT-NAME - the name of the project
1434 PATH - Path to the project.
1435 Suggestion: Use (elinstall-directory-true-name) to get the real
1436 current directoery name even from loaded files.
1438 SPEC - a spec for the autoloads etc to make. It can be as simple
1441 If FORCE is `t', install a package even if it has already been
1442 installed. If it's a list or `nil', it's treated as a list of
1443 installation restraints. User customizations override this
1446 VERSION-STRING, if given, must be a string of the version for this package."
1448 (elinstall-call-with-restraints
1454 project-name path spec version-string
))
1456 ;;;_ . elinstall-update-directory-autoloads
1459 (defun elinstall-update-directory-autoloads (dir)
1460 "Update autoloads for directory DIR"
1462 (interactive "DUpdate autoloads for all elisp files from directory: ")
1463 (elinstall-call-with-restraints
1471 ;;;_ . elinstall-update-directory
1473 (defun elinstall-update-directory (dir)
1474 "Update autoloads for directory DIR"
1476 (interactive "DInstall all elisp files from directory: ")
1477 (elinstall-call-with-restraints
1484 ;;;_ . elinstall-update-file-autoloads
1486 (defun elinstall-update-file-autoloads (file)
1487 "Update autoloads for elisp file FILE"
1489 (interactive "fUpdate autoloads for elisp file: ")
1490 (elinstall-call-with-restraints
1494 (file-name-directory file
)
1495 `(file ,(file-name-nondirectory file
))))
1497 ;;;_ . elinstall-update-file
1499 (defun elinstall-update-file (file)
1500 "Install elisp file FILE"
1502 (interactive "fInstall elisp file: ")
1503 (elinstall-call-with-restraints
1508 (file-name-directory file
)
1509 `(file ,(file-name-nondirectory file
))))
1514 (provide 'elinstall
)
1516 ;;;_ * Local emacs vars.
1517 ;;;_ + Local variables:
1522 ;;; elinstall.el ends here