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 ;;;_ , elinstall-call-with-restraints
174 (defun elinstall-call-with-restraints (restraints package func
&rest args
)
175 "Call FUNC with ARGS, in scope of RESTRAINTS.
176 RESTRAINTS is a list of package restraints. User restraints for the
177 given package will also be applied in scope.
179 PACKAGE can be `t' or a string naming a package."
182 ((elinstall:*pkg-restraints
* restraints
)
183 ;;$$PUNT for now. Figure out user restraints for this
185 (elinstall:*user-restraints
*
188 elinstall
:*pkg-restraints
*
189 elinstall
:*user-restraints
*))
192 (defun elinstall-proceed-p
193 (topic message-params
&optional already-p
)
194 "Return non-nil if actions on TOPIC should proceed.
195 Call this transitively only thru `elinstall-call-with-restraints'.
196 TOPIC is a symbol indicating the topic, such as `byte-compile'.
197 MESSAGE-PARAMS is a cons of:
198 * A list of format strings:
199 * To ask whether to do this action
200 * To ask whether to redo this action, for `ask-for-old'
201 * To report that this action was skipped because already done.
202 * The arguments to the formatter.
203 ALREADY-P is an extended boolean whether the task has been done
204 before, if caller can tell."
206 (check-type topic symbol
)
208 elinstall
:*pkg-restraints
*
209 elinstall
:*user-restraints
*))
211 (boundp 'elinstall
:*pkg-restraints
*)
212 (boundp 'elinstall
:*user-restraints
*))
213 (error "elinstall-proceed-p called out of scope"))
216 ((ask-prompt &optional redo-prompt noredo-msg
) &rest message-args
)
219 ( ;;Get the applicable cell. We look in several places.
220 (cell (assq topic elinstall
:*user-restraints
*))
221 (cell (or cell
(assq t elinstall
:*user-restraints
*)))
223 ;;`t' means use the pkg-restraints value instead.
225 (or (not cell
) (eq (second cell
) t
))
226 (assq topic elinstall
:*pkg-restraints
*)
228 (cell (or cell
(assq t elinstall
:*pkg-restraints
*)))
230 ;;Default is to just update.
231 (if cell
(second cell
) 'update
)))
240 (apply #'message noredo-msg message-args
)
245 (y-or-n-p (apply #'format redo-prompt message-args
))
249 (apply #'format ask-prompt message-args
)))))))
254 ;;;_ , Doing autoload actions (adapted from autoload.el)
255 ;;;_ . Utilities about the action list
256 ;;;_ , elinstall-remove-autogen-action
257 (defun elinstall-remove-autogen-action (file actions
)
258 "Return ACTIONS minus any add-file-autoloads on FILE removed."
265 (if (equal file
(third act
))
270 ;;;_ , elinstall-get-autogen-action
271 (defun elinstall-get-autogen-action (file actions
)
275 (dolist (act actions
)
278 (when (equal file
(third act
))
279 (setq the-act act
)))))
281 ;;;_ . About printing to autoload file
282 ;;;_ , elinstall-insert-section-header
283 (defun elinstall-insert-section-header (outbuf form
)
284 "Insert the section-header line,
285 which lists the file name and which functions are in it, etc."
286 (insert generate-autoload-section-header
)
289 ;; Break that line at spaces, to avoid very long lines.
290 ;; Make each sub-line into a comment.
291 (with-current-buffer outbuf
296 (skip-chars-forward "^ \n")
298 (insert "\n" generate-autoload-section-continuation
))))))
300 ;;;_ , elinstall-insert-autoload-section
301 (defun elinstall-insert-autoload-section (text form
&optional comment-string
)
302 "Insert TEXT into current buffer as an autoload section"
307 ;; This does something in Lucid Emacs.
309 (float-output-format nil
))
311 (elinstall-insert-section-header (current-buffer) form
)
313 (insert ";;; " comment-string
"\n"))
315 (insert generate-autoload-section-trailer
)))
317 ;;;_ . Making autoloads
318 ;;;_ , elinstall-make-autoload-action
319 (defun elinstall-make-autoload-action (buf def-file load-path-element full-path
)
320 "Return the autoloads for current buffer as a string"
322 ;;We put all the text into a temp buffer, then get that buffer's
326 (generate-new-buffer " *temp*"))
329 (file-name-nondirectory full-path
))
333 ;; Apparently this does something in Lucid Emacs.
335 (float-output-format nil
)
337 ;;load-name relative to a member of load-path.
339 (file-name-sans-extension
342 load-path-element
))))
344 (with-current-buffer buf
349 (goto-char (point-min))
350 (message "Finding autoloads for %s..." short-name
)
352 (skip-chars-forward " \t\n\f")
354 ((looking-at (regexp-quote generate-autoload-cookie
))
355 (search-forward generate-autoload-cookie
)
356 (skip-chars-forward " \t")
358 ;; Read the next form and make an autoload.
359 (let* ((form (prog1 (read (current-buffer))
360 (or (bolp) (forward-line 1))))
362 (make-autoload form relative-name
)))
364 (push (nth 1 form
) autoloads-done
)
365 (setq autoload form
))
366 (let ((autoload-print-form-outbuf outbuf
))
367 (autoload-print-form autoload
)))
369 ;; Copy the rest of the line to the output.
370 (princ (buffer-substring
372 ;; Back up over whitespace,
374 (skip-chars-backward " \f\t")
375 (if (= (char-after (1+ (point))) ?
)
379 (progn (forward-line 1) (point)))
382 ;; Don't read the comment.
387 (message "Finding autoloads for %s...done" short-name
))
389 ;;Return this action. The temp buffer's contents is
395 ,(with-current-buffer outbuf
(buffer-string))
398 ;;This in unwind-protected
399 (when (buffer-live-p outbuf
) (kill-buffer outbuf
))))))
402 ;;;_ , elinstall-generate-file-autoloads
404 (defun elinstall-generate-file-autoloads
405 (relative-name full-name text autoloads-done
)
406 "Insert at point a loaddefs autoload section for FILE.
407 Autoloads are generated for defuns and defmacros in FILE
408 marked by `generate-autoload-cookie' (which see).
409 If FILE is being visited in a buffer, the contents of the buffer
411 Return non-nil in the case where no autoloads were added at point.
413 FULL-NAME is the absolute name of the file.
414 RELATIVE-NAME is its name respective to some component of load-path."
415 (if (not (equal text
""))
416 ;; Insert the section-header line which lists the file name and
417 ;; which functions are in it, etc.
418 (elinstall-insert-autoload-section
423 (autoload-trim-file-name full-name
)
424 (elinstall-file-mod-time full-name
))
426 "Generated autoloads from "
427 (autoload-trim-file-name full-name
)))
430 ;;;_ , elinstall-deffile-insert-autoloads
431 (defun elinstall-deffile-insert-autoloads (file args
)
432 "Update the autoloads for FILE in current buffer.
433 Return FILE if there was no autoload cookie in it, else nil.
435 Current buffer must be a loaddef-style file.
437 LOAD-NAME is the absolute name of the file.
438 RELATIVE-NAME is its name respective to some component of load-path."
446 (goto-char (point-min))
447 ;; Look for the section for FILE
448 (while (and (not found
)
449 (search-forward generate-autoload-section-header nil t
))
450 (let ((form (autoload-read-section-header)))
452 ((equal (nth 2 form
) file
)
453 ;; We found the section for this file.
454 (let ((begin (match-beginning 0)))
456 (search-forward generate-autoload-section-trailer
)
457 (delete-region begin
(point))
459 ((string< file
(nth 2 form
))
460 ;; We've come to a section alphabetically later than
461 ;; FILE. We assume the file is in order and so
462 ;; there must be no section for FILE. We will
463 ;; insert one before the section here.
464 (goto-char (match-beginning 0))
465 (setq found
'new
)))))
469 ;; No later sections in the file. Put before the last page.
470 (goto-char (point-max))
471 (search-backward "\f" nil t
)))
473 (apply #'elinstall-generate-file-autoloads
476 (if no-autoloads file nil
)))
477 ;;;_ . Arranging to add to info-path and load-path
478 ;;;_ , elinstall-generate-add-to-path
479 (defun elinstall-generate-add-to-path (path-element type
)
480 "Insert code at point to add PATH-ELEMENT to a path.
482 * `add-to-load-path', add to load-path
483 * `add-to-info-path', add to Info-additional-directory-list
485 Current buffer must be a loaddef-style file."
488 (add-to-load-path 'load-path
)
489 (add-to-info-path 'Info-additional-directory-list
)
490 (t (error "Type not recognized"))))
493 (add-to-load-path "load-path")
494 (add-to-info-path "info-path")))
498 ;; This does something in Lucid Emacs.
500 (float-output-format nil
))
502 (message "Generating %s additions..." description
)
504 (elinstall-insert-autoload-section
506 `(add-to-list ',path-symbol
508 ,(file-relative-name path-element
)
511 (file-truename load-file-name
))))))
512 (list type
(list path-element
) nil nil nil
)
514 (message "Generating %s additions...done" description
)))
517 ;;;_ , elinstall-deffile-insert-add-to-path
518 (defun elinstall-deffile-insert-add-to-path (path-element type
)
519 "Insert code in current buffer to add PATH-ELEMENT to a path.
521 * `add-to-load-path', add to load-path
522 * `add-to-info-path', add to Info-default-directory-list
524 Current buffer must be a loaddef-style file."
532 (goto-char (point-min))
533 ;; Look for the section for PATH-ELEMENT
534 (while (and (not found
)
535 (search-forward generate-autoload-section-header nil t
))
536 (let ((form (autoload-read-section-header)))
539 (equal (nth 0 form
) type
)
540 (member path-element
(nth 1 form
)))
542 ;; We found the section for this add.
543 (let ((begin (match-beginning 0)))
545 (search-forward generate-autoload-section-trailer
)
546 (delete-region begin
(point))
552 ;; No later sections in the file. Put before the last page.
553 (goto-char (point-max))
554 (search-backward "\f" nil t
)))
556 (elinstall-generate-add-to-path path-element type
)))
558 ;;This never belongs in the no-autoloads section.
560 ;;;_ . elinstall-deffile-insert
562 (defun elinstall-deffile-insert (action)
563 "Insert autoloads etc into current file according to ACTION.
564 The format of ACTION is described in the design docs.
566 Return filename if this action belongs in the no-autoload section."
571 (elinstall-deffile-insert-autoloads
576 (elinstall-deffile-insert-add-to-path
582 (elinstall-deffile-insert-add-to-path
587 ((preload-file run-tests byte-compile
)
588 (error "This case should not come here.")))))
590 ;;;_ . elinstall-prepare-deffile
591 (defun elinstall-prepare-deffile (deffile)
592 "Try to ensure that DEFFILE is available for receiving autoloads"
594 (autoload-ensure-default-file deffile
)
595 (with-current-buffer (find-file-noselect deffile
)
598 ;; We must read/write the file without any code conversion,
599 ;; but still decode EOLs.
600 (let ((coding-system-for-read 'raw-text
))
602 ;; This is to make generated-autoload-file have Unix EOLs, so
603 ;; that it is portable to all platforms.
604 (setq buffer-file-coding-system
'raw-text-unix
))
605 (or (> (buffer-size) 0)
606 (error "Autoloads file %s does not exist" buffer-file-name
))
607 (or (file-writable-p buffer-file-name
)
608 (error "Autoloads file %s is not writable"
611 ;;;_ . elinstall-update-deffile
613 ;;Adapted from autoload.el `update-directory-autoloads'.
615 (defun elinstall-update-deffile (target actions
&optional
618 Update file TARGET with current autoloads as specified by ACTIONS.
619 Also remove any old definitions pointing to libraries that can no
622 ACTIONS must be a list of actions (See the format doc). Each one's
623 filename must be relative to some element of load-path.
625 USE-LOAD-PATH is a list to use as load-path. It should include
626 any new load-path that we are arranging to create. If it's not given,
627 load-path itself is used.
629 If FORCE is `t', do it regardless of timestamps etc. (Not implemented)
630 Other non-nil cases of FORCE are reserved for future development.
632 This uses `update-file-autoloads' (which see) to do its work.
633 In an interactive call, you must give one argument, the name
634 of a single directory."
637 (use-load-path (or use-load-path load-path
))
638 (this-time (current-time))
639 ;;files with no autoload cookies.
642 (elinstall-prepare-deffile target
)
644 (find-file-noselect target
)
647 (elinstall-remove-autogen-action
648 (autoload-trim-file-name target
)
651 (goto-char (point-min))
652 (while (search-forward generate-autoload-section-header nil t
)
653 (let* ((form (autoload-read-section-header))
655 (cond ((and (consp file
) (stringp (car file
)))
656 ;; This is a list of files that have no
658 ;; There shouldn't be more than one such entry.
659 ;; Remove the obsolete section.
660 (autoload-remove-section (match-beginning 0))
661 (let ((last-time (nth 4 form
)))
663 (let ((file-time (elinstall-file-mod-time file
)))
665 (not (time-less-p last-time file-time
)))
667 (push file no-autoloads
)
669 (elinstall-remove-autogen-action
671 ((not (stringp file
)))
675 (locate-library file nil use-load-path
)))
677 ;;File doesn't exist, so remove its
680 (autoload-remove-section
681 (match-beginning 0)))
683 ;; File hasn't changed, so do nothing.
686 (elinstall-file-mod-time file-path
))
689 (elinstall-deffile-insert
690 (elinstall-get-autogen-action
694 (elinstall-remove-autogen-action
697 ;; Remaining actions have no existing autoload sections yet.
700 (delq nil
(mapcar #'elinstall-deffile-insert actions
))))
702 ;; Sort them for better readability.
703 (setq no-autoloads
(sort no-autoloads
'string
<))
704 ;; Add the `no-autoloads' section.
705 (goto-char (point-max))
706 (search-backward "\f" nil t
)
707 (elinstall-insert-autoload-section
709 (list 'autoloads nil nil no-autoloads this-time
)))
712 ;;;_ . elinstall-stage-update-deffiles
713 (defun elinstall-stage-update-deffiles (segment-list force use-load-path
)
714 "Update any deffiles mentioned in SEGMENT-LIST.
715 FORCE and USE-LOAD-PATH have the same meaning as in
716 `elinstall-update-deffile'.
721 ((deffile (car segment
)))
722 (if (stringp deffile
)
723 (elinstall-update-deffile deffile
(cdr segment
) force
727 ;;;_ , Doing actions to arrange preloads
728 ;;;_ . elinstall-symlink-on-emacs-start
729 (defun elinstall-symlink-on-emacs-start
730 (filename target-basename target-dir
&optional priority force
)
731 "Symlink to TARGET-BASENAME.el in TARGET-DIR
733 If PRIORITY is given, it will be used as the priority prefix,
734 otherwise elinstall-default-priority will be.
735 PRIORITY must be an integer or nil.
736 If FORCE is `t', do it regardless of timestamps etc.
737 Other non-nil cases of FORCE are reserved for future development."
740 (priority (or priority elinstall-default-priority
))
747 (expand-file-name target-name-nodir target-dir
)))
751 ;;Path should already exist.
753 (file-exists-p target-dir
))
754 (message "The target directory doesn't exist."))
755 ;;Target shouldn't already exist, but if force is given, let
757 ;;$$IMPROVE ME If it is a symlink pointing to the same place,
758 ;;do nothing even on force.
760 (file-exists-p target
)
765 (format "Really overwrite %s? " target
))))
766 (message "File %s already exists" target
)))
774 ;;;_ . elinstall-add-to-dot-emacs
775 (defun elinstall-add-to-dot-emacs (dot-emacs-name filename force
&rest r
)
776 "Add code to load FILENAME to .emacs.
777 FILENAME should not have an extension"
780 (with-current-buffer (find-file-noselect dot-emacs-name
)
783 (goto-char (point-max))
784 (insert "\n;;Added by elinstall")
785 (insert "\n;;Consider using my-site-start to manage .emacs\n")
786 (pp `(load ,filename
) (current-buffer))
790 ;;;_ . elinstall-arrange-preload
792 (defun elinstall-arrange-preload (force filename basename
&optional priority
)
793 "Arrange for FILENAME to be loaded on emacs start.
794 FORCE has its usual meaning.
795 BASENAME and PRIORITY are used as arguments to
796 `elinstall-symlink-on-emacs-start'.
800 ((preload-target elinstall-default-preload-target
))
802 ;;Dispatch the possibilities.
804 ((eq preload-target
'dot-emacs
)
805 (elinstall-add-to-dot-emacs "~/.emacs" filename force
))
806 ((stringp preload-target
)
807 (elinstall-symlink-on-emacs-start
808 filename basename preload-target priority force
))
809 ((null preload-target
)
810 (message "Not arranging for preloads"))
812 (message "I don't recognize that")))))
813 ;;;_ . elinstall-stage-arrange-preloads
814 (defun elinstall-stage-arrange-preloads (actions deffiles-used force
)
815 "Arrange any preloads mentioned in ACTIONS."
829 (member filename deffiles-used
)))))
833 #'elinstall-arrange-preload
838 "elinstall-stage-arrange-preloads: Action not
844 ;;;_ . elinstall-stage-run-tests
845 (defun elinstall-stage-run-tests (actions)
846 "Run any tests mentioned in ACTIONS."
852 ;;$$WRITE ME - not a high priority right now.
856 "elinstall-stage-run-tests: Action not
862 ;;;_ . elinstall-stage-byte-compile
863 (defun elinstall-stage-byte-compile (actions)
864 "Do any byte-compilation mentioned in ACTIONS."
869 ;;$$IMPROVE ME Understand flags to control second
870 ;;argument (whether to load file after
873 (byte-compile-file (second act
)))
876 "elinstall-stage-byte-compile: Action not
879 ;;;_ . Segregating actions
880 ;;;_ , elinstall-remove-empty-segs
881 (defun elinstall-remove-empty-segs (segment-list)
882 "Return SEGMENT-LIST minus any segments that have no actions.
883 Intended only for the deffile stage data."
892 ;;;_ , elinstall-segregate-actions
893 (defun elinstall-segregate-actions (actions)
894 "Return actions segregated by deffile.
896 Returns a list whose elements are each a cons of:
897 * deffile filename or nil
898 * A list of actions to be done for that deffile."
905 (arrange-preloads '()))
907 (dolist (act actions
)
914 ((deffile-name (second act
))
916 (assoc deffile-name build-deffiles
)))
918 ;;There are already actions on this deffile.
919 ;;Splice this action in.
921 (cons act
(cdr cell-already
)))
922 ;;There are no actions on this deffile. Add a
923 ;;place for them and include this action.
924 (push (list deffile-name act
) build-deffiles
))))
926 (push act arrange-preloads
))
928 (push act run-tests
))
930 (push act byte-compile
)))))
932 (elinstall-make-stages
934 (elinstall-remove-empty-segs build-deffiles
)
941 ;;;_ . Finding actions
943 ;;;_ . elinstall-dir-has-info
945 ;;$$IMPROVE ME - Can this test be made more precise?
946 (defun elinstall-dir-has-info (dir)
947 "Return non-nil if DIR has info files in it.
948 DIR should be an absolute path."
950 (string-match "/info/" dir
)
951 (directory-files dir nil
"\\.info\\(-[0-9]+\\)?\\(\\.gz\\)?$")))
952 ;;;_ . elinstall-directory-files
953 (defun elinstall-directory-files (dirname)
954 "Return a list of files in directory DIRNAME, minus certain files.
955 The following files are omitted:
957 * Files that match an entry in `block-in-subtree'.
958 Filenames are relative."
960 def-file block-in-dir block-in-subtree
))
963 ;;Relative filenames of this directory's files.
965 ;; Don't include dot files. If user really wants to
966 ;;explore one he can use (dir ".NAME") or (file ".NAME")
967 (directory-files dirname nil
"[^\\.]"))
968 ;;We know our def-file isn't really source so remove it.
969 ;;We'd have removed it anyways after seeing file local vars.
971 (remove def-file all-files
))
982 (string-match blocked filename
))
991 ;;;_ . List of special variables used in this section
992 ;;load-path-element - The relevant element of load-path
993 ;;def-file - The file the autoload definitions etc will go into.
994 ;;add-to-load-path-p - Controls whether to add to load-path.
995 ;;recurse-dirs-p - Whether to recurse into subdirectories.
997 ;;block-in-dir - (NOT IMPLEMENTED) List of filenames to reject. They
998 ;;may include wildcards. They apply wrt the original directory.
1000 ;;block-in-subtree - (NOT IMPLEMENTED) List of filenames to reject.
1001 ;;They may include wildcards. They apply wrt any directory in the
1002 ;;tree. Specifically, in the spec tree, which may differ from the
1004 ;;byte-compile - whether to byte-compile at all, t by default.
1005 ;;autoloads - boolean whether to make autoloads, t by default.
1006 ;;preloads - boolean whether to set up preloads, t by default.
1007 (defconst elinstall-find-actions-control-vars
1008 '(add-to-load-path-p recurse-dirs-p byte-compile
1010 "Control special variables that the find-actions tree recognizes" )
1011 ;;;_ . elinstall-actions-for-source-file
1012 (defun elinstall-actions-for-source-file (filename dir
)
1013 "Return a list of actions to do for FILENAME in DIR.
1014 Special variables are as noted in \"List of special variables\"."
1016 load-path-element def-file byte-compile
))
1019 (expand-file-name filename dir
)))
1022 (file-readable-p full-path
)
1023 (not (auto-save-file-name-p full-path
)))
1024 ;;$$IMPROVE ME Use more of the control variables.
1027 (visited (get-file-buffer full-path
))
1031 ;;Visit the file cheaply.
1032 ;;hack-local-variables can give errors.
1033 (ignore-errors (autoload-find-file full-path
))))
1037 (with-current-buffer buf
1038 (if (local-variable-p 'generated-autoload-file
)
1039 (elinstall-expand-deffile-name
1040 generated-autoload-file
)
1043 ;;Figure out whether to run some actions, by file local vars.
1046 (with-current-buffer buf
1047 (not no-update-autoloads
))))
1051 (featurep 'byte-compile
)
1052 (string-match emacs-lisp-file-regexp filename
)
1054 (with-current-buffer buf
1055 (not no-byte-compile
)))
1056 (elinstall-proceed-p 'byte-compile
1060 "Already compiled %s.")
1063 ((dest (byte-compile-dest-file full-path
)))
1065 (file-exists-p dest
)
1066 (file-newer-than-file-p full-path dest
)))))))
1071 `(byte-compile ,full-path
)
1074 (elinstall-make-autoload-action
1075 buf def-file load-path-element full-path
)
1077 (unless visited
(kill-buffer-if-not-modified buf
)))))))
1078 ;;;_ . elinstall-actions-for-dir
1079 (defun elinstall-actions-for-dir (dirname &optional recurse-dirs-p
)
1080 "Make actions for DIR.
1081 Recurse just if RECURSE-DIRS-P"
1083 load-path-element def-file add-to-load-path-p
))
1084 ;;This does not treat symlinks specially. $$IMPROVE ME it could
1085 ;;treat/not treat them conditional on control variables.
1088 (files (elinstall-directory-files dirname
))
1090 ;;Relative filenames of elisp source
1094 #'(lambda (filename)
1096 (string-match elinstall-elisp-regexp filename
)
1101 ;;Absolute filenames of subdirectories.
1106 #'(lambda (filename)
1108 ((fn (expand-file-name filename dirname
)))
1110 (file-directory-p fn
)
1118 elisp-source-files
;;If list is not empty.
1119 add-to-load-path-p
))
1121 (if load-path-here-p
1123 load-path-element
)))
1126 ;;Sometimes arrange to add this directory to load-path.
1127 (if load-path-here-p
1130 ,load-path-element
))
1133 ;;$$IMPROVE ME - be controlled by a control variable.
1134 ;;Sometimes add this directory to info path.
1136 (elinstall-dir-has-info dirname
)
1144 #'(lambda (filename)
1145 (elinstall-actions-for-source-file
1148 elisp-source-files
))
1153 #'(lambda (filename)
1154 (elinstall-find-actions-by-spec-x
1162 ;;;_ . elinstall-find-actions-by-spec-x
1164 (defun elinstall-find-actions-by-spec-x (spec dir
)
1165 "Return a list of actions to do, controlled by SPEC."
1167 load-path-element def-file add-to-load-path-p
1168 recurse-dirs-p block-in-dir block-in-subtree
))
1176 #'(lambda (sub-spec)
1177 (elinstall-find-actions-by-spec-x
1182 ;;(block-in-subtree (* FN) SPEC)
1184 ((block-in-subtree (second spec
)))
1185 (elinstall-find-actions-by-spec-x
1189 ;;Rather than trying to bind all control variables each time
1190 ;;thru, we use `set' and `unwind-protect'.
1192 ;;control TYPE DISPOSITION SPEC
1194 ((key (second spec
))
1196 (if (memq key elinstall-find-actions-control-vars
)
1199 (setq old-value
(symbol-value key
))
1200 (set key
(third spec
))
1201 (elinstall-find-actions-by-spec-x
1204 (set key old-value
))
1205 (error "Unrecognized control variable %s" key
))))
1209 ;;(def-file FN ARGS SPEC)
1215 (for-preload (third spec
)))
1216 (assert (listp for-preload
))
1220 (and for-preload
(car for-preload
))
1224 ,@(cdr for-preload
))
1227 (elinstall-find-actions-by-spec-x
1228 (fourth spec
) dir
))))
1232 (elinstall-actions-for-dir
1240 (elinstall-actions-for-source-file
1251 (elinstall-find-actions-by-spec-x
1258 `((add-to-load-path ,def-file
,dir
))
1260 ((load-path-element dir
)
1261 (add-to-load-path-p nil
))
1262 (elinstall-find-actions-by-spec-x
1267 ;;(matching PATTERN SPEC)
1271 ;;$$PUNT Assume that `block-in-subtree' and
1272 ;;`block-in-dir' aren't matched.
1273 (elinstall-find-actions-by-spec-x
1277 dir t
(second spec
)))))
1279 ;;(preload FN SYM &rest ARGS)
1281 ((key (third spec
)))
1283 (and (symbolp key
) (symbol-value key
))
1286 ,(expand-file-name (second spec
) dir
)
1293 (elinstall-actions-for-dir dir nil
))
1295 (elinstall-actions-for-dir dir t
)))))
1297 ;;;_ . elinstall-find-actions-by-spec
1298 (defun elinstall-find-actions-by-spec
1299 (spec load-path-element dir def-file redo-old
)
1300 "Find the list of actions to do according to SPEC."
1304 (def-file-time (elinstall-file-mod-time def-file
))
1305 (add-to-load-path-p t
)
1311 (block-in-subtree '(".git" "RCS" "CVS" "SVN" "^tests\.el")))
1314 load-path-element def-file add-to-load-path-p
1315 recurse-dirs-p byte-compile
1316 block-in-dir block-in-subtree
))
1318 (elinstall-find-actions-by-spec-x spec dir
)))
1320 ;;;_ . high-level work
1321 ;;;_ , elinstall-get-relevant-load-path
1322 (defun elinstall-get-relevant-load-path (actions)
1332 ;;;_ , elinstall-get-deffile-list
1333 (defun elinstall-get-deffile-list (stages)
1334 "Get a list of deffile names"
1338 (elinstall-stages->build-deffiles stages
)))
1340 (defun elinstall-x (dir spec
&optional force
)
1341 "High-level worker function to install elisp files."
1344 ;;This is just the default deffile, spec can override it.
1346 (elinstall-expand-deffile-name nil
))
1348 (elinstall-find-actions-by-spec
1353 (eq force
'redo-old
)))
1354 (stages (elinstall-segregate-actions actions
))
1356 (elinstall-get-relevant-load-path
1359 (elinstall-stage-update-deffiles
1360 (elinstall-stages->build-deffiles stages
)
1363 (elinstall-stage-arrange-preloads
1364 (elinstall-stages->arrange-preloads stages
)
1365 (elinstall-get-deffile-list stages
)
1367 (elinstall-stage-byte-compile
1368 (elinstall-stages->byte-compile stages
))
1370 ;;;_ , elinstall-package
1371 (defun elinstall-package (project-name path spec version-string
)
1372 "Install elisp files. See doc for `elinstall'."
1374 (elinstall-proceed-p 'install
1378 "Already installed %s.")
1380 (elinstall-already-installed project-name
))
1383 `(def-file "loaddefs.el" (if-used ,project-name
) ,spec
)
1385 (elinstall-record-installed project-name version-string
)))
1390 (defun elinstall (project-name path spec
&optional force version-string
)
1391 "Install elisp files.
1392 They need not be a formal package.
1396 PROJECT-NAME - the name of the project
1398 PATH - Path to the project.
1399 Suggestion: Use (elinstall-directory-true-name) to get the real
1400 current directoery name even from loaded files.
1402 SPEC - a spec for the autoloads etc to make. It can be as simple
1405 If FORCE is `t', install a package even if it has already been
1406 installed. If it's a list or `nil', it's treated as a list of
1407 installation restraints. User customizations override this
1410 VERSION-STRING, if given, must be a string of the version for this package."
1412 (elinstall-call-with-restraints
1418 project-name path spec version-string
))
1420 ;;;_ . elinstall-update-directory-autoloads
1423 (defun elinstall-update-directory-autoloads (dir)
1424 "Update autoloads for directory DIR"
1426 (interactive "DUpdate autoloads for all elisp files from directory: ")
1427 (elinstall-call-with-restraints
1435 ;;;_ . elinstall-update-directory
1437 (defun elinstall-update-directory (dir)
1438 "Update autoloads for directory DIR"
1440 (interactive "DInstall all elisp files from directory: ")
1441 (elinstall-call-with-restraints
1448 ;;;_ . elinstall-update-file-autoloads
1450 (defun elinstall-update-file-autoloads (file)
1451 "Update autoloads for elisp file FILE"
1453 (interactive "fUpdate autoloads for elisp file: ")
1454 (elinstall-call-with-restraints
1458 (file-name-directory file
)
1459 `(file ,(file-name-nondirectory file
))))
1461 ;;;_ . elinstall-update-file
1463 (defun elinstall-update-file (file)
1464 "Install elisp file FILE"
1466 (interactive "fInstall elisp file: ")
1467 (elinstall-call-with-restraints
1472 (file-name-directory file
)
1473 `(file ,(file-name-nondirectory file
))))
1478 (provide 'elinstall
)
1480 ;;;_ * Local emacs vars.
1481 ;;;_ + Local variables:
1486 ;;; elinstall.el ends here