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
)))
140 (setq elinstall-already-installed
141 (delete old-item elinstall-already-installed
)))
142 (push new-item elinstall-already-installed
)
143 (customize-save-variable
144 'elinstall-already-installed
145 elinstall-already-installed
146 "Set by elinstall-record-installed")))
147 ;;;_ . Finding deffiles
148 ;;;_ , elinstall-expand-deffile-name
149 (defun elinstall-expand-deffile-name (deffile)
150 "Expand DEFFILE autoload.el's way."
152 (expand-file-name (or deffile
"loaddefs.el")
153 (expand-file-name "lisp"
159 ;;;_ , Doing autoload actions (adapted from autoload.el)
160 ;;;_ . Utilities about the action list
161 ;;;_ , elinstall-remove-autogen-action
162 (defun elinstall-remove-autogen-action (file actions
)
163 "Return ACTIONS minus any add-file-autoloads on FILE removed."
170 (if (equal file
(third act
))
175 ;;;_ , elinstall-get-autogen-action
176 (defun elinstall-get-autogen-action (file actions
)
180 (dolist (act actions
)
183 (when (equal file
(third act
))
184 (setq the-act act
)))))
186 ;;;_ . About printing to autoload file
187 ;;;_ , elinstall-insert-section-header
188 (defun elinstall-insert-section-header (outbuf form
)
189 "Insert the section-header line,
190 which lists the file name and which functions are in it, etc."
191 (insert generate-autoload-section-header
)
194 ;; Break that line at spaces, to avoid very long lines.
195 ;; Make each sub-line into a comment.
196 (with-current-buffer outbuf
201 (skip-chars-forward "^ \n")
203 (insert "\n" generate-autoload-section-continuation
))))))
205 ;;;_ , elinstall-insert-autoload-section
206 (defun elinstall-insert-autoload-section (text form
&optional comment-string
)
207 "Insert TEXT into current buffer as an autoload section"
209 (let* ( ;; This does something in Lucid Emacs.
212 (float-output-format nil
))
214 (elinstall-insert-section-header (current-buffer) form
)
216 (insert ";;; " comment-string
"\n"))
218 (insert generate-autoload-section-trailer
)))
220 ;;;_ . Making autoloads
221 ;;;_ , elinstall-make-autoload-action
222 (defun elinstall-make-autoload-action (buf def-file load-path-element full-path
)
223 "Return the autoloads for current buffer as a string"
225 ;;We put all the text into a temp buffer, then get that buffer's
229 (generate-new-buffer " *temp*"))
232 (file-name-nondirectory full-path
))
234 ;; Apparently this does something in Lucid Emacs.
237 (float-output-format nil
)
239 ;;load-name relative to a member of load-path.
241 (file-name-sans-extension
244 load-path-element
))))
246 (with-current-buffer buf
251 (goto-char (point-min))
252 (message "Finding autoloads for %s..." short-name
)
254 (skip-chars-forward " \t\n\f")
256 ((looking-at (regexp-quote generate-autoload-cookie
))
257 (search-forward generate-autoload-cookie
)
258 (skip-chars-forward " \t")
261 ;; Read the next form and make an autoload.
262 (let* ((form (prog1 (read (current-buffer))
263 (or (bolp) (forward-line 1))))
265 (make-autoload form relative-name
)))
267 (push (nth 1 form
) autoloads-done
)
268 (setq autoload form
))
269 (let ((autoload-print-form-outbuf outbuf
))
270 (autoload-print-form autoload
)))
272 ;; Copy the rest of the line to the output.
273 (princ (buffer-substring
275 ;; Back up over whitespace,
277 (skip-chars-backward " \f\t")
278 (if (= (char-after (1+ (point))) ?
)
282 (progn (forward-line 1) (point)))
285 ;; Don't read the comment.
290 (message "Finding autoloads for %s...done" short-name
))
292 ;;Return this action. The temp buffer's contents is
298 ,(with-current-buffer outbuf
(buffer-string))
301 ;;This in unwind-protected
302 (when (buffer-live-p outbuf
) (kill-buffer outbuf
))))))
305 ;;;_ , elinstall-generate-file-autoloads
307 (defun elinstall-generate-file-autoloads
308 (relative-name full-name text autoloads-done
)
309 "Insert at point a loaddefs autoload section for FILE.
310 Autoloads are generated for defuns and defmacros in FILE
311 marked by `generate-autoload-cookie' (which see).
312 If FILE is being visited in a buffer, the contents of the buffer
314 Return non-nil in the case where no autoloads were added at point.
316 FULL-NAME is the absolute name of the file.
317 RELATIVE-NAME is its name respective to some component of load-path."
318 (if (not (equal text
""))
319 ;; Insert the section-header line which lists the file name and
320 ;; which functions are in it, etc.
321 (elinstall-insert-autoload-section
326 (autoload-trim-file-name full-name
)
327 (elinstall-file-mod-time full-name
))
329 "Generated autoloads from "
330 (autoload-trim-file-name full-name
)))
333 ;;;_ , elinstall-deffile-insert-autoloads
334 (defun elinstall-deffile-insert-autoloads (file args
)
335 "Update the autoloads for FILE in current buffer.
336 Return FILE if there was no autoload cookie in it, else nil.
338 Current buffer must be a loaddef-style file.
340 LOAD-NAME is the absolute name of the file.
341 RELATIVE-NAME is its name respective to some component of load-path."
349 (goto-char (point-min))
350 ;; Look for the section for FILE
351 (while (and (not found
)
352 (search-forward generate-autoload-section-header nil t
))
353 (let ((form (autoload-read-section-header)))
355 ((equal (nth 2 form
) file
)
356 ;; We found the section for this file.
357 (let ((begin (match-beginning 0)))
359 (search-forward generate-autoload-section-trailer
)
360 (delete-region begin
(point))
362 ((string< file
(nth 2 form
))
363 ;; We've come to a section alphabetically later than
364 ;; FILE. We assume the file is in order and so
365 ;; there must be no section for FILE. We will
366 ;; insert one before the section here.
367 (goto-char (match-beginning 0))
368 (setq found
'new
)))))
372 ;; No later sections in the file. Put before the last page.
373 (goto-char (point-max))
374 (search-backward "\f" nil t
)))
376 (apply #'elinstall-generate-file-autoloads
379 (if no-autoloads file nil
)))
380 ;;;_ . Arranging to add to info-path and load-path
381 ;;;_ , elinstall-generate-add-to-path
382 (defun elinstall-generate-add-to-path (path-element type
)
383 "Insert code at point to add PATH-ELEMENT to a path.
385 * `add-to-load-path', add to load-path
386 * `add-to-info-path', add to Info-additional-directory-list
388 Current buffer must be a loaddef-style file."
391 (add-to-load-path 'load-path
)
392 (add-to-info-path 'Info-additional-directory-list
)
393 (t (error "Type not recognized"))))
396 (add-to-load-path "load-path")
397 (add-to-info-path "info-path")))
400 (print-readably t
) ; This does something in Lucid Emacs.
401 (float-output-format nil
))
403 (message "Generating %s additions..." description
)
405 (elinstall-insert-autoload-section
407 `(add-to-list ',path-symbol
409 ,(file-relative-name path-element
)
412 (file-truename load-file-name
))))))
413 (list type
(list path-element
) nil nil nil
)
415 (message "Generating %s additions...done" description
)))
418 ;;;_ , elinstall-deffile-insert-add-to-path
419 (defun elinstall-deffile-insert-add-to-path (path-element type
)
420 "Insert code in current buffer to add PATH-ELEMENT to a path.
422 * `add-to-load-path', add to load-path
423 * `add-to-info-path', add to Info-default-directory-list
425 Current buffer must be a loaddef-style file."
433 (goto-char (point-min))
434 ;; Look for the section for PATH-ELEMENT
435 (while (and (not found
)
436 (search-forward generate-autoload-section-header nil t
))
437 (let ((form (autoload-read-section-header)))
440 (equal (nth 0 form
) type
)
441 (member path-element
(nth 1 form
)))
443 ;; We found the section for this add.
444 (let ((begin (match-beginning 0)))
446 (search-forward generate-autoload-section-trailer
)
447 (delete-region begin
(point))
453 ;; No later sections in the file. Put before the last page.
454 (goto-char (point-max))
455 (search-backward "\f" nil t
)))
457 (elinstall-generate-add-to-path path-element type
)))
459 ;;This never belongs in the no-autoloads section.
461 ;;;_ . elinstall-deffile-insert
463 (defun elinstall-deffile-insert (action)
464 "Insert autoloads etc into current file according to ACTION.
465 The format of ACTION is described in the design docs.
467 Return filename if this action belongs in the no-autoload section."
472 (elinstall-deffile-insert-autoloads
477 (elinstall-deffile-insert-add-to-path
483 (elinstall-deffile-insert-add-to-path
488 ((preload-file run-tests byte-compile
)
489 (error "This case should not come here.")))))
491 ;;;_ . elinstall-prepare-deffile
492 (defun elinstall-prepare-deffile (deffile)
493 "Try to ensure that DEFFILE is available for receiving autoloads"
495 (autoload-ensure-default-file deffile
)
496 (with-current-buffer (find-file-noselect deffile
)
499 ;; We must read/write the file without any code conversion,
500 ;; but still decode EOLs.
501 (let ((coding-system-for-read 'raw-text
))
503 ;; This is to make generated-autoload-file have Unix EOLs, so
504 ;; that it is portable to all platforms.
505 (setq buffer-file-coding-system
'raw-text-unix
))
506 (or (> (buffer-size) 0)
507 (error "Autoloads file %s does not exist" buffer-file-name
))
508 (or (file-writable-p buffer-file-name
)
509 (error "Autoloads file %s is not writable"
512 ;;;_ . elinstall-update-deffile
514 ;;Adapted from autoload.el `update-directory-autoloads'.
516 (defun elinstall-update-deffile (target actions
&optional
519 Update file TARGET with current autoloads as specified by ACTIONS.
520 Also remove any old definitions pointing to libraries that can no
523 ACTIONS must be a list of actions (See the format doc). Each one's
524 filename must be relative to some element of load-path.
526 USE-LOAD-PATH is a list to use as load-path. It should include
527 any new load-path that we are arranging to create. If it's not given,
528 load-path itself is used.
530 If FORCE is `t', do it regardless of timestamps etc. (Not implemented)
531 Other non-nil cases of FORCE are reserved for future development.
533 This uses `update-file-autoloads' (which see) to do its work.
534 In an interactive call, you must give one argument, the name
535 of a single directory."
538 (use-load-path (or use-load-path load-path
))
539 (this-time (current-time))
540 ;;files with no autoload cookies.
543 (elinstall-prepare-deffile target
)
545 (find-file-noselect target
)
548 (elinstall-remove-autogen-action
549 (autoload-trim-file-name target
)
552 (goto-char (point-min))
553 (while (search-forward generate-autoload-section-header nil t
)
554 (let* ((form (autoload-read-section-header))
556 (cond ((and (consp file
) (stringp (car file
)))
557 ;; This is a list of files that have no
559 ;; There shouldn't be more than one such entry.
560 ;; Remove the obsolete section.
561 (autoload-remove-section (match-beginning 0))
562 (let ((last-time (nth 4 form
)))
564 (let ((file-time (elinstall-file-mod-time file
)))
566 (not (time-less-p last-time file-time
)))
568 (push file no-autoloads
)
570 (elinstall-remove-autogen-action
572 ((not (stringp file
)))
576 (locate-library file nil use-load-path
)))
578 ;;File doesn't exist, so remove its
581 (autoload-remove-section
582 (match-beginning 0)))
584 ;; File hasn't changed, so do nothing.
587 (elinstall-file-mod-time file-path
))
590 (elinstall-deffile-insert
591 (elinstall-get-autogen-action
595 (elinstall-remove-autogen-action
598 ;; Remaining actions have no existing autoload sections yet.
601 (delq nil
(mapcar #'elinstall-deffile-insert actions
))))
603 ;; Sort them for better readability.
604 (setq no-autoloads
(sort no-autoloads
'string
<))
605 ;; Add the `no-autoloads' section.
606 (goto-char (point-max))
607 (search-backward "\f" nil t
)
608 (elinstall-insert-autoload-section
610 (list 'autoloads nil nil no-autoloads this-time
)))
613 ;;;_ . elinstall-stage-update-deffiles
614 (defun elinstall-stage-update-deffiles (segment-list force use-load-path
)
615 "Update any deffiles mentioned in SEGMENT-LIST.
616 FORCE and USE-LOAD-PATH have the same meaning as in
617 `elinstall-update-deffile'.
622 ((deffile (car segment
)))
623 (if (stringp deffile
)
624 (elinstall-update-deffile deffile
(cdr segment
) force
628 ;;;_ , Doing actions to arrange preloads
629 ;;;_ . elinstall-symlink-on-emacs-start
630 (defun elinstall-symlink-on-emacs-start
631 (filename target-basename target-dir
&optional priority force
)
632 "Symlink to TARGET-BASENAME.el in TARGET-DIR
634 If PRIORITY is given, it will be used as the priority prefix,
635 otherwise elinstall-default-priority will be.
636 PRIORITY must be an integer or nil.
637 If FORCE is `t', do it regardless of timestamps etc.
638 Other non-nil cases of FORCE are reserved for future development."
641 (priority (or priority elinstall-default-priority
))
648 (expand-file-name target-name-nodir target-dir
)))
652 ;;Path should already exist.
654 (file-exists-p target-dir
))
655 (message "The target directory doesn't exist."))
656 ;;Target shouldn't already exist, but if force is given, let
658 ;;$$IMPROVE ME If it is a symlink pointing to the same place,
659 ;;do nothing even on force.
661 (file-exists-p target
)
666 (format "Really overwrite %s? " target
))))
667 (message "File %s already exists" target
)))
675 ;;;_ . elinstall-add-to-dot-emacs
676 (defun elinstall-add-to-dot-emacs (dot-emacs-name filename force
&rest r
)
677 "Add code to load FILENAME to .emacs.
678 FILENAME should not have an extension"
681 (with-current-buffer (find-file-noselect dot-emacs-name
)
684 (goto-char (point-max))
685 (insert "\n;;Added by elinstall")
686 (insert "\n;;Consider using my-site-start to manage .emacs\n")
687 (pp `(load ,filename
) (current-buffer))
691 ;;;_ . elinstall-arrange-preload
693 (defun elinstall-arrange-preload (force filename basename
&optional priority
)
694 "Arrange for FILENAME to be loaded on emacs start.
695 FORCE has its usual meaning.
696 BASENAME and PRIORITY are used as arguments to
697 `elinstall-symlink-on-emacs-start'.
701 ((preload-target elinstall-default-preload-target
))
703 ;;Dispatch the possibilities.
705 ((eq preload-target
'dot-emacs
)
706 (elinstall-add-to-dot-emacs "~/.emacs" filename force
))
707 ((stringp preload-target
)
708 (elinstall-symlink-on-emacs-start
709 filename basename preload-target priority force
))
710 ((null preload-target
)
711 (message "Not arranging for preloads"))
713 (message "I don't recognize that")))))
714 ;;;_ . elinstall-stage-arrange-preloads
715 (defun elinstall-stage-arrange-preloads (actions deffiles-used force
)
716 "Arrange any preloads mentioned in ACTIONS."
730 (member filename deffiles-used
)))))
734 #'elinstall-arrange-preload
739 "elinstall-stage-arrange-preloads: Action not
745 ;;;_ . elinstall-stage-run-tests
746 (defun elinstall-stage-run-tests (actions)
747 "Run any tests mentioned in ACTIONS."
753 ;;$$WRITE ME - not a high priority right now.
757 "elinstall-stage-run-tests: Action not
763 ;;;_ . elinstall-stage-byte-compile
764 (defun elinstall-stage-byte-compile (actions)
765 "Do any byte-compilation mentioned in ACTIONS."
770 ;;$$IMPROVE ME Understand flags to control second
771 ;;argument (whether to load file after
774 (byte-compile-file (second act
)))
777 "elinstall-stage-byte-compile: Action not
780 ;;;_ . Segregating actions
781 ;;;_ , elinstall-remove-empty-segs
782 (defun elinstall-remove-empty-segs (segment-list)
783 "Return SEGMENT-LIST minus any segments that have no actions.
784 Intended only for the deffile stage data."
793 ;;;_ , elinstall-segregate-actions
794 (defun elinstall-segregate-actions (actions)
795 "Return actions segregated by deffile.
797 Returns a list whose elements are each a cons of:
798 * deffile filename or nil
799 * A list of actions to be done for that deffile."
806 (arrange-preloads '()))
808 (dolist (act actions
)
815 ((deffile-name (second act
))
817 (assoc deffile-name build-deffiles
)))
819 ;;There are already actions on this deffile.
820 ;;Splice this action in.
822 (cons act
(cdr cell-already
)))
823 ;;There are no actions on this deffile. Add a
824 ;;place for them and include this action.
825 (push (list deffile-name act
) build-deffiles
))))
827 (push act arrange-preloads
))
829 (push act run-tests
))
831 (push act byte-compile
)))))
833 (elinstall-make-stages
835 (elinstall-remove-empty-segs build-deffiles
)
842 ;;;_ . Finding actions
844 ;;;_ . elinstall-dir-has-info
846 ;;$$IMPROVE ME - Can this test be made more precise?
847 (defun elinstall-dir-has-info (dir)
848 "Return non-nil if DIR has info files in it.
849 DIR should be an absolute path."
851 (string-match "/info/" dir
)
852 (directory-files dir nil
"\\.info\\(-[0-9]+\\)?\\(\\.gz\\)?$")))
855 ;;;_ . List of special variables used in this section
856 ;;load-path-element - The relevant element of load-path
857 ;;def-file - The file the autoload definitions etc will go into.
858 ;;add-to-load-path-p - Controls whether to add to load-path.
859 ;;recurse-dirs-p - Whether to recurse into subdirectories.
860 (defconst elinstall-find-actions-control-vars
861 '(add-to-load-path-p recurse-dirs-p compile-p force-recompile-p
)
862 "Control special variables that the find-actions tree recognizes" )
863 ;;;_ . elinstall-actions-for-source-file
864 (defun elinstall-actions-for-source-file (filename dir
)
865 "Return a list of actions to do for FILENAME in DIR.
866 Special variables are as noted in \"List of special variables\"."
868 load-path-element def-file compile-p force-recompile-p
))
871 (expand-file-name filename dir
)))
874 (file-readable-p full-path
)
875 (not (auto-save-file-name-p full-path
)))
876 ;;$$IMPROVE ME create and use relevant control variables.
879 (visited (get-file-buffer full-path
))
883 ;;Visit the file cheaply.
884 ;;hack-local-variables can give errors.
885 (ignore-errors (autoload-find-file full-path
))))
889 (with-current-buffer buf
890 (if (local-variable-p 'generated-autoload-file
)
891 (elinstall-expand-deffile-name
892 generated-autoload-file
)
895 ;;Figure out whether to run some actions, by file local vars.
898 (with-current-buffer buf
899 (not no-update-autoloads
))))
902 (featurep 'byte-compile
)
903 (string-match emacs-lisp-file-regexp filename
)
905 (with-current-buffer buf
906 (not no-byte-compile
)))
908 ((dest (byte-compile-dest-file full-path
)))
909 (if (file-exists-p dest
)
910 ;; File was already compiled.
911 (or force-recompile-p
912 (file-newer-than-file-p full-path dest
))
914 (y-or-n-p (concat "Compile " filename
"? "))))))))
919 `(byte-compile ,full-path
)
922 (elinstall-make-autoload-action
923 buf def-file load-path-element full-path
)
925 (unless visited
(kill-buffer-if-not-modified buf
)))))))
926 ;;;_ . elinstall-actions-for-dir
927 (defun elinstall-actions-for-dir (dirname &optional recurse-dirs-p
)
928 "Make actions for DIR.
929 Recurse just if RECURSE-DIRS-P"
931 load-path-element def-file add-to-load-path-p
))
932 ;;This does not treat symlinks specially. $$IMPROVE ME it could
933 ;;treat/not treat them conditional on control variables.
936 ;;Relative filenames of the source files. We know our
937 ;;loaddefs.el isn't really source so remove it. We'd have
938 ;;removed it anyways after seeing file local vars.
945 elinstall-elisp-regexp
)))
946 ;;Absolute filenames of subdirectories.
947 ;;Don't accept any directories beginning with dot. If user
948 ;;really wants to explore one he can use `(dir ".NAME")'.
955 (file-directory-p filename
)
965 elisp-source-files
;;If list is not empty.
973 ;;Sometimes arrange to add this directory to load-path.
980 ;;$$IMPROVE ME - be controlled by a control variable.
981 ;;Sometimes add this directory to info path.
983 (elinstall-dir-has-info dirname
)
992 (elinstall-actions-for-source-file
1000 #'(lambda (filename)
1001 (elinstall-find-actions-by-spec-x
1009 ;;;_ . elinstall-find-actions-by-spec-x
1011 (defun elinstall-find-actions-by-spec-x (spec dir
)
1012 "Return a list of actions to do, controlled by SPEC."
1014 load-path-element def-file add-to-load-path-p
1023 #'(lambda (sub-spec)
1024 (elinstall-find-actions-by-spec-x
1029 ;;Rather than trying to bind all control variables each time
1030 ;;thru, we use `set' and `unwind-protect'.
1032 ;;control TYPE DISPOSITION SPEC
1034 ((key (second spec
))
1036 (if (memq key elinstall-find-actions-control-vars
)
1039 (set old-value
(symbol-value key
))
1040 (set key
(third spec
))
1041 (elinstall-find-actions-by-spec-x
1044 (set key old-value
))
1045 (error "Unrecognized control variable %s" key
))))
1049 ;;(def-file FN ARGS SPEC)
1055 (for-preload (third spec
)))
1056 (assert (listp for-preload
))
1060 (and for-preload
(car for-preload
))
1064 ,@(cdr for-preload
))
1067 (elinstall-find-actions-by-spec-x
1068 (fourth spec
) dir
))))
1072 (elinstall-actions-for-dir
1080 (elinstall-actions-for-source-file
1091 (elinstall-find-actions-by-spec-x
1098 `((add-to-load-path ,def-file
,dir
))
1100 ((load-path-element dir
)
1101 (add-to-load-path-p nil
))
1102 (elinstall-find-actions-by-spec-x
1107 ;;(matching PATTERN SPEC)
1111 (elinstall-find-actions-by-spec-x
1115 dir t
(second spec
)))))
1117 ;;(preload FN SYM &rest ARGS)
1119 ((key (third spec
)))
1121 (and (symbolp key
) (symbol-value key
))
1124 ,(expand-file-name (second spec
) dir
)
1131 (elinstall-actions-for-dir dir nil
))
1133 (elinstall-actions-for-dir dir t
)))))
1135 ;;;_ . elinstall-find-actions-by-spec
1136 (defun elinstall-find-actions-by-spec
1137 (spec load-path-element dir def-file redo-old
)
1138 "Find the list of actions to do according to SPEC."
1142 (def-file-time (elinstall-file-mod-time def-file
))
1143 (add-to-load-path-p t
)
1145 (force-recompile-p nil
)
1148 load-path-element def-file add-to-load-path-p
1149 recurse-dirs-p force-recompile-p compile-p
))
1151 (elinstall-find-actions-by-spec-x spec dir
)))
1153 ;;;_ . high-level work
1154 ;;;_ , elinstall-get-relevant-load-path
1155 (defun elinstall-get-relevant-load-path (actions)
1165 ;;;_ , elinstall-get-deffile-list
1166 (defun elinstall-get-deffile-list (stages)
1167 "Get a list of deffile names"
1171 (elinstall-stages->build-deffiles stages
)))
1173 (defun elinstall-x (dir spec
&optional force
)
1174 "High-level worker function to install elisp files."
1177 ;;This is just the default deffile, spec can override it.
1179 (elinstall-expand-deffile-name nil
))
1181 (elinstall-find-actions-by-spec
1186 (eq force
'redo-old
)))
1187 (stages (elinstall-segregate-actions actions
))
1189 (elinstall-get-relevant-load-path
1192 (elinstall-stage-update-deffiles
1193 (elinstall-stages->build-deffiles stages
)
1196 (elinstall-stage-arrange-preloads
1197 (elinstall-stages->arrange-preloads stages
)
1198 (elinstall-get-deffile-list stages
)
1200 (elinstall-stage-byte-compile
1201 (elinstall-stages->byte-compile stages
))
1206 (defun elinstall (project-name path spec
&optional force version-string
)
1207 "Install elisp files.
1208 They need not be a formal package.
1212 PROJECT-NAME - the name of the project
1214 PATH - Path to the project.
1215 Suggestion: (elinstall-directory-true-name)
1217 SPEC - a spec for the autoloads etc to make. It can be as simple as
1218 \(dir \"\.\") for installing one directory.
1220 If FORCE is t, install a package even if it has already been
1221 installed. Other non-nil cases of FORCE are reserved for future
1227 (not (elinstall-already-installed project-name
))
1228 (yes-or-no-p (format "Re-install %s? " project-name
)))
1231 `(def-file "loaddefs.el" (if-used ,project-name
) ,spec
)
1233 (elinstall-record-installed project-name version-string
)))
1237 ;;;_ . elinstall-update-directory-autoloads
1239 ;;The control variables and values of `force' that would stop other
1240 ;;actions don't exist yet. Similarly for
1241 ;;`elinstall-update-file-autoloads'.
1243 (defun elinstall-update-directory-autoloads (dir)
1244 "Update autoloads for directory DIR"
1246 (interactive "DUpdate autoloads for all elisp files from directory: ")
1249 `(control compile-p nil
1252 ;;;_ . elinstall-update-directory
1254 (defun elinstall-update-directory (dir)
1255 "Update autoloads for directory DIR"
1257 (interactive "DInstall all elisp files from directory: ")
1262 ;;;_ . elinstall-update-file-autoloads
1264 (defun elinstall-update-file-autoloads (file)
1265 "Update autoloads for elisp file FILE"
1267 (interactive "fUpdate autoloads for elisp file: ")
1269 (file-name-directory file
)
1270 `(control compile-p nil
1271 (file ,(file-name-nondirectory file
)))))
1273 ;;;_ . elinstall-update-file
1275 (defun elinstall-update-file (file)
1276 "Install elisp file FILE"
1278 (interactive "fInstall elisp file: ")
1280 (file-name-directory file
)
1281 `(file ,(file-name-nondirectory file
))))
1286 (provide 'elinstall
)
1288 ;;;_ * Local emacs vars.
1289 ;;;_ + Local variables:
1294 ;;; elinstall.el ends here