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 ask-prompt
&optional already-p redo-prompt noredo-msg
)
194 "Return non-nil if actions on TOPIC should proceed.
195 Call this transitively only thru `elinstall-call-with-restraints'"
197 (check-type topic symbol
)
199 elinstall
:*pkg-restraints
*
200 elinstall
:*user-restraints
*))
202 (boundp 'elinstall
:*pkg-restraints
*)
203 (boundp 'elinstall
:*user-restraints
*))
204 (error "elinstall-proceed-p called out of scope"))
207 ( (cell (assq topic elinstall
:*user-restraints
*))
208 (cell (or cell
(assq t elinstall
:*user-restraints
*)))
210 ;;`t' means use the pkg-restraints value instead.
212 (or (not cell
) (eq (second cell
) t
))
213 (assq topic elinstall
:*pkg-restraints
*)
215 (cell (or cell
(assq t elinstall
:*pkg-restraints
*)))
216 ;;Default is to just update.
218 (if cell
(second cell
) 'update
)))
232 (y-or-n-p redo-prompt
)
235 (y-or-n-p ask-prompt
)))))
240 ;;;_ , Doing autoload actions (adapted from autoload.el)
241 ;;;_ . Utilities about the action list
242 ;;;_ , elinstall-remove-autogen-action
243 (defun elinstall-remove-autogen-action (file actions
)
244 "Return ACTIONS minus any add-file-autoloads on FILE removed."
251 (if (equal file
(third act
))
256 ;;;_ , elinstall-get-autogen-action
257 (defun elinstall-get-autogen-action (file actions
)
261 (dolist (act actions
)
264 (when (equal file
(third act
))
265 (setq the-act act
)))))
267 ;;;_ . About printing to autoload file
268 ;;;_ , elinstall-insert-section-header
269 (defun elinstall-insert-section-header (outbuf form
)
270 "Insert the section-header line,
271 which lists the file name and which functions are in it, etc."
272 (insert generate-autoload-section-header
)
275 ;; Break that line at spaces, to avoid very long lines.
276 ;; Make each sub-line into a comment.
277 (with-current-buffer outbuf
282 (skip-chars-forward "^ \n")
284 (insert "\n" generate-autoload-section-continuation
))))))
286 ;;;_ , elinstall-insert-autoload-section
287 (defun elinstall-insert-autoload-section (text form
&optional comment-string
)
288 "Insert TEXT into current buffer as an autoload section"
293 ;; This does something in Lucid Emacs.
295 (float-output-format nil
))
297 (elinstall-insert-section-header (current-buffer) form
)
299 (insert ";;; " comment-string
"\n"))
301 (insert generate-autoload-section-trailer
)))
303 ;;;_ . Making autoloads
304 ;;;_ , elinstall-make-autoload-action
305 (defun elinstall-make-autoload-action (buf def-file load-path-element full-path
)
306 "Return the autoloads for current buffer as a string"
308 ;;We put all the text into a temp buffer, then get that buffer's
312 (generate-new-buffer " *temp*"))
315 (file-name-nondirectory full-path
))
319 ;; Apparently this does something in Lucid Emacs.
321 (float-output-format nil
)
323 ;;load-name relative to a member of load-path.
325 (file-name-sans-extension
328 load-path-element
))))
330 (with-current-buffer buf
335 (goto-char (point-min))
336 (message "Finding autoloads for %s..." short-name
)
338 (skip-chars-forward " \t\n\f")
340 ((looking-at (regexp-quote generate-autoload-cookie
))
341 (search-forward generate-autoload-cookie
)
342 (skip-chars-forward " \t")
344 ;; Read the next form and make an autoload.
345 (let* ((form (prog1 (read (current-buffer))
346 (or (bolp) (forward-line 1))))
348 (make-autoload form relative-name
)))
350 (push (nth 1 form
) autoloads-done
)
351 (setq autoload form
))
352 (let ((autoload-print-form-outbuf outbuf
))
353 (autoload-print-form autoload
)))
355 ;; Copy the rest of the line to the output.
356 (princ (buffer-substring
358 ;; Back up over whitespace,
360 (skip-chars-backward " \f\t")
361 (if (= (char-after (1+ (point))) ?
)
365 (progn (forward-line 1) (point)))
368 ;; Don't read the comment.
373 (message "Finding autoloads for %s...done" short-name
))
375 ;;Return this action. The temp buffer's contents is
381 ,(with-current-buffer outbuf
(buffer-string))
384 ;;This in unwind-protected
385 (when (buffer-live-p outbuf
) (kill-buffer outbuf
))))))
388 ;;;_ , elinstall-generate-file-autoloads
390 (defun elinstall-generate-file-autoloads
391 (relative-name full-name text autoloads-done
)
392 "Insert at point a loaddefs autoload section for FILE.
393 Autoloads are generated for defuns and defmacros in FILE
394 marked by `generate-autoload-cookie' (which see).
395 If FILE is being visited in a buffer, the contents of the buffer
397 Return non-nil in the case where no autoloads were added at point.
399 FULL-NAME is the absolute name of the file.
400 RELATIVE-NAME is its name respective to some component of load-path."
401 (if (not (equal text
""))
402 ;; Insert the section-header line which lists the file name and
403 ;; which functions are in it, etc.
404 (elinstall-insert-autoload-section
409 (autoload-trim-file-name full-name
)
410 (elinstall-file-mod-time full-name
))
412 "Generated autoloads from "
413 (autoload-trim-file-name full-name
)))
416 ;;;_ , elinstall-deffile-insert-autoloads
417 (defun elinstall-deffile-insert-autoloads (file args
)
418 "Update the autoloads for FILE in current buffer.
419 Return FILE if there was no autoload cookie in it, else nil.
421 Current buffer must be a loaddef-style file.
423 LOAD-NAME is the absolute name of the file.
424 RELATIVE-NAME is its name respective to some component of load-path."
432 (goto-char (point-min))
433 ;; Look for the section for FILE
434 (while (and (not found
)
435 (search-forward generate-autoload-section-header nil t
))
436 (let ((form (autoload-read-section-header)))
438 ((equal (nth 2 form
) file
)
439 ;; We found the section for this file.
440 (let ((begin (match-beginning 0)))
442 (search-forward generate-autoload-section-trailer
)
443 (delete-region begin
(point))
445 ((string< file
(nth 2 form
))
446 ;; We've come to a section alphabetically later than
447 ;; FILE. We assume the file is in order and so
448 ;; there must be no section for FILE. We will
449 ;; insert one before the section here.
450 (goto-char (match-beginning 0))
451 (setq found
'new
)))))
455 ;; No later sections in the file. Put before the last page.
456 (goto-char (point-max))
457 (search-backward "\f" nil t
)))
459 (apply #'elinstall-generate-file-autoloads
462 (if no-autoloads file nil
)))
463 ;;;_ . Arranging to add to info-path and load-path
464 ;;;_ , elinstall-generate-add-to-path
465 (defun elinstall-generate-add-to-path (path-element type
)
466 "Insert code at point to add PATH-ELEMENT to a path.
468 * `add-to-load-path', add to load-path
469 * `add-to-info-path', add to Info-additional-directory-list
471 Current buffer must be a loaddef-style file."
474 (add-to-load-path 'load-path
)
475 (add-to-info-path 'Info-additional-directory-list
)
476 (t (error "Type not recognized"))))
479 (add-to-load-path "load-path")
480 (add-to-info-path "info-path")))
484 ;; This does something in Lucid Emacs.
486 (float-output-format nil
))
488 (message "Generating %s additions..." description
)
490 (elinstall-insert-autoload-section
492 `(add-to-list ',path-symbol
494 ,(file-relative-name path-element
)
497 (file-truename load-file-name
))))))
498 (list type
(list path-element
) nil nil nil
)
500 (message "Generating %s additions...done" description
)))
503 ;;;_ , elinstall-deffile-insert-add-to-path
504 (defun elinstall-deffile-insert-add-to-path (path-element type
)
505 "Insert code in current buffer to add PATH-ELEMENT to a path.
507 * `add-to-load-path', add to load-path
508 * `add-to-info-path', add to Info-default-directory-list
510 Current buffer must be a loaddef-style file."
518 (goto-char (point-min))
519 ;; Look for the section for PATH-ELEMENT
520 (while (and (not found
)
521 (search-forward generate-autoload-section-header nil t
))
522 (let ((form (autoload-read-section-header)))
525 (equal (nth 0 form
) type
)
526 (member path-element
(nth 1 form
)))
528 ;; We found the section for this add.
529 (let ((begin (match-beginning 0)))
531 (search-forward generate-autoload-section-trailer
)
532 (delete-region begin
(point))
538 ;; No later sections in the file. Put before the last page.
539 (goto-char (point-max))
540 (search-backward "\f" nil t
)))
542 (elinstall-generate-add-to-path path-element type
)))
544 ;;This never belongs in the no-autoloads section.
546 ;;;_ . elinstall-deffile-insert
548 (defun elinstall-deffile-insert (action)
549 "Insert autoloads etc into current file according to ACTION.
550 The format of ACTION is described in the design docs.
552 Return filename if this action belongs in the no-autoload section."
557 (elinstall-deffile-insert-autoloads
562 (elinstall-deffile-insert-add-to-path
568 (elinstall-deffile-insert-add-to-path
573 ((preload-file run-tests byte-compile
)
574 (error "This case should not come here.")))))
576 ;;;_ . elinstall-prepare-deffile
577 (defun elinstall-prepare-deffile (deffile)
578 "Try to ensure that DEFFILE is available for receiving autoloads"
580 (autoload-ensure-default-file deffile
)
581 (with-current-buffer (find-file-noselect deffile
)
584 ;; We must read/write the file without any code conversion,
585 ;; but still decode EOLs.
586 (let ((coding-system-for-read 'raw-text
))
588 ;; This is to make generated-autoload-file have Unix EOLs, so
589 ;; that it is portable to all platforms.
590 (setq buffer-file-coding-system
'raw-text-unix
))
591 (or (> (buffer-size) 0)
592 (error "Autoloads file %s does not exist" buffer-file-name
))
593 (or (file-writable-p buffer-file-name
)
594 (error "Autoloads file %s is not writable"
597 ;;;_ . elinstall-update-deffile
599 ;;Adapted from autoload.el `update-directory-autoloads'.
601 (defun elinstall-update-deffile (target actions
&optional
604 Update file TARGET with current autoloads as specified by ACTIONS.
605 Also remove any old definitions pointing to libraries that can no
608 ACTIONS must be a list of actions (See the format doc). Each one's
609 filename must be relative to some element of load-path.
611 USE-LOAD-PATH is a list to use as load-path. It should include
612 any new load-path that we are arranging to create. If it's not given,
613 load-path itself is used.
615 If FORCE is `t', do it regardless of timestamps etc. (Not implemented)
616 Other non-nil cases of FORCE are reserved for future development.
618 This uses `update-file-autoloads' (which see) to do its work.
619 In an interactive call, you must give one argument, the name
620 of a single directory."
623 (use-load-path (or use-load-path load-path
))
624 (this-time (current-time))
625 ;;files with no autoload cookies.
628 (elinstall-prepare-deffile target
)
630 (find-file-noselect target
)
633 (elinstall-remove-autogen-action
634 (autoload-trim-file-name target
)
637 (goto-char (point-min))
638 (while (search-forward generate-autoload-section-header nil t
)
639 (let* ((form (autoload-read-section-header))
641 (cond ((and (consp file
) (stringp (car file
)))
642 ;; This is a list of files that have no
644 ;; There shouldn't be more than one such entry.
645 ;; Remove the obsolete section.
646 (autoload-remove-section (match-beginning 0))
647 (let ((last-time (nth 4 form
)))
649 (let ((file-time (elinstall-file-mod-time file
)))
651 (not (time-less-p last-time file-time
)))
653 (push file no-autoloads
)
655 (elinstall-remove-autogen-action
657 ((not (stringp file
)))
661 (locate-library file nil use-load-path
)))
663 ;;File doesn't exist, so remove its
666 (autoload-remove-section
667 (match-beginning 0)))
669 ;; File hasn't changed, so do nothing.
672 (elinstall-file-mod-time file-path
))
675 (elinstall-deffile-insert
676 (elinstall-get-autogen-action
680 (elinstall-remove-autogen-action
683 ;; Remaining actions have no existing autoload sections yet.
686 (delq nil
(mapcar #'elinstall-deffile-insert actions
))))
688 ;; Sort them for better readability.
689 (setq no-autoloads
(sort no-autoloads
'string
<))
690 ;; Add the `no-autoloads' section.
691 (goto-char (point-max))
692 (search-backward "\f" nil t
)
693 (elinstall-insert-autoload-section
695 (list 'autoloads nil nil no-autoloads this-time
)))
698 ;;;_ . elinstall-stage-update-deffiles
699 (defun elinstall-stage-update-deffiles (segment-list force use-load-path
)
700 "Update any deffiles mentioned in SEGMENT-LIST.
701 FORCE and USE-LOAD-PATH have the same meaning as in
702 `elinstall-update-deffile'.
707 ((deffile (car segment
)))
708 (if (stringp deffile
)
709 (elinstall-update-deffile deffile
(cdr segment
) force
713 ;;;_ , Doing actions to arrange preloads
714 ;;;_ . elinstall-symlink-on-emacs-start
715 (defun elinstall-symlink-on-emacs-start
716 (filename target-basename target-dir
&optional priority force
)
717 "Symlink to TARGET-BASENAME.el in TARGET-DIR
719 If PRIORITY is given, it will be used as the priority prefix,
720 otherwise elinstall-default-priority will be.
721 PRIORITY must be an integer or nil.
722 If FORCE is `t', do it regardless of timestamps etc.
723 Other non-nil cases of FORCE are reserved for future development."
726 (priority (or priority elinstall-default-priority
))
733 (expand-file-name target-name-nodir target-dir
)))
737 ;;Path should already exist.
739 (file-exists-p target-dir
))
740 (message "The target directory doesn't exist."))
741 ;;Target shouldn't already exist, but if force is given, let
743 ;;$$IMPROVE ME If it is a symlink pointing to the same place,
744 ;;do nothing even on force.
746 (file-exists-p target
)
751 (format "Really overwrite %s? " target
))))
752 (message "File %s already exists" target
)))
760 ;;;_ . elinstall-add-to-dot-emacs
761 (defun elinstall-add-to-dot-emacs (dot-emacs-name filename force
&rest r
)
762 "Add code to load FILENAME to .emacs.
763 FILENAME should not have an extension"
766 (with-current-buffer (find-file-noselect dot-emacs-name
)
769 (goto-char (point-max))
770 (insert "\n;;Added by elinstall")
771 (insert "\n;;Consider using my-site-start to manage .emacs\n")
772 (pp `(load ,filename
) (current-buffer))
776 ;;;_ . elinstall-arrange-preload
778 (defun elinstall-arrange-preload (force filename basename
&optional priority
)
779 "Arrange for FILENAME to be loaded on emacs start.
780 FORCE has its usual meaning.
781 BASENAME and PRIORITY are used as arguments to
782 `elinstall-symlink-on-emacs-start'.
786 ((preload-target elinstall-default-preload-target
))
788 ;;Dispatch the possibilities.
790 ((eq preload-target
'dot-emacs
)
791 (elinstall-add-to-dot-emacs "~/.emacs" filename force
))
792 ((stringp preload-target
)
793 (elinstall-symlink-on-emacs-start
794 filename basename preload-target priority force
))
795 ((null preload-target
)
796 (message "Not arranging for preloads"))
798 (message "I don't recognize that")))))
799 ;;;_ . elinstall-stage-arrange-preloads
800 (defun elinstall-stage-arrange-preloads (actions deffiles-used force
)
801 "Arrange any preloads mentioned in ACTIONS."
815 (member filename deffiles-used
)))))
819 #'elinstall-arrange-preload
824 "elinstall-stage-arrange-preloads: Action not
830 ;;;_ . elinstall-stage-run-tests
831 (defun elinstall-stage-run-tests (actions)
832 "Run any tests mentioned in ACTIONS."
838 ;;$$WRITE ME - not a high priority right now.
842 "elinstall-stage-run-tests: Action not
848 ;;;_ . elinstall-stage-byte-compile
849 (defun elinstall-stage-byte-compile (actions)
850 "Do any byte-compilation mentioned in ACTIONS."
855 ;;$$IMPROVE ME Understand flags to control second
856 ;;argument (whether to load file after
859 (byte-compile-file (second act
)))
862 "elinstall-stage-byte-compile: Action not
865 ;;;_ . Segregating actions
866 ;;;_ , elinstall-remove-empty-segs
867 (defun elinstall-remove-empty-segs (segment-list)
868 "Return SEGMENT-LIST minus any segments that have no actions.
869 Intended only for the deffile stage data."
878 ;;;_ , elinstall-segregate-actions
879 (defun elinstall-segregate-actions (actions)
880 "Return actions segregated by deffile.
882 Returns a list whose elements are each a cons of:
883 * deffile filename or nil
884 * A list of actions to be done for that deffile."
891 (arrange-preloads '()))
893 (dolist (act actions
)
900 ((deffile-name (second act
))
902 (assoc deffile-name build-deffiles
)))
904 ;;There are already actions on this deffile.
905 ;;Splice this action in.
907 (cons act
(cdr cell-already
)))
908 ;;There are no actions on this deffile. Add a
909 ;;place for them and include this action.
910 (push (list deffile-name act
) build-deffiles
))))
912 (push act arrange-preloads
))
914 (push act run-tests
))
916 (push act byte-compile
)))))
918 (elinstall-make-stages
920 (elinstall-remove-empty-segs build-deffiles
)
927 ;;;_ . Finding actions
929 ;;;_ . elinstall-dir-has-info
931 ;;$$IMPROVE ME - Can this test be made more precise?
932 (defun elinstall-dir-has-info (dir)
933 "Return non-nil if DIR has info files in it.
934 DIR should be an absolute path."
936 (string-match "/info/" dir
)
937 (directory-files dir nil
"\\.info\\(-[0-9]+\\)?\\(\\.gz\\)?$")))
938 ;;;_ . elinstall-directory-files
939 (defun elinstall-directory-files (dirname)
940 "Return a list of files in directory DIRNAME, minus certain files.
941 The following files are omitted:
943 * Files that match an entry in `block-in-subtree'.
944 Filenames are relative."
946 def-file block-in-dir block-in-subtree
))
949 ;;Relative filenames of this directory's files.
951 ;; Don't include dot files. If user really wants to
952 ;;explore one he can use (dir ".NAME") or (file ".NAME")
953 (directory-files dirname nil
"[^\\.]"))
954 ;;We know our def-file isn't really source so remove it.
955 ;;We'd have removed it anyways after seeing file local vars.
957 (remove def-file all-files
))
968 (string-match blocked filename
))
977 ;;;_ . List of special variables used in this section
978 ;;load-path-element - The relevant element of load-path
979 ;;def-file - The file the autoload definitions etc will go into.
980 ;;add-to-load-path-p - Controls whether to add to load-path.
981 ;;recurse-dirs-p - Whether to recurse into subdirectories.
983 ;;block-in-dir - (NOT IMPLEMENTED) List of filenames to reject. They
984 ;;may include wildcards. They apply wrt the original directory.
986 ;;block-in-subtree - (NOT IMPLEMENTED) List of filenames to reject.
987 ;;They may include wildcards. They apply wrt any directory in the
988 ;;tree. Specifically, in the spec tree, which may differ from the
990 ;;byte-compile - whether to byte-compile at all, t by default.
991 ;;autoloads - boolean whether to make autoloads, t by default.
992 ;;preloads - boolean whether to set up preloads, t by default.
993 (defconst elinstall-find-actions-control-vars
994 '(add-to-load-path-p recurse-dirs-p byte-compile
996 "Control special variables that the find-actions tree recognizes" )
997 ;;;_ . elinstall-actions-for-source-file
998 (defun elinstall-actions-for-source-file (filename dir
)
999 "Return a list of actions to do for FILENAME in DIR.
1000 Special variables are as noted in \"List of special variables\"."
1002 load-path-element def-file byte-compile
))
1005 (expand-file-name filename dir
)))
1008 (file-readable-p full-path
)
1009 (not (auto-save-file-name-p full-path
)))
1010 ;;$$IMPROVE ME Use more of the control variables.
1013 (visited (get-file-buffer full-path
))
1017 ;;Visit the file cheaply.
1018 ;;hack-local-variables can give errors.
1019 (ignore-errors (autoload-find-file full-path
))))
1023 (with-current-buffer buf
1024 (if (local-variable-p 'generated-autoload-file
)
1025 (elinstall-expand-deffile-name
1026 generated-autoload-file
)
1029 ;;Figure out whether to run some actions, by file local vars.
1032 (with-current-buffer buf
1033 (not no-update-autoloads
))))
1037 (featurep 'byte-compile
)
1038 (string-match emacs-lisp-file-regexp filename
)
1040 (with-current-buffer buf
1041 (not no-byte-compile
)))
1042 (elinstall-proceed-p 'byte-compile
1043 (concat "Compile " filename
"? ")
1045 ((dest (byte-compile-dest-file full-path
)))
1047 (file-exists-p dest
)
1048 (file-newer-than-file-p full-path dest
)))
1049 (concat "Recompile " filename
"? ")
1050 (concat "Already compiled " filename
"."))
1051 '(elinstall-proceed-p 'byte-compile
1055 "Already compiled %s.")
1058 ((dest (byte-compile-dest-file full-path
)))
1060 (file-exists-p dest
)
1061 (file-newer-than-file-p full-path dest
)))))))
1066 `(byte-compile ,full-path
)
1069 (elinstall-make-autoload-action
1070 buf def-file load-path-element full-path
)
1072 (unless visited
(kill-buffer-if-not-modified buf
)))))))
1073 ;;;_ . elinstall-actions-for-dir
1074 (defun elinstall-actions-for-dir (dirname &optional recurse-dirs-p
)
1075 "Make actions for DIR.
1076 Recurse just if RECURSE-DIRS-P"
1078 load-path-element def-file add-to-load-path-p
))
1079 ;;This does not treat symlinks specially. $$IMPROVE ME it could
1080 ;;treat/not treat them conditional on control variables.
1083 (files (elinstall-directory-files dirname
))
1085 ;;Relative filenames of elisp source
1089 #'(lambda (filename)
1091 (string-match elinstall-elisp-regexp filename
)
1096 ;;Absolute filenames of subdirectories.
1101 #'(lambda (filename)
1103 ((fn (expand-file-name filename dirname
)))
1105 (file-directory-p fn
)
1113 elisp-source-files
;;If list is not empty.
1114 add-to-load-path-p
))
1116 (if load-path-here-p
1118 load-path-element
)))
1121 ;;Sometimes arrange to add this directory to load-path.
1122 (if load-path-here-p
1125 ,load-path-element
))
1128 ;;$$IMPROVE ME - be controlled by a control variable.
1129 ;;Sometimes add this directory to info path.
1131 (elinstall-dir-has-info dirname
)
1139 #'(lambda (filename)
1140 (elinstall-actions-for-source-file
1143 elisp-source-files
))
1148 #'(lambda (filename)
1149 (elinstall-find-actions-by-spec-x
1157 ;;;_ . elinstall-find-actions-by-spec-x
1159 (defun elinstall-find-actions-by-spec-x (spec dir
)
1160 "Return a list of actions to do, controlled by SPEC."
1162 load-path-element def-file add-to-load-path-p
1163 recurse-dirs-p block-in-dir block-in-subtree
))
1171 #'(lambda (sub-spec)
1172 (elinstall-find-actions-by-spec-x
1177 ;;(block-in-subtree (* FN) SPEC)
1179 ((block-in-subtree (second spec
)))
1180 (elinstall-find-actions-by-spec-x
1184 ;;Rather than trying to bind all control variables each time
1185 ;;thru, we use `set' and `unwind-protect'.
1187 ;;control TYPE DISPOSITION SPEC
1189 ((key (second spec
))
1191 (if (memq key elinstall-find-actions-control-vars
)
1194 (setq old-value
(symbol-value key
))
1195 (set key
(third spec
))
1196 (elinstall-find-actions-by-spec-x
1199 (set key old-value
))
1200 (error "Unrecognized control variable %s" key
))))
1204 ;;(def-file FN ARGS SPEC)
1210 (for-preload (third spec
)))
1211 (assert (listp for-preload
))
1215 (and for-preload
(car for-preload
))
1219 ,@(cdr for-preload
))
1222 (elinstall-find-actions-by-spec-x
1223 (fourth spec
) dir
))))
1227 (elinstall-actions-for-dir
1235 (elinstall-actions-for-source-file
1246 (elinstall-find-actions-by-spec-x
1253 `((add-to-load-path ,def-file
,dir
))
1255 ((load-path-element dir
)
1256 (add-to-load-path-p nil
))
1257 (elinstall-find-actions-by-spec-x
1262 ;;(matching PATTERN SPEC)
1266 ;;$$PUNT Assume that `block-in-subtree' and
1267 ;;`block-in-dir' aren't matched.
1268 (elinstall-find-actions-by-spec-x
1272 dir t
(second spec
)))))
1274 ;;(preload FN SYM &rest ARGS)
1276 ((key (third spec
)))
1278 (and (symbolp key
) (symbol-value key
))
1281 ,(expand-file-name (second spec
) dir
)
1288 (elinstall-actions-for-dir dir nil
))
1290 (elinstall-actions-for-dir dir t
)))))
1292 ;;;_ . elinstall-find-actions-by-spec
1293 (defun elinstall-find-actions-by-spec
1294 (spec load-path-element dir def-file redo-old
)
1295 "Find the list of actions to do according to SPEC."
1299 (def-file-time (elinstall-file-mod-time def-file
))
1300 (add-to-load-path-p t
)
1306 (block-in-subtree '(".git" "RCS" "CVS" "SVN" "^tests\.el")))
1309 load-path-element def-file add-to-load-path-p
1310 recurse-dirs-p byte-compile
1311 block-in-dir block-in-subtree
))
1313 (elinstall-find-actions-by-spec-x spec dir
)))
1315 ;;;_ . high-level work
1316 ;;;_ , elinstall-get-relevant-load-path
1317 (defun elinstall-get-relevant-load-path (actions)
1327 ;;;_ , elinstall-get-deffile-list
1328 (defun elinstall-get-deffile-list (stages)
1329 "Get a list of deffile names"
1333 (elinstall-stages->build-deffiles stages
)))
1335 (defun elinstall-x (dir spec
&optional force
)
1336 "High-level worker function to install elisp files."
1339 ;;This is just the default deffile, spec can override it.
1341 (elinstall-expand-deffile-name nil
))
1343 (elinstall-find-actions-by-spec
1348 (eq force
'redo-old
)))
1349 (stages (elinstall-segregate-actions actions
))
1351 (elinstall-get-relevant-load-path
1354 (elinstall-stage-update-deffiles
1355 (elinstall-stages->build-deffiles stages
)
1358 (elinstall-stage-arrange-preloads
1359 (elinstall-stages->arrange-preloads stages
)
1360 (elinstall-get-deffile-list stages
)
1362 (elinstall-stage-byte-compile
1363 (elinstall-stages->byte-compile stages
))
1365 ;;;_ , elinstall-package
1366 (defun elinstall-package (project-name path spec version-string
)
1367 "Install elisp files. See doc for `elinstall'."
1369 (elinstall-proceed-p 'install
1370 (format "Install %s? " project-name
)
1371 (elinstall-already-installed project-name
)
1372 (format "Re-install %s? " project-name
)
1373 (format "Already installed %s. " project-name
))
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