unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#8205: user-controlled load-path extension: load-dir
@ 2011-03-08 18:05 Ben Key
  2011-03-08 18:48 ` bug#8205: user-controlled load-path extension: load-dir (Ben Key) Ben Key
       [not found] ` <mailman.15.1299611216.4046.bug-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 3+ messages in thread
From: Ben Key @ 2011-03-08 18:05 UTC (permalink / raw)
  To: 8205, tzz


[-- Attachment #1.1: Type: text/plain, Size: 1146 bytes --]

Hello,

I have attached to this message version 2 of user-load-dir.el.  This version
incorporates the recursive load-dir function written by Evans Winner (see <
http://lists.gnu.org/archive/html/emacs-devel/2011-03/msg00239.html>).  It
also adds two new defcustom variables,
load-files-in-user-load-dir-recursively and
auto-load-files-in-user-load-dir.

Note that one major new feature introduced by this version is that if the
.el file has been byte compiled, the byte compiled version will be loaded
instead of the source version.  This is a major improvement over my original
version which would only load .el files.

There are two remaining issues with this version.  If one of the files in
the user-load-dir has been byte-compiled, it will be loaded twice.  Also it
has no error handling.

I am more than willing to continue development of this file into an Emacs
package that can be included in ELPA.  This would make it possible for this
useful feature to be made readily available to those who want to use it
without including it in Emacs itself.

I have one question.  What sort of error handling should I incorporate into
this package?

[-- Attachment #1.2: Type: text/html, Size: 1306 bytes --]

[-- Attachment #2: user-load-dir.el --]
[-- Type: application/octet-stream, Size: 3741 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/>.

(defcustom user-load-dir
  (format "%s.emacs.d/load" (file-name-directory (expand-file-name user-init-file)))
  "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 was written by Evans Winner.  See the message
<http://lists.gnu.org/archive/html/emacs-devel/2011-03/msg00239.html>"
  (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 (load-dir file)))
     ((string-match "\\.el$\\|\\.elc$" file)
      (load-library (file-name-sans-extension file))))))

(defun load-user-load-dir-files ()
  "Loads all .el files found in the `user-load-dir.'"
  (interactive)
  (load-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 auto-load-files-in-user-load-dir
	  (load-user-load-dir-files)
	)
  )

(add-hook 'after-init-hook 'load-user-load-dir-files)

(provide 'user-load-dir)

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

* bug#8205: user-controlled load-path extension: load-dir (Ben Key)
  2011-03-08 18:05 bug#8205: user-controlled load-path extension: load-dir Ben Key
@ 2011-03-08 18:48 ` Ben Key
       [not found] ` <mailman.15.1299611216.4046.bug-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 3+ messages in thread
From: Ben Key @ 2011-03-08 18:48 UTC (permalink / raw)
  To: bug-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 210 bytes --]

Hello,

Please ignore this bug.  I did not intend to send the message to
bug-gnu-emacs@gnu.org.  I meant it to go to Emacs-devel@gnu.org.  I guess I
was just careless then typing the addresses in the To field.

[-- Attachment #2: Type: text/html, Size: 335 bytes --]

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

* bug#8205: Closing bug#8205: user-controlled load-path extension: load-dir (Ben Key)
       [not found] ` <mailman.15.1299611216.4046.bug-gnu-emacs@gnu.org>
@ 2011-03-08 19:51   ` Ted Zlatanov
  0 siblings, 0 replies; 3+ messages in thread
From: Ted Zlatanov @ 2011-03-08 19:51 UTC (permalink / raw)
  To: 8205-done, Ben Key

On Tue, 8 Mar 2011 12:48:58 -0600 Ben Key <bkey76@gmail.com> wrote: 

BK> Hello,
BK> Please ignore this bug.  I did not intend to send the message to
BK> bug-gnu-emacs@gnu.org.  I meant it to go to Emacs-devel@gnu.org.  I guess I
BK> was just careless then typing the addresses in the To field.

This should close the bug.

Ted





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

end of thread, other threads:[~2011-03-08 19:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-08 18:05 bug#8205: user-controlled load-path extension: load-dir Ben Key
2011-03-08 18:48 ` bug#8205: user-controlled load-path extension: load-dir (Ben Key) Ben Key
     [not found] ` <mailman.15.1299611216.4046.bug-gnu-emacs@gnu.org>
2011-03-08 19:51   ` bug#8205: Closing " Ted Zlatanov

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).