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 21:46:44 -0500 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <871v25xi0b.fsf@lifelogs.com> References: <87lj0eyq1x.fsf@lifelogs.com> <87lj0dtqaj.fsf@lifelogs.com> <87d3lptpa3.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1300416430 17305 80.91.229.12 (18 Mar 2011 02:47:10 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 18 Mar 2011 02:47:10 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Mar 18 03:47:06 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 1Q0PiT-0006s5-UQ for ged-emacs-devel@m.gmane.org; Fri, 18 Mar 2011 03:47:06 +0100 Original-Received: from localhost ([127.0.0.1]:38360 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q0PiS-0003R3-Ox for ged-emacs-devel@m.gmane.org; Thu, 17 Mar 2011 22:47:04 -0400 Original-Received: from [140.186.70.92] (port=52327 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q0PiL-0003Qx-Ha for emacs-devel@gnu.org; Thu, 17 Mar 2011 22:46:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q0PiK-0001ZW-Bs for emacs-devel@gnu.org; Thu, 17 Mar 2011 22:46:57 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:42608) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q0PiJ-0001ZQ-UP for emacs-devel@gnu.org; Thu, 17 Mar 2011 22:46:56 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Q0PiJ-0006oL-5o for emacs-devel@gnu.org; Fri, 18 Mar 2011 03:46:55 +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 ; Fri, 18 Mar 2011 03:46:55 +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 ; Fri, 18 Mar 2011 03:46:55 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 179 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:I6MDW39yO+6Z/zt/Gza0TcRVv80= 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:137388 Archived-At: --=-=-= Content-Type: text/plain On Thu, 17 Mar 2011 18:50:42 -0400 Glenn Morris wrote: GM> Ted Zlatanov wrote: Tom> Why not put an autoload cookie on load-dirs? Tom> That would be friendlier for users. >> >> I didn't think of it, thanks. I added those to my copy. GM> Noooo.... Please don't autoload defcustoms unless they really, really GM> need it. OK. See attached. On Thu, 17 Mar 2011 22:21:33 -0400 Stefan Monnier wrote: >> 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 SM> The mapcar call should be replaced by mapc or dolist. As mentioned, SM> you may want to add an autoload cookie on the [`load-dirs'] SM> function. I did the mapc. Not sure about the autoload cookie, see above. So it's off for now. SM> Also you'll want to replace `ignore-errors' with SM> `with-demoted-errors'. More importantly, if it's an ELPA package, SM> it can hook itself via autoload cookies so the user doesn't even SM> need to call load-dirs and can just set load-dirs instead. E.g. SM> ;;;###autoload SM> (add-hook 'after-init-hook 'load-dirs) Done. Thanks for the suggestions. I wasn't sure if this is a good default because of people who want to use this package but not on startup. But I guess that's a rare enough case that this is OK as the default. 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) ;; 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 :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 (mapc 'load-dir-one (if (stringp load-dirs) (list load-dirs) 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 --=-=-=--