1 ;;;_ elinstall.el --- Automatically and flexibly install elisp files
5 ;; Copyright (C) 2010 Tom Breton (Tehom)
7 ;; Author: Tom Breton (Tehom) <tehom@panix.com>
8 ;; Keywords: maint, tools, internal
10 ;; This file is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This file is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
30 ;; elinstall Use this for overall loading
32 ;; elinstall-arrange-preload - Use this for non-autogenerated
33 ;; files that need to be linked in.
35 ;; elinstall-update-directory-autoloads
36 ;; elinstall-update-file-autoloads
42 (require 'cus-edit
) ;;Because we save "installedness" manually
43 (require 'byte-compile nil t
) ;;
51 "Customizations for elinstall"
53 ;;;_ . elinstall-default-priority
54 (defcustom elinstall-default-priority
56 "Default priority for site-start"
59 ;;;_ . elinstall-default-preload-target
60 (defcustom elinstall-default-preload-target
61 "~/.emacs.d/site-start.d/"
62 "Default preload-target for registering autoloads"
66 (const "~/.emacs.d/site-start.d/")
67 (const "/etc/emacs/site-start.d/")
71 ;;;_ . elinstall-restrain-install
72 (defcustom elinstall-restrain-install
'()
73 "Restrain elinstall for specific packages"
78 (choice :format
"%[%t%]: %v"
79 (string :tag
"Package name")
80 (const :tag
"All packages" t
))
84 ;;;_ . elinstall-already-installed
86 (defcustom elinstall-already-installed
88 "(AUTOMATIC) Things that have already been installed.
89 This exists for recording what has been installed.
91 Though it's saved as customizable, user interaction is not
93 ;;Tell the byte-compiler it's a variable.
94 (defvar elinstall-already-installed
)
96 ;;;_ . elinstall-stages
97 (defstruct (elinstall-stages
98 (:constructor elinstall-make-stages
)
99 (:conc-name elinstall-stages-
>)
101 "The elinstall stages"
107 ;;;_ . Regular expressions
108 ;;;_ , elinstall-elisp-regexp
109 (defconst elinstall-elisp-regexp
112 (suf (get-load-suffixes))
113 (unless (string-match "\\.elc" suf
) (push suf tmp
)))
114 (concat "^[^=.].*" (regexp-opt tmp t
) "\\'"))
115 "Regular expression that matches elisp files" )
117 ;;;_ . elinstall-file-mod-time
118 (defsubst elinstall-file-mod-time
(file)
119 "Return the modification time of FILE"
120 (nth 5 (file-attributes file
)))
122 ;;;_ . elinstall-directory-true-name
123 (defun elinstall-directory-true-name ()
124 "Get the true name of the directory the calling code lives in.
125 CAUTION: This is sensitive to where it's called. That's the point of it."
128 (file-truename load-file-name
)
129 (file-truename buffer-file-name
))))
130 ;;;_ . Checking installedness
131 ;;;_ , elinstall-get-installation-record
132 (defun elinstall-get-installation-record (project-name)
133 "Return the installation record for PROJECT-NAME."
135 (assoc project-name elinstall-already-installed
))
137 ;;;_ , elinstall-already-installed
138 (defun elinstall-already-installed (project-name)
139 "Return non-nil if PROJECT-NAME has been installed."
140 (elinstall-get-installation-record project-name
))
142 ;;;_ , elinstall-record-installed
143 (defun elinstall-record-installed (project-name &optional version
)
144 "Record that PROJECT-NAME has been installed."
153 (elinstall-get-installation-record project-name
))
157 (setq elinstall-already-installed
158 (delete old-item elinstall-already-installed
)))
159 (push new-item elinstall-already-installed
)
160 (customize-save-variable
161 'elinstall-already-installed
162 elinstall-already-installed
163 "Set by elinstall-record-installed")))
164 ;;;_ . Finding deffiles
165 ;;;_ , elinstall-expand-deffile-name
166 (defun elinstall-expand-deffile-name (deffile)
167 "Expand DEFFILE autoload.el's way."
169 (expand-file-name (or deffile
"loaddefs.el")
170 (expand-file-name "lisp"
172 ;;;_ . Checking restraint specs
173 (defun elinstall-proceed-p (topic restraints-1 restraints-2 old-p
174 redo-prompt ask-prompt
)
175 "Return non-nil if actions on TOPIC should proceed."
177 (check-type topic symbol
)
179 ( (cell (assq topic restraints-1
))
182 (or (not cell
) (eq (second cell
) t
))
183 (assq topic restraints-2
)
194 (y-or-n-p redo-prompt
)
197 (y-or-n-p ask-prompt
)))))
202 ;;;_ , Doing autoload actions (adapted from autoload.el)
203 ;;;_ . Utilities about the action list
204 ;;;_ , elinstall-remove-autogen-action
205 (defun elinstall-remove-autogen-action (file actions
)
206 "Return ACTIONS minus any add-file-autoloads on FILE removed."
213 (if (equal file
(third act
))
218 ;;;_ , elinstall-get-autogen-action
219 (defun elinstall-get-autogen-action (file actions
)
223 (dolist (act actions
)
226 (when (equal file
(third act
))
227 (setq the-act act
)))))
229 ;;;_ . About printing to autoload file
230 ;;;_ , elinstall-insert-section-header
231 (defun elinstall-insert-section-header (outbuf form
)
232 "Insert the section-header line,
233 which lists the file name and which functions are in it, etc."
234 (insert generate-autoload-section-header
)
237 ;; Break that line at spaces, to avoid very long lines.
238 ;; Make each sub-line into a comment.
239 (with-current-buffer outbuf
244 (skip-chars-forward "^ \n")
246 (insert "\n" generate-autoload-section-continuation
))))))
248 ;;;_ , elinstall-insert-autoload-section
249 (defun elinstall-insert-autoload-section (text form
&optional comment-string
)
250 "Insert TEXT into current buffer as an autoload section"
255 ;; This does something in Lucid Emacs.
257 (float-output-format nil
))
259 (elinstall-insert-section-header (current-buffer) form
)
261 (insert ";;; " comment-string
"\n"))
263 (insert generate-autoload-section-trailer
)))
265 ;;;_ . Making autoloads
266 ;;;_ , elinstall-make-autoload-action
267 (defun elinstall-make-autoload-action (buf def-file load-path-element full-path
)
268 "Return the autoloads for current buffer as a string"
270 ;;We put all the text into a temp buffer, then get that buffer's
274 (generate-new-buffer " *temp*"))
277 (file-name-nondirectory full-path
))
281 ;; Apparently this does something in Lucid Emacs.
283 (float-output-format nil
)
285 ;;load-name relative to a member of load-path.
287 (file-name-sans-extension
290 load-path-element
))))
292 (with-current-buffer buf
297 (goto-char (point-min))
298 (message "Finding autoloads for %s..." short-name
)
300 (skip-chars-forward " \t\n\f")
302 ((looking-at (regexp-quote generate-autoload-cookie
))
303 (search-forward generate-autoload-cookie
)
304 (skip-chars-forward " \t")
306 ;; Read the next form and make an autoload.
307 (let* ((form (prog1 (read (current-buffer))
308 (or (bolp) (forward-line 1))))
310 (make-autoload form relative-name
)))
312 (push (nth 1 form
) autoloads-done
)
313 (setq autoload form
))
314 (let ((autoload-print-form-outbuf outbuf
))
315 (autoload-print-form autoload
)))
317 ;; Copy the rest of the line to the output.
318 (princ (buffer-substring
320 ;; Back up over whitespace,
322 (skip-chars-backward " \f\t")
323 (if (= (char-after (1+ (point))) ?
)
327 (progn (forward-line 1) (point)))
330 ;; Don't read the comment.
335 (message "Finding autoloads for %s...done" short-name
))
337 ;;Return this action. The temp buffer's contents is
343 ,(with-current-buffer outbuf
(buffer-string))
346 ;;This in unwind-protected
347 (when (buffer-live-p outbuf
) (kill-buffer outbuf
))))))
350 ;;;_ , elinstall-generate-file-autoloads
352 (defun elinstall-generate-file-autoloads
353 (relative-name full-name text autoloads-done
)
354 "Insert at point a loaddefs autoload section for FILE.
355 Autoloads are generated for defuns and defmacros in FILE
356 marked by `generate-autoload-cookie' (which see).
357 If FILE is being visited in a buffer, the contents of the buffer
359 Return non-nil in the case where no autoloads were added at point.
361 FULL-NAME is the absolute name of the file.
362 RELATIVE-NAME is its name respective to some component of load-path."
363 (if (not (equal text
""))
364 ;; Insert the section-header line which lists the file name and
365 ;; which functions are in it, etc.
366 (elinstall-insert-autoload-section
371 (autoload-trim-file-name full-name
)
372 (elinstall-file-mod-time full-name
))
374 "Generated autoloads from "
375 (autoload-trim-file-name full-name
)))
378 ;;;_ , elinstall-deffile-insert-autoloads
379 (defun elinstall-deffile-insert-autoloads (file args
)
380 "Update the autoloads for FILE in current buffer.
381 Return FILE if there was no autoload cookie in it, else nil.
383 Current buffer must be a loaddef-style file.
385 LOAD-NAME is the absolute name of the file.
386 RELATIVE-NAME is its name respective to some component of load-path."
394 (goto-char (point-min))
395 ;; Look for the section for FILE
396 (while (and (not found
)
397 (search-forward generate-autoload-section-header nil t
))
398 (let ((form (autoload-read-section-header)))
400 ((equal (nth 2 form
) file
)
401 ;; We found the section for this file.
402 (let ((begin (match-beginning 0)))
404 (search-forward generate-autoload-section-trailer
)
405 (delete-region begin
(point))
407 ((string< file
(nth 2 form
))
408 ;; We've come to a section alphabetically later than
409 ;; FILE. We assume the file is in order and so
410 ;; there must be no section for FILE. We will
411 ;; insert one before the section here.
412 (goto-char (match-beginning 0))
413 (setq found
'new
)))))
417 ;; No later sections in the file. Put before the last page.
418 (goto-char (point-max))
419 (search-backward "\f" nil t
)))
421 (apply #'elinstall-generate-file-autoloads
424 (if no-autoloads file nil
)))
425 ;;;_ . Arranging to add to info-path and load-path
426 ;;;_ , elinstall-generate-add-to-path
427 (defun elinstall-generate-add-to-path (path-element type
)
428 "Insert code at point to add PATH-ELEMENT to a path.
430 * `add-to-load-path', add to load-path
431 * `add-to-info-path', add to Info-additional-directory-list
433 Current buffer must be a loaddef-style file."
436 (add-to-load-path 'load-path
)
437 (add-to-info-path 'Info-additional-directory-list
)
438 (t (error "Type not recognized"))))
441 (add-to-load-path "load-path")
442 (add-to-info-path "info-path")))
446 ;; This does something in Lucid Emacs.
448 (float-output-format nil
))
450 (message "Generating %s additions..." description
)
452 (elinstall-insert-autoload-section
454 `(add-to-list ',path-symbol
456 ,(file-relative-name path-element
)
459 (file-truename load-file-name
))))))
460 (list type
(list path-element
) nil nil nil
)
462 (message "Generating %s additions...done" description
)))
465 ;;;_ , elinstall-deffile-insert-add-to-path
466 (defun elinstall-deffile-insert-add-to-path (path-element type
)
467 "Insert code in current buffer to add PATH-ELEMENT to a path.
469 * `add-to-load-path', add to load-path
470 * `add-to-info-path', add to Info-default-directory-list
472 Current buffer must be a loaddef-style file."
480 (goto-char (point-min))
481 ;; Look for the section for PATH-ELEMENT
482 (while (and (not found
)
483 (search-forward generate-autoload-section-header nil t
))
484 (let ((form (autoload-read-section-header)))
487 (equal (nth 0 form
) type
)
488 (member path-element
(nth 1 form
)))
490 ;; We found the section for this add.
491 (let ((begin (match-beginning 0)))
493 (search-forward generate-autoload-section-trailer
)
494 (delete-region begin
(point))
500 ;; No later sections in the file. Put before the last page.
501 (goto-char (point-max))
502 (search-backward "\f" nil t
)))
504 (elinstall-generate-add-to-path path-element type
)))
506 ;;This never belongs in the no-autoloads section.
508 ;;;_ . elinstall-deffile-insert
510 (defun elinstall-deffile-insert (action)
511 "Insert autoloads etc into current file according to ACTION.
512 The format of ACTION is described in the design docs.
514 Return filename if this action belongs in the no-autoload section."
519 (elinstall-deffile-insert-autoloads
524 (elinstall-deffile-insert-add-to-path
530 (elinstall-deffile-insert-add-to-path
535 ((preload-file run-tests byte-compile
)
536 (error "This case should not come here.")))))
538 ;;;_ . elinstall-prepare-deffile
539 (defun elinstall-prepare-deffile (deffile)
540 "Try to ensure that DEFFILE is available for receiving autoloads"
542 (autoload-ensure-default-file deffile
)
543 (with-current-buffer (find-file-noselect deffile
)
546 ;; We must read/write the file without any code conversion,
547 ;; but still decode EOLs.
548 (let ((coding-system-for-read 'raw-text
))
550 ;; This is to make generated-autoload-file have Unix EOLs, so
551 ;; that it is portable to all platforms.
552 (setq buffer-file-coding-system
'raw-text-unix
))
553 (or (> (buffer-size) 0)
554 (error "Autoloads file %s does not exist" buffer-file-name
))
555 (or (file-writable-p buffer-file-name
)
556 (error "Autoloads file %s is not writable"
559 ;;;_ . elinstall-update-deffile
561 ;;Adapted from autoload.el `update-directory-autoloads'.
563 (defun elinstall-update-deffile (target actions
&optional
566 Update file TARGET with current autoloads as specified by ACTIONS.
567 Also remove any old definitions pointing to libraries that can no
570 ACTIONS must be a list of actions (See the format doc). Each one's
571 filename must be relative to some element of load-path.
573 USE-LOAD-PATH is a list to use as load-path. It should include
574 any new load-path that we are arranging to create. If it's not given,
575 load-path itself is used.
577 If FORCE is `t', do it regardless of timestamps etc. (Not implemented)
578 Other non-nil cases of FORCE are reserved for future development.
580 This uses `update-file-autoloads' (which see) to do its work.
581 In an interactive call, you must give one argument, the name
582 of a single directory."
585 (use-load-path (or use-load-path load-path
))
586 (this-time (current-time))
587 ;;files with no autoload cookies.
590 (elinstall-prepare-deffile target
)
592 (find-file-noselect target
)
595 (elinstall-remove-autogen-action
596 (autoload-trim-file-name target
)
599 (goto-char (point-min))
600 (while (search-forward generate-autoload-section-header nil t
)
601 (let* ((form (autoload-read-section-header))
603 (cond ((and (consp file
) (stringp (car file
)))
604 ;; This is a list of files that have no
606 ;; There shouldn't be more than one such entry.
607 ;; Remove the obsolete section.
608 (autoload-remove-section (match-beginning 0))
609 (let ((last-time (nth 4 form
)))
611 (let ((file-time (elinstall-file-mod-time file
)))
613 (not (time-less-p last-time file-time
)))
615 (push file no-autoloads
)
617 (elinstall-remove-autogen-action
619 ((not (stringp file
)))
623 (locate-library file nil use-load-path
)))
625 ;;File doesn't exist, so remove its
628 (autoload-remove-section
629 (match-beginning 0)))
631 ;; File hasn't changed, so do nothing.
634 (elinstall-file-mod-time file-path
))
637 (elinstall-deffile-insert
638 (elinstall-get-autogen-action
642 (elinstall-remove-autogen-action
645 ;; Remaining actions have no existing autoload sections yet.
648 (delq nil
(mapcar #'elinstall-deffile-insert actions
))))
650 ;; Sort them for better readability.
651 (setq no-autoloads
(sort no-autoloads
'string
<))
652 ;; Add the `no-autoloads' section.
653 (goto-char (point-max))
654 (search-backward "\f" nil t
)
655 (elinstall-insert-autoload-section
657 (list 'autoloads nil nil no-autoloads this-time
)))
660 ;;;_ . elinstall-stage-update-deffiles
661 (defun elinstall-stage-update-deffiles (segment-list force use-load-path
)
662 "Update any deffiles mentioned in SEGMENT-LIST.
663 FORCE and USE-LOAD-PATH have the same meaning as in
664 `elinstall-update-deffile'.
669 ((deffile (car segment
)))
670 (if (stringp deffile
)
671 (elinstall-update-deffile deffile
(cdr segment
) force
675 ;;;_ , Doing actions to arrange preloads
676 ;;;_ . elinstall-symlink-on-emacs-start
677 (defun elinstall-symlink-on-emacs-start
678 (filename target-basename target-dir
&optional priority force
)
679 "Symlink to TARGET-BASENAME.el in TARGET-DIR
681 If PRIORITY is given, it will be used as the priority prefix,
682 otherwise elinstall-default-priority will be.
683 PRIORITY must be an integer or nil.
684 If FORCE is `t', do it regardless of timestamps etc.
685 Other non-nil cases of FORCE are reserved for future development."
688 (priority (or priority elinstall-default-priority
))
695 (expand-file-name target-name-nodir target-dir
)))
699 ;;Path should already exist.
701 (file-exists-p target-dir
))
702 (message "The target directory doesn't exist."))
703 ;;Target shouldn't already exist, but if force is given, let
705 ;;$$IMPROVE ME If it is a symlink pointing to the same place,
706 ;;do nothing even on force.
708 (file-exists-p target
)
713 (format "Really overwrite %s? " target
))))
714 (message "File %s already exists" target
)))
722 ;;;_ . elinstall-add-to-dot-emacs
723 (defun elinstall-add-to-dot-emacs (dot-emacs-name filename force
&rest r
)
724 "Add code to load FILENAME to .emacs.
725 FILENAME should not have an extension"
728 (with-current-buffer (find-file-noselect dot-emacs-name
)
731 (goto-char (point-max))
732 (insert "\n;;Added by elinstall")
733 (insert "\n;;Consider using my-site-start to manage .emacs\n")
734 (pp `(load ,filename
) (current-buffer))
738 ;;;_ . elinstall-arrange-preload
740 (defun elinstall-arrange-preload (force filename basename
&optional priority
)
741 "Arrange for FILENAME to be loaded on emacs start.
742 FORCE has its usual meaning.
743 BASENAME and PRIORITY are used as arguments to
744 `elinstall-symlink-on-emacs-start'.
748 ((preload-target elinstall-default-preload-target
))
750 ;;Dispatch the possibilities.
752 ((eq preload-target
'dot-emacs
)
753 (elinstall-add-to-dot-emacs "~/.emacs" filename force
))
754 ((stringp preload-target
)
755 (elinstall-symlink-on-emacs-start
756 filename basename preload-target priority force
))
757 ((null preload-target
)
758 (message "Not arranging for preloads"))
760 (message "I don't recognize that")))))
761 ;;;_ . elinstall-stage-arrange-preloads
762 (defun elinstall-stage-arrange-preloads (actions deffiles-used force
)
763 "Arrange any preloads mentioned in ACTIONS."
777 (member filename deffiles-used
)))))
781 #'elinstall-arrange-preload
786 "elinstall-stage-arrange-preloads: Action not
792 ;;;_ . elinstall-stage-run-tests
793 (defun elinstall-stage-run-tests (actions)
794 "Run any tests mentioned in ACTIONS."
800 ;;$$WRITE ME - not a high priority right now.
804 "elinstall-stage-run-tests: Action not
810 ;;;_ . elinstall-stage-byte-compile
811 (defun elinstall-stage-byte-compile (actions)
812 "Do any byte-compilation mentioned in ACTIONS."
817 ;;$$IMPROVE ME Understand flags to control second
818 ;;argument (whether to load file after
821 (byte-compile-file (second act
)))
824 "elinstall-stage-byte-compile: Action not
827 ;;;_ . Segregating actions
828 ;;;_ , elinstall-remove-empty-segs
829 (defun elinstall-remove-empty-segs (segment-list)
830 "Return SEGMENT-LIST minus any segments that have no actions.
831 Intended only for the deffile stage data."
840 ;;;_ , elinstall-segregate-actions
841 (defun elinstall-segregate-actions (actions)
842 "Return actions segregated by deffile.
844 Returns a list whose elements are each a cons of:
845 * deffile filename or nil
846 * A list of actions to be done for that deffile."
853 (arrange-preloads '()))
855 (dolist (act actions
)
862 ((deffile-name (second act
))
864 (assoc deffile-name build-deffiles
)))
866 ;;There are already actions on this deffile.
867 ;;Splice this action in.
869 (cons act
(cdr cell-already
)))
870 ;;There are no actions on this deffile. Add a
871 ;;place for them and include this action.
872 (push (list deffile-name act
) build-deffiles
))))
874 (push act arrange-preloads
))
876 (push act run-tests
))
878 (push act byte-compile
)))))
880 (elinstall-make-stages
882 (elinstall-remove-empty-segs build-deffiles
)
889 ;;;_ . Finding actions
891 ;;;_ . elinstall-dir-has-info
893 ;;$$IMPROVE ME - Can this test be made more precise?
894 (defun elinstall-dir-has-info (dir)
895 "Return non-nil if DIR has info files in it.
896 DIR should be an absolute path."
898 (string-match "/info/" dir
)
899 (directory-files dir nil
"\\.info\\(-[0-9]+\\)?\\(\\.gz\\)?$")))
900 ;;;_ . elinstall-directory-files
901 (defun elinstall-directory-files (dirname)
902 "Return a list of files in directory DIRNAME, minus certain files.
903 The following files are omitted:
905 * Files that match an entry in `block-in-subtree'.
906 Filenames are relative."
908 def-file block-in-dir block-in-subtree
))
911 ;;Relative filenames of this directory's files.
913 ;; Don't include dot files. If user really wants to
914 ;;explore one he can use (dir ".NAME") or (file ".NAME")
915 (directory-files dirname nil
"[^\\.]"))
916 ;;We know our def-file isn't really source so remove it.
917 ;;We'd have removed it anyways after seeing file local vars.
919 (remove def-file all-files
))
930 (string-match blocked filename
))
939 ;;;_ . List of special variables used in this section
940 ;;load-path-element - The relevant element of load-path
941 ;;def-file - The file the autoload definitions etc will go into.
942 ;;add-to-load-path-p - Controls whether to add to load-path.
943 ;;recurse-dirs-p - Whether to recurse into subdirectories.
945 ;;block-in-dir - (NOT IMPLEMENTED) List of filenames to reject. They
946 ;;may include wildcards. They apply wrt the original directory.
948 ;;block-in-subtree - (NOT IMPLEMENTED) List of filenames to reject.
949 ;;They may include wildcards. They apply wrt any directory in the
950 ;;tree. Specifically, in the spec tree, which may differ from the
952 ;;byte-compile - whether to byte-compile at all, t by default. If it's
953 ;;`ask', prompt the user unless recompiling an out-of-date file.
954 ;;make-autoloads - boolean whether to make autoloads, t by default.
955 ;;setup-preloads - boolean whether to set up preloads, t by default.
956 (defconst elinstall-find-actions-control-vars
957 '(add-to-load-path-p recurse-dirs-p byte-compile
958 make-autoloads setup-preloads
)
959 "Control special variables that the find-actions tree recognizes" )
960 ;;;_ . elinstall-actions-for-source-file
961 (defun elinstall-actions-for-source-file (filename dir
)
962 "Return a list of actions to do for FILENAME in DIR.
963 Special variables are as noted in \"List of special variables\"."
965 load-path-element def-file byte-compile
))
968 (expand-file-name filename dir
)))
971 (file-readable-p full-path
)
972 (not (auto-save-file-name-p full-path
)))
973 ;;$$IMPROVE ME create and use relevant control variables.
976 (visited (get-file-buffer full-path
))
980 ;;Visit the file cheaply.
981 ;;hack-local-variables can give errors.
982 (ignore-errors (autoload-find-file full-path
))))
986 (with-current-buffer buf
987 (if (local-variable-p 'generated-autoload-file
)
988 (elinstall-expand-deffile-name
989 generated-autoload-file
)
992 ;;Figure out whether to run some actions, by file local vars.
995 (with-current-buffer buf
996 (not no-update-autoloads
))))
1000 (featurep 'byte-compile
)
1001 (string-match emacs-lisp-file-regexp filename
)
1003 (with-current-buffer buf
1004 (not no-byte-compile
)))
1006 ((dest (byte-compile-dest-file full-path
))
1009 ((file-exists-p dest
)
1010 (or (eq byte-compile
'always
)
1011 (file-newer-than-file-p full-path dest
)))
1012 ((memq byte-compile
'(t update ask
))
1014 (if (eq byte-compile
'ask
)
1018 (concat "Compile " filename
"? ")))
1024 `(byte-compile ,full-path
)
1027 (elinstall-make-autoload-action
1028 buf def-file load-path-element full-path
)
1030 (unless visited
(kill-buffer-if-not-modified buf
)))))))
1031 ;;;_ . elinstall-actions-for-dir
1032 (defun elinstall-actions-for-dir (dirname &optional recurse-dirs-p
)
1033 "Make actions for DIR.
1034 Recurse just if RECURSE-DIRS-P"
1036 load-path-element def-file add-to-load-path-p
))
1037 ;;This does not treat symlinks specially. $$IMPROVE ME it could
1038 ;;treat/not treat them conditional on control variables.
1041 (files (elinstall-directory-files dirname
))
1043 ;;Relative filenames of elisp source
1047 #'(lambda (filename)
1049 (string-match elinstall-elisp-regexp filename
)
1054 ;;Absolute filenames of subdirectories.
1059 #'(lambda (filename)
1061 ((fn (expand-file-name filename dirname
)))
1063 (file-directory-p fn
)
1071 elisp-source-files
;;If list is not empty.
1072 add-to-load-path-p
))
1074 (if load-path-here-p
1076 load-path-element
)))
1079 ;;Sometimes arrange to add this directory to load-path.
1080 (if load-path-here-p
1083 ,load-path-element
))
1086 ;;$$IMPROVE ME - be controlled by a control variable.
1087 ;;Sometimes add this directory to info path.
1089 (elinstall-dir-has-info dirname
)
1097 #'(lambda (filename)
1098 (elinstall-actions-for-source-file
1101 elisp-source-files
))
1106 #'(lambda (filename)
1107 (elinstall-find-actions-by-spec-x
1115 ;;;_ . elinstall-find-actions-by-spec-x
1117 (defun elinstall-find-actions-by-spec-x (spec dir
)
1118 "Return a list of actions to do, controlled by SPEC."
1120 load-path-element def-file add-to-load-path-p
1121 recurse-dirs-p block-in-dir block-in-subtree
))
1129 #'(lambda (sub-spec)
1130 (elinstall-find-actions-by-spec-x
1135 ;;(block-in-subtree (* FN) SPEC)
1137 ((block-in-subtree (second spec
)))
1138 (elinstall-find-actions-by-spec-x
1142 ;;Rather than trying to bind all control variables each time
1143 ;;thru, we use `set' and `unwind-protect'.
1145 ;;control TYPE DISPOSITION SPEC
1147 ((key (second spec
))
1149 (if (memq key elinstall-find-actions-control-vars
)
1152 (setq old-value
(symbol-value key
))
1153 (set key
(third spec
))
1154 (elinstall-find-actions-by-spec-x
1157 (set key old-value
))
1158 (error "Unrecognized control variable %s" key
))))
1162 ;;(def-file FN ARGS SPEC)
1168 (for-preload (third spec
)))
1169 (assert (listp for-preload
))
1173 (and for-preload
(car for-preload
))
1177 ,@(cdr for-preload
))
1180 (elinstall-find-actions-by-spec-x
1181 (fourth spec
) dir
))))
1185 (elinstall-actions-for-dir
1193 (elinstall-actions-for-source-file
1204 (elinstall-find-actions-by-spec-x
1211 `((add-to-load-path ,def-file
,dir
))
1213 ((load-path-element dir
)
1214 (add-to-load-path-p nil
))
1215 (elinstall-find-actions-by-spec-x
1220 ;;(matching PATTERN SPEC)
1224 ;;$$PUNT Assume that `block-in-subtree' and
1225 ;;`block-in-dir' aren't matched.
1226 (elinstall-find-actions-by-spec-x
1230 dir t
(second spec
)))))
1232 ;;(preload FN SYM &rest ARGS)
1234 ((key (third spec
)))
1236 (and (symbolp key
) (symbol-value key
))
1239 ,(expand-file-name (second spec
) dir
)
1246 (elinstall-actions-for-dir dir nil
))
1248 (elinstall-actions-for-dir dir t
)))))
1250 ;;;_ . elinstall-find-actions-by-spec
1251 (defun elinstall-find-actions-by-spec
1252 (spec load-path-element dir def-file redo-old
)
1253 "Find the list of actions to do according to SPEC."
1257 (def-file-time (elinstall-file-mod-time def-file
))
1258 (add-to-load-path-p t
)
1264 (block-in-subtree '(".git" "RCS" "CVS" "SVN" "^tests\.el")))
1267 load-path-element def-file add-to-load-path-p
1268 recurse-dirs-p byte-compile
1269 block-in-dir block-in-subtree
))
1271 (elinstall-find-actions-by-spec-x spec dir
)))
1273 ;;;_ . high-level work
1274 ;;;_ , elinstall-get-relevant-load-path
1275 (defun elinstall-get-relevant-load-path (actions)
1285 ;;;_ , elinstall-get-deffile-list
1286 (defun elinstall-get-deffile-list (stages)
1287 "Get a list of deffile names"
1291 (elinstall-stages->build-deffiles stages
)))
1293 (defun elinstall-x (dir spec
&optional force
)
1294 "High-level worker function to install elisp files."
1297 ;;This is just the default deffile, spec can override it.
1299 (elinstall-expand-deffile-name nil
))
1301 (elinstall-find-actions-by-spec
1306 (eq force
'redo-old
)))
1307 (stages (elinstall-segregate-actions actions
))
1309 (elinstall-get-relevant-load-path
1312 (elinstall-stage-update-deffiles
1313 (elinstall-stages->build-deffiles stages
)
1316 (elinstall-stage-arrange-preloads
1317 (elinstall-stages->arrange-preloads stages
)
1318 (elinstall-get-deffile-list stages
)
1320 (elinstall-stage-byte-compile
1321 (elinstall-stages->byte-compile stages
))
1326 (defun elinstall (project-name path spec
&optional force version-string
)
1327 "Install elisp files.
1328 They need not be a formal package.
1332 PROJECT-NAME - the name of the project
1334 PATH - Path to the project.
1335 Suggestion: Use (elinstall-directory-true-name) to get the real
1336 current directoery name even from loaded files.
1338 SPEC - a spec for the autoloads etc to make. It can be as simple as
1339 \(dir \"\.\") for installing one directory.
1341 If FORCE is t, install a package even if it has already been
1342 installed. If it's a list, it's treated as a list of
1343 installation restraints. User customizations override this
1346 ;;$$IMPROVE ME - override these with user spec if there's one given
1351 '((install 'always
))
1353 (when ;;(elinstall-proceed-p 'install restraints)
1357 ((cell (assq 'install restraints
)))
1358 (and cell
(eq (second cell
) 'always
)))
1359 (not (elinstall-already-installed project-name
))
1360 (yes-or-no-p (format "Re-install %s? " project-name
)))
1363 `(def-file "loaddefs.el" (if-used ,project-name
) ,spec
)
1365 (elinstall-record-installed project-name version-string
))))
1369 ;;;_ . elinstall-update-directory-autoloads
1372 (defun elinstall-update-directory-autoloads (dir)
1373 "Update autoloads for directory DIR"
1375 (interactive "DUpdate autoloads for all elisp files from directory: ")
1378 `(control byte-compile nil
1381 ;;;_ . elinstall-update-directory
1383 (defun elinstall-update-directory (dir)
1384 "Update autoloads for directory DIR"
1386 (interactive "DInstall all elisp files from directory: ")
1391 ;;;_ . elinstall-update-file-autoloads
1393 (defun elinstall-update-file-autoloads (file)
1394 "Update autoloads for elisp file FILE"
1396 (interactive "fUpdate autoloads for elisp file: ")
1398 (file-name-directory file
)
1399 `(control byte-compile nil
1400 (file ,(file-name-nondirectory file
)))))
1402 ;;;_ . elinstall-update-file
1404 (defun elinstall-update-file (file)
1405 "Install elisp file FILE"
1407 (interactive "fInstall elisp file: ")
1409 (file-name-directory file
)
1410 `(file ,(file-name-nondirectory file
))))
1415 (provide 'elinstall
)
1417 ;;;_ * Local emacs vars.
1418 ;;;_ + Local variables:
1423 ;;; elinstall.el ends here