unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Should require and provide be symmetrical?
@ 2010-02-10  1:29 Nathaniel Flath
  2010-02-10  2:44 ` chad
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Nathaniel Flath @ 2010-02-10  1:29 UTC (permalink / raw)
  To: emacs-devel

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

I came across a problem with require and provide that seems rather
counterintuitive, although it is implicit in the documentaiton.  If one file
provides a feature with (provide 'feature) and another requires it, there is
no guarantee that that specific file is loaded, even if no other file calls
(provide 'feature).  I ran into this whil splitting up my personal
configuration - I was attempting to mirror the packages I was loading, so
for example org.el in my directory would contain customizations for
org-mode.  However, in this file, a (require 'org) would cause an infinite
require error, as it tried to load itself instead of the org.el in emacs.
Should this behaviour be changed, or is there a reason for it?

Thanks,
Nathaniel Flath

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

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

* Re: Should require and provide be symmetrical?
  2010-02-10  1:29 Should require and provide be symmetrical? Nathaniel Flath
@ 2010-02-10  2:44 ` chad
  2010-02-10  2:48 ` Stephen J. Turnbull
  2010-02-10 18:27 ` Andreas Schwab
  2 siblings, 0 replies; 5+ messages in thread
From: chad @ 2010-02-10  2:44 UTC (permalink / raw)
  To: Nathaniel Flath; +Cc: emacs-devel

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


On Feb 9, 2010, at 5:29 PM, Nathaniel Flath wrote:

>  I ran into this whil splitting up my personal configuration - I was attempting to mirror the packages I was loading, so for example org.el in my directory would contain customizations for org-mode.  However, in this file, a (require 'org) would cause an infinite require error, as it tried to load itself instead of the org.el in emacs.  Should this behaviour be changed, or is there a reason for it?

try putting those files in a directory ``my-customizations'' and then (require 'my-customizations/org), etc?


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

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

* Should require and provide be symmetrical?
  2010-02-10  1:29 Should require and provide be symmetrical? Nathaniel Flath
  2010-02-10  2:44 ` chad
@ 2010-02-10  2:48 ` Stephen J. Turnbull
  2010-02-10 18:27 ` Andreas Schwab
  2 siblings, 0 replies; 5+ messages in thread
From: Stephen J. Turnbull @ 2010-02-10  2:48 UTC (permalink / raw)
  To: Nathaniel Flath; +Cc: emacs-devel

Nathaniel Flath writes:

 > I came across a problem with require and provide that seems rather
 > counterintuitive, although it is implicit in the documentaiton.  If one file
 > provides a feature with (provide 'feature) and another requires it, there is
 > no guarantee that that specific file is loaded, even if no other file calls
 > (provide 'feature).

How do you propose that Emacs would know this?  N.B. In general there
are usually at least two files that provide any feature (the .el and
its corresponding .elc).

 > I ran into this whil splitting up my personal configuration - I was
 > attempting to mirror the packages I was loading, so for example
 > org.el in my directory would contain customizations for org-mode.
 > However, in this file, a (require 'org) would cause an infinite
 > require error, as it tried to load itself instead of the org.el in
 > emacs.  Should this behaviour be changed, or is there a reason for
 > it?

You'd have to change the loader to parse the file without loading it.
Yuck.  Then, if you get a provide error, you have to keep walking the
load-path to the very end in hopes of find one that does do a provide.
This is still (Big-O (length load-path)), but your coefficient has
been pessimized.  Yuck.  And now we have to maintain state for error-
reporting (a list of tried-and-failed org.el and org.elc files).
Double-yuck.

So, no, I can see no positive reason for the behavior, but I can see
lots of reasons not to change the implementation.  If I were you, I'd
just put those configs somewhere that isn't on load-path.






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

* Re: Should require and provide be symmetrical?
  2010-02-10  1:29 Should require and provide be symmetrical? Nathaniel Flath
  2010-02-10  2:44 ` chad
  2010-02-10  2:48 ` Stephen J. Turnbull
@ 2010-02-10 18:27 ` Andreas Schwab
  2010-02-10 19:12   ` Harald Hanche-Olsen
  2 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2010-02-10 18:27 UTC (permalink / raw)
  To: Nathaniel Flath; +Cc: emacs-devel

Nathaniel Flath <flat0103@gmail.com> writes:

> I ran into this whil splitting up my personal configuration - I was
> attempting to mirror the packages I was loading, so for example org.el
> in my directory would contain customizations for org-mode.

You can use eval-after-load for that.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




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

* Re: Should require and provide be symmetrical?
  2010-02-10 18:27 ` Andreas Schwab
@ 2010-02-10 19:12   ` Harald Hanche-Olsen
  0 siblings, 0 replies; 5+ messages in thread
From: Harald Hanche-Olsen @ 2010-02-10 19:12 UTC (permalink / raw)
  To: emacs-devel

+ Andreas Schwab <schwab@linux-m68k.org>:

> Nathaniel Flath <flat0103@gmail.com> writes:
> 
> > I ran into this whil splitting up my personal configuration - I was
> > attempting to mirror the packages I was loading, so for example org.el
> > in my directory would contain customizations for org-mode.
> 
> You can use eval-after-load for that.

From my .emacs (this is ancient code, not necessarily an example of
good coding style):

(setf HOME (expand-file-name "~hanche"))
(setf my-libdir (concat HOME "/lib/emacs"))
(push my-libdir load-path)
(let ((fixes (mapcar #'(lambda (s) (cons (substring s 4 -3) (substring s 0 -3)))
		     (directory-files my-libdir nil "^fix-.*[.]el$"))))
  (while fixes
    (let ((fix (first fixes)))
      (eval-after-load (car fix) (list 'load (cdr fix))))
    (setf fixes (rest fixes))))

So, if there is a file named fix-org.el in my-libdir, the above will
automatically do (eval-after-load "org" '(load "fix-org")). I use it
more for bugfixes than customizations, but it has served me well over
the years.

- Harald




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

end of thread, other threads:[~2010-02-10 19:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-10  1:29 Should require and provide be symmetrical? Nathaniel Flath
2010-02-10  2:44 ` chad
2010-02-10  2:48 ` Stephen J. Turnbull
2010-02-10 18:27 ` Andreas Schwab
2010-02-10 19:12   ` Harald Hanche-Olsen

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).