]> code.delx.au - gnu-emacs-elpa/commitdiff
packages/load-dir-0.0.2.el: added.
authorTed Zlatanov <tzz@lifelogs.com>
Sat, 26 Mar 2011 11:32:18 +0000 (06:32 -0500)
committerTed Zlatanov <tzz@lifelogs.com>
Sat, 26 Mar 2011 11:32:18 +0000 (06:32 -0500)
packages/archive-contents
packages/elpa.rss
packages/load-dir-0.0.2.el [new file with mode: 0644]
packages/load-dir-readme.txt [new file with mode: 0644]

index ce85f0815b92653b5a3123fc374b45be739990aa..2968ad4eab00872ea5e49be7e4ecf5b0b679f5ac 100644 (file)
@@ -8,6 +8,9 @@
  (debbugs .
        [(0 1)
        nil "SOAP library to access debbugs servers" tar])
+ (load-dir .
+       [(0 0 2)
+       nil "Modularize your .emacs: autoload Lisp snippets." single])
  (muse .
        [(3 20)
        nil "Authoring and publishing tool" tar])
index 8523c280fada97120a723a4d08fea6997fcd89c8..68706c1d947e994a54caf729a2ea7a895a864f78 100644 (file)
@@ -5,6 +5,12 @@
     <language>en</language>
     <description>News for the Emacs Lisp Package Archive</description>
 <item>
+<title>load-dir version 0.0.2</title>
+<link>http://elpa.gnu.org/packages/news.html</link>
+<description>Modularize your .emacs: autoload Lisp snippets</description>
+<pubDate>Sat, 26 March 2011 06:10:00 -0500</pubDate>
+</item>
+<item>
 <title>auctex.tar version 11.86</title>
 <link>http://elpa.gnu.org/packages/news.html</link>
 <description>integrated environment for *TeX*</description>
diff --git a/packages/load-dir-0.0.2.el b/packages/load-dir-0.0.2.el
new file mode 100644 (file)
index 0000000..b9f07da
--- /dev/null
@@ -0,0 +1,139 @@
+;;; load-dir.el --- load all Emacs Lisp files in given directories
+
+;; Copyright (C) 2011 Free Software Foundation, Inc
+
+;; Authors: Teodor Zlatanov <tzz@lifelogs.com>,
+;;          Ben Key <bkey76@gmail.com>
+;; With-Help-From: Evans Winner <ego111@gmail.com>, PJ Weisberg <pj@irregularexpressions.net>
+;; Version: 0.0.2
+;; Keywords: lisp, files, convenience
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs 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 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs 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 GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library will load all Lisp files found in the `load-dirs' variable.
+;; (you may also want to set `load-dir-debug', `load-dir-recursive',
+;;  and `load-dir-ignore-errors')
+
+;; Normal usage in .emacs:
+
+;; (setq load-dirs '("~/mystuff")) ;; or Customize it
+;; (require 'load-dir) ;; this will add `load-dirs' to your `after-init-hook'
+
+;; Then after startup:
+
+;; Explicitly load new files only...
+;; M-x load-dirs
+
+;; Or reload all your files...
+;; M-x load-dirs-reload
+
+;;; Code:
+
+(eval-when-compile (require 'cl))
+
+(defgroup load-dir nil
+  "Automatically load all Emacs Lisp files in given directories."
+  :group 'initialization)
+
+(defcustom load-dir-debug t
+  "Debugging messages toggle, default to t."
+  :group 'load-dir
+  :type 'boolean)
+
+(defcustom load-dir-recursive nil
+  "Whether subdirectories should be loaded too."
+  :group 'load-dir
+  :type 'boolean)
+
+(defcustom load-dir-ignore-errors nil
+  "Whether errors in the loaded files should be ignored."
+  :group 'load-dir
+  :type 'boolean)
+
+(defcustom load-dirs nil
+  "This variable allows you to define which directories should be loaded.
+
+If nil, no directories are loaded.  This is the default behavior.
+If t, only files in ~/.emacs.d/load.d will be loaded.
+If a single directory name, only files in that directory will be loaded.
+If a list of directory names, all files found in all the
+directories will be loaded."
+  :group 'load-dir
+  :tag "What directories to load"
+  :type '(choice (const :tag "Load all from ~/.emacs.d/load.d" t)
+                 (const :tag "Don't load anything" nil)
+                 directory
+                 (repeat :tag "Directories" directory)))
+
+(defun load-dirs ()
+  "Load all Emacs Lisp files in `load-dirs'.
+Will not load a file twice (use `load-dir-reload' for that).
+Recurses into subdirectories if `load-dir-recursive' is t."
+  (interactive)
+  ;; avoid the case where users inadvertently set `load-dirs' to a string
+  (mapc 'load-dir-one (cond
+                       ((eq load-dirs t)
+                        (list (expand-file-name "~/.emacs.d/load.d")))
+                       ((stringp load-dirs)
+                        (list load-dirs))
+                       (t load-dirs))))
+
+(defvar load-dir-loaded nil
+  "List of already loaded files.")
+
+;;;###autoload
+(defun load-dirs-reload ()
+  "Load all Emacs Lisp files in `load-dirs'.
+Clears the list of loaded files and just calls `load-dir-load'."
+  (interactive)
+  (setq load-dir-loaded nil)
+  (load-dirs))
+
+(defun load-dir-one (dir)
+  "Load all Emacs Lisp files in DIR.
+Recurses into subdirectories if `load-dir-recursive' is t."
+  (load-dir-debug "Loading Emacs Lisp code from %s" dir)
+  (let ((suffixes (get-load-suffixes)))
+    (dolist (f (and (file-exists-p dir)
+                    (file-directory-p dir)
+                    (directory-files dir t)))
+      (when (and (not (file-directory-p f))
+                 (member (file-name-extension f t) suffixes))
+        (setq f (file-name-sans-extension f))
+        (if (member f load-dir-loaded)
+            (load-dir-debug "Skipping %s, it's already loaded." f)
+          (if load-dir-ignore-errors
+              (with-demoted-errors (load f))
+            (load f))
+          (add-to-list 'load-dir-loaded f))))
+
+    (when load-dir-recursive
+      (dolist (f (directory-files dir t))
+        (when (file-directory-p f)
+          (load-dir-one f))))))
+
+(defun load-dir-debug (&rest args)
+  "Print a debug message like `message' if `load-dir-debug' is set."
+  (when load-dir-debug
+    (apply 'message args)))
+
+;;;###autoload
+(add-hook 'after-init-hook 'load-dirs)
+
+(provide 'load-dir)
+;;; load-dir.el ends here
diff --git a/packages/load-dir-readme.txt b/packages/load-dir-readme.txt
new file mode 100644 (file)
index 0000000..f88210a
--- /dev/null
@@ -0,0 +1,12 @@
+This package provides a way to load all Emacs Lisp snippets (they
+don't have to be libraries) in a directory on startup or when Emacs is
+already running.  It won't reload snippets unless the user requests
+it, so for instance adding a lambda to a hook is usually safe.
+
+You can specify ~/.emacs.d/load.d, a single directory, or a list of
+directories.  The file search can be recursive.
+
+The intent with ~/.emacs.d/load.d is to give package installers like
+el-get.el (see https://github.com/dimitri/el-get) and other tools a
+way to easily bootstrap themselves without necessarily modifying your
+.emacs or custom files directly.