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 ;;$$PUNT for now. Figure out user restraints for this
213 (elinstall:*user-restraints
*
216 elinstall
:*pkg-restraints
*
217 elinstall
:*user-restraints
*))
220 (defun elinstall-proceed-p
221 (topic message-params
&optional already-p
)
222 "Return non-nil if actions on TOPIC should proceed.
223 Call this transitively only thru `elinstall-call-with-restraints'.
224 TOPIC is a symbol indicating the topic, such as `byte-compile'.
225 MESSAGE-PARAMS is a cons of:
226 * A list of format strings:
227 * To ask whether to do this action
228 * To ask whether to redo this action, for `ask-for-old'
229 * To report that this action was skipped because already done.
230 * The arguments to the formatter.
231 ALREADY-P is an extended boolean whether the task has been done
232 before, if caller can tell."
234 (check-type topic symbol
)
236 elinstall
:*pkg-restraints
*
237 elinstall
:*user-restraints
*))
239 (boundp 'elinstall
:*pkg-restraints
*)
240 (boundp 'elinstall
:*user-restraints
*))
241 (error "elinstall-proceed-p called out of scope"))
244 ((ask-prompt &optional redo-prompt noredo-msg
) &rest message-args
)
247 ( ;;Get the applicable cell. We look in several places.
248 (cell (assq topic elinstall
:*user-restraints
*))
249 (cell (or cell
(assq t elinstall
:*user-restraints
*)))
251 ;;`t' means use the pkg-restraints value instead.
253 (or (not cell
) (eq (second cell
) t
))
254 (assq topic elinstall
:*pkg-restraints
*)
256 (cell (or cell
(assq t elinstall
:*pkg-restraints
*)))
258 ;;Default is to just update.
259 (if cell
(second cell
) 'update
)))
268 (apply #'message noredo-msg message-args
)
273 (y-or-n-p (apply #'format redo-prompt message-args
))
277 (apply #'format ask-prompt message-args
)))))))
282 ;;;_ , Doing autoload actions (adapted from autoload.el)
283 ;;;_ . Utilities about the action list
284 ;;;_ , elinstall-remove-autogen-action
285 (defun elinstall-remove-autogen-action (file actions
)
286 "Return ACTIONS minus any add-file-autoloads on FILE removed."
293 (if (equal file
(third act
))
298 ;;;_ , elinstall-get-autogen-action
299 (defun elinstall-get-autogen-action (file actions
)
303 (dolist (act actions
)
306 (when (equal file
(third act
))
307 (setq the-act act
)))))
309 ;;;_ . About printing to autoload file
310 ;;;_ , elinstall-insert-section-header
311 (defun elinstall-insert-section-header (outbuf form
)
312 "Insert the section-header line,
313 which lists the file name and which functions are in it, etc."
314 (insert generate-autoload-section-header
)
317 ;; Break that line at spaces, to avoid very long lines.
318 ;; Make each sub-line into a comment.
319 (with-current-buffer outbuf
324 (skip-chars-forward "^ \n")
326 (insert "\n" generate-autoload-section-continuation
))))))
328 ;;;_ , elinstall-insert-autoload-section
329 (defun elinstall-insert-autoload-section (text form
&optional comment-string
)
330 "Insert TEXT into current buffer as an autoload section"
335 ;; This does something in Lucid Emacs.
337 (float-output-format nil
))
339 (elinstall-insert-section-header (current-buffer) form
)
341 (insert ";;; " comment-string
"\n"))
343 (insert generate-autoload-section-trailer
)))
345 ;;;_ . Making autoloads
346 ;;;_ , elinstall-make-autoload-action
347 (defun elinstall-make-autoload-action (buf def-file load-path-element full-path
)
348 "Return the autoloads for current buffer as a string"
350 ;;We put all the text into a temp buffer, then get that buffer's
354 (generate-new-buffer " *temp*"))
357 (file-name-nondirectory full-path
))
361 ;; Apparently this does something in Lucid Emacs.
363 (float-output-format nil
)
365 ;;load-name relative to a member of load-path.
367 (file-name-sans-extension
370 load-path-element
))))
372 (with-current-buffer buf
377 (goto-char (point-min))
378 (message "Finding autoloads for %s..." short-name
)
380 (skip-chars-forward " \t\n\f")
382 ((looking-at (regexp-quote generate-autoload-cookie
))
383 (search-forward generate-autoload-cookie
)
384 (skip-chars-forward " \t")
386 ;; Read the next form and make an autoload.
387 (let* ((form (prog1 (read (current-buffer))
388 (or (bolp) (forward-line 1))))
390 (make-autoload form relative-name
)))
392 (push (nth 1 form
) autoloads-done
)
393 (setq autoload form
))
394 (let ((autoload-print-form-outbuf outbuf
))
395 (autoload-print-form autoload
)))
397 ;; Copy the rest of the line to the output.
398 (princ (buffer-substring
400 ;; Back up over whitespace,
402 (skip-chars-backward " \f\t")
403 (if (= (char-after (1+ (point))) ?
)
407 (progn (forward-line 1) (point)))
410 ;; Don't read the comment.
415 (message "Finding autoloads for %s...done" short-name
))
417 ;;Return this action. The temp buffer's contents is
423 ,(with-current-buffer outbuf
(buffer-string))
426 ;;This in unwind-protected
427 (when (buffer-live-p outbuf
) (kill-buffer outbuf
))))))
430 ;;;_ , elinstall-generate-file-autoloads
432 (defun elinstall-generate-file-autoloads
433 (relative-name full-name text autoloads-done
)
434 "Insert at point a loaddefs autoload section for FILE.
435 Autoloads are generated for defuns and defmacros in FILE
436 marked by `generate-autoload-cookie' (which see).
437 If FILE is being visited in a buffer, the contents of the buffer
439 Return non-nil in the case where no autoloads were added at point.
441 FULL-NAME is the absolute name of the file.
442 RELATIVE-NAME is its name respective to some component of load-path."
443 (if (not (equal text
""))
444 ;; Insert the section-header line which lists the file name and
445 ;; which functions are in it, etc.
446 (elinstall-insert-autoload-section
451 (autoload-trim-file-name full-name
)
452 (elinstall-file-mod-time full-name
))
454 "Generated autoloads from "
455 (autoload-trim-file-name full-name
)))
458 ;;;_ , elinstall-deffile-insert-autoloads
459 (defun elinstall-deffile-insert-autoloads (file args
)
460 "Update the autoloads for FILE in current buffer.
461 Return FILE if there was no autoload cookie in it, else nil.
463 Current buffer must be a loaddef-style file.
465 LOAD-NAME is the absolute name of the file.
466 RELATIVE-NAME is its name respective to some component of load-path."
474 (goto-char (point-min))
475 ;; Look for the section for FILE
476 (while (and (not found
)
477 (search-forward generate-autoload-section-header nil t
))
478 (let ((form (autoload-read-section-header)))
480 ((equal (nth 2 form
) file
)
481 ;; We found the section for this file.
482 (let ((begin (match-beginning 0)))
484 (search-forward generate-autoload-section-trailer
)
485 (delete-region begin
(point))
487 ((string< file
(nth 2 form
))
488 ;; We've come to a section alphabetically later than
489 ;; FILE. We assume the file is in order and so
490 ;; there must be no section for FILE. We will
491 ;; insert one before the section here.
492 (goto-char (match-beginning 0))
493 (setq found
'new
)))))
497 ;; No later sections in the file. Put before the last page.
498 (goto-char (point-max))
499 (search-backward "\f" nil t
)))
501 (apply #'elinstall-generate-file-autoloads
504 (if no-autoloads file nil
)))
505 ;;;_ . Arranging to add to info-path and load-path
506 ;;;_ , elinstall-generate-add-to-path
507 (defun elinstall-generate-add-to-path (path-element type
)
508 "Insert code at point to add PATH-ELEMENT to a path.
510 * `add-to-load-path', add to load-path
511 * `add-to-info-path', add to Info-additional-directory-list
513 Current buffer must be a loaddef-style file."
516 (add-to-load-path 'load-path
)
517 (add-to-info-path 'Info-additional-directory-list
)
518 (t (error "Type not recognized"))))
521 (add-to-load-path "load-path")
522 (add-to-info-path "info-path")))
526 ;; This does something in Lucid Emacs.
528 (float-output-format nil
))
530 (message "Generating %s additions..." description
)
532 (elinstall-insert-autoload-section
534 `(add-to-list ',path-symbol
536 ,(file-relative-name path-element
)
539 (file-truename load-file-name
))))))
540 (list type
(list path-element
) nil nil nil
)
542 (message "Generating %s additions...done" description
)))
545 ;;;_ , elinstall-deffile-insert-add-to-path
546 (defun elinstall-deffile-insert-add-to-path (path-element type
)
547 "Insert code in current buffer to add PATH-ELEMENT to a path.
549 * `add-to-load-path', add to load-path
550 * `add-to-info-path', add to Info-default-directory-list
552 Current buffer must be a loaddef-style file."
560 (goto-char (point-min))
561 ;; Look for the section for PATH-ELEMENT
562 (while (and (not found
)
563 (search-forward generate-autoload-section-header nil t
))
564 (let ((form (autoload-read-section-header)))
567 (equal (nth 0 form
) type
)
568 (member path-element
(nth 1 form
)))
570 ;; We found the section for this add.
571 (let ((begin (match-beginning 0)))
573 (search-forward generate-autoload-section-trailer
)
574 (delete-region begin
(point))
580 ;; No later sections in the file. Put before the last page.
581 (goto-char (point-max))
582 (search-backward "\f" nil t
)))
584 (elinstall-generate-add-to-path path-element type
)))
586 ;;This never belongs in the no-autoloads section.
588 ;;;_ . elinstall-deffile-insert
590 (defun elinstall-deffile-insert (action)
591 "Insert autoloads etc into current file according to ACTION.
592 The format of ACTION is described in the design docs.
594 Return filename if this action belongs in the no-autoload section."
599 (elinstall-deffile-insert-autoloads
604 (elinstall-deffile-insert-add-to-path
610 (elinstall-deffile-insert-add-to-path
615 ((preload-file run-tests byte-compile
)
616 (error "This case should not come here.")))))
618 ;;;_ . elinstall-prepare-deffile
619 (defun elinstall-prepare-deffile (deffile)
620 "Try to ensure that DEFFILE is available for receiving autoloads"
622 (autoload-ensure-default-file deffile
)
623 (with-current-buffer (find-file-noselect deffile
)
626 ;; We must read/write the file without any code conversion,
627 ;; but still decode EOLs.
628 (let ((coding-system-for-read 'raw-text
))
630 ;; This is to make generated-autoload-file have Unix EOLs, so
631 ;; that it is portable to all platforms.
632 (setq buffer-file-coding-system
'raw-text-unix
))
633 (or (> (buffer-size) 0)
634 (error "Autoloads file %s does not exist" buffer-file-name
))
635 (or (file-writable-p buffer-file-name
)
636 (error "Autoloads file %s is not writable"
639 ;;;_ . elinstall-update-deffile
641 ;;Adapted from autoload.el `update-directory-autoloads'.
643 (defun elinstall-update-deffile (target actions
&optional
646 Update file TARGET with current autoloads as specified by ACTIONS.
647 Also remove any old definitions pointing to libraries that can no
650 ACTIONS must be a list of actions (See the format doc). Each one's
651 filename must be relative to some element of load-path.
653 USE-LOAD-PATH is a list to use as load-path. It should include
654 any new load-path that we are arranging to create. If it's not given,
655 load-path itself is used.
657 If FORCE is `t', do it regardless of timestamps etc. (Not implemented)
658 Other non-nil cases of FORCE are reserved for future development.
660 This uses `update-file-autoloads' (which see) to do its work.
661 In an interactive call, you must give one argument, the name
662 of a single directory."
665 (use-load-path (or use-load-path load-path
))
666 (this-time (current-time))
667 ;;files with no autoload cookies.
670 (elinstall-prepare-deffile target
)
672 (find-file-noselect target
)
675 (elinstall-remove-autogen-action
676 (autoload-trim-file-name target
)
679 (goto-char (point-min))
680 (while (search-forward generate-autoload-section-header nil t
)
681 (let* ((form (autoload-read-section-header))
683 (cond ((and (consp file
) (stringp (car file
)))
684 ;; This is a list of files that have no
686 ;; There shouldn't be more than one such entry.
687 ;; Remove the obsolete section.
688 (autoload-remove-section (match-beginning 0))
689 (let ((last-time (nth 4 form
)))
691 (let ((file-time (elinstall-file-mod-time file
)))
693 (not (time-less-p last-time file-time
)))
695 (push file no-autoloads
)
697 (elinstall-remove-autogen-action
699 ((not (stringp file
)))
703 (locate-library file nil use-load-path
)))
705 ;;File doesn't exist, so remove its
708 (autoload-remove-section
709 (match-beginning 0)))
711 ;; File hasn't changed, so do nothing.
714 (elinstall-file-mod-time file-path
))
717 (elinstall-deffile-insert
718 (elinstall-get-autogen-action
722 (elinstall-remove-autogen-action
725 ;; Remaining actions have no existing autoload sections yet.
728 (delq nil
(mapcar #'elinstall-deffile-insert actions
))))
730 ;; Sort them for better readability.
731 (setq no-autoloads
(sort no-autoloads
'string
<))
732 ;; Add the `no-autoloads' section.
733 (goto-char (point-max))
734 (search-backward "\f" nil t
)
735 (elinstall-insert-autoload-section
737 (list 'autoloads nil nil no-autoloads this-time
)))
740 ;;;_ . elinstall-stage-update-deffiles
741 (defun elinstall-stage-update-deffiles (segment-list force use-load-path
)
742 "Update any deffiles mentioned in SEGMENT-LIST.
743 FORCE and USE-LOAD-PATH have the same meaning as in
744 `elinstall-update-deffile'.
749 ((deffile (car segment
)))
750 (if (stringp deffile
)
751 (elinstall-update-deffile deffile
(cdr segment
) force
755 ;;;_ , Doing actions to arrange preloads
756 ;;;_ . elinstall-symlink-on-emacs-start
757 (defun elinstall-symlink-on-emacs-start
758 (filename target-basename target-dir
&optional priority force
)
759 "Symlink to TARGET-BASENAME.el in TARGET-DIR
761 If PRIORITY is given, it will be used as the priority prefix,
762 otherwise elinstall-default-priority will be.
763 PRIORITY must be an integer or nil.
764 If FORCE is `t', do it regardless of timestamps etc.
765 Other non-nil cases of FORCE are reserved for future development."
768 (priority (or priority elinstall-default-priority
))
775 (expand-file-name target-name-nodir target-dir
)))
779 ;;Path should already exist.
781 (file-exists-p target-dir
))
782 (message "The target directory doesn't exist."))
783 ;;Target shouldn't already exist, but if force is given, let
785 ;;$$IMPROVE ME If it is a symlink pointing to the same place,
786 ;;do nothing even on force.
788 (file-exists-p target
)
793 (format "Really overwrite %s? " target
))))
794 (message "File %s already exists" target
)))
802 ;;;_ . elinstall-add-to-dot-emacs
803 (defun elinstall-add-to-dot-emacs (dot-emacs-name filename force
&rest r
)
804 "Add code to load FILENAME to .emacs.
805 FILENAME should not have an extension"
808 (with-current-buffer (find-file-noselect dot-emacs-name
)
811 (goto-char (point-max))
812 (insert "\n;;Added by elinstall")
813 (insert "\n;;Consider using my-site-start to manage .emacs\n")
814 (pp `(load ,filename
) (current-buffer))
818 ;;;_ . elinstall-arrange-preload
820 (defun elinstall-arrange-preload (force filename basename
&optional priority
)
821 "Arrange for FILENAME to be loaded on emacs start.
822 FORCE has its usual meaning.
823 BASENAME and PRIORITY are used as arguments to
824 `elinstall-symlink-on-emacs-start'.
828 ((preload-target elinstall-default-preload-target
))
830 ;;Dispatch the possibilities.
832 ((eq preload-target
'dot-emacs
)
833 (elinstall-add-to-dot-emacs "~/.emacs" filename force
))
834 ((stringp preload-target
)
835 (elinstall-symlink-on-emacs-start
836 filename basename preload-target priority force
))
837 ((null preload-target
)
838 (message "Not arranging for preloads"))
840 (message "I don't recognize that")))))
841 ;;;_ . elinstall-stage-arrange-preloads
842 (defun elinstall-stage-arrange-preloads (actions deffiles-used force
)
843 "Arrange any preloads mentioned in ACTIONS."
857 (member filename deffiles-used
)))))
861 #'elinstall-arrange-preload
866 "elinstall-stage-arrange-preloads: Action not
872 ;;;_ . elinstall-stage-run-tests
873 (defun elinstall-stage-run-tests (actions)
874 "Run any tests mentioned in ACTIONS."
880 ;;$$WRITE ME - not a high priority right now.
884 "elinstall-stage-run-tests: Action not
890 ;;;_ . elinstall-stage-byte-compile
891 (defun elinstall-stage-byte-compile (actions)
892 "Do any byte-compilation mentioned in ACTIONS."
897 ;;$$IMPROVE ME Understand flags to control second
898 ;;argument (whether to load file after
901 (byte-compile-file (second act
)))
904 "elinstall-stage-byte-compile: Action not
907 ;;;_ . Segregating actions
908 ;;;_ , elinstall-remove-empty-segs
909 (defun elinstall-remove-empty-segs (segment-list)
910 "Return SEGMENT-LIST minus any segments that have no actions.
911 Intended only for the deffile stage data."
920 ;;;_ , elinstall-segregate-actions
921 (defun elinstall-segregate-actions (actions)
922 "Return actions segregated by deffile.
924 Returns a list whose elements are each a cons of:
925 * deffile filename or nil
926 * A list of actions to be done for that deffile."
933 (arrange-preloads '()))
935 (dolist (act actions
)
942 ((deffile-name (second act
))
944 (assoc deffile-name build-deffiles
)))
946 ;;There are already actions on this deffile.
947 ;;Splice this action in.
949 (cons act
(cdr cell-already
)))
950 ;;There are no actions on this deffile. Add a
951 ;;place for them and include this action.
952 (push (list deffile-name act
) build-deffiles
))))
954 (push act arrange-preloads
))
956 (push act run-tests
))
958 (push act byte-compile
)))))
960 (elinstall-make-stages
962 (elinstall-remove-empty-segs build-deffiles
)
969 ;;;_ . Finding actions
971 ;;;_ . elinstall-dir-has-info
973 ;;$$IMPROVE ME - Can this test be made more precise?
974 (defun elinstall-dir-has-info (dir)
975 "Return non-nil if DIR has info files in it.
976 DIR should be an absolute path."
978 (string-match "/info/" dir
)
979 (directory-files dir nil
"\\.info\\(-[0-9]+\\)?\\(\\.gz\\)?$")))
980 ;;;_ . elinstall-directory-files
981 (defun elinstall-directory-files (dirname)
982 "Return a list of files in directory DIRNAME, minus certain files.
983 The following files are omitted:
985 * Files that match an entry in `block-in-subtree'.
986 Filenames are relative."
988 def-file block-in-dir block-in-subtree
))
991 ;;Relative filenames of this directory's files.
993 ;; Don't include dot files. If user really wants to
994 ;;explore one he can use (dir ".NAME") or (file ".NAME")
995 (directory-files dirname nil
"[^\\.]"))
996 ;;We know our def-file isn't really source so remove it.
997 ;;We'd have removed it anyways after seeing file local vars.
999 (remove def-file all-files
))
1004 #'(lambda (filename)
1010 (string-match blocked filename
))
1019 ;;;_ . List of special variables used in this section
1020 ;;load-path-element - The relevant element of load-path
1021 ;;def-file - The file the autoload definitions etc will go into.
1022 ;;add-to-load-path-p - Controls whether to add to load-path.
1023 ;;recurse-dirs-p - Whether to recurse into subdirectories.
1025 ;;block-in-dir - (NOT IMPLEMENTED) List of filenames to reject. They
1026 ;;may include wildcards. They apply wrt the original directory.
1028 ;;block-in-subtree - (NOT IMPLEMENTED) List of filenames to reject.
1029 ;;They may include wildcards. They apply wrt any directory in the
1030 ;;tree. Specifically, in the spec tree, which may differ from the
1032 ;;byte-compile - whether to byte-compile at all, t by default.
1033 ;;autoloads - boolean whether to make autoloads, t by default.
1034 ;;preloads - boolean whether to set up preloads, t by default.
1035 (defconst elinstall-find-actions-control-vars
1036 '(add-to-load-path-p recurse-dirs-p byte-compile
1038 "Control special variables that the find-actions tree recognizes" )
1039 ;;;_ . elinstall-actions-for-source-file
1040 (defun elinstall-actions-for-source-file (filename dir
)
1041 "Return a list of actions to do for FILENAME in DIR.
1042 Special variables are as noted in \"List of special variables\"."
1044 load-path-element def-file byte-compile
))
1047 (expand-file-name filename dir
)))
1050 (file-readable-p full-path
)
1051 (not (auto-save-file-name-p full-path
)))
1052 ;;$$IMPROVE ME Use more of the control variables.
1055 (visited (get-file-buffer full-path
))
1059 ;;Visit the file cheaply.
1060 ;;hack-local-variables can give errors.
1061 (ignore-errors (autoload-find-file full-path
))))
1065 (with-current-buffer buf
1066 (if (local-variable-p 'generated-autoload-file
)
1067 (elinstall-expand-deffile-name
1068 generated-autoload-file
)
1071 ;;Figure out whether to run some actions, by file local vars.
1074 (with-current-buffer buf
1075 (not no-update-autoloads
))))
1079 (featurep 'byte-compile
)
1080 (string-match emacs-lisp-file-regexp filename
)
1082 (with-current-buffer buf
1083 (not no-byte-compile
)))
1084 (elinstall-proceed-p 'byte-compile
1088 "Already compiled %s.")
1091 ((dest (byte-compile-dest-file full-path
)))
1093 (file-exists-p dest
)
1094 (file-newer-than-file-p full-path dest
)))))))
1099 `(byte-compile ,full-path
)
1102 (elinstall-make-autoload-action
1103 buf def-file load-path-element full-path
)
1105 (unless visited
(kill-buffer-if-not-modified buf
)))))))
1106 ;;;_ . elinstall-actions-for-dir
1107 (defun elinstall-actions-for-dir (dirname &optional recurse-dirs-p
)
1108 "Make actions for DIR.
1109 Recurse just if RECURSE-DIRS-P"
1111 load-path-element def-file add-to-load-path-p
))
1112 ;;This does not treat symlinks specially. $$IMPROVE ME it could
1113 ;;treat/not treat them conditional on control variables.
1116 (files (elinstall-directory-files dirname
))
1118 ;;Relative filenames of elisp source
1122 #'(lambda (filename)
1124 (string-match elinstall-elisp-regexp filename
)
1129 ;;Absolute filenames of subdirectories.
1134 #'(lambda (filename)
1136 ((fn (expand-file-name filename dirname
)))
1138 (file-directory-p fn
)
1146 elisp-source-files
;;If list is not empty.
1147 add-to-load-path-p
))
1149 (if load-path-here-p
1151 load-path-element
)))
1154 ;;Sometimes arrange to add this directory to load-path.
1155 (if load-path-here-p
1158 ,load-path-element
))
1161 ;;$$IMPROVE ME - be controlled by a control variable.
1162 ;;Sometimes add this directory to info path.
1164 (elinstall-dir-has-info dirname
)
1172 #'(lambda (filename)
1173 (elinstall-actions-for-source-file
1176 elisp-source-files
))
1181 #'(lambda (filename)
1182 (elinstall-find-actions-by-spec-x
1190 ;;;_ . elinstall-find-actions-by-spec-x
1192 (defun elinstall-find-actions-by-spec-x (spec dir
)
1193 "Return a list of actions to do, controlled by SPEC."
1195 load-path-element def-file add-to-load-path-p
1196 recurse-dirs-p block-in-dir block-in-subtree
))
1204 #'(lambda (sub-spec)
1205 (elinstall-find-actions-by-spec-x
1210 ;;(block-in-subtree (* FN) SPEC)
1212 ((block-in-subtree (second spec
)))
1213 (elinstall-find-actions-by-spec-x
1217 ;;Rather than trying to bind all control variables each time
1218 ;;thru, we use `set' and `unwind-protect'.
1220 ;;control TYPE DISPOSITION SPEC
1222 ((key (second spec
))
1224 (if (memq key elinstall-find-actions-control-vars
)
1227 (setq old-value
(symbol-value key
))
1228 (set key
(third spec
))
1229 (elinstall-find-actions-by-spec-x
1232 (set key old-value
))
1233 (error "Unrecognized control variable %s" key
))))
1237 ;;(def-file FN ARGS SPEC)
1243 (for-preload (third spec
)))
1244 (assert (listp for-preload
))
1248 (and for-preload
(car for-preload
))
1252 ,@(cdr for-preload
))
1255 (elinstall-find-actions-by-spec-x
1256 (fourth spec
) dir
))))
1260 (elinstall-actions-for-dir
1268 (elinstall-actions-for-source-file
1279 (elinstall-find-actions-by-spec-x
1286 `((add-to-load-path ,def-file
,dir
))
1288 ((load-path-element dir
)
1289 (add-to-load-path-p nil
))
1290 (elinstall-find-actions-by-spec-x
1295 ;;(matching PATTERN SPEC)
1299 ;;$$PUNT Assume that `block-in-subtree' and
1300 ;;`block-in-dir' aren't matched.
1301 (elinstall-find-actions-by-spec-x
1305 dir t
(second spec
)))))
1307 ;;(preload FN SYM &rest ARGS)
1309 ((key (third spec
)))
1311 (and (symbolp key
) (symbol-value key
))
1314 ,(expand-file-name (second spec
) dir
)
1321 (elinstall-actions-for-dir dir nil
))
1323 (elinstall-actions-for-dir dir t
)))))
1325 ;;;_ . elinstall-find-actions-by-spec
1326 (defun elinstall-find-actions-by-spec
1327 (spec load-path-element dir def-file redo-old
)
1328 "Find the list of actions to do according to SPEC."
1332 (def-file-time (elinstall-file-mod-time def-file
))
1333 (add-to-load-path-p t
)
1339 (block-in-subtree '(".git" "RCS" "CVS" "SVN" "^tests\.el")))
1342 load-path-element def-file add-to-load-path-p
1343 recurse-dirs-p byte-compile
1344 block-in-dir block-in-subtree
))
1346 (elinstall-find-actions-by-spec-x spec dir
)))
1348 ;;;_ . high-level work
1349 ;;;_ , elinstall-get-relevant-load-path
1350 (defun elinstall-get-relevant-load-path (actions)
1360 ;;;_ , elinstall-get-deffile-list
1361 (defun elinstall-get-deffile-list (stages)
1362 "Get a list of deffile names"
1366 (elinstall-stages->build-deffiles stages
)))
1368 (defun elinstall-x (dir spec
&optional force
)
1369 "High-level worker function to install elisp files."
1372 ;;This is just the default deffile, spec can override it.
1374 (elinstall-expand-deffile-name nil
))
1376 (elinstall-find-actions-by-spec
1381 (eq force
'redo-old
)))
1382 (stages (elinstall-segregate-actions actions
))
1384 (elinstall-get-relevant-load-path
1387 (elinstall-stage-update-deffiles
1388 (elinstall-stages->build-deffiles stages
)
1391 (elinstall-stage-arrange-preloads
1392 (elinstall-stages->arrange-preloads stages
)
1393 (elinstall-get-deffile-list stages
)
1395 (elinstall-stage-byte-compile
1396 (elinstall-stages->byte-compile stages
))
1398 ;;;_ , elinstall-package
1399 (defun elinstall-package (project-name path spec version-string
)
1400 "Install elisp files. See doc for `elinstall'."
1402 (elinstall-proceed-p 'install
1406 "Already installed %s.")
1408 (elinstall-already-installed project-name
))
1411 `(def-file "loaddefs.el" (if-used ,project-name
) ,spec
)
1413 (elinstall-record-installed project-name version-string
)))
1418 (defun elinstall (project-name path spec
&optional force version-string
)
1419 "Install elisp files.
1420 They need not be a formal package.
1424 PROJECT-NAME - the name of the project
1426 PATH - Path to the project.
1427 Suggestion: Use (elinstall-directory-true-name) to get the real
1428 current directoery name even from loaded files.
1430 SPEC - a spec for the autoloads etc to make. It can be as simple
1433 If FORCE is `t', install a package even if it has already been
1434 installed. If it's a list or `nil', it's treated as a list of
1435 installation restraints. User customizations override this
1438 VERSION-STRING, if given, must be a string of the version for this package."
1440 (elinstall-call-with-restraints
1446 project-name path spec version-string
))
1448 ;;;_ . elinstall-update-directory-autoloads
1451 (defun elinstall-update-directory-autoloads (dir)
1452 "Update autoloads for directory DIR"
1454 (interactive "DUpdate autoloads for all elisp files from directory: ")
1455 (elinstall-call-with-restraints
1463 ;;;_ . elinstall-update-directory
1465 (defun elinstall-update-directory (dir)
1466 "Update autoloads for directory DIR"
1468 (interactive "DInstall all elisp files from directory: ")
1469 (elinstall-call-with-restraints
1476 ;;;_ . elinstall-update-file-autoloads
1478 (defun elinstall-update-file-autoloads (file)
1479 "Update autoloads for elisp file FILE"
1481 (interactive "fUpdate autoloads for elisp file: ")
1482 (elinstall-call-with-restraints
1486 (file-name-directory file
)
1487 `(file ,(file-name-nondirectory file
))))
1489 ;;;_ . elinstall-update-file
1491 (defun elinstall-update-file (file)
1492 "Install elisp file FILE"
1494 (interactive "fInstall elisp file: ")
1495 (elinstall-call-with-restraints
1500 (file-name-directory file
)
1501 `(file ,(file-name-nondirectory file
))))
1506 (provide 'elinstall
)
1508 ;;;_ * Local emacs vars.
1509 ;;;_ + Local variables:
1514 ;;; elinstall.el ends here