Partly wrote test for elinstall-get-relevant-load-path. (Won't complete)
[elinstall.git] / elinstall.el
blobb4c461f90a6f3f48bd36a17da34b96c99e94214b
1 ;;;_ elinstall.el --- Automatically and flexibly install elisp files
3 ;;;_. Headers
4 ;;;_ , License
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)
13 ;; any later version.
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.
25 ;;;_ , Commentary:
27 ;; Entry points:
28 ;; elinstall Use this for overall loading
30 ;; elinstall-link-on-emacs-start - Use this for non-autogenerated
31 ;; files that need to be linked in.
33 ;; elinstall-update-directory-autoloads
34 ;; elinstall-update-file-autoloads
36 ;;;_ , Requires
38 (require 'autoload)
39 (require 'pp)
40 (require 'cus-edit) ;;Because we save "installedness" manually
43 ;;;_. Body
44 ;;;_ , Customizations
45 (defgroup elinstall
46 '()
47 "Customizations for elinstall"
48 :group 'elinstall)
50 (defcustom elinstall-default-priority
52 "Default priority for site-start"
53 :group 'elinstall
54 :type 'integer)
56 (defcustom elinstall-default-preload-target
57 "~/.emacs.d/site-start.d/"
58 "Default preload-target for registering autoloads"
59 :group 'elinstall
60 :type
61 '(choice
62 (const "~/.emacs.d/site-start.d/")
63 (const "/etc/emacs/site-start.d/")
64 (directory "" )
65 (const 'dot-emacs)))
68 (defcustom elinstall-already-installed
69 '()
70 "Things that have already been installed.
71 This exists for recording what has been installed. User interaction is not
72 contemplated at this time." )
74 ;;;_ , Data
75 ;;;_ . Regular expressions
76 ;;;_ , elinstall-elisp-regexp
77 (defconst elinstall-elisp-regexp
78 (let ((tmp nil))
79 (dolist
80 (suf (get-load-suffixes))
81 (unless (string-match "\\.elc" suf) (push suf tmp)))
82 (concat "^[^=.].*" (regexp-opt tmp t) "\\'"))
83 "Regular expression that matches elisp files" )
85 ;;;_ , Utilities
86 ;;;_ . elinstall-directory-true-name
87 (defun elinstall-directory-true-name ()
88 "Get the true name of the directory the calling code lives in.
89 CAUTION: This is sensitive to where it's called. That's the point of it."
90 (file-name-directory
91 (if load-file-name
92 (file-truename load-file-name)
93 (file-truename buffer-file-name))))
94 ;;;_ . Checking installedness
95 ;;;_ , elinstall-already-installed
96 (defun elinstall-already-installed (project-name)
97 "Return non-nil if PROJECT-NAME has been installed."
98 (member project-name elinstall-already-installed))
100 ;;;_ , elinstall-record-installed
101 (defun elinstall-record-installed (project-name)
102 "Record that PROJECT-NAME has been installed."
104 (add-to-list 'elinstall-already-installed project-name)
105 (customize-save-variable
106 'elinstall-already-installed
107 elinstall-already-installed
108 "Set by elinstall-record-installed"))
109 ;;;_ , Work
110 ;;;_ . Doing actions
112 ;;;_ , Doing autoload actions (All adapted from autoload.el)
113 ;;;_ . Utilities about the action list
114 ;;;_ , elinstall-remove-autogen-action
115 (defun elinstall-remove-autogen-action (file actions)
116 "Return ACTIONS minus any add-file-autoloads on FILE removed."
118 (delq nil
119 (mapcar
120 #'(lambda (act)
121 (case (car act)
122 (add-file-autoloads
123 (if (equal file (third act))
125 act))))
126 actions)))
127 ;;;_ , elinstall-get-autogen-action
128 (defun elinstall-get-autogen-action (file actions)
130 (let
131 ((the-act))
132 (dolist (act actions)
133 (case (car act)
134 (add-file-autoloads
135 (when (equal file (third act))
136 (setq the-act act)))))
137 the-act))
140 ;;;_ . elinstall-generate-file-autoloads
141 ;;override to allow slashed load-paths
142 ;;Quick and dirty: We just adapt `generate-file-autoloads' and add
143 ;;a new arg.
144 ;;`relative-to' can be:
145 ;; * nil: act as at present. Assume that FILE's immediate directory
146 ;;is in load-path.
147 ;; * t :: use default-directory
148 ;; * a string :: relative to it, as a filename
150 (defun elinstall-generate-file-autoloads (relative-name full-name)
151 "Insert at point a loaddefs autoload section for FILE.
152 Autoloads are generated for defuns and defmacros in FILE
153 marked by `generate-autoload-cookie' (which see).
154 If FILE is being visited in a buffer, the contents of the buffer
155 are used.
156 Return non-nil in the case where no autoloads were added at point.
158 FULL-NAME is the absolute name of the file.
159 RELATIVE-NAME is its name respective to some component of load-path."
160 (let ((outbuf (current-buffer))
161 (autoloads-done '())
162 (print-length nil)
163 (print-readably t) ; This does something in Lucid Emacs.
164 (float-output-format nil)
165 (done-any nil)
166 (visited (get-file-buffer full-name))
167 output-start)
169 ;;Older code massaged `file' but we take both `relative-name' and
170 ;;`full-name', so we don't.
172 (with-current-buffer (or visited
173 ;; It is faster to avoid visiting the file.
174 (autoload-find-file full-name))
175 ;;$$MOVE ME - this should be checked in action-finding.
176 ;; Obey the no-update-autoloads file local variable.
177 (unless no-update-autoloads
178 (message "Generating autoloads for %s..." relative-name)
179 (setq output-start (with-current-buffer outbuf (point)))
180 (save-excursion
181 (save-restriction
182 (widen)
183 (goto-char (point-min))
184 (while (not (eobp))
185 (skip-chars-forward " \t\n\f")
186 (cond
187 ((looking-at (regexp-quote generate-autoload-cookie))
188 (search-forward generate-autoload-cookie)
189 (skip-chars-forward " \t")
190 (setq done-any t)
191 (if (eolp)
192 ;; Read the next form and make an autoload.
193 (let* ((form (prog1 (read (current-buffer))
194 (or (bolp) (forward-line 1))))
195 (autoload (make-autoload form load-name)))
196 (if autoload
197 (push (nth 1 form) autoloads-done)
198 (setq autoload form))
199 (let ((autoload-print-form-outbuf outbuf))
200 (autoload-print-form autoload)))
202 ;; Copy the rest of the line to the output.
203 (princ (buffer-substring
204 (progn
205 ;; Back up over whitespace, to preserve it.
206 (skip-chars-backward " \f\t")
207 (if (= (char-after (1+ (point))) ? )
208 ;; Eat one space.
209 (forward-char 1))
210 (point))
211 (progn (forward-line 1) (point)))
212 outbuf)))
213 ((looking-at ";")
214 ;; Don't read the comment.
215 (forward-line 1))
217 (forward-sexp 1)
218 (forward-line 1))))))
220 (when done-any
221 (with-current-buffer outbuf
222 (save-excursion
223 ;; Insert the section-header line which lists the file name
224 ;; and which functions are in it, etc.
225 (goto-char output-start)
226 (autoload-insert-section-header
227 outbuf autoloads-done relative-name full-name
228 (nth 5 (file-attributes full-name)))
229 (insert ";;; Generated autoloads from "
230 (autoload-trim-file-name full-name) "\n"))
231 (insert generate-autoload-section-trailer)))
232 (message "Generating autoloads for %s...done" relative-name))
233 (or visited
234 ;; We created this buffer, so we should kill it.
235 (kill-buffer (current-buffer))))
236 (not done-any)))
239 ;;;_ . elinstall-deffile-insert-x
240 ;;This now operates in the current buffer. We already did most of
241 ;;this checking on setup.
242 ;; Removed
243 ;; * buffer optional save,
244 ;; * converting file to load-name
245 ;; * checking for timestamp
246 (defun elinstall-deffile-insert-x (file load-name)
247 "Update the autoloads for FILE in `generated-autoload-file'
248 \(which FILE might bind in its local variables).
250 LOAD-NAME is the full name of the file
253 Return FILE if there was no autoload cookie in it, else nil."
254 (let (
255 (found nil)
256 (no-autoloads nil))
258 (save-excursion
259 (save-restriction
260 (widen)
261 (goto-char (point-min))
262 ;; Look for the section for FILE
263 (while (and (not found)
264 (search-forward generate-autoload-section-header nil t))
265 (let ((form (autoload-read-section-header)))
266 (cond
267 ((equal (nth 2 form) file)
268 ;; We found the section for this file.
269 ;; Check if it is up to date.
270 (let ((begin (match-beginning 0)))
271 (progn
272 (search-forward generate-autoload-section-trailer)
273 (delete-region begin (point))
274 (setq found t))))
275 ((string< file (nth 2 form))
276 ;; We've come to a section alphabetically later than
277 ;; FILE. We assume the file is in order and so
278 ;; there must be no section for FILE. We will
279 ;; insert one before the section here.
280 (goto-char (match-beginning 0))
281 (setq found 'new)))))
282 (unless found
283 (progn
284 (setq found 'new)
285 ;; No later sections in the file. Put before the last page.
286 (goto-char (point-max))
287 (search-backward "\f" nil t)))
288 (setq no-autoloads
289 (elinstall-generate-file-autoloads file load-name))))
291 (if no-autoloads file nil)))
293 ;;;_ . elinstall-deffile-insert
295 (defun elinstall-deffile-insert (action)
296 "Insert autoloads etc into current file according to ACTION.
297 The format of ACTION is described in the design docs.
299 Return filename if this action belongs in the no-autoload section."
301 (when action
302 (case (car action)
303 (add-file-autoloads
304 (elinstall-deffile-insert-x
305 (third action)
306 (fifth action)))
308 (add-to-load-path
309 ;;Go to the right position, then call:
310 '(elinstall-insert-add-to-load-path)
311 nil)
313 ;;Similar, but for info-path.
314 (add-to-info-path
315 'elinstall-insert-add-to-info-path
316 nil)
318 (preload-file
319 (error "This case should not come here.")))))
321 ;;;_ . elinstall-prepare-deffile
322 (defun elinstall-prepare-deffile (deffile)
323 "Try to ensure that DEFFILE is available for receiving autoloads"
325 (autoload-ensure-default-file deffile)
326 (with-current-buffer (find-file-noselect deffile)
329 ;; We must read/write the file without any code conversion,
330 ;; but still decode EOLs.
331 (let ((coding-system-for-read 'raw-text))
333 ;; This is to make generated-autoload-file have Unix EOLs, so
334 ;; that it is portable to all platforms.
335 (setq buffer-file-coding-system 'raw-text-unix))
336 (or (> (buffer-size) 0)
337 (error "Autoloads file %s does not exist" buffer-file-name))
338 (or (file-writable-p buffer-file-name)
339 (error "Autoloads file %s is not writable"
340 buffer-file-name))))
342 ;;;_ . elinstall-update-deffile
344 ;;Adapted from autoload.el `update-directory-autoloads'.
345 ;;Still being adapted:
347 ;; * Still need to treat add-to-info-path and
348 ;;add-to-load-path. Both recognize them and insert them.
349 ;; * Adapt `elinstall-update-file-autoloads' to understand actions.
351 ;; * Finding "file" among actions is rickety. Maybe knowing the
352 ;; respective load-path element would help.
354 (defun elinstall-update-deffile (target actions &optional
355 use-load-path force)
357 Update file TARGET with current autoloads as specified by ACTIONS.
358 Also remove any old definitions pointing to libraries that can no
359 longer be found.
361 ACTIONS must be a list of actions (See the format doc). Each one's
362 filename must be relative to some element of load-path.
364 USE-LOAD-PATH is a list to use as load-path. It should include
365 any new load-path that we are arranging to create. If it's not given,
366 load-path itself is used.
368 If FORCE is `t', do it regardless of timestamps etc. (Not implemented)
369 Other non-nil cases of FORCE are reserved for future development.
371 This uses `update-file-autoloads' (which see) to do its work.
372 In an interactive call, you must give one argument, the name
373 of a single directory."
374 (let
376 (use-load-path (or use-load-path load-path))
377 (this-time (current-time))
378 ;;files with no autoload cookies.
379 (no-autoloads nil))
381 (elinstall-prepare-deffile target)
382 (with-current-buffer
383 (find-file-noselect target)
384 (save-excursion
385 (setq actions
386 (elinstall-remove-autogen-action
387 (autoload-trim-file-name target)
388 actions))
390 (goto-char (point-min))
391 (while (search-forward generate-autoload-section-header nil t)
392 (let* ((form (autoload-read-section-header))
393 (file (nth 3 form)))
394 (cond ((and (consp file) (stringp (car file)))
395 ;; This is a list of files that have no
396 ;; autoload cookies.
397 ;; There shouldn't be more than one such entry.
398 ;; Remove the obsolete section.
399 (autoload-remove-section (match-beginning 0))
400 (let ((last-time (nth 4 form)))
401 (dolist (file file)
402 (let ((file-time (nth 5 (file-attributes file))))
403 (when (and file-time
404 (not (time-less-p last-time file-time)))
405 ;; file unchanged
406 (push file no-autoloads)
407 (setq actions
408 (elinstall-remove-autogen-action
409 file actions)))))))
410 ((not (stringp file)))
412 (let
413 ((file-path
414 (locate-library file nil use-load-path)))
415 (cond
416 ;;File doesn't exist, so remove its
417 ;;section.
418 ((not file-path)
419 (autoload-remove-section
420 (match-beginning 0)))
422 ;; File hasn't changed, so do nothing.
423 ((equal
424 (nth 4 form)
425 (nth 5 (file-attributes file-path)))
426 nil)
428 (elinstall-deffile-insert
429 (elinstall-get-autogen-action
430 file actions))))
432 (setq actions
433 (elinstall-remove-autogen-action
434 file actions))))))))
436 ;; Remaining actions have no existing autoload sections yet.
437 (setq no-autoloads
438 (append no-autoloads
439 (delq nil (mapcar #'elinstall-deffile-insert actions))))
440 (when no-autoloads
441 ;; Sort them for better readability.
442 (setq no-autoloads (sort no-autoloads 'string<))
443 ;; Add the `no-autoloads' section.
444 (goto-char (point-max))
445 (search-backward "\f" nil t)
446 (autoload-insert-section-header
447 (current-buffer) nil nil no-autoloads this-time)
448 (insert generate-autoload-section-trailer))
449 (save-buffer))))
452 ;;;_ , Doing actions to arrange preloads
453 ;;;_ . elinstall-insert-add-to-path
454 (defun elinstall-insert-add-to-path (new path-sym)
455 "Insert code to add NEW to PATH-SYM.
456 Insert this at point in current buffer."
457 (insert "\n")
459 `(add-to-list ',path-sym
460 (expand-file-name ,new
461 (if load-file-name
462 (file-name-directory
463 (file-truename load-file-name)))))
464 (current-buffer)))
466 ;;;_ . elinstall-insert-add-to-load-path
467 (defun elinstall-insert-add-to-load-path (new)
468 "Insert code to add NEW to load-path.
469 Insert this at point in current buffer."
470 (elinstall-insert-add-to-path new 'load-path))
472 ;;;_ . elinstall-insert-add-to-info-path
473 (defun elinstall-insert-add-to-info-path (new)
474 "Insert code to add NEW to info-path.
475 Insert this at point in current buffer."
476 (elinstall-insert-add-to-path new 'Info-default-directory-list))
478 ;;;_ . elinstall-symlink-on-emacs-start
479 (defun elinstall-symlink-on-emacs-start
480 (filename target-basename target-dir &optional priority force)
481 "Symlink to TARGET-BASENAME.el in TARGET-DIR
483 If PRIORITY is given, it will be used as the priority prefix,
484 otherwise elinstall-default-priority will be.
485 PRIORITY must be an integer or nil.
486 If FORCE is `t', do it regardless of timestamps etc.
487 Other non-nil cases of FORCE are reserved for future development."
488 (let*
490 (priority (or priority elinstall-default-priority))
491 (target-name-nodir
492 (format
493 "%d%s.el"
494 priority
495 target-basename))
496 (target
497 (expand-file-name target-name-nodir target-dir)))
500 (cond
501 ;;Path should already exist.
502 ((not
503 (file-exists-p target-dir))
504 (message "The target directory doesn't exist."))
505 ;;Target shouldn't already exist, but if force is given, let
506 ;;user override.
507 ((and
508 (file-exists-p target)
510 (not force)
511 (not
512 (yes-or-no-p
513 (format "Really overwrite %s? " project-name))))
514 (message "No symlink made to %s" target)))
517 (make-symbolic-link
518 filename
519 target
520 nil)))))
522 ;;;_ . elinstall-add-to-dot-emacs
523 (defun elinstall-add-to-dot-emacs (dot-emacs-name filename force &rest r)
524 "Add code to load FILENAME to .emacs.
525 FILENAME should not have an extension"
527 ;;Visit .emacs
528 (with-current-buffer (find-file-noselect dot-emacs-name)
529 (save-excursion
530 ;;add at end of file
531 (goto-char (point-max))
532 (insert "\n;;Added by elinstall")
533 (insert "\n;;Consider using my-site-start to manage .emacs\n")
534 (pp `(load ,filename) (current-buffer))
535 (save-buffer))))
538 ;;;_ . elinstall-link-on-emacs-start
539 ;;;###autoload
540 (defun elinstall-link-on-emacs-start (filename force basename priority)
543 ;;Figure out parameters, using defaults when needed.
544 (let*
545 ( (preload-target elinstall-default-preload-target))
547 ;;Dispatch the possibilities.
548 (cond
549 ((eq preload-target 'dot-emacs)
550 (elinstall-add-to-dot-emacs "~/.emacs" filename))
551 ((stringp preload-target)
552 (elinstall-symlink-on-emacs-start
553 filename basename preload-target priority force))
556 (message "I don't recognize that")))))
558 ;;;_ , Cleanup actions
559 ;;Nothing yet. This will be another type of action.
561 ;;;_ . Segregating actions
562 ;;;_ , elinstall-segregate-actions
563 (defun elinstall-segregate-actions (actions)
564 "Return actions segregated by deffile.
566 Returns a list whose elements are each a cons of:
567 * deffile filename or nil
568 * A list of actions to be done for that deffile."
570 (let
571 ((segment-list '()))
572 (dolist (act actions)
573 (when act
574 (let*
575 ( (deffile-name
576 (case (car act)
577 ((add-file-autoloads
578 add-to-info-path
579 add-to-load-path)
580 (second act))
581 (preload-file nil)))
583 (cell (assoc deffile-name segment-list)))
584 (if cell
585 (setcdr cell (cons act (cdr cell)))
586 (setq segment-list
587 (cons
588 (cons
589 deffile-name
590 (list act))
591 segment-list))))))
592 segment-list))
596 ;;;_ . Finding actions
597 ;;;_ , Treating the parameter list
598 ;;;_ . elinstall-add-parameter
599 (defun elinstall-add-parameter (alist key new-value)
600 "Add a new value for KEY to ALIST"
602 (cons
603 (cons key new-value)
604 (assq-delete-all key (copy-list alist))))
606 ;;;_ . elinstall-get-parameter
607 (defun elinstall-get-parameter (alist key)
608 "Get the value of KEY from ALIST"
610 (cdr (assq key alist)))
611 ;;;_ . elinstall-expand-file-name
612 ;;$$OBSOLETE
614 (defun elinstall-expand-file-name (filename alist)
615 "Expand FILENAME by the value of `path' in ALIST"
616 (expand-file-name
617 filename
618 (elinstall-get-parameter alist 'path)))
619 ;;;_ , Finding deffiles
620 ;;;_ . elinstall-expand-deffile-name
621 (defun elinstall-expand-deffile-name (deffile)
622 "Expand DEFFILE autoload.el's way."
624 (expand-file-name (or deffile "loaddefs.el")
625 (expand-file-name "lisp"
626 source-directory)))
628 ;;;_ . elinstall-maybe-get-deffile
629 (defun elinstall-maybe-get-deffile (file)
630 "If FILE defined `generated-autoload-file', return it.
631 Otherwise return nil.
632 Return it as an absolute filename."
634 (save-excursion
635 ;;$$FIXME load buffer if it's not already loaded
636 (let*
637 ((existing-buffer (get-file-buffer file)))
639 ;; We want to get a value for generated-autoload-file from
640 ;; the local variables section if it's there.
641 ;;But if it's not loaded, we don't? Maybe should use
642 ;; `autoload-find-file' and load it.
643 (if existing-buffer
644 (set-buffer existing-buffer))
645 (if (local-variable-p 'generated-autoload-file)
646 (elinstall-expand-deffile-name
647 generated-autoload-file)
648 nil))))
652 ;;;_ , elinstall-find-actions-by-spec
654 (defun elinstall-find-actions-by-spec (spec load-path-element path parameters)
655 "Return a list of actions to do, controlled by SPEC and PARAMETERS.
657 LOAD-PATH-ELEMENT is the conceptual element of load-path that
658 surrounds PATH. It may not yet have been added to load-path."
659 (if (consp spec)
660 ;;$$IMPROVE ME by adding the other cases in the design.
661 (case (car spec)
663 (let
664 ((new-path
665 (expand-file-name
666 (second spec)
667 path)))
669 (elinstall-find-actions-by-spec
670 (third spec)
671 load-path-element
672 new-path
673 parameters)))
675 (all
676 (apply #'append
677 (mapcar
678 #'(lambda (sub-spec)
679 (elinstall-find-actions-by-spec
680 sub-spec
681 load-path-element
682 path
683 parameters))
684 (cdr spec))))
685 ;;$$WRITEME
686 (file
689 (dir
690 (let
691 ((dirname
692 (expand-file-name
693 (second spec)
694 path))
695 (load-path-here
696 (not
697 (elinstall-get-parameter
698 parameters 'block-add-to-load-path))))
699 (cons
700 ;;$$IMPROVE ME
701 ;;Do this only if there are loadable files.
702 (if load-path-here
703 `(add-to-load-path
704 ,(elinstall-get-parameter
705 parameters 'def-file)
706 ,dirname)
707 '())
708 ;;$$IMPROVE ME
709 ;;Do add-to-info-path too. But test if there are
710 ;;any info files present.
712 ;;$$IMPROVE ME
713 ;; We want to get a value for generated-autoload-file
714 ;; from the local variables section if it's there.
715 ;;Use `elinstall-maybe-get-deffile'
716 ;; Otherwise we'll use `def-file' in parameters.
718 ;;$$FIXME This isn't quite right. If directory
719 ;;itself is not in load-path, this will be wrong.
720 ;;Gotta know where our encompassing part of
721 ;;load-path is.
723 ;;$$ENCAP ME This should be shared with the
724 ;;treatment of (file FN)
726 ;;$$FIXME Don't do directories, but maybe recurse on
727 ;;them, if a flag is set. And since we definitely
728 ;;have a load-path element here,
729 ;;'block-add-to-load-path according to a parameter.
730 ;;Maybe could follow/not symlinks similarly.
731 (mapcar
732 #'(lambda (filename)
733 (let
734 ((full-path
735 (expand-file-name filename dirname)))
736 `(add-file-autoloads
737 ,(elinstall-get-parameter
738 parameters 'def-file)
739 ,(file-name-sans-extension
740 (file-relative-name
741 full-path
742 load-path-element))
743 ,load-path-element ;;Is this still used?
744 ,full-path)))
746 (directory-files
747 dirname
748 nil ;;Relative filenames
749 elinstall-elisp-regexp)))))
751 (def-file
752 (let
753 ((new-def-file
754 (expand-file-name
755 (second spec)
756 path)))
757 (elinstall-find-actions-by-spec
758 (third spec)
759 load-path-element
760 path
761 (elinstall-add-parameter parameters
762 'def-file new-def-file)))))
764 ;;$$IMPROVE ME by adding the other cases in the design.
765 (case spec
766 (t))))
767 ;;;_ . high-level work
768 ;;;_ , elinstall-get-relevant-load-path
769 (defun elinstall-get-relevant-load-path (actions)
771 (delq nil
772 (mapcar
773 #'(lambda (act)
774 (case (car act)
775 (add-to-load-path
776 (second act))
777 (t nil)))
778 actions)))
780 ;;;_ , elinstall-do-segment
781 (defun elinstall-do-segment (segment force use-load-path)
782 "Do all the actions in SEGMENT.
783 FORCE has its usual meaning.
784 USE-LOAD-PATH is the effective load-path."
786 ;;$$IMPROVE ME - this will have to know the additions to load-path.
787 (let*
788 ((deffile (car segment)))
789 (if (stringp deffile)
790 (elinstall-update-deffile deffile (cdr segment) force
791 use-load-path)
792 ;;Do other actions: link-in actions and cleanups.
793 (mapcar
794 #'(lambda (act)
795 ;;$$FIXME Distinguish link-in and cleanup actions.
796 (apply
797 #'elinstall-link-on-emacs-start
798 force
799 (cdr act)))
800 (cdr segment)))))
803 ;;;_ . Overall work
804 ;;;_ , elinstall-x
805 (defun elinstall-x (dir spec &optional preload-target force)
807 (let*
808 ((actions
809 (elinstall-find-actions-by-spec
810 spec
814 ;;$$RETHINK ME - maybe hand this work off to autoload?
815 ;;This is just the default loaddefs file, spec actually
816 ;;controls it.
817 (def-file . ,(elinstall-expand-deffile-name nil) ))))
818 (segment-list (elinstall-segregate-actions actions))
819 (use-load-path
820 (elinstall-get-relevant-load-path
821 actions)))
823 (mapcar
824 #'(lambda (segment)
825 (elinstall-do-segment segment force use-load-path))
826 segment-list)))
828 ;;;_ . Entry points
829 ;;;_ , elinstall
830 (defun elinstall (project-name dir spec &optional preload-target force)
831 "Install elisp files.
833 They need not be presented as a package.
835 Parameters:
836 PROJECT-NAME - the name of the project
837 DIR - the root directory of the project.
838 Suggestion: (elinstall-directory-true-name)
840 SPEC - a spec for the autoloads etc to make. It can be as simple as
841 `(in DIRECTORY t).
842 Suggestion: `(in ,(elinstall-directory-true-name) t)
843 PRELOAD-TARGET is where the autoload files are to be symlinked in. If
844 `nil' `elinstall-default-preload-target' is used instead.
846 If FORCE is t, install a package even if it has already been
847 installed.
848 Other non-nil cases of FORCE are reserved for future development."
850 (when
851 (and
852 (or
853 force
854 (not (elinstall-already-installed project-name)))
855 ;;$$RE-ADD ME - I commented it out just for development.
856 '(yes-or-no-p (format "Install %s " project-name)))
857 (elinstall-x dir spec preload-target force)
859 ;;$$RE-ADD ME - I commented it out just for development.
860 '(elinstall-record-installed project-name)))
864 ;;;_ , elinstall-update-directory-autoloads
865 ;;$$TEST ME
866 (defun elinstall-update-directory-autoloads (dir)
869 (interactive "DInstall all elisp files from directory: ")
871 (elinstall-x
873 '(dir ".")
874 (elinstall-expand-deffile-name
875 generated-autoload-file)))
878 ;;;_ , elinstall-update-file-autoloads
879 ;;$$TEST ME
880 (defun elinstall-update-file-autoloads (file)
883 (interactive "fInstall elisp file: ")
884 (elinstall
885 file
886 `(file ,file)
888 (elinstall-maybe-get-deffile file)
889 (elinstall-expand-deffile-name
890 generated-autoload-file))))
897 ;;;_. Footers
898 ;;;_ , Provides
900 (provide 'elinstall)
902 ;;;_ * Local emacs vars.
903 ;;;_ + Local variables:
904 ;;;_ + mode: allout
905 ;;;_ + End:
907 ;;;_ , End
908 ;;; elinstall.el ends here