home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / gnu / emacs / help / 5240 < prev    next >
Encoding:
Text File  |  1993-01-05  |  5.4 KB  |  136 lines

  1. Xref: sparky gnu.emacs.help:5240 comp.emacs:3905
  2. Newsgroups: gnu.emacs.help,comp.emacs
  3. Path: sparky!uunet!stanford.edu!EE.Stanford.EDU!sierra!mcgrant
  4. From: mcgrant@rascals.stanford.edu (Michael C. Grant)
  5. Subject: Re: Organizing the .../emacs/lisp directory?
  6. In-Reply-To: dave@gctech.co.jp's message of Mon, 4 Jan 1993 22:55:25 GMT
  7. Message-ID: <MCGRANT.93Jan5043541@rascals.stanford.edu>
  8. Sender: usenet@EE.Stanford.EDU (Usenet)
  9. Organization: Information Systems Laboratory, Stanford University
  10. References: <DAVE.93Jan5075525@gctgw.gctech.co.jp>
  11. Distribution: gnu
  12. Date: 5 Jan 93 04:35:41
  13. Lines: 121
  14.  
  15.  
  16. In article <DAVE.93Jan5075525@gctgw.gctech.co.jp> dave@gctech.co.jp (Dave) writes:
  17.  
  18.    I would like to organize the directory contents into a set of
  19.    sub-directories, setting the load-path variable to include each of the
  20.    sub-directories by default at loadup time.  I have two problems:
  21.  
  22. Here's my solution: I made modifications so that, every time emacs is
  23. re-started, it created a load-path dynamically from the subdirectories
  24. of my lisp trees.
  25.  
  26. 1) add a hook (I call it initialization-hook) which is called before
  27.    .emacs is loaded:
  28.  
  29. *** startup.el  Thu Dec 31 19:08:37 1992
  30. --- startup.el.dist     Thu Dec 31 19:03:22 1992
  31. ***************
  32. *** 69,74 ****
  33. --- 69,75 ----
  34.   It is called with no arguments.  You can use this to override the
  35.   definitions made by the terminal-specific file.")
  36.  
  37. + ; MCG ADDITION
  38.   (defvar initialization-hook nil
  39.     "Function to be called before the user's .emacs is loaded. Perhaps
  40.   this hook can be used to dynamically set paths at startup time.")
  41. ***************
  42. *** 87,96 ****
  43.              (getenv "PWD")
  44.              (equal (nthcdr 10 (file-attributes default-directory))
  45.                     (nthcdr 10 (file-attributes (getenv "PWD")))))
  46. !       (setq default-directory (file-name-as-directory (getenv "PWD"))))
  47.   ; MCG ADDITION
  48.       (and initialization-hook
  49. !          (funcall initialization-hook))
  50.       (unwind-protect
  51.         (command-line)
  52.         (and term-setup-hook
  53. --- 88,97 ----
  54.              (getenv "PWD")
  55.              (equal (nthcdr 10 (file-attributes default-directory))
  56.                     (nthcdr 10 (file-attributes (getenv "PWD")))))
  57. !       (setq default-directory (file-name-as-directory (getenv "PWD"))))
  58.   ; MCG ADDITION
  59.       (and initialization-hook
  60. !            (funcall initialization-hook))
  61.       (unwind-protect
  62.         (command-line)
  63.         (and term-setup-hook
  64.  
  65. 2) Add the following to your site-init.el file:
  66.    a) flatten-list --- removes all hierarchy from a list tree
  67.    b) expand-paths --- takes a load-path like list of directory names,
  68.       and expands all of the ones with two trailing slashes "//" to
  69.       include their subdirectories.
  70.    c) an initialization-hook, which performs this path expansion only
  71.       if it's not going to be overridden by the EMACSLOADPATH variable.
  72.       Note that in my load-path, I only expand the .../local_lisp
  73.       directory, since I can be relatively sure that all of the
  74.       other directories are not going to be expandable. If someone
  75.       needs to, the documented expand-paths function can be used
  76.       within to his/her .emacs file to add to the load-path.
  77.  
  78. ;; This code simply expands the load-path to include any subdirectories in
  79. ;; the load-path.
  80.  
  81. (defun flatten-list (n)
  82.   "Flattens a list out so that it contains no sublists.
  83. Texutally speaking, it removes all of the inner parentheses."
  84.   (if (listp n) (apply 'nconc (mapcar 'flatten-list n)) (list n)))
  85.  
  86. (defun expand-paths (n &optional expand-all)
  87. "Expands directories ending in '//' to include subdirectories.
  88. Input is normally a path list. If the &optional expand-all argument
  89. is non-nil, it expands ALL directories, not just those ending in '//'."
  90.   (cond
  91.    ((stringp n)
  92.     (let ((expand-used (and (not (< (length n) 2))
  93.                             (string= (substring n -2 nil) "//"))))
  94.       (if expand-used (setq n (substring n 0 -1)))
  95.       (if (file-directory-p n)
  96.           (progn
  97.             (and (not (string= n ""))
  98.                  (setq n (expand-file-name
  99.                      (substitute-in-file-name
  100.                       (file-name-as-directory n)))))
  101.             (if (or expand-used expand-all)
  102.               (cons n
  103.                     (apply 'nconc
  104.                            (mapcar
  105.                             '(lambda (y)
  106.                                (if (or (not (file-directory-p y))
  107.                                        (string= (substring y -2 nil) "/.")
  108.                                        (string= (substring y -3 nil) "/.."))
  109.                                    nil (expand-paths y t)))
  110.                             (directory-files n t))))
  111.               (list n)))
  112.         nil)))
  113.    ((listp n) (flatten-list (mapcar 'expand-paths n)))
  114.    (t nil)))
  115.  
  116. (defvar initialization-hook nil)
  117. (setq initialization-hook
  118.       (function (lambda ()
  119.           (and (not (getenv "EMACSLOADPATH"))
  120.                (setq load-path
  121.                      (expand-paths '("" "~/emacs/" "~/emacslib/"
  122.                                      "/local/lib/emacs-18.59/local_lisp//"
  123.                                      "/local/lib/emacs-18.59/lisp/"
  124.                                      "/local/lib/emacs-18.59/lisp/term/"
  125.                                      "/local/lib/emacs-18.59/etc/")))))))
  126.  
  127. I just wrote this stuff the other day, so there's no more documentation
  128. than this, but hopefully you can use this.
  129.  
  130. NOTE: this works only with Unix paths, not VMS. Sorry.
  131.  
  132. Mike
  133.  
  134. --
  135. "Long hair, short hair--what's the difference once the head's blowed off?" (?)
  136.