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-already-installed
73 (defcustom elinstall-already-installed
75 "(AUTOMATIC) Things that have already been installed.
76 This exists for recording what has been installed.
78 Though it's saved as customizable, user interaction is not
80 ;;Tell the byte-compiler it's a variable.
81 (defvar elinstall-already-installed
)
83 ;;;_ . elinstall-stages
84 (defstruct (elinstall-stages
85 (:constructor elinstall-make-stages
)
86 (:conc-name elinstall-stages-
>)
88 "The elinstall stages"
94 ;;;_ . Regular expressions
95 ;;;_ , elinstall-elisp-regexp
96 (defconst elinstall-elisp-regexp
99 (suf (get-load-suffixes))
100 (unless (string-match "\\.elc" suf
) (push suf tmp
)))
101 (concat "^[^=.].*" (regexp-opt tmp t
) "\\'"))
102 "Regular expression that matches elisp files" )
104 ;;;_ . elinstall-file-mod-time
105 (defsubst elinstall-file-mod-time
(file)
106 "Return the modification time of FILE"
107 (nth 5 (file-attributes file
)))
109 ;;;_ . elinstall-directory-true-name
110 (defun elinstall-directory-true-name ()
111 "Get the true name of the directory the calling code lives in.
112 CAUTION: This is sensitive to where it's called. That's the point of it."
115 (file-truename load-file-name
)
116 (file-truename buffer-file-name
))))
117 ;;;_ . Checking installedness
118 ;;;_ , elinstall-get-installation-record
119 (defun elinstall-get-installation-record (project-name)
120 "Return the installation record for PROJECT-NAME."
122 (assoc project-name elinstall-already-installed
))
124 ;;;_ , elinstall-already-installed
125 (defun elinstall-already-installed (project-name)
126 "Return non-nil if PROJECT-NAME has been installed."
127 (elinstall-get-installation-record project-name
))
129 ;;;_ , elinstall-record-installed
130 (defun elinstall-record-installed (project-name &optional version
)
131 "Record that PROJECT-NAME has been installed."
140 (elinstall-get-installation-record project-name
))
144 (setq elinstall-already-installed
145 (delete old-item elinstall-already-installed
)))
146 (push new-item elinstall-already-installed
)
147 (customize-save-variable
148 'elinstall-already-installed
149 elinstall-already-installed
150 "Set by elinstall-record-installed")))
151 ;;;_ . Finding deffiles
152 ;;;_ , elinstall-expand-deffile-name
153 (defun elinstall-expand-deffile-name (deffile)
154 "Expand DEFFILE autoload.el's way."
156 (expand-file-name (or deffile
"loaddefs.el")
157 (expand-file-name "lisp"
163 ;;;_ , Doing autoload actions (adapted from autoload.el)
164 ;;;_ . Utilities about the action list
165 ;;;_ , elinstall-remove-autogen-action
166 (defun elinstall-remove-autogen-action (file actions
)
167 "Return ACTIONS minus any add-file-autoloads on FILE removed."
174 (if (equal file
(third act
))
179 ;;;_ , elinstall-get-autogen-action
180 (defun elinstall-get-autogen-action (file actions
)
184 (dolist (act actions
)
187 (when (equal file
(third act
))
188 (setq the-act act
)))))
190 ;;;_ . About printing to autoload file
191 ;;;_ , elinstall-insert-section-header
192 (defun elinstall-insert-section-header (outbuf form
)
193 "Insert the section-header line,
194 which lists the file name and which functions are in it, etc."
195 (insert generate-autoload-section-header
)
198 ;; Break that line at spaces, to avoid very long lines.
199 ;; Make each sub-line into a comment.
200 (with-current-buffer outbuf
205 (skip-chars-forward "^ \n")
207 (insert "\n" generate-autoload-section-continuation
))))))
209 ;;;_ , elinstall-insert-autoload-section
210 (defun elinstall-insert-autoload-section (text form
&optional comment-string
)
211 "Insert TEXT into current buffer as an autoload section"
216 ;; This does something in Lucid Emacs.
218 (float-output-format nil
))
220 (elinstall-insert-section-header (current-buffer) form
)
222 (insert ";;; " comment-string
"\n"))
224 (insert generate-autoload-section-trailer
)))
226 ;;;_ . Making autoloads
227 ;;;_ , elinstall-make-autoload-action
228 (defun elinstall-make-autoload-action (buf def-file load-path-element full-path
)
229 "Return the autoloads for current buffer as a string"
231 ;;We put all the text into a temp buffer, then get that buffer's
235 (generate-new-buffer " *temp*"))
238 (file-name-nondirectory full-path
))
242 ;; Apparently this does something in Lucid Emacs.
244 (float-output-format nil
)
246 ;;load-name relative to a member of load-path.
248 (file-name-sans-extension
251 load-path-element
))))
253 (with-current-buffer buf
258 (goto-char (point-min))
259 (message "Finding autoloads for %s..." short-name
)
261 (skip-chars-forward " \t\n\f")
263 ((looking-at (regexp-quote generate-autoload-cookie
))
264 (search-forward generate-autoload-cookie
)
265 (skip-chars-forward " \t")
267 ;; Read the next form and make an autoload.
268 (let* ((form (prog1 (read (current-buffer))
269 (or (bolp) (forward-line 1))))
271 (make-autoload form relative-name
)))
273 (push (nth 1 form
) autoloads-done
)
274 (setq autoload form
))
275 (let ((autoload-print-form-outbuf outbuf
))
276 (autoload-print-form autoload
)))
278 ;; Copy the rest of the line to the output.
279 (princ (buffer-substring
281 ;; Back up over whitespace,
283 (skip-chars-backward " \f\t")
284 (if (= (char-after (1+ (point))) ?
)
288 (progn (forward-line 1) (point)))
291 ;; Don't read the comment.
296 (message "Finding autoloads for %s...done" short-name
))
298 ;;Return this action. The temp buffer's contents is
304 ,(with-current-buffer outbuf
(buffer-string))
307 ;;This in unwind-protected
308 (when (buffer-live-p outbuf
) (kill-buffer outbuf
))))))
311 ;;;_ , elinstall-generate-file-autoloads
313 (defun elinstall-generate-file-autoloads
314 (relative-name full-name text autoloads-done
)
315 "Insert at point a loaddefs autoload section for FILE.
316 Autoloads are generated for defuns and defmacros in FILE
317 marked by `generate-autoload-cookie' (which see).
318 If FILE is being visited in a buffer, the contents of the buffer
320 Return non-nil in the case where no autoloads were added at point.
322 FULL-NAME is the absolute name of the file.
323 RELATIVE-NAME is its name respective to some component of load-path."
324 (if (not (equal text
""))
325 ;; Insert the section-header line which lists the file name and
326 ;; which functions are in it, etc.
327 (elinstall-insert-autoload-section
332 (autoload-trim-file-name full-name
)
333 (elinstall-file-mod-time full-name
))
335 "Generated autoloads from "
336 (autoload-trim-file-name full-name
)))
339 ;;;_ , elinstall-deffile-insert-autoloads
340 (defun elinstall-deffile-insert-autoloads (file args
)
341 "Update the autoloads for FILE in current buffer.
342 Return FILE if there was no autoload cookie in it, else nil.
344 Current buffer must be a loaddef-style file.
346 LOAD-NAME is the absolute name of the file.
347 RELATIVE-NAME is its name respective to some component of load-path."
355 (goto-char (point-min))
356 ;; Look for the section for FILE
357 (while (and (not found
)
358 (search-forward generate-autoload-section-header nil t
))
359 (let ((form (autoload-read-section-header)))
361 ((equal (nth 2 form
) file
)
362 ;; We found the section for this file.
363 (let ((begin (match-beginning 0)))
365 (search-forward generate-autoload-section-trailer
)
366 (delete-region begin
(point))
368 ((string< file
(nth 2 form
))
369 ;; We've come to a section alphabetically later than
370 ;; FILE. We assume the file is in order and so
371 ;; there must be no section for FILE. We will
372 ;; insert one before the section here.
373 (goto-char (match-beginning 0))
374 (setq found
'new
)))))
378 ;; No later sections in the file. Put before the last page.
379 (goto-char (point-max))
380 (search-backward "\f" nil t
)))
382 (apply #'elinstall-generate-file-autoloads
385 (if no-autoloads file nil
)))
386 ;;;_ . Arranging to add to info-path and load-path
387 ;;;_ , elinstall-generate-add-to-path
388 (defun elinstall-generate-add-to-path (path-element type
)
389 "Insert code at point to add PATH-ELEMENT to a path.
391 * `add-to-load-path', add to load-path
392 * `add-to-info-path', add to Info-additional-directory-list
394 Current buffer must be a loaddef-style file."
397 (add-to-load-path 'load-path
)
398 (add-to-info-path 'Info-additional-directory-list
)
399 (t (error "Type not recognized"))))
402 (add-to-load-path "load-path")
403 (add-to-info-path "info-path")))
407 ;; This does something in Lucid Emacs.
409 (float-output-format nil
))
411 (message "Generating %s additions..." description
)
413 (elinstall-insert-autoload-section
415 `(add-to-list ',path-symbol
417 ,(file-relative-name path-element
)
420 (file-truename load-file-name
))))))
421 (list type
(list path-element
) nil nil nil
)
423 (message "Generating %s additions...done" description
)))
426 ;;;_ , elinstall-deffile-insert-add-to-path
427 (defun elinstall-deffile-insert-add-to-path (path-element type
)
428 "Insert code in current buffer to add PATH-ELEMENT to a path.
430 * `add-to-load-path', add to load-path
431 * `add-to-info-path', add to Info-default-directory-list
433 Current buffer must be a loaddef-style file."
441 (goto-char (point-min))
442 ;; Look for the section for PATH-ELEMENT
443 (while (and (not found
)
444 (search-forward generate-autoload-section-header nil t
))
445 (let ((form (autoload-read-section-header)))
448 (equal (nth 0 form
) type
)
449 (member path-element
(nth 1 form
)))
451 ;; We found the section for this add.
452 (let ((begin (match-beginning 0)))
454 (search-forward generate-autoload-section-trailer
)
455 (delete-region begin
(point))
461 ;; No later sections in the file. Put before the last page.
462 (goto-char (point-max))
463 (search-backward "\f" nil t
)))
465 (elinstall-generate-add-to-path path-element type
)))
467 ;;This never belongs in the no-autoloads section.
469 ;;;_ . elinstall-deffile-insert
471 (defun elinstall-deffile-insert (action)
472 "Insert autoloads etc into current file according to ACTION.
473 The format of ACTION is described in the design docs.
475 Return filename if this action belongs in the no-autoload section."
480 (elinstall-deffile-insert-autoloads
485 (elinstall-deffile-insert-add-to-path
491 (elinstall-deffile-insert-add-to-path
496 ((preload-file run-tests byte-compile
)
497 (error "This case should not come here.")))))
499 ;;;_ . elinstall-prepare-deffile
500 (defun elinstall-prepare-deffile (deffile)
501 "Try to ensure that DEFFILE is available for receiving autoloads"
503 (autoload-ensure-default-file deffile
)
504 (with-current-buffer (find-file-noselect deffile
)
507 ;; We must read/write the file without any code conversion,
508 ;; but still decode EOLs.
509 (let ((coding-system-for-read 'raw-text
))
511 ;; This is to make generated-autoload-file have Unix EOLs, so
512 ;; that it is portable to all platforms.
513 (setq buffer-file-coding-system
'raw-text-unix
))
514 (or (> (buffer-size) 0)
515 (error "Autoloads file %s does not exist" buffer-file-name
))
516 (or (file-writable-p buffer-file-name
)
517 (error "Autoloads file %s is not writable"
520 ;;;_ . elinstall-update-deffile
522 ;;Adapted from autoload.el `update-directory-autoloads'.
524 (defun elinstall-update-deffile (target actions
&optional
527 Update file TARGET with current autoloads as specified by ACTIONS.
528 Also remove any old definitions pointing to libraries that can no
531 ACTIONS must be a list of actions (See the format doc). Each one's
532 filename must be relative to some element of load-path.
534 USE-LOAD-PATH is a list to use as load-path. It should include
535 any new load-path that we are arranging to create. If it's not given,
536 load-path itself is used.
538 If FORCE is `t', do it regardless of timestamps etc. (Not implemented)
539 Other non-nil cases of FORCE are reserved for future development.
541 This uses `update-file-autoloads' (which see) to do its work.
542 In an interactive call, you must give one argument, the name
543 of a single directory."
546 (use-load-path (or use-load-path load-path
))
547 (this-time (current-time))
548 ;;files with no autoload cookies.
551 (elinstall-prepare-deffile target
)
553 (find-file-noselect target
)
556 (elinstall-remove-autogen-action
557 (autoload-trim-file-name target
)
560 (goto-char (point-min))
561 (while (search-forward generate-autoload-section-header nil t
)
562 (let* ((form (autoload-read-section-header))
564 (cond ((and (consp file
) (stringp (car file
)))
565 ;; This is a list of files that have no
567 ;; There shouldn't be more than one such entry.
568 ;; Remove the obsolete section.
569 (autoload-remove-section (match-beginning 0))
570 (let ((last-time (nth 4 form
)))
572 (let ((file-time (elinstall-file-mod-time file
)))
574 (not (time-less-p last-time file-time
)))
576 (push file no-autoloads
)
578 (elinstall-remove-autogen-action
580 ((not (stringp file
)))
584 (locate-library file nil use-load-path
)))
586 ;;File doesn't exist, so remove its
589 (autoload-remove-section
590 (match-beginning 0)))
592 ;; File hasn't changed, so do nothing.
595 (elinstall-file-mod-time file-path
))
598 (elinstall-deffile-insert
599 (elinstall-get-autogen-action
603 (elinstall-remove-autogen-action
606 ;; Remaining actions have no existing autoload sections yet.
609 (delq nil
(mapcar #'elinstall-deffile-insert actions
))))
611 ;; Sort them for better readability.
612 (setq no-autoloads
(sort no-autoloads
'string
<))
613 ;; Add the `no-autoloads' section.
614 (goto-char (point-max))
615 (search-backward "\f" nil t
)
616 (elinstall-insert-autoload-section
618 (list 'autoloads nil nil no-autoloads this-time
)))
621 ;;;_ . elinstall-stage-update-deffiles
622 (defun elinstall-stage-update-deffiles (segment-list force use-load-path
)
623 "Update any deffiles mentioned in SEGMENT-LIST.
624 FORCE and USE-LOAD-PATH have the same meaning as in
625 `elinstall-update-deffile'.
630 ((deffile (car segment
)))
631 (if (stringp deffile
)
632 (elinstall-update-deffile deffile
(cdr segment
) force
636 ;;;_ , Doing actions to arrange preloads
637 ;;;_ . elinstall-symlink-on-emacs-start
638 (defun elinstall-symlink-on-emacs-start
639 (filename target-basename target-dir
&optional priority force
)
640 "Symlink to TARGET-BASENAME.el in TARGET-DIR
642 If PRIORITY is given, it will be used as the priority prefix,
643 otherwise elinstall-default-priority will be.
644 PRIORITY must be an integer or nil.
645 If FORCE is `t', do it regardless of timestamps etc.
646 Other non-nil cases of FORCE are reserved for future development."
649 (priority (or priority elinstall-default-priority
))
656 (expand-file-name target-name-nodir target-dir
)))
660 ;;Path should already exist.
662 (file-exists-p target-dir
))
663 (message "The target directory doesn't exist."))
664 ;;Target shouldn't already exist, but if force is given, let
666 ;;$$IMPROVE ME If it is a symlink pointing to the same place,
667 ;;do nothing even on force.
669 (file-exists-p target
)
674 (format "Really overwrite %s? " target
))))
675 (message "File %s already exists" target
)))
683 ;;;_ . elinstall-add-to-dot-emacs
684 (defun elinstall-add-to-dot-emacs (dot-emacs-name filename force
&rest r
)
685 "Add code to load FILENAME to .emacs.
686 FILENAME should not have an extension"
689 (with-current-buffer (find-file-noselect dot-emacs-name
)
692 (goto-char (point-max))
693 (insert "\n;;Added by elinstall")
694 (insert "\n;;Consider using my-site-start to manage .emacs\n")
695 (pp `(load ,filename
) (current-buffer))
699 ;;;_ . elinstall-arrange-preload
701 (defun elinstall-arrange-preload (force filename basename
&optional priority
)
702 "Arrange for FILENAME to be loaded on emacs start.
703 FORCE has its usual meaning.
704 BASENAME and PRIORITY are used as arguments to
705 `elinstall-symlink-on-emacs-start'.
709 ((preload-target elinstall-default-preload-target
))
711 ;;Dispatch the possibilities.
713 ((eq preload-target
'dot-emacs
)
714 (elinstall-add-to-dot-emacs "~/.emacs" filename force
))
715 ((stringp preload-target
)
716 (elinstall-symlink-on-emacs-start
717 filename basename preload-target priority force
))
718 ((null preload-target
)
719 (message "Not arranging for preloads"))
721 (message "I don't recognize that")))))
722 ;;;_ . elinstall-stage-arrange-preloads
723 (defun elinstall-stage-arrange-preloads (actions deffiles-used force
)
724 "Arrange any preloads mentioned in ACTIONS."
738 (member filename deffiles-used
)))))
742 #'elinstall-arrange-preload
747 "elinstall-stage-arrange-preloads: Action not
753 ;;;_ . elinstall-stage-run-tests
754 (defun elinstall-stage-run-tests (actions)
755 "Run any tests mentioned in ACTIONS."
761 ;;$$WRITE ME - not a high priority right now.
765 "elinstall-stage-run-tests: Action not
771 ;;;_ . elinstall-stage-byte-compile
772 (defun elinstall-stage-byte-compile (actions)
773 "Do any byte-compilation mentioned in ACTIONS."
778 ;;$$IMPROVE ME Understand flags to control second
779 ;;argument (whether to load file after
782 (byte-compile-file (second act
)))
785 "elinstall-stage-byte-compile: Action not
788 ;;;_ . Segregating actions
789 ;;;_ , elinstall-remove-empty-segs
790 (defun elinstall-remove-empty-segs (segment-list)
791 "Return SEGMENT-LIST minus any segments that have no actions.
792 Intended only for the deffile stage data."
801 ;;;_ , elinstall-segregate-actions
802 (defun elinstall-segregate-actions (actions)
803 "Return actions segregated by deffile.
805 Returns a list whose elements are each a cons of:
806 * deffile filename or nil
807 * A list of actions to be done for that deffile."
814 (arrange-preloads '()))
816 (dolist (act actions
)
823 ((deffile-name (second act
))
825 (assoc deffile-name build-deffiles
)))
827 ;;There are already actions on this deffile.
828 ;;Splice this action in.
830 (cons act
(cdr cell-already
)))
831 ;;There are no actions on this deffile. Add a
832 ;;place for them and include this action.
833 (push (list deffile-name act
) build-deffiles
))))
835 (push act arrange-preloads
))
837 (push act run-tests
))
839 (push act byte-compile
)))))
841 (elinstall-make-stages
843 (elinstall-remove-empty-segs build-deffiles
)
850 ;;;_ . Finding actions
852 ;;;_ . elinstall-dir-has-info
854 ;;$$IMPROVE ME - Can this test be made more precise?
855 (defun elinstall-dir-has-info (dir)
856 "Return non-nil if DIR has info files in it.
857 DIR should be an absolute path."
859 (string-match "/info/" dir
)
860 (directory-files dir nil
"\\.info\\(-[0-9]+\\)?\\(\\.gz\\)?$")))
863 ;;;_ . List of special variables used in this section
864 ;;load-path-element - The relevant element of load-path
865 ;;def-file - The file the autoload definitions etc will go into.
866 ;;add-to-load-path-p - Controls whether to add to load-path.
867 ;;recurse-dirs-p - Whether to recurse into subdirectories.
868 (defconst elinstall-find-actions-control-vars
869 '(add-to-load-path-p recurse-dirs-p compile-p force-recompile-p
)
870 "Control special variables that the find-actions tree recognizes" )
871 ;;;_ . elinstall-actions-for-source-file
872 (defun elinstall-actions-for-source-file (filename dir
)
873 "Return a list of actions to do for FILENAME in DIR.
874 Special variables are as noted in \"List of special variables\"."
876 load-path-element def-file compile-p force-recompile-p
))
879 (expand-file-name filename dir
)))
882 (file-readable-p full-path
)
883 (not (auto-save-file-name-p full-path
)))
884 ;;$$IMPROVE ME create and use relevant control variables.
887 (visited (get-file-buffer full-path
))
891 ;;Visit the file cheaply.
892 ;;hack-local-variables can give errors.
893 (ignore-errors (autoload-find-file full-path
))))
897 (with-current-buffer buf
898 (if (local-variable-p 'generated-autoload-file
)
899 (elinstall-expand-deffile-name
900 generated-autoload-file
)
903 ;;Figure out whether to run some actions, by file local vars.
906 (with-current-buffer buf
907 (not no-update-autoloads
))))
910 (featurep 'byte-compile
)
911 (string-match emacs-lisp-file-regexp filename
)
913 (with-current-buffer buf
914 (not no-byte-compile
)))
916 ((dest (byte-compile-dest-file full-path
)))
917 (if (file-exists-p dest
)
918 ;; File was already compiled.
919 (or force-recompile-p
920 (file-newer-than-file-p full-path dest
))
922 (y-or-n-p (concat "Compile " filename
"? "))))))))
927 `(byte-compile ,full-path
)
930 (elinstall-make-autoload-action
931 buf def-file load-path-element full-path
)
933 (unless visited
(kill-buffer-if-not-modified buf
)))))))
934 ;;;_ . elinstall-actions-for-dir
935 (defun elinstall-actions-for-dir (dirname &optional recurse-dirs-p
)
936 "Make actions for DIR.
937 Recurse just if RECURSE-DIRS-P"
939 load-path-element def-file add-to-load-path-p
))
940 ;;This does not treat symlinks specially. $$IMPROVE ME it could
941 ;;treat/not treat them conditional on control variables.
944 ;;Relative filenames of the source files. We know our
945 ;;loaddefs.el isn't really source so remove it. We'd have
946 ;;removed it anyways after seeing file local vars.
953 elinstall-elisp-regexp
)))
954 ;;Absolute filenames of subdirectories.
955 ;;Don't accept any directories beginning with dot. If user
956 ;;really wants to explore one he can use `(dir ".NAME")'.
963 (file-directory-p filename
)
973 elisp-source-files
;;If list is not empty.
981 ;;Sometimes arrange to add this directory to load-path.
988 ;;$$IMPROVE ME - be controlled by a control variable.
989 ;;Sometimes add this directory to info path.
991 (elinstall-dir-has-info dirname
)
1000 (elinstall-actions-for-source-file
1003 elisp-source-files
))
1008 #'(lambda (filename)
1009 (elinstall-find-actions-by-spec-x
1017 ;;;_ . elinstall-find-actions-by-spec-x
1019 (defun elinstall-find-actions-by-spec-x (spec dir
)
1020 "Return a list of actions to do, controlled by SPEC."
1022 load-path-element def-file add-to-load-path-p
1031 #'(lambda (sub-spec)
1032 (elinstall-find-actions-by-spec-x
1037 ;;Rather than trying to bind all control variables each time
1038 ;;thru, we use `set' and `unwind-protect'.
1040 ;;control TYPE DISPOSITION SPEC
1042 ((key (second spec
))
1044 (if (memq key elinstall-find-actions-control-vars
)
1047 (set old-value
(symbol-value key
))
1048 (set key
(third spec
))
1049 (elinstall-find-actions-by-spec-x
1052 (set key old-value
))
1053 (error "Unrecognized control variable %s" key
))))
1057 ;;(def-file FN ARGS SPEC)
1063 (for-preload (third spec
)))
1064 (assert (listp for-preload
))
1068 (and for-preload
(car for-preload
))
1072 ,@(cdr for-preload
))
1075 (elinstall-find-actions-by-spec-x
1076 (fourth spec
) dir
))))
1080 (elinstall-actions-for-dir
1088 (elinstall-actions-for-source-file
1099 (elinstall-find-actions-by-spec-x
1106 `((add-to-load-path ,def-file
,dir
))
1108 ((load-path-element dir
)
1109 (add-to-load-path-p nil
))
1110 (elinstall-find-actions-by-spec-x
1115 ;;(matching PATTERN SPEC)
1119 (elinstall-find-actions-by-spec-x
1123 dir t
(second spec
)))))
1125 ;;(preload FN SYM &rest ARGS)
1127 ((key (third spec
)))
1129 (and (symbolp key
) (symbol-value key
))
1132 ,(expand-file-name (second spec
) dir
)
1139 (elinstall-actions-for-dir dir nil
))
1141 (elinstall-actions-for-dir dir t
)))))
1143 ;;;_ . elinstall-find-actions-by-spec
1144 (defun elinstall-find-actions-by-spec
1145 (spec load-path-element dir def-file redo-old
)
1146 "Find the list of actions to do according to SPEC."
1150 (def-file-time (elinstall-file-mod-time def-file
))
1151 (add-to-load-path-p t
)
1153 (force-recompile-p nil
)
1156 load-path-element def-file add-to-load-path-p
1157 recurse-dirs-p force-recompile-p compile-p
))
1159 (elinstall-find-actions-by-spec-x spec dir
)))
1161 ;;;_ . high-level work
1162 ;;;_ , elinstall-get-relevant-load-path
1163 (defun elinstall-get-relevant-load-path (actions)
1173 ;;;_ , elinstall-get-deffile-list
1174 (defun elinstall-get-deffile-list (stages)
1175 "Get a list of deffile names"
1179 (elinstall-stages->build-deffiles stages
)))
1181 (defun elinstall-x (dir spec
&optional force
)
1182 "High-level worker function to install elisp files."
1185 ;;This is just the default deffile, spec can override it.
1187 (elinstall-expand-deffile-name nil
))
1189 (elinstall-find-actions-by-spec
1194 (eq force
'redo-old
)))
1195 (stages (elinstall-segregate-actions actions
))
1197 (elinstall-get-relevant-load-path
1200 (elinstall-stage-update-deffiles
1201 (elinstall-stages->build-deffiles stages
)
1204 (elinstall-stage-arrange-preloads
1205 (elinstall-stages->arrange-preloads stages
)
1206 (elinstall-get-deffile-list stages
)
1208 (elinstall-stage-byte-compile
1209 (elinstall-stages->byte-compile stages
))
1214 (defun elinstall (project-name path spec
&optional force version-string
)
1215 "Install elisp files.
1216 They need not be a formal package.
1220 PROJECT-NAME - the name of the project
1222 PATH - Path to the project.
1223 Suggestion: (elinstall-directory-true-name)
1225 SPEC - a spec for the autoloads etc to make. It can be as simple as
1226 \(dir \"\.\") for installing one directory.
1228 If FORCE is t, install a package even if it has already been
1229 installed. Other non-nil cases of FORCE are reserved for future
1235 (not (elinstall-already-installed project-name
))
1236 (yes-or-no-p (format "Re-install %s? " project-name
)))
1239 `(def-file "loaddefs.el" (if-used ,project-name
) ,spec
)
1241 (elinstall-record-installed project-name version-string
)))
1245 ;;;_ . elinstall-update-directory-autoloads
1247 ;;The control variables and values of `force' that would stop other
1248 ;;actions don't exist yet. Similarly for
1249 ;;`elinstall-update-file-autoloads'.
1251 (defun elinstall-update-directory-autoloads (dir)
1252 "Update autoloads for directory DIR"
1254 (interactive "DUpdate autoloads for all elisp files from directory: ")
1257 `(control compile-p nil
1260 ;;;_ . elinstall-update-directory
1262 (defun elinstall-update-directory (dir)
1263 "Update autoloads for directory DIR"
1265 (interactive "DInstall all elisp files from directory: ")
1270 ;;;_ . elinstall-update-file-autoloads
1272 (defun elinstall-update-file-autoloads (file)
1273 "Update autoloads for elisp file FILE"
1275 (interactive "fUpdate autoloads for elisp file: ")
1277 (file-name-directory file
)
1278 `(control compile-p nil
1279 (file ,(file-name-nondirectory file
)))))
1281 ;;;_ . elinstall-update-file
1283 (defun elinstall-update-file (file)
1284 "Install elisp file FILE"
1286 (interactive "fInstall elisp file: ")
1288 (file-name-directory file
)
1289 `(file ,(file-name-nondirectory file
))))
1294 (provide 'elinstall
)
1296 ;;;_ * Local emacs vars.
1297 ;;;_ + Local variables:
1302 ;;; elinstall.el ends here