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 customizations
)
95 (const :tag
"Use as default" t
))
98 :tag
"Do this unless it's up to date"
101 :tag
"Use the package spec for this"
104 :tag
"Don't do this at all"
110 :tag
"Ask only when it's up-to-date."
113 :tag
"Do everything even if it's up to date."
117 ;;;_ . elinstall-already-installed
119 (defcustom elinstall-already-installed
121 "(AUTOMATIC) Things that have already been installed.
122 This exists for recording what has been installed.
124 Though it's saved as customizable, user interaction is not
126 ;;Tell the byte-compiler it's a variable.
127 (defvar elinstall-already-installed
)
129 ;;;_ . elinstall-stages
130 (defstruct (elinstall-stages
131 (:constructor elinstall-make-stages
)
132 (:conc-name elinstall-stages-
>)
134 "The elinstall stages"
140 ;;;_ . Regular expressions
141 ;;;_ , elinstall-elisp-regexp
142 (defconst elinstall-elisp-regexp
145 (suf (get-load-suffixes))
146 (unless (string-match "\\.elc" suf
) (push suf tmp
)))
147 (concat "^[^=.].*" (regexp-opt tmp t
) "\\'"))
148 "Regular expression that matches elisp files" )
150 ;;;_ . elinstall-file-mod-time
151 (defsubst elinstall-file-mod-time
(file)
152 "Return the modification time of FILE"
153 (nth 5 (file-attributes file
)))
155 ;;;_ . elinstall-directory-true-name
156 (defun elinstall-directory-true-name ()
157 "Get the true name of the directory the calling code lives in.
158 CAUTION: This is sensitive to where it's called. That's the point of it."
161 (file-truename load-file-name
)
162 (file-truename buffer-file-name
))))
163 ;;;_ . Checking installedness
164 ;;;_ , elinstall-get-installation-record
165 (defun elinstall-get-installation-record (project-name)
166 "Return the installation record for PROJECT-NAME."
168 (assoc project-name elinstall-already-installed
))
170 ;;;_ , elinstall-already-installed
171 (defun elinstall-already-installed (project-name)
172 "Return non-nil if PROJECT-NAME has been installed."
173 (elinstall-get-installation-record project-name
))
175 ;;;_ , elinstall-record-installed
176 (defun elinstall-record-installed (project-name &optional version
)
177 "Record that PROJECT-NAME has been installed."
186 (elinstall-get-installation-record project-name
))
190 (setq elinstall-already-installed
191 (delete old-item elinstall-already-installed
)))
192 (push new-item elinstall-already-installed
)
193 (customize-save-variable
194 'elinstall-already-installed
195 elinstall-already-installed
196 "Set by elinstall-record-installed")))
197 ;;;_ . Finding deffiles
198 ;;;_ , elinstall-expand-deffile-name
199 (defun elinstall-expand-deffile-name (deffile)
200 "Expand DEFFILE autoload.el's way."
202 (expand-file-name (or deffile
"loaddefs.el")
203 (expand-file-name "lisp"
205 ;;;_ . Checking restraint specs
206 ;;;_ , elinstall-call-with-restraints
207 (defun elinstall-call-with-restraints (restraints package func
&rest args
)
208 "Call FUNC with ARGS, in scope of RESTRAINTS.
209 RESTRAINTS is a list of package restraints. User restraints for the
210 given package will also be applied in scope.
212 PACKAGE can be `t' or a string naming a package."
215 ((elinstall:*pkg-restraints
* restraints
)
216 (elinstall:*user-restraints
*
220 (assoc package elinstall-restrain-install
)
221 (assoc t elinstall-restrain-install
))))
226 elinstall
:*pkg-restraints
*
227 elinstall
:*user-restraints
*))
229 ;;;_ , elinstall-get-restraint
230 (defun elinstall-get-restraint (topic)
231 "Get the applicable restraint symbol for TOPIC.
232 Call this transitively only thru `elinstall-call-with-restraints'."
233 (check-type topic symbol
)
235 elinstall
:*pkg-restraints
*
236 elinstall
:*user-restraints
*))
238 (boundp 'elinstall
:*pkg-restraints
*)
239 (boundp 'elinstall
:*user-restraints
*))
240 (error "elinstall-proceed-p called out of scope"))
245 (assq topic elinstall
:*user-restraints
*)
246 (assq t elinstall
:*user-restraints
*)))
248 ;;`t' means use the pkg-restraints value instead.
250 (or (not cell
) (eq (second cell
) t
))
252 (assq topic elinstall
:*pkg-restraints
*)
253 (assq t elinstall
:*pkg-restraints
*))
255 ;;Default is to just update.
256 (if cell
(second cell
) 'update
)))
258 ;;;_ , elinstall-proceed-p
259 (defun elinstall-proceed-p
260 (topic message-params
&optional already-p
)
261 "Return non-nil if actions on TOPIC should proceed.
262 Call this transitively only thru `elinstall-call-with-restraints'.
263 TOPIC is a symbol indicating the topic, such as `byte-compile'.
264 MESSAGE-PARAMS is a cons of:
265 * A list of format strings:
266 * To ask whether to do this action
267 * To ask whether to redo this action, for `ask-for-old'
268 * To report that this action was skipped because already done.
269 * The arguments to the formatter.
270 ALREADY-P is an extended boolean whether the task has been done
271 before, if caller can tell."
275 ((ask-prompt &optional redo-prompt noredo-msg
) &rest message-args
)
277 (case (elinstall-get-restraint topic
)
285 (apply #'message noredo-msg message-args
)
290 (y-or-n-p (apply #'format redo-prompt message-args
))
294 (apply #'format ask-prompt message-args
))))))
295 ;;;_ , elinstall-proceed-at-all-p
296 (defsubst elinstall-proceed-at-all-p
(topic)
297 "Return non-nil if there's any possibility that actions on TOPIC should proceed."
298 ;;It just so happens that `nil' treatment corresponds to `nil'
300 (elinstall-get-restraint topic
))
305 ;;;_ , Doing autoload actions (adapted from autoload.el)
306 ;;;_ . Utilities about the action list
307 ;;;_ , elinstall-remove-autogen-action
308 (defun elinstall-remove-autogen-action (file actions
)
309 "Return ACTIONS minus any add-file-autoloads on FILE removed."
316 (if (equal file
(third act
))
321 ;;;_ , elinstall-get-autogen-action
322 (defun elinstall-get-autogen-action (file actions
)
326 (dolist (act actions
)
329 (when (equal file
(third act
))
330 (setq the-act act
)))))
332 ;;;_ . About printing to autoload file
333 ;;;_ , elinstall-insert-section-header
334 (defun elinstall-insert-section-header (outbuf form
)
335 "Insert the section-header line,
336 which lists the file name and which functions are in it, etc."
337 (insert generate-autoload-section-header
)
340 ;; Break that line at spaces, to avoid very long lines.
341 ;; Make each sub-line into a comment.
342 (with-current-buffer outbuf
347 (skip-chars-forward "^ \n")
349 (insert "\n" generate-autoload-section-continuation
))))))
351 ;;;_ , elinstall-insert-autoload-section
352 (defun elinstall-insert-autoload-section (text form
&optional comment-string
)
353 "Insert TEXT into current buffer as an autoload section"
358 ;; This does something in Lucid Emacs.
360 (float-output-format nil
))
362 (elinstall-insert-section-header (current-buffer) form
)
364 (insert ";;; " comment-string
"\n"))
366 (insert generate-autoload-section-trailer
)))
368 ;;;_ . Making autoloads
369 ;;;_ , elinstall-make-autoload-action
370 (defun elinstall-make-autoload-action (buf def-file load-path-element full-path
)
371 "Return the autoloads for current buffer as a string"
373 ;;We put all the text into a temp buffer, then get that buffer's
377 (generate-new-buffer " *temp*"))
380 (file-name-nondirectory full-path
))
384 ;; Apparently this does something in Lucid Emacs.
386 (float-output-format nil
)
388 ;;load-name relative to a member of load-path.
390 (file-name-sans-extension
393 load-path-element
))))
395 (with-current-buffer buf
400 (goto-char (point-min))
401 (message "Finding autoloads for %s..." short-name
)
403 (skip-chars-forward " \t\n\f")
405 ((looking-at (regexp-quote generate-autoload-cookie
))
406 (search-forward generate-autoload-cookie
)
407 (skip-chars-forward " \t")
409 ;; Read the next form and make an autoload.
410 (let* ((form (prog1 (read (current-buffer))
411 (or (bolp) (forward-line 1))))
413 (make-autoload form relative-name
)))
415 (push (nth 1 form
) autoloads-done
)
416 (setq autoload form
))
417 (let ((autoload-print-form-outbuf outbuf
))
418 (autoload-print-form autoload
)))
420 ;; Copy the rest of the line to the output.
421 (princ (buffer-substring
423 ;; Back up over whitespace,
425 (skip-chars-backward " \f\t")
426 (if (= (char-after (1+ (point))) ?
)
430 (progn (forward-line 1) (point)))
433 ;; Don't read the comment.
438 (message "Finding autoloads for %s...done" short-name
))
440 ;;Return this action. The temp buffer's contents is
446 ,(with-current-buffer outbuf
(buffer-string))
449 ;;This in unwind-protected
450 (when (buffer-live-p outbuf
) (kill-buffer outbuf
))))))
453 ;;;_ , elinstall-generate-file-autoloads
455 (defun elinstall-generate-file-autoloads
456 (relative-name full-name text autoloads-done
)
457 "Insert at point a loaddefs autoload section for FILE.
458 Autoloads are generated for defuns and defmacros in FILE
459 marked by `generate-autoload-cookie' (which see).
460 If FILE is being visited in a buffer, the contents of the buffer
462 Return non-nil in the case where no autoloads were added at point.
464 FULL-NAME is the absolute name of the file.
465 RELATIVE-NAME is its name respective to some component of load-path."
466 (if (not (equal text
""))
467 ;; Insert the section-header line which lists the file name and
468 ;; which functions are in it, etc.
469 (elinstall-insert-autoload-section
474 (autoload-trim-file-name full-name
)
475 (elinstall-file-mod-time full-name
))
477 "Generated autoloads from "
478 (autoload-trim-file-name full-name
)))
481 ;;;_ , elinstall-deffile-insert-autoloads
482 (defun elinstall-deffile-insert-autoloads (file args
)
483 "Update the autoloads for FILE in current buffer.
484 Return FILE if there was no autoload cookie in it, else nil.
486 Current buffer must be a loaddef-style file.
488 LOAD-NAME is the absolute name of the file.
489 RELATIVE-NAME is its name respective to some component of load-path."
497 (goto-char (point-min))
498 ;; Look for the section for FILE
499 (while (and (not found
)
500 (search-forward generate-autoload-section-header nil t
))
501 (let ((form (autoload-read-section-header)))
503 ((equal (nth 2 form
) file
)
504 ;; We found the section for this file.
505 (let ((begin (match-beginning 0)))
507 (search-forward generate-autoload-section-trailer
)
508 (delete-region begin
(point))
510 ((string< file
(nth 2 form
))
511 ;; We've come to a section alphabetically later than
512 ;; FILE. We assume the file is in order and so
513 ;; there must be no section for FILE. We will
514 ;; insert one before the section here.
515 (goto-char (match-beginning 0))
516 (setq found
'new
)))))
520 ;; No later sections in the file. Put before the last page.
521 (goto-char (point-max))
522 (search-backward "\f" nil t
)))
524 (apply #'elinstall-generate-file-autoloads
527 (if no-autoloads file nil
)))
528 ;;;_ . Arranging to add to info-path and load-path
529 ;;;_ , elinstall-generate-add-to-path
530 (defun elinstall-generate-add-to-path (path-element type
)
531 "Insert code at point to add PATH-ELEMENT to a path.
533 * `add-to-load-path', add to load-path
534 * `add-to-info-path', add to Info-additional-directory-list
536 Current buffer must be a loaddef-style file."
539 (add-to-load-path 'load-path
)
540 (add-to-info-path 'Info-additional-directory-list
)
541 (t (error "Type not recognized"))))
544 (add-to-load-path "load-path")
545 (add-to-info-path "info-path")))
549 ;; This does something in Lucid Emacs.
551 (float-output-format nil
))
553 (message "Generating %s additions..." description
)
555 (elinstall-insert-autoload-section
557 `(add-to-list ',path-symbol
559 ,(file-relative-name path-element
)
562 (file-truename load-file-name
))))))
563 (list type
(list path-element
) nil nil nil
)
565 (message "Generating %s additions...done" description
)))
568 ;;;_ , elinstall-deffile-insert-add-to-path
569 (defun elinstall-deffile-insert-add-to-path (path-element type
)
570 "Insert code in current buffer to add PATH-ELEMENT to a path.
572 * `add-to-load-path', add to load-path
573 * `add-to-info-path', add to Info-default-directory-list
575 Current buffer must be a loaddef-style file."
583 (goto-char (point-min))
584 ;; Look for the section for PATH-ELEMENT
585 (while (and (not found
)
586 (search-forward generate-autoload-section-header nil t
))
587 (let ((form (autoload-read-section-header)))
590 (equal (nth 0 form
) type
)
591 (member path-element
(nth 1 form
)))
593 ;; We found the section for this add.
594 (let ((begin (match-beginning 0)))
596 (search-forward generate-autoload-section-trailer
)
597 (delete-region begin
(point))
603 ;; No later sections in the file. Put before the last page.
604 (goto-char (point-max))
605 (search-backward "\f" nil t
)))
607 (elinstall-generate-add-to-path path-element type
)))
609 ;;This never belongs in the no-autoloads section.
611 ;;;_ . elinstall-deffile-insert
613 (defun elinstall-deffile-insert (action)
614 "Insert autoloads etc into current file according to ACTION.
615 The format of ACTION is described in the design docs.
617 Return filename if this action belongs in the no-autoload section."
622 (elinstall-deffile-insert-autoloads
627 (elinstall-deffile-insert-add-to-path
633 (elinstall-deffile-insert-add-to-path
638 ((preload-file run-tests byte-compile
)
639 (error "This case should not come here.")))))
641 ;;;_ . elinstall-prepare-deffile
642 (defun elinstall-prepare-deffile (deffile)
643 "Try to ensure that DEFFILE is available for receiving autoloads"
645 (autoload-ensure-default-file deffile
)
646 (with-current-buffer (find-file-noselect deffile
)
649 ;; We must read/write the file without any code conversion,
650 ;; but still decode EOLs.
651 (let ((coding-system-for-read 'raw-text
))
653 ;; This is to make generated-autoload-file have Unix EOLs, so
654 ;; that it is portable to all platforms.
655 (setq buffer-file-coding-system
'raw-text-unix
))
656 (or (> (buffer-size) 0)
657 (error "Autoloads file %s does not exist" buffer-file-name
))
658 (or (file-writable-p buffer-file-name
)
659 (error "Autoloads file %s is not writable"
662 ;;;_ . elinstall-update-deffile
664 ;;Adapted from autoload.el `update-directory-autoloads'.
666 (defun elinstall-update-deffile (target actions
&optional use-load-path
)
668 Update file TARGET with current autoloads as specified by ACTIONS.
669 Also remove any old definitions pointing to libraries that can no
672 ACTIONS must be a list of actions (See the format doc). Each one's
673 filename must be relative to some element of load-path.
675 USE-LOAD-PATH is a list to use as load-path. It should include
676 any new load-path that we are arranging to create. If it's not given,
677 load-path itself is used.
679 This uses `update-file-autoloads' (which see) to do its work.
680 In an interactive call, you must give one argument, the name
681 of a single directory."
684 (use-load-path (or use-load-path load-path
))
685 (this-time (current-time))
686 ;;files with no autoload cookies.
689 (elinstall-prepare-deffile target
)
691 (find-file-noselect target
)
694 (elinstall-remove-autogen-action
695 (autoload-trim-file-name target
)
698 (goto-char (point-min))
699 (while (search-forward generate-autoload-section-header nil t
)
700 (let* ((form (autoload-read-section-header))
702 (cond ((and (consp file
) (stringp (car file
)))
703 ;; This is a list of files that have no
705 ;; There shouldn't be more than one such entry.
706 ;; Remove the obsolete section.
707 (autoload-remove-section (match-beginning 0))
708 (let ((last-time (nth 4 form
)))
710 (let ((file-time (elinstall-file-mod-time file
)))
712 (not (time-less-p last-time file-time
)))
714 (push file no-autoloads
)
716 (elinstall-remove-autogen-action
718 ((not (stringp file
)))
722 (locate-library file nil use-load-path
)))
724 ;;$$MAKE ME SAFER Also check normal
725 ;;load-path in case `use-load-path' is
727 ;;$$MAKE ME SAFER Don't do this for a
728 ;;file we are inserting. Need a boolean
729 ;;return for checking that.
730 ;;File doesn't exist, so remove its
733 (autoload-remove-section
734 (match-beginning 0)))
735 ;;$$IMPROVE ME Consult elinstall-proceed-p.
736 ;; File hasn't changed, so do nothing.
739 (elinstall-file-mod-time file-path
))
742 (elinstall-deffile-insert
743 (elinstall-get-autogen-action
747 (elinstall-remove-autogen-action
750 ;; Remaining actions have no existing autoload sections yet.
753 (delq nil
(mapcar #'elinstall-deffile-insert actions
))))
755 ;; Sort them for better readability.
756 (setq no-autoloads
(sort no-autoloads
'string
<))
757 ;; Add the `no-autoloads' section.
758 (goto-char (point-max))
759 (search-backward "\f" nil t
)
760 (elinstall-insert-autoload-section
762 (list 'autoloads nil nil no-autoloads this-time
)))
765 ;;;_ . elinstall-stage-update-deffiles
766 (defun elinstall-stage-update-deffiles (segment-list use-load-path
)
767 "Update any deffiles mentioned in SEGMENT-LIST.
768 FORCE and USE-LOAD-PATH have the same meaning as in
769 `elinstall-update-deffile'.
774 ((deffile (car segment
)))
775 (if (stringp deffile
)
776 (elinstall-update-deffile
782 ;;;_ , Doing actions to arrange preloads
783 ;;;_ . elinstall-symlink-on-emacs-start
784 (defun elinstall-symlink-on-emacs-start
785 (filename target-basename target-dir
&optional priority
)
786 "Symlink to TARGET-BASENAME.el in TARGET-DIR
788 If PRIORITY is given, it will be used as the priority prefix,
789 otherwise elinstall-default-priority will be.
790 PRIORITY must be an integer or nil."
793 (priority (or priority elinstall-default-priority
))
800 (expand-file-name target-name-nodir target-dir
)))
804 ;;Path should already exist.
806 (file-exists-p target-dir
))
807 (message "The target directory doesn't exist."))
808 ;;$$IMPROVE ME If it is a symlink pointing to the same place,
811 ;;$$IMPROVE ME The condition here is really not updating but
812 ;;bulldozing a possibly different symlink. Add another
813 ;;treatment symbol meaning to bulldoze what's in the way.
814 ((elinstall-proceed-p 'preloads
817 "Really overwrite %s? "
818 "File %s already exists")
820 (file-exists-p target
))
826 ;;;_ . elinstall-add-to-dot-emacs
827 (defun elinstall-add-to-dot-emacs (dot-emacs-name filename
&rest r
)
828 "Add code to load FILENAME to .emacs.
829 FILENAME should not have an extension"
832 (with-current-buffer (find-file-noselect dot-emacs-name
)
835 (goto-char (point-max))
836 (insert "\n;;Added by elinstall")
837 (insert "\n;;Consider using my-site-start to manage .emacs\n")
838 (pp `(load ,filename
) (current-buffer))
842 ;;;_ . elinstall-arrange-preload
844 (defun elinstall-arrange-preload (filename basename
&optional priority
)
845 "Arrange for FILENAME to be loaded on emacs start.
846 BASENAME and PRIORITY are used as arguments to
847 `elinstall-symlink-on-emacs-start'.
851 ((preload-target elinstall-default-preload-target
))
853 ;;Dispatch the possibilities.
855 ((eq preload-target
'dot-emacs
)
856 (elinstall-add-to-dot-emacs "~/.emacs" filename
))
857 ((stringp preload-target
)
858 (elinstall-symlink-on-emacs-start
859 filename basename preload-target priority
))
860 ((null preload-target
)
861 (message "Not arranging for preloads"))
863 (message "I don't recognize that")))))
864 ;;;_ . elinstall-stage-arrange-preloads
865 (defun elinstall-stage-arrange-preloads (actions deffiles-used
)
866 "Arrange any preloads mentioned in ACTIONS."
880 (member filename deffiles-used
)))))
884 #'elinstall-arrange-preload
888 "elinstall-stage-arrange-preloads: Action not
894 ;;;_ . elinstall-stage-run-tests
895 (defun elinstall-stage-run-tests (actions)
896 "Run any tests mentioned in ACTIONS."
902 ;;$$WRITE ME - not a high priority right now.
906 "elinstall-stage-run-tests: Action not
912 ;;;_ . elinstall-stage-byte-compile
913 (defun elinstall-stage-byte-compile (actions)
914 "Do any byte-compilation mentioned in ACTIONS."
919 ;;$$IMPROVE ME Understand flags to control second
920 ;;argument (whether to load file after
923 (byte-compile-file (second act
)))
926 "elinstall-stage-byte-compile: Action not
929 ;;;_ . Segregating actions
930 ;;;_ , elinstall-remove-empty-segs
931 (defun elinstall-remove-empty-segs (segment-list)
932 "Return SEGMENT-LIST minus any segments that have no actions.
933 Intended only for the deffile stage data."
942 ;;;_ , elinstall-segregate-actions
943 (defun elinstall-segregate-actions (actions)
944 "Return actions segregated by deffile.
946 Returns a list whose elements are each a cons of:
947 * deffile filename or nil
948 * A list of actions to be done for that deffile."
955 (arrange-preloads '()))
957 (dolist (act actions
)
964 ((deffile-name (second act
))
966 (assoc deffile-name build-deffiles
)))
968 ;;There are already actions on this deffile.
969 ;;Splice this action in.
971 (cons act
(cdr cell-already
)))
972 ;;There are no actions on this deffile. Add a
973 ;;place for them and include this action.
974 (push (list deffile-name act
) build-deffiles
))))
976 (push act arrange-preloads
))
978 (push act run-tests
))
980 (push act byte-compile
)))))
982 (elinstall-make-stages
984 (elinstall-remove-empty-segs build-deffiles
)
991 ;;;_ . Finding actions
993 ;;;_ . elinstall-dir-has-info
995 ;;$$IMPROVE ME - Can this test be made more precise?
996 (defun elinstall-dir-has-info (dir)
997 "Return non-nil if DIR has info files in it.
998 DIR should be an absolute path."
1000 (string-match "/info/" dir
)
1001 (directory-files dir nil
"\\.info\\(-[0-9]+\\)?\\(\\.gz\\)?$")))
1002 ;;;_ . elinstall-directory-files
1003 (defun elinstall-directory-files (dirname)
1004 "Return a list of files in directory DIRNAME, minus certain files.
1005 The following files are omitted:
1007 * Files that match an entry in `block-in-subtree'.
1008 Filenames are relative."
1010 def-file block-in-dir block-in-subtree
))
1013 ;;Relative filenames of this directory's files.
1015 ;; Don't include dot files. If user really wants to
1016 ;;explore one he can use (dir ".NAME") or (file ".NAME")
1017 (directory-files dirname nil
"[^\\.]"))
1018 ;;We know our def-file isn't really source so remove it.
1019 ;;We'd have removed it anyways after seeing file local vars.
1021 (remove def-file all-files
))
1026 #'(lambda (filename)
1032 (string-match blocked filename
))
1041 ;;;_ . List of special variables used in this section
1042 ;;load-path-element - The relevant element of load-path
1043 ;;def-file - The file the autoload definitions etc will go into.
1044 ;;add-to-load-path-p - Controls whether to add to load-path.
1045 ;;recurse-dirs-p - Whether to recurse into subdirectories.
1047 ;;block-in-dir - (NOT IMPLEMENTED) List of filenames to reject. They
1048 ;;may include wildcards. They apply wrt the original directory.
1050 ;;block-in-subtree - (NOT IMPLEMENTED) List of filenames to reject.
1051 ;;They may include wildcards. They apply wrt any directory in the
1052 ;;tree. Specifically, in the spec tree, which may differ from the
1054 ;;byte-compile - whether to byte-compile at all, t by default.
1055 ;;autoloads - boolean whether to make autoloads, t by default.
1056 ;;preloads - boolean whether to set up preloads, t by default.
1057 (defconst elinstall-find-actions-control-vars
1058 '(add-to-load-path-p recurse-dirs-p byte-compile
1060 "Control special variables that the find-actions tree recognizes" )
1061 ;;;_ . elinstall-actions-for-source-file
1062 (defun elinstall-actions-for-source-file (filename dir
)
1063 "Return a list of actions to do for FILENAME in DIR.
1064 Special variables are as noted in \"List of special variables\"."
1066 load-path-element def-file byte-compile
))
1069 (expand-file-name filename dir
)))
1072 (file-readable-p full-path
)
1073 (not (auto-save-file-name-p full-path
))
1074 (string-match emacs-lisp-file-regexp filename
))
1077 (visited (get-file-buffer full-path
))
1081 ;;Visit the file cheaply.
1082 ;;hack-local-variables can give errors.
1083 (ignore-errors (autoload-find-file full-path
))))
1087 (with-current-buffer buf
1088 (if (local-variable-p 'generated-autoload-file
)
1089 (elinstall-expand-deffile-name
1090 generated-autoload-file
)
1093 ;;Figure out whether to run some actions, by file local vars.
1097 (with-current-buffer buf
1098 (not no-update-autoloads
)))
1099 (elinstall-proceed-p 'autoloads
1101 '( "Do autoloads for %s? ")
1107 (featurep 'byte-compile
)
1109 (with-current-buffer buf
1110 (not no-byte-compile
)))
1111 (elinstall-proceed-p 'byte-compile
1115 "Already compiled %s.")
1118 (file-newer-than-file-p
1120 (byte-compile-dest-file full-path
)))))))
1125 `(byte-compile ,full-path
)
1128 (elinstall-make-autoload-action
1129 buf def-file load-path-element full-path
)
1131 (unless visited
(kill-buffer-if-not-modified buf
)))))))
1132 ;;;_ . elinstall-actions-for-dir
1133 (defun elinstall-actions-for-dir (dirname &optional recurse-dirs-p
)
1134 "Make actions for DIR.
1135 Recurse just if RECURSE-DIRS-P"
1137 load-path-element def-file add-to-load-path-p
))
1138 ;;This does not treat symlinks specially. $$IMPROVE ME it could
1139 ;;treat/not treat them conditional on control variables.
1142 (files (elinstall-directory-files dirname
))
1144 ;;Relative filenames of elisp source
1148 #'(lambda (filename)
1150 (string-match elinstall-elisp-regexp filename
)
1155 ;;Absolute filenames of subdirectories.
1160 #'(lambda (filename)
1162 ((fn (expand-file-name filename dirname
)))
1164 (file-directory-p fn
)
1172 elisp-source-files
;;If list is not empty.
1173 add-to-load-path-p
))
1175 (if load-path-here-p
1177 load-path-element
)))
1180 ;;$$IMPROVE ME - check `elinstall-proceed-p'. But even if
1181 ;;that says no, we still must use it as our load-path
1182 ;;element, we just don't add it to def-file.
1184 ;;Sometimes arrange to add this directory to load-path.
1185 (if load-path-here-p
1188 ,load-path-element
))
1191 ;;$$IMPROVE ME - check a control variable and
1192 ;;`elinstall-proceed-p'.
1193 ;;Sometimes add this directory to info path.
1195 (elinstall-dir-has-info dirname
)
1203 #'(lambda (filename)
1204 (elinstall-actions-for-source-file
1207 elisp-source-files
))
1212 #'(lambda (filename)
1213 (elinstall-find-actions-by-spec-x
1221 ;;;_ . elinstall-find-actions-by-spec-x
1223 (defun elinstall-find-actions-by-spec-x (spec dir
)
1224 "Return a list of actions to do, controlled by SPEC."
1226 load-path-element def-file add-to-load-path-p
1227 recurse-dirs-p block-in-dir block-in-subtree
))
1235 #'(lambda (sub-spec)
1236 (elinstall-find-actions-by-spec-x
1241 ;;(block-in-subtree (* FN) SPEC)
1243 ((block-in-subtree (second spec
)))
1244 (elinstall-find-actions-by-spec-x
1248 ;;Rather than trying to bind all control variables each time
1249 ;;thru, we use `set' and `unwind-protect'.
1251 ;;control TYPE DISPOSITION SPEC
1253 ((key (second spec
))
1255 (if (memq key elinstall-find-actions-control-vars
)
1258 (setq old-value
(symbol-value key
))
1259 (set key
(third spec
))
1260 (elinstall-find-actions-by-spec-x
1263 (set key old-value
))
1264 (error "Unrecognized control variable %s" key
))))
1268 ;;(def-file FN ARGS SPEC)
1274 (for-preload (third spec
)))
1275 (assert (listp for-preload
))
1279 (and for-preload
(car for-preload
))
1283 ,@(cdr for-preload
))
1286 (elinstall-find-actions-by-spec-x
1287 (fourth spec
) dir
))))
1291 (elinstall-actions-for-dir
1299 (elinstall-actions-for-source-file
1310 (elinstall-find-actions-by-spec-x
1317 `((add-to-load-path ,def-file
,dir
))
1319 ((load-path-element dir
)
1320 (add-to-load-path-p nil
))
1321 (elinstall-find-actions-by-spec-x
1326 ;;(matching PATTERN SPEC)
1330 ;;$$PUNT Assume that `block-in-subtree' and
1331 ;;`block-in-dir' aren't matched.
1332 (elinstall-find-actions-by-spec-x
1336 dir t
(second spec
)))))
1338 ;;(preload FN SYM &rest ARGS)
1340 ((key (third spec
)))
1342 (and (symbolp key
) (symbol-value key
))
1345 ,(expand-file-name (second spec
) dir
)
1352 (elinstall-actions-for-dir dir nil
))
1354 (elinstall-actions-for-dir dir t
)))))
1356 ;;;_ . elinstall-find-actions-by-spec
1357 (defun elinstall-find-actions-by-spec
1358 (spec load-path-element dir def-file
)
1359 "Find the list of actions to do according to SPEC."
1363 (def-file-time (elinstall-file-mod-time def-file
))
1364 (add-to-load-path-p t
)
1370 (block-in-subtree '(".git" "RCS" "CVS" "SVN" "^tests\.el")))
1373 load-path-element def-file add-to-load-path-p
1374 recurse-dirs-p byte-compile
1375 block-in-dir block-in-subtree
))
1377 (elinstall-find-actions-by-spec-x spec dir
)))
1379 ;;;_ . high-level work
1380 ;;;_ , elinstall-get-relevant-load-path
1381 (defun elinstall-get-relevant-load-path (actions)
1391 ;;;_ , elinstall-get-deffile-list
1392 (defun elinstall-get-deffile-list (stages)
1393 "Get a list of deffile names"
1397 (elinstall-stages->build-deffiles stages
)))
1399 (defun elinstall-x (dir spec
)
1400 "High-level worker function to install elisp files."
1403 ;;This is just the default deffile, spec can override it.
1405 (elinstall-expand-deffile-name nil
))
1407 (elinstall-find-actions-by-spec
1412 (stages (elinstall-segregate-actions actions
))
1414 (elinstall-get-relevant-load-path
1417 (elinstall-stage-update-deffiles
1418 (elinstall-stages->build-deffiles stages
)
1420 (elinstall-stage-arrange-preloads
1421 (elinstall-stages->arrange-preloads stages
)
1422 (elinstall-get-deffile-list stages
))
1423 (elinstall-stage-byte-compile
1424 (elinstall-stages->byte-compile stages
))
1426 ;;;_ , elinstall-package
1427 (defun elinstall-package (project-name path spec version-string
)
1428 "Install elisp files. See doc for `elinstall'."
1430 (elinstall-proceed-p 'install
1434 "Already installed %s.")
1436 (elinstall-already-installed project-name
))
1439 `(def-file "loaddefs.el" (if-used ,project-name
) ,spec
))
1440 (elinstall-record-installed project-name version-string
)))
1445 (defun elinstall (project-name path spec
&optional force version-string
)
1446 "Install elisp files.
1447 They need not be a formal package.
1451 PROJECT-NAME - the name of the project
1453 PATH - Path to the project.
1454 Suggestion: Use (elinstall-directory-true-name) to get the real
1455 current directoery name even from loaded files.
1457 SPEC - a spec for the autoloads etc to make. It can be as simple
1460 If FORCE is `t', install a package even if it has already been
1461 installed. If it's a list or `nil', it's treated as a list of
1462 installation restraints. User customizations override this
1465 VERSION-STRING, if given, must be a string of the version for this package."
1467 (elinstall-call-with-restraints
1473 project-name path spec version-string
))
1475 ;;;_ . elinstall-update-directory-autoloads
1478 (defun elinstall-update-directory-autoloads (dir)
1479 "Update autoloads for directory DIR"
1481 (interactive "DUpdate autoloads for all elisp files from directory: ")
1482 (elinstall-call-with-restraints
1490 ;;;_ . elinstall-update-directory
1492 (defun elinstall-update-directory (dir)
1493 "Update autoloads for directory DIR"
1495 (interactive "DInstall all elisp files from directory: ")
1496 (elinstall-call-with-restraints
1503 ;;;_ . elinstall-update-file-autoloads
1505 (defun elinstall-update-file-autoloads (file)
1506 "Update autoloads for elisp file FILE"
1508 (interactive "fUpdate autoloads for elisp file: ")
1509 (elinstall-call-with-restraints
1513 (file-name-directory file
)
1514 `(file ,(file-name-nondirectory file
))))
1516 ;;;_ . elinstall-update-file
1518 (defun elinstall-update-file (file)
1519 "Install elisp file FILE"
1521 (interactive "fInstall elisp file: ")
1522 (elinstall-call-with-restraints
1527 (file-name-directory file
)
1528 `(file ,(file-name-nondirectory file
))))
1533 (provide 'elinstall
)
1535 ;;;_ * Local emacs vars.
1536 ;;;_ + Local variables:
1541 ;;; elinstall.el ends here