unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* (require 'filename) doesn't find the file
@ 2017-03-10  9:17 hector
  2017-03-10  9:37 ` tomas
  2017-03-10  9:38 ` hector
  0 siblings, 2 replies; 6+ messages in thread
From: hector @ 2017-03-10  9:17 UTC (permalink / raw)
  To: help-gnu-emacs

The file called BASENAME.el that I want to (require) is in the load-path.
If I add to it the line

(provide 'basename)

it works.

But if I remove the line when I try to compile it says:

syntax.el:26:1:Error: Required feature `basename' was not provided

The part that I think isn't working:
If FEATURE is not a member of the list `features', then the feature
is not loaded; so load the file FILENAME.

Why doesn't it find the file even if it does not contain a (provide)?

I searched for an answer in the list but couldn't find it.
The topic "Requiring elisp that comes with Emacs" comes close
but not to the point.



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

* Re: (require 'filename) doesn't find the file
  2017-03-10  9:17 (require 'filename) doesn't find the file hector
@ 2017-03-10  9:37 ` tomas
  2017-03-10 10:26   ` hector
  2017-03-10  9:38 ` hector
  1 sibling, 1 reply; 6+ messages in thread
From: tomas @ 2017-03-10  9:37 UTC (permalink / raw)
  To: help-gnu-emacs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, Mar 10, 2017 at 10:17:37AM +0100, hector wrote:
> The file called BASENAME.el that I want to (require) is in the load-path.
> If I add to it the line
> 
> (provide 'basename)
> 
> it works.
> 
> But if I remove the line when I try to compile it says:
> 
> syntax.el:26:1:Error: Required feature `basename' was not provided
> 
> The part that I think isn't working:
> If FEATURE is not a member of the list `features', then the feature
> is not loaded; so load the file FILENAME.
> 
> Why doesn't it find the file even if it does not contain a (provide)?

It finds the file. But the file doesn't keep its promise of "providing"
the feature.

See it this way: a "require"d file might find out that something is
broken. Then it would return without "provide"-ing the feature, to
signal that sorry, this feature isn't available after all.

In short: just end your file with (provide 'basename), as you noticed
up there. Or do you see a problem with that?

regards
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAljCc+0ACgkQBcgs9XrR2kbKBwCdG4mgblQzZIfoaHlmIl0ryDkV
dVQAn0jNDAiBjE/az/LL+g3+WuJqd0fO
=Ol2N
-----END PGP SIGNATURE-----



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

* Re: (require 'filename) doesn't find the file
  2017-03-10  9:17 (require 'filename) doesn't find the file hector
  2017-03-10  9:37 ` tomas
@ 2017-03-10  9:38 ` hector
  2017-03-10  9:55   ` tomas
  1 sibling, 1 reply; 6+ messages in thread
From: hector @ 2017-03-10  9:38 UTC (permalink / raw)
  To: help-gnu-emacs

From the Emacs lisp manual:
     If loading the file succeeds but does not provide FEATURE,
     `require' signals an error, `Required feature FEATURE was not
     provided'.

This part is a bit obscure. So, it does what I want (loading the file)
but signals an error? I don't get it.

So is it bad practice to use the file name as a feature like
"(require 'filename)"?



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

* Re: (require 'filename) doesn't find the file
  2017-03-10  9:38 ` hector
@ 2017-03-10  9:55   ` tomas
  0 siblings, 0 replies; 6+ messages in thread
From: tomas @ 2017-03-10  9:55 UTC (permalink / raw)
  To: help-gnu-emacs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, Mar 10, 2017 at 10:38:29AM +0100, hector wrote:
> >From the Emacs lisp manual:
>      If loading the file succeeds but does not provide FEATURE,
>      `require' signals an error, `Required feature FEATURE was not
>      provided'.
> 
> This part is a bit obscure. So, it does what I want (loading the file)
> but signals an error? I don't get it.
> 
> So is it bad practice to use the file name as a feature like
> "(require 'filename)"?

No. That means, that somewhere, in the path following the (require ...),
there must be a corresponding (provide ...) *unless* something went
wrong.

Typically, the last line of "filename.el" just says (provide 'filename),
but this is just one (the most common) way of doing things.

Think like "filename.el" saying "yep, all went well, now you have
feature 'filename".

As to why this makes sense... (a) other code can ask "do we have this
feature?" (and possibly offer the user alternatives, or an apology,
or hints, or whatever) -- and (b) caching: require itself just skips
loading the file when we've got the feature. No need to load the
file one thousand times when there are thousand packages out there
depending on it.

Regards
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAljCd/4ACgkQBcgs9XrR2kY6wgCeOOu+nJAcKVprRHpBIYVr8wZz
XegAn3ZAqbHpFy4kj4Fq2xqU9OvxqdJS
=wXIQ
-----END PGP SIGNATURE-----



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

* Re: (require 'filename) doesn't find the file
  2017-03-10  9:37 ` tomas
@ 2017-03-10 10:26   ` hector
  2017-03-10 10:46     ` tomas
  0 siblings, 1 reply; 6+ messages in thread
From: hector @ 2017-03-10 10:26 UTC (permalink / raw)
  To: help-gnu-emacs

On Fri, Mar 10, 2017 at 10:37:49AM +0100, tomas@tuxteam.de wrote:
> It finds the file. But the file doesn't keep its promise of "providing"
> the feature.
> 
> See it this way: a "require"d file might find out that something is
> broken. Then it would return without "provide"-ing the feature, to
> signal that sorry, this feature isn't available after all.
> 
> In short: just end your file with (provide 'basename), as you noticed
> up there. Or do you see a problem with that?

No problem at all. But I see a problem in that function require doesn't
behave as its documentation says it does. Or I just don't understand it,
which is worse.

OK, let's widen the picture frame.

I have 2 files: required.el and requiring.el.

required.el contains:

(defvar var1 "Value"
  "This variable is used by \"requiring.el\"")

Them, since requiring.el uses this variable, I write:

(require 'required)

expecting that "required.el" to be loaded at run time.

I'm afraid this is not the right approach. Perhaps both files should be
put together. Or use (load "required.el") instead. I just don't know.



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

* Re: (require 'filename) doesn't find the file
  2017-03-10 10:26   ` hector
@ 2017-03-10 10:46     ` tomas
  0 siblings, 0 replies; 6+ messages in thread
From: tomas @ 2017-03-10 10:46 UTC (permalink / raw)
  To: help-gnu-emacs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, Mar 10, 2017 at 11:26:31AM +0100, hector wrote:
> On Fri, Mar 10, 2017 at 10:37:49AM +0100, tomas@tuxteam.de wrote:
> > It finds the file. But the file doesn't keep its promise of "providing"
> > the feature.
> > 
> > See it this way: a "require"d file might find out that something is
> > broken. Then it would return without "provide"-ing the feature, to
> > signal that sorry, this feature isn't available after all.
> > 
> > In short: just end your file with (provide 'basename), as you noticed
> > up there. Or do you see a problem with that?
> 
> No problem at all. But I see a problem in that function require doesn't
> behave as its documentation says it does. Or I just don't understand it,
> which is worse.
> 
> OK, let's widen the picture frame.
> 
> I have 2 files: required.el and requiring.el.
> 
> required.el contains:
> 
> (defvar var1 "Value"
>   "This variable is used by \"requiring.el\"")
> 
> Them, since requiring.el uses this variable, I write:
> 
> (require 'required)
> 
> expecting that "required.el" to be loaded at run time.
> 
> I'm afraid this is not the right approach. Perhaps both files should be
> put together. Or use (load "required.el") instead. I just don't know.

Your expectation *is* right (assuming paths and things align correctly).

The only missing bit in that picture is for the file "required.el" to
contain one last line

  (provide 'required)

Is the doc unclear about that? (sorry, no time now to check -- ping me
again if you want me to, probly this afternoon)

regards
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAljChAYACgkQBcgs9XrR2kaioQCfRP/FD3UValPdQ1i5JqtZyUSo
jqAAnjZU4sq0f+qE5IMuE1eoqTy929/i
=8zTZ
-----END PGP SIGNATURE-----



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

end of thread, other threads:[~2017-03-10 10:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-10  9:17 (require 'filename) doesn't find the file hector
2017-03-10  9:37 ` tomas
2017-03-10 10:26   ` hector
2017-03-10 10:46     ` tomas
2017-03-10  9:38 ` hector
2017-03-10  9:55   ` tomas

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