From: Ben Key <bkey76@gmail.com>
To: Emacs-devel@gnu.org
Cc: tzz@lifelogs.com, ego111@gmail.com
Subject: Re: user-controlled load-path extension: load-dir
Date: Wed, 9 Mar 2011 00:50:23 -0600 [thread overview]
Message-ID: <AANLkTikvAFWbdVhqeCcw6qCWUf9V3zaVP5xvoV9_ehua@mail.gmail.com> (raw)
In-Reply-To: <AANLkTin9YM7G_ro=eo+Vnsb5x5wg4EN4EEfNyP7MOSWu@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 1587 bytes --]
Hello,
I have attached to this message version 4 of user-load-dir.el.
Several changes have been made to this version.
1. The error handling in load-dir actually works as expected. If one of
the files in the user-load-dir generates an error, it is silently ignored
and load-dir continues to load all the other files in the user-load-dir.
2. Added the function byte-compile-dir to user-load-dir.el. This
function can be used to byte compile all files in the directory specified by
the directory parameter. If the optional parameter recurs is non-nil, this
is done recursively.
3. Added the function byte-compile-user-load-dir-files. This interactive
function may be used to byte compile all files in the user-load-dir.
4. The function load-user-load-dir-files does nothing if user-load-dir is
nil.
5. Modified the user-load-dir defcustom so that it is set to t instead of
nil in the case that it cannot be initialized at load time due to
user-init-file being nil.
6. Modified user-load-dir-after-init-hook so that it only sets
user-load-dir to its default value if it is equal to t.
The reason I made changes 5 and 6 is to allow for the possibility of this
feature being disabled by the user setting user-load-dir to nil.
Setting auto-load-files-in-user-load-dir to nil causes to not be called
automatically by the user-load-dir-after-init-hook but the files can still
be called by calling load-user-load-dir-files interactively. Setting
user-load-dir
to nil disables load-user-load-dir-files and
byte-compile-user-load-dir-files.
[-- Attachment #1.2: Type: text/html, Size: 1912 bytes --]
[-- Attachment #2: user-load-dir.el --]
[-- Type: application/octet-stream, Size: 5588 bytes --]
;;; user-load-dir.el -- A quick and dirty implementation of a user load
;;; directory. This file is provided as a possible answer to the
;;; "user-controlled load-path extension: load-dir" discussion on the
;;; emacs-devel list found at
;;; <http://lists.gnu.org/archive/html/emacs-devel/2011-03/msg00048.html>.
;;; This could eventually be turned into an Emacs package that can be
;;; installed via package.el. For now, this file can be installed by
;;; placing it somewhere in your load path and add the line
;;; (require 'user-load-dir)
;;; to your .emacs or site-start.el file.
;;; Copyright (c) 2011 Ben Key
;; This file 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.
;;
;; This file 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 the bk-emacs-tools package. If not, see
;; <http://www.gnu.org/licenses/>.
(if (not (boundp 'directory-files-no-dot-files-regexp))
(defconst directory-files-no-dot-files-regexp
"^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*"
"Regexp matching any file name except \".\" and \"..\".")
)
(defcustom user-load-dir
(if (not (null user-init-file))
;; If this file is loaded from site-start.el, `user-init-file'
;; will be nil, this will cause `file-name-directory' to throw an
;; error due to the argument not being a string. As a result, we
;; only attempt to set the default value of `user-load-dir' here
;; if `user-init-file' is not nil.
(format "%s.emacs.d/load.d" (file-name-directory (expand-file-name user-init-file)))
t
)
"A user defined directory in which the user can place .el files that
will automatically be loaded after Emacs initialization is complete."
:type 'directory
:group 'initialization
:require 'user-load-dir
)
(defcustom load-files-in-user-load-dir-recursively nil
"Non-nil causes `load-user-load-dir-files' to load all .el or .elc
files in the `user-load-dir' and in all subdirectories of the
`user-load-dir.' Nil causes `load-user-load-dir-files' to load only
the files in the `user-load-dir.'
The default value is nil."
:type 'boolean
:group 'initialization
:require 'user-load-dir
)
(defcustom auto-load-files-in-user-load-dir t
"Non-nil causes `load-user-load-dir-files' to be called automatically
from the `after-init-hook.' Nil suppresses this automatic loading.
Note that since `load-user-load-dir-files' is an interactive function,
you may call it manually by using 'M-x load-user-load-dir-files' if you
choose to set this variable to nil.
The default value is t."
:type 'boolean
:group 'initialization
:require 'user-load-dir
)
(defun load-dir (directory &optional recurse)
"Load all Emacs Lisp files in DIRECTORY.
If RECURSE is non-nil, recursively load all such files in all
subdirectories.
This function is based on one written by Evans Winner. See the message
<http://lists.gnu.org/archive/html/emacs-devel/2011-03/msg00239.html>
for details."
(interactive "D")
(let (this-file loaded-files-list)
(dolist
(file
(directory-files
(expand-file-name directory)
t directory-files-no-dot-files-regexp) nil)
(cond
((and recurse (file-directory-p file))
(when recurse (load-dir file))
)
((string-match "\\.el$\\|\\.elc$" file)
(setq this-file (file-name-sans-extension file))
(if (not (member this-file loaded-files-list))
(progn
(setq loaded-files-list (add-to-list 'loaded-files-list this-file))
(ignore-errors
(load this-file))
)
)
)
)
)
)
)
(defun load-user-load-dir-files ()
"Loads all .el files found in the `user-load-dir.'"
(interactive)
(if (not (null user-load-dir))
(load-dir user-load-dir load-files-in-user-load-dir-recursively)
)
)
(defun byte-compile-dir (directory &optional recurse)
"Byte compile all Emacs Lisp files in DIRECTORY. If RECURSE is
non-nil, recursively byte compile all such files in all
subdirectories."
(interactive "D")
(dolist
(file
(directory-files
(expand-file-name directory)
t directory-files-no-dot-files-regexp) nil)
(cond
((and recurse (file-directory-p file))
(when recurse (byte-compile-dir file))
)
((string-match "\\.el$" file)
(ignore-errors
(byte-compile-file file))
)
)
)
)
(defun byte-compile-user-load-dir-files ()
"Byte compiles all .el files found in the `user-load-dir.'"
(interactive)
(if (not (null user-load-dir))
(byte-compile-dir user-load-dir load-files-in-user-load-dir-recursively)
)
)
(defun user-load-dir-after-init-hook ()
"An `after-init-hook' function that is used to conditionally call
`load-user-load-dir-files' depending on the value of
`auto-load-files-in-user-load-dir'."
(if (equal user-load-dir t)
;; If this file is loaded from site-start.el, `user-load-dir' may
;; be nil at this point. See the comments for `user-load-dir'
;; above. If this happens, use the default value here.
(setq user-load-dir
(format "%s.emacs.d/load.d" (file-name-directory (expand-file-name user-init-file))))
)
(if auto-load-files-in-user-load-dir
(load-user-load-dir-files)
)
)
(add-hook 'after-init-hook 'user-load-dir-after-init-hook)
(provide 'user-load-dir)
next prev parent reply other threads:[~2011-03-09 6:50 UTC|newest]
Thread overview: 129+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <AANLkTin1zXJQo2vsju7kpa31Nw568m_eNZS+gJ6g2tQO@mail.gmail.com>
2011-03-08 18:49 ` user-controlled load-path extension: load-dir Ben Key
2011-03-08 20:01 ` Dimitri Fontaine
2011-03-08 20:25 ` Chad Brown
2011-03-08 20:38 ` Dimitri Fontaine
2011-03-08 22:40 ` Chad Brown
2011-03-09 9:36 ` Dimitri Fontaine
2011-03-09 11:52 ` Ted Zlatanov
2011-03-08 22:57 ` Ben Key
2011-03-09 3:28 ` Ben Key
2011-03-09 6:50 ` Ben Key [this message]
2011-03-09 7:29 ` Jan D.
2011-03-09 16:00 ` Ben Key
2011-03-09 11:39 ` Ted Zlatanov
2011-03-09 19:51 ` Chong Yidong
2011-03-09 20:08 ` Ben Key
2011-03-09 20:18 ` Ted Zlatanov
2011-03-09 20:32 ` Chong Yidong
2011-03-09 20:44 ` Ted Zlatanov
2011-03-10 11:30 ` Dimitri Fontaine
2011-03-10 14:27 ` Tom Tromey
2011-03-10 17:23 ` Dimitri Fontaine
2011-03-10 18:33 ` Tom Tromey
2011-03-10 18:56 ` Chong Yidong
2011-03-10 19:32 ` Eli Zaretskii
2011-03-10 20:30 ` Dimitri Fontaine
2011-03-10 21:54 ` Chong Yidong
2011-03-11 8:43 ` Dimitri Fontaine
2011-03-10 19:36 ` Jambunathan K
2011-03-11 15:00 ` chad
2011-03-11 17:41 ` Dimitri Fontaine
2011-03-12 5:51 ` chad
2011-03-12 10:09 ` Jan Djärv
2011-03-11 18:51 ` Ted Zlatanov
2011-03-16 14:16 ` Ted Zlatanov
2011-03-16 15:43 ` Stefan Monnier
2011-03-16 20:08 ` Ted Zlatanov
2011-03-17 2:13 ` Stefan Monnier
2011-03-17 3:34 ` Ted Zlatanov
2011-03-17 4:42 ` PJ Weisberg
2011-03-16 20:11 ` Evans Winner
2011-03-16 20:23 ` Ted Zlatanov
2011-03-10 2:21 ` Stefan Monnier
2011-03-24 0:03 Ben Key
2011-03-24 14:38 ` Stefan Monnier
2011-03-26 11:37 ` Ted Zlatanov
2011-04-02 18:35 ` Chong Yidong
2011-04-04 9:54 ` Ted Zlatanov
-- strict thread matches above, loose matches on Subject: below --
2011-03-19 4:10 Ben Key
2011-03-19 13:29 ` Juanma Barranquero
2011-03-19 16:07 ` Ben Key
2011-03-19 14:15 ` Ted Zlatanov
2011-03-20 2:58 ` Stefan Monnier
2011-03-20 12:05 ` Ted Zlatanov
2011-03-23 15:32 ` Ted Zlatanov
2011-03-23 20:33 ` Stefan Monnier
2011-03-17 4:22 Ben Key
2011-03-17 6:31 ` Evans Winner
2011-03-17 10:55 ` Ted Zlatanov
2011-03-17 20:11 ` Stefan Monnier
2011-03-17 21:01 ` Ted Zlatanov
2011-03-17 21:05 ` Tom Tromey
2011-03-17 21:23 ` Ted Zlatanov
2011-03-17 22:50 ` Glenn Morris
2011-03-18 2:46 ` Ted Zlatanov
2011-03-18 10:56 ` Dimitri Fontaine
2011-03-18 13:07 ` Ted Zlatanov
2011-03-18 2:21 ` Stefan Monnier
2011-03-08 7:14 Ben Key
2011-03-08 9:58 ` Evans Winner
2011-03-08 18:49 ` PJ Weisberg
2011-03-01 20:32 Ted Zlatanov
2011-03-03 21:07 ` Dimitri Fontaine
2011-03-04 9:55 ` Julien Danjou
2011-03-04 17:18 ` Tom Tromey
2011-03-04 18:04 ` Ted Zlatanov
2011-03-04 18:37 ` Dimitri Fontaine
2011-03-04 19:35 ` Tom Tromey
2011-03-04 19:45 ` Dimitri Fontaine
2011-03-04 19:54 ` Ted Zlatanov
2011-03-04 20:21 ` Dimitri Fontaine
2011-03-04 20:25 ` Chad Brown
2011-03-04 20:46 ` Ted Zlatanov
2011-03-05 19:24 ` Chad Brown
2011-03-04 20:26 ` Chad Brown
2011-03-04 20:08 ` Tom Tromey
2011-03-04 20:24 ` Dimitri Fontaine
2011-03-04 21:17 ` Tom Tromey
2011-03-04 21:33 ` Dimitri Fontaine
2011-03-04 21:37 ` Tom Tromey
2011-03-05 3:18 ` Ted Zlatanov
2011-03-05 19:11 ` Chad Brown
2011-03-06 7:21 ` Mike Mattie
2011-03-07 16:24 ` Ted Zlatanov
2011-03-07 17:18 ` Chad Brown
2011-03-07 17:59 ` Ted Zlatanov
2011-03-08 17:36 ` Dimitri Fontaine
2011-03-08 18:30 ` Chad Brown
2011-03-07 17:52 ` Stefan Monnier
2011-03-07 20:39 ` PJ Weisberg
2011-03-08 2:46 ` Stefan Monnier
2011-03-08 10:26 ` Ted Zlatanov
2011-03-08 17:14 ` Chong Yidong
2011-03-08 18:47 ` Ted Zlatanov
2011-03-08 19:23 ` Julien Danjou
2011-03-09 2:54 ` Stefan Monnier
2011-03-09 19:57 ` Chong Yidong
2011-03-08 20:59 ` Stefan Monnier
2011-03-08 21:38 ` Ted Zlatanov
2011-03-09 7:06 ` Jan D.
2011-03-09 7:17 ` Christoph Scholtes
2011-03-09 10:01 ` Jan Djärv
2011-03-09 17:29 ` Stephen J. Turnbull
2011-03-09 18:18 ` Ted Zlatanov
2011-03-09 19:33 ` Stephen J. Turnbull
2011-03-09 19:57 ` Ted Zlatanov
2011-03-10 3:20 ` Stephen J. Turnbull
2011-03-10 5:01 ` Ted Zlatanov
2011-03-10 7:08 ` Stephen J. Turnbull
2011-03-10 13:15 ` Ted Zlatanov
2011-03-11 2:10 ` Stephen J. Turnbull
2011-03-09 21:57 ` Mike Mattie
2011-03-10 7:08 ` Jan Djärv
2011-03-09 6:03 ` Mike Mattie
2011-03-09 7:20 ` Jan D.
2011-03-09 23:44 ` Mike Mattie
2011-03-08 0:47 ` Mike Mattie
2011-03-08 10:37 ` Ted Zlatanov
2011-03-09 6:26 ` Mike Mattie
2011-03-09 11:26 ` Ted Zlatanov
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTikvAFWbdVhqeCcw6qCWUf9V3zaVP5xvoV9_ehua@mail.gmail.com \
--to=bkey76@gmail.com \
--cc=Emacs-devel@gnu.org \
--cc=ego111@gmail.com \
--cc=tzz@lifelogs.com \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).