unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Adding Additional Trees to the Load Path
@ 2009-01-27 20:07 Tim Visher
  2009-01-27 20:16 ` Juanma Barranquero
  0 siblings, 1 reply; 3+ messages in thread
From: Tim Visher @ 2009-01-27 20:07 UTC (permalink / raw)
  To: Emacs Help List

Hello Everyone,

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?

Thanks in advance!

-- 

In Christ,

Timmy V.

http://burningones.com/
http://five.sentenc.es/ - Spend less time on e-mail




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Adding Additional Trees to the Load Path
  2009-01-27 20:07 Adding Additional Trees to the Load Path Tim Visher
@ 2009-01-27 20:16 ` Juanma Barranquero
  0 siblings, 0 replies; 3+ messages in thread
From: Juanma Barranquero @ 2009-01-27 20:16 UTC (permalink / raw)
  To: Tim Visher; +Cc: Emacs Help List

On Tue, Jan 27, 2009 at 21:07, Tim Visher <tim.visher@gmail.com> wrote:

> (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?

After adding ~/.emacs.d to load path, try adding a subdirs.el file to
~/.emacs.d with the following contents:

;; -*- no-byte-compile: t -*-
(if (fboundp 'normal-top-level-add-subdirs-to-load-path)
    (normal-top-level-add-subdirs-to-load-path))


    Juanma




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Adding Additional Trees to the Load Path
       [not found] <mailman.5999.1233086875.26697.help-gnu-emacs@gnu.org>
@ 2009-01-28  8:57 ` Fabrice Niessen
  0 siblings, 0 replies; 3+ messages in thread
From: Fabrice Niessen @ 2009-01-28  8:57 UTC (permalink / raw)
  To: help-gnu-emacs-mXXj517/zsQ

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-01-28  8:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-27 20:07 Adding Additional Trees to the Load Path Tim Visher
2009-01-27 20:16 ` Juanma Barranquero
     [not found] <mailman.5999.1233086875.26697.help-gnu-emacs@gnu.org>
2009-01-28  8:57 ` Fabrice Niessen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).