unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* using string variable with file name
@ 2008-02-23 11:53 saneman
  2008-02-23 12:00 ` Joost Kremers
  2008-02-23 23:45 ` Daniel Pittman
  0 siblings, 2 replies; 7+ messages in thread
From: saneman @ 2008-02-23 11:53 UTC (permalink / raw)
  To: help-gnu-emacs

In my .emacs file I have made:

;; Directories
(setq mylisp "~/work/mylisp/")

;; Line numbers
(load-file mylisp cons "setnu.el")
(global-set-key "\C-cl" 'setnu-mode)

But this gives an error. How do I "cons" the variable mylisp with a 
filename?


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

* Re: using string variable with file name
  2008-02-23 11:53 using string variable with file name saneman
@ 2008-02-23 12:00 ` Joost Kremers
  2008-02-23 12:16   ` saneman
  2008-02-23 23:45 ` Daniel Pittman
  1 sibling, 1 reply; 7+ messages in thread
From: Joost Kremers @ 2008-02-23 12:00 UTC (permalink / raw)
  To: help-gnu-emacs

saneman wrote:
> In my .emacs file I have made:
>
> ;; Directories
> (setq mylisp "~/work/mylisp/")
>
> ;; Line numbers
> (load-file mylisp cons "setnu.el")
> (global-set-key "\C-cl" 'setnu-mode)
>
> But this gives an error. How do I "cons" the variable mylisp with a 
> filename?

(cons mylisp "setnu.el")

however, that gives you a cons, which (i think) is not what you want. in
order to concatenate strings, you need concat:

(concat mylisp "setnu.el")

but even that is probably not the best way to do what you want. it's
probably better to add "~/work/mylisp" to your load path:

(setq load-path (cons "~/work/mylisp" load-path))

then you can load the file without explicitly naming its path:

(load-file "setnu.el")


-- 
Joost Kremers                                      joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


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

* Re: using string variable with file name
  2008-02-23 12:00 ` Joost Kremers
@ 2008-02-23 12:16   ` saneman
  2008-02-23 12:44     ` Johan Bockgård
                       ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: saneman @ 2008-02-23 12:16 UTC (permalink / raw)
  To: help-gnu-emacs

Joost Kremers wrote:
> saneman wrote:
>> In my .emacs file I have made:
>>
>> ;; Directories
>> (setq mylisp "~/work/mylisp/")
>>
>> ;; Line numbers
>> (load-file mylisp cons "setnu.el")
>> (global-set-key "\C-cl" 'setnu-mode)
>>
>> But this gives an error. How do I "cons" the variable mylisp with a 
>> filename?
> 
> (cons mylisp "setnu.el")
> 
> however, that gives you a cons, which (i think) is not what you want. in
> order to concatenate strings, you need concat:
> 
> (concat mylisp "setnu.el")
> 
> but even that is probably not the best way to do what you want. it's
> probably better to add "~/work/mylisp" to your load path:
> 
> (setq load-path (cons "~/work/mylisp" load-path))
> 
> then you can load the file without explicitly naming its path:
> 
> (load-file "setnu.el")
> 
> 

When using you last advice:
(setq load-path (cons "~/work/mylisp" load-path))
(load-file "setnu.el")

I get the error:
File error: "Cannot open load file", "/home/saneman/setnu.el"


Seems that the load-path is not updated.


The fist solution:
(setq mylisp "~/work/mylisp/")
(load-file (concat mylisp "setnu.el" ))

works. Are there any rules that say that .el files will not be found in 
the load-path?


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

* Re: using string variable with file name
  2008-02-23 12:16   ` saneman
@ 2008-02-23 12:44     ` Johan Bockgård
  2008-02-23 13:03     ` Joost Kremers
  2008-02-23 16:49     ` Thierry Volpiatto
  2 siblings, 0 replies; 7+ messages in thread
From: Johan Bockgård @ 2008-02-23 12:44 UTC (permalink / raw)
  To: help-gnu-emacs

saneman <asdfsdf@asd.com> writes:

> When using you last advice:
> (setq load-path (cons "~/work/mylisp" load-path))
> (load-file "setnu.el")
>
> I get the error:
> File error: "Cannot open load file", "/home/saneman/setnu.el"

Use `load', not `load-file'.

Or (require 'setnu).

-- 
Johan Bockgård


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

* Re: using string variable with file name
  2008-02-23 12:16   ` saneman
  2008-02-23 12:44     ` Johan Bockgård
@ 2008-02-23 13:03     ` Joost Kremers
  2008-02-23 16:49     ` Thierry Volpiatto
  2 siblings, 0 replies; 7+ messages in thread
From: Joost Kremers @ 2008-02-23 13:03 UTC (permalink / raw)
  To: help-gnu-emacs

saneman wrote:
> When using you last advice:
> (setq load-path (cons "~/work/mylisp" load-path))
> (load-file "setnu.el")
>
> I get the error:
> File error: "Cannot open load file", "/home/saneman/setnu.el"

my bad, i should have used load instead of load-file:

(load "setnu.el")

> Seems that the load-path is not updated.

it is. the problem is that load-file expands the file name you pass to it
to an absolute path before it calls load. IOW it doesn't search the
load-path at all.


-- 
Joost Kremers                                      joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


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

* Re: using string variable with file name
  2008-02-23 12:16   ` saneman
  2008-02-23 12:44     ` Johan Bockgård
  2008-02-23 13:03     ` Joost Kremers
@ 2008-02-23 16:49     ` Thierry Volpiatto
  2 siblings, 0 replies; 7+ messages in thread
From: Thierry Volpiatto @ 2008-02-23 16:49 UTC (permalink / raw)
  To: saneman; +Cc: help-gnu-emacs

saneman <asdfsdf@asd.com> writes:

> Joost Kremers wrote:
>> saneman wrote:
>>> In my .emacs file I have made:
>>>
>>> ;; Directories
>>> (setq mylisp "~/work/mylisp/")
>>>
>>> ;; Line numbers
>>> (load-file mylisp cons "setnu.el")
>>> (global-set-key "\C-cl" 'setnu-mode)
>>>
>>> But this gives an error. How do I "cons" the variable mylisp with a
>>> filename?
>>
>> (cons mylisp "setnu.el")
>>
>> however, that gives you a cons, which (i think) is not what you want. in
>> order to concatenate strings, you need concat:
>>
>> (concat mylisp "setnu.el")
>>
>> but even that is probably not the best way to do what you want. it's
>> probably better to add "~/work/mylisp" to your load path:
>>
>> (setq load-path (cons "~/work/mylisp" load-path))
>>
>> then you can load the file without explicitly naming its path:
>>
>> (load-file "setnu.el")
>>
>>
>
> When using you last advice:
> (setq load-path (cons "~/work/mylisp" load-path))
> (load-file "setnu.el")
>
> I get the error:
> File error: "Cannot open load file", "/home/saneman/setnu.el"
>
>
> Seems that the load-path is not updated.
>
>
> The fist solution:
> (setq mylisp "~/work/mylisp/")
> (load-file (concat mylisp "setnu.el" ))
>
> works. Are there any rules that say that .el files will not be found
> in the load-path?
>
Try that:(if setnu.el is in the directory mylisp)

(add-to-list 'load-path "~/work/mylisp")
(load "setnu.el")
-- 
A + Thierry
Pub key: http://pgp.mit.edu




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

* Re: using string variable with file name
  2008-02-23 11:53 using string variable with file name saneman
  2008-02-23 12:00 ` Joost Kremers
@ 2008-02-23 23:45 ` Daniel Pittman
  1 sibling, 0 replies; 7+ messages in thread
From: Daniel Pittman @ 2008-02-23 23:45 UTC (permalink / raw)
  To: help-gnu-emacs

saneman <asdfsdf@asd.com> writes:

> In my .emacs file I have made:
>
> ;; Directories
> (setq mylisp "~/work/mylisp/")

This is the wrong approach.  See the help for the `load-path' variable
instead.

> ;; Line numbers
> (load-file mylisp cons "setnu.el")

This is utterly incorrect syntax, unrelated to Lisp.  You would do well
to invest time in the Emacs Lisp tutorial, or any other Lisp tutorial,
until you understand the basic syntax of the language.

> (global-set-key "\C-cl" 'setnu-mode)
>
> But this gives an error. How do I "cons" the variable mylisp with a filename?

You use the `cons' function; if you succeed you will then have another
error to deal with because what you *want* to do is create a single
string from both parts -- not a cons cell, which will not work as an
argument to `load-file'.

The correct function is `concat', rather than `cons', but that will also
fail until you actually use the correct syntax for the language.

HTH. HAND.
        Daniel





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

end of thread, other threads:[~2008-02-23 23:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-23 11:53 using string variable with file name saneman
2008-02-23 12:00 ` Joost Kremers
2008-02-23 12:16   ` saneman
2008-02-23 12:44     ` Johan Bockgård
2008-02-23 13:03     ` Joost Kremers
2008-02-23 16:49     ` Thierry Volpiatto
2008-02-23 23:45 ` Daniel Pittman

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