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-directory-true-name
103 (defun elinstall-directory-true-name ()
104 "Get the true name of the directory the calling code lives in.
105 CAUTION: This is sensitive to where it's called. That's the point of it."
108 (file-truename load-file-name
)
109 (file-truename buffer-file-name
))))
110 ;;;_ . Checking installedness
111 ;;;_ , elinstall-get-installation-record
112 (defun elinstall-get-installation-record (project-name)
113 "Return the installation record for PROJECT-NAME."
115 (assoc project-name elinstall-already-installed
))
117 ;;;_ , elinstall-already-installed
118 (defun elinstall-already-installed (project-name)
119 "Return non-nil if PROJECT-NAME has been installed."
120 (elinstall-get-installation-record project-name
))
122 ;;;_ , elinstall-record-installed
123 (defun elinstall-record-installed (project-name &optional version
)
124 "Record that PROJECT-NAME has been installed."
133 (elinstall-get-installation-record project-name
)))
135 (setq elinstall-already-installed
136 (delete old-item elinstall-already-installed
)))
137 (push new-item elinstall-already-installed
)
138 (customize-save-variable
139 'elinstall-already-installed
140 elinstall-already-installed
141 "Set by elinstall-record-installed")))
142 ;;;_ . Finding deffiles
143 ;;;_ , elinstall-expand-deffile-name
144 (defun elinstall-expand-deffile-name (deffile)
145 "Expand DEFFILE autoload.el's way."
147 (expand-file-name (or deffile
"loaddefs.el")
148 (expand-file-name "lisp"
154 ;;;_ , Doing autoload actions (adapted from autoload.el)
155 ;;;_ . Utilities about the action list
156 ;;;_ , elinstall-remove-autogen-action
157 (defun elinstall-remove-autogen-action (file actions
)
158 "Return ACTIONS minus any add-file-autoloads on FILE removed."
165 (if (equal file
(third act
))
170 ;;;_ , elinstall-get-autogen-action
171 (defun elinstall-get-autogen-action (file actions
)
175 (dolist (act actions
)
178 (when (equal file
(third act
))
179 (setq the-act act
)))))
181 ;;;_ . About printing to autoload file
182 ;;;_ , elinstall-insert-section-header
183 (defun elinstall-insert-section-header (outbuf form
)
184 "Insert the section-header line,
185 which lists the file name and which functions are in it, etc."
186 (insert generate-autoload-section-header
)
189 ;; Break that line at spaces, to avoid very long lines.
190 ;; Make each sub-line into a comment.
191 (with-current-buffer outbuf
196 (skip-chars-forward "^ \n")
198 (insert "\n" generate-autoload-section-continuation
))))))
200 ;;;_ , elinstall-insert-autoload-section
201 (defun elinstall-insert-autoload-section (text form
&optional comment-string
)
202 "Insert TEXT into current buffer as an autoload section"
204 (let* ( ;; This does something in Lucid Emacs.
207 (float-output-format nil
))
209 (elinstall-insert-section-header (current-buffer) form
)
211 (insert ";;; " comment-string
"\n"))
213 (insert generate-autoload-section-trailer
)))
215 ;;;_ . Making autoloads
216 ;;;_ , elinstall-make-autoload-action
217 (defun elinstall-make-autoload-action (buf def-file load-path-element full-path
)
218 "Return the autoloads for current buffer as a string"
220 ;;We put all the text into a temp buffer, then get that buffer's
224 (generate-new-buffer " *temp*"))
227 (file-name-nondirectory full-path
))
229 ;; Apparently this does something in Lucid Emacs.
232 (float-output-format nil
)
234 ;;load-name relative to a member of load-path.
236 (file-name-sans-extension
239 load-path-element
))))
241 (with-current-buffer buf
246 (goto-char (point-min))
247 (message "Finding autoloads for %s..." short-name
)
249 (skip-chars-forward " \t\n\f")
251 ((looking-at (regexp-quote generate-autoload-cookie
))
252 (search-forward generate-autoload-cookie
)
253 (skip-chars-forward " \t")
256 ;; Read the next form and make an autoload.
257 (let* ((form (prog1 (read (current-buffer))
258 (or (bolp) (forward-line 1))))
260 (make-autoload form relative-name
)))
262 (push (nth 1 form
) autoloads-done
)
263 (setq autoload form
))
264 (let ((autoload-print-form-outbuf outbuf
))
265 (autoload-print-form autoload
)))
267 ;; Copy the rest of the line to the output.
268 (princ (buffer-substring
270 ;; Back up over whitespace,
272 (skip-chars-backward " \f\t")
273 (if (= (char-after (1+ (point))) ?
)
277 (progn (forward-line 1) (point)))
280 ;; Don't read the comment.
285 (message "Finding autoloads for %s...done" short-name
))
287 ;;Return this action. The temp buffer's contents is
293 ,(with-current-buffer outbuf
(buffer-string))
296 ;;This in unwind-protected
297 (when (buffer-live-p outbuf
) (kill-buffer outbuf
))))))
300 ;;;_ , elinstall-generate-file-autoloads
302 (defun elinstall-generate-file-autoloads
303 (relative-name full-name text autoloads-done
)
304 "Insert at point a loaddefs autoload section for FILE.
305 Autoloads are generated for defuns and defmacros in FILE
306 marked by `generate-autoload-cookie' (which see).
307 If FILE is being visited in a buffer, the contents of the buffer
309 Return non-nil in the case where no autoloads were added at point.
311 FULL-NAME is the absolute name of the file.
312 RELATIVE-NAME is its name respective to some component of load-path."
313 (if (not (equal text
""))
314 ;; Insert the section-header line which lists the file name and
315 ;; which functions are in it, etc.
316 (elinstall-insert-autoload-section
321 (autoload-trim-file-name full-name
)
322 (nth 5 (file-attributes full-name
)))
324 "Generated autoloads from "
325 (autoload-trim-file-name full-name
)))
328 ;;;_ , elinstall-deffile-insert-autoloads
329 (defun elinstall-deffile-insert-autoloads (file args
)
330 "Update the autoloads for FILE in current buffer.
331 Return FILE if there was no autoload cookie in it, else nil.
333 Current buffer must be a loaddef-style file.
335 LOAD-NAME is the absolute name of the file.
336 RELATIVE-NAME is its name respective to some component of load-path."
344 (goto-char (point-min))
345 ;; Look for the section for FILE
346 (while (and (not found
)
347 (search-forward generate-autoload-section-header nil t
))
348 (let ((form (autoload-read-section-header)))
350 ((equal (nth 2 form
) file
)
351 ;; We found the section for this file.
352 (let ((begin (match-beginning 0)))
354 (search-forward generate-autoload-section-trailer
)
355 (delete-region begin
(point))
357 ((string< file
(nth 2 form
))
358 ;; We've come to a section alphabetically later than
359 ;; FILE. We assume the file is in order and so
360 ;; there must be no section for FILE. We will
361 ;; insert one before the section here.
362 (goto-char (match-beginning 0))
363 (setq found
'new
)))))
367 ;; No later sections in the file. Put before the last page.
368 (goto-char (point-max))
369 (search-backward "\f" nil t
)))
371 (apply #'elinstall-generate-file-autoloads
374 (if no-autoloads file nil
)))
375 ;;;_ . Arranging to add to info-path and load-path
376 ;;;_ , elinstall-generate-add-to-path
377 (defun elinstall-generate-add-to-path (path-element type
)
378 "Insert code at point to add PATH-ELEMENT to a path.
380 * `add-to-load-path', add to load-path
381 * `add-to-info-path', add to Info-additional-directory-list
383 Current buffer must be a loaddef-style file."
386 (add-to-load-path 'load-path
)
387 (add-to-info-path 'Info-additional-directory-list
)
388 (t (error "Type not recognized"))))
391 (add-to-load-path "load-path")
392 (add-to-info-path "info-path")))
395 (print-readably t
) ; This does something in Lucid Emacs.
396 (float-output-format nil
))
398 (message "Generating %s additions..." description
)
400 (elinstall-insert-autoload-section
402 `(add-to-list ',path-symbol
404 ,(file-relative-name path-element
)
407 (file-truename load-file-name
))))))
408 (list type
(list path-element
) nil nil nil
)
410 (message "Generating %s additions...done" description
)))
413 ;;;_ , elinstall-deffile-insert-add-to-path
414 (defun elinstall-deffile-insert-add-to-path (path-element type
)
415 "Insert code in current buffer to add PATH-ELEMENT to a path.
417 * `add-to-load-path', add to load-path
418 * `add-to-info-path', add to Info-default-directory-list
420 Current buffer must be a loaddef-style file."
428 (goto-char (point-min))
429 ;; Look for the section for PATH-ELEMENT
430 (while (and (not found
)
431 (search-forward generate-autoload-section-header nil t
))
432 (let ((form (autoload-read-section-header)))
435 (equal (nth 0 form
) type
)
436 (member path-element
(nth 1 form
)))
438 ;; We found the section for this add.
439 (let ((begin (match-beginning 0)))
441 (search-forward generate-autoload-section-trailer
)
442 (delete-region begin
(point))
448 ;; No later sections in the file. Put before the last page.
449 (goto-char (point-max))
450 (search-backward "\f" nil t
)))
452 (elinstall-generate-add-to-path path-element type
)))
454 ;;This never belongs in the no-autoloads section.
456 ;;;_ . elinstall-deffile-insert
458 (defun elinstall-deffile-insert (action)
459 "Insert autoloads etc into current file according to ACTION.
460 The format of ACTION is described in the design docs.
462 Return filename if this action belongs in the no-autoload section."
467 (elinstall-deffile-insert-autoloads
472 (elinstall-deffile-insert-add-to-path
478 (elinstall-deffile-insert-add-to-path
483 ((preload-file run-tests byte-compile
)
484 (error "This case should not come here.")))))
486 ;;;_ . elinstall-prepare-deffile
487 (defun elinstall-prepare-deffile (deffile)
488 "Try to ensure that DEFFILE is available for receiving autoloads"
490 (autoload-ensure-default-file deffile
)
491 (with-current-buffer (find-file-noselect deffile
)
494 ;; We must read/write the file without any code conversion,
495 ;; but still decode EOLs.
496 (let ((coding-system-for-read 'raw-text
))
498 ;; This is to make generated-autoload-file have Unix EOLs, so
499 ;; that it is portable to all platforms.
500 (setq buffer-file-coding-system
'raw-text-unix
))
501 (or (> (buffer-size) 0)
502 (error "Autoloads file %s does not exist" buffer-file-name
))
503 (or (file-writable-p buffer-file-name
)
504 (error "Autoloads file %s is not writable"
507 ;;;_ . elinstall-update-deffile
509 ;;Adapted from autoload.el `update-directory-autoloads'.
511 (defun elinstall-update-deffile (target actions
&optional
514 Update file TARGET with current autoloads as specified by ACTIONS.
515 Also remove any old definitions pointing to libraries that can no
518 ACTIONS must be a list of actions (See the format doc). Each one's
519 filename must be relative to some element of load-path.
521 USE-LOAD-PATH is a list to use as load-path. It should include
522 any new load-path that we are arranging to create. If it's not given,
523 load-path itself is used.
525 If FORCE is `t', do it regardless of timestamps etc. (Not implemented)
526 Other non-nil cases of FORCE are reserved for future development.
528 This uses `update-file-autoloads' (which see) to do its work.
529 In an interactive call, you must give one argument, the name
530 of a single directory."
533 (use-load-path (or use-load-path load-path
))
534 (this-time (current-time))
535 ;;files with no autoload cookies.
538 (elinstall-prepare-deffile target
)
540 (find-file-noselect target
)
543 (elinstall-remove-autogen-action
544 (autoload-trim-file-name target
)
547 (goto-char (point-min))
548 (while (search-forward generate-autoload-section-header nil t
)
549 (let* ((form (autoload-read-section-header))
551 (cond ((and (consp file
) (stringp (car file
)))
552 ;; This is a list of files that have no
554 ;; There shouldn't be more than one such entry.
555 ;; Remove the obsolete section.
556 (autoload-remove-section (match-beginning 0))
557 (let ((last-time (nth 4 form
)))
559 (let ((file-time (nth 5 (file-attributes file
))))
561 (not (time-less-p last-time file-time
)))
563 (push file no-autoloads
)
565 (elinstall-remove-autogen-action
567 ((not (stringp file
)))
571 (locate-library file nil use-load-path
)))
573 ;;File doesn't exist, so remove its
576 (autoload-remove-section
577 (match-beginning 0)))
579 ;; File hasn't changed, so do nothing.
582 (nth 5 (file-attributes file-path
)))
585 (elinstall-deffile-insert
586 (elinstall-get-autogen-action
590 (elinstall-remove-autogen-action
593 ;; Remaining actions have no existing autoload sections yet.
596 (delq nil
(mapcar #'elinstall-deffile-insert actions
))))
598 ;; Sort them for better readability.
599 (setq no-autoloads
(sort no-autoloads
'string
<))
600 ;; Add the `no-autoloads' section.
601 (goto-char (point-max))
602 (search-backward "\f" nil t
)
603 (elinstall-insert-autoload-section
605 (list 'autoloads nil nil no-autoloads this-time
)))
608 ;;;_ . elinstall-stage-update-deffiles
609 (defun elinstall-stage-update-deffiles (segment-list force use-load-path
)
610 "Update any deffiles mentioned in SEGMENT-LIST.
611 FORCE and USE-LOAD-PATH have the same meaning as in
612 `elinstall-update-deffile'.
617 ((deffile (car segment
)))
618 (if (stringp deffile
)
619 (elinstall-update-deffile deffile
(cdr segment
) force
623 ;;;_ , Doing actions to arrange preloads
624 ;;;_ . elinstall-symlink-on-emacs-start
625 (defun elinstall-symlink-on-emacs-start
626 (filename target-basename target-dir
&optional priority force
)
627 "Symlink to TARGET-BASENAME.el in TARGET-DIR
629 If PRIORITY is given, it will be used as the priority prefix,
630 otherwise elinstall-default-priority will be.
631 PRIORITY must be an integer or nil.
632 If FORCE is `t', do it regardless of timestamps etc.
633 Other non-nil cases of FORCE are reserved for future development."
636 (priority (or priority elinstall-default-priority
))
643 (expand-file-name target-name-nodir target-dir
)))
647 ;;Path should already exist.
649 (file-exists-p target-dir
))
650 (message "The target directory doesn't exist."))
651 ;;Target shouldn't already exist, but if force is given, let
653 ;;$$IMPROVE ME If it is a symlink pointing to the same place,
654 ;;do nothing even on force.
656 (file-exists-p target
)
661 (format "Really overwrite %s? " target
))))
662 (message "File %s already exists" target
)))
670 ;;;_ . elinstall-add-to-dot-emacs
671 (defun elinstall-add-to-dot-emacs (dot-emacs-name filename force
&rest r
)
672 "Add code to load FILENAME to .emacs.
673 FILENAME should not have an extension"
676 (with-current-buffer (find-file-noselect dot-emacs-name
)
679 (goto-char (point-max))
680 (insert "\n;;Added by elinstall")
681 (insert "\n;;Consider using my-site-start to manage .emacs\n")
682 (pp `(load ,filename
) (current-buffer))
686 ;;;_ . elinstall-arrange-preload
688 (defun elinstall-arrange-preload (force filename basename
&optional priority
)
689 "Arrange for FILENAME to be loaded on emacs start.
690 FORCE has its usual meaning.
691 BASENAME and PRIORITY are used as arguments to
692 `elinstall-symlink-on-emacs-start'.
696 ((preload-target elinstall-default-preload-target
))
698 ;;Dispatch the possibilities.
700 ((eq preload-target
'dot-emacs
)
701 (elinstall-add-to-dot-emacs "~/.emacs" filename force
))
702 ((stringp preload-target
)
703 (elinstall-symlink-on-emacs-start
704 filename basename preload-target priority force
))
705 ((null preload-target
)
706 (message "Not arranging for preloads"))
708 (message "I don't recognize that")))))
709 ;;;_ . elinstall-stage-arrange-preloads
710 (defun elinstall-stage-arrange-preloads (actions deffiles-used force
)
711 "Arrange any preloads mentioned in ACTIONS."
725 (member filename deffiles-used
)))))
729 #'elinstall-arrange-preload
734 "elinstall-stage-arrange-preloads: Action not
740 ;;;_ . elinstall-stage-run-tests
741 (defun elinstall-stage-run-tests (actions)
742 "Run any tests mentioned in ACTIONS."
748 ;;$$WRITE ME - not a high priority right now.
752 "elinstall-stage-run-tests: Action not
758 ;;;_ . elinstall-stage-byte-compile
759 (defun elinstall-stage-byte-compile (actions)
760 "Do any byte-compilation mentioned in ACTIONS."
765 ;;$$IMPROVE ME Understand flags to control second
766 ;;argument (whether to load file after
769 (byte-compile-file (second act
)))
772 "elinstall-stage-byte-compile: Action not
775 ;;;_ . Segregating actions
776 ;;;_ , elinstall-remove-empty-segs
777 (defun elinstall-remove-empty-segs (segment-list)
778 "Return SEGMENT-LIST minus any segments that have no actions.
779 Intended only for the deffile stage data."
788 ;;;_ , elinstall-segregate-actions
789 (defun elinstall-segregate-actions (actions)
790 "Return actions segregated by deffile.
792 Returns a list whose elements are each a cons of:
793 * deffile filename or nil
794 * A list of actions to be done for that deffile."
801 (arrange-preloads '()))
803 (dolist (act actions
)
810 ((deffile-name (second act
))
812 (assoc deffile-name build-deffiles
)))
814 ;;There are already actions on this deffile.
815 ;;Splice this action in.
817 (cons act
(cdr cell-already
)))
818 ;;There are no actions on this deffile. Add a
819 ;;place for them and include this action.
820 (push (list deffile-name act
) build-deffiles
))))
822 (push act arrange-preloads
))
824 (push act run-tests
))
826 (push act byte-compile
)))))
828 (elinstall-make-stages
830 (elinstall-remove-empty-segs build-deffiles
)
837 ;;;_ . Finding actions
839 ;;;_ . elinstall-dir-has-info
841 ;;$$IMPROVE ME - Can this test be made more precise?
842 (defun elinstall-dir-has-info (dir)
843 "Return non-nil if DIR has info files in it.
844 DIR should be an absolute path."
846 (string-match "/info/" dir
)
847 (directory-files dir nil
"\\.info\\(-[0-9]+\\)?\\(\\.gz\\)?$")))
850 ;;;_ . List of special variables used in this section
851 ;;load-path-element - The relevant element of load-path
852 ;;def-file - The file the autoload definitions etc will go into.
853 ;;add-to-load-path-p - Controls whether to add to load-path.
854 ;;recurse-dirs-p - Whether to recurse into subdirectories.
855 (defconst elinstall-find-actions-control-vars
856 '(add-to-load-path-p recurse-dirs-p compile-p force-recompile-p
)
857 "Control special variables that the find-actions tree recognizes" )
858 ;;;_ . elinstall-actions-for-source-file
859 (defun elinstall-actions-for-source-file (filename dir
)
860 "Return a list of actions to do for FILENAME in DIR.
861 Special variables are as noted in \"List of special variables\"."
863 load-path-element def-file compile-p force-recompile-p
))
866 (expand-file-name filename dir
)))
869 (file-readable-p full-path
)
870 (not (auto-save-file-name-p full-path
)))
871 ;;$$IMPROVE ME create and use relevant control variables.
874 (visited (get-file-buffer full-path
))
878 ;;Visit the file cheaply.
879 ;;hack-local-variables can give errors.
880 (ignore-errors (autoload-find-file full-path
))))
884 (with-current-buffer buf
885 (if (local-variable-p 'generated-autoload-file
)
886 (elinstall-expand-deffile-name
887 generated-autoload-file
)
890 ;;Figure out whether to run some actions, by file local vars.
893 (with-current-buffer buf
894 (not no-update-autoloads
))))
897 (featurep 'byte-compile
)
898 (string-match emacs-lisp-file-regexp filename
)
900 (with-current-buffer buf
901 (not no-byte-compile
)))
903 ((dest (byte-compile-dest-file full-path
)))
904 (if (file-exists-p dest
)
905 ;; File was already compiled.
906 (or force-recompile-p
907 (file-newer-than-file-p full-path dest
))
909 (y-or-n-p (concat "Compile " filename
"? "))))))))
914 `(byte-compile ,full-path
)
917 (elinstall-make-autoload-action
918 buf def-file load-path-element full-path
)
920 (unless visited
(kill-buffer-if-not-modified buf
)))))))
921 ;;;_ . elinstall-actions-for-dir
922 (defun elinstall-actions-for-dir (dirname &optional recurse-dirs-p
)
923 "Make actions for DIR.
924 Recurse just if RECURSE-DIRS-P"
926 load-path-element def-file add-to-load-path-p
))
927 ;;This does not treat symlinks specially. $$IMPROVE ME it could
928 ;;treat/not treat them conditional on control variables.
931 ;;Relative filenames of the source files. We know our
932 ;;loaddefs.el isn't really source so remove it. We'd have
933 ;;removed it anyways after seeing file local vars.
940 elinstall-elisp-regexp
)))
941 ;;Absolute filenames of subdirectories.
942 ;;Don't accept any directories beginning with dot. If user
943 ;;really wants to explore one he can use `(dir ".NAME")'.
950 (file-directory-p filename
)
960 elisp-source-files
;;If list is not empty.
968 ;;Sometimes arrange to add this directory to load-path.
975 ;;$$IMPROVE ME - be controlled by a control variable.
976 ;;Sometimes add this directory to info path.
978 (elinstall-dir-has-info dirname
)
987 (elinstall-actions-for-source-file
996 (elinstall-find-actions-by-spec-x
1004 ;;;_ . elinstall-find-actions-by-spec-x
1006 (defun elinstall-find-actions-by-spec-x (spec dir
)
1007 "Return a list of actions to do, controlled by SPEC."
1009 load-path-element def-file add-to-load-path-p
1022 (elinstall-find-actions-by-spec-x
1030 #'(lambda (sub-spec)
1031 (elinstall-find-actions-by-spec-x
1036 ;;(matching PATTERN SPEC)
1040 (elinstall-find-actions-by-spec-x
1044 dir t
(second spec
))))
1048 (elinstall-actions-for-source-file
1051 ;;Rather than trying to bind all control variables each time
1052 ;;thru, we use `set' and `unwind-protect'.
1054 ;;control TYPE DISPOSITION SPEC
1056 ((key (second spec
))
1058 (if (memq key elinstall-find-actions-control-vars
)
1061 (set old-value
(symbol-value key
))
1062 (set key
(third spec
))
1063 (elinstall-find-actions-by-spec-x
1066 (set key old-value
))
1067 (error "Unrecognized control variable %s" key
))))
1072 (elinstall-actions-for-dir
1082 `((add-to-load-path ,def-file
,dir
))
1084 ((load-path-element dir
))
1085 (elinstall-find-actions-by-spec-x
1091 ;;(def-file FN ARGS SPEC)
1097 (for-preload (third spec
)))
1098 (assert (listp for-preload
))
1102 (and for-preload
(car for-preload
))
1106 ,@(cdr for-preload
))
1109 (elinstall-find-actions-by-spec-x
1110 (fourth spec
) dir
)))))
1116 (elinstall-actions-for-dir dir nil
))
1118 (elinstall-actions-for-dir dir t
)))))
1120 ;;;_ . elinstall-find-actions-by-spec
1121 (defun elinstall-find-actions-by-spec (spec load-path-element dir def-file
)
1125 ((load-path-element load-path-element
)
1127 (add-to-load-path-p t
)
1129 (force-recompile-p nil
)
1132 load-path-element def-file add-to-load-path-p
1133 recurse-dirs-p force-recompile-p compile-p
))
1135 (elinstall-find-actions-by-spec-x
1138 ;;;_ . high-level work
1139 ;;;_ , elinstall-get-relevant-load-path
1140 (defun elinstall-get-relevant-load-path (actions)
1150 ;;;_ , elinstall-get-deffile-list
1151 (defun elinstall-get-deffile-list (stages)
1152 "Get a list of deffile names"
1156 (elinstall-stages->build-deffiles stages
)))
1158 (defun elinstall-x (dir spec
&optional force
)
1159 "High-level worker function to install elisp files."
1162 ;;This is just the default deffile, spec can override it.
1164 (elinstall-expand-deffile-name nil
))
1166 (elinstall-find-actions-by-spec
1171 (stages (elinstall-segregate-actions actions
))
1173 (elinstall-get-relevant-load-path
1176 (elinstall-stage-update-deffiles
1177 (elinstall-stages->build-deffiles stages
)
1180 (elinstall-stage-arrange-preloads
1181 (elinstall-stages->arrange-preloads stages
)
1182 (elinstall-get-deffile-list stages
)
1184 (elinstall-stage-byte-compile
1185 (elinstall-stages->byte-compile stages
))
1190 (defun elinstall (project-name path spec
&optional force version-string
)
1191 "Install elisp files.
1192 They need not be a formal package.
1196 PROJECT-NAME - the name of the project
1198 PATH - Path to the project.
1199 Suggestion: (elinstall-directory-true-name)
1201 SPEC - a spec for the autoloads etc to make. It can be as simple as
1202 \(dir \"\.\") for installing one directory.
1204 If FORCE is t, install a package even if it has already been
1205 installed. Other non-nil cases of FORCE are reserved for future
1211 (not (elinstall-already-installed project-name
))
1212 (yes-or-no-p (format "Re-install %s? " project-name
)))
1215 `(def-file "loaddefs.el" (if-used ,project-name
) ,spec
)
1217 (elinstall-record-installed project-name version-string
)))
1221 ;;;_ . elinstall-update-directory-autoloads
1223 ;;The control variables and values of `force' that would stop other
1224 ;;actions don't exist yet. Similarly for
1225 ;;`elinstall-update-file-autoloads'.
1227 (defun elinstall-update-directory-autoloads (dir)
1228 "Update autoloads for directory DIR"
1230 (interactive "DUpdate autoloads for all elisp files from directory: ")
1233 `(control compile-p nil
1236 ;;;_ . elinstall-update-directory
1238 (defun elinstall-update-directory (dir)
1239 "Update autoloads for directory DIR"
1241 (interactive "DInstall all elisp files from directory: ")
1246 ;;;_ . elinstall-update-file-autoloads
1248 (defun elinstall-update-file-autoloads (file)
1249 "Update autoloads for elisp file FILE"
1251 (interactive "fUpdate autoloads for elisp file: ")
1254 `(control compile-p nil
1257 ;;;_ . elinstall-update-file
1259 (defun elinstall-update-file (file)
1260 "Install elisp file FILE"
1262 (interactive "fInstall elisp file: ")
1270 (provide 'elinstall
)
1272 ;;;_ * Local emacs vars.
1273 ;;;_ + Local variables:
1278 ;;; elinstall.el ends here