🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.help
Article #2057

Re: Organizing the .../emacs/lisp directory?

#2057
From: Michael C. Grant
Date: Tue, 05 Jan 1993 04:35
121 lines
5644 bytes
In article <DAVE.93Jan5075525@gctgw.gctech.co.jp> dave@gctech.co.jp (Dave) writes:

   I would like to organize the directory contents into a set of
   sub-directories, setting the load-path variable to include each of the
   sub-directories by default at loadup time.  I have two problems:

Here's my solution: I made modifications so that, every time emacs is
re-started, it created a load-path dynamically from the subdirectories
of my lisp trees.

1) add a hook (I call it initialization-hook) which is called before
   .emacs is loaded:

*** startup.el  Thu Dec 31 19:08:37 1992
--- startup.el.dist     Thu Dec 31 19:03:22 1992
***************
*** 69,74 ****
--- 69,75 ----
  It is called with no arguments.  You can use this to override the
  definitions made by the terminal-specific file.")

+ ; MCG ADDITION
  (defvar initialization-hook nil
    "Function to be called before the user's .emacs is loaded. Perhaps
  this hook can be used to dynamically set paths at startup time.")
***************
*** 87,96 ****
             (getenv "PWD")
             (equal (nthcdr 10 (file-attributes default-directory))
                    (nthcdr 10 (file-attributes (getenv "PWD")))))
!       (setq default-directory (file-name-as-directory (getenv "PWD"))))
  ; MCG ADDITION
      (and initialization-hook
!          (funcall initialization-hook))
      (unwind-protect
        (command-line)
        (and term-setup-hook
--- 88,97 ----
             (getenv "PWD")
             (equal (nthcdr 10 (file-attributes default-directory))
                    (nthcdr 10 (file-attributes (getenv "PWD")))))
!       (setq default-directory (file-name-as-directory (getenv "PWD"))))
  ; MCG ADDITION
      (and initialization-hook
!            (funcall initialization-hook))
      (unwind-protect
        (command-line)
        (and term-setup-hook

2) Add the following to your site-init.el file:
   a) flatten-list --- removes all hierarchy from a list tree
   b) expand-paths --- takes a load-path like list of directory names,
      and expands all of the ones with two trailing slashes "//" to
      include their subdirectories.
   c) an initialization-hook, which performs this path expansion only
      if it's not going to be overridden by the EMACSLOADPATH variable.
      Note that in my load-path, I only expand the .../local_lisp
      directory, since I can be relatively sure that all of the
      other directories are not going to be expandable. If someone
      needs to, the documented expand-paths function can be used
      within to his/her .emacs file to add to the load-path.

;; This code simply expands the load-path to include any subdirectories in
;; the load-path.

(defun flatten-list (n)
  "Flattens a list out so that it contains no sublists.
Texutally speaking, it removes all of the inner parentheses."
  (if (listp n) (apply 'nconc (mapcar 'flatten-list n)) (list n)))

(defun expand-paths (n &optional expand-all)
"Expands directories ending in '//' to include subdirectories.
Input is normally a path list. If the &optional expand-all argument
is non-nil, it expands ALL directories, not just those ending in '//'."
  (cond
   ((stringp n)
    (let ((expand-used (and (not (< (length n) 2))
                            (string= (substring n -2 nil) "//"))))
      (if expand-used (setq n (substring n 0 -1)))
      (if (file-directory-p n)
          (progn
            (and (not (string= n ""))
                 (setq n (expand-file-name
                     (substitute-in-file-name
                      (file-name-as-directory n)))))
            (if (or expand-used expand-all)
              (cons n
                    (apply 'nconc
                           (mapcar
                            '(lambda (y)
                               (if (or (not (file-directory-p y))
                                       (string= (substring y -2 nil) "/.")
                                       (string= (substring y -3 nil) "/.."))
                                   nil (expand-paths y t)))
                            (directory-files n t))))
              (list n)))
        nil)))
   ((listp n) (flatten-list (mapcar 'expand-paths n)))
   (t nil)))

(defvar initialization-hook nil)
(setq initialization-hook
      (function (lambda ()
          (and (not (getenv "EMACSLOADPATH"))
               (setq load-path
                     (expand-paths '("" "~/emacs/" "~/emacslib/"
                                     "/local/lib/emacs-18.59/local_lisp//"
                                     "/local/lib/emacs-18.59/lisp/"
                                     "/local/lib/emacs-18.59/lisp/term/"
                                     "/local/lib/emacs-18.59/etc/")))))))

I just wrote this stuff the other day, so there's no more documentation
than this, but hopefully you can use this.

NOTE: this works only with Unix paths, not VMS. Sorry.

Mike

--
"Long hair, short hair--what's the difference once the head's blowed off?" (?)
Technical Details
Message-ID: <MCGRANT.93Jan5043541@rascals.stanford.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!EE.Stanford.EDU!sierra!mcgrant
References: <DAVE.93Jan5075525@gctgw.gctech.co.jp>

Show Full Headers
Complete Article Headers
Newsgroups: gnu.emacs.help,comp.emacs
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!EE.Stanford.EDU!sierra!mcgrant
From: mcgrant@rascals.stanford.edu (Michael C. Grant)
Subject: Re: Organizing the .../emacs/lisp directory?
In-Reply-To: dave@gctech.co.jp's message of Mon, 4 Jan 1993 22:55:25 GMT
Message-ID: <MCGRANT.93Jan5043541@rascals.stanford.edu>
Sender: usenet@EE.Stanford.EDU (Usenet)
Organization: Information Systems Laboratory, Stanford University
References: <DAVE.93Jan5075525@gctgw.gctech.co.jp>
Distribution: gnu
Date: 5 Jan 93 04:35:41
Lines: 121