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 05:55:22 -0500 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <87lj0eyq1x.fsf@lifelogs.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1300359356 9808 80.91.229.12 (17 Mar 2011 10:55:56 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 17 Mar 2011 10:55:56 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Mar 17 11:55:52 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 1Q0Ars-00059c-Dt for ged-emacs-devel@m.gmane.org; Thu, 17 Mar 2011 11:55:49 +0100 Original-Received: from localhost ([127.0.0.1]:42760 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q0Arr-0000eT-Lc for ged-emacs-devel@m.gmane.org; Thu, 17 Mar 2011 06:55:47 -0400 Original-Received: from [140.186.70.92] (port=56503 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q0Ari-0000aJ-Pt for emacs-devel@gnu.org; Thu, 17 Mar 2011 06:55:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q0Arh-0003qa-5h for emacs-devel@gnu.org; Thu, 17 Mar 2011 06:55:38 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:55258) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q0Arg-0003qM-N5 for emacs-devel@gnu.org; Thu, 17 Mar 2011 06:55:37 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Q0Arf-00053x-2E for emacs-devel@gnu.org; Thu, 17 Mar 2011 11:55:35 +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 ; Thu, 17 Mar 2011 11:55:35 +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 ; Thu, 17 Mar 2011 11:55:35 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 198 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:2P14F/r2xNCl3yrZaKDqLloQKGA= 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:137335 Archived-At: --=-=-= Content-Type: text/plain On Thu, 17 Mar 2011 00:22:10 -0400 Ben Key wrote: BK> For what it is worth I signed the necessary copyright assignment papers BK> years ago. I have been a member of the Emacs project since Wednesday, BK> November 13, 2002. If you go to the Emacs Project Memberlist page you will BK> see me listed as Ben Key . I simply have not been an active BK> contributor to Emacs for the past several years. Sorry Ben, I just checked the ChangeLogs. I put you in the authors list of user-load-dirs.el, which is attached below. Please suggest any changes you think are necessary. BK> I do think it is important to trap errors though. If you do not, and you BK> call this new load directory function in your .emacs file, Emacs BK> initialization will abort at the first error leaving your Emacs session half BK> configured (any code positioned after the call to load directory will not BK> run). I do not think this is a good idea. I do not feel very strongly BK> about this though. I think it's a valid way to do it, but the way I think of it (as a logical extension to .emacs) errors should not be trapped. I made it an option. On Thu, 17 Mar 2011 00:31:34 -0600 Evans Winner wrote: EW> By the way, a version of `load-dir' that I sent Ben Key a EW> week or so ago mostly/partly includes handling of gzipped EW> libraries (or whatever is returned by `get-load-suffixes') EW> which seemed a useful variation, though it occurs to me that EW> I don't know if that is portable across platforms. It seems to work OK and automatically filters out "." and ".." so it's a good idea. I added that to user-load-dirs.el as well. On Wed, 16 Mar 2011 21:42:17 -0700 PJ Weisberg wrote: PW> I only saw Stefan say to go ahead with a load-directory function, 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. PW> which I assumed would live in files.el next to load-file and look PW> something like this: PW> (defun load-directory (dir recursive) PW> "Load all Lisp files in DIR. If RECURSIVE is non-nil, PW> recursively call load-directory for all subdirectories of dir." PW> (interactive "DLoad Dir: \nP") PW> (dolist (file (directory-files dir t ".*\\.el$")) PW> ;; Cut off the .el so load will pick up the .elc version if it's there PW> (setq file (substring file 0 -3)) PW> (load file)) PW> (when recursive PW> (dolist (file (directory-files dir t)) PW> (if (and (file-directory-p file) PW> (not (string-match "/\\.\\.?$" file))) PW> (load-directory file recursive))))) PW> If I'm not mistaken that's about 90% of what you want, and makes using PW> your own load-dir at least as easy as using your own custom-file. I will use `file-name-sans-extension' instead of the substring to handle all the possible values from `get-load-suffixes', but yeah I think using the bare file name is better than explicitly loading it with the extension. Thanks for that (and I think both Ben and Evans had something similar). If `user-load-dirs-load' is autoloaded then it's just as easy to manage at the user level as the `load-directory' function you suggest. The library can be made into an ELPA package easily and thus used in older Emacsen. My goal, though, is to call `user-load-dirs-load' in the Emacs startup, as I've mentioned. Ted --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=user-load-dirs.el Content-Transfer-Encoding: quoted-printable ;;; user-load-dirs.el --- load all Emacs Lisp files in given directories ;; Copyright (C) 2011 Teodor Zlatanov ;; Authors: Teodor Zlatanov , ;; Ben Key ;; With-Help-From: Evans Winner , PJ Weisberg ;; Version: 0.0.1 ;; Keywords: lisp, files, convenience ;; This program 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 program 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 this program. If not, see . ;;; Commentary: ;; This library will load all Lisp files found in the `user-load-dirs' ;; variable. ;; Normal usage: ;; (setq user-load-dirs-list '("~/mystuff")) ;; or Customize it ;; you may also want to set user-load-dirs-recursive ;; (require 'user-load-dirs) ;; this may be automatic in Emacs at some point but you still need to ;; do it manually if you add files ;; M-x user-load-dirs-load ;;; Code: (eval-when-compile (require 'cl)) (defgroup user-load-dirs nil "Automatically load all Emacs Lisp files in given directories." :group 'initialization) (defcustom user-load-dirs-recursive nil "List of directories to load." :group 'user-load-dirs :type 'boolean) (defcustom user-load-dirs-ignore-errors nil "Whether errors in the loaded files should be ignored." :group 'user-load-dirs :type 'boolean) (defcustom user-load-dirs-list nil "List of directories to load." :group 'user-load-dirs :type '(repeat directory)) (defun user-load-dirs-load () "Load all Emacs Lisp files in `user-load-dirs-list'. Will not load a file twice (use `user-load-dirs-reload' for that). Recurses into subdirectories if `user-load-dirs-recursive' is t." (interactive) (mapcar 'user-load-dirs-one (if (stringp user-load-dirs-list) (list user-load-dirs-list) user-load-dirs-list))) (defun user-load-dirs-reload () "Load all Emacs Lisp files in `user-load-dirs-list'. Clears the list of loaded files and just calls `user-load-dirs-load'." (interactive) (setq user-load-dirs-loaded nil) (user-load-dirs-load)) (defvar user-load-dirs-loaded nil "List of already loaded files.") (defun user-load-dirs-one (dir) "Load all Emacs Lisp files in DIR. Recurses into subdirectories if `user-load-dirs-recursive' is t." (message "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 user-load-dirs-loaded) (message "Skipping %s, it's already loaded." f) (message "Loading %s..." f) (if user-load-dirs-ignore-errors (ignore-errors (load f)) (load f)) (message "Loading %s... done" f) (add-to-list 'user-load-dirs-loaded f)))) (when user-load-dirs-recursive (dolist (f (directory-files dir t)) (when (file-directory-p f) (user-load-dirs-one f)))))) (provide 'user-load-dirs) ;;; user-load-dirs.el ends here --=-=-=--