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: Thu, 17 Mar 2011 16:01:24 -0500 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <87lj0dtqaj.fsf@lifelogs.com> References: <87lj0eyq1x.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1300395721 14134 80.91.229.12 (17 Mar 2011 21:02:01 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 17 Mar 2011 21:02:01 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Mar 17 22:01: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 1Q0KKR-0007pw-Vd for ged-emacs-devel@m.gmane.org; Thu, 17 Mar 2011 22:01:56 +0100 Original-Received: from localhost ([127.0.0.1]:38674 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q0KKR-00051d-8h for ged-emacs-devel@m.gmane.org; Thu, 17 Mar 2011 17:01:55 -0400 Original-Received: from [140.186.70.92] (port=39918 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q0KKH-0004zG-CZ for emacs-devel@gnu.org; Thu, 17 Mar 2011 17:01:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q0KKD-0007WV-7w for emacs-devel@gnu.org; Thu, 17 Mar 2011 17:01:45 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:40066) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q0KKC-0007WB-TI for emacs-devel@gnu.org; Thu, 17 Mar 2011 17:01:41 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Q0KKB-0007hr-6H for emacs-devel@gnu.org; Thu, 17 Mar 2011 22:01:39 +0100 Original-Received: from 38.98.147.130 ([38.98.147.130]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 17 Mar 2011 22:01:39 +0100 Original-Received: from tzz by 38.98.147.130 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 17 Mar 2011 22:01:39 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 159 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 38.98.147.130 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:qNa0RhzvkNvn81vj4Y72+YxcTpw= 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:137374 Archived-At: --=-=-= Content-Type: text/plain On Thu, 17 Mar 2011 16:11:47 -0400 Stefan Monnier wrote: SM> Ted wrote: >> I know, but a package IMO will provide a better user experience because >> of the number of possible options. We already have recursive and >> ignore-errors; I imagine the list will only grow. Plus the loaded cache >> in `user-load-dirs-loaded' is pretty crucial to avoid double-loading >> files; remember Stephen Turnbull's concerns about installing hooks twice >> for instance. All of that is a pain to handle without a package. SM> Sounds fine, but then make it an ELPA package. If/when experience shows SM> it's a package many users want/need, we can move it into core SM> (i.e. bundle it with the standard Emacs distribution). OK. I've attached the library (now called load-dir.el, which I think is much better than user-load-*, especially since the function names are shorter). If you find it acceptable I'll commit it to the ELPA branch and deploy it (or let me know what more is needed). I modified the comments and license a bit as well. It should be possible to include it like rainbow-mode, directly as a single file. The Commentary was adjusted to reflect that the user needs to explicitly call (load-dirs) in their .emacs. Thanks 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.1 ;; 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) ;; (load-dirs) ;; Then after startup: ;; 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 "List of directories to load." :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 "List of directories to load." :group 'load-dir :type '(repeat 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 (mapcar 'load-dir-one (if (stringp load-dirs) (list load-dirs) load-dirs))) (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 (ignore-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))) (provide 'load-dir) ;;; load-dir.el ends here --=-=-=--