From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.devel Subject: Re: user-controlled load-path extension: load-dir Date: Sat, 19 Mar 2011 09:15:31 -0500 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <87sjujurgc.fsf@lifelogs.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1300544162 15796 80.91.229.12 (19 Mar 2011 14:16:02 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 19 Mar 2011 14:16:02 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Mar 19 15:15:56 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q0wwd-0006IQ-4M for ged-emacs-devel@m.gmane.org; Sat, 19 Mar 2011 15:15:55 +0100 Original-Received: from localhost ([127.0.0.1]:53767 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q0wwc-0002yu-IA for ged-emacs-devel@m.gmane.org; Sat, 19 Mar 2011 10:15:54 -0400 Original-Received: from [140.186.70.92] (port=52779 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q0wwW-0002wE-Gl for emacs-devel@gnu.org; Sat, 19 Mar 2011 10:15:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q0wwV-00042I-61 for emacs-devel@gnu.org; Sat, 19 Mar 2011 10:15:48 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:51781) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q0wwU-00042A-OC for emacs-devel@gnu.org; Sat, 19 Mar 2011 10:15:47 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Q0wwQ-0006GU-Sl for emacs-devel@gnu.org; Sat, 19 Mar 2011 15:15:42 +0100 Original-Received: from c-67-186-102-106.hsd1.il.comcast.net ([67.186.102.106]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 19 Mar 2011 15:15:42 +0100 Original-Received: from tzz by c-67-186-102-106.hsd1.il.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 19 Mar 2011 15:15:42 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 200 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: c-67-186-102-106.hsd1.il.comcast.net X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" User-Agent: Gnus/5.110014 (No Gnus v0.14) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:Mwr2iEh73CkwjkWKq5F8xUl/QM8= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 80.91.229.12 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:137421 Archived-At: --=-=-= Content-Type: text/plain On Sat, 19 Mar 2011 00:10:26 -0400 Ben Key wrote: BK> 1. Each of the defcustom items now has a require property. The main BK> benefit of this is that a user may now simply place load-dir.el in their BK> load path, use M-x load-library to load 'load-dir' and then do a M-x BK> customize-group to customize the 'load-dir' group, customize load-dirs, and BK> restart Emacs. There is no need to also manually edit their .emacs file to BK> add a '(require 'load-dir)' in order to actually cause Emacs to load BK> load-dir.el. Cool. BK> 2. Modified the load-dirs defcustom so that it can now accept several BK> types via the "Value Menu" customize feature. BK> 1. nil, the default value, effectively causes load-dir.el to do BK> nothing. BK> 2. t causes the default directory of ~/.emacs.d/load.d to be used BK> (saves typing). BK> 3. A single directory causes files in that directory to be loaded. BK> 4. A list of directories causes all files in every directory in the BK> list to be loaded. I added :tag properties too so it looks nice in Customize and changed the double `if' you had to handle these load-dirs variations to a `cond'. But yeah, this is a good change. I was thinking that maybe ~/.emacs.d/load.d should be customizable (it shows up in 3 places and may need to vary on W32) but it works either way. On Sat, 19 Mar 2011 14:29:30 +0100 Juanma Barranquero wrote: JB> (defcustom load-dir-recursive nil JB> "List of directories to load." JB> That docstring can't possibly be right :-) Thanks, fixed. Version 0.0.2 attached for your review. Ted --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=load-dir.el Content-Transfer-Encoding: quoted-printable ;;; load-dir.el --- load all Emacs Lisp files in given directories ;; Copyright (C) 2011 Free Software Foundation, Inc ;; Authors: Teodor Zlatanov , ;; Ben Key ;; With-Help-From: Evans Winner , PJ Weisberg ;; 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 . ;;; 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-hoo= k' ;; 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 :require 'load-dir :type 'boolean) (defcustom load-dir-recursive nil "Whether subdirectories should be loaded too." :group 'load-dir :require 'load-dir :type 'boolean) (defcustom load-dir-ignore-errors nil "Whether errors in the loaded files should be ignored." :group 'load-dir :require 'load-dir :type 'boolean) (defcustom load-dirs nil "This variable allows you to define which directories should be loaded in= one of several ways. If load-dirs is nil, no directories are loaded. This is the default behavi= or. If load-dirs is t, only files in ~/.emacs.d/load.d will be loaded. If load-dirs is a single directory, only files in that directory will be lo= aded. If load-dirs is a list of directories, all files found in all the directori= es in the list will be loaded." :group 'load-dir :require '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)))) ;;;###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)) (defvar load-dir-loaded nil "List of already loaded files.") (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 --=-=-=--