unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: user-controlled load-path extension: load-dir
@ 2011-03-17  4:22 Ben Key
  2011-03-17  6:31 ` Evans Winner
  2011-03-17 10:55 ` Ted Zlatanov
  0 siblings, 2 replies; 129+ messages in thread
From: Ben Key @ 2011-03-17  4:22 UTC (permalink / raw)
  To: tzz, Emacs-devel

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

Hello,

For what it is worth I signed the necessary copyright assignment papers
years ago.  I have been a member of the Emacs project since Wednesday,
November 13, 2002.  If you go to the Emacs Project Memberlist page you will
see me listed as Ben Key <bkey1>.  I simply have not been an active
contributor to Emacs for the past several years.

I also have been very busy at work for the last several weeks and have not
had a chance yet to make the various suggested name changes to the functions
and variables.  In fact I am on a business trip now, the second in 3 weeks.

I do not mind what Ted has done though.

I do think it is important to trap errors though.  If you do not, and you
call this new load directory function in your .emacs file, Emacs
initialization will abort at the first error leaving your Emacs session half
configured (any code positioned after the call to load directory will not
run).  I do not think this is a good idea.  I do not feel very strongly
about this though.

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

^ permalink raw reply	[flat|nested] 129+ messages in thread
* Re: user-controlled load-path extension: load-dir
@ 2011-03-24  0:03 Ben Key
  2011-03-24 14:38 ` Stefan Monnier
  0 siblings, 1 reply; 129+ messages in thread
From: Ben Key @ 2011-03-24  0:03 UTC (permalink / raw)
  To: Emacs-devel, monnier, tzz

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

Stefan Monnier wrote:

> You can commit it into the ELPA (tho I think it'd make more sense to
> merge yours and Ben's first).

The latest version Ted released on Sat, 19 Mar 2011 already has all my
changes merged in.  Ted's implementation was actually cleaner than my
original implementation.  As far as I am concerned, he can simply use that
version with the :require tags removed from the defcustom's.

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

^ permalink raw reply	[flat|nested] 129+ messages in thread
* Re: user-controlled load-path extension: load-dir
@ 2011-03-19  4:10 Ben Key
  2011-03-19 13:29 ` Juanma Barranquero
                   ` (2 more replies)
  0 siblings, 3 replies; 129+ messages in thread
From: Ben Key @ 2011-03-19  4:10 UTC (permalink / raw)
  To: tzz, Emacs-devel


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

Hello,

I have attached to this message an updated version of load-dir.el.  In this
version, I have made several basic improvements.

   1. Each of the defcustom items now has a require property.  The main
   benefit of this is that a user may now simply place load-dir.el in their
   load path, use M-x load-library to load 'load-dir' and then do a M-x
   customize-group to customize the 'load-dir' group, customize load-dirs, and
   restart Emacs.  There is no need to also manually edit their .emacs file to
   add a '(require 'load-dir)' in order to actually cause Emacs to load
   load-dir.el.
   2. Modified the load-dirs defcustom so that it can now accept several
   types via the "Value Menu" customize feature.
      1. nil, the default value, effectively causes load-dir.el to do
      nothing.
      2. t causes the default directory of ~/.emacs.d/load.d to be used
      (saves typing).
      3. A single directory causes files in that directory to be loaded.
      4. A list of directories causes all files in every directory in the
      list to be loaded.

Note that the error handling code does not appear to be working as
expected.  I set load-dir-ignore-errors to t.  I then placed a file error.el
in my load-dir directory that contains a deliberate error.  The expected
behavior is for Emacs initialization to complete with perhaps a message
telling me about the error.  Instead, Emacs initialization halts at the
error and the "*GNU Emacs*" buffer is never displayed.  I will look into
this latter.

I hope that you find this changes useful.

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

[-- Attachment #2: load-dir.el --]
[-- Type: application/octet-stream, Size: 4579 bytes --]

;;; load-dir.el --- load all Emacs Lisp files in given directories

;; Copyright (C) 2011 Free Software Foundation, Inc

;; Authors: Teodor Zlatanov <tzz@lifelogs.com>,
;;          Ben Key <bkey76@gmail.com>
;; With-Help-From: Evans Winner <ego111@gmail.com>, PJ Weisberg <pj@irregularexpressions.net>
;; 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 <http://www.gnu.org/licenses/>.

;;; 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-hook'

;; 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
  "List of directories to load."
  :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 behavior.
If load-dirs is t, only files in the default directory, which is ~/.emacs.d/load.d,
will be loaded.
If load-dirs is a single directory, only files in that directory will be loaded.
If load-dirs is a list of directories, all files found in all the directories in
the list will be loaded."
  :group 'load-dir
  :require 'load-dir
  :type '(choice (const t) (const nil) directory (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 (eq load-dirs t)
						  (list (expand-file-name "~/.emacs.d/load.d"))
						(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

^ permalink raw reply	[flat|nested] 129+ messages in thread
[parent not found: <AANLkTin1zXJQo2vsju7kpa31Nw568m_eNZS+gJ6g2tQO@mail.gmail.com>]
* Re: user-controlled load-path extension: load-dir
@ 2011-03-08  7:14 Ben Key
  2011-03-08  9:58 ` Evans Winner
  0 siblings, 1 reply; 129+ messages in thread
From: Ben Key @ 2011-03-08  7:14 UTC (permalink / raw)
  To: Emacs-devel, tzz


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

Hello,

I personally do not think that this is a good idea for inclusion in Emacs.
However it is a fairly simple task to implement this feature in Emacs lisp.
I am attaching to this message a quick implementation of this feature I
threw together in about an hour.  I am not familiar with the Emacs package
mechanism but I am certain that this could be converted to an Emacs package
without too much work thus making it easier to install.

For now it can be installed by simply placing the file in a directory
located somewhere in the load path and adding the line
(require 'user-load-dir)
to your either .emacs or site-start.el file.

Then from that point on, it will be possible to do exactly what you want,
place a .el file in the directory specified by the user-load-dir variable
(~/.emacs.d/load by default) and have it loaded without having to make any
additional changes to your .emacs file.

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

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

(defun load-user-load-dir-files ()
  "Loads all .el files found in the `user-load-dir.'"
  (interactive)
  (mapc 'load (directory-files user-load-dir t "\\.el\\'"))
  )

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

(provide 'user-load-dir)

^ permalink raw reply	[flat|nested] 129+ messages in thread
* user-controlled load-path extension: load-dir
@ 2011-03-01 20:32 Ted Zlatanov
  2011-03-03 21:07 ` Dimitri Fontaine
  0 siblings, 1 reply; 129+ messages in thread
From: Ted Zlatanov @ 2011-03-01 20:32 UTC (permalink / raw)
  To: emacs-devel

Sorry if this has been discussed before.  I don't recall such a
discussion and the search terms are too generic.

I think it's useful to load on startup any .el files placed in a
particular directory (if the user approves the directory).  For example,
if the user sets `load-dir' to '("~/.emacs.d/load"),
~/.emacs.d/load/*.el will be loaded on startup.  The `load-path' is not
involved, this would be a straight `eval' call.

`load-dir' is just a name suggestion.

This can be done on the user side, of course, but if Emacs had a
built-in facility to do it, enabling and controlling Emacs
configurations in a modular way would be easier, especially for new
users.

Ted




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

end of thread, other threads:[~2011-04-04  9:54 UTC | newest]

Thread overview: 129+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-17  4:22 user-controlled load-path extension: load-dir Ben Key
2011-03-17  6:31 ` Evans Winner
2011-03-17 10:55 ` Ted Zlatanov
2011-03-17 20:11   ` Stefan Monnier
2011-03-17 21:01     ` Ted Zlatanov
2011-03-17 21:05       ` Tom Tromey
2011-03-17 21:23         ` Ted Zlatanov
2011-03-17 22:50           ` Glenn Morris
2011-03-18  2:46             ` Ted Zlatanov
2011-03-18 10:56               ` Dimitri Fontaine
2011-03-18 13:07                 ` Ted Zlatanov
2011-03-18  2:21       ` Stefan Monnier
  -- strict thread matches above, loose matches on Subject: below --
2011-03-24  0:03 Ben Key
2011-03-24 14:38 ` Stefan Monnier
2011-03-26 11:37   ` Ted Zlatanov
2011-04-02 18:35     ` Chong Yidong
2011-04-04  9:54       ` Ted Zlatanov
2011-03-19  4:10 Ben Key
2011-03-19 13:29 ` Juanma Barranquero
2011-03-19 16:07   ` Ben Key
2011-03-19 14:15 ` Ted Zlatanov
2011-03-20  2:58 ` Stefan Monnier
2011-03-20 12:05   ` Ted Zlatanov
2011-03-23 15:32     ` Ted Zlatanov
2011-03-23 20:33       ` Stefan Monnier
     [not found] <AANLkTin1zXJQo2vsju7kpa31Nw568m_eNZS+gJ6g2tQO@mail.gmail.com>
2011-03-08 18:49 ` Ben Key
2011-03-08 20:01   ` Dimitri Fontaine
2011-03-08 20:25     ` Chad Brown
2011-03-08 20:38       ` Dimitri Fontaine
2011-03-08 22:40         ` Chad Brown
2011-03-09  9:36           ` Dimitri Fontaine
2011-03-09 11:52             ` Ted Zlatanov
2011-03-08 22:57     ` Ben Key
2011-03-09  3:28       ` Ben Key
2011-03-09  6:50         ` Ben Key
2011-03-09  7:29           ` Jan D.
2011-03-09 16:00             ` Ben Key
2011-03-09 11:39           ` Ted Zlatanov
2011-03-09 19:51       ` Chong Yidong
2011-03-09 20:08         ` Ben Key
2011-03-09 20:18         ` Ted Zlatanov
2011-03-09 20:32           ` Chong Yidong
2011-03-09 20:44             ` Ted Zlatanov
2011-03-10 11:30             ` Dimitri Fontaine
2011-03-10 14:27               ` Tom Tromey
2011-03-10 17:23                 ` Dimitri Fontaine
2011-03-10 18:33                   ` Tom Tromey
2011-03-10 18:56                     ` Chong Yidong
2011-03-10 19:32                       ` Eli Zaretskii
2011-03-10 20:30                       ` Dimitri Fontaine
2011-03-10 21:54                         ` Chong Yidong
2011-03-11  8:43                           ` Dimitri Fontaine
2011-03-10 19:36                     ` Jambunathan K
2011-03-11 15:00               ` chad
2011-03-11 17:41                 ` Dimitri Fontaine
2011-03-12  5:51                   ` chad
2011-03-12 10:09                     ` Jan Djärv
2011-03-11 18:51                 ` Ted Zlatanov
2011-03-16 14:16             ` Ted Zlatanov
2011-03-16 15:43               ` Stefan Monnier
2011-03-16 20:08                 ` Ted Zlatanov
2011-03-17  2:13                   ` Stefan Monnier
2011-03-17  3:34                     ` Ted Zlatanov
2011-03-17  4:42                       ` PJ Weisberg
2011-03-16 20:11               ` Evans Winner
2011-03-16 20:23                 ` Ted Zlatanov
2011-03-10  2:21         ` Stefan Monnier
2011-03-08  7:14 Ben Key
2011-03-08  9:58 ` Evans Winner
2011-03-08 18:49   ` PJ Weisberg
2011-03-01 20:32 Ted Zlatanov
2011-03-03 21:07 ` Dimitri Fontaine
2011-03-04  9:55   ` Julien Danjou
2011-03-04 17:18     ` Tom Tromey
2011-03-04 18:04       ` Ted Zlatanov
2011-03-04 18:37       ` Dimitri Fontaine
2011-03-04 19:35         ` Tom Tromey
2011-03-04 19:45           ` Dimitri Fontaine
2011-03-04 19:54             ` Ted Zlatanov
2011-03-04 20:21               ` Dimitri Fontaine
2011-03-04 20:25               ` Chad Brown
2011-03-04 20:46                 ` Ted Zlatanov
2011-03-05 19:24                   ` Chad Brown
2011-03-04 20:26               ` Chad Brown
2011-03-04 20:08             ` Tom Tromey
2011-03-04 20:24               ` Dimitri Fontaine
2011-03-04 21:17                 ` Tom Tromey
2011-03-04 21:33                   ` Dimitri Fontaine
2011-03-04 21:37                     ` Tom Tromey
2011-03-05  3:18                     ` Ted Zlatanov
2011-03-05 19:11                       ` Chad Brown
2011-03-06  7:21                       ` Mike Mattie
2011-03-07 16:24                         ` Ted Zlatanov
2011-03-07 17:18                           ` Chad Brown
2011-03-07 17:59                             ` Ted Zlatanov
2011-03-08 17:36                             ` Dimitri Fontaine
2011-03-08 18:30                               ` Chad Brown
2011-03-07 17:52                           ` Stefan Monnier
2011-03-07 20:39                             ` PJ Weisberg
2011-03-08  2:46                               ` Stefan Monnier
2011-03-08 10:26                                 ` Ted Zlatanov
2011-03-08 17:14                                   ` Chong Yidong
2011-03-08 18:47                                     ` Ted Zlatanov
2011-03-08 19:23                                       ` Julien Danjou
2011-03-09  2:54                                         ` Stefan Monnier
2011-03-09 19:57                                           ` Chong Yidong
2011-03-08 20:59                                   ` Stefan Monnier
2011-03-08 21:38                                     ` Ted Zlatanov
2011-03-09  7:06                                       ` Jan D.
2011-03-09  7:17                                         ` Christoph Scholtes
2011-03-09 10:01                                           ` Jan Djärv
2011-03-09 17:29                                             ` Stephen J. Turnbull
2011-03-09 18:18                                               ` Ted Zlatanov
2011-03-09 19:33                                                 ` Stephen J. Turnbull
2011-03-09 19:57                                                   ` Ted Zlatanov
2011-03-10  3:20                                                     ` Stephen J. Turnbull
2011-03-10  5:01                                                       ` Ted Zlatanov
2011-03-10  7:08                                                         ` Stephen J. Turnbull
2011-03-10 13:15                                                           ` Ted Zlatanov
2011-03-11  2:10                                                             ` Stephen J. Turnbull
2011-03-09 21:57                                         ` Mike Mattie
2011-03-10  7:08                                           ` Jan Djärv
2011-03-09  6:03                                   ` Mike Mattie
2011-03-09  7:20                                     ` Jan D.
2011-03-09 23:44                                       ` Mike Mattie
2011-03-08  0:47                           ` Mike Mattie
2011-03-08 10:37                             ` Ted Zlatanov
2011-03-09  6:26                               ` Mike Mattie
2011-03-09 11:26                                 ` 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).