gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

auto-load-path.el


From: Fernando Dobladez
Subject: auto-load-path.el
Date: Tue, 13 Nov 2001 12:28:11 -0600
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.5) Gecko/20011012

Should I post this here?

Thanks,

Fernando.
;; auto-load-path.el -- Automagically add ~/elisp subdirs to the load-path
;; 
;; Author: Fernando Dobladez <address@hidden>
;; Version:   1.0 
;; Keywords:  load-path, load
;; 
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, you can either send email to this
;; program's maintainer or write to: The Free Software Foundation,
;; Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.

;;; Commentary:

;;
;;
;; One day I got tired of manually updating my load-path in my .emacs file...
;;
;; It looked something like this:
;; 
;; (setq load-path (nconc '( "/home/ferd/elisp" "/home/ferd/elisp/jde/lisp"
;;                           "/home/ferd/elisp/elib" "/home/ferd/elisp/semantic"
;;                           "/home/ferd/elisp/speedbar" 
"/home/ferd/elisp/w3/lisp"
;;                           "/home/ferd/elisp/dictionary") load-path))
;;
;;
;; So, I decided to write this quick&dirty function to forget about it.
;;
;; This little package adds the subdirs under the specified
;; directory(ies) (defaults to "~/elisp") to the load-path variable.
;; 
;; Those directories that don't contain .el nor .elc files are not
;; added to the load-path. Also, directories named "CVS", "RCS" or
;; ".*" (dot something) are totally ignored (their subdirs are not
;; scanned).
;; 
;; The new directories are added to the beginning of the load-path
;; list.
;;
;; The auto-load-path function will not add directories that are
;; already in load-path, making it harmless to call auto-load-path
;; many times. This allows you to update your load-path "on-the-fly":
;; if you create a new subdir in your ~/elisp while emacs is running,
;; just call auto-load-path again, and it'll be added to the
;; load-path.
;; 
;; 
;; Usage/Instalation:
;; ==================
;;
;; Assuming you copy auto-load-path.el to your ~/elisp directory, all
;; you need to have in your .emacs is the following line:
;;
;;    (load-library "~/elisp/auto-load-path.el")
;;
;; That's it!  I find it much cleaner (and automatic) that the (setq
;; load-path...) thing.
;;
;;
;; If you want to add a subdir tree different from ~/elisp, you can set the
;; auto-load-path-roots variable before loading auto-load-path.el:
;; 
;;    (setq auto-load-path-roots '("~/emacsLisp"))
;;    (load-library "~/elisp/auto-load-path.el")
;;
;; Also note that auto-load-path-roots is a list, so, you can specify more than
;; one "root" directory:
;; 
;;    (setq auto-load-path-roots '("~/elisp"  "~/emacsLisp"  
"/usr/share/elisp"))
;;    (load-library "~/elisp/auto-load-path.el")
;;
;; 
;; Remember that after loading the auto-load-path.el library, you can
;; call the auto-load-path function ("M-x auto-load-path") to update
;; the load-path variable
;; 
;; 
;; That's all. Let me know your comments...
;; 
;; NOTES: This is not very well tested... it just works for me on my
;; current GNU Emacs 21.1.1 (on Linux).
;; 
;; //ferd//
;;
;; Known issues:
;;   - The directories specified as "roots" are always added to the load-path, 
even if
;;     they don't have any .el/.elc in them.
;;
;; 

(defun auto-load-path-for-roots (rootpaths)
  "Returns a list with all subdirectories under rootpaths. Directories
that have no .el nor .elc files in it are excluded. Directories named
CVS, RCS or .* (dot something) are totally ignored (their subdirs are not
scanned)."
  (let* ((dirs rootpaths)
         (p dirs))

    ; first, add the root dirs to load-path (if they are not already there)
    (while p
      (add-to-list 'load-path (car p))
      (setq p (cdr p)))

   
    (setq p dirs)

    ; Now, do a breath-first traversal on the sub-directory tree...
    (while p
      (let ((q (directory-files (car p) 'absolute "^[^\\.].*"))) ; Exclude 
dirnames that start with "."
        (while q
          (if (and (file-accessible-directory-p (car q))  ; only traverse the 
accesible directory entries,
                   (not (member (car q) '("CVS" "RCS")))) ; excluding CVS and 
RCS
              (progn (nconc dirs (list (car q)))
                     (if (directory-files (car q) 'absolute "\\.elc?$")
                         (add-to-list 'load-path (car q))))) ; OK, add to 
load-path
          (setq q (cdr q))))
      (setq p (cdr p)))

    ))

;;
;; This is just a wrapper function that calls auto-load-path-for-roots
;; with the list of root dirs defined in var auto-load-path-roots (or only
;; "~/elisp" if it's not specified)
;;
(defun auto-load-path ()
  (interactive)
  (auto-load-path-for-roots (if (boundp 'auto-load-path-roots)
                                auto-load-path-roots
                              (list "~/elisp"))) ; by default, use "~/elisp" as 
the only root dir
  )

;; Call the function
(auto-load-path)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]