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-update-directory-autoloads
33 ;; elinstall-update-file-autoloads
34 ;; elinstall-update-directory
35 ;; elinstall-update-file
37 ;; elinstall-arrange-preload - Use this for non-autogenerated files
38 ;; that need to be linked in. Packages are advised to write a spec
39 ;; instead of calling this directly.
45 (require 'cus-edit
) ;;Because we save "installedness" manually
46 (require 'byte-compile nil t
) ;;
54 "Customizations for elinstall"
56 ;;;_ . elinstall-default-priority
57 (defcustom elinstall-default-priority
59 "Default priority for site-start"
62 ;;;_ . elinstall-default-preload-target
63 (defcustom elinstall-default-preload-target
64 "~/.emacs.d/site-start.d/"
65 "Default preload-target for registering autoloads"
69 (const "~/.emacs.d/site-start.d/")
70 (const "/etc/emacs/site-start.d/")
74 ;;;_ . elinstall-restrain-install
75 (defcustom elinstall-restrain-install
'()
76 "Restrain elinstall for specific packages"
81 (choice :format
"%[%t%]: %v"
82 (string :tag
"Package name")
83 (const :tag
"All packages" t
))
84 (repeat :tag
"Actions to restrain:"
93 (const :tag
"Use as default" t
))
96 :tag
"Do this unless it's up to date"
99 :tag
"Use the package spec for this"
102 :tag
"Don't do this at all"
108 :tag
"Ask only when it's up-to-date."
111 :tag
"Do everything even if it's up to date."
115 ;;;_ . elinstall-already-installed
117 (defcustom elinstall-already-installed
119 "(AUTOMATIC) Things that have already been installed.
120 This exists for recording what has been installed.
122 Though it's saved as customizable, user interaction is not
124 ;;Tell the byte-compiler it's a variable.
125 (defvar elinstall-already-installed
)
127 ;;;_ . elinstall-stages
128 (defstruct (elinstall-stages
129 (:constructor elinstall-make-stages
)
130 (:conc-name elinstall-stages-
>)
132 "The elinstall stages"
138 ;;;_ . Regular expressions
139 ;;;_ , elinstall-elisp-regexp
140 (defconst elinstall-elisp-regexp
143 (suf (get-load-suffixes))
144 (unless (string-match "\\.elc" suf
) (push suf tmp
)))
145 (concat "^[^=.].*" (regexp-opt tmp t
) "\\'"))
146 "Regular expression that matches elisp files" )
148 ;;;_ . elinstall-file-mod-time
149 (defsubst elinstall-file-mod-time
(file)
150 "Return the modification time of FILE"
151 (nth 5 (file-attributes file
)))
153 ;;;_ . elinstall-directory-true-name
154 (defun elinstall-directory-true-name ()
155 "Get the true name of the directory the calling code lives in.
156 CAUTION: This is sensitive to where it's called. That's the point of it."
159 (file-truename load-file-name
)
160 (file-truename buffer-file-name
))))
161 ;;;_ . Checking installedness
162 ;;;_ , elinstall-get-installation-record
163 (defun elinstall-get-installation-record (project-name)
164 "Return the installation record for PROJECT-NAME."
166 (assoc project-name elinstall-already-installed
))
168 ;;;_ , elinstall-already-installed
169 (defun elinstall-already-installed (project-name)
170 "Return non-nil if PROJECT-NAME has been installed."
171 (elinstall-get-installation-record project-name
))
173 ;;;_ , elinstall-record-installed
174 (defun elinstall-record-installed (project-name &optional version
)
175 "Record that PROJECT-NAME has been installed."
184 (elinstall-get-installation-record project-name
))
188 (setq elinstall-already-installed
189 (delete old-item elinstall-already-installed
)))
190 (push new-item elinstall-already-installed
)
191 (customize-save-variable
192 'elinstall-already-installed
193 elinstall-already-installed
194 "Set by elinstall-record-installed")))
195 ;;;_ . Finding deffiles
196 ;;;_ , elinstall-expand-deffile-name
197 (defun elinstall-expand-deffile-name (deffile)
198 "Expand DEFFILE autoload.el's way."
200 (expand-file-name (or deffile
"loaddefs.el")
201 (expand-file-name "lisp"
203 ;;;_ . Checking restraint specs
204 ;;;_ , elinstall-call-with-restraints
205 (defun elinstall-call-with-restraints (restraints package func
&rest args
)
206 "Call FUNC with ARGS, in scope of RESTRAINTS.
207 RESTRAINTS is a list of package restraints. User restraints for the
208 given package will also be applied in scope.
210 PACKAGE can be `t' or a string naming a package."
213 ((elinstall:*pkg-restraints
* restraints
)
214 (elinstall:*user-restraints
*
218 (assoc package elinstall-restrain-install
)
219 (assoc t elinstall-restrain-install
))))
224 elinstall
:*pkg-restraints
*
225 elinstall
:*user-restraints
*))
227 ;;;_ , elinstall-proceed-p
228 (defun elinstall-proceed-p
229 (topic message-params
&optional already-p
)
230 "Return non-nil if actions on TOPIC should proceed.
231 Call this transitively only thru `elinstall-call-with-restraints'.
232 TOPIC is a symbol indicating the topic, such as `byte-compile'.
233 MESSAGE-PARAMS is a cons of:
234 * A list of format strings:
235 * To ask whether to do this action
236 * To ask whether to redo this action, for `ask-for-old'
237 * To report that this action was skipped because already done.
238 * The arguments to the formatter.
239 ALREADY-P is an extended boolean whether the task has been done
240 before, if caller can tell."
242 (check-type topic symbol
)
244 elinstall
:*pkg-restraints
*
245 elinstall
:*user-restraints
*))
247 (boundp 'elinstall
:*pkg-restraints
*)
248 (boundp 'elinstall
:*user-restraints
*))
249 (error "elinstall-proceed-p called out of scope"))
252 ((ask-prompt &optional redo-prompt noredo-msg
) &rest message-args
)
255 ( ;;Get the applicable cell. We look in several places.
258 (assq topic elinstall
:*user-restraints
*)
259 (assq t elinstall
:*user-restraints
*)))
261 ;;`t' means use the pkg-restraints value instead.
263 (or (not cell
) (eq (second cell
) t
))
265 (assq topic elinstall
:*pkg-restraints
*)
266 (assq t elinstall
:*pkg-restraints
*))
269 ;;Default is to just update.
270 (if cell
(second cell
) 'update
)))
279 (apply #'message noredo-msg message-args
)
284 (y-or-n-p (apply #'format redo-prompt message-args
))
288 (apply #'format ask-prompt message-args
)))))))
289 ;;;_ , elinstall-proceed-at-all-p
290 ;;$$WRITE ME Whether to proceed at all on a given topic.
295 ;;;_ , Doing autoload actions (adapted from autoload.el)
296 ;;;_ . Utilities about the action list
297 ;;;_ , elinstall-remove-autogen-action
298 (defun elinstall-remove-autogen-action (file actions
)
299 "Return ACTIONS minus any add-file-autoloads on FILE removed."
306 (if (equal file
(third act
))
311 ;;;_ , elinstall-get-autogen-action
312 (defun elinstall-get-autogen-action (file actions
)
316 (dolist (act actions
)
319 (when (equal file
(third act
))
320 (setq the-act act
)))))
322 ;;;_ . About printing to autoload file
323 ;;;_ , elinstall-insert-section-header
324 (defun elinstall-insert-section-header (outbuf form
)
325 "Insert the section-header line,
326 which lists the file name and which functions are in it, etc."
327 (insert generate-autoload-section-header
)
330 ;; Break that line at spaces, to avoid very long lines.
331 ;; Make each sub-line into a comment.
332 (with-current-buffer outbuf
337 (skip-chars-forward "^ \n")
339 (insert "\n" generate-autoload-section-continuation
))))))
341 ;;;_ , elinstall-insert-autoload-section
342 (defun elinstall-insert-autoload-section (text form
&optional comment-string
)
343 "Insert TEXT into current buffer as an autoload section"
348 ;; This does something in Lucid Emacs.
350 (float-output-format nil
))
352 (elinstall-insert-section-header (current-buffer) form
)
354 (insert ";;; " comment-string
"\n"))
356 (insert generate-autoload-section-trailer
)))
358 ;;;_ . Making autoloads
359 ;;;_ , elinstall-make-autoload-action
360 (defun elinstall-make-autoload-action (buf def-file load-path-element full-path
)
361 "Return the autoloads for current buffer as a string"
363 ;;We put all the text into a temp buffer, then get that buffer's
367 (generate-new-buffer " *temp*"))
370 (file-name-nondirectory full-path
))
374 ;; Apparently this does something in Lucid Emacs.
376 (float-output-format nil
)
378 ;;load-name relative to a member of load-path.
380 (file-name-sans-extension
383 load-path-element
))))
385 (with-current-buffer buf
390 (goto-char (point-min))
391 (message "Finding autoloads for %s..." short-name
)
393 (skip-chars-forward " \t\n\f")
395 ((looking-at (regexp-quote generate-autoload-cookie
))
396 (search-forward generate-autoload-cookie
)
397 (skip-chars-forward " \t")
399 ;; Read the next form and make an autoload.
400 (let* ((form (prog1 (read (current-buffer))
401 (or (bolp) (forward-line 1))))
403 (make-autoload form relative-name
)))
405 (push (nth 1 form
) autoloads-done
)
406 (setq autoload form
))
407 (let ((autoload-print-form-outbuf outbuf
))
408 (autoload-print-form autoload
)))
410 ;; Copy the rest of the line to the output.
411 (princ (buffer-substring
413 ;; Back up over whitespace,
415 (skip-chars-backward " \f\t")
416 (if (= (char-after (1+ (point))) ?
)
420 (progn (forward-line 1) (point)))
423 ;; Don't read the comment.
428 (message "Finding autoloads for %s...done" short-name
))
430 ;;Return this action. The temp buffer's contents is
436 ,(with-current-buffer outbuf
(buffer-string))
439 ;;This in unwind-protected
440 (when (buffer-live-p outbuf
) (kill-buffer outbuf
))))))
443 ;;;_ , elinstall-generate-file-autoloads
445 (defun elinstall-generate-file-autoloads
446 (relative-name full-name text autoloads-done
)
447 "Insert at point a loaddefs autoload section for FILE.
448 Autoloads are generated for defuns and defmacros in FILE
449 marked by `generate-autoload-cookie' (which see).
450 If FILE is being visited in a buffer, the contents of the buffer
452 Return non-nil in the case where no autoloads were added at point.
454 FULL-NAME is the absolute name of the file.
455 RELATIVE-NAME is its name respective to some component of load-path."
456 (if (not (equal text
""))
457 ;; Insert the section-header line which lists the file name and
458 ;; which functions are in it, etc.
459 (elinstall-insert-autoload-section
464 (autoload-trim-file-name full-name
)
465 (elinstall-file-mod-time full-name
))
467 "Generated autoloads from "
468 (autoload-trim-file-name full-name
)))
471 ;;;_ , elinstall-deffile-insert-autoloads
472 (defun elinstall-deffile-insert-autoloads (file args
)
473 "Update the autoloads for FILE in current buffer.
474 Return FILE if there was no autoload cookie in it, else nil.
476 Current buffer must be a loaddef-style file.
478 LOAD-NAME is the absolute name of the file.
479 RELATIVE-NAME is its name respective to some component of load-path."
487 (goto-char (point-min))
488 ;; Look for the section for FILE
489 (while (and (not found
)
490 (search-forward generate-autoload-section-header nil t
))
491 (let ((form (autoload-read-section-header)))
493 ((equal (nth 2 form
) file
)
494 ;; We found the section for this file.
495 (let ((begin (match-beginning 0)))
497 (search-forward generate-autoload-section-trailer
)
498 (delete-region begin
(point))
500 ((string< file
(nth 2 form
))
501 ;; We've come to a section alphabetically later than
502 ;; FILE. We assume the file is in order and so
503 ;; there must be no section for FILE. We will
504 ;; insert one before the section here.
505 (goto-char (match-beginning 0))
506 (setq found
'new
)))))
510 ;; No later sections in the file. Put before the last page.
511 (goto-char (point-max))
512 (search-backward "\f" nil t
)))
514 (apply #'elinstall-generate-file-autoloads
517 (if no-autoloads file nil
)))
518 ;;;_ . Arranging to add to info-path and load-path
519 ;;;_ , elinstall-generate-add-to-path
520 (defun elinstall-generate-add-to-path (path-element type
)
521 "Insert code at point to add PATH-ELEMENT to a path.
523 * `add-to-load-path', add to load-path
524 * `add-to-info-path', add to Info-additional-directory-list
526 Current buffer must be a loaddef-style file."
529 (add-to-load-path 'load-path
)
530 (add-to-info-path 'Info-additional-directory-list
)
531 (t (error "Type not recognized"))))
534 (add-to-load-path "load-path")
535 (add-to-info-path "info-path")))
539 ;; This does something in Lucid Emacs.
541 (float-output-format nil
))
543 (message "Generating %s additions..." description
)
545 (elinstall-insert-autoload-section
547 `(add-to-list ',path-symbol
549 ,(file-relative-name path-element
)
552 (file-truename load-file-name
))))))
553 (list type
(list path-element
) nil nil nil
)
555 (message "Generating %s additions...done" description
)))
558 ;;;_ , elinstall-deffile-insert-add-to-path
559 (defun elinstall-deffile-insert-add-to-path (path-element type
)
560 "Insert code in current buffer to add PATH-ELEMENT to a path.
562 * `add-to-load-path', add to load-path
563 * `add-to-info-path', add to Info-default-directory-list
565 Current buffer must be a loaddef-style file."
573 (goto-char (point-min))
574 ;; Look for the section for PATH-ELEMENT
575 (while (and (not found
)
576 (search-forward generate-autoload-section-header nil t
))
577 (let ((form (autoload-read-section-header)))
580 (equal (nth 0 form
) type
)
581 (member path-element
(nth 1 form
)))
583 ;; We found the section for this add.
584 (let ((begin (match-beginning 0)))
586 (search-forward generate-autoload-section-trailer
)
587 (delete-region begin
(point))
593 ;; No later sections in the file. Put before the last page.
594 (goto-char (point-max))
595 (search-backward "\f" nil t
)))
597 (elinstall-generate-add-to-path path-element type
)))
599 ;;This never belongs in the no-autoloads section.
601 ;;;_ . elinstall-deffile-insert
603 (defun elinstall-deffile-insert (action)
604 "Insert autoloads etc into current file according to ACTION.
605 The format of ACTION is described in the design docs.
607 Return filename if this action belongs in the no-autoload section."
612 (elinstall-deffile-insert-autoloads
617 (elinstall-deffile-insert-add-to-path
623 (elinstall-deffile-insert-add-to-path
628 ((preload-file run-tests byte-compile
)
629 (error "This case should not come here.")))))
631 ;;;_ . elinstall-prepare-deffile
632 (defun elinstall-prepare-deffile (deffile)
633 "Try to ensure that DEFFILE is available for receiving autoloads"
635 (autoload-ensure-default-file deffile
)
636 (with-current-buffer (find-file-noselect deffile
)
639 ;; We must read/write the file without any code conversion,
640 ;; but still decode EOLs.
641 (let ((coding-system-for-read 'raw-text
))
643 ;; This is to make generated-autoload-file have Unix EOLs, so
644 ;; that it is portable to all platforms.
645 (setq buffer-file-coding-system
'raw-text-unix
))
646 (or (> (buffer-size) 0)
647 (error "Autoloads file %s does not exist" buffer-file-name
))
648 (or (file-writable-p buffer-file-name
)
649 (error "Autoloads file %s is not writable"
652 ;;;_ . elinstall-update-deffile
654 ;;Adapted from autoload.el `update-directory-autoloads'.
656 (defun elinstall-update-deffile (target actions
&optional use-load-path
)
658 Update file TARGET with current autoloads as specified by ACTIONS.
659 Also remove any old definitions pointing to libraries that can no
662 ACTIONS must be a list of actions (See the format doc). Each one's
663 filename must be relative to some element of load-path.
665 USE-LOAD-PATH is a list to use as load-path. It should include
666 any new load-path that we are arranging to create. If it's not given,
667 load-path itself is used.
669 This uses `update-file-autoloads' (which see) to do its work.
670 In an interactive call, you must give one argument, the name
671 of a single directory."
674 (use-load-path (or use-load-path load-path
))
675 (this-time (current-time))
676 ;;files with no autoload cookies.
679 (elinstall-prepare-deffile target
)
681 (find-file-noselect target
)
684 (elinstall-remove-autogen-action
685 (autoload-trim-file-name target
)
688 (goto-char (point-min))
689 (while (search-forward generate-autoload-section-header nil t
)
690 (let* ((form (autoload-read-section-header))
692 (cond ((and (consp file
) (stringp (car file
)))
693 ;; This is a list of files that have no
695 ;; There shouldn't be more than one such entry.
696 ;; Remove the obsolete section.
697 (autoload-remove-section (match-beginning 0))
698 (let ((last-time (nth 4 form
)))
700 (let ((file-time (elinstall-file-mod-time file
)))
702 (not (time-less-p last-time file-time
)))
704 (push file no-autoloads
)
706 (elinstall-remove-autogen-action
708 ((not (stringp file
)))
712 (locate-library file nil use-load-path
)))
714 ;;$$MAKE ME SAFER Also check normal
715 ;;load-path in case `use-load-path' is
717 ;;$$MAKE ME SAFER Don't do this for a
718 ;;file we are inserting. Need a boolean
719 ;;return for checking that.
720 ;;File doesn't exist, so remove its
723 (autoload-remove-section
724 (match-beginning 0)))
725 ;;$$IMPROVE ME Consult elinstall-proceed-p.
726 ;; File hasn't changed, so do nothing.
729 (elinstall-file-mod-time file-path
))
732 (elinstall-deffile-insert
733 (elinstall-get-autogen-action
737 (elinstall-remove-autogen-action
740 ;; Remaining actions have no existing autoload sections yet.
743 (delq nil
(mapcar #'elinstall-deffile-insert actions
))))
745 ;; Sort them for better readability.
746 (setq no-autoloads
(sort no-autoloads
'string
<))
747 ;; Add the `no-autoloads' section.
748 (goto-char (point-max))
749 (search-backward "\f" nil t
)
750 (elinstall-insert-autoload-section
752 (list 'autoloads nil nil no-autoloads this-time
)))
755 ;;;_ . elinstall-stage-update-deffiles
756 (defun elinstall-stage-update-deffiles (segment-list use-load-path
)
757 "Update any deffiles mentioned in SEGMENT-LIST.
758 FORCE and USE-LOAD-PATH have the same meaning as in
759 `elinstall-update-deffile'.
764 ((deffile (car segment
)))
765 (if (stringp deffile
)
766 (elinstall-update-deffile
772 ;;;_ , Doing actions to arrange preloads
773 ;;;_ . elinstall-symlink-on-emacs-start
774 (defun elinstall-symlink-on-emacs-start
775 (filename target-basename target-dir
&optional priority
)
776 "Symlink to TARGET-BASENAME.el in TARGET-DIR
778 If PRIORITY is given, it will be used as the priority prefix,
779 otherwise elinstall-default-priority will be.
780 PRIORITY must be an integer or nil."
783 (priority (or priority elinstall-default-priority
))
790 (expand-file-name target-name-nodir target-dir
)))
794 ;;Path should already exist.
796 (file-exists-p target-dir
))
797 (message "The target directory doesn't exist."))
798 ;;$$IMPROVE ME If it is a symlink pointing to the same place,
801 ;;$$IMPROVE ME The condition here is really not updating but
802 ;;bulldozing a possibly different symlink. Add another
803 ;;treatment symbol meaning to bulldoze what's in the way.
804 ((elinstall-proceed-p 'preloads-compile
807 "Really overwrite %s? "
808 "File %s already exists")
810 (file-exists-p target
))
816 ;;;_ . elinstall-add-to-dot-emacs
817 (defun elinstall-add-to-dot-emacs (dot-emacs-name filename
&rest r
)
818 "Add code to load FILENAME to .emacs.
819 FILENAME should not have an extension"
822 (with-current-buffer (find-file-noselect dot-emacs-name
)
825 (goto-char (point-max))
826 (insert "\n;;Added by elinstall")
827 (insert "\n;;Consider using my-site-start to manage .emacs\n")
828 (pp `(load ,filename
) (current-buffer))
832 ;;;_ . elinstall-arrange-preload
834 (defun elinstall-arrange-preload (filename basename
&optional priority
)
835 "Arrange for FILENAME to be loaded on emacs start.
836 BASENAME and PRIORITY are used as arguments to
837 `elinstall-symlink-on-emacs-start'.
841 ((preload-target elinstall-default-preload-target
))
843 ;;Dispatch the possibilities.
845 ((eq preload-target
'dot-emacs
)
846 (elinstall-add-to-dot-emacs "~/.emacs" filename
))
847 ((stringp preload-target
)
848 (elinstall-symlink-on-emacs-start
849 filename basename preload-target priority
))
850 ((null preload-target
)
851 (message "Not arranging for preloads"))
853 (message "I don't recognize that")))))
854 ;;;_ . elinstall-stage-arrange-preloads
855 (defun elinstall-stage-arrange-preloads (actions deffiles-used
)
856 "Arrange any preloads mentioned in ACTIONS."
870 (member filename deffiles-used
)))))
874 #'elinstall-arrange-preload
878 "elinstall-stage-arrange-preloads: Action not
884 ;;;_ . elinstall-stage-run-tests
885 (defun elinstall-stage-run-tests (actions)
886 "Run any tests mentioned in ACTIONS."
892 ;;$$WRITE ME - not a high priority right now.
896 "elinstall-stage-run-tests: Action not
902 ;;;_ . elinstall-stage-byte-compile
903 (defun elinstall-stage-byte-compile (actions)
904 "Do any byte-compilation mentioned in ACTIONS."
909 ;;$$IMPROVE ME Understand flags to control second
910 ;;argument (whether to load file after
913 (byte-compile-file (second act
)))
916 "elinstall-stage-byte-compile: Action not
919 ;;;_ . Segregating actions
920 ;;;_ , elinstall-remove-empty-segs
921 (defun elinstall-remove-empty-segs (segment-list)
922 "Return SEGMENT-LIST minus any segments that have no actions.
923 Intended only for the deffile stage data."
932 ;;;_ , elinstall-segregate-actions
933 (defun elinstall-segregate-actions (actions)
934 "Return actions segregated by deffile.
936 Returns a list whose elements are each a cons of:
937 * deffile filename or nil
938 * A list of actions to be done for that deffile."
945 (arrange-preloads '()))
947 (dolist (act actions
)
954 ((deffile-name (second act
))
956 (assoc deffile-name build-deffiles
)))
958 ;;There are already actions on this deffile.
959 ;;Splice this action in.
961 (cons act
(cdr cell-already
)))
962 ;;There are no actions on this deffile. Add a
963 ;;place for them and include this action.
964 (push (list deffile-name act
) build-deffiles
))))
966 (push act arrange-preloads
))
968 (push act run-tests
))
970 (push act byte-compile
)))))
972 (elinstall-make-stages
974 (elinstall-remove-empty-segs build-deffiles
)
981 ;;;_ . Finding actions
983 ;;;_ . elinstall-dir-has-info
985 ;;$$IMPROVE ME - Can this test be made more precise?
986 (defun elinstall-dir-has-info (dir)
987 "Return non-nil if DIR has info files in it.
988 DIR should be an absolute path."
990 (string-match "/info/" dir
)
991 (directory-files dir nil
"\\.info\\(-[0-9]+\\)?\\(\\.gz\\)?$")))
992 ;;;_ . elinstall-directory-files
993 (defun elinstall-directory-files (dirname)
994 "Return a list of files in directory DIRNAME, minus certain files.
995 The following files are omitted:
997 * Files that match an entry in `block-in-subtree'.
998 Filenames are relative."
1000 def-file block-in-dir block-in-subtree
))
1003 ;;Relative filenames of this directory's files.
1005 ;; Don't include dot files. If user really wants to
1006 ;;explore one he can use (dir ".NAME") or (file ".NAME")
1007 (directory-files dirname nil
"[^\\.]"))
1008 ;;We know our def-file isn't really source so remove it.
1009 ;;We'd have removed it anyways after seeing file local vars.
1011 (remove def-file all-files
))
1016 #'(lambda (filename)
1022 (string-match blocked filename
))
1031 ;;;_ . List of special variables used in this section
1032 ;;load-path-element - The relevant element of load-path
1033 ;;def-file - The file the autoload definitions etc will go into.
1034 ;;add-to-load-path-p - Controls whether to add to load-path.
1035 ;;recurse-dirs-p - Whether to recurse into subdirectories.
1037 ;;block-in-dir - (NOT IMPLEMENTED) List of filenames to reject. They
1038 ;;may include wildcards. They apply wrt the original directory.
1040 ;;block-in-subtree - (NOT IMPLEMENTED) List of filenames to reject.
1041 ;;They may include wildcards. They apply wrt any directory in the
1042 ;;tree. Specifically, in the spec tree, which may differ from the
1044 ;;byte-compile - whether to byte-compile at all, t by default.
1045 ;;autoloads - boolean whether to make autoloads, t by default.
1046 ;;preloads - boolean whether to set up preloads, t by default.
1047 (defconst elinstall-find-actions-control-vars
1048 '(add-to-load-path-p recurse-dirs-p byte-compile
1050 "Control special variables that the find-actions tree recognizes" )
1051 ;;;_ . elinstall-actions-for-source-file
1052 (defun elinstall-actions-for-source-file (filename dir
)
1053 "Return a list of actions to do for FILENAME in DIR.
1054 Special variables are as noted in \"List of special variables\"."
1056 load-path-element def-file byte-compile
))
1059 (expand-file-name filename dir
)))
1062 (file-readable-p full-path
)
1063 (not (auto-save-file-name-p full-path
))
1064 (string-match emacs-lisp-file-regexp filename
))
1067 (visited (get-file-buffer full-path
))
1071 ;;Visit the file cheaply.
1072 ;;hack-local-variables can give errors.
1073 (ignore-errors (autoload-find-file full-path
))))
1077 (with-current-buffer buf
1078 (if (local-variable-p 'generated-autoload-file
)
1079 (elinstall-expand-deffile-name
1080 generated-autoload-file
)
1083 ;;Figure out whether to run some actions, by file local vars.
1087 (with-current-buffer buf
1088 (not no-update-autoloads
)))
1089 (elinstall-proceed-p 'autoloads
1091 '( "Do autoloads for %s? ")
1097 (featurep 'byte-compile
)
1099 (with-current-buffer buf
1100 (not no-byte-compile
)))
1101 (elinstall-proceed-p 'byte-compile
1105 "Already compiled %s.")
1108 (file-newer-than-file-p
1110 (byte-compile-dest-file full-path
)))))))
1115 `(byte-compile ,full-path
)
1118 (elinstall-make-autoload-action
1119 buf def-file load-path-element full-path
)
1121 (unless visited
(kill-buffer-if-not-modified buf
)))))))
1122 ;;;_ . elinstall-actions-for-dir
1123 (defun elinstall-actions-for-dir (dirname &optional recurse-dirs-p
)
1124 "Make actions for DIR.
1125 Recurse just if RECURSE-DIRS-P"
1127 load-path-element def-file add-to-load-path-p
))
1128 ;;This does not treat symlinks specially. $$IMPROVE ME it could
1129 ;;treat/not treat them conditional on control variables.
1132 (files (elinstall-directory-files dirname
))
1134 ;;Relative filenames of elisp source
1138 #'(lambda (filename)
1140 (string-match elinstall-elisp-regexp filename
)
1145 ;;Absolute filenames of subdirectories.
1150 #'(lambda (filename)
1152 ((fn (expand-file-name filename dirname
)))
1154 (file-directory-p fn
)
1162 elisp-source-files
;;If list is not empty.
1163 add-to-load-path-p
))
1165 (if load-path-here-p
1167 load-path-element
)))
1170 ;;Sometimes arrange to add this directory to load-path.
1171 (if load-path-here-p
1174 ,load-path-element
))
1177 ;;$$IMPROVE ME - be controlled by a control variable.
1178 ;;Sometimes add this directory to info path.
1180 (elinstall-dir-has-info dirname
)
1188 #'(lambda (filename)
1189 (elinstall-actions-for-source-file
1192 elisp-source-files
))
1197 #'(lambda (filename)
1198 (elinstall-find-actions-by-spec-x
1206 ;;;_ . elinstall-find-actions-by-spec-x
1208 (defun elinstall-find-actions-by-spec-x (spec dir
)
1209 "Return a list of actions to do, controlled by SPEC."
1211 load-path-element def-file add-to-load-path-p
1212 recurse-dirs-p block-in-dir block-in-subtree
))
1220 #'(lambda (sub-spec)
1221 (elinstall-find-actions-by-spec-x
1226 ;;(block-in-subtree (* FN) SPEC)
1228 ((block-in-subtree (second spec
)))
1229 (elinstall-find-actions-by-spec-x
1233 ;;Rather than trying to bind all control variables each time
1234 ;;thru, we use `set' and `unwind-protect'.
1236 ;;control TYPE DISPOSITION SPEC
1238 ((key (second spec
))
1240 (if (memq key elinstall-find-actions-control-vars
)
1243 (setq old-value
(symbol-value key
))
1244 (set key
(third spec
))
1245 (elinstall-find-actions-by-spec-x
1248 (set key old-value
))
1249 (error "Unrecognized control variable %s" key
))))
1253 ;;(def-file FN ARGS SPEC)
1259 (for-preload (third spec
)))
1260 (assert (listp for-preload
))
1264 (and for-preload
(car for-preload
))
1268 ,@(cdr for-preload
))
1271 (elinstall-find-actions-by-spec-x
1272 (fourth spec
) dir
))))
1276 (elinstall-actions-for-dir
1284 (elinstall-actions-for-source-file
1295 (elinstall-find-actions-by-spec-x
1302 `((add-to-load-path ,def-file
,dir
))
1304 ((load-path-element dir
)
1305 (add-to-load-path-p nil
))
1306 (elinstall-find-actions-by-spec-x
1311 ;;(matching PATTERN SPEC)
1315 ;;$$PUNT Assume that `block-in-subtree' and
1316 ;;`block-in-dir' aren't matched.
1317 (elinstall-find-actions-by-spec-x
1321 dir t
(second spec
)))))
1323 ;;(preload FN SYM &rest ARGS)
1325 ((key (third spec
)))
1327 (and (symbolp key
) (symbol-value key
))
1330 ,(expand-file-name (second spec
) dir
)
1337 (elinstall-actions-for-dir dir nil
))
1339 (elinstall-actions-for-dir dir t
)))))
1341 ;;;_ . elinstall-find-actions-by-spec
1342 (defun elinstall-find-actions-by-spec
1343 (spec load-path-element dir def-file
)
1344 "Find the list of actions to do according to SPEC."
1348 (def-file-time (elinstall-file-mod-time def-file
))
1349 (add-to-load-path-p t
)
1355 (block-in-subtree '(".git" "RCS" "CVS" "SVN" "^tests\.el")))
1358 load-path-element def-file add-to-load-path-p
1359 recurse-dirs-p byte-compile
1360 block-in-dir block-in-subtree
))
1362 (elinstall-find-actions-by-spec-x spec dir
)))
1364 ;;;_ . high-level work
1365 ;;;_ , elinstall-get-relevant-load-path
1366 (defun elinstall-get-relevant-load-path (actions)
1376 ;;;_ , elinstall-get-deffile-list
1377 (defun elinstall-get-deffile-list (stages)
1378 "Get a list of deffile names"
1382 (elinstall-stages->build-deffiles stages
)))
1384 (defun elinstall-x (dir spec
)
1385 "High-level worker function to install elisp files."
1388 ;;This is just the default deffile, spec can override it.
1390 (elinstall-expand-deffile-name nil
))
1392 (elinstall-find-actions-by-spec
1397 (stages (elinstall-segregate-actions actions
))
1399 (elinstall-get-relevant-load-path
1402 (elinstall-stage-update-deffiles
1403 (elinstall-stages->build-deffiles stages
)
1405 (elinstall-stage-arrange-preloads
1406 (elinstall-stages->arrange-preloads stages
)
1407 (elinstall-get-deffile-list stages
))
1408 (elinstall-stage-byte-compile
1409 (elinstall-stages->byte-compile stages
))
1411 ;;;_ , elinstall-package
1412 (defun elinstall-package (project-name path spec version-string
)
1413 "Install elisp files. See doc for `elinstall'."
1415 (elinstall-proceed-p 'install
1419 "Already installed %s.")
1421 (elinstall-already-installed project-name
))
1424 `(def-file "loaddefs.el" (if-used ,project-name
) ,spec
))
1425 (elinstall-record-installed project-name version-string
)))
1430 (defun elinstall (project-name path spec
&optional force version-string
)
1431 "Install elisp files.
1432 They need not be a formal package.
1436 PROJECT-NAME - the name of the project
1438 PATH - Path to the project.
1439 Suggestion: Use (elinstall-directory-true-name) to get the real
1440 current directoery name even from loaded files.
1442 SPEC - a spec for the autoloads etc to make. It can be as simple
1445 If FORCE is `t', install a package even if it has already been
1446 installed. If it's a list or `nil', it's treated as a list of
1447 installation restraints. User customizations override this
1450 VERSION-STRING, if given, must be a string of the version for this package."
1452 (elinstall-call-with-restraints
1458 project-name path spec version-string
))
1460 ;;;_ . elinstall-update-directory-autoloads
1463 (defun elinstall-update-directory-autoloads (dir)
1464 "Update autoloads for directory DIR"
1466 (interactive "DUpdate autoloads for all elisp files from directory: ")
1467 (elinstall-call-with-restraints
1475 ;;;_ . elinstall-update-directory
1477 (defun elinstall-update-directory (dir)
1478 "Update autoloads for directory DIR"
1480 (interactive "DInstall all elisp files from directory: ")
1481 (elinstall-call-with-restraints
1488 ;;;_ . elinstall-update-file-autoloads
1490 (defun elinstall-update-file-autoloads (file)
1491 "Update autoloads for elisp file FILE"
1493 (interactive "fUpdate autoloads for elisp file: ")
1494 (elinstall-call-with-restraints
1498 (file-name-directory file
)
1499 `(file ,(file-name-nondirectory file
))))
1501 ;;;_ . elinstall-update-file
1503 (defun elinstall-update-file (file)
1504 "Install elisp file FILE"
1506 (interactive "fInstall elisp file: ")
1507 (elinstall-call-with-restraints
1512 (file-name-directory file
)
1513 `(file ,(file-name-nondirectory file
))))
1518 (provide 'elinstall
)
1520 ;;;_ * Local emacs vars.
1521 ;;;_ + Local variables:
1526 ;;; elinstall.el ends here