unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Loading a file vs evaluating its buffer
@ 2014-10-06  7:40 Thorsten Jolitz
  0 siblings, 0 replies; 3+ messages in thread
From: Thorsten Jolitz @ 2014-10-06  7:40 UTC (permalink / raw)
  To: help-gnu-emacs


Hi List, 

when I try to store the installation directory of an app while loading
its init file "A.el" with this code

#+BEGIN_SRC emacs-lisp
(defvar my-installation-directory ""
 "My installation directory.")

(setq my-installation-directory
      (file-name-directory
       (directory-file-name
	(file-name-directory
	 (buffer-file-name)))))
#+END_SRC

I get 

,----
| Load error for /home/tj/junk/el/A.el:
| (wrong-type-argument stringp nil)
`----

but doing M-x eval-buffer in buffer "A.el" works as expected:

,----[ C-h v my-installation-directory RET ]
| my-installation-directory is a variable defined in `A.el'.
| Its value is "/home/tj/junk/"
| 
| Documentation:
| My installation directory.
`----

How can I get the same result when loading the file?

-- 
cheers,
Thorsten




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

* Re: Loading a file vs evaluating its buffer
       [not found] <mailman.10550.1412581277.1147.help-gnu-emacs@gnu.org>
@ 2014-10-06  8:15 ` Pascal J. Bourguignon
  2014-10-06  8:33   ` Thorsten Jolitz
  0 siblings, 1 reply; 3+ messages in thread
From: Pascal J. Bourguignon @ 2014-10-06  8:15 UTC (permalink / raw)
  To: help-gnu-emacs

Thorsten Jolitz <tjolitz@gmail.com> writes:

> Hi List, 
>
> when I try to store the installation directory of an app while loading
> its init file "A.el" with this code
>
> #+BEGIN_SRC emacs-lisp
> (defvar my-installation-directory ""
>  "My installation directory.")
>
> (setq my-installation-directory
>       (file-name-directory
>        (directory-file-name
> 	(file-name-directory
> 	 (buffer-file-name)))))
> #+END_SRC
>
> I get 
>
> ,----
> | Load error for /home/tj/junk/el/A.el:
> | (wrong-type-argument stringp nil)
> `----
>
> but doing M-x eval-buffer in buffer "A.el" works as expected:
>
> ,----[ C-h v my-installation-directory RET ]
> | my-installation-directory is a variable defined in `A.el'.
> | Its value is "/home/tj/junk/"
> | 
> | Documentation:
> | My installation directory.
> `----
>
> How can I get the same result when loading the file?



(defvar my-installation-directory ""
  "My installation directory.")

(eval-when (load eval)
  ;; This sets my-installation-directory to the directory containing 
  ;; the directory containing this file.
  (setq my-installation-directory
        (file-name-directory
         (directory-file-name
          (file-name-directory
           (or load-file-name (buffer-file-name)))))))



-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk


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

* Re: Loading a file vs evaluating its buffer
  2014-10-06  8:15 ` Loading a file vs evaluating its buffer Pascal J. Bourguignon
@ 2014-10-06  8:33   ` Thorsten Jolitz
  0 siblings, 0 replies; 3+ messages in thread
From: Thorsten Jolitz @ 2014-10-06  8:33 UTC (permalink / raw)
  To: help-gnu-emacs

"Pascal J. Bourguignon" <pjb@informatimago.com> writes:

>            (or load-file-name (buffer-file-name)))))))

Great, thx, did not know about that variable. 

-- 
cheers,
Thorsten




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

end of thread, other threads:[~2014-10-06  8:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.10550.1412581277.1147.help-gnu-emacs@gnu.org>
2014-10-06  8:15 ` Loading a file vs evaluating its buffer Pascal J. Bourguignon
2014-10-06  8:33   ` Thorsten Jolitz
2014-10-06  7:40 Thorsten Jolitz

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