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
)))))))
293 ;;;_ , Doing autoload actions (adapted from autoload.el)
294 ;;;_ . Utilities about the action list
295 ;;;_ , elinstall-remove-autogen-action
296 (defun elinstall-remove-autogen-action (file actions
)
297 "Return ACTIONS minus any add-file-autoloads on FILE removed."
304 (if (equal file
(third act
))
309 ;;;_ , elinstall-get-autogen-action
310 (defun elinstall-get-autogen-action (file actions
)
314 (dolist (act actions
)
317 (when (equal file
(third act
))
318 (setq the-act act
)))))
320 ;;;_ . About printing to autoload file
321 ;;;_ , elinstall-insert-section-header
322 (defun elinstall-insert-section-header (outbuf form
)
323 "Insert the section-header line,
324 which lists the file name and which functions are in it, etc."
325 (insert generate-autoload-section-header
)
328 ;; Break that line at spaces, to avoid very long lines.
329 ;; Make each sub-line into a comment.
330 (with-current-buffer outbuf
335 (skip-chars-forward "^ \n")
337 (insert "\n" generate-autoload-section-continuation
))))))
339 ;;;_ , elinstall-insert-autoload-section
340 (defun elinstall-insert-autoload-section (text form
&optional comment-string
)
341 "Insert TEXT into current buffer as an autoload section"
346 ;; This does something in Lucid Emacs.
348 (float-output-format nil
))
350 (elinstall-insert-section-header (current-buffer) form
)
352 (insert ";;; " comment-string
"\n"))
354 (insert generate-autoload-section-trailer
)))
356 ;;;_ . Making autoloads
357 ;;;_ , elinstall-make-autoload-action
358 (defun elinstall-make-autoload-action (buf def-file load-path-element full-path
)
359 "Return the autoloads for current buffer as a string"
361 ;;We put all the text into a temp buffer, then get that buffer's
365 (generate-new-buffer " *temp*"))
368 (file-name-nondirectory full-path
))
372 ;; Apparently this does something in Lucid Emacs.
374 (float-output-format nil
)
376 ;;load-name relative to a member of load-path.
378 (file-name-sans-extension
381 load-path-element
))))
383 (with-current-buffer buf
388 (goto-char (point-min))
389 (message "Finding autoloads for %s..." short-name
)
391 (skip-chars-forward " \t\n\f")
393 ((looking-at (regexp-quote generate-autoload-cookie
))
394 (search-forward generate-autoload-cookie
)
395 (skip-chars-forward " \t")
397 ;; Read the next form and make an autoload.
398 (let* ((form (prog1 (read (current-buffer))
399 (or (bolp) (forward-line 1))))
401 (make-autoload form relative-name
)))
403 (push (nth 1 form
) autoloads-done
)
404 (setq autoload form
))
405 (let ((autoload-print-form-outbuf outbuf
))
406 (autoload-print-form autoload
)))
408 ;; Copy the rest of the line to the output.
409 (princ (buffer-substring
411 ;; Back up over whitespace,
413 (skip-chars-backward " \f\t")
414 (if (= (char-after (1+ (point))) ?
)
418 (progn (forward-line 1) (point)))
421 ;; Don't read the comment.
426 (message "Finding autoloads for %s...done" short-name
))
428 ;;Return this action. The temp buffer's contents is
434 ,(with-current-buffer outbuf
(buffer-string))
437 ;;This in unwind-protected
438 (when (buffer-live-p outbuf
) (kill-buffer outbuf
))))))
441 ;;;_ , elinstall-generate-file-autoloads
443 (defun elinstall-generate-file-autoloads
444 (relative-name full-name text autoloads-done
)
445 "Insert at point a loaddefs autoload section for FILE.
446 Autoloads are generated for defuns and defmacros in FILE
447 marked by `generate-autoload-cookie' (which see).
448 If FILE is being visited in a buffer, the contents of the buffer
450 Return non-nil in the case where no autoloads were added at point.
452 FULL-NAME is the absolute name of the file.
453 RELATIVE-NAME is its name respective to some component of load-path."
454 (if (not (equal text
""))
455 ;; Insert the section-header line which lists the file name and
456 ;; which functions are in it, etc.
457 (elinstall-insert-autoload-section
462 (autoload-trim-file-name full-name
)
463 (elinstall-file-mod-time full-name
))
465 "Generated autoloads from "
466 (autoload-trim-file-name full-name
)))
469 ;;;_ , elinstall-deffile-insert-autoloads
470 (defun elinstall-deffile-insert-autoloads (file args
)
471 "Update the autoloads for FILE in current buffer.
472 Return FILE if there was no autoload cookie in it, else nil.
474 Current buffer must be a loaddef-style file.
476 LOAD-NAME is the absolute name of the file.
477 RELATIVE-NAME is its name respective to some component of load-path."
485 (goto-char (point-min))
486 ;; Look for the section for FILE
487 (while (and (not found
)
488 (search-forward generate-autoload-section-header nil t
))
489 (let ((form (autoload-read-section-header)))
491 ((equal (nth 2 form
) file
)
492 ;; We found the section for this file.
493 (let ((begin (match-beginning 0)))
495 (search-forward generate-autoload-section-trailer
)
496 (delete-region begin
(point))
498 ((string< file
(nth 2 form
))
499 ;; We've come to a section alphabetically later than
500 ;; FILE. We assume the file is in order and so
501 ;; there must be no section for FILE. We will
502 ;; insert one before the section here.
503 (goto-char (match-beginning 0))
504 (setq found
'new
)))))
508 ;; No later sections in the file. Put before the last page.
509 (goto-char (point-max))
510 (search-backward "\f" nil t
)))
512 (apply #'elinstall-generate-file-autoloads
515 (if no-autoloads file nil
)))
516 ;;;_ . Arranging to add to info-path and load-path
517 ;;;_ , elinstall-generate-add-to-path
518 (defun elinstall-generate-add-to-path (path-element type
)
519 "Insert code at point to add PATH-ELEMENT to a path.
521 * `add-to-load-path', add to load-path
522 * `add-to-info-path', add to Info-additional-directory-list
524 Current buffer must be a loaddef-style file."
527 (add-to-load-path 'load-path
)
528 (add-to-info-path 'Info-additional-directory-list
)
529 (t (error "Type not recognized"))))
532 (add-to-load-path "load-path")
533 (add-to-info-path "info-path")))
537 ;; This does something in Lucid Emacs.
539 (float-output-format nil
))
541 (message "Generating %s additions..." description
)
543 (elinstall-insert-autoload-section
545 `(add-to-list ',path-symbol
547 ,(file-relative-name path-element
)
550 (file-truename load-file-name
))))))
551 (list type
(list path-element
) nil nil nil
)
553 (message "Generating %s additions...done" description
)))
556 ;;;_ , elinstall-deffile-insert-add-to-path
557 (defun elinstall-deffile-insert-add-to-path (path-element type
)
558 "Insert code in current buffer to add PATH-ELEMENT to a path.
560 * `add-to-load-path', add to load-path
561 * `add-to-info-path', add to Info-default-directory-list
563 Current buffer must be a loaddef-style file."
571 (goto-char (point-min))
572 ;; Look for the section for PATH-ELEMENT
573 (while (and (not found
)
574 (search-forward generate-autoload-section-header nil t
))
575 (let ((form (autoload-read-section-header)))
578 (equal (nth 0 form
) type
)
579 (member path-element
(nth 1 form
)))
581 ;; We found the section for this add.
582 (let ((begin (match-beginning 0)))
584 (search-forward generate-autoload-section-trailer
)
585 (delete-region begin
(point))
591 ;; No later sections in the file. Put before the last page.
592 (goto-char (point-max))
593 (search-backward "\f" nil t
)))
595 (elinstall-generate-add-to-path path-element type
)))
597 ;;This never belongs in the no-autoloads section.
599 ;;;_ . elinstall-deffile-insert
601 (defun elinstall-deffile-insert (action)
602 "Insert autoloads etc into current file according to ACTION.
603 The format of ACTION is described in the design docs.
605 Return filename if this action belongs in the no-autoload section."
610 (elinstall-deffile-insert-autoloads
615 (elinstall-deffile-insert-add-to-path
621 (elinstall-deffile-insert-add-to-path
626 ((preload-file run-tests byte-compile
)
627 (error "This case should not come here.")))))
629 ;;;_ . elinstall-prepare-deffile
630 (defun elinstall-prepare-deffile (deffile)
631 "Try to ensure that DEFFILE is available for receiving autoloads"
633 (autoload-ensure-default-file deffile
)
634 (with-current-buffer (find-file-noselect deffile
)
637 ;; We must read/write the file without any code conversion,
638 ;; but still decode EOLs.
639 (let ((coding-system-for-read 'raw-text
))
641 ;; This is to make generated-autoload-file have Unix EOLs, so
642 ;; that it is portable to all platforms.
643 (setq buffer-file-coding-system
'raw-text-unix
))
644 (or (> (buffer-size) 0)
645 (error "Autoloads file %s does not exist" buffer-file-name
))
646 (or (file-writable-p buffer-file-name
)
647 (error "Autoloads file %s is not writable"
650 ;;;_ . elinstall-update-deffile
652 ;;Adapted from autoload.el `update-directory-autoloads'.
654 (defun elinstall-update-deffile (target actions
&optional use-load-path
)
656 Update file TARGET with current autoloads as specified by ACTIONS.
657 Also remove any old definitions pointing to libraries that can no
660 ACTIONS must be a list of actions (See the format doc). Each one's
661 filename must be relative to some element of load-path.
663 USE-LOAD-PATH is a list to use as load-path. It should include
664 any new load-path that we are arranging to create. If it's not given,
665 load-path itself is used.
667 This uses `update-file-autoloads' (which see) to do its work.
668 In an interactive call, you must give one argument, the name
669 of a single directory."
672 (use-load-path (or use-load-path load-path
))
673 (this-time (current-time))
674 ;;files with no autoload cookies.
677 (elinstall-prepare-deffile target
)
679 (find-file-noselect target
)
682 (elinstall-remove-autogen-action
683 (autoload-trim-file-name target
)
686 (goto-char (point-min))
687 (while (search-forward generate-autoload-section-header nil t
)
688 (let* ((form (autoload-read-section-header))
690 (cond ((and (consp file
) (stringp (car file
)))
691 ;; This is a list of files that have no
693 ;; There shouldn't be more than one such entry.
694 ;; Remove the obsolete section.
695 (autoload-remove-section (match-beginning 0))
696 (let ((last-time (nth 4 form
)))
698 (let ((file-time (elinstall-file-mod-time file
)))
700 (not (time-less-p last-time file-time
)))
702 (push file no-autoloads
)
704 (elinstall-remove-autogen-action
706 ((not (stringp file
)))
710 (locate-library file nil use-load-path
)))
712 ;;$$MAKE ME SAFER Also check normal
713 ;;load-path in case `use-load-path' is
715 ;;$$MAKE ME SAFER Don't do this for a
716 ;;file we are inserting. Need a boolean
717 ;;return for checking that.
718 ;;File doesn't exist, so remove its
721 (autoload-remove-section
722 (match-beginning 0)))
723 ;;$$IMPROVE ME Consult elinstall-proceed-p.
724 ;; File hasn't changed, so do nothing.
727 (elinstall-file-mod-time file-path
))
730 (elinstall-deffile-insert
731 (elinstall-get-autogen-action
735 (elinstall-remove-autogen-action
738 ;; Remaining actions have no existing autoload sections yet.
741 (delq nil
(mapcar #'elinstall-deffile-insert actions
))))
743 ;; Sort them for better readability.
744 (setq no-autoloads
(sort no-autoloads
'string
<))
745 ;; Add the `no-autoloads' section.
746 (goto-char (point-max))
747 (search-backward "\f" nil t
)
748 (elinstall-insert-autoload-section
750 (list 'autoloads nil nil no-autoloads this-time
)))
753 ;;;_ . elinstall-stage-update-deffiles
754 (defun elinstall-stage-update-deffiles (segment-list use-load-path
)
755 "Update any deffiles mentioned in SEGMENT-LIST.
756 FORCE and USE-LOAD-PATH have the same meaning as in
757 `elinstall-update-deffile'.
762 ((deffile (car segment
)))
763 (if (stringp deffile
)
764 (elinstall-update-deffile
770 ;;;_ , Doing actions to arrange preloads
771 ;;;_ . elinstall-symlink-on-emacs-start
772 (defun elinstall-symlink-on-emacs-start
773 (filename target-basename target-dir
&optional priority
)
774 "Symlink to TARGET-BASENAME.el in TARGET-DIR
776 If PRIORITY is given, it will be used as the priority prefix,
777 otherwise elinstall-default-priority will be.
778 PRIORITY must be an integer or nil."
781 (priority (or priority elinstall-default-priority
))
788 (expand-file-name target-name-nodir target-dir
)))
792 ;;Path should already exist.
794 (file-exists-p target-dir
))
795 (message "The target directory doesn't exist."))
796 ;;$$IMPROVE ME If it is a symlink pointing to the same place,
799 ;;$$IMPROVE ME The condition here is not updating but
800 ;;bulldozing a possibly different symlink. Add another
801 ;;treatment symbol meaning to bulldoze what's in the way.
802 ((elinstall-proceed-p 'preloads-compile
805 "Really overwrite %s? "
806 "File %s already exists")
808 (file-exists-p target
))
814 ;;;_ . elinstall-add-to-dot-emacs
815 (defun elinstall-add-to-dot-emacs (dot-emacs-name filename
&rest r
)
816 "Add code to load FILENAME to .emacs.
817 FILENAME should not have an extension"
820 (with-current-buffer (find-file-noselect dot-emacs-name
)
823 (goto-char (point-max))
824 (insert "\n;;Added by elinstall")
825 (insert "\n;;Consider using my-site-start to manage .emacs\n")
826 (pp `(load ,filename
) (current-buffer))
830 ;;;_ . elinstall-arrange-preload
832 (defun elinstall-arrange-preload (filename basename
&optional priority
)
833 "Arrange for FILENAME to be loaded on emacs start.
834 BASENAME and PRIORITY are used as arguments to
835 `elinstall-symlink-on-emacs-start'.
839 ((preload-target elinstall-default-preload-target
))
841 ;;Dispatch the possibilities.
843 ((eq preload-target
'dot-emacs
)
844 (elinstall-add-to-dot-emacs "~/.emacs" filename
))
845 ((stringp preload-target
)
846 (elinstall-symlink-on-emacs-start
847 filename basename preload-target priority
))
848 ((null preload-target
)
849 (message "Not arranging for preloads"))
851 (message "I don't recognize that")))))
852 ;;;_ . elinstall-stage-arrange-preloads
853 (defun elinstall-stage-arrange-preloads (actions deffiles-used
)
854 "Arrange any preloads mentioned in ACTIONS."
868 (member filename deffiles-used
)))))
872 #'elinstall-arrange-preload
876 "elinstall-stage-arrange-preloads: Action not
882 ;;;_ . elinstall-stage-run-tests
883 (defun elinstall-stage-run-tests (actions)
884 "Run any tests mentioned in ACTIONS."
890 ;;$$WRITE ME - not a high priority right now.
894 "elinstall-stage-run-tests: Action not
900 ;;;_ . elinstall-stage-byte-compile
901 (defun elinstall-stage-byte-compile (actions)
902 "Do any byte-compilation mentioned in ACTIONS."
907 ;;$$IMPROVE ME Understand flags to control second
908 ;;argument (whether to load file after
911 (byte-compile-file (second act
)))
914 "elinstall-stage-byte-compile: Action not
917 ;;;_ . Segregating actions
918 ;;;_ , elinstall-remove-empty-segs
919 (defun elinstall-remove-empty-segs (segment-list)
920 "Return SEGMENT-LIST minus any segments that have no actions.
921 Intended only for the deffile stage data."
930 ;;;_ , elinstall-segregate-actions
931 (defun elinstall-segregate-actions (actions)
932 "Return actions segregated by deffile.
934 Returns a list whose elements are each a cons of:
935 * deffile filename or nil
936 * A list of actions to be done for that deffile."
943 (arrange-preloads '()))
945 (dolist (act actions
)
952 ((deffile-name (second act
))
954 (assoc deffile-name build-deffiles
)))
956 ;;There are already actions on this deffile.
957 ;;Splice this action in.
959 (cons act
(cdr cell-already
)))
960 ;;There are no actions on this deffile. Add a
961 ;;place for them and include this action.
962 (push (list deffile-name act
) build-deffiles
))))
964 (push act arrange-preloads
))
966 (push act run-tests
))
968 (push act byte-compile
)))))
970 (elinstall-make-stages
972 (elinstall-remove-empty-segs build-deffiles
)
979 ;;;_ . Finding actions
981 ;;;_ . elinstall-dir-has-info
983 ;;$$IMPROVE ME - Can this test be made more precise?
984 (defun elinstall-dir-has-info (dir)
985 "Return non-nil if DIR has info files in it.
986 DIR should be an absolute path."
988 (string-match "/info/" dir
)
989 (directory-files dir nil
"\\.info\\(-[0-9]+\\)?\\(\\.gz\\)?$")))
990 ;;;_ . elinstall-directory-files
991 (defun elinstall-directory-files (dirname)
992 "Return a list of files in directory DIRNAME, minus certain files.
993 The following files are omitted:
995 * Files that match an entry in `block-in-subtree'.
996 Filenames are relative."
998 def-file block-in-dir block-in-subtree
))
1001 ;;Relative filenames of this directory's files.
1003 ;; Don't include dot files. If user really wants to
1004 ;;explore one he can use (dir ".NAME") or (file ".NAME")
1005 (directory-files dirname nil
"[^\\.]"))
1006 ;;We know our def-file isn't really source so remove it.
1007 ;;We'd have removed it anyways after seeing file local vars.
1009 (remove def-file all-files
))
1014 #'(lambda (filename)
1020 (string-match blocked filename
))
1029 ;;;_ . List of special variables used in this section
1030 ;;load-path-element - The relevant element of load-path
1031 ;;def-file - The file the autoload definitions etc will go into.
1032 ;;add-to-load-path-p - Controls whether to add to load-path.
1033 ;;recurse-dirs-p - Whether to recurse into subdirectories.
1035 ;;block-in-dir - (NOT IMPLEMENTED) List of filenames to reject. They
1036 ;;may include wildcards. They apply wrt the original directory.
1038 ;;block-in-subtree - (NOT IMPLEMENTED) List of filenames to reject.
1039 ;;They may include wildcards. They apply wrt any directory in the
1040 ;;tree. Specifically, in the spec tree, which may differ from the
1042 ;;byte-compile - whether to byte-compile at all, t by default.
1043 ;;autoloads - boolean whether to make autoloads, t by default.
1044 ;;preloads - boolean whether to set up preloads, t by default.
1045 (defconst elinstall-find-actions-control-vars
1046 '(add-to-load-path-p recurse-dirs-p byte-compile
1048 "Control special variables that the find-actions tree recognizes" )
1049 ;;;_ . elinstall-actions-for-source-file
1050 (defun elinstall-actions-for-source-file (filename dir
)
1051 "Return a list of actions to do for FILENAME in DIR.
1052 Special variables are as noted in \"List of special variables\"."
1054 load-path-element def-file byte-compile
))
1057 (expand-file-name filename dir
)))
1060 (file-readable-p full-path
)
1061 (not (auto-save-file-name-p full-path
))
1062 (string-match emacs-lisp-file-regexp filename
))
1065 (visited (get-file-buffer full-path
))
1069 ;;Visit the file cheaply.
1070 ;;hack-local-variables can give errors.
1071 (ignore-errors (autoload-find-file full-path
))))
1075 (with-current-buffer buf
1076 (if (local-variable-p 'generated-autoload-file
)
1077 (elinstall-expand-deffile-name
1078 generated-autoload-file
)
1081 ;;Figure out whether to run some actions, by file local vars.
1085 (with-current-buffer buf
1086 (not no-update-autoloads
)))
1087 (elinstall-proceed-p 'autoloads
1089 '( "Do autoloads for %s? ")
1095 (featurep 'byte-compile
)
1097 (with-current-buffer buf
1098 (not no-byte-compile
)))
1099 (elinstall-proceed-p 'byte-compile
1103 "Already compiled %s.")
1106 ((dest (byte-compile-dest-file full-path
)))
1108 (file-exists-p dest
)
1109 (file-newer-than-file-p full-path dest
)))))))
1114 `(byte-compile ,full-path
)
1117 (elinstall-make-autoload-action
1118 buf def-file load-path-element full-path
)
1120 (unless visited
(kill-buffer-if-not-modified buf
)))))))
1121 ;;;_ . elinstall-actions-for-dir
1122 (defun elinstall-actions-for-dir (dirname &optional recurse-dirs-p
)
1123 "Make actions for DIR.
1124 Recurse just if RECURSE-DIRS-P"
1126 load-path-element def-file add-to-load-path-p
))
1127 ;;This does not treat symlinks specially. $$IMPROVE ME it could
1128 ;;treat/not treat them conditional on control variables.
1131 (files (elinstall-directory-files dirname
))
1133 ;;Relative filenames of elisp source
1137 #'(lambda (filename)
1139 (string-match elinstall-elisp-regexp filename
)
1144 ;;Absolute filenames of subdirectories.
1149 #'(lambda (filename)
1151 ((fn (expand-file-name filename dirname
)))
1153 (file-directory-p fn
)
1161 elisp-source-files
;;If list is not empty.
1162 add-to-load-path-p
))
1164 (if load-path-here-p
1166 load-path-element
)))
1169 ;;Sometimes arrange to add this directory to load-path.
1170 (if load-path-here-p
1173 ,load-path-element
))
1176 ;;$$IMPROVE ME - be controlled by a control variable.
1177 ;;Sometimes add this directory to info path.
1179 (elinstall-dir-has-info dirname
)
1187 #'(lambda (filename)
1188 (elinstall-actions-for-source-file
1191 elisp-source-files
))
1196 #'(lambda (filename)
1197 (elinstall-find-actions-by-spec-x
1205 ;;;_ . elinstall-find-actions-by-spec-x
1207 (defun elinstall-find-actions-by-spec-x (spec dir
)
1208 "Return a list of actions to do, controlled by SPEC."
1210 load-path-element def-file add-to-load-path-p
1211 recurse-dirs-p block-in-dir block-in-subtree
))
1219 #'(lambda (sub-spec)
1220 (elinstall-find-actions-by-spec-x
1225 ;;(block-in-subtree (* FN) SPEC)
1227 ((block-in-subtree (second spec
)))
1228 (elinstall-find-actions-by-spec-x
1232 ;;Rather than trying to bind all control variables each time
1233 ;;thru, we use `set' and `unwind-protect'.
1235 ;;control TYPE DISPOSITION SPEC
1237 ((key (second spec
))
1239 (if (memq key elinstall-find-actions-control-vars
)
1242 (setq old-value
(symbol-value key
))
1243 (set key
(third spec
))
1244 (elinstall-find-actions-by-spec-x
1247 (set key old-value
))
1248 (error "Unrecognized control variable %s" key
))))
1252 ;;(def-file FN ARGS SPEC)
1258 (for-preload (third spec
)))
1259 (assert (listp for-preload
))
1263 (and for-preload
(car for-preload
))
1267 ,@(cdr for-preload
))
1270 (elinstall-find-actions-by-spec-x
1271 (fourth spec
) dir
))))
1275 (elinstall-actions-for-dir
1283 (elinstall-actions-for-source-file
1294 (elinstall-find-actions-by-spec-x
1301 `((add-to-load-path ,def-file
,dir
))
1303 ((load-path-element dir
)
1304 (add-to-load-path-p nil
))
1305 (elinstall-find-actions-by-spec-x
1310 ;;(matching PATTERN SPEC)
1314 ;;$$PUNT Assume that `block-in-subtree' and
1315 ;;`block-in-dir' aren't matched.
1316 (elinstall-find-actions-by-spec-x
1320 dir t
(second spec
)))))
1322 ;;(preload FN SYM &rest ARGS)
1324 ((key (third spec
)))
1326 (and (symbolp key
) (symbol-value key
))
1329 ,(expand-file-name (second spec
) dir
)
1336 (elinstall-actions-for-dir dir nil
))
1338 (elinstall-actions-for-dir dir t
)))))
1340 ;;;_ . elinstall-find-actions-by-spec
1341 (defun elinstall-find-actions-by-spec
1342 (spec load-path-element dir def-file
)
1343 "Find the list of actions to do according to SPEC."
1347 (def-file-time (elinstall-file-mod-time def-file
))
1348 (add-to-load-path-p t
)
1354 (block-in-subtree '(".git" "RCS" "CVS" "SVN" "^tests\.el")))
1357 load-path-element def-file add-to-load-path-p
1358 recurse-dirs-p byte-compile
1359 block-in-dir block-in-subtree
))
1361 (elinstall-find-actions-by-spec-x spec dir
)))
1363 ;;;_ . high-level work
1364 ;;;_ , elinstall-get-relevant-load-path
1365 (defun elinstall-get-relevant-load-path (actions)
1375 ;;;_ , elinstall-get-deffile-list
1376 (defun elinstall-get-deffile-list (stages)
1377 "Get a list of deffile names"
1381 (elinstall-stages->build-deffiles stages
)))
1383 (defun elinstall-x (dir spec
)
1384 "High-level worker function to install elisp files."
1387 ;;This is just the default deffile, spec can override it.
1389 (elinstall-expand-deffile-name nil
))
1391 (elinstall-find-actions-by-spec
1396 (stages (elinstall-segregate-actions actions
))
1398 (elinstall-get-relevant-load-path
1401 (elinstall-stage-update-deffiles
1402 (elinstall-stages->build-deffiles stages
)
1404 (elinstall-stage-arrange-preloads
1405 (elinstall-stages->arrange-preloads stages
)
1406 (elinstall-get-deffile-list stages
))
1407 (elinstall-stage-byte-compile
1408 (elinstall-stages->byte-compile stages
))
1410 ;;;_ , elinstall-package
1411 (defun elinstall-package (project-name path spec version-string
)
1412 "Install elisp files. See doc for `elinstall'."
1414 (elinstall-proceed-p 'install
1418 "Already installed %s.")
1420 (elinstall-already-installed project-name
))
1423 `(def-file "loaddefs.el" (if-used ,project-name
) ,spec
))
1424 (elinstall-record-installed project-name version-string
)))
1429 (defun elinstall (project-name path spec
&optional force version-string
)
1430 "Install elisp files.
1431 They need not be a formal package.
1435 PROJECT-NAME - the name of the project
1437 PATH - Path to the project.
1438 Suggestion: Use (elinstall-directory-true-name) to get the real
1439 current directoery name even from loaded files.
1441 SPEC - a spec for the autoloads etc to make. It can be as simple
1444 If FORCE is `t', install a package even if it has already been
1445 installed. If it's a list or `nil', it's treated as a list of
1446 installation restraints. User customizations override this
1449 VERSION-STRING, if given, must be a string of the version for this package."
1451 (elinstall-call-with-restraints
1457 project-name path spec version-string
))
1459 ;;;_ . elinstall-update-directory-autoloads
1462 (defun elinstall-update-directory-autoloads (dir)
1463 "Update autoloads for directory DIR"
1465 (interactive "DUpdate autoloads for all elisp files from directory: ")
1466 (elinstall-call-with-restraints
1474 ;;;_ . elinstall-update-directory
1476 (defun elinstall-update-directory (dir)
1477 "Update autoloads for directory DIR"
1479 (interactive "DInstall all elisp files from directory: ")
1480 (elinstall-call-with-restraints
1487 ;;;_ . elinstall-update-file-autoloads
1489 (defun elinstall-update-file-autoloads (file)
1490 "Update autoloads for elisp file FILE"
1492 (interactive "fUpdate autoloads for elisp file: ")
1493 (elinstall-call-with-restraints
1497 (file-name-directory file
)
1498 `(file ,(file-name-nondirectory file
))))
1500 ;;;_ . elinstall-update-file
1502 (defun elinstall-update-file (file)
1503 "Install elisp file FILE"
1505 (interactive "fInstall elisp file: ")
1506 (elinstall-call-with-restraints
1511 (file-name-directory file
)
1512 `(file ,(file-name-nondirectory file
))))
1517 (provide 'elinstall
)
1519 ;;;_ * Local emacs vars.
1520 ;;;_ + Local variables:
1525 ;;; elinstall.el ends here