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
81 ;;;_ . elinstall-stages
82 (defstruct (elinstall-stages
83 (:constructor elinstall-make-stages
)
84 (:conc-name elinstall-stages-
>)
86 "The elinstall stages"
92 ;;;_ . Regular expressions
93 ;;;_ , elinstall-elisp-regexp
94 (defconst elinstall-elisp-regexp
97 (suf (get-load-suffixes))
98 (unless (string-match "\\.elc" suf
) (push suf tmp
)))
99 (concat "^[^=.].*" (regexp-opt tmp t
) "\\'"))
100 "Regular expression that matches elisp files" )
102 ;;;_ . elinstall-file-mod-time
103 (defsubst elinstall-file-mod-time
(file)
104 "Return the modification time of FILE"
105 (nth 5 (file-attributes file
)))
107 ;;;_ . elinstall-directory-true-name
108 (defun elinstall-directory-true-name ()
109 "Get the true name of the directory the calling code lives in.
110 CAUTION: This is sensitive to where it's called. That's the point of it."
113 (file-truename load-file-name
)
114 (file-truename buffer-file-name
))))
115 ;;;_ . Checking installedness
116 ;;;_ , elinstall-get-installation-record
117 (defun elinstall-get-installation-record (project-name)
118 "Return the installation record for PROJECT-NAME."
120 (assoc project-name elinstall-already-installed
))
122 ;;;_ , elinstall-already-installed
123 (defun elinstall-already-installed (project-name)
124 "Return non-nil if PROJECT-NAME has been installed."
125 (elinstall-get-installation-record project-name
))
127 ;;;_ , elinstall-record-installed
128 (defun elinstall-record-installed (project-name &optional version
)
129 "Record that PROJECT-NAME has been installed."
138 (elinstall-get-installation-record project-name
))
142 (setq elinstall-already-installed
143 (delete old-item elinstall-already-installed
)))
144 (push new-item elinstall-already-installed
)
145 (customize-save-variable
146 'elinstall-already-installed
147 elinstall-already-installed
148 "Set by elinstall-record-installed")))
149 ;;;_ . Finding deffiles
150 ;;;_ , elinstall-expand-deffile-name
151 (defun elinstall-expand-deffile-name (deffile)
152 "Expand DEFFILE autoload.el's way."
154 (expand-file-name (or deffile
"loaddefs.el")
155 (expand-file-name "lisp"
161 ;;;_ , Doing autoload actions (adapted from autoload.el)
162 ;;;_ . Utilities about the action list
163 ;;;_ , elinstall-remove-autogen-action
164 (defun elinstall-remove-autogen-action (file actions
)
165 "Return ACTIONS minus any add-file-autoloads on FILE removed."
172 (if (equal file
(third act
))
177 ;;;_ , elinstall-get-autogen-action
178 (defun elinstall-get-autogen-action (file actions
)
182 (dolist (act actions
)
185 (when (equal file
(third act
))
186 (setq the-act act
)))))
188 ;;;_ . About printing to autoload file
189 ;;;_ , elinstall-insert-section-header
190 (defun elinstall-insert-section-header (outbuf form
)
191 "Insert the section-header line,
192 which lists the file name and which functions are in it, etc."
193 (insert generate-autoload-section-header
)
196 ;; Break that line at spaces, to avoid very long lines.
197 ;; Make each sub-line into a comment.
198 (with-current-buffer outbuf
203 (skip-chars-forward "^ \n")
205 (insert "\n" generate-autoload-section-continuation
))))))
207 ;;;_ , elinstall-insert-autoload-section
208 (defun elinstall-insert-autoload-section (text form
&optional comment-string
)
209 "Insert TEXT into current buffer as an autoload section"
214 ;; This does something in Lucid Emacs.
216 (float-output-format nil
))
218 (elinstall-insert-section-header (current-buffer) form
)
220 (insert ";;; " comment-string
"\n"))
222 (insert generate-autoload-section-trailer
)))
224 ;;;_ . Making autoloads
225 ;;;_ , elinstall-make-autoload-action
226 (defun elinstall-make-autoload-action (buf def-file load-path-element full-path
)
227 "Return the autoloads for current buffer as a string"
229 ;;We put all the text into a temp buffer, then get that buffer's
233 (generate-new-buffer " *temp*"))
236 (file-name-nondirectory full-path
))
240 ;; Apparently this does something in Lucid Emacs.
242 (float-output-format nil
)
244 ;;load-name relative to a member of load-path.
246 (file-name-sans-extension
249 load-path-element
))))
251 (with-current-buffer buf
256 (goto-char (point-min))
257 (message "Finding autoloads for %s..." short-name
)
259 (skip-chars-forward " \t\n\f")
261 ((looking-at (regexp-quote generate-autoload-cookie
))
262 (search-forward generate-autoload-cookie
)
263 (skip-chars-forward " \t")
265 ;; Read the next form and make an autoload.
266 (let* ((form (prog1 (read (current-buffer))
267 (or (bolp) (forward-line 1))))
269 (make-autoload form relative-name
)))
271 (push (nth 1 form
) autoloads-done
)
272 (setq autoload form
))
273 (let ((autoload-print-form-outbuf outbuf
))
274 (autoload-print-form autoload
)))
276 ;; Copy the rest of the line to the output.
277 (princ (buffer-substring
279 ;; Back up over whitespace,
281 (skip-chars-backward " \f\t")
282 (if (= (char-after (1+ (point))) ?
)
286 (progn (forward-line 1) (point)))
289 ;; Don't read the comment.
294 (message "Finding autoloads for %s...done" short-name
))
296 ;;Return this action. The temp buffer's contents is
302 ,(with-current-buffer outbuf
(buffer-string))
305 ;;This in unwind-protected
306 (when (buffer-live-p outbuf
) (kill-buffer outbuf
))))))
309 ;;;_ , elinstall-generate-file-autoloads
311 (defun elinstall-generate-file-autoloads
312 (relative-name full-name text autoloads-done
)
313 "Insert at point a loaddefs autoload section for FILE.
314 Autoloads are generated for defuns and defmacros in FILE
315 marked by `generate-autoload-cookie' (which see).
316 If FILE is being visited in a buffer, the contents of the buffer
318 Return non-nil in the case where no autoloads were added at point.
320 FULL-NAME is the absolute name of the file.
321 RELATIVE-NAME is its name respective to some component of load-path."
322 (if (not (equal text
""))
323 ;; Insert the section-header line which lists the file name and
324 ;; which functions are in it, etc.
325 (elinstall-insert-autoload-section
330 (autoload-trim-file-name full-name
)
331 (elinstall-file-mod-time full-name
))
333 "Generated autoloads from "
334 (autoload-trim-file-name full-name
)))
337 ;;;_ , elinstall-deffile-insert-autoloads
338 (defun elinstall-deffile-insert-autoloads (file args
)
339 "Update the autoloads for FILE in current buffer.
340 Return FILE if there was no autoload cookie in it, else nil.
342 Current buffer must be a loaddef-style file.
344 LOAD-NAME is the absolute name of the file.
345 RELATIVE-NAME is its name respective to some component of load-path."
353 (goto-char (point-min))
354 ;; Look for the section for FILE
355 (while (and (not found
)
356 (search-forward generate-autoload-section-header nil t
))
357 (let ((form (autoload-read-section-header)))
359 ((equal (nth 2 form
) file
)
360 ;; We found the section for this file.
361 (let ((begin (match-beginning 0)))
363 (search-forward generate-autoload-section-trailer
)
364 (delete-region begin
(point))
366 ((string< file
(nth 2 form
))
367 ;; We've come to a section alphabetically later than
368 ;; FILE. We assume the file is in order and so
369 ;; there must be no section for FILE. We will
370 ;; insert one before the section here.
371 (goto-char (match-beginning 0))
372 (setq found
'new
)))))
376 ;; No later sections in the file. Put before the last page.
377 (goto-char (point-max))
378 (search-backward "\f" nil t
)))
380 (apply #'elinstall-generate-file-autoloads
383 (if no-autoloads file nil
)))
384 ;;;_ . Arranging to add to info-path and load-path
385 ;;;_ , elinstall-generate-add-to-path
386 (defun elinstall-generate-add-to-path (path-element type
)
387 "Insert code at point to add PATH-ELEMENT to a path.
389 * `add-to-load-path', add to load-path
390 * `add-to-info-path', add to Info-additional-directory-list
392 Current buffer must be a loaddef-style file."
395 (add-to-load-path 'load-path
)
396 (add-to-info-path 'Info-additional-directory-list
)
397 (t (error "Type not recognized"))))
400 (add-to-load-path "load-path")
401 (add-to-info-path "info-path")))
405 ;; This does something in Lucid Emacs.
407 (float-output-format nil
))
409 (message "Generating %s additions..." description
)
411 (elinstall-insert-autoload-section
413 `(add-to-list ',path-symbol
415 ,(file-relative-name path-element
)
418 (file-truename load-file-name
))))))
419 (list type
(list path-element
) nil nil nil
)
421 (message "Generating %s additions...done" description
)))
424 ;;;_ , elinstall-deffile-insert-add-to-path
425 (defun elinstall-deffile-insert-add-to-path (path-element type
)
426 "Insert code in current buffer to add PATH-ELEMENT to a path.
428 * `add-to-load-path', add to load-path
429 * `add-to-info-path', add to Info-default-directory-list
431 Current buffer must be a loaddef-style file."
439 (goto-char (point-min))
440 ;; Look for the section for PATH-ELEMENT
441 (while (and (not found
)
442 (search-forward generate-autoload-section-header nil t
))
443 (let ((form (autoload-read-section-header)))
446 (equal (nth 0 form
) type
)
447 (member path-element
(nth 1 form
)))
449 ;; We found the section for this add.
450 (let ((begin (match-beginning 0)))
452 (search-forward generate-autoload-section-trailer
)
453 (delete-region begin
(point))
459 ;; No later sections in the file. Put before the last page.
460 (goto-char (point-max))
461 (search-backward "\f" nil t
)))
463 (elinstall-generate-add-to-path path-element type
)))
465 ;;This never belongs in the no-autoloads section.
467 ;;;_ . elinstall-deffile-insert
469 (defun elinstall-deffile-insert (action)
470 "Insert autoloads etc into current file according to ACTION.
471 The format of ACTION is described in the design docs.
473 Return filename if this action belongs in the no-autoload section."
478 (elinstall-deffile-insert-autoloads
483 (elinstall-deffile-insert-add-to-path
489 (elinstall-deffile-insert-add-to-path
494 ((preload-file run-tests byte-compile
)
495 (error "This case should not come here.")))))
497 ;;;_ . elinstall-prepare-deffile
498 (defun elinstall-prepare-deffile (deffile)
499 "Try to ensure that DEFFILE is available for receiving autoloads"
501 (autoload-ensure-default-file deffile
)
502 (with-current-buffer (find-file-noselect deffile
)
505 ;; We must read/write the file without any code conversion,
506 ;; but still decode EOLs.
507 (let ((coding-system-for-read 'raw-text
))
509 ;; This is to make generated-autoload-file have Unix EOLs, so
510 ;; that it is portable to all platforms.
511 (setq buffer-file-coding-system
'raw-text-unix
))
512 (or (> (buffer-size) 0)
513 (error "Autoloads file %s does not exist" buffer-file-name
))
514 (or (file-writable-p buffer-file-name
)
515 (error "Autoloads file %s is not writable"
518 ;;;_ . elinstall-update-deffile
520 ;;Adapted from autoload.el `update-directory-autoloads'.
522 (defun elinstall-update-deffile (target actions
&optional
525 Update file TARGET with current autoloads as specified by ACTIONS.
526 Also remove any old definitions pointing to libraries that can no
529 ACTIONS must be a list of actions (See the format doc). Each one's
530 filename must be relative to some element of load-path.
532 USE-LOAD-PATH is a list to use as load-path. It should include
533 any new load-path that we are arranging to create. If it's not given,
534 load-path itself is used.
536 If FORCE is `t', do it regardless of timestamps etc. (Not implemented)
537 Other non-nil cases of FORCE are reserved for future development.
539 This uses `update-file-autoloads' (which see) to do its work.
540 In an interactive call, you must give one argument, the name
541 of a single directory."
544 (use-load-path (or use-load-path load-path
))
545 (this-time (current-time))
546 ;;files with no autoload cookies.
549 (elinstall-prepare-deffile target
)
551 (find-file-noselect target
)
554 (elinstall-remove-autogen-action
555 (autoload-trim-file-name target
)
558 (goto-char (point-min))
559 (while (search-forward generate-autoload-section-header nil t
)
560 (let* ((form (autoload-read-section-header))
562 (cond ((and (consp file
) (stringp (car file
)))
563 ;; This is a list of files that have no
565 ;; There shouldn't be more than one such entry.
566 ;; Remove the obsolete section.
567 (autoload-remove-section (match-beginning 0))
568 (let ((last-time (nth 4 form
)))
570 (let ((file-time (elinstall-file-mod-time file
)))
572 (not (time-less-p last-time file-time
)))
574 (push file no-autoloads
)
576 (elinstall-remove-autogen-action
578 ((not (stringp file
)))
582 (locate-library file nil use-load-path
)))
584 ;;File doesn't exist, so remove its
587 (autoload-remove-section
588 (match-beginning 0)))
590 ;; File hasn't changed, so do nothing.
593 (elinstall-file-mod-time file-path
))
596 (elinstall-deffile-insert
597 (elinstall-get-autogen-action
601 (elinstall-remove-autogen-action
604 ;; Remaining actions have no existing autoload sections yet.
607 (delq nil
(mapcar #'elinstall-deffile-insert actions
))))
609 ;; Sort them for better readability.
610 (setq no-autoloads
(sort no-autoloads
'string
<))
611 ;; Add the `no-autoloads' section.
612 (goto-char (point-max))
613 (search-backward "\f" nil t
)
614 (elinstall-insert-autoload-section
616 (list 'autoloads nil nil no-autoloads this-time
)))
619 ;;;_ . elinstall-stage-update-deffiles
620 (defun elinstall-stage-update-deffiles (segment-list force use-load-path
)
621 "Update any deffiles mentioned in SEGMENT-LIST.
622 FORCE and USE-LOAD-PATH have the same meaning as in
623 `elinstall-update-deffile'.
628 ((deffile (car segment
)))
629 (if (stringp deffile
)
630 (elinstall-update-deffile deffile
(cdr segment
) force
634 ;;;_ , Doing actions to arrange preloads
635 ;;;_ . elinstall-symlink-on-emacs-start
636 (defun elinstall-symlink-on-emacs-start
637 (filename target-basename target-dir
&optional priority force
)
638 "Symlink to TARGET-BASENAME.el in TARGET-DIR
640 If PRIORITY is given, it will be used as the priority prefix,
641 otherwise elinstall-default-priority will be.
642 PRIORITY must be an integer or nil.
643 If FORCE is `t', do it regardless of timestamps etc.
644 Other non-nil cases of FORCE are reserved for future development."
647 (priority (or priority elinstall-default-priority
))
654 (expand-file-name target-name-nodir target-dir
)))
658 ;;Path should already exist.
660 (file-exists-p target-dir
))
661 (message "The target directory doesn't exist."))
662 ;;Target shouldn't already exist, but if force is given, let
664 ;;$$IMPROVE ME If it is a symlink pointing to the same place,
665 ;;do nothing even on force.
667 (file-exists-p target
)
672 (format "Really overwrite %s? " target
))))
673 (message "File %s already exists" target
)))
681 ;;;_ . elinstall-add-to-dot-emacs
682 (defun elinstall-add-to-dot-emacs (dot-emacs-name filename force
&rest r
)
683 "Add code to load FILENAME to .emacs.
684 FILENAME should not have an extension"
687 (with-current-buffer (find-file-noselect dot-emacs-name
)
690 (goto-char (point-max))
691 (insert "\n;;Added by elinstall")
692 (insert "\n;;Consider using my-site-start to manage .emacs\n")
693 (pp `(load ,filename
) (current-buffer))
697 ;;;_ . elinstall-arrange-preload
699 (defun elinstall-arrange-preload (force filename basename
&optional priority
)
700 "Arrange for FILENAME to be loaded on emacs start.
701 FORCE has its usual meaning.
702 BASENAME and PRIORITY are used as arguments to
703 `elinstall-symlink-on-emacs-start'.
707 ((preload-target elinstall-default-preload-target
))
709 ;;Dispatch the possibilities.
711 ((eq preload-target
'dot-emacs
)
712 (elinstall-add-to-dot-emacs "~/.emacs" filename force
))
713 ((stringp preload-target
)
714 (elinstall-symlink-on-emacs-start
715 filename basename preload-target priority force
))
716 ((null preload-target
)
717 (message "Not arranging for preloads"))
719 (message "I don't recognize that")))))
720 ;;;_ . elinstall-stage-arrange-preloads
721 (defun elinstall-stage-arrange-preloads (actions deffiles-used force
)
722 "Arrange any preloads mentioned in ACTIONS."
736 (member filename deffiles-used
)))))
740 #'elinstall-arrange-preload
745 "elinstall-stage-arrange-preloads: Action not
751 ;;;_ . elinstall-stage-run-tests
752 (defun elinstall-stage-run-tests (actions)
753 "Run any tests mentioned in ACTIONS."
759 ;;$$WRITE ME - not a high priority right now.
763 "elinstall-stage-run-tests: Action not
769 ;;;_ . elinstall-stage-byte-compile
770 (defun elinstall-stage-byte-compile (actions)
771 "Do any byte-compilation mentioned in ACTIONS."
776 ;;$$IMPROVE ME Understand flags to control second
777 ;;argument (whether to load file after
780 (byte-compile-file (second act
)))
783 "elinstall-stage-byte-compile: Action not
786 ;;;_ . Segregating actions
787 ;;;_ , elinstall-remove-empty-segs
788 (defun elinstall-remove-empty-segs (segment-list)
789 "Return SEGMENT-LIST minus any segments that have no actions.
790 Intended only for the deffile stage data."
799 ;;;_ , elinstall-segregate-actions
800 (defun elinstall-segregate-actions (actions)
801 "Return actions segregated by deffile.
803 Returns a list whose elements are each a cons of:
804 * deffile filename or nil
805 * A list of actions to be done for that deffile."
812 (arrange-preloads '()))
814 (dolist (act actions
)
821 ((deffile-name (second act
))
823 (assoc deffile-name build-deffiles
)))
825 ;;There are already actions on this deffile.
826 ;;Splice this action in.
828 (cons act
(cdr cell-already
)))
829 ;;There are no actions on this deffile. Add a
830 ;;place for them and include this action.
831 (push (list deffile-name act
) build-deffiles
))))
833 (push act arrange-preloads
))
835 (push act run-tests
))
837 (push act byte-compile
)))))
839 (elinstall-make-stages
841 (elinstall-remove-empty-segs build-deffiles
)
848 ;;;_ . Finding actions
850 ;;;_ . elinstall-dir-has-info
852 ;;$$IMPROVE ME - Can this test be made more precise?
853 (defun elinstall-dir-has-info (dir)
854 "Return non-nil if DIR has info files in it.
855 DIR should be an absolute path."
857 (string-match "/info/" dir
)
858 (directory-files dir nil
"\\.info\\(-[0-9]+\\)?\\(\\.gz\\)?$")))
861 ;;;_ . List of special variables used in this section
862 ;;load-path-element - The relevant element of load-path
863 ;;def-file - The file the autoload definitions etc will go into.
864 ;;add-to-load-path-p - Controls whether to add to load-path.
865 ;;recurse-dirs-p - Whether to recurse into subdirectories.
866 (defconst elinstall-find-actions-control-vars
867 '(add-to-load-path-p recurse-dirs-p compile-p force-recompile-p
)
868 "Control special variables that the find-actions tree recognizes" )
869 ;;;_ . elinstall-actions-for-source-file
870 (defun elinstall-actions-for-source-file (filename dir
)
871 "Return a list of actions to do for FILENAME in DIR.
872 Special variables are as noted in \"List of special variables\"."
874 load-path-element def-file compile-p force-recompile-p
))
877 (expand-file-name filename dir
)))
880 (file-readable-p full-path
)
881 (not (auto-save-file-name-p full-path
)))
882 ;;$$IMPROVE ME create and use relevant control variables.
885 (visited (get-file-buffer full-path
))
889 ;;Visit the file cheaply.
890 ;;hack-local-variables can give errors.
891 (ignore-errors (autoload-find-file full-path
))))
895 (with-current-buffer buf
896 (if (local-variable-p 'generated-autoload-file
)
897 (elinstall-expand-deffile-name
898 generated-autoload-file
)
901 ;;Figure out whether to run some actions, by file local vars.
904 (with-current-buffer buf
905 (not no-update-autoloads
))))
908 (featurep 'byte-compile
)
909 (string-match emacs-lisp-file-regexp filename
)
911 (with-current-buffer buf
912 (not no-byte-compile
)))
914 ((dest (byte-compile-dest-file full-path
)))
915 (if (file-exists-p dest
)
916 ;; File was already compiled.
917 (or force-recompile-p
918 (file-newer-than-file-p full-path dest
))
920 (y-or-n-p (concat "Compile " filename
"? "))))))))
925 `(byte-compile ,full-path
)
928 (elinstall-make-autoload-action
929 buf def-file load-path-element full-path
)
931 (unless visited
(kill-buffer-if-not-modified buf
)))))))
932 ;;;_ . elinstall-actions-for-dir
933 (defun elinstall-actions-for-dir (dirname &optional recurse-dirs-p
)
934 "Make actions for DIR.
935 Recurse just if RECURSE-DIRS-P"
937 load-path-element def-file add-to-load-path-p
))
938 ;;This does not treat symlinks specially. $$IMPROVE ME it could
939 ;;treat/not treat them conditional on control variables.
942 ;;Relative filenames of the source files. We know our
943 ;;loaddefs.el isn't really source so remove it. We'd have
944 ;;removed it anyways after seeing file local vars.
951 elinstall-elisp-regexp
)))
952 ;;Absolute filenames of subdirectories.
953 ;;Don't accept any directories beginning with dot. If user
954 ;;really wants to explore one he can use `(dir ".NAME")'.
961 (file-directory-p filename
)
971 elisp-source-files
;;If list is not empty.
979 ;;Sometimes arrange to add this directory to load-path.
986 ;;$$IMPROVE ME - be controlled by a control variable.
987 ;;Sometimes add this directory to info path.
989 (elinstall-dir-has-info dirname
)
998 (elinstall-actions-for-source-file
1001 elisp-source-files
))
1006 #'(lambda (filename)
1007 (elinstall-find-actions-by-spec-x
1015 ;;;_ . elinstall-find-actions-by-spec-x
1017 (defun elinstall-find-actions-by-spec-x (spec dir
)
1018 "Return a list of actions to do, controlled by SPEC."
1020 load-path-element def-file add-to-load-path-p
1029 #'(lambda (sub-spec)
1030 (elinstall-find-actions-by-spec-x
1035 ;;Rather than trying to bind all control variables each time
1036 ;;thru, we use `set' and `unwind-protect'.
1038 ;;control TYPE DISPOSITION SPEC
1040 ((key (second spec
))
1042 (if (memq key elinstall-find-actions-control-vars
)
1045 (set old-value
(symbol-value key
))
1046 (set key
(third spec
))
1047 (elinstall-find-actions-by-spec-x
1050 (set key old-value
))
1051 (error "Unrecognized control variable %s" key
))))
1055 ;;(def-file FN ARGS SPEC)
1061 (for-preload (third spec
)))
1062 (assert (listp for-preload
))
1066 (and for-preload
(car for-preload
))
1070 ,@(cdr for-preload
))
1073 (elinstall-find-actions-by-spec-x
1074 (fourth spec
) dir
))))
1078 (elinstall-actions-for-dir
1086 (elinstall-actions-for-source-file
1097 (elinstall-find-actions-by-spec-x
1104 `((add-to-load-path ,def-file
,dir
))
1106 ((load-path-element dir
)
1107 (add-to-load-path-p nil
))
1108 (elinstall-find-actions-by-spec-x
1113 ;;(matching PATTERN SPEC)
1117 (elinstall-find-actions-by-spec-x
1121 dir t
(second spec
)))))
1123 ;;(preload FN SYM &rest ARGS)
1125 ((key (third spec
)))
1127 (and (symbolp key
) (symbol-value key
))
1130 ,(expand-file-name (second spec
) dir
)
1137 (elinstall-actions-for-dir dir nil
))
1139 (elinstall-actions-for-dir dir t
)))))
1141 ;;;_ . elinstall-find-actions-by-spec
1142 (defun elinstall-find-actions-by-spec
1143 (spec load-path-element dir def-file redo-old
)
1144 "Find the list of actions to do according to SPEC."
1148 (def-file-time (elinstall-file-mod-time def-file
))
1149 (add-to-load-path-p t
)
1151 (force-recompile-p nil
)
1154 load-path-element def-file add-to-load-path-p
1155 recurse-dirs-p force-recompile-p compile-p
))
1157 (elinstall-find-actions-by-spec-x spec dir
)))
1159 ;;;_ . high-level work
1160 ;;;_ , elinstall-get-relevant-load-path
1161 (defun elinstall-get-relevant-load-path (actions)
1171 ;;;_ , elinstall-get-deffile-list
1172 (defun elinstall-get-deffile-list (stages)
1173 "Get a list of deffile names"
1177 (elinstall-stages->build-deffiles stages
)))
1179 (defun elinstall-x (dir spec
&optional force
)
1180 "High-level worker function to install elisp files."
1183 ;;This is just the default deffile, spec can override it.
1185 (elinstall-expand-deffile-name nil
))
1187 (elinstall-find-actions-by-spec
1192 (eq force
'redo-old
)))
1193 (stages (elinstall-segregate-actions actions
))
1195 (elinstall-get-relevant-load-path
1198 (elinstall-stage-update-deffiles
1199 (elinstall-stages->build-deffiles stages
)
1202 (elinstall-stage-arrange-preloads
1203 (elinstall-stages->arrange-preloads stages
)
1204 (elinstall-get-deffile-list stages
)
1206 (elinstall-stage-byte-compile
1207 (elinstall-stages->byte-compile stages
))
1212 (defun elinstall (project-name path spec
&optional force version-string
)
1213 "Install elisp files.
1214 They need not be a formal package.
1218 PROJECT-NAME - the name of the project
1220 PATH - Path to the project.
1221 Suggestion: (elinstall-directory-true-name)
1223 SPEC - a spec for the autoloads etc to make. It can be as simple as
1224 \(dir \"\.\") for installing one directory.
1226 If FORCE is t, install a package even if it has already been
1227 installed. Other non-nil cases of FORCE are reserved for future
1233 (not (elinstall-already-installed project-name
))
1234 (yes-or-no-p (format "Re-install %s? " project-name
)))
1237 `(def-file "loaddefs.el" (if-used ,project-name
) ,spec
)
1239 (elinstall-record-installed project-name version-string
)))
1243 ;;;_ . elinstall-update-directory-autoloads
1245 ;;The control variables and values of `force' that would stop other
1246 ;;actions don't exist yet. Similarly for
1247 ;;`elinstall-update-file-autoloads'.
1249 (defun elinstall-update-directory-autoloads (dir)
1250 "Update autoloads for directory DIR"
1252 (interactive "DUpdate autoloads for all elisp files from directory: ")
1255 `(control compile-p nil
1258 ;;;_ . elinstall-update-directory
1260 (defun elinstall-update-directory (dir)
1261 "Update autoloads for directory DIR"
1263 (interactive "DInstall all elisp files from directory: ")
1268 ;;;_ . elinstall-update-file-autoloads
1270 (defun elinstall-update-file-autoloads (file)
1271 "Update autoloads for elisp file FILE"
1273 (interactive "fUpdate autoloads for elisp file: ")
1275 (file-name-directory file
)
1276 `(control compile-p nil
1277 (file ,(file-name-nondirectory file
)))))
1279 ;;;_ . elinstall-update-file
1281 (defun elinstall-update-file (file)
1282 "Install elisp file FILE"
1284 (interactive "fInstall elisp file: ")
1286 (file-name-directory file
)
1287 `(file ,(file-name-nondirectory file
))))
1292 (provide 'elinstall
)
1294 ;;;_ * Local emacs vars.
1295 ;;;_ + Local variables:
1300 ;;; elinstall.el ends here