all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Fabrice Niessen" <tdhkhcidiacy-geNee64TY+gS+FvcfC7Uqw@public.gmane.org>
To: help-gnu-emacs-mXXj517/zsQ@public.gmane.org
Subject: Re: Adding Additional Trees to the Load Path
Date: Wed, 28 Jan 2009 09:57:15 +0100	[thread overview]
Message-ID: <87ab9bzu38.fsf@mundaneum.com> (raw)
In-Reply-To: mailman.5999.1233086875.26697.help-gnu-emacs@gnu.org

Hello Tim,

> I have a directory `.emacs.d` in my home directory where I put lisp
> libraries for extensions to Emacs.  Currently, I have to explicitly
> include each of the extensions in my `.emacs` file in order to get
> them to work.  I tried adding `.emacs.d` to my load-path via the
> following:
>
> (add-to-list 'load-path (expand-file-name "~/.emacs.d"))
>
> But that had no effect.  I would like behaviour similar to site-lisp
> where all of the trees under site-lisp are automitacally added.  Any
> way I can do this?

My solution is to define my own custom function for adding
directories to the `load-path':

--8<---------------cut here---------------start------------->8---
;; load-path enhancement
(defun my-add-to-load-path (this-directory &optional with-subdirs recursive)
  "Add THIS-DIRECTORY at the beginning of the load-path, if it exists.
Add all its subdirectories not starting with a '.' if the
optional argument WITH-SUBDIRS is not nil.
Do it recursively if the third argument is not nil."
  (when this-directory
    (when (file-directory-p this-directory)
      (let* ((this-directory (expand-file-name this-directory))
             (files (directory-files this-directory t "^[^\\.]")))

        ;; completely canonicalize the directory name (*may not* begin with `~')
        (while (not (string= this-directory (expand-file-name this-directory)))
          (setq this-directory (expand-file-name this-directory)))

        (message "Adding `%s' to load-path..." this-directory)
        (add-to-list 'load-path this-directory)

        (if with-subdirs
            (progn
              (while files
                (setq dir-or-file (car files))
                (when (file-directory-p dir-or-file)
                  (if recursive
                      (my-add-to-load-path dir-or-file 'with-subdirs)
                    (my-add-to-load-path dir-or-file)))
                (setq files (cdr files)))))))))
--8<---------------cut here---------------end--------------->8---

Then, depending on my needs, I simply write a call such as:

--8<---------------cut here---------------start------------->8---
(my-add-to-load-path "~/.emacs.d/" 'with-subdirs 'recursive)
--8<---------------cut here---------------end--------------->8---

As you can read above, all directories starting with a `.' will
be avoided. That allows me to have a `.TEMP' subdirectory where
I can put files I wanna test later, or versions I wanna keep but
not see loaded.

As well, on a case by case basis, I decide if I want subdirs to
be loaded, even recursively, by setting or not the two optional
parameters.

Have a look at my .emacs file if you need more examples:

    http://www.mygooglest.com/fni/dot-emacs.html

Fabrice

_________________________________________________________________________
Fabrice Niessen
Search the Web with "My Google Search Tools" on http://www.MyGooglest.com


       reply	other threads:[~2009-01-28  8:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.5999.1233086875.26697.help-gnu-emacs@gnu.org>
2009-01-28  8:57 ` Fabrice Niessen [this message]
2009-01-27 20:07 Adding Additional Trees to the Load Path Tim Visher
2009-01-27 20:16 ` Juanma Barranquero

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ab9bzu38.fsf@mundaneum.com \
    --to=tdhkhcidiacy-genee64ty+gs+fvcfc7uqw@public.gmane.org \
    --cc=help-gnu-emacs-mXXj517/zsQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.